DMA 传送完成后(通常在中断例程中),驱动程序可以通过调用 ddi_dma_unbind_handle(9F) 来释放 DMA 资源。
如Synchronizing Memory Objects中所述,ddi_dma_unbind_handle(9F) 可调用 ddi_dma_sync(9F),从而无需进行任何显式同步。调用 ddi_dma_unbind_handle (9F) 之后,DMA 资源将无效,并且对资源的进一步引用会产生无法预料的结果。以下示例说明如何使用 ddi_dma_unbind_handle(9F)。
示例 9-5 释放 DMA 资源static uint_t
xxintr(caddr_t arg)
{
struct xxstate *xsp = (struct xxstate *)arg;
uint8_t status;
volatile uint8_t temp;
mutex_enter(&xsp->mu);
/* read status */
status = ddi_get8(xsp->access_hdl, &xsp->regp->csr);
if (!(status & INTERRUPTING)) {
mutex_exit(&xsp->mu);
return (DDI_INTR_UNCLAIMED);
}
ddi_put8(xsp->access_hdl, &xsp->regp->csr, CLEAR_INTERRUPT);
/* for store buffers */
temp = ddi_get8(xsp->access_hdl, &xsp->regp->csr);
ddi_dma_unbind_handle(xsp->handle);
/* Check for errors. */
xsp->busy = 0;
mutex_exit(&xsp->mu);
if ( /* pending transfers */ ) {
(void) xxstart((caddr_t)xsp);
}
return (DDI_INTR_CLAIMED);
}
应释放 DMA 资源。如果要在下一传送中使用不同对象,则应重新分配 DMA 资源。但是,如果始终使用同一个对象,则分配一次资源即可。只要保持对 ddi_dma_sync(9F) 的介入调用,随后便可重用资源。