Skip to contentSkip to conversation

powerpc: ppc EDAC ECC software scrubber

PATCH In review Dave Jiang 1 participant 2 messages Mar 2, 2007 1 message not in the archive

lore
Share & tools
lore

Dave Jiang

author
#0 lore raw

PATCH 1/1 powerpc: ppc EDAC ECC software scrubber

Implements the per arch atomic_scrub() function that EDAC uses for software ECC scrubbing. It scrubs 32bit chunks of memory by using the PPC memory reservation instructions. It reads the memory location and does a memory reservation. When it attempts to write back the same value and thus "scrub" the memory, the operation fails if the memory is dirty. It will continue to retry until it succeeds at "scrubbing".

---

include/asm-powerpc/edac.h new file +45 -0
new file mode 100644
index 0000000..0b7ac4d
@@ -0,0 +1,45 @@
+/*
+ * PPC EDAC common defs
+ *
+ * Author: Dave Jiang <[email protected]>
+ *
+ * (C) 2007 MontaVista Software
+ * This file may be distributed under the terms of the
+ * GNU General Public License Version 2.
+ */
+#ifndef ASM_EDAC_H
+#define ASM_EDAC_H
+/* ECC atomic, DMA, SMP and interrupt safe scrub function */
+
+/*
+ * This routine must provide a way to atomically read and then write
+ * back the value it reads to the same memory location in order to 
+ * "scrub" the memory. On x86 it is possible to do this in a single 
+ * instruction with the appropriate prefix. On PPC it is not possible
+ * because of the RISC instruction set. PPC instructions allow one to place 
+ * a reservation on the memory location during the read. And if the 
+ * location is dirtied by somebody else when the scrubber attempt the write, 
+ * the scrubber just have to try again.
+ */
+static __inline__ void atomic_scrub(void *va, u32 size)
+{
+    unsigned int *virt_addr = va;
+	unsigned int temp;
+    unsigned int i;
+
+    for (i = 0; i < size / 4; i++, virt_addr++) {
+        /* Very carefully read and write to memory atomically
+         * so we are interrupt, DMA and SMP safe.
+         */
+		__asm__ __volatile__ ("\n\
+				1:	lwarx	%0,0,%1\n\
+					stwcx.	%0,0,%1\n\
+					bne-	1b\n\
+					isync"
+					: "=&r"(temp)
+					: "r"(virt_addr)
+					: "cr0", "memory");
+	}
+}
+
+#endif
author
#2 lore raw
In reply to a message not in the archive

Resubmit of patch. Fixed whitespace issues.

---

Implements the per arch atomic_scrub() that EDAC use for software ECC scrubbing. It reads memory and then writes back the original value, allowing the hardware to detect and correct memory errors.

---

 include/asm-powerpc/edac.h |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)
include/asm-powerpc/edac.h new file +40 -0
new file mode 100644
index 0000000..384b37d
@@ -0,0 +1,40 @@
+/*
+ * PPC EDAC common defs
+ *
+ * Author: Dave Jiang <[email protected]>
+ *
+ * 2007 (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+#ifndef ASM_EDAC_H
+#define ASM_EDAC_H
+/* 
+ * ECC atomic, DMA, SMP and interrupt safe scrub function.
+ * Implements the per arch atomic_scrub() that EDAC use for software
+ * ECC scrubbing.  It reads memory and then writes back the original
+ * value, allowing the hardware to detect and correct memory errors.
+ */
+static __inline__ void atomic_scrub(void *va, u32 size)
+{
+	unsigned int *virt_addr = va;
+	unsigned int temp;
+	unsigned int i;
+
+	for (i = 0; i < size / sizeof(*virt_addr); i++, virt_addr++) {
+		/* Very carefully read and write to memory atomically
+		 * so we are interrupt, DMA and SMP safe.
+		 */
+		__asm__ __volatile__ ("\n\
+				1:	lwarx	%0,0,%1\n\
+					stwcx.	%0,0,%1\n\
+					bne-	1b\n\
+					isync"
+					: "=&r"(temp)
+					: "r"(virt_addr)
+					: "cr0", "memory");
+	}
+}
+
+#endif