Skip to contentSkip to conversation

powerpc: check cache coherency of kernel vs firmware

PATCH In review Dale Farnsworth 3 participants 4 messages May 2, 2007 – May 4, 2007 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc: check cache coherency of kernel vs firmware

This function verifies that the cache coherency setting of the kernel (CONFIG_NOT_COHERENT_CACHE) matches that left by the firmware, as indicated by coherency-off device tree property.

It's only needed on platforms where cache-coherency can be enabled or disabled by firmware, e.g. mv64x60-based platforms.

---
 arch/powerpc/Kconfig                       |    3 +
 arch/powerpc/kernel/setup-common.c         |   41 +++++++++++++++++++
 arch/powerpc/platforms/embedded6xx/Kconfig |    1 
 3 files changed, 45 insertions(+)
arch/powerpc/kernel/setup-common.c +41 -0
Index: linux-2.6-powerpc-df/arch/powerpc/kernel/setup-common.c
===================================================================
@@ -530,3 +530,44 @@ void __init setup_panic(void)
 {
 	atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block);
 }
+
+#ifdef CONFIG_CHECK_CACHE_COHERENCY
+/*
+ * For platforms that have configurable cache-coherency.  This function
+ * checks that the cache coherency setting of the kernel matches the setting
+ * left by the firmware, as indicated in the device tree.  Since a mismatch
+ * will eventually result in DMA failures, we print * and error and call
+ * BUG() in that case.
+ */
+
+#ifdef CONFIG_NOT_COHERENT_CACHE
+#define KERNEL_COHERENCY	0
+#else
+#define KERNEL_COHERENCY	1
+#endif
+
+static int __init check_cache_coherency(void)
+{
+	struct device_node *np;
+	const void *prop;
+	int devtree_coherency;
+
+	np = of_find_node_by_path("/");
+	prop = of_get_property(np, "coherency-off", NULL);
+	of_node_put(np);
+
+	devtree_coherency = prop ? 0 : 1;
+
+	if (devtree_coherency != KERNEL_COHERENCY) {
+		printk(KERN_ERR
+			"kernel coherency:%s != device tree_coherency:%s\n",
+			KERNEL_COHERENCY ? "on" : "off",
+			devtree_coherency ? "on" : "off");
+		BUG();
+	}
+
+	return 0;
+}
+
+late_initcall(check_cache_coherency);
+#endif /* CONFIG_CHECK_CACHE_COHERENCY */
arch/powerpc/Kconfig +3 -0
Index: linux-2.6-powerpc-df/arch/powerpc/Kconfig
===================================================================
@@ -373,6 +373,9 @@ config NOT_COHERENT_CACHE
 	bool
 	depends on 4xx || 8xx || E200
 	default y
+
+config CHECK_COHERENT_CACHE
+	bool
 endmenu
 
 source "init/Kconfig"
arch/powerpc/platforms/embedded6xx/Kconfig +1 -0
Index: linux-2.6-powerpc-df/arch/powerpc/platforms/embedded6xx/Kconfig
===================================================================
@@ -41,6 +41,7 @@ config MPC10X_BRIDGE
 config MV64X60
 	bool
 	select PPC_INDIRECT_PCI
+	select CHECK_COHERENT_CACHE
 
 config MPC10X_OPENPIC
 	bool
#1 lore raw

arch/powerpc/kernel/setup-common.c void __init setup_panic(void) · line 573

Quoted 3 lines · On Wed, 2 May 2007 14:59:38 -0700 "Dale Farnsworth" <[email protected]> wrote:
arch/powerpc/kernel/setup-common.c +2 -0
+#ifdef CONFIG_CHECK_CACHE_COHERENCY
+#endif /* CONFIG_CHECK_CACHE_COHERENCY */

These ...

Quoted 1 line

+config CHECK_COHERENT_CACHE

don't match this.
--
Cheers,
Stephen Rothwell [email protected]
http://www.canb.auug.org.au/~sfr/

#2 lore raw
Quoted 10 lines · Stephen Rothwell

arch/powerpc/kernel/setup-common.c void __init setup_panic(void) · line 573

Quoted 3 lines · On Wed, 2 May 2007 14:59:38 -0700 "Dale Farnsworth" <[email protected]> wrote:
arch/powerpc/kernel/setup-common.c +2 -0
+#ifdef CONFIG_CHECK_CACHE_COHERENCY
+#endif /* CONFIG_CHECK_CACHE_COHERENCY */

These ...

Quoted 1 line

+config CHECK_COHERENT_CACHE

don't match this.

Oops. Brown paper bag time.

Thanks,
-Dale

#3 lore raw

PATCH 1/1 powerpc: check cache coherency of kernel vs firmware

In reply to Dale Farnsworth

check_cache_coherency() verifies that the cache coherency setting of the kernel (CONFIG_NOT_COHERENT_CACHE) matches that left by the firmware, as indicated by coherency-off device tree property.

---
New, improved! Now with matching config var names. Thanks Stephen.

 arch/powerpc/Kconfig                       |    3 +
 arch/powerpc/kernel/setup-common.c         |   41 +++++++++++++++++++
 arch/powerpc/platforms/embedded6xx/Kconfig |    1 
 3 files changed, 45 insertions(+)
arch/powerpc/kernel/setup-common.c +41 -0
Index: linux-2.6-powerpc-df/arch/powerpc/kernel/setup-common.c
===================================================================
@@ -530,3 +530,44 @@ void __init setup_panic(void)
 {
 	atomic_notifier_chain_register(&panic_notifier_list, &ppc_panic_block);
 }
+
+#ifdef CONFIG_CHECK_CACHE_COHERENCY
+/*
+ * For platforms that have configurable cache-coherency.  This function
+ * checks that the cache coherency setting of the kernel matches the setting
+ * left by the firmware, as indicated in the device tree.  Since a mismatch
+ * will eventually result in DMA failures, we print * and error and call
+ * BUG() in that case.
+ */
+
+#ifdef CONFIG_NOT_COHERENT_CACHE
+#define KERNEL_COHERENCY	0
+#else
+#define KERNEL_COHERENCY	1
+#endif
+
+static int __init check_cache_coherency(void)
+{
+	struct device_node *np;
+	const void *prop;
+	int devtree_coherency;
+
+	np = of_find_node_by_path("/");
+	prop = of_get_property(np, "coherency-off", NULL);
+	of_node_put(np);
+
+	devtree_coherency = prop ? 0 : 1;
+
+	if (devtree_coherency != KERNEL_COHERENCY) {
+		printk(KERN_ERR
+			"kernel coherency:%s != device tree_coherency:%s\n",
+			KERNEL_COHERENCY ? "on" : "off",
+			devtree_coherency ? "on" : "off");
+		BUG();
+	}
+
+	return 0;
+}
+
+late_initcall(check_cache_coherency);
+#endif /* CONFIG_CHECK_CACHE_COHERENCY */
arch/powerpc/Kconfig +3 -0
Index: linux-2.6-powerpc-df/arch/powerpc/Kconfig
===================================================================
@@ -373,6 +373,9 @@ config NOT_COHERENT_CACHE
 	bool
 	depends on 4xx || 8xx || E200
 	default y
+
+config CONFIG_CHECK_CACHE_COHERENCY
+	bool
 endmenu
 
 source "init/Kconfig"
arch/powerpc/platforms/embedded6xx/Kconfig +1 -0
Index: linux-2.6-powerpc-df/arch/powerpc/platforms/embedded6xx/Kconfig
===================================================================
@@ -41,6 +41,7 @@ config MPC10X_BRIDGE
 config MV64X60
 	bool
 	select PPC_INDIRECT_PCI
+	select CONFIG_CHECK_CACHE_COHERENCY
 
 config MPC10X_OPENPIC
 	bool