blob: 4a16ffb22dc93b07fe641613874c407afcfddaf0 [file] [log] [blame]
wdenke339a7a2005-05-07 19:06:32 +00001/*
2 * (C) Copyright 2005
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenke339a7a2005-05-07 19:06:32 +00006 *
7 * The test exercises SDRAM accesses in burst mode
8 */
9
10#include <common.h>
11#include <exports.h>
12
13#include <commproc.h>
14#include <asm/mmu.h>
15#include <asm/processor.h>
16
17#include <serial.h>
18#include <watchdog.h>
19
20#include "test_burst.h"
21
22/* 8 MB test region of physical RAM */
23#define TEST_PADDR 0x00800000
24/* The uncached virtual region */
25#define TEST_VADDR_NC 0x00800000
26/* The cached virtual region */
27#define TEST_VADDR_C 0x01000000
28/* When an error is detected, the address where the error has been found,
29 and also the current and the expected data will be written to
30 the following flash address
31*/
32#define TEST_FLASH_ADDR 0x40100000
33
wdenk4e5bc872005-05-16 14:19:49 +000034/* Define GPIO ports to signal start of burst transfers and errors */
35#ifdef CONFIG_LWMON
36/* Use PD.8 to signal start of burst transfers */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020037#define GPIO1_DAT (((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat)
wdenk4e5bc872005-05-16 14:19:49 +000038#define GPIO1_BIT 0x0080
39/* Configure PD.8 as general purpose output */
40#define GPIO1_INIT \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020041 ((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar &= ~GPIO1_BIT; \
42 ((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir |= GPIO1_BIT;
wdenk4e5bc872005-05-16 14:19:49 +000043/* Use PD.9 to signal error */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044#define GPIO2_DAT (((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddat)
wdenk4e5bc872005-05-16 14:19:49 +000045#define GPIO2_BIT 0x0040
46/* Configure PD.9 as general purpose output */
47#define GPIO2_INIT \
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020048 ((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pdpar &= ~GPIO2_BIT; \
49 ((volatile immap_t *)CONFIG_SYS_IMMR)->im_ioport.iop_pddir |= GPIO2_BIT;
wdenk4e5bc872005-05-16 14:19:49 +000050#endif /* CONFIG_LWMON */
51
52
wdenke339a7a2005-05-07 19:06:32 +000053static void test_prepare (void);
54static int test_burst_start (unsigned long size, unsigned long pattern);
55static void test_map_8M (unsigned long paddr, unsigned long vaddr, int cached);
56static int test_mmu_is_on(void);
57static void test_desc(unsigned long size);
58static void test_error(char * step, volatile void * addr, unsigned long val, unsigned long pattern);
wdenk4e5bc872005-05-16 14:19:49 +000059static void signal_init(void);
wdenke339a7a2005-05-07 19:06:32 +000060static void signal_start(void);
61static void signal_error(void);
62static void test_usage(void);
63
64static unsigned long test_pattern [] = {
65 0x00000000,
66 0xffffffff,
67 0x55555555,
68 0xaaaaaaaa,
69};
70
71
Wolfgang Denk6262d0212010-06-28 22:00:46 +020072int test_burst (int argc, char * const argv[])
wdenke339a7a2005-05-07 19:06:32 +000073{
74 unsigned long size = CACHE_LINE_SIZE;
wdenkf593f462005-05-23 10:49:50 +000075 unsigned int pass = 0;
76 int res = 0;
77 int i, j;
wdenke339a7a2005-05-07 19:06:32 +000078
wdenkf593f462005-05-23 10:49:50 +000079 if (argc == 3) {
wdenke339a7a2005-05-07 19:06:32 +000080 char * d;
81 for (size = 0, d = argv[1]; *d >= '0' && *d <= '9'; d++) {
82 size *= 10;
83 size += *d - '0';
84 }
85 if (size == 0 || *d) {
86 test_usage();
87 return 1;
88 }
wdenkf593f462005-05-23 10:49:50 +000089 for (d = argv[2]; *d >= '0' && *d <= '9'; d++) {
90 pass *= 10;
91 pass += *d - '0';
92 }
93 if (*d) {
94 test_usage();
95 return 1;
96 }
97 } else if (argc > 3) {
wdenke339a7a2005-05-07 19:06:32 +000098 test_usage();
99 return 1;
100 }
101
102 size += (CACHE_LINE_SIZE - 1);
103 size &= ~(CACHE_LINE_SIZE - 1);
104
105 if (!test_mmu_is_on()) {
106 test_prepare();
107 }
108
109 test_desc(size);
110
wdenkf593f462005-05-23 10:49:50 +0000111 for (j = 0; !pass || j < pass; j++) {
112 for (i = 0; i < sizeof(test_pattern) / sizeof(test_pattern[0]);
113 i++) {
114 res = test_burst_start(size, test_pattern[i]);
115 if (res != 0) {
116 goto Done;
117 }
wdenke339a7a2005-05-07 19:06:32 +0000118 }
wdenkf593f462005-05-23 10:49:50 +0000119
120 printf ("Iteration #%d passed\n", j + 1);
121
122 if (tstc() && 0x03 == getc())
123 break;
wdenke339a7a2005-05-07 19:06:32 +0000124 }
125Done:
126 return res;
127}
128
129static void test_prepare (void)
130{
wdenke339a7a2005-05-07 19:06:32 +0000131 printf ("\n");
132
133 caches_init();
134 disable_interrupts();
135 mmu_init();
136
137 printf ("Interrupts are disabled\n");
138 printf ("I-Cache is ON\n");
139 printf ("D-Cache is ON\n");
140 printf ("MMU is ON\n");
141
142 printf ("\n");
143
144 test_map_8M (TEST_PADDR, TEST_VADDR_NC, 0);
145 test_map_8M (TEST_PADDR, TEST_VADDR_C, 1);
146
147 test_map_8M (TEST_FLASH_ADDR & 0xFF800000, TEST_FLASH_ADDR & 0xFF800000, 0);
148
wdenk4e5bc872005-05-16 14:19:49 +0000149 /* Configure GPIO ports */
150 signal_init();
wdenke339a7a2005-05-07 19:06:32 +0000151}
152
153static int test_burst_start (unsigned long size, unsigned long pattern)
154{
155 volatile unsigned long * vaddr_c = (unsigned long *)TEST_VADDR_C;
156 volatile unsigned long * vaddr_nc = (unsigned long *)TEST_VADDR_NC;
157 int i, n;
158 int res = 1;
159
Wolfgang Denk8d541882008-07-10 13:16:09 +0200160 printf ("Test pattern %08lx ...", pattern);
wdenke339a7a2005-05-07 19:06:32 +0000161
162 n = size / 4;
163
164 for (i = 0; i < n; i ++) {
165 vaddr_c [i] = pattern;
166 }
167 signal_start();
168 flush_dcache_range((unsigned long)vaddr_c, (unsigned long)(vaddr_c + n) - 1);
169
170 for (i = 0; i < n; i ++) {
171 register unsigned long tmp = vaddr_nc [i];
172 if (tmp != pattern) {
173 test_error("2a", vaddr_nc + i, tmp, pattern);
174 goto Done;
175 }
176 }
177
178 for (i = 0; i < n; i ++) {
179 register unsigned long tmp = vaddr_c [i];
180 if (tmp != pattern) {
181 test_error("2b", vaddr_c + i, tmp, pattern);
182 goto Done;
183 }
184 }
185
186 for (i = 0; i < n; i ++) {
187 vaddr_nc [i] = pattern;
188 }
189
190 for (i = 0; i < n; i ++) {
191 register unsigned long tmp = vaddr_nc [i];
192 if (tmp != pattern) {
193 test_error("3a", vaddr_nc + i, tmp, pattern);
194 goto Done;
195 }
196 }
197
198 signal_start();
199 for (i = 0; i < n; i ++) {
200 register unsigned long tmp = vaddr_c [i];
201 if (tmp != pattern) {
202 test_error("3b", vaddr_c + i, tmp, pattern);
203 goto Done;
204 }
205 }
206
207 res = 0;
208Done:
209 printf(" %s\n", res == 0 ? "OK" : "");
210
211 return res;
212}
213
214static void test_map_8M (unsigned long paddr, unsigned long vaddr, int cached)
215{
216 mtspr (MD_EPN, (vaddr & 0xFFFFFC00) | MI_EVALID);
217 mtspr (MD_TWC, MI_PS8MEG | MI_SVALID);
218 mtspr (MD_RPN, (paddr & 0xFFFFF000) | MI_BOOTINIT | (cached ? 0 : 2));
219 mtspr (MD_AP, MI_Kp);
220}
221
222static int test_mmu_is_on(void)
223{
224 unsigned long msr;
225
226 asm volatile("mfmsr %0" : "=r" (msr) :);
227
228 return msr & MSR_DR;
229}
230
231static void test_desc(unsigned long size)
232{
233 printf(
234 "The following tests will be conducted:\n"
Wolfgang Denk8d541882008-07-10 13:16:09 +0200235 "1) Map %ld-byte region of physical RAM at 0x%08x\n"
wdenke339a7a2005-05-07 19:06:32 +0000236 " into two virtual regions:\n"
237 " one cached at 0x%08x and\n"
238 " the the other uncached at 0x%08x.\n",
239 size, TEST_PADDR, TEST_VADDR_NC, TEST_VADDR_C);
240
241 puts(
242 "2) Fill the cached region with a pattern, and flush the cache\n"
243 "2a) Check the uncached region to match the pattern\n"
244 "2b) Check the cached region to match the pattern\n"
245 "3) Fill the uncached region with a pattern\n"
246 "3a) Check the cached region to match the pattern\n"
247 "3b) Check the uncached region to match the pattern\n"
248 "2b) Change the patterns and go to step 2\n"
249 "\n"
250 );
251}
252
253static void test_error(
254 char * step, volatile void * addr, unsigned long val, unsigned long pattern)
255{
256 volatile unsigned long * p = (void *)TEST_FLASH_ADDR;
257
258 signal_error();
259
260 p[0] = (unsigned long)addr;
261 p[1] = val;
262 p[2] = pattern;
263
Wolfgang Denk8d541882008-07-10 13:16:09 +0200264 printf ("\nError at step %s, addr %08lx: read %08lx, pattern %08lx",
Wolfgang Denk12cec0a2008-07-11 01:16:00 +0200265 step, (unsigned long)addr, val, pattern);
wdenke339a7a2005-05-07 19:06:32 +0000266}
267
wdenk4e5bc872005-05-16 14:19:49 +0000268static void signal_init(void)
wdenke339a7a2005-05-07 19:06:32 +0000269{
wdenk4e5bc872005-05-16 14:19:49 +0000270#if defined(GPIO1_INIT)
271 GPIO1_INIT;
272#endif
273#if defined(GPIO2_INIT)
274 GPIO2_INIT;
275#endif
276}
wdenke339a7a2005-05-07 19:06:32 +0000277
wdenk4e5bc872005-05-16 14:19:49 +0000278static void signal_start(void)
279{
280#if defined(GPIO1_INIT)
281 if (GPIO1_DAT & GPIO1_BIT) {
282 GPIO1_DAT &= ~GPIO1_BIT;
wdenke339a7a2005-05-07 19:06:32 +0000283 } else {
wdenk4e5bc872005-05-16 14:19:49 +0000284 GPIO1_DAT |= GPIO1_BIT;
wdenke339a7a2005-05-07 19:06:32 +0000285 }
wdenk4e5bc872005-05-16 14:19:49 +0000286#endif
wdenke339a7a2005-05-07 19:06:32 +0000287}
288
289static void signal_error(void)
290{
wdenk4e5bc872005-05-16 14:19:49 +0000291#if defined(GPIO2_INIT)
292 if (GPIO2_DAT & GPIO2_BIT) {
293 GPIO2_DAT &= ~GPIO2_BIT;
wdenke339a7a2005-05-07 19:06:32 +0000294 } else {
wdenk4e5bc872005-05-16 14:19:49 +0000295 GPIO2_DAT |= GPIO2_BIT;
wdenke339a7a2005-05-07 19:06:32 +0000296 }
wdenk4e5bc872005-05-16 14:19:49 +0000297#endif
wdenke339a7a2005-05-07 19:06:32 +0000298}
299
300static void test_usage(void)
301{
wdenkf593f462005-05-23 10:49:50 +0000302 printf("Usage: go 0x40004 [size] [count]\n");
wdenke339a7a2005-05-07 19:06:32 +0000303}