linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Dave Jiang <djiang@mvista.com>
To: linuxppc-dev@ozlabs.org, paulus@samba.org
Cc: norsk5@yahoo.com, bluesmoke-devel@lists.sourceforge.net
Subject: [patch 1/1] powerpc: ppc EDAC ECC software scrubber
Date: Thu, 1 Mar 2007 17:09:30 -0700	[thread overview]
Message-ID: <20070302000930.GA8426@blade.az.mvista.com> (raw)

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

             reply	other threads:[~2007-03-02  0:33 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-02  0:09 Dave Jiang [this message]
     [not found] ` <20070302190220.GA9656@mvista.com>
2007-03-02 20:36   ` [patch 1/1] powerpc: ppc EDAC ECC software scrubber Dave Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070302000930.GA8426@blade.az.mvista.com \
    --to=djiang@mvista.com \
    --cc=bluesmoke-devel@lists.sourceforge.net \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=norsk5@yahoo.com \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).