1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * PPC EDAC common defs
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Author: Dave Jiang <djiang@mvista.com>
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * 2007 (c) MontaVista Software, Inc. This file is licensed under
7*4882a593Smuzhiyun * the terms of the GNU General Public License version 2. This program
8*4882a593Smuzhiyun * is licensed "as is" without any warranty of any kind, whether express
9*4882a593Smuzhiyun * or implied.
10*4882a593Smuzhiyun */
11*4882a593Smuzhiyun #ifndef ASM_EDAC_H
12*4882a593Smuzhiyun #define ASM_EDAC_H
13*4882a593Smuzhiyun /*
14*4882a593Smuzhiyun * ECC atomic, DMA, SMP and interrupt safe scrub function.
15*4882a593Smuzhiyun * Implements the per arch edac_atomic_scrub() that EDAC use for software
16*4882a593Smuzhiyun * ECC scrubbing. It reads memory and then writes back the original
17*4882a593Smuzhiyun * value, allowing the hardware to detect and correct memory errors.
18*4882a593Smuzhiyun */
edac_atomic_scrub(void * va,u32 size)19*4882a593Smuzhiyun static __inline__ void edac_atomic_scrub(void *va, u32 size)
20*4882a593Smuzhiyun {
21*4882a593Smuzhiyun unsigned int *virt_addr = va;
22*4882a593Smuzhiyun unsigned int temp;
23*4882a593Smuzhiyun unsigned int i;
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun for (i = 0; i < size / sizeof(*virt_addr); i++, virt_addr++) {
26*4882a593Smuzhiyun /* Very carefully read and write to memory atomically
27*4882a593Smuzhiyun * so we are interrupt, DMA and SMP safe.
28*4882a593Smuzhiyun */
29*4882a593Smuzhiyun __asm__ __volatile__ ("\n\
30*4882a593Smuzhiyun 1: lwarx %0,0,%1\n\
31*4882a593Smuzhiyun stwcx. %0,0,%1\n\
32*4882a593Smuzhiyun bne- 1b\n\
33*4882a593Smuzhiyun isync"
34*4882a593Smuzhiyun : "=&r"(temp)
35*4882a593Smuzhiyun : "r"(virt_addr)
36*4882a593Smuzhiyun : "cr0", "memory");
37*4882a593Smuzhiyun }
38*4882a593Smuzhiyun }
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #endif
41