So yes, this is definitely a cache coherency problem. And while I’m quite familiar with RISC-V, I’m not too much with the multi-core aspects of it. But I know that the RISC-V specs define very little in that area apart from basic principles and it’s really up to CPU/SoC designers. So it’s not all identical either from one SoC to the next.
There’s apparently no cache coherency feature on this SoC, so we seem to have to handle it all manually, but since there’s a lot of missing documentation, there may be missing stuff. I have also looked at the C906 specs (open), I’ll have another look yet.
What I did was really to just confirm the issue - having to clear the cache (trigger write-back of all dirty entries) on the writing side and invalidate entries on the reading side is like using a hammer to kill a fly. I hope there’s less heavyweight ways of dealing with this on the CV1800B. I have tried just using fence instructions, but that wasn’t enough. I know there are cache instructions that can clear/invalidate only some specific cache lines rather than the whole cache, but since each line is 64 bytes, for any large enough buffer to share, that would require calling many such instructions in a row. That doesn’t look very pretty.
No, one can’t use the PMP for this. The PMP only deals with memory protection AFAIK. For marking areas not cacheable, that would be the MMU - and, as far as several of us have gotten it, the second core doesn’t have any MMU. So, no luck. Anyway, marking the shared area non-cacheable would make things pretty inefficient (directly accessing DDR RAM without caching doesn’t look too appealing).
As to setting the cache to write-through, it’s not possible. From the C906 specs, its D-Cache doesn’t support write-through, only write-back…
Even so, that still wouldn’t handle the reading side, which also needs its cache to be invalidated when data is modified. And if there isn’t any cache coherency mechanism on this SoC, we’re out of luck and will have to handle it all manually.
Of course, if anyone has done this and knows more about how to handle cache coherency properly on this SoC, please help!