18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * PPC EDAC common defs
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Author: Dave Jiang <djiang@mvista.com>
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * 2007 (c) MontaVista Software, Inc. This file is licensed under
78c2ecf20Sopenharmony_ci * the terms of the GNU General Public License version 2. This program
88c2ecf20Sopenharmony_ci * is licensed "as is" without any warranty of any kind, whether express
98c2ecf20Sopenharmony_ci * or implied.
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#ifndef ASM_EDAC_H
128c2ecf20Sopenharmony_ci#define ASM_EDAC_H
138c2ecf20Sopenharmony_ci/*
148c2ecf20Sopenharmony_ci * ECC atomic, DMA, SMP and interrupt safe scrub function.
158c2ecf20Sopenharmony_ci * Implements the per arch edac_atomic_scrub() that EDAC use for software
168c2ecf20Sopenharmony_ci * ECC scrubbing.  It reads memory and then writes back the original
178c2ecf20Sopenharmony_ci * value, allowing the hardware to detect and correct memory errors.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_cistatic __inline__ void edac_atomic_scrub(void *va, u32 size)
208c2ecf20Sopenharmony_ci{
218c2ecf20Sopenharmony_ci	unsigned int *virt_addr = va;
228c2ecf20Sopenharmony_ci	unsigned int temp;
238c2ecf20Sopenharmony_ci	unsigned int i;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	for (i = 0; i < size / sizeof(*virt_addr); i++, virt_addr++) {
268c2ecf20Sopenharmony_ci		/* Very carefully read and write to memory atomically
278c2ecf20Sopenharmony_ci		 * so we are interrupt, DMA and SMP safe.
288c2ecf20Sopenharmony_ci		 */
298c2ecf20Sopenharmony_ci		__asm__ __volatile__ ("\n\
308c2ecf20Sopenharmony_ci				1:	lwarx	%0,0,%1\n\
318c2ecf20Sopenharmony_ci					stwcx.	%0,0,%1\n\
328c2ecf20Sopenharmony_ci					bne-	1b\n\
338c2ecf20Sopenharmony_ci					isync"
348c2ecf20Sopenharmony_ci					: "=&r"(temp)
358c2ecf20Sopenharmony_ci					: "r"(virt_addr)
368c2ecf20Sopenharmony_ci					: "cr0", "memory");
378c2ecf20Sopenharmony_ci	}
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#endif
41