Writing Device Drivers

Exporting the Mapping

The devmap(9E) entry point is called as a result of an mmap(2) system call. devmap(9E) is used to:


int xxdevmap(dev_t dev, devmap_cookie_t handle, offset_t off,
 	size_t len, size_t *maplen, u_int model);

dev is the device whose memory is to be mapped. handle is a device-mapping handle that the system creates and uses to describe a mapping to contiguous device or kernel memory. The system may create multiple mapping handles in one mmap(2) system call (for example, if the mapping contains multiple physically discontiguous memory regions). off is the logical offset within the application mapping which has to be translated by the driver to the corresponding offset within the device or kernel memory. len is the length (in bytes) of the memory being mapped.

Initially devmap(9E) is called with parameters off and len, which were passed by the application to mmap(2). devmap(9E) sets *maplen to the length from off to the end of a contiguous memory region. *maplen must be rounded up to a multiple of a page size. If *maplen is set to less than the original mapping length len, the system will repeatedly call devmap(9E) with a new mapping handle and adjusted off and len parameters until the initial mapping length is satisfied. Setting *maplen to less then len allows the driver to associate different kernel memory regions or multiple physically discontiguous memory regions with one contiguous user application mapping.

model is the data model type of the current thread. If a driver supports multiple application data models, model has to be passed to ddi_model_convert_from(9F) to determine whether there is a data model mismatch between the current thread and the device driver. The device driver might have to adjust the shape of data structures before exporting them to a user thread which supports a different data model. See Appendix F, Making a Device Driver 64-Bit Ready for more details.

devmap(9E) must return ENXIO if the logical offset, off, is out of the range of memory exported by the driver.