DMA通常包括system dma和bus-master dma。他们的区别在于system dma是依赖于系统,device本身并没有dma控制传输的能力,而bus-master则相反,device有dma控制传输的能力。通常比较多见的是bus-master dma方式。
DMA的使用,首先在Start device中获取DMA_ADAPTER,透过DMA_ADAPTER提供的call back来实现dma传输。
获取DMA_ADAPTER的函数:
IoGetDmaAdapter
The IoGetDmaAdapter routine returns a pointer to the DMA adapter structure for a physical device object.
PDMA_ADAPTER
IoGetDmaAdapter(
IN PDEVICE_OBJECT PhysicalDeviceObject,
IN PDEVICE_DESCRIPTION DeviceDescription,
OUT PULONG NumberOfMapRegisters
);
Parameters
PhysicalDeviceObject
Pointer to the physical device object for the device requesting the DMA adapter structure.
DeviceDescription
Pointer to a DEVICE_DESCRIPTION structure, which describes the attributes of the physical device.
NumberOfMapRegisters
A pointer to, on output, the maximum number of map registers that the driver can allocate for any DMA transfer operation.
Return Value
IoGetDmaAdapter returns a pointer to a DMA_ADAPTER structure, which contains pointers to functions that support system-defined DMA operations. If the structure cannot be allocated, the routine returns NULL.
Comments
Before calling this routine, a driver must zero-initialize the structure passed at DeviceDescription and then supply the relevant information for its device.
On success, the DmaOperations member of the routine's return value points to a DMA_OPERATIONS structure, which is a table of pointers to functions that the driver can use to perform subsequent DMA operations. If the driver passes DEVICE_DESCRIPTION_VERSION or DEVICE_DESCRIPTION_VERSION1 in the Version member of the DeviceDescription parameter, IoGetDmaAdapter returns a pointer to version 1 of the DMA_OPERATIONS structure. If the driver passes DEVICE_DESCRIPTION_VERSION2, IoGetDmaAdapter returns version 2 of the table if version 2 is supported; otherwise, it returns NULL. Drivers must check to see if version 2 is supported before attempting to use any version 2 function.
A PnP driver calls IoGetDmaAdapter when its AddDevice routine is called or when it handles a PnP IRP_MN_START_DEVICE request for a device. This IRP includes information about the device's hardware resources that the driver must supply in the DeviceDescription structure.
The caller uses the MaximumLength member in the DeviceDescription structure to indicate the optimal number of map registers it can use. The I/O manager will attempt to allocate enough map registers to accommodate a DMA transfer operation of this maximum size. On output, the I/O manager returns, in the NumberOfMapRegisters parameter, the number of map registers that it allocates. Drivers should check the returned value; there is no guarantee a driver will receive

本文介绍了DMA中的System DMA与Bus-Master DMA的区别,重点讲述了Bus-Master DMA,其中设备具备直接控制数据传输的能力。在使用DMA时,通过获取DMA_ADAPTER并利用其回调实现传输。DeviceDescription的Version和MaximumLength对DMA操作有直接影响,IoGetDmaAdapter会根据MaximumLength确定最大传输长度和map regs数量。对于Storage设备,最大传输长度的设置会限制单次传输的大小。
最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



