Using Static Data Structures for DMA

I had a driver for the linux kernel (2.6.18) in which I used kmalloc (sizeof (my_struct_t), GFP_ATOMIC) to allocate memory, which was later used to transfer data using the DMA controller on some device. Later I had to increase the size of my_struct. It got too big, so the kmalloc () code used a static statement and compiled the __you_cannot_kmalloc_that_much symbol to notify that the chunks of memory were too large to allocate. So I thought that I was declaring my_struct_t as a static variable and I would not allocate it at all.

I defined static my_struct_t my_struct;

but the DMA transaction did not work, and I received invalid DMA'd data in the buffer.

My question is: is it forbidden to use static (global) buffers for dma? And if so, where exactly in the kernel memory card do these buffers sit.

thanks

+3
source share
2 answers

Usually you cannot take any old memory and use it for DMA. The problem is that your memory area can cross page boundaries and break up into different areas of physical memory. In addition, it can be replaced and then replaced back to another physical location earlier. Some architectures have memory areas that are not visible at all from the device bus. Sometimes you may be lucky that your improper DMA buffers work, but this is not guaranteed.

dma, dma_alloc_coherent(). LDD3 15.

DMA, , , , DMA- , DMA -.

+2

, , , . , DMA .

DMA , kmalloc? n DMA-, 1. , .

+2

Source: https://habr.com/ru/post/1724627/


All Articles