[PATCH] arm64: cacheinfo: Report cache sets, ways, and line size
From: Sean Anderson
Date: Fri May 09 2025 - 19:38:40 EST
Cache geometry is exposed through the Cache Size ID register. There is
one register for each cache, and they are selected through the Cache
Size Selection register. If FEAT_CCIDX is implemented, the layout of
CCSIDR changes to allow a larger number of sets and ways.
Signed-off-by: Sean Anderson <sean.anderson@xxxxxxxxx>
---
arch/arm64/include/asm/cache.h | 3 +++
arch/arm64/kernel/cacheinfo.c | 28 ++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/arch/arm64/include/asm/cache.h b/arch/arm64/include/asm/cache.h
index 99cd6546e72e..569330689a2f 100644
--- a/arch/arm64/include/asm/cache.h
+++ b/arch/arm64/include/asm/cache.h
@@ -8,6 +8,9 @@
#define L1_CACHE_SHIFT (6)
#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
+#define CCSIDR_CCIDX_NumSets GENMASK_ULL(55, 32)
+#define CCSIDR_CCIDX_Associativity GENMASK_ULL(23, 3)
+
#define CLIDR_LOUU_SHIFT 27
#define CLIDR_LOC_SHIFT 24
#define CLIDR_LOUIS_SHIFT 21
diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c
index 309942b06c5b..a0180d3f1631 100644
--- a/arch/arm64/kernel/cacheinfo.c
+++ b/arch/arm64/kernel/cacheinfo.c
@@ -34,8 +34,36 @@ static inline enum cache_type get_cache_type(int level)
static void ci_leaf_init(struct cacheinfo *this_leaf,
enum cache_type type, unsigned int level)
{
+ u64 val;
+
this_leaf->level = level;
this_leaf->type = type;
+ if (type == CACHE_TYPE_NOCACHE)
+ return;
+
+ val = FIELD_PREP(CSSELR_EL1_Level, level - 1);
+ if (type == CACHE_TYPE_INST)
+ val |= CSSELR_EL1_InD;
+ write_sysreg(val, csselr_el1);
+
+ val = read_sysreg(ccsidr_el1);
+ this_leaf->coherency_line_size =
+ BIT(FIELD_GET(CCSIDR_EL1_LineSize, val) + 4);
+ if (FIELD_GET(ID_MMFR4_EL1_CCIDX,
+ read_sanitised_ftr_reg(SYS_ID_AA64MMFR4_EL1))) {
+ this_leaf->number_of_sets =
+ FIELD_GET(CCSIDR_CCIDX_NumSets, val) + 1;
+ this_leaf->ways_of_associativity =
+ FIELD_GET(CCSIDR_CCIDX_Associativity, val) + 1;
+ } else {
+ this_leaf->number_of_sets =
+ FIELD_GET(CCSIDR_EL1_NumSets, val) + 1;
+ this_leaf->ways_of_associativity =
+ FIELD_GET(CCSIDR_EL1_Associativity, val) + 1;
+ }
+ this_leaf->size = this_leaf->coherency_line_size *
+ this_leaf->number_of_sets *
+ this_leaf->ways_of_associativity;
}
static void detect_cache_level(unsigned int *level_p, unsigned int *leaves_p)
--
2.35.1.1320.gc452695387.dirty