bus-master dma 注意事项

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值