From 4c140532385563b2bfdb14e415328baa8e7ce250 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Mar 2014 16:32:16 -0600 Subject: [PATCH] SAM4E CMCC: Fix some errors introducted in last check-in --- arch/arm/src/sam34/chip/sam_cmcc.h | 3 +++ arch/arm/src/sam34/sam_cmcc.c | 33 ++++++++++++++++++------------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/arch/arm/src/sam34/chip/sam_cmcc.h b/arch/arm/src/sam34/chip/sam_cmcc.h index 440ea72c1fc..0d0d96b9161 100644 --- a/arch/arm/src/sam34/chip/sam_cmcc.h +++ b/arch/arm/src/sam34/chip/sam_cmcc.h @@ -51,6 +51,9 @@ ****************************************************************************************/ /* This information is available in the Cache Type Register. How every, it is more * efficient if we do not to do the decoding on each cache access. + * + * CacheSize = CacheLineSize * NCacheLines * NWays + * CacheAddressRange = CacheLineSize * NCacheLines = CacheSize / NWays */ #ifdef CONFIG_ARCH_CHIP_SAM4E diff --git a/arch/arm/src/sam34/sam_cmcc.c b/arch/arm/src/sam34/sam_cmcc.c index 1dd8f660c64..3ffee694749 100644 --- a/arch/arm/src/sam34/sam_cmcc.c +++ b/arch/arm/src/sam34/sam_cmcc.c @@ -39,6 +39,7 @@ #include +#include #include #include @@ -144,24 +145,31 @@ void sam_cmcc_invalidate(uintptr_t start, uintptr_t end) { uintptr_t addr; uint32_t regval; - uint32_t way - uint32_t index; - size_t size; - int nlines; + ssize_t size; + int index; + int way; - /* Get the aligned addresses and size for the memory region to be - * invalidated. + /* Get the aligned addresses and size (in bytes) for the memory region + * to be invalidated. */ start = ALIGN_DOWN(start); - end = ALIGN_up(end); - size = end - start; + end = ALIGN_UP(end); + size = end - start + 1; /* If this is a large region (as big as the cache), then just invalidate * the entire cache the easy way. + * + * CacheSize = CacheLineSize * NCacheLines * NWays + * CacheAddressRange = CacheLineSize * NCacheLines = CacheSize / NWays + * + * Example: CacheSize = 2048, CacheLineSize=16, NWays=4: + * + * CacheAddressRange = 2048 / 4 = 512 + * NCacheLines = 32 */ - if (size >= (CMCC_CACHE_SIZE / CMCC_CACHE_LINE_SIZE / CMCC_NWAYS) + if (size >= (CMCC_CACHE_SIZE / CMCC_NWAYS)) { sam_cmcc_invalidateall(); return; @@ -189,10 +197,9 @@ void sam_cmcc_invalidate(uintptr_t start, uintptr_t end) /* Invalidate the address region */ - index = (start >> CMCC_SHIFT) - nlines = ((end - start) >> CMCC_SHIFT); - - for (addr = start; addr < end; addr += CMCC_CACHE_LINE_SIZE, index++) + for (addr = start, index = (int)(start >> CMCC_SHIFT); + addr <= end; + addr += CMCC_CACHE_LINE_SIZE, index++) { regval = CMCC_MAINT1_INDEX(index); for (way = 0; way < CMCC_NWAYS; way++)