--- c/src/lib/libbsp/sparc/leon3/include/cache_.h | 81 +++++++++++++++++++++++++ 1 files changed, 81 insertions(+), 0 deletions(-)
diff --git a/c/src/lib/libbsp/sparc/leon3/include/cache_.h b/c/src/lib/libbsp/sparc/leon3/include/cache_.h index eafbb48..32fae4d 100644 --- a/c/src/lib/libbsp/sparc/leon3/include/cache_.h +++ b/c/src/lib/libbsp/sparc/leon3/include/cache_.h @@ -15,14 +15,90 @@ #ifndef LEON3_CACHE_H #define LEON3_CACHE_H +#include <amba.h> + #ifdef __cplusplus extern "C" { #endif #define CPU_CACHE_SUPPORT_PROVIDES_RANGE_FUNCTIONS +#define CPU_CACHE_SUPPORT_PROVIDES_CACHE_SIZE_FUNCTIONS + #define CPU_INSTRUCTION_CACHE_ALIGNMENT 64 +#define CPU_DATA_CACHE_ALIGNMENT 64 + +#define L1_CACHE_SIZE 16384 + +static inline volatile struct l2c_regs *get_l2c_regs(void) +{ + volatile struct l2c_regs *l2c = NULL; + struct ambapp_dev *adev; + + adev = (void *) ambapp_for_each( + &ambapp_plb, + OPTIONS_ALL | OPTIONS_AHB_SLVS, + VENDOR_GAISLER, + GAISLER_L2CACHE, + ambapp_find_by_idx, + NULL + ); + if (adev != NULL) { + l2c = (volatile struct l2c_regs *) DEV_TO_AHB(adev)->start[1]; + } + + return l2c; +} + +static inline size_t get_l2_cache_size(void) +{ + size_t size = 0; + volatile struct l2c_regs *l2c = get_l2c_regs(); + + if (l2c != NULL) { + unsigned status = l2c->status; + unsigned ways = (status & 0x3) + 1; + unsigned set_size = ((status & 0x7ff) >> 2) * 1024; + + size = ways * set_size; + } + + return size; +} + +static inline size_t get_max_size(size_t a, size_t b) +{ + return a < b ? b : a; +} + +static inline size_t get_cache_size(uint32_t level) +{ + size_t size; + + switch (level) { + case 0: + size = get_max_size(L1_CACHE_SIZE, get_l2_cache_size()); + break; + case 1: + size = L1_CACHE_SIZE; + break; + case 2: + size = get_l2_cache_size(); + break; + default: + size = 0; + break; + } + + return size; +} + +static inline size_t _CPU_cache_get_data_cache_size(uint32_t level) +{ + return get_cache_size(level); +} + static inline void _CPU_cache_flush_data_range( const void *d_addr, size_t n_bytes @@ -92,6 +168,11 @@ static inline void _CPU_cache_disable_data(void) /* TODO */ } +static inline size_t _CPU_cache_get_instruction_cache_size( uint32_t level ) +{ + return get_cache_size(level); +} + static inline void _CPU_cache_enable_instruction(void) { /* TODO */ -- 1.7.7 _______________________________________________ rtems-devel mailing list rtems-devel@rtems.org http://www.rtems.org/mailman/listinfo/rtems-devel