xref: /OK3568_Linux_fs/kernel/arch/arm/include/asm/edac.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright 2011 Calxeda, Inc.
4*4882a593Smuzhiyun  * Based on PPC version Copyright 2007 MontaVista Software, Inc.
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #ifndef ASM_EDAC_H
7*4882a593Smuzhiyun #define ASM_EDAC_H
8*4882a593Smuzhiyun /*
9*4882a593Smuzhiyun  * ECC atomic, DMA, SMP and interrupt safe scrub function.
10*4882a593Smuzhiyun  * Implements the per arch edac_atomic_scrub() that EDAC use for software
11*4882a593Smuzhiyun  * ECC scrubbing.  It reads memory and then writes back the original
12*4882a593Smuzhiyun  * value, allowing the hardware to detect and correct memory errors.
13*4882a593Smuzhiyun  */
14*4882a593Smuzhiyun 
edac_atomic_scrub(void * va,u32 size)15*4882a593Smuzhiyun static inline void edac_atomic_scrub(void *va, u32 size)
16*4882a593Smuzhiyun {
17*4882a593Smuzhiyun #if __LINUX_ARM_ARCH__ >= 6
18*4882a593Smuzhiyun 	unsigned int *virt_addr = va;
19*4882a593Smuzhiyun 	unsigned int temp, temp2;
20*4882a593Smuzhiyun 	unsigned int i;
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun 	for (i = 0; i < size / sizeof(*virt_addr); i++, virt_addr++) {
23*4882a593Smuzhiyun 		/* Very carefully read and write to memory atomically
24*4882a593Smuzhiyun 		 * so we are interrupt, DMA and SMP safe.
25*4882a593Smuzhiyun 		 */
26*4882a593Smuzhiyun 		__asm__ __volatile__("\n"
27*4882a593Smuzhiyun 			"1:	ldrex	%0, [%2]\n"
28*4882a593Smuzhiyun 			"	strex	%1, %0, [%2]\n"
29*4882a593Smuzhiyun 			"	teq	%1, #0\n"
30*4882a593Smuzhiyun 			"	bne	1b\n"
31*4882a593Smuzhiyun 			: "=&r"(temp), "=&r"(temp2)
32*4882a593Smuzhiyun 			: "r"(virt_addr)
33*4882a593Smuzhiyun 			: "cc");
34*4882a593Smuzhiyun 	}
35*4882a593Smuzhiyun #endif
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun #endif
39