您的位置:首页 > 其它

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

2015-07-25 19:24 477 查看

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


注size最好以页为单位分配。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: