Some insights into DMA

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
Rob

Some insights into DMA

Post by Rob »

A Microsoft driver developer has started a blog. His first couple of entries are on DMA where he discusses some "problems" with DMA and an Operating System. It is Windows oriented, of course, but contains some interesting insights (imho).

DMA part 1
DMA part 2
DMA part 3
DMA part 4

I don't know if there will be more parts.
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:Some insights into DMA

Post by Pype.Clicker »

part 1 & 2 seems a bit "trivial" to me ... part 3 & 4 could worth more indepth reading, but i somehow get the feeling that they'll be highly coupled with Windows DDK ...

Btw, we also have http://www.osdev.org/osfaq2/index.php/DMA in the FAQ (which seems to extend on a regular basis :)
Rob

Re:Some insights into DMA

Post by Rob »

That's true Pype. However, one thing I found very interesting was the notion of a 64-bit memory space with a 32-bit adapter (ie, it can't address above 4 GB).

Of course if you think about it that makes perfect sense. But it's one of those things that's easy to "forget".

Also it was a nice introduction (for me) into scatter-gather lists (for some reason I "assumed" it was always one contingous physical memory range)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Some insights into DMA

Post by Brendan »

Hi,
Rob wrote:That's true Pype. However, one thing I found very interesting was the notion of a 64-bit memory space with a 32-bit adapter (ie, it can't address above 4 GB).
This is actually one of the things that's easy to overlook when you're designing your physical memory manager - especially for long mode (for PAE you need to be able to allocate 32 bit physical addresses for PDPTs anyway).

Also note that 64-bit AMD CPUs have an "IOMMU" which allows a 32 bit PCI device to access all of memory by remapping the addresses (e.g. a 32 bit device can be tricked into thinking it's using addresses below 4 GB when in reality it's not). AFAIK there's also some interesting tricks that this IOMMU can do for hardware virtualization, but I haven't really looked into this yet.

Unfortunately Intel's 64-bit CPUs (or more correctly, their chipsets, as it would go in the northbridge) don't have an IOMMU (which caused some problems for Linux devlopers). :)

Part of the problem the Linux developers had is allocating contiguous buffers below 4 GB. Initially they thought they could re-use the ISA DMA memory management (e.g. physical RAM below 16 MB), but (AFAIK) the kernel is permanantly mapped at 0x00110000 and consumes half of this, often only leaving about 5 or 6 MB for DMA buffers (which wasn't enough).


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.
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:Some insights into DMA

Post by Colonel Kernel »

That was an interesting read. I was a bit puzzled by this footnote though:
1-There are other conditions that can cause this. If you have a controller which used DAC to get at all 64-bits of memory hooked onto a bridge that doesn't properly support DAC (these do exist) your card might be in 32-bit mode anyway. Some day we may be able to block devices from transferring to or from main memory unless the OS has granted them access, and that will probably require some translation as well. There are a few exceptions to this, but for the most part just accept that you'll have to do some translation.
What does he mean by DAC here? I think this is a usage of the abbreviation that I'm not familiar with...
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Some insights into DMA

Post by Brendan »

Hi,
Colonel Kernel wrote:What does he mean by DAC here? I think this is a usage of the abbreviation that I'm not familiar with...
It's "Dual Address Cycle", and is used to get a 64 bit address across a 32 bit bus.

From http://www.techfest.com/hardware/bus/pci_sokos.htm:

Dual Address Cycle (1101)

Two address cycles are necessary when a 64 bit address is used,
but only a 32 bit physical address exists. The least significant portion
of the address is placed on the AD lines first, followed by the most
significant 32 bits. The second address cycle also contains the command
for the type of transfer (I/O, Memory, etc). The PCI bus supports a 64 bit
I/O address space, although this is not available on Intel based PCs due
to limitations of the CPU.



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