pci 设备使用struct pci_dev来表示的,因此pci设备使用dma的时候需要通过pci_dev->dev 得到struct device *dev之后才能使用dma_alloc_coherent等的接口
但是其实kernel 已经有提供给pci device准备的dma接口,其都定义在include/linux/pci-dma-compat.h 中
例如:
static inline void *
pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
dma_addr_t *dma_handle)
{
return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
}
这样pci设备就能直接使用pci_alloc_consistent 来申请dma内存
但是其实kernel 已经有提供给pci device准备的dma接口,其都定义在include/linux/pci-dma-compat.h 中
例如:
static inline void *
pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
dma_addr_t *dma_handle)
{
return dma_alloc_coherent(hwdev == NULL ? NULL : &hwdev->dev, size, dma_handle, GFP_ATOMIC);
}
这样pci设备就能直接使用pci_alloc_consistent 来申请dma内存