Skip to content

Commit bfe7707

Browse files
lyakhlgirdwood
authored andcommitted
cavs: disable data cache operations on uncached addresses
Trying to write back cache on uncached addresses can overwrite data. Invalidating cache should have no ill effects but isn't very meaningful either. Disable both. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent bbe046f commit bfe7707

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

  • src
    • arch/xtensa/include/arch/lib
    • platform/intel/cavs/include/cavs/lib

src/arch/xtensa/include/arch/lib/cache.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@
2020
#include <stddef.h>
2121
#include <stdint.h>
2222

23+
#define SRAM_UNCACHED_ALIAS 0x20000000
24+
25+
#define is_cached(address) (!!((uintptr_t)(address) & SRAM_UNCACHED_ALIAS))
26+
2327
static inline void dcache_writeback_region(void *addr, size_t size)
2428
{
2529
#if XCHAL_DCACHE_SIZE > 0
26-
xthal_dcache_region_writeback(addr, size);
30+
if (is_cached(addr))
31+
xthal_dcache_region_writeback(addr, size);
2732
#endif
2833
}
2934

@@ -37,7 +42,8 @@ static inline void dcache_writeback_all(void)
3742
static inline void dcache_invalidate_region(void *addr, size_t size)
3843
{
3944
#if XCHAL_DCACHE_SIZE > 0
40-
xthal_dcache_region_invalidate(addr, size);
45+
if (is_cached(addr))
46+
xthal_dcache_region_invalidate(addr, size);
4147
#endif
4248
}
4349

@@ -65,7 +71,8 @@ static inline void icache_invalidate_all(void)
6571
static inline void dcache_writeback_invalidate_region(void *addr, size_t size)
6672
{
6773
#if XCHAL_DCACHE_SIZE > 0
68-
xthal_dcache_region_writeback_inv(addr, size);
74+
if (is_cached(addr))
75+
xthal_dcache_region_writeback_inv(addr, size);
6976
#endif
7077
}
7178

src/platform/intel/cavs/include/cavs/lib/memory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct sof;
8585

8686
#define SRAM_ALIAS_BASE 0x9E000000
8787
#define SRAM_ALIAS_MASK 0xFF000000
88-
#define SRAM_ALIAS_OFFSET 0x20000000
88+
#define SRAM_ALIAS_OFFSET SRAM_UNCACHED_ALIAS
8989

9090
#if !defined UNIT_TEST && !defined __ZEPHYR__
9191
#define uncache_to_cache(address) \

0 commit comments

Comments
 (0)