Subject: Re: Request for comments: sharing memory between user/kernel space
To: Zeljko Vrba <zvrba@globalnet.hr>
From: Jachym Holecek <freza@dspfpga.com>
List: tech-kern
Date: 03/20/2007 21:31:32
# Zeljko Vrba 2007-03-20:
> I want to write a device that supports only mmap() and ioctl() operations.
> When loaded, the device would allocate and lock (I believe the BSD's correct
> term is "wire"?) a contiguous[1] chunk of physical memory.  The chunk's size
> would be specified at the module load time, and to keep things simple,
> currently I do not have in mind resizing.  A process[2] may mmap() the region
> in its virtual address space as read/write.  This establishes the shared
> memory area between the processes and the kernel.

Any piece of user process address space can be considered "shared with
kernel"...

> [1] I intend to use this area for DMA to/from hardware.  I'm not sure whether
>     contiguity is required, but it seems that it might make life simpler.
>     (Otherwise, what is contiguous in virtual memory might not be contiguous
>     in physical, so how to DMA such data?  Does kernel already handle this?)

See bus_dma(9). IIRC sys/arch/evbppc/virtex/dev/tft_ll.c does something
similar to what you're describing.

> [2] It might be wise to restrict this functionality to only eg. root-owned
>     processes.

  chown root:wheel /dev/foo0
  chmod 600 /dev/foo0

If you need more fine-grained permission control (you don't, unless you
really have to I think), take a look at kauth(9).

	-- Jachym