From cbace906c6c17bf4912d838385d7c1ee7fb81b25 Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Thu, 4 Mar 2021 11:32:06 -0500 Subject: mips: Revert to commiting the cache when we're told to discard an unaligned block. The filesystem API often passes in unaligned receive buffers, and some code (eg BMP reader) processes data in-place, leading to data loss when we dropped the cache. (And document exactly what we're doing, so we don't go through this again at $future_date) Change-Id: If47a7f2148a5a1a43777f0bd3be1bdfe8239e91e --- firmware/target/mips/mmu-mips.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'firmware') diff --git a/firmware/target/mips/mmu-mips.c b/firmware/target/mips/mmu-mips.c index 35c47207dd..4f2de528bd 100644 --- a/firmware/target/mips/mmu-mips.c +++ b/firmware/target/mips/mmu-mips.c @@ -222,6 +222,22 @@ void discard_dcache_range(const void *base, unsigned int size) char *ptr = CACHEALIGN_DOWN((char*)base); char *end = CACHEALIGN_UP((char*)base + size); + /* If the start of the buffer is unaligned, write + back that cacheline and shrink up the region + to discard. */ + if (base != ptr) { + __CACHE_OP(DCHitWBInv, ptr); + ptr += CACHEALIGN_SIZE; + } + + /* If the end of the buffer is unaligned, write back that + cacheline and shrink down the region to discard. */ + if (ptr != end && (end !=((char*)base + size))) { + end -= CACHEALIGN_SIZE; + __CACHE_OP(DCHitWBInv, ptr); + } + + /* Finally, discard whatever is left */ for(; ptr != end; ptr += CACHEALIGN_SIZE) __CACHE_OP(DCHitInv, ptr); -- cgit v1.2.3