DMA to user space

From: John Wilson (
Date: Wed Mar 15 2000 - 17:12:16 EST

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?

Background: the device is a bus adapter which connects antique minicomputer
peripherals to the PC. The application software emulates those minicomputers,
so the idea is to allow the user to connect arbitrary DMA devices (which the
application does not know anything about) which may do DMA at any time to
any address, and they will "just work" in the emulated environment.

What I'm currently doing, is requiring that the memory buffer (4 MB) be owned
by the driver, rather than by the application. So when the application opens
the device, it mmaps in the driver's buffer, and forgets about its own existing
4 MB buffer (after copying it into the mmapped area) unless the user asks for
the device to be disconnected (at which points it copies the 4 MB back into
its own buffer). It's yucky but it works. It has a couple of problems:

- wastes the 4 MB of user space (not easily fixed due to the very stupid
  custom memory allocator I'm using).

- more importantly, only *one* of these devices can be open at any one time,
  since each one has a separate buffer and the application needs to have just
  one buf.

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.

So, is it as simple as requiring the user to mlock() the buffer and then
using virt_to_bus to get the page addresses? Or is it more complicated, or
just totally hopeless?

Thanks!!! And let me just say I'm *amazed* how easy it was to get this
driver more or less working, I've written lots of drivers for other systems
and it was usually a nightmare. This is my first for Linux though and it's
been a total breeze.

John Wilson
D Bit

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

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