Skip to contentSkip to conversation

cache: sifive: clear out the error irqs on init

PATCH In review Ben Dooks 1 participant 3 messages Sep 8, 2023

Subsystems (2)
lore
Share & tools
lore

Ben Dooks

author
#0 lore raw

PATCH 1/2 cache: sifive: clear out the error irqs on init

We are getting a number of cache errors on starting an OS, so to try and avoid this, clear the errors when we first probe the cache.

[[email protected]: changed from sifive.com address]
---
 drivers/cache/cache-sifive-ccache.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/cache/cache-sifive-ccache.c +8 -1
index 540e7df138..178bdcc82d 100644
@@ -51,11 +51,18 @@ static const struct cache_ops sifive_ccache_ops = {
 static int sifive_ccache_probe(struct udevice *dev)
 {
 	struct sifive_ccache *priv = dev_get_priv(dev);
+	void __iomem *base;
 
-	priv->base = dev_read_addr_ptr(dev);
+	priv->base = base = dev_read_addr_ptr(dev);
 	if (!priv->base)
 		return -EINVAL;
 
+	/* read and clear any current errors, possilbly from reset */
+	(void)readl(base + 0x108);
+	(void)readl(base + 0x128);
+	(void)readl(base + 0x148);
+	(void)readl(base + 0x168);
+
 	return 0;
 }
 
Signature · 1 line
2.40.1
author
#1 lore raw

PATCH 2/2 sifive: ccache: add clear LIM area

Add option to clear the LIM area on startup, just in case this is the cause of some of the data-errors on startup.

[[email protected]: changed from sifive.com address]
---
 drivers/cache/Kconfig               |  8 ++++++
 drivers/cache/cache-sifive-ccache.c | 40 +++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)
drivers/cache/Kconfig +8 -0
index abe7de9abf..9d5cbaedea 100644
@@ -46,6 +46,14 @@ config SIFIVE_CCACHE
 	  This driver is for SiFive Composable L2/L3 cache. It enables cache
 	  ways of composable cache.
 
+config SIFIVE_CCACHE_LIMZERO
+	bool "Zero LIM (loosely integrated memory) on startup"
+	depends on SIFIVE_CCACHE
+	help
+	  Select this option to clear the LIM (cache memory) block before
+	  enabling the cache. This will increase the init time but may
+	  help with some of the errors being seen on OS startup.
+
 config SIFIVE_PL2CACHE
 	bool "SiFive per-core L2 cache"
 	select CACHE
drivers/cache/cache-sifive-ccache.c +40 -0
index 178bdcc82d..a84b5c9d04 100644
@@ -8,6 +8,7 @@
 #include <dm.h>
 #include <asm/io.h>
 #include <dm/device.h>
+#include <dm/device_compat.h>
 #include <linux/bitfield.h>
 
 #define SIFIVE_CCACHE_CONFIG		0x000
@@ -43,6 +44,43 @@ static int sifive_ccache_get_info(struct udevice *dev, struct cache_info *info)
 	return 0;
 }
 
+#ifdef CONFIG_SIFIVE_CCACHE_LIMZERO
+static int sifive_clear_lim(struct udevice *dev)
+{
+
+	fdt_addr_t base, size;
+	ofnode mem_node;
+	u32 handle = 0;
+	int ret;
+
+	ret = ofnode_read_u32(dev_ofnode(dev), "memory-region", &handle);
+	if (ret) {
+		dev_err(dev, "no memory-region for lim\n");
+		return -EINVAL;
+	}
+
+	mem_node = ofnode_get_by_phandle(handle);
+	if (!ofnode_valid(mem_node)) {
+		dev_err(dev, "invalid memory region for lim\n");
+		return -EINVAL;
+	}
+
+	base = ofnode_get_addr_size_index(mem_node, 0, &size);
+
+	/* note, we assume this is called so early none of the ways of
+	 * the cache have been enabled, so just clear the entire cache
+	 * memory
+	 */
+
+	dev_info(dev, "clearing l3lim %llx..%llx\n", base, base+size);
+	memset((void *)base, 0x0, size);
+
+	return 0;
+}
+#else
+static inline int sifive_clear_lim(struct udevice *dev) { return 0; }
+#endif
+
 static const struct cache_ops sifive_ccache_ops = {
 	.enable = sifive_ccache_enable,
 	.get_info = sifive_ccache_get_info,
@@ -63,6 +101,8 @@ static int sifive_ccache_probe(struct udevice *dev)
 	(void)readl(base + 0x148);
 	(void)readl(base + 0x168);
 
+	sifive_clear_lim(dev);
+
 	return 0;
 }
 
Signature · 1 line
2.40.1
author
#2 lore raw
In reply to Ben Dooks
Quoted 6 lines · Ben Dooks

We are getting a number of cache errors on starting an OS, so to try and avoid this, clear the errors when we first probe the cache.

[[email protected]: changed from sifive.com address]

As a follow-up, this hasn't been checked to see if it fixes the unmatched or other fuXXX cores. If someone could test it on others and see if it removes the issues, then it would be more than worth getting this merged.

Signature · 4 lines
Ben Dooks				http://www.codethink.co.uk/
Senior Engineer				Codethink - Providing Genius

https://www.codethink.co.uk/privacy.html