Skip to content

Commit c28d382

Browse files
edersondisouzanashif
authored andcommitted
arch/xtensa: Fix z_xtensa_cache_[flush|inv|flush_inv]_all functions
They were basically using the wrong instructions to traverse the cache by index: `dhi`, `dhwb` and `dhwbi` instead of `dii`, `diwb` and `diwbi` variants. Fixes #49112. Signed-off-by: Ederson de Souza <ederson.desouza@intel.com>
1 parent 7b31b0e commit c28d382

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

include/zephyr/arch/xtensa/cache.h

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,38 @@ static ALWAYS_INLINE void z_xtensa_cache_inv(void *addr, size_t bytes)
6565

6666
static ALWAYS_INLINE void z_xtensa_cache_inv_all(void)
6767
{
68-
z_xtensa_cache_inv(NULL, Z_DCACHE_MAX);
68+
#if XCHAL_DCACHE_SIZE
69+
size_t step = XCHAL_DCACHE_LINESIZE;
70+
size_t line;
71+
72+
for (line = 0; line < XCHAL_DCACHE_SIZE; line += step) {
73+
__asm__ volatile("dii %0, 0" :: "r"(line));
74+
}
75+
#endif
6976
}
7077

7178
static ALWAYS_INLINE void z_xtensa_cache_flush_all(void)
7279
{
73-
z_xtensa_cache_flush(NULL, Z_DCACHE_MAX);
80+
#if XCHAL_DCACHE_SIZE
81+
size_t step = XCHAL_DCACHE_LINESIZE;
82+
size_t line;
83+
84+
for (line = 0; line < XCHAL_DCACHE_SIZE; line += step) {
85+
__asm__ volatile("diwb %0, 0" :: "r"(line));
86+
}
87+
#endif
7488
}
7589

7690
static ALWAYS_INLINE void z_xtensa_cache_flush_inv_all(void)
7791
{
78-
z_xtensa_cache_flush_inv(NULL, Z_DCACHE_MAX);
92+
#if XCHAL_DCACHE_SIZE
93+
size_t step = XCHAL_DCACHE_LINESIZE;
94+
size_t line;
95+
96+
for (line = 0; line < XCHAL_DCACHE_SIZE; line += step) {
97+
__asm__ volatile("diwbi %0, 0" :: "r"(line));
98+
}
99+
#endif
79100
}
80101

81102

0 commit comments

Comments
 (0)