Is it really necessary to reserve memory for DMA?
Is it really necessary to reserve memory for DMA?
I was thinking about my memory manager and how it needed to reserve addresses below the 16 MiB mark for DMA, but then I asked myself whether or not I really needed to do so. I've read that the motherboard DMA is slow and outdated. Most of the devices seem to rely on PCI and IDE bus mastering nowadays. If I don't plan on supporting legacy devices (floppy drive, ISA sound cards, etc.) do I still need to reserve the lower 16 MiB for something? Is the motherboard DMA still required for modern devices?
Hi,
This is probably an odd way of doing it, but my kernel reserves a different amount depending on the total system RAM. If you had 32MB total, for example, I reserve 1MB. If you had 4GB total, my kernel reserves the entire 16MB - there are various stages in between. Not that I do much with DMA yet...
Cheers,
Adam
This is probably an odd way of doing it, but my kernel reserves a different amount depending on the total system RAM. If you had 32MB total, for example, I reserve 1MB. If you had 4GB total, my kernel reserves the entire 16MB - there are various stages in between. Not that I do much with DMA yet...
Cheers,
Adam
Hi,
For physical memory management I really like using "free page stacks" - they're fast. If I could I'd use free page stacks and nothing else, but this would make it impossible for any device driver (PCI or ISA) to ask for contiguous pages.
To get around this I use a bitmap (instead of free page stacks) to manage the lowest part of physical memory. This doesn't mean that this space is *reserved* for contiguous allocations - it just means that this space is the only space that can be used for contiguous allocations. For normal allocations (single pages where the phyical address doesn't matter) the physical memory manager tries to allocate other areas when it can, but if it can't it'll allocate the page from the area of lower memory.
This might mean that there isn't enough contiguous space left when a device driver wants it, but this is very unlikely - device drivers normally allocate their DMA buffers when they first start up (during boot), before other software gets a chance to use it all up.
The size of the area managed by the bitmap doesn't make much difference as long as it's "big enough". If it's too small device drivers may fail to initialize, but if it's too large then I end up with less space managed by faster free page stacks and more space managed by the slower bitmap - it reduces performance a little, but I doubt it'd be a huge difference. This means it's much better to have too much space managed by the bitmap than not enough...
I also don't 1:1 map anything. When a device driver says "give me N contiguous pages at FOO" then I allocate N contiguous pages and map those pages into their address space at "FOO". Until software allocates the physical pages the physical pages aren't mapped anywhere in any linear address space.
Cheers,
Brendan
Consider my memory manager/s...deadmutex wrote:Well, I guess I can manage to reserve the first meg of physical memory for something... But do modern devices need the extra 15 MiB of 1:1 mapped memory?
For physical memory management I really like using "free page stacks" - they're fast. If I could I'd use free page stacks and nothing else, but this would make it impossible for any device driver (PCI or ISA) to ask for contiguous pages.
To get around this I use a bitmap (instead of free page stacks) to manage the lowest part of physical memory. This doesn't mean that this space is *reserved* for contiguous allocations - it just means that this space is the only space that can be used for contiguous allocations. For normal allocations (single pages where the phyical address doesn't matter) the physical memory manager tries to allocate other areas when it can, but if it can't it'll allocate the page from the area of lower memory.
This might mean that there isn't enough contiguous space left when a device driver wants it, but this is very unlikely - device drivers normally allocate their DMA buffers when they first start up (during boot), before other software gets a chance to use it all up.
The size of the area managed by the bitmap doesn't make much difference as long as it's "big enough". If it's too small device drivers may fail to initialize, but if it's too large then I end up with less space managed by faster free page stacks and more space managed by the slower bitmap - it reduces performance a little, but I doubt it'd be a huge difference. This means it's much better to have too much space managed by the bitmap than not enough...
I also don't 1:1 map anything. When a device driver says "give me N contiguous pages at FOO" then I allocate N contiguous pages and map those pages into their address space at "FOO". Until software allocates the physical pages the physical pages aren't mapped anywhere in any linear address space.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
You can use floppy for initial booting, but if floppy found on modern(your OS will probably be ready in about 2-10 years for extensive public use) computer then the floppy is deserved not to be working.Combuster wrote:I'm not convinced that not supporting the floppy drive for it's DMA needs is the right way. In fact many of us still use floppy disks for the real testing.
My point is: There is no need of support of any legacy devices such as COM mouses,modems,floppy, and with limited recourses available(human power,devices to test) you gotta aim for devices that are produced nowadays and not whose that out of production already.
Hi,
Every 4 years or so there's a change to ATA/SATA/ATAPI, and video cards become obsolete in about 12 months. Network cards are a little better - they tend to remain used until the network itself is upgraded (cabling, switches, etc). I also wouldn't be surprised if a new "USB 3.0" standard is released in the next year or so, so you can expect scanners, printers, flash drives, etc to change too.
Out of all of this, I'd guess that floppy drives, parallel ports and serial ports are probably the most likely to remain unchanged between now and when your OS is finished...![Smile :)](./images/smilies/icon_smile.gif)
The other thing is that they really aren't that hard to support, and because of this they're good device drivers to write before you get buried under things like PCI-Express, USB, power management and badly documented hardware.
Cheers,
Brendan
Floppy drives, parallel ports and serial ports have all remained mostly unchanged for 20 years or more. Sound cards last for ages - even a 10 year old ISA card is "good enough" for most people.exkor wrote:My point is: There is no need of support of any legacy devices such as COM mouses,modems,floppy, and with limited recourses available(human power,devices to test) you gotta aim for devices that are produced nowadays and not whose that out of production already.
Every 4 years or so there's a change to ATA/SATA/ATAPI, and video cards become obsolete in about 12 months. Network cards are a little better - they tend to remain used until the network itself is upgraded (cabling, switches, etc). I also wouldn't be surprised if a new "USB 3.0" standard is released in the next year or so, so you can expect scanners, printers, flash drives, etc to change too.
Out of all of this, I'd guess that floppy drives, parallel ports and serial ports are probably the most likely to remain unchanged between now and when your OS is finished...
![Smile :)](./images/smilies/icon_smile.gif)
The other thing is that they really aren't that hard to support, and because of this they're good device drivers to write before you get buried under things like PCI-Express, USB, power management and badly documented hardware.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
And all old devices will remain unchanged for another 10 years. But majority don't used LPT printers, COM mouses, and PCs are sold without floppies. If somebody uses these then I suggest to switch to USB which atleast provides better transfer rates.
Supporting anything takes time and more time if there are many devices. Besides any programming job may yield programming mistakes in drivers. Nobody will need polished driver in several years people need them now and better start with nowadays devices and if all drivers written - have a life with your girlfriend.
After you boot your OS first drivers to write is hard drvice, usb, ps2 mouse & kbd, flash cards, network & one generic graphics driver. Manufactures will write more if they see that you OS is popular and if not then the lifetime will not be enough for you to support everything.
It is required to get deept into docs to write drivers and if not you'll be rewriting/copy linux drivers.
Supporting anything takes time and more time if there are many devices. Besides any programming job may yield programming mistakes in drivers. Nobody will need polished driver in several years people need them now and better start with nowadays devices and if all drivers written - have a life with your girlfriend.
After you boot your OS first drivers to write is hard drvice, usb, ps2 mouse & kbd, flash cards, network & one generic graphics driver. Manufactures will write more if they see that you OS is popular and if not then the lifetime will not be enough for you to support everything.
It is required to get deept into docs to write drivers and if not you'll be rewriting/copy linux drivers.
Hmm... well I wanted to somehow avoid DMA as much as practically possible, since it seems to be rather clunky. The whole point in using it is to transfer memory without having to go through the processor. However, sometimes there isn't an interrupt to notify when the transfer is done. That means that the processor has to poll to verify completion which defeats the entire purpose of using DMA in the first place, IMO.
Since I want to create a microkernel, I was wondering where to put something like DMA(if I need to use it). I'm guessing the kernel, because if DMA transfers physical memory, then there's a security/stability risk if a server manages it.
Man... trying to support all of these different devices can really ruin some good designs...![Mad :x](./images/smilies/icon_mad.gif)
Since I want to create a microkernel, I was wondering where to put something like DMA(if I need to use it). I'm guessing the kernel, because if DMA transfers physical memory, then there's a security/stability risk if a server manages it.
Man... trying to support all of these different devices can really ruin some good designs...
![Mad :x](./images/smilies/icon_mad.gif)
- Kevin McGuire
- Member
- Posts: 843
- Joined: Tue Nov 09, 2004 12:00 am
- Location: United States
- Contact:
You should be able to easily reserve memory needed by legacy DMA transaction by tinkering your memory manager to help you. The idea would be that during early kernel booting you need to specify all pages that legacy devices may use with a legacy flag. If you also use the standard method of having each process use virtual memory and map the kernel into each process then you can simply hand out all the legacy memory pages you want to.
When a driver requests legacy memory you see if there exists any free pages. If not then you find one that it used and swap it with a non-legacy page. It is as simple as copying the data from the legacy physical page to another free physical page, then changing the mapping for the process that was using the page. Also since the kernel executes in a virtual mode if it happened to be holding a virtual page that is mapped to this physical location you could also swap them out.
That method might allow you to add some flexibility so that no matter where a driver needs memory at you can provide it.
While, I just thought about it you should be able to force swap any physical page in the system with another as long as nothing has allocated that page as a physical page (only virtual). This might remove the need to even have to specify a page as being legacy. You would have to be careful about a page that might host a page directory or table in that before you start the force swap operation you verify and check and if it is you take the proper action or just deny it.
When a driver requests legacy memory you see if there exists any free pages. If not then you find one that it used and swap it with a non-legacy page. It is as simple as copying the data from the legacy physical page to another free physical page, then changing the mapping for the process that was using the page. Also since the kernel executes in a virtual mode if it happened to be holding a virtual page that is mapped to this physical location you could also swap them out.
That method might allow you to add some flexibility so that no matter where a driver needs memory at you can provide it.
While, I just thought about it you should be able to force swap any physical page in the system with another as long as nothing has allocated that page as a physical page (only virtual). This might remove the need to even have to specify a page as being legacy. You would have to be careful about a page that might host a page directory or table in that before you start the force swap operation you verify and check and if it is you take the proper action or just deny it.
There are 6 usable ISA DMA channels. 3 each of 8 bit, and 16 bit. An 8 bit channel maxes out at a 64K transfer. A 16 bit channel maxes out at a 128K transfer. Except for the floppy (8 bit) which shouldn't be asked to transfer more than 1 cylinder/head at a time. For a 2.88M floppy, that means a max of 18K per transfer, as I recall. If you want to be nice, and have 2 buffers for each DMA channel (so one can be DMAing while the other is being loaded/unloaded) then I figure that the first 1.75M is sufficient to handle all possible ISA DMA with enough space left over for minimal V8086 functionality. Then any driver acquires the 2 buffers when it acquires the DMA channel.
And I kinda figure that SoundBlaster cards are my main reason to want to support ISA DMA.
And I kinda figure that SoundBlaster cards are my main reason to want to support ISA DMA.