5#ifndef ZEPHYR_INCLUDE_ARCH_XTENSA_CACHE_H_
6#define ZEPHYR_INCLUDE_ARCH_XTENSA_CACHE_H_
8#include <xtensa/config/core-isa.h>
15#define Z_DCACHE_MAX (XCHAL_DCACHE_SIZE / XCHAL_DCACHE_WAYS)
18#define Z_IS_POW2(x) (((x) != 0) && (((x) & ((x)-1)) == 0))
19BUILD_ASSERT(Z_IS_POW2(XCHAL_DCACHE_LINESIZE));
20BUILD_ASSERT(Z_IS_POW2(Z_DCACHE_MAX));
23static inline void z_xtensa_cache_flush(
void *addr,
size_t bytes)
26 size_t step = XCHAL_DCACHE_LINESIZE;
28 size_t last =
ROUND_UP(((
long)addr) + bytes, step);
31 for (line = first; bytes && line < last; line += step) {
32 __asm__
volatile(
"dhwb %0, 0" ::
"r"(line));
37static inline void z_xtensa_cache_flush_inv(
void *addr,
size_t bytes)
40 size_t step = XCHAL_DCACHE_LINESIZE;
42 size_t last =
ROUND_UP(((
long)addr) + bytes, step);
45 for (line = first; bytes && line < last; line += step) {
46 __asm__
volatile(
"dhwbi %0, 0" ::
"r"(line));
51static inline void z_xtensa_cache_inv(
void *addr,
size_t bytes)
54 size_t step = XCHAL_DCACHE_LINESIZE;
56 size_t last =
ROUND_UP(((
long)addr) + bytes, step);
59 for (line = first; bytes && line < last; line += step) {
60 __asm__
volatile(
"dhi %0, 0" ::
"r"(line));
65static inline void z_xtensa_cache_inv_all(
void)
67 z_xtensa_cache_inv(NULL, Z_DCACHE_MAX);
70static inline void z_xtensa_cache_flush_all(
void)
72 z_xtensa_cache_flush(NULL, Z_DCACHE_MAX);
75static inline void z_xtensa_cache_flush_inv_all(
void)
77 z_xtensa_cache_flush_inv(NULL, Z_DCACHE_MAX);
#define ROUND_UP(x, align)
Value of x rounded up to the next multiple of align, which must be a power of 2.
Definition: util.h:138
#define ROUND_DOWN(x, align)
Value of x rounded down to the previous multiple of align, which must be a power of 2.
Definition: util.h:146