DMA example, how does DMA work?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
confused

DMA example, how does DMA work?

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:DMA example, how does DMA work?

Post 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.
RMX

Re:DMA example, how does DMA work?

Post by RMX »

Do anybody know some links to pages about programming DMA in 32bit addresing "mode"" or even in "24bit mode"?
RMX

Re:DMA example, how does DMA work?

Post by RMX »

PS: in the net, the only faqs and tutorials i found was about DMA programming in real mode - 16bit addressing :(
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:DMA example, how does DMA work?

Post 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)
RMX

Re:DMA example, how does DMA work?

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:DMA example, how does DMA work?

Post 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;
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:DMA example, how does DMA work?

Post 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
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.
RMX

Re:DMA example, how does DMA work?

Post 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
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:DMA example, how does DMA work?

Post 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
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.
Post Reply