Skip to content

Commit 4a3a373

Browse files
yashshah7palmer-dabbelt
authored andcommitted
riscv: Add support to determine no. of L2 cache way enabled
In order to determine the number of L2 cache ways enabled at runtime, implement a private attribute ("number_of_ways_enabled"). Reading this attribute returns the number of enabled L2 cache ways at runtime. Using riscv_set_cacheinfo_ops() hook a custom function, that returns this private attribute, to the generic ops structure which is used by cache_get_priv_group() in cacheinfo framework. Signed-off-by: Yash Shah <[email protected]> Reviewed-by: Anup Patel <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 087958a commit 4a3a373

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

drivers/soc/sifive/sifive_l2_cache.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <linux/interrupt.h>
1010
#include <linux/of_irq.h>
1111
#include <linux/of_address.h>
12+
#include <linux/device.h>
13+
#include <asm/cacheinfo.h>
1214
#include <soc/sifive/sifive_l2_cache.h>
1315

1416
#define SIFIVE_L2_DIRECCFIX_LOW 0x100
@@ -31,6 +33,7 @@
3133

3234
static void __iomem *l2_base;
3335
static int g_irq[SIFIVE_L2_MAX_ECCINTR];
36+
static struct riscv_cacheinfo_ops l2_cache_ops;
3437

3538
enum {
3639
DIR_CORR = 0,
@@ -107,6 +110,38 @@ int unregister_sifive_l2_error_notifier(struct notifier_block *nb)
107110
}
108111
EXPORT_SYMBOL_GPL(unregister_sifive_l2_error_notifier);
109112

113+
static int l2_largest_wayenabled(void)
114+
{
115+
return readl(l2_base + SIFIVE_L2_WAYENABLE) & 0xFF;
116+
}
117+
118+
static ssize_t number_of_ways_enabled_show(struct device *dev,
119+
struct device_attribute *attr,
120+
char *buf)
121+
{
122+
return sprintf(buf, "%u\n", l2_largest_wayenabled());
123+
}
124+
125+
static DEVICE_ATTR_RO(number_of_ways_enabled);
126+
127+
static struct attribute *priv_attrs[] = {
128+
&dev_attr_number_of_ways_enabled.attr,
129+
NULL,
130+
};
131+
132+
static const struct attribute_group priv_attr_group = {
133+
.attrs = priv_attrs,
134+
};
135+
136+
const struct attribute_group *l2_get_priv_group(struct cacheinfo *this_leaf)
137+
{
138+
/* We want to use private group for L2 cache only */
139+
if (this_leaf->level == 2)
140+
return &priv_attr_group;
141+
else
142+
return NULL;
143+
}
144+
110145
static irqreturn_t l2_int_handler(int irq, void *device)
111146
{
112147
unsigned int add_h, add_l;
@@ -170,6 +205,9 @@ static int __init sifive_l2_init(void)
170205

171206
l2_config_read();
172207

208+
l2_cache_ops.get_priv_group = l2_get_priv_group;
209+
riscv_set_cacheinfo_ops(&l2_cache_ops);
210+
173211
#ifdef CONFIG_DEBUG_FS
174212
setup_sifive_debug();
175213
#endif

0 commit comments

Comments
 (0)