[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250509233735.641419-1-sean.anderson@linux.dev>
Date: Fri, 9 May 2025 19:37:35 -0400
From: Sean Anderson <sean.anderson@...ux.dev>
To: Catalin Marinas <catalin.marinas@....com>,
linux-arm-kernel@...ts.infradead.org
Cc: Radu Rendec <rrendec@...hat.com>,
Will Deacon <will@...nel.org>,
Thomas Weißschuh <thomas.weissschuh@...utronix.de>,
Thomas Gleixner <tglx@...utronix.de>,
linux-kernel@...r.kernel.org,
Sean Anderson <sean.anderson@...ux.dev>
Subject: [PATCH] arm64: cacheinfo: Report cache sets, ways, and line size
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@...ux.dev>
---
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
Powered by blists - more mailing lists