162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * PPC EDAC common defs 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Author: Dave Jiang <djiang@mvista.com> 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * 2007 (c) MontaVista Software, Inc. This file is licensed under 762306a36Sopenharmony_ci * the terms of the GNU General Public License version 2. This program 862306a36Sopenharmony_ci * is licensed "as is" without any warranty of any kind, whether express 962306a36Sopenharmony_ci * or implied. 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci#ifndef ASM_EDAC_H 1262306a36Sopenharmony_ci#define ASM_EDAC_H 1362306a36Sopenharmony_ci/* 1462306a36Sopenharmony_ci * ECC atomic, DMA, SMP and interrupt safe scrub function. 1562306a36Sopenharmony_ci * Implements the per arch edac_atomic_scrub() that EDAC use for software 1662306a36Sopenharmony_ci * ECC scrubbing. It reads memory and then writes back the original 1762306a36Sopenharmony_ci * value, allowing the hardware to detect and correct memory errors. 1862306a36Sopenharmony_ci */ 1962306a36Sopenharmony_cistatic __inline__ void edac_atomic_scrub(void *va, u32 size) 2062306a36Sopenharmony_ci{ 2162306a36Sopenharmony_ci unsigned int *virt_addr = va; 2262306a36Sopenharmony_ci unsigned int temp; 2362306a36Sopenharmony_ci unsigned int i; 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci for (i = 0; i < size / sizeof(*virt_addr); i++, virt_addr++) { 2662306a36Sopenharmony_ci /* Very carefully read and write to memory atomically 2762306a36Sopenharmony_ci * so we are interrupt, DMA and SMP safe. 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_ci __asm__ __volatile__ ("\n\ 3062306a36Sopenharmony_ci 1: lwarx %0,0,%1\n\ 3162306a36Sopenharmony_ci stwcx. %0,0,%1\n\ 3262306a36Sopenharmony_ci bne- 1b\n\ 3362306a36Sopenharmony_ci isync" 3462306a36Sopenharmony_ci : "=&r"(temp) 3562306a36Sopenharmony_ci : "r"(virt_addr) 3662306a36Sopenharmony_ci : "cr0", "memory"); 3762306a36Sopenharmony_ci } 3862306a36Sopenharmony_ci} 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#endif 41