Mail Archives: djgpp/1996/02/15/11:29:08
>>>>> "Malcolm" == Malcolm Taylor <malcolm AT manawatu DOT gen DOT nz> writes:
>>>>> "Ulf" == Ulf Griesmann <ulfg AT groundhog DOT phy DOT nist DOT gov> writes:
Ulf> Hello All,
Ulf> The 8237 DMA controllers in a PC can only perform DMA
Ulf> transfers to the lower 16MB of physical memory. This makes it
Ulf> awkward to allocate buffers for DMA transfers on machines
Ulf> with >16MB of memory because a simple 'malloc' is no longer
Ulf> guaranteed to allocate DMAable memory. Does anyone out there
Ulf> know of a good strategy for allocating DMA buffers which
Ulf> works on large memory machines ? (Will take source code...)
Neil> It is actually worse than this - the 8237 DMA controller takes
Neil> physical addresses, malloc returns virtual addresses. There
Neil> is currently no mechanism to translate malloc'ed virtual
Neil> addresses into physical addresses with which to program the
Neil> DMA controller.
Neil> Having said that, I came up with a solution that uses XMS to allocate
Neil> and lock a region of memory above 1Mb - XMS will tell you
Neil> the physical address of this region, allowing you to program
Neil> DMA transfers. I then used DPMI to map a region of linear
Neil> memory to this XMS region. The application can then access
Neil> the data using the <sys/farptr.h> functions.
Malcolm> There is actually an easier method than that (it has it's
Malcolm> restrictions though). Under DPMI the first 1M of memory
Malcolm> is always locked and has the linear addresses 0-1M. Just allocate
Malcolm> some DOS memory from the DPMI provider and the get the
Malcolm> linear address by segment*16+offset. This can be accessed
Malcolm> with the far-ptr routines using the
Malcolm> __go32_info_block.selector_for_linear_memory as the
Malcolm> selector and the linear address as the offset. Usually
Malcolm> you will want memory that starts on the DMA page
Malcolm> boundaries, so just allocate the size+64K and figure from
Malcolm> the address the start of the first page in the block.
Malcolm> The only limitation of this that I know of is only a
Malcolm> limited amount of memory can be allocated this way. This
Malcolm> isn't normally a problem as the limit is high.
Agreed this is much simpler and I do use this when I can. My scheme
has a lot of management overhead.
Unfortunately my application requires the allocation of between 2 and
4Mb of DMA buffers. I just couldn't get them to fit into the first 1M
of memory :-)
-- Neil Jarvis, Proteon International, York R&D (Neil DOT Jarvis AT proteon DOT com)
-- Don't use commas, which aren't necessary.
- Raw text -