Writing Device Drivers

Register and Memory Mapping

These interfaces support the mapping of device memory and device registers into kernel memory so that a device driver can address them.

int ddi_devmap_segmap(dev_t dev, off_t offset,  	
			struct as *as, caddr_t *addrp, off_t len, u_int prot, 
			u_int maxprot, u_int flags, cred_t *credp);

ddi_devmap_segmap(9F) supports the mmap(2) system call, which allows application programs to map device or kernel memory into their address spaces. ddi_devmap_segmap(9F) should be used as the segmap(9E) entry in the cb_ops(9S) structure.

int devmap_devmem_setup(devmap_cookie_t handle, dev_info_t *dip,  	
			struct devmap_callback_ctl *callbackops, u_int rnumber, offset_t roff, 
			size_t len,  	u_int maxprot, u_int flags, 
			ddi_device_acc_attr_t *accattrp);

devmap_devmem_setup(9F) sets up user mappings to device space. It is called from the devmap(9E) entry point to export a range of a register set specified by rnumber, roff and len.

int devmap_umem_setup(devmap_cookie_t handle,  	
			dev_info_t *dip, struct devmap_callback_ctl *callbackops,  	
			ddi_umem_cookie_t cookie, offset_t koff, size_t len, u_int maxprot, 
			u_int flags, ddi_device_acc_attr_t *accattrp);

devmap_umem_setup(9F) sets up user mappings to kernel memory. It is called from the devmap(9E) entry point to export a range of kernel memory specified by cookie, koff and len.

int devmap_load(devmap_cookie_t handle,  	
			offset_t offset, size_t len, uint_t type, uint_t rw);
int devmap_unload(devmap_cookie_t handle  	
			offset_t offset, size_t len);

devmap_load(9F) and devmap_unload(9F) control whether user accesses to the device mappings created by devmap_devmem_setup(9F) or devmap_umem_setup(9F) in the specified range will generate an access event notification to the device driver.

devmap_unload(9F) tells the system to intercept mapping accesses and invalidates the mapping translations. devmap_load(9F) prevents the system from intercepting mapping accesses and validates the mapping translations.

int ddi_dev_nregs(dev_info_t *dip, int *resultp);

ddi_dev_nregs(9F) passes back in the location pointed to by resultp the number of register specifications a device has.

int ddi_dev_regsize(dev_info_t *dip, u_int rnumber,  	
			off_t *resultp);

ddi_dev_regsize(9F) passes back in the location pointed to by resultp the size of the register set identified by rnumber on the device identified by dip.

int ddi_regs_map_setup(dev_info_t *dip, uint_t  	rnumber, 
			caddr_t *addrp, offset_t offset, offset_t len, 
			ddi_device_acc_attr_t *accattrp, ddi_acc_handle_t *handlep);

ddi_regs_map_setup(9F) maps in the register set given by rnumber. The register number determines which register set is mapped if more than one exists.

void ddi_regs_map_free(ddi_acc_handle_t *handle);

ddi_regs_map_setup(9F) frees the mapping represented by the data access handle. This function is provided for drivers preparing to detach themselves from the system, allowing them to release allocated system resources represented in the handle.

int pci_config_setup(dev_info_t *dip, ddi_acc_handle_t *handle);  
void pci_config_teardown(ddi_acc_handle_t *handle);

pci_config_setup(9F) sets up the necessary resources for enabling subsequent data accesses to the PCI local bus configuration space. pci_config_teardown(9F) reclaims and removes those resources represented by the data access handle returned from pci_config_setup(9F).