Re: how to get a 64k DMA buffer for a user program?

Hannu Savolainen (
Thu, 3 Apr 1997 00:15:10 +0300 (EET DST)

On Wed, 2 Apr 1997, Harald Koenig wrote:

> Hi,
> is there a simple hack for Linux 2.0.X that the kernel allocates a
> contigous 64k area of memory which then can be mmaped by a user program
> which is going to use this as DMA buffer then ?
> using a full kernel driver is no option (at least right now for first tests)
> and having this 64k locked, contiguous area seems to be enough for now
> (it's a PCI card, so there is no need for <16MB addresses).
Take a look at the sound driver (linux/drivers/sound/soundcard.c). It
allocates 64k of physically contiguous pages in (sound_alloc_dmap()) using
__get_free_pages() and marks them reserved. Then in sound_mmap() this
memory is mapped to user program's space. The mmap_test.c program in shows how the user process side works.

In practice you should implement a simple loadable device driver with just
open, close and mmap calls. Allocate the memory in init_module() and free
it in cleanup_module(). Freeing mmapped memory in the close routine seems
to cause serious problems in some cases.

Best regards,

Hannu Savolainen (, (Open Sound System (OSS)) (OSS Free/TASD/VoxWare)