Specifications

Developing a Device Drive
r
10-19
device minor number. If the I/O event for which the device is being polled has not
occurred when the driver’s chpoll routine is initially called, the driver returns a pointer
to the pollhead structure associated with the device minor number (see the
chpoll(D2) manual page in the Device Driver Reference). The poll service then links
onto this pollhead structure such information as the processes that are waiting for the
I/O event and the events for which they are waiting. When an event occurs on the device,
the driver calls the pollwakeup() kernel function and supplies the pointer to the
pollhead structure as a parameter so that the poll service can identify and wake the pro-
cess that is waiting for the event to occur.
The Mmap Routine 10
Specification
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/vm.h>
#include <sys/ddi.h>
int
xx
mmap(dev
,
off
, prot
)
dev_t
dev
;
off_t
off
;
int
prot
;
Return Values
the physical page ID if the protection and the offset are valid for the device
otherwise, return NOPAGE if the protection and offset are not valid
The device driver’s mmap routine is called upon receiving a mmap(2) system call for the
associated device. It is optional.
The dev argument specifies the device whose memory is to be mapped.
The off argument specifies the offset within device memory at which mapping begins. For
better or for worse, this offset remains an off_t even for large offset drivers (for which
offsets normally are the larger off64_t type).
The prot argument specifies the access permissions associated with the mapped data.
Valid values for this argument are defined in <sys/mman.h> as follows:
PROT_READ Data can be read from the device
PROT_WRITE Data can be written to the device
PROT_EXEC Data can be executed
PROT_USER Data are accessible from user-level
PROT_ALL All of the above
The mmap routine checks whether the offset is within the range of pages supported by the
device. For example, a device that has 32 K bytes of memory that can be mapped into user
space should not support offsets greater than or equal to 32 K. If the offset does not exist,