coherent (建立一致性 DMA 映射函数)

1、函数申明/** * dma_alloc_coherent – allocate consistent memory for DMA * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices * @size: required memory size * @handle: bus-specific DMA address * * Allocate some uncached, unbuffered memory for a device for * performing DMA. This function allocates pages, and will * return the CPU-viewed address, and sets @handle to be the * device-viewed address. */void *dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, int flag);

该函数实际获得两个地址, 1、函数的返回值是一个 void *,代表缓冲区的内核虚拟地址 2、相关的总线地址(物理地址),保存在dma_handle中

2、调用A =dma_alloc_writecombine(B,C,D,GFP_KERNEL);含义:A: 内存的虚拟起始地址,,在内核要用此地址来操作所分配的内存B: struct device指针,可以平台初始化里指定,主要是dma_mask之类,可参考framebufferC: 实际分配大小,传入dma_map_size即可D: 返回的内存物理地址,dma就可以用。所以,A和D是一一对应的,只不过,A是虚拟地址,而D是物理地址。对任意一个操作都将改变缓冲区内容。当然要注意操作环境。

注size最好以页为单位分配。

别为荒漠的艰难而哭泣,只为奔流入海功成名就那一天,

coherent (建立一致性 DMA 映射函数)

相关文章:

你感兴趣的文章:

标签云: