Writing Device Drivers

Allocating a DMA Handle

A DMA handle is an opaque object that is used as a reference to subsequently allocated DMA resources. It is usually allocated in the driver's attach entry point using ddi_dma_alloc_handle(9F). ddi_dma_alloc_handle(9F) takes the device information referred to by dip and the device's DMA attributes described by a ddi_dma_attr(9S) structure as parameters.

	int ddi_dma_alloc_handle(dev_info_t *dip, ddi_dma_attr_t *attr,
 		int (*callback)(void *), void *arg,
 		ddi_dma_handle_t *handlep);

dip is a pointer to the device's dev_info structure.

attr is a pointer to a ddi_dma_attr(9S) structure as described in "DMA Attributes".

waitfp is the address of the callback function for handling resource allocation failures.

arg is the argument to pass to the callback function.

handlep is a pointer to a DMA handle to store the returned handle.

Handling Resource Allocation Failures

The resource-allocation routines provide the driver with several options when handling allocation failures. The waitfp argument indicates whether the allocation routines will block, return immediately, or schedule a callback, as shown in Table 7-1.

Table 7-1 Resource Allocation Handling


Indicated Action 


Driver does not need to wait for resources to become available. 


Driver is willing to wait indefinitely for resources to 

become available. 

Other values 

The address of a function to be called when resources 

are likely to be available.