1 /* SPDX-License-Identifier: GPL-2.0-only */
10 PATTERN3
= 0xA5A5A500,
11 PATTERN4
= 0xA500A500,
12 PATTERN5
= 0xA5000000,
13 PATTERN6
= 0xFFFF0000,
14 PATTERN7
= 0x0000FFFF,
15 PATTERN8
= 0x00000012,
16 PATTERN9
= 0x00000034,
17 PATTERNA
= 0x00000056,
18 PATTERNB
= 0x00000078,
19 PATTERNC
= 0x00001234,
20 PATTERND
= 0x00005678,
21 PATTERNE
= 0x12345678,
25 int complex_mem_test(u8
*start
, unsigned int len
)
27 unsigned char *mem8_base
= (unsigned char *)start
;
28 unsigned short *mem16_base
= (unsigned short *)start
;
29 unsigned int *mem32_base
= (unsigned int *)start
;
30 unsigned int *mem_base
= (unsigned int *)start
;
31 unsigned char pattern8
;
32 unsigned short pattern16
;
33 unsigned int i
, j
, size
, pattern32
;
39 /* verify the tied bits (tied high) */
40 for (i
= 0; i
< size
; i
++)
41 mem32_base
[i
] = PATTERN0
;
43 for (i
= 0; i
< size
; i
++) {
44 if (mem32_base
[i
] != PATTERN0
)
47 mem32_base
[i
] = PATTERNF
;
50 /* verify the tied bits (tied low) */
51 for (i
= 0; i
< size
; i
++) {
52 if (mem32_base
[i
] != PATTERNF
)
54 mem32_base
[i
] = PATTERN0
;
57 /* verify pattern 1 (0x00~0xff) */
59 for (i
= 0; i
< len
; i
++)
60 mem8_base
[i
] = pattern8
++;
62 for (i
= 0; i
< len
; i
++) {
63 if (mem8_base
[i
] != pattern8
++)
67 /* verify pattern 2 (0x00~0xff) */
69 for (i
= j
= 0; i
< len
; i
+= 2, j
++) {
70 if (mem8_base
[i
] == pattern8
)
71 mem16_base
[j
] = pattern8
;
72 if (mem16_base
[j
] != pattern8
)
78 /* verify pattern 3 (0x00~0xffff) */
80 for (i
= 0; i
< (len
>> 1); i
++)
81 mem16_base
[i
] = pattern16
++;
83 for (i
= 0; i
< (len
>> 1); i
++) {
84 if (mem16_base
[i
] != pattern16
++)
88 /* verify pattern 4 (0x00~0xffffffff) */
90 for (i
= 0; i
< (len
>> 2); i
++)
91 mem32_base
[i
] = pattern32
++;
93 for (i
= 0; i
< (len
>> 2); i
++) {
94 if (mem32_base
[i
] != pattern32
++)
98 /* pattern 5: filling memory range with 0x12345678 */
99 for (i
= 0; i
< size
; i
++)
100 mem32_base
[i
] = PATTERNE
;
102 /* read check then fill memory with a5a5a5a5 pattern */
103 for (i
= 0; i
< size
; i
++) {
104 if (mem32_base
[i
] != PATTERNE
)
107 mem32_base
[i
] = PATTERN2
;
110 /* read check then fill memory with 00 byte pattern at offset 0h */
111 for (i
= 0; i
< size
; i
++) {
112 if (mem32_base
[i
] != PATTERN2
)
115 mem8_base
[i
* 4] = PATTERN0
;
118 /* read check then fill memory with 00 byte pattern at offset 2h */
119 for (i
= 0; i
< size
; i
++) {
120 if (mem32_base
[i
] != PATTERN3
)
123 mem8_base
[i
* 4 + 2] = PATTERN0
;
126 /* read check then fill memory with 00 byte pattern at offset 1h */
127 for (i
= 0; i
< size
; i
++) {
128 if (mem32_base
[i
] != PATTERN4
)
131 mem8_base
[i
* 4 + 1] = PATTERN0
;
134 /* read check then fill memory with 00 byte pattern at offset 3h */
135 for (i
= 0; i
< size
; i
++) {
136 if (mem32_base
[i
] != PATTERN5
)
139 mem8_base
[i
* 4 + 3] = PATTERN0
;
142 /* read check then fill memory with ffff word pattern at offset 1h */
143 for (i
= 0; i
< size
; i
++) {
144 if (mem32_base
[i
] != PATTERN0
)
147 mem16_base
[i
* 2 + 1] = PATTERN7
;
150 /* read check then fill memory with ffff word pattern at offset 0h */
151 for (i
= 0; i
< size
; i
++) {
152 if (mem32_base
[i
] != PATTERN6
)
155 mem16_base
[i
* 2] = PATTERN7
;
159 for (i
= 0; i
< size
; i
++) {
160 if (mem32_base
[i
] != PATTERNF
)
164 /* stage 1 => write 0 */
165 for (i
= 0; i
< size
; i
++)
166 mem_base
[i
] = PATTERN1
;
168 /* stage 2 => read 0, write 0xf */
169 for (i
= 0; i
< size
; i
++) {
172 if (value
!= PATTERN1
)
175 mem_base
[i
] = PATTERN2
;
178 /* stage 3 => read 0xf, write 0 */
179 for (i
= 0; i
< size
; i
++) {
181 if (value
!= PATTERN2
)
184 mem_base
[i
] = PATTERN1
;
187 /* stage 4 => read 0, write 0xf */
188 for (i
= 0; i
< size
; i
++) {
190 if (value
!= PATTERN1
)
193 mem_base
[i
] = PATTERN2
;
196 /* stage 5 => read 0xf, write 0 */
197 for (i
= 0; i
< size
; i
++) {
199 if (value
!= PATTERN2
)
202 mem_base
[i
] = PATTERN1
;
205 /* stage 6 => read 0 */
206 for (i
= 0; i
< size
; i
++) {
208 if (value
!= PATTERN1
)
212 /* 1/2/4-byte combination test */
213 p
= (uintptr_t)mem_base
;
215 while (p
< (uintptr_t)mem_base
+ (size
<< 2)) {
216 *((unsigned char *)p
) = PATTERNB
;
218 *((unsigned char *)p
) = PATTERNA
;
220 *((unsigned short *)p
) = PATTERNC
;
222 *((unsigned int *)p
) = PATTERNE
;
224 *((unsigned short *)p
) = PATTERND
;
226 *((unsigned char *)p
) = PATTERN9
;
228 *((unsigned char *)p
) = PATTERN8
;
230 *((unsigned int *)p
) = PATTERNE
;
232 *((unsigned char *)p
) = PATTERNB
;
234 *((unsigned char *)p
) = PATTERNA
;
236 *((unsigned short *)p
) = PATTERNC
;
238 *((unsigned int *)p
) = PATTERNE
;
240 *((unsigned short *)p
) = PATTERND
;
242 *((unsigned char *)p
) = PATTERN9
;
244 *((unsigned char *)p
) = PATTERN8
;
246 *((unsigned int *)p
) = PATTERNE
;
250 for (i
= 0; i
< size
; i
++) {
252 if (value
!= PATTERNE
)
256 /* verify pattern 1 (0x00~0xff) */
258 mem8_base
[0] = pattern8
;
259 for (i
= 0; i
< size
* 4; i
++) {
260 unsigned char waddr8
, raddr8
;
264 if (i
< size
* 4 - 1)
265 mem8_base
[waddr8
] = pattern8
+ 1;
266 if (mem8_base
[raddr8
] != pattern8
)
272 /* verify pattern 2 (0x00~0xffff) */
273 pattern16
= PATTERN0
;
274 mem16_base
[0] = pattern16
;
275 for (i
= 0; i
< size
* 2; i
++) {
276 if (i
< size
* 2 - 1)
277 mem16_base
[i
+ 1] = pattern16
+ 1;
278 if (mem16_base
[i
] != pattern16
)
284 /* verify pattern 3 (0x00~0xffffffff) */
285 pattern32
= PATTERN0
;
286 mem32_base
[0] = pattern32
;
287 for (i
= 0; i
< size
; i
++) {
289 mem32_base
[i
+ 1] = pattern32
+ 1;
290 if (mem32_base
[i
] != pattern32
)