ecc.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * (C) Copyright 2010
  3. * Eastman Kodak Company, <www.kodak.com>
  4. * Michael Zaidman, <michael.zaidman@kodak.com>
  5. *
  6. * The code is based on the cpu/mpc83xx/ecc.c written by
  7. * Dave Liu <daveliu@freescale.com>
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <mpc83xx.h>
  29. #include <watchdog.h>
  30. #include <asm/io.h>
  31. #include <post.h>
  32. #if CONFIG_POST & CONFIG_SYS_POST_ECC
  33. /*
  34. * We use the RAW I/O accessors where possible in order to
  35. * achieve performance goal, since the test's execution time
  36. * affects the board start up time.
  37. */
  38. static inline void ecc_clear(ddr83xx_t *ddr)
  39. {
  40. /* Clear capture registers */
  41. __raw_writel(0, &ddr->capture_address);
  42. __raw_writel(0, &ddr->capture_data_hi);
  43. __raw_writel(0, &ddr->capture_data_lo);
  44. __raw_writel(0, &ddr->capture_ecc);
  45. __raw_writel(0, &ddr->capture_attributes);
  46. /* Clear SBEC and set SBET to 1 */
  47. out_be32(&ddr->err_sbe, 1 << ECC_ERROR_MAN_SBET_SHIFT);
  48. /* Clear Error Detect register */
  49. out_be32(&ddr->err_detect, ECC_ERROR_DETECT_MME |\
  50. ECC_ERROR_DETECT_MBE |\
  51. ECC_ERROR_DETECT_SBE |\
  52. ECC_ERROR_DETECT_MSE);
  53. isync();
  54. }
  55. int ecc_post_test(int flags)
  56. {
  57. int ret = 0;
  58. int int_state;
  59. int errbit;
  60. u32 pattern[2], writeback[2], retval[2];
  61. ddr83xx_t *ddr = &((immap_t *)CONFIG_SYS_IMMR)->ddr;
  62. volatile u64 *addr = (u64 *)CONFIG_SYS_POST_ECC_START_ADDR;
  63. /* The pattern is written into memory to generate error */
  64. pattern[0] = 0xfedcba98UL;
  65. pattern[1] = 0x76543210UL;
  66. /* After injecting error, re-initialize the memory with the value */
  67. writeback[0] = ~pattern[0];
  68. writeback[1] = ~pattern[1];
  69. /* Check if ECC is enabled */
  70. if (__raw_readl(&ddr->err_disable) & ECC_ERROR_ENABLE) {
  71. debug("DDR's ECC is not enabled, skipping the ECC POST.\n");
  72. return 0;
  73. }
  74. int_state = disable_interrupts();
  75. icache_enable();
  76. #ifdef CONFIG_DDR_32BIT
  77. /* It seems like no one really uses the CONFIG_DDR_32BIT mode */
  78. #error "Add ECC POST support for CONFIG_DDR_32BIT here!"
  79. #else
  80. for (addr = (u64*)CONFIG_SYS_POST_ECC_START_ADDR, errbit=0;
  81. addr < (u64*)CONFIG_SYS_POST_ECC_STOP_ADDR; addr++, errbit++ ) {
  82. WATCHDOG_RESET();
  83. ecc_clear(ddr);
  84. /* Enable error injection */
  85. setbits_be32(&ddr->ecc_err_inject, ECC_ERR_INJECT_EIEN);
  86. sync();
  87. isync();
  88. /* Set bit to be injected */
  89. if (errbit < 32) {
  90. __raw_writel(1 << errbit, &ddr->data_err_inject_lo);
  91. __raw_writel(0, &ddr->data_err_inject_hi);
  92. } else {
  93. __raw_writel(0, &ddr->data_err_inject_lo);
  94. __raw_writel(1<<(errbit-32), &ddr->data_err_inject_hi);
  95. }
  96. sync();
  97. isync();
  98. /* Write memory location injecting SBE */
  99. ppcDWstore((u32*)addr, pattern);
  100. sync();
  101. /* Disable error injection */
  102. clrbits_be32(&ddr->ecc_err_inject, ECC_ERR_INJECT_EIEN);
  103. sync();
  104. isync();
  105. /* Data read should generate SBE */
  106. ppcDWload((u32*)addr, retval);
  107. sync();
  108. if (!(__raw_readl(&ddr->err_detect) & ECC_ERROR_DETECT_SBE) ||
  109. (__raw_readl(&ddr->data_err_inject_hi) !=
  110. (__raw_readl(&ddr->capture_data_hi) ^ pattern[0])) ||
  111. (__raw_readl(&ddr->data_err_inject_lo) !=
  112. (__raw_readl(&ddr->capture_data_lo) ^ pattern[1]))) {
  113. post_log("ECC failed to detect SBE error at %08x, "
  114. "SBE injection mask %08x-%08x, wrote "
  115. "%08x-%08x, read %08x-%08x\n", addr,
  116. ddr->data_err_inject_hi,
  117. ddr->data_err_inject_lo,
  118. pattern[0], pattern[1],
  119. retval[0], retval[1]);
  120. printf("ERR_DETECT Reg: %08x\n", ddr->err_detect);
  121. printf("ECC CAPTURE_DATA Reg: %08x-%08x\n",
  122. ddr->capture_data_hi, ddr->capture_data_lo);
  123. ret = 1;
  124. break;
  125. }
  126. /* Re-initialize the ECC memory */
  127. ppcDWstore((u32*)addr, writeback);
  128. sync();
  129. isync();
  130. errbit %= 63;
  131. }
  132. #endif /* !CONFIG_DDR_32BIT */
  133. ecc_clear(ddr);
  134. icache_disable();
  135. if (int_state)
  136. enable_interrupts();
  137. return ret;
  138. }
  139. #endif