3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * The test exercises SDRAM accesses in burst mode
31 #include <asm/processor.h>
36 #include "test_burst.h"
38 /* 8 MB test region of physical RAM */
39 #define TEST_PADDR 0x00800000
40 /* The uncached virtual region */
41 #define TEST_VADDR_NC 0x00800000
42 /* The cached virtual region */
43 #define TEST_VADDR_C 0x01000000
44 /* When an error is detected, the address where the error has been found,
45 and also the current and the expected data will be written to
46 the following flash address
48 #define TEST_FLASH_ADDR 0x40100000
50 /* Define GPIO ports to signal start of burst transfers and errors */
52 /* Use PD.8 to signal start of burst transfers */
53 #define GPIO1_DAT (((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pddat)
54 #define GPIO1_BIT 0x0080
55 /* Configure PD.8 as general purpose output */
57 ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pdpar &= ~GPIO1_BIT; \
58 ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pddir |= GPIO1_BIT;
59 /* Use PD.9 to signal error */
60 #define GPIO2_DAT (((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pddat)
61 #define GPIO2_BIT 0x0040
62 /* Configure PD.9 as general purpose output */
64 ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pdpar &= ~GPIO2_BIT; \
65 ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pddir |= GPIO2_BIT;
66 #endif /* CONFIG_LWMON */
69 static void test_prepare (void);
70 static int test_burst_start (unsigned long size, unsigned long pattern);
71 static void test_map_8M (unsigned long paddr, unsigned long vaddr, int cached);
72 static int test_mmu_is_on(void);
73 static void test_desc(unsigned long size);
74 static void test_error(char * step, volatile void * addr, unsigned long val, unsigned long pattern);
75 static void signal_init(void);
76 static void signal_start(void);
77 static void signal_error(void);
78 static void test_usage(void);
80 static unsigned long test_pattern [] = {
88 int test_burst (int argc, char *argv[])
90 unsigned long size = CACHE_LINE_SIZE;
96 for (size = 0, d = argv[1]; *d >= '0' && *d <= '9'; d++) {
100 if (size == 0 || *d) {
104 } else if (argc > 2) {
109 size += (CACHE_LINE_SIZE - 1);
110 size &= ~(CACHE_LINE_SIZE - 1);
112 if (!test_mmu_is_on()) {
118 for (i = 0; i < sizeof(test_pattern) / sizeof(test_pattern[0]); i++) {
119 res = test_burst_start(size, test_pattern[i]);
128 static void test_prepare (void)
133 disable_interrupts();
136 printf ("Interrupts are disabled\n");
137 printf ("I-Cache is ON\n");
138 printf ("D-Cache is ON\n");
139 printf ("MMU is ON\n");
143 test_map_8M (TEST_PADDR, TEST_VADDR_NC, 0);
144 test_map_8M (TEST_PADDR, TEST_VADDR_C, 1);
146 test_map_8M (TEST_FLASH_ADDR & 0xFF800000, TEST_FLASH_ADDR & 0xFF800000, 0);
148 /* Configure GPIO ports */
152 static int test_burst_start (unsigned long size, unsigned long pattern)
154 volatile unsigned long * vaddr_c = (unsigned long *)TEST_VADDR_C;
155 volatile unsigned long * vaddr_nc = (unsigned long *)TEST_VADDR_NC;
159 printf ("Test pattern %08x ...", pattern);
163 for (i = 0; i < n; i ++) {
164 vaddr_c [i] = pattern;
167 flush_dcache_range((unsigned long)vaddr_c, (unsigned long)(vaddr_c + n) - 1);
169 for (i = 0; i < n; i ++) {
170 register unsigned long tmp = vaddr_nc [i];
171 if (tmp != pattern) {
172 test_error("2a", vaddr_nc + i, tmp, pattern);
177 for (i = 0; i < n; i ++) {
178 register unsigned long tmp = vaddr_c [i];
179 if (tmp != pattern) {
180 test_error("2b", vaddr_c + i, tmp, pattern);
185 for (i = 0; i < n; i ++) {
186 vaddr_nc [i] = pattern;
189 for (i = 0; i < n; i ++) {
190 register unsigned long tmp = vaddr_nc [i];
191 if (tmp != pattern) {
192 test_error("3a", vaddr_nc + i, tmp, pattern);
198 for (i = 0; i < n; i ++) {
199 register unsigned long tmp = vaddr_c [i];
200 if (tmp != pattern) {
201 test_error("3b", vaddr_c + i, tmp, pattern);
208 printf(" %s\n", res == 0 ? "OK" : "");
213 static void test_map_8M (unsigned long paddr, unsigned long vaddr, int cached)
215 mtspr (MD_EPN, (vaddr & 0xFFFFFC00) | MI_EVALID);
216 mtspr (MD_TWC, MI_PS8MEG | MI_SVALID);
217 mtspr (MD_RPN, (paddr & 0xFFFFF000) | MI_BOOTINIT | (cached ? 0 : 2));
218 mtspr (MD_AP, MI_Kp);
221 static int test_mmu_is_on(void)
225 asm volatile("mfmsr %0" : "=r" (msr) :);
230 static void test_desc(unsigned long size)
233 "The following tests will be conducted:\n"
234 "1) Map %d-byte region of physical RAM at 0x%08x\n"
235 " into two virtual regions:\n"
236 " one cached at 0x%08x and\n"
237 " the the other uncached at 0x%08x.\n",
238 size, TEST_PADDR, TEST_VADDR_NC, TEST_VADDR_C);
241 "2) Fill the cached region with a pattern, and flush the cache\n"
242 "2a) Check the uncached region to match the pattern\n"
243 "2b) Check the cached region to match the pattern\n"
244 "3) Fill the uncached region with a pattern\n"
245 "3a) Check the cached region to match the pattern\n"
246 "3b) Check the uncached region to match the pattern\n"
247 "2b) Change the patterns and go to step 2\n"
252 static void test_error(
253 char * step, volatile void * addr, unsigned long val, unsigned long pattern)
255 volatile unsigned long * p = (void *)TEST_FLASH_ADDR;
259 p[0] = (unsigned long)addr;
263 printf ("\nError at step %s, addr %08x: read %08x, pattern %08x",
264 step, addr, val, pattern);
267 static void signal_init(void)
269 #if defined(GPIO1_INIT)
272 #if defined(GPIO2_INIT)
277 static void signal_start(void)
279 #if defined(GPIO1_INIT)
280 if (GPIO1_DAT & GPIO1_BIT) {
281 GPIO1_DAT &= ~GPIO1_BIT;
283 GPIO1_DAT |= GPIO1_BIT;
288 static void signal_error(void)
290 #if defined(GPIO2_INIT)
291 if (GPIO2_DAT & GPIO2_BIT) {
292 GPIO2_DAT &= ~GPIO2_BIT;
294 GPIO2_DAT |= GPIO2_BIT;
299 static void test_usage(void)
301 printf("Usage: go 0x40004 [size]\n");