문제

I am working on a network driver and am somewhat confused with the memory management. On the TX path, i receive a skb, as the lower layer expects to get only physical addresses, I think I need to call *virt_to_phys* and send the return value to the lower layer. (Does it make sense?)

Now, I know there are the functions *dma_map_single* and *dma_unmap_single*. I am still not sure how they come to the picture here. So the lower layer wants to work with DMA... Does it mean that I need to run the above commands (in the appropriate time) before dispatching the packet to the lower layer?

I also not sure I understand the meaning of the description of dma_map_single

Ensure that any data held in the cache is appropriately discarded or written back.

Would appreciate your help.

도움이 되었습니까?

해결책

The files DMA-API.txt and DMA-API-HOWTO.txt in the Documentation directory of the Linux sources document how to use these functions.

You can't use virt_to_phys() and the like to get DMA addresses. That worked a long time ago in simpler times. Linux supports a wide range of hardware architectures and buses and for many of those, the address space the devices see does not map 1:1 to the physical address space of the CPU. Then there are also IOMMUs that can change that mapping dynamically. All of this necessitates the use of the DMA API.

다른 팁

Physical addresses are not necessarily the same as I/O bus addresses, so you must always use the dma_map_ functions.

On many systems, DMA accesses go only to main memory, which would break if there were a copy of that memory's contents in the CPU cache. On these systems, the dma_ functions take the appropriate architecture-dependent action to ensure that such conflicts do not happen.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top