test_burst.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * (C) Copyright 2005
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  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.
  12. *
  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.
  17. *
  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,
  21. * MA 02111-1307 USA
  22. *
  23. * The test exercises SDRAM accesses in burst mode
  24. */
  25. #include <common.h>
  26. #include <exports.h>
  27. #include <commproc.h>
  28. #include <asm/mmu.h>
  29. #include <asm/processor.h>
  30. #include <serial.h>
  31. #include <watchdog.h>
  32. #include "test_burst.h"
  33. /* 8 MB test region of physical RAM */
  34. #define TEST_PADDR 0x00800000
  35. /* The uncached virtual region */
  36. #define TEST_VADDR_NC 0x00800000
  37. /* The cached virtual region */
  38. #define TEST_VADDR_C 0x01000000
  39. /* When an error is detected, the address where the error has been found,
  40. and also the current and the expected data will be written to
  41. the following flash address
  42. */
  43. #define TEST_FLASH_ADDR 0x40100000
  44. /* Define GPIO ports to signal start of burst transfers and errors */
  45. #ifdef CONFIG_LWMON
  46. /* Use PD.8 to signal start of burst transfers */
  47. #define GPIO1_DAT (((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pddat)
  48. #define GPIO1_BIT 0x0080
  49. /* Configure PD.8 as general purpose output */
  50. #define GPIO1_INIT \
  51. ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pdpar &= ~GPIO1_BIT; \
  52. ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pddir |= GPIO1_BIT;
  53. /* Use PD.9 to signal error */
  54. #define GPIO2_DAT (((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pddat)
  55. #define GPIO2_BIT 0x0040
  56. /* Configure PD.9 as general purpose output */
  57. #define GPIO2_INIT \
  58. ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pdpar &= ~GPIO2_BIT; \
  59. ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pddir |= GPIO2_BIT;
  60. #endif /* CONFIG_LWMON */
  61. static void test_prepare (void);
  62. static int test_burst_start (unsigned long size, unsigned long pattern);
  63. static void test_map_8M (unsigned long paddr, unsigned long vaddr, int cached);
  64. static int test_mmu_is_on(void);
  65. static void test_desc(unsigned long size);
  66. static void test_error(char * step, volatile void * addr, unsigned long val, unsigned long pattern);
  67. static void signal_init(void);
  68. static void signal_start(void);
  69. static void signal_error(void);
  70. static void test_usage(void);
  71. static unsigned long test_pattern [] = {
  72. 0x00000000,
  73. 0xffffffff,
  74. 0x55555555,
  75. 0xaaaaaaaa,
  76. };
  77. int test_burst (int argc, char *argv[])
  78. {
  79. unsigned long size = CACHE_LINE_SIZE;
  80. unsigned int pass = 0;
  81. int res = 0;
  82. int i, j;
  83. if (argc == 3) {
  84. char * d;
  85. for (size = 0, d = argv[1]; *d >= '0' && *d <= '9'; d++) {
  86. size *= 10;
  87. size += *d - '0';
  88. }
  89. if (size == 0 || *d) {
  90. test_usage();
  91. return 1;
  92. }
  93. for (d = argv[2]; *d >= '0' && *d <= '9'; d++) {
  94. pass *= 10;
  95. pass += *d - '0';
  96. }
  97. if (*d) {
  98. test_usage();
  99. return 1;
  100. }
  101. } else if (argc > 3) {
  102. test_usage();
  103. return 1;
  104. }
  105. size += (CACHE_LINE_SIZE - 1);
  106. size &= ~(CACHE_LINE_SIZE - 1);
  107. if (!test_mmu_is_on()) {
  108. test_prepare();
  109. }
  110. test_desc(size);
  111. 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. }
  118. }
  119. printf ("Iteration #%d passed\n", j + 1);
  120. if (tstc() && 0x03 == getc())
  121. break;
  122. }
  123. Done:
  124. return res;
  125. }
  126. static void test_prepare (void)
  127. {
  128. printf ("\n");
  129. caches_init();
  130. disable_interrupts();
  131. mmu_init();
  132. printf ("Interrupts are disabled\n");
  133. printf ("I-Cache is ON\n");
  134. printf ("D-Cache is ON\n");
  135. printf ("MMU is ON\n");
  136. printf ("\n");
  137. test_map_8M (TEST_PADDR, TEST_VADDR_NC, 0);
  138. test_map_8M (TEST_PADDR, TEST_VADDR_C, 1);
  139. test_map_8M (TEST_FLASH_ADDR & 0xFF800000, TEST_FLASH_ADDR & 0xFF800000, 0);
  140. /* Configure GPIO ports */
  141. signal_init();
  142. }
  143. static int test_burst_start (unsigned long size, unsigned long pattern)
  144. {
  145. volatile unsigned long * vaddr_c = (unsigned long *)TEST_VADDR_C;
  146. volatile unsigned long * vaddr_nc = (unsigned long *)TEST_VADDR_NC;
  147. int i, n;
  148. int res = 1;
  149. printf ("Test pattern %08x ...", pattern);
  150. n = size / 4;
  151. for (i = 0; i < n; i ++) {
  152. vaddr_c [i] = pattern;
  153. }
  154. signal_start();
  155. flush_dcache_range((unsigned long)vaddr_c, (unsigned long)(vaddr_c + n) - 1);
  156. for (i = 0; i < n; i ++) {
  157. register unsigned long tmp = vaddr_nc [i];
  158. if (tmp != pattern) {
  159. test_error("2a", vaddr_nc + i, tmp, pattern);
  160. goto Done;
  161. }
  162. }
  163. for (i = 0; i < n; i ++) {
  164. register unsigned long tmp = vaddr_c [i];
  165. if (tmp != pattern) {
  166. test_error("2b", vaddr_c + i, tmp, pattern);
  167. goto Done;
  168. }
  169. }
  170. for (i = 0; i < n; i ++) {
  171. vaddr_nc [i] = pattern;
  172. }
  173. for (i = 0; i < n; i ++) {
  174. register unsigned long tmp = vaddr_nc [i];
  175. if (tmp != pattern) {
  176. test_error("3a", vaddr_nc + i, tmp, pattern);
  177. goto Done;
  178. }
  179. }
  180. signal_start();
  181. for (i = 0; i < n; i ++) {
  182. register unsigned long tmp = vaddr_c [i];
  183. if (tmp != pattern) {
  184. test_error("3b", vaddr_c + i, tmp, pattern);
  185. goto Done;
  186. }
  187. }
  188. res = 0;
  189. Done:
  190. printf(" %s\n", res == 0 ? "OK" : "");
  191. return res;
  192. }
  193. static void test_map_8M (unsigned long paddr, unsigned long vaddr, int cached)
  194. {
  195. mtspr (MD_EPN, (vaddr & 0xFFFFFC00) | MI_EVALID);
  196. mtspr (MD_TWC, MI_PS8MEG | MI_SVALID);
  197. mtspr (MD_RPN, (paddr & 0xFFFFF000) | MI_BOOTINIT | (cached ? 0 : 2));
  198. mtspr (MD_AP, MI_Kp);
  199. }
  200. static int test_mmu_is_on(void)
  201. {
  202. unsigned long msr;
  203. asm volatile("mfmsr %0" : "=r" (msr) :);
  204. return msr & MSR_DR;
  205. }
  206. static void test_desc(unsigned long size)
  207. {
  208. printf(
  209. "The following tests will be conducted:\n"
  210. "1) Map %d-byte region of physical RAM at 0x%08x\n"
  211. " into two virtual regions:\n"
  212. " one cached at 0x%08x and\n"
  213. " the the other uncached at 0x%08x.\n",
  214. size, TEST_PADDR, TEST_VADDR_NC, TEST_VADDR_C);
  215. puts(
  216. "2) Fill the cached region with a pattern, and flush the cache\n"
  217. "2a) Check the uncached region to match the pattern\n"
  218. "2b) Check the cached region to match the pattern\n"
  219. "3) Fill the uncached region with a pattern\n"
  220. "3a) Check the cached region to match the pattern\n"
  221. "3b) Check the uncached region to match the pattern\n"
  222. "2b) Change the patterns and go to step 2\n"
  223. "\n"
  224. );
  225. }
  226. static void test_error(
  227. char * step, volatile void * addr, unsigned long val, unsigned long pattern)
  228. {
  229. volatile unsigned long * p = (void *)TEST_FLASH_ADDR;
  230. signal_error();
  231. p[0] = (unsigned long)addr;
  232. p[1] = val;
  233. p[2] = pattern;
  234. printf ("\nError at step %s, addr %08x: read %08x, pattern %08x",
  235. step, addr, val, pattern);
  236. }
  237. static void signal_init(void)
  238. {
  239. #if defined(GPIO1_INIT)
  240. GPIO1_INIT;
  241. #endif
  242. #if defined(GPIO2_INIT)
  243. GPIO2_INIT;
  244. #endif
  245. }
  246. static void signal_start(void)
  247. {
  248. #if defined(GPIO1_INIT)
  249. if (GPIO1_DAT & GPIO1_BIT) {
  250. GPIO1_DAT &= ~GPIO1_BIT;
  251. } else {
  252. GPIO1_DAT |= GPIO1_BIT;
  253. }
  254. #endif
  255. }
  256. static void signal_error(void)
  257. {
  258. #if defined(GPIO2_INIT)
  259. if (GPIO2_DAT & GPIO2_BIT) {
  260. GPIO2_DAT &= ~GPIO2_BIT;
  261. } else {
  262. GPIO2_DAT |= GPIO2_BIT;
  263. }
  264. #endif
  265. }
  266. static void test_usage(void)
  267. {
  268. printf("Usage: go 0x40004 [size] [count]\n");
  269. }