pseudo device driver with mmap

Klaus Schuler (kschuler@freenet.columbus.oh.us)
Tue, 29 Apr 1997 04:26:26 -0400 (EDT)


I am trying to write a pseudo device driver for Linux.
The device driver provides a kind of smart buffer scheme for unrelated
processes. Let's call the driver buf.
The driver provides the entry points buf_open, buf_close, buf_read, buf_write,
buf_ioctl, buf_mmap.
In buf_open, a piece of kernel memory is allocated.
This piece of kernel memory is to be made available in user land by
issuing a
mmap() call into the pseudo device driver buf.
Now the problem is, what code do I need in buf_mmap to make a piece of
allocated kernel memory available to userland?

The sequence of calls in user land:
Process 1:

buf_fd = open("/dev/buf");
ioctl(buf_fd, get_address_of_allocated_kernel_buf, &kernelbufaddr)
buf = mmap(kernelbufaddr, ...)
read(buf_fd, ...) /* blocks until another proc puts something in buf */

work on buf

close(fd);

Process 2

buf_fd = open("/dev/buf");
write(buf_fd, ...)
close(buf_fd);

The details are a bit more complicated than this, but I hope you get the idea.

I have looked at the mmap code of the mem device driver, but it seems it
doesn't do exactly what I want to accomplish. It expects a physical address
to be mapped (correct me, if I'm wrong), buf I have a virtual kernel address
from my call to kmalloc.

What code do I need in buf_mmap to map a piece of allocated kernel memory
to userland?
Any and all replies are appreciated.

K. Schuler
kschuler@freenet.columbus.oh.us