test_burst.c 5.9 KB

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