编写设备驱动程序

分配 DMA 句柄

DMA 句柄是一个不透明的对象,用作对后续分配的 DMA 资源的引用。DMA 句柄通常在驱动程序的使用 ddi_dma_alloc_handle(9F)attach() 入口点中分配。ddi_dma_alloc_handle() 函数采用 dip 引用的设备信息以及 ddi_dma_attr(9S) 结构描述的设备的 DMA 特性作为参数。ddi_dma_alloc_handle() 函数的语法如下所示:

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

其中:

dip

指向设备的 dev_info 结构的指针。

attr

指向 ddi_dma_attr(9S) 结构的指针,如DMA 特性中所述。

callback

用于处理资源分配故障的回调函数的地址。

arg

要传递给回调函数的参数。

handlep

指向 DMA 句柄的指针,用于存储返回的句柄。