dma_alloc_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_coherent(B,C,D,GFP_KERNEL);
含義:
A: 內存的虛擬起始地址,在內核要用此地址來操作所分配的內存
B: struct device指針。能夠平台初始化里指定。主要是dma_mask之類。可參考framebuffer
C: 實際分配大小,傳入dma_map_size就可以
D: 返回的內存物理地址,dma就能夠用。
所以,A和D是一一相應的,僅僅只是,A是虛擬地址,而D是物理地址。

對 隨意一個操作都將改變緩沖區內容。當然要注意操作環境。

注size最好以頁為單位分配。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM