Skip to content
Advertisement

How to disable cache memory in kernel modules

I’am currently trying to develop a Linux driver to use a custom module developed in FPGA. For that, I use a Xilinx Zynq SoC with a Linux distribution that runs on the 2 ARM cores and my VHDL modules are implemented on the FPGA part, but this is not really important to understand my problem.

My FPGA module writes directly to the RAM, and I would like to read what it wrote with the driver, but I have problems because of the cache memory. The driver reads from the cache and not for the RAM, so it reads older data.

To define the memory space where the FPGA can write, I use the kmalloc function. Do you know if flags I could use to force reading from the RAM memory instead of the cache exist ?

I saw 2 flags that could be what I am looking for but I don’t really understand what they do :

__GFP_COLD : Request cache-cold pages instead of trying to return cache-warm pages. –> I think it just force the use of a not-already cached page but it cache it afterward. Is that correct ?

GFP_DMA : It seems like what I am looking for exect I read it only force the use of a part of the memory that is compatible with DMA.

How can I disable caching of the array I create with kmalloc ? Or at least how can I force the processor to read from RAM instead of reading from cache ?

Thank you for your help !

Advertisement

Answer

I think I found what I was looking for this morning.

I discovered the function dma_alloc_coherent(), and it seems to do exactly what I am looking for.

More information about this function can be found here :

https://www.kernel.org/doc/Documentation/DMA-API.txt

and here :

https://www.kernel.org/doc/Documentation/DMA-API-HOWTO.txt.

Advertisement