denali_ecc.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * (C) Copyright 2007
  3. * Developed for DENX Software Engineering GmbH.
  4. *
  5. * Author: Pavel Kolesnikov <concord@emcraft.com>
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. /* define DEBUG for debugging output (obviously ;-)) */
  26. #if 0
  27. #define DEBUG
  28. #endif
  29. #include <common.h>
  30. #include <watchdog.h>
  31. #if defined(CONFIG_POST) && (defined(CONFIG_440EPX) || defined(CONFIG_440GRX))
  32. #include <post.h>
  33. #if CONFIG_POST & CFG_POST_ECC
  34. /*
  35. * MEMORY ECC test
  36. *
  37. * This test performs the checks ECC facility of memory.
  38. */
  39. #include <asm/processor.h>
  40. #include <asm/mmu.h>
  41. #include <asm/io.h>
  42. #include <ppc440.h>
  43. DECLARE_GLOBAL_DATA_PTR;
  44. const static unsigned char syndrome_codes[] = {
  45. 0xF4, 0XF1, 0XEC ,0XEA, 0XE9, 0XE6, 0XE5, 0XE3,
  46. 0XDC, 0XDA, 0XD9, 0XD6, 0XD5, 0XD3, 0XCE, 0XCB,
  47. 0xB5, 0XB0, 0XAD, 0XAB, 0XA8, 0XA7, 0XA4, 0XA2,
  48. 0X9D, 0X9B, 0X98, 0X97, 0X94, 0X92, 0X8F, 0X8A,
  49. 0x75, 0x70, 0X6D, 0X6B, 0X68, 0X67, 0X64, 0X62,
  50. 0X5E, 0X5B, 0X58, 0X57, 0X54, 0X52, 0X4F, 0X4A,
  51. 0x34, 0x31, 0X2C, 0X2A, 0X29, 0X26, 0X25, 0X23,
  52. 0X1C, 0X1A, 0X19, 0X16, 0X15, 0X13, 0X0E, 0X0B,
  53. 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
  54. };
  55. #define ECC_START_ADDR 0x10
  56. #define ECC_STOP_ADDR 0x2000
  57. #define ECC_PATTERN 0x01010101
  58. #define ECC_PATTERN_CORR 0x11010101
  59. #define ECC_PATTERN_UNCORR 0xF1010101
  60. static int test_ecc_error(void)
  61. {
  62. unsigned long value;
  63. unsigned long hdata, ldata, haddr, laddr;
  64. unsigned int bit;
  65. int ret = 0;
  66. mfsdram(DDR0_23, value);
  67. for (bit = 0; bit < sizeof(syndrome_codes); bit++)
  68. if (syndrome_codes[bit] == ((value >> 16) & 0xff))
  69. break;
  70. mfsdram(DDR0_00, value);
  71. if (value & DDR0_00_INT_STATUS_BIT0) {
  72. debug("Bit0. A single access outside the defined PHYSICAL"
  73. " memory space detected\n");
  74. mfsdram(DDR0_32, laddr);
  75. mfsdram(DDR0_33, haddr);
  76. debug(" addr = 0x%08x%08x\n", haddr, laddr);
  77. ret = 1;
  78. }
  79. if (value & DDR0_00_INT_STATUS_BIT1) {
  80. debug("Bit1. Multiple accesses outside the defined PHYSICAL"
  81. " memory space detected\n");
  82. ret = 2;
  83. }
  84. if (value & DDR0_00_INT_STATUS_BIT2) {
  85. debug("Bit2. Single correctable ECC event detected\n");
  86. mfsdram(DDR0_38, laddr);
  87. mfsdram(DDR0_39, haddr);
  88. mfsdram(DDR0_40, ldata);
  89. mfsdram(DDR0_41, hdata);
  90. debug(" 0x%08x - 0x%08x%08x, bit - %d\n",
  91. laddr, hdata, ldata, bit);
  92. ret = 3;
  93. }
  94. if (value & DDR0_00_INT_STATUS_BIT3) {
  95. debug("Bit3. Multiple correctable ECC events detected\n");
  96. mfsdram(DDR0_38, laddr);
  97. mfsdram(DDR0_39, haddr);
  98. mfsdram(DDR0_40, ldata);
  99. mfsdram(DDR0_41, hdata);
  100. debug(" 0x%08x - 0x%08x%08x, bit - %d\n",
  101. laddr, hdata, ldata, bit);
  102. ret = 4;
  103. }
  104. if (value & DDR0_00_INT_STATUS_BIT4) {
  105. debug("Bit4. Single uncorrectable ECC event detected\n");
  106. mfsdram(DDR0_34, laddr);
  107. mfsdram(DDR0_35, haddr);
  108. mfsdram(DDR0_36, ldata);
  109. mfsdram(DDR0_37, hdata);
  110. debug(" 0x%08x - 0x%08x%08x, bit - %d\n",
  111. laddr, hdata, ldata, bit);
  112. ret = 5;
  113. }
  114. if (value & DDR0_00_INT_STATUS_BIT5) {
  115. debug("Bit5. Multiple uncorrectable ECC events detected\n");
  116. mfsdram(DDR0_34, laddr);
  117. mfsdram(DDR0_35, haddr);
  118. mfsdram(DDR0_36, ldata);
  119. mfsdram(DDR0_37, hdata);
  120. debug(" 0x%08x - 0x%08x%08x, bit - %d\n",
  121. laddr, hdata, ldata, bit);
  122. ret = 6;
  123. }
  124. if (value & DDR0_00_INT_STATUS_BIT6) {
  125. debug("Bit6. DRAM initialization complete\n");
  126. ret = 7;
  127. }
  128. /* error status cleared */
  129. mfsdram(DDR0_00, value);
  130. mtsdram(DDR0_00, value | DDR0_00_INT_ACK_ALL);
  131. return ret;
  132. }
  133. static int test_ecc(unsigned long ecc_addr)
  134. {
  135. unsigned long value;
  136. volatile unsigned *const ecc_mem = (volatile unsigned *) ecc_addr;
  137. int pret;
  138. int ret = 0;
  139. sync();
  140. eieio();
  141. WATCHDOG_RESET();
  142. debug("Entering test_ecc(0x%08lX)\n", ecc_addr);
  143. out_be32(ecc_mem, ECC_PATTERN);
  144. out_be32(ecc_mem + 1, ECC_PATTERN);
  145. in_be32(ecc_mem);
  146. pret = test_ecc_error();
  147. if (pret != 0) {
  148. debug("pret: expected 0, got %d\n", pret);
  149. ret = 1;
  150. }
  151. /* test for correctable error */
  152. /* disconnect from ecc storage */
  153. mfsdram(DDR0_22, value);
  154. mtsdram(DDR0_22, (value &~ DDR0_22_CTRL_RAW_MASK)
  155. | DDR0_22_CTRL_RAW_ECC_DISABLE);
  156. /* creating (correctable) single-bit error */
  157. out_be32(ecc_mem, ECC_PATTERN_CORR);
  158. /* enable ecc */
  159. mfsdram(DDR0_22, value);
  160. mtsdram(DDR0_22, (value &~ DDR0_22_CTRL_RAW_MASK)
  161. | DDR0_22_CTRL_RAW_ECC_ENABLE);
  162. sync();
  163. eieio();
  164. in_be32(ecc_mem);
  165. pret = test_ecc_error();
  166. /* if read data ok, 1 correctable error must be fixed */
  167. if (pret != 3) {
  168. debug("pret: expected 3, got %d\n", pret);
  169. ret = 1;
  170. }
  171. /* test for uncorrectable error */
  172. /* disconnect from ecc storage */
  173. mfsdram(DDR0_22, value);
  174. mtsdram(DDR0_22, (value &~ DDR0_22_CTRL_RAW_MASK)
  175. | DDR0_22_CTRL_RAW_NO_ECC_RAM);
  176. /* creating (uncorrectable) multiple-bit error */
  177. out_be32(ecc_mem, ECC_PATTERN_UNCORR);
  178. /* enable ecc */
  179. mfsdram(DDR0_22, value);
  180. mtsdram(DDR0_22, (value &~ DDR0_22_CTRL_RAW_MASK)
  181. | DDR0_22_CTRL_RAW_ECC_ENABLE);
  182. sync();
  183. eieio();
  184. in_be32(ecc_mem);
  185. pret = test_ecc_error();
  186. /* info about uncorrectable error must appear */
  187. if (pret != 5) {
  188. debug("pret: expected 5, got %d\n", pret);
  189. ret = 1;
  190. }
  191. /* remove error from SDRAM */
  192. out_be32(ecc_mem, ECC_PATTERN);
  193. /* clear error caused by read-modify-write */
  194. mfsdram(DDR0_00, value);
  195. mtsdram(DDR0_00, value | DDR0_00_INT_ACK_ALL);
  196. sync();
  197. eieio();
  198. return ret;
  199. }
  200. int ecc_post_test (int flags)
  201. {
  202. int ret = 0;
  203. unsigned long value;
  204. unsigned long iaddr;
  205. sync();
  206. eieio();
  207. mfsdram(DDR0_22, value);
  208. if (0x3 != DDR0_22_CTRL_RAW_DECODE(value)) {
  209. debug("SDRAM ECC not enabled, skipping ECC POST.\n");
  210. return 0;
  211. }
  212. /* mask all int */
  213. mfsdram(DDR0_01, value);
  214. mtsdram(DDR0_01, (value &~ DDR0_01_INT_MASK_MASK)
  215. | DDR0_01_INT_MASK_ALL_OFF);
  216. /* clear error status */
  217. mfsdram(DDR0_00, value);
  218. mtsdram(DDR0_00, value | DDR0_00_INT_ACK_ALL);
  219. for (iaddr = ECC_START_ADDR; iaddr <= ECC_STOP_ADDR; iaddr += iaddr) {
  220. ret = test_ecc(iaddr);
  221. if (ret)
  222. break;
  223. }
  224. /*
  225. * Clear possible errors resulting from ECC testing.
  226. * If not done, then we could get an interrupt later on when
  227. * exceptions are enabled.
  228. */
  229. set_mcsr(get_mcsr());
  230. return ret;
  231. }
  232. #endif /* CONFIG_POST & CFG_POST_ECC */
  233. #endif /* defined(CONFIG_POST) && ... */