Writing Device Drivers

devmap(9E)

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

Device whose memory is to be mapped

handle

Device-mapping handle that the system creates and uses to describe a mapping to contiguous device or kernel memory

off

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

Length (in bytes) of the memory being mapped.

maplen

Allows driver to associate different kernel memory regions or multiple physically discontiguous memory regions with one contiguous user application mapping

model

Data model type of the current thread

The system creates multiple mapping handles in one mmap(2) system call (for example, if the mapping contains multiple physically discontiguous memory regions).

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.

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 that supports a different data model. See Appendix C, Making a Device Driver 64-Bit Ready for more details.

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