Page 1 of 1

DMA example, how does DMA work?

Posted: Thu Sep 02, 2004 3:15 pm
by confused
Is DMA handled by the Super I/O chip on modern motherboards? How does DMA work register- and I/O port-wise, and are there any code examples anywhere?

Re:DMA example, how does DMA work?

Posted: Fri Sep 03, 2004 8:52 am
by Pype.Clicker
don't know of any example quickly, but
http://www.mega-tokyo.com/forum/index.p ... eadid=6599


http://www.mega-tokyo.com/forum/index.p ... eadid=6624

could help you with basic information.

And yes, nowaday the 8237 (iirc) is emulated by the chipset.

Re:DMA example, how does DMA work?

Posted: Sun Sep 05, 2004 1:01 pm
by RMX
Do anybody know some links to pages about programming DMA in 32bit addresing "mode"" or even in "24bit mode"?

Re:DMA example, how does DMA work?

Posted: Sun Sep 05, 2004 1:04 pm
by RMX
PS: in the net, the only faqs and tutorials i found was about DMA programming in real mode - 16bit addressing :(

Re:DMA example, how does DMA work?

Posted: Sun Sep 05, 2004 4:07 pm
by Pype.Clicker
the DMA completely ignores what the CPU does with addresses. It works the very same way regardless of whether the CPU is in real or protected mode. DMA only has access to lowest 16MB of physical memory and must be programmed with *physical* address.

Thus when operating the DMA controller from protected mode, one must compute the physical address (looking up pages and segment descriptors manually in some cases) of the target buffer rather than programming the DMA with the 'linear' address (e.g. what &buffer returns)

Re:DMA example, how does DMA work?

Posted: Tue Sep 07, 2004 6:59 am
by RMX
ok, but how physical 32bit address is computed when there are only 24 bits avaible in DMA chip?
How to calculate page and the rest of the address knowing physical position of the buffer?

Re:DMA example, how does DMA work?

Posted: Tue Sep 07, 2004 8:02 am
by Pype.Clicker
very simple: the highest 8 bits are always zero ... the 'page' register has nothing to do with the 'paging' unit of the MMU, here. It just contains bits 16..23 (iirc). Thus once you have the physical address,

Code: Select all

page=phys>>16;
offset=phys & 0xFFFF;

Re:DMA example, how does DMA work?

Posted: Tue Sep 07, 2004 8:09 am
by Brendan
Hi,
RMX wrote: ok, but how physical 32bit address is computed when there are only 24 bits avaible in DMA chip?
The DMA chip can only address 16 Mb of physical memory. It only needs 24 bits for this (there's no way for ISA DMA to transfer anything above 16 Mb).
RMX wrote: How to calculate page and the rest of the address knowing physical position of the buffer?
That's not too hard:

Code: Select all

   DMApage = (bufferAddress >> 16);
   DMAoffset = (bufferAddress & 0xFFFF);
It might be a good idea to use a memory area that is specially selected for DMA use though. If you used *any* physical address you felt like then you might end up with DMAoffset too high, which would restrict the size of the DMA transfer. In general you probably want DMAoffset=0x0000 so that you can transfer a full 64 KB in one go.

If you had DMAoffset = 0xFFF0 and tried to transfer more than 16 bytes it'd wrap around. For example, if you tried to transfer 32 Kb to 0x0007FFF0 it'd put the first 16 bytes from 0x0007FFF0 to 0x0007FFFF and the remaining 32752 bytes from 0x00070000 to 0x00077FF0 - probably not what you'd want.


Cheers,

Brendan

Re:DMA example, how does DMA work?

Posted: Sun Sep 12, 2004 3:06 pm
by RMX
It might be a good idea to use a memory area that is specially selected for DMA use though. If you used *any* physical address you felt like then you might end up with DMAoffset too high, which would restrict the size of the DMA transfer. In general you probably want DMAoffset=0x0000 so that you can transfer a full 64 KB in one go.

If you had DMAoffset = 0xFFF0 and tried to transfer more than 16 bytes it'd wrap around. For example, if you tried to transfer 32 Kb to 0x0007FFF0 it'd put the first 16 bytes from 0x0007FFF0 to 0x0007FFFF and the remaining 32752 bytes from 0x00070000 to 0x00077FF0 - probably not what you'd want.
hm...i thought that this problem was already solved by adding new couter registers and few other(?):
http://members.tripod.com/ben_schmitz/freebsd/handbook/handbook295.html

Re:DMA example, how does DMA work?

Posted: Mon Sep 13, 2004 2:37 am
by Brendan
Hi,
RMX wrote: hm...i thought that this problem was already solved by adding new couter registers and few other(?):
Yes it was solved, but the solution was abandoned :-)

As far as I can tell the EISA DMA controller was only ever present in EISA computers (which are rare as EISA died before it really got started)...

Of course PCI devices can have built in bus mastering capabilities, but that doesn't help the legacy ISA stuff (floppy, parallel port, older sound cards, etc)..


Cheers,

Brendan