Page 1 of 1

Some insights into DMA

Posted: Mon Mar 13, 2006 8:12 am
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.

Re:Some insights into DMA

Posted: Mon Mar 13, 2006 11:23 am
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 :)

Re:Some insights into DMA

Posted: Mon Mar 13, 2006 2:40 pm
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)

Re:Some insights into DMA

Posted: Mon Mar 13, 2006 4:11 pm
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

Re:Some insights into DMA

Posted: Mon Mar 13, 2006 5:28 pm
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...

Re:Some insights into DMA

Posted: Mon Mar 13, 2006 6:13 pm
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