DMA Operations
The steps involved in a DMA transfer are similar among the types of DMA. The sections below present methods for performing DMA transfers.
Note - You do not have to ensure the DMA object is locked in memory in block drivers for buffers coming from the file system, as the file system has already locked the data in memory.
Performing Bus-Master DMA Transfers
In general, the driver should perform the following steps for bus-master DMA.
Describe the DMA attributes. This enables the routines to ensure that the device will be able to access the buffer.
Allocate a DMA handle.
Ensure that the DMA object is locked in memory (see physio(9F) or ddi_umem_lock(9F)).
Allocate DMA resources for the object.
Program the DMA engine on the device and start it (this is device specific). When the transfer is complete, continue the bus master operation.
Perform any required object synchronizations.
Release the DMA resources.
Free the DMA handle.
Performing First-Party DMA Transfers
In general, the driver should perform the following steps for first-party DMA.
Allocate a DMA channel.
Configure the channel with ddi_dmae_1stparty(9F).
Ensure that the DMA object is locked in memory (see physio(9F) or ddi_umem_lock(9F)).
Allocate DMA resources for the object.
Program the DMA engine on the device and start it (this is device specific). When the transfer is complete, continue the bus-master operation.
Perform any required object synchronizations.
Release the DMA resources.
Deallocate the DMA channel.
Performing Third-Party DMA Transfers
In general, the driver should perform these steps for third-party DMA.
Allocate a DMA channel.
Retrieve the system's DMA engine attributes with ddi_dmae_getattr(9F).
Lock the DMA object in memory (see physio(9F) or ddi_umem_lock(9F)).
Allocate DMA resources for the object.
Program the system DMA engine to perform the transfer with ddi_dmae_prog(9F).
Perform any required object synchronizations.
Stop the DMA engine with ddi_dmae_stop(9F).
Release the DMA resources.
Deallocate the DMA channel.
Certain hardware platforms restrict DMA capabilities in a bus-specific way. Drivers should use ddi_slaveonly(9F) to determine if the device is in a slot in which DMA is possible.
DMA Attributes
DMA attributes describe the built-in attributes and limits of a DMA engine, including:
Limits on addresses the device can access
Maximum transfer count
Address alignment restrictions
To ensure that DMA resources allocated by the system can be accessed by the device's DMA engine, device drivers must inform the system of their DMA engine limitations using a ddi_dma_attr(9S) structure. The system might impose additional restrictions on the device attributes, but it never removes any of the driver-supplied restrictions.