dma_map_sg函数定义在/asm/dma-mapping.h中,如下所示: intdma_map_sg(structdevice*dev,structscatterlist*sglist,intnents,enumdma_data_directiondir){...}参数*dev是设备结构体;参数*sg是scatterlist结构体数组;参数nents是页数,也就是SG缓存块的个数;参数direction是DMA传输方向,它是一个枚举类型变量; 常...
.get_sgtable = iommu_dma_get_sgtable, .map_page = iommu_dma_map_page, .unmap_page = iommu_dma_unmap_page, .map_sg = iommu_dma_map_sg, .unmap_sg = iommu_dma_unmap_sg, .sync_single_for_cpu = iommu_dma_sync_single_for_cpu, .sync_single_for_device = iommu_dma_sync_single_fo...
.get_sgtable = iommu_dma_get_sgtable, .map_page = iommu_dma_map_page, ---(2) .unmap_page = iommu_dma_unmap_page, .map_sg = iommu_dma_map_sg, .unmap_sg = iommu_dma_unmap_sg, .sync_single_for_cpu = iommu_dma_sync_single_for_cpu, .sync_single_for_device = iommu_dma_sync...
(5) 上一小节说到scatterlist结构体描述SG缓存块的,包含页面、页内偏移、长度等信息,Linux提供了sg_set_page函数来把这些信息存入scatterlist结构体中(遍历scatterlist结构体数组一个一个分配)。 (6) 最后调用dma_map_sg函数建立SGDMA映射,此时SGDMA的环境就建立好了。dma_map_sg函数定义在/asm/dma-mapping.h中,...
返回的 sg_table 保证有 1 个单一的 DMA 映射段,如 sgt->nents 所示,但可能有多个 CPU 端段,如 sgt->orig_nents 所示。 dir 参数指定设备是读取和/或写入数据,详细信息请参阅 dma_map_single()。 gfp 参数允许调用者指定 GFP_ 标志(参见 kmalloc())进行分配,但拒绝用于指定内存区域的标志,如 GFP_DMA...
还有dma_map_sg, dma_unmap_sg这两个API,有的dma引擎较强,支持 聚集散列,自动传n个buffer,第一个传完,传第二个,并不需要连续的内存做DMA.可以用上述两个api,可以将多个不连续的 buffer 做自动传输(以后接触到再查资料学习把)。 dma_alloc_coherent的例外 ...
我们知道DMA映射有两种方式,一种是一致性映射 dma_alloc_coherent,一种是流式映射 dma_map_single(dma_map_sg可以映射多个dma buffer)。 一致性映射 dma_alloc_coherent dma_alloc_coherent会调用dma_alloc_attrs: 代码语言:javascript 复制 staticinlinevoid*dma_alloc_attrs(struct device*dev,size_t size,dma_...
static struct dma_map_ops iommu_dma_ops = { .alloc = __iommu_alloc_attrs, .free = __iommu_free_attrs, .mmap = __iommu_mmap_attrs, .get_sgtable = __iommu_get_sgtable, .map_page = __iommu_map_page, .unmap_page = __iommu_unmap_page, ...
mapping_error = __swiotlb_dma_mapping_error, }; static struct dma_map_ops iommu_dma_ops = { .alloc = __iommu_alloc_attrs, .free = __iommu_free_attrs, .mmap = __iommu_mmap_attrs, .get_sgtable = __iommu_get_sgtable, .map_page = __iommu_map_page, .unmap_page = __iommu_...
int i, count = dma_map_sg(dev, sglist, nents, direction); struct scatterlist *sg; for_each_sg(sglist, sg, count, i) { hw_address[i] = sg_dma_address(sg); hw_len[i] = sg_dma_len(sg); } where nents is the number of entries in the sglist. 其中 nents 是 sglist 中的...