I am writing an operating system for the raspberry pi. I have a problem with the sdcard driver for the custom sdhost controller (emmc2) of the raspberry-pi 4 (Cortex-A72, ARMv8-A, bcm2711 chipset). Without using sdma everything works. With sdma, read works, but after writing sectors, the data on the sdcard sometimes contains invalid data.
For the sdma data transfer, I use a transfer buffer with a device type memory attribute (nGnRnE). When I use a fresh data buffer for the dma write transfer, the data on the sdcard is correct. But when I reuse the same buffer for the next write, then the sector on the sdcard partially contains data from the previous buffer content.
Maybe this is a cache coherency problem. I have enabled all caches (I and D). In the ARM manuals there is a talk of the SCU (snoop control unit) and I don't know whether I have do bother about the SCU.
My questions are:
- Is it necessary to enable the SCU on a Cortex-A72 and how can this be done ?
- What other things have to be kept in mind when using dma for device access ?