Re: DMA to user space

From: Richard B. Johnson (root@chaos.analogic.com)
Date: Thu Mar 16 2000 - 08:22:38 EST


On Wed, 15 Mar 2000, John Wilson wrote:

> I hope I'm asking this in the right place, flame away if not! :-)
>
> I'm writing a driver for a strange DMA device and I would like to be able
> to do DMA directly into the user's buffer. Is this possible?
>

No. Not a "user-buffer". It may be possible to memory-map something that's
DMA..able to user space, but even that's not guaranteed. To have something
DMA..able in the ix86 machines, it needs to be:

(1) Physical, below 16 Megabytes
(2) DATA alignment must be such that a 64k block is not crossed
        during a DMA transfer. The ix86 machines use a page register
        to access 64k pages.
(3) You need access to the DMA controller which the kernel isn't
        going to give you, without a fight iopl(3), etc., from user-
        space.

If you need DMA, make a module to access the device. This leads to
the question of; "Why do you need DMA?"

[SNIPPED]

>
> The advantage of doing the DMA in user space is that arbitrarily many devices
> (potentially using different drivers) could be connected to the same 4
> MB user buffer. Not many users will need this, but it works great in the
> DOS version of the application and if possible I'd like to avoid having to
> explain to customers why moving to the "better" OS means losing features.
>

DMA has nothing at all to do with this. DMA transfers data between
physical areas, memory-to-ports, ports-to-memory, or (one channel)
memory-to-memory. They are not "connected-to" some common buffer.

If you have N devices that are memory-mapped to the same physical
address, they will interfere. If you have N devices that can copy
their data from a port to a shared buffer then, in principle, you
can use these devices together if you can synchronize the copying
operation. You can copy to/from ports without ever using DMA.

This means that you can copy directly to/from any user buffer
you want. You don't need to even know its physical address.

Cheers,
Dick Johnson

Penguin : Linux version 2.3.41 on an i686 machine (800.63 BogoMips).

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Mar 23 2000 - 21:00:18 EST