diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2021-07-19 11:06:09 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2022-09-22 13:22:22 +0200 |
commit | cd70c791a4b31b529c3b5ebf80742f3e413cd337 (patch) | |
tree | 1ee96961e54c53da3027c68c6313f6767b226071 /bsps/sparc/leon3/start/cache.c | |
parent | 7008cc54c04a59eae6e23c1241e664b2a004ccab (diff) |
bsp/leon3: Add LEON3_L2CACHE_BASE
Diffstat (limited to 'bsps/sparc/leon3/start/cache.c')
-rw-r--r-- | bsps/sparc/leon3/start/cache.c | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/bsps/sparc/leon3/start/cache.c b/bsps/sparc/leon3/start/cache.c index 670d03005b..e507e66e7e 100644 --- a/bsps/sparc/leon3/start/cache.c +++ b/bsps/sparc/leon3/start/cache.c @@ -11,7 +11,13 @@ #include <bsp/leon3.h> +#if !defined(LEON3_L2CACHE_BASE) #include <grlib/ambapp.h> +#endif + +#if !defined(LEON3_L2CACHE_BASE) || LEON3_L2CACHE_BASE != 0 +#define LEON3_MAYBE_HAS_L2CACHE +#endif #define CPU_CACHE_SUPPORT_PROVIDES_RANGE_FUNCTIONS @@ -23,6 +29,7 @@ #define CPU_DATA_CACHE_ALIGNMENT 64 +#if !defined(LEON3_L2CACHE_BASE) static inline l2cache *get_l2c_regs(void) { struct ambapp_dev *adev; @@ -42,7 +49,17 @@ static inline l2cache *get_l2c_regs(void) return (l2cache *) DEV_TO_AHB(adev)->start[1]; } +#endif + +static inline size_t get_l1_size(uint32_t l1_cfg) +{ + uint32_t ways = ((l1_cfg >> 24) & 0x7) + 1; + uint32_t wsize = UINT32_C(1) << (((l1_cfg >> 20) & 0xf) + 10); + + return ways * wsize; +} +#if defined(LEON3_MAYBE_HAS_L2CACHE) static inline size_t get_l2_size(void) { l2cache *regs; @@ -50,11 +67,15 @@ static inline size_t get_l2_size(void) unsigned ways; unsigned set_size; +#if defined(LEON3_L2CACHE_BASE) + regs = (l2cache *) LEON3_L2CACHE_BASE; +#else regs = get_l2c_regs(); if (regs == NULL) { return 0; } +#endif status = grlib_load_32(®s->l2cs); ways = L2CACHE_L2CS_WAY_GET(status) + 1; @@ -63,18 +84,11 @@ static inline size_t get_l2_size(void) return ways * set_size; } -static inline size_t get_l1_size(uint32_t l1_cfg) -{ - uint32_t ways = ((l1_cfg >> 24) & 0x7) + 1; - uint32_t wsize = UINT32_C(1) << (((l1_cfg >> 20) & 0xf) + 10); - - return ways * wsize; -} - static inline size_t get_max_size(size_t a, size_t b) { return a < b ? b : a; } +#endif static inline size_t get_cache_size(uint32_t level, uint32_t l1_cfg) { @@ -82,14 +96,20 @@ static inline size_t get_cache_size(uint32_t level, uint32_t l1_cfg) switch (level) { case 0: +#if defined(LEON3_MAYBE_HAS_L2CACHE) size = get_max_size(get_l1_size(l1_cfg), get_l2_size()); +#else + size = get_l1_size(l1_cfg); +#endif break; case 1: size = get_l1_size(l1_cfg); break; +#if defined(LEON3_MAYBE_HAS_L2CACHE) case 2: size = get_l2_size(); break; +#endif default: size = 0; break; |