linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [patch 1/1] powerpc: ppc EDAC ECC software scrubber
@ 2007-03-02  0:09 Dave Jiang
       [not found] ` <20070302190220.GA9656@mvista.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Dave Jiang @ 2007-03-02  0:09 UTC (permalink / raw)
  To: linuxppc-dev, paulus; +Cc: norsk5, bluesmoke-devel

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".

Signed-off-by: Dave Jiang <djiang@mvista.com>

---

diff --git a/include/asm-powerpc/edac.h b/include/asm-powerpc/edac.h
new file mode 100644
index 0000000..0b7ac4d
--- /dev/null
+++ b/include/asm-powerpc/edac.h
@@ -0,0 +1,45 @@
+/*
+ * PPC EDAC common defs
+ *
+ * Author: Dave Jiang <djiang@mvista.com>
+ *
+ * (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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch 1/1] powerpc: ppc EDAC ECC software scrubber
       [not found] ` <20070302190220.GA9656@mvista.com>
@ 2007-03-02 20:36   ` Dave Jiang
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Jiang @ 2007-03-02 20:36 UTC (permalink / raw)
  To: linuxppc-dev, paulus; +Cc: norsk5, dfarnsworth, bluesmoke-devel

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.

Signed-off-by: Dave Jiang <djiang@mvista.com>
---

 include/asm-powerpc/edac.h |   40 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/include/asm-powerpc/edac.h b/include/asm-powerpc/edac.h
new file mode 100644
index 0000000..384b37d
--- /dev/null
+++ b/include/asm-powerpc/edac.h
@@ -0,0 +1,40 @@
+/*
+ * PPC EDAC common defs
+ *
+ * Author: Dave Jiang <djiang@mvista.com>
+ *
+ * 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-03-02 20:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-02  0:09 [patch 1/1] powerpc: ppc EDAC ECC software scrubber Dave Jiang
     [not found] ` <20070302190220.GA9656@mvista.com>
2007-03-02 20:36   ` Dave Jiang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).