diff --git a/arch/arm/src/sam34/sam_cmcc.c b/arch/arm/src/sam34/sam_cmcc.c index 9b7ef0725f..1dd8f660c6 100644 --- a/arch/arm/src/sam34/sam_cmcc.c +++ b/arch/arm/src/sam34/sam_cmcc.c @@ -146,8 +146,27 @@ void sam_cmcc_invalidate(uintptr_t start, uintptr_t end) uint32_t regval; uint32_t way uint32_t index; + size_t size; int nlines; + /* Get the aligned addresses and size for the memory region to be + * invalidated. + */ + + start = ALIGN_DOWN(start); + end = ALIGN_up(end); + size = end - start; + + /* If this is a large region (as big as the cache), then just invalidate + * the entire cache the easy way. + */ + + if (size >= (CMCC_CACHE_SIZE / CMCC_CACHE_LINE_SIZE / CMCC_NWAYS) + { + sam_cmcc_invalidateall(); + return; + } + /* "When an invalidate by line command is issued the cache controller resets * the valid bit information of the decoded cache line. As the line is no * longer valid the replacement counter points to that line. @@ -170,9 +189,6 @@ void sam_cmcc_invalidate(uintptr_t start, uintptr_t end) /* Invalidate the address region */ - start = ALIGN_DOWN(start); - end = ALIGN_up(end); - index = (start >> CMCC_SHIFT) nlines = ((end - start) >> CMCC_SHIFT);