ecc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2010
  4. * Eastman Kodak Company, <www.kodak.com>
  5. * Michael Zaidman, <michael.zaidman@kodak.com>
  6. *
  7. * The code is based on the cpu/mpc83xx/ecc.c written by
  8. * Dave Liu <daveliu@freescale.com>
  9. */
  10. #include <common.h>
  11. #include <mpc83xx.h>
  12. #include <watchdog.h>
  13. #include <asm/io.h>
  14. #include <post.h>
  15. #if CONFIG_POST & CONFIG_SYS_POST_ECC
  16. /*
  17. * We use the RAW I/O accessors where possible in order to
  18. * achieve performance goal, since the test's execution time
  19. * affects the board start up time.
  20. */
  21. static inline void ecc_clear(ddr83xx_t *ddr)
  22. {
  23. /* Clear capture registers */
  24. __raw_writel(0, &ddr->capture_address);
  25. __raw_writel(0, &ddr->capture_data_hi);
  26. __raw_writel(0, &ddr->capture_data_lo);
  27. __raw_writel(0, &ddr->capture_ecc);
  28. __raw_writel(0, &ddr->capture_attributes);
  29. /* Clear SBEC and set SBET to 1 */
  30. out_be32(&ddr->err_sbe, 1 << ECC_ERROR_MAN_SBET_SHIFT);
  31. /* Clear Error Detect register */
  32. out_be32(&ddr->err_detect, ECC_ERROR_DETECT_MME |\
  33. ECC_ERROR_DETECT_MBE |\
  34. ECC_ERROR_DETECT_SBE |\
  35. ECC_ERROR_DETECT_MSE);
  36. isync();
  37. }
  38. int ecc_post_test(int flags)
  39. {
  40. int ret = 0;
  41. int int_state;
  42. int errbit;
  43. u32 pattern[2], writeback[2], retval[2];
  44. ddr83xx_t *ddr = &((immap_t *)CONFIG_SYS_IMMR)->ddr;
  45. volatile u64 *addr = (u64 *)CONFIG_SYS_POST_ECC_START_ADDR;
  46. /* The pattern is written into memory to generate error */
  47. pattern[0] = 0xfedcba98UL;
  48. pattern[1] = 0x76543210UL;
  49. /* After injecting error, re-initialize the memory with the value */
  50. writeback[0] = ~pattern[0];
  51. writeback[1] = ~pattern[1];
  52. /* Check if ECC is enabled */
  53. if (__raw_readl(&ddr->err_disable) & ECC_ERROR_ENABLE) {
  54. debug("DDR's ECC is not enabled, skipping the ECC POST.\n");
  55. return 0;
  56. }
  57. int_state = disable_interrupts();
  58. icache_enable();
  59. #ifdef CONFIG_DDR_32BIT
  60. /* It seems like no one really uses the CONFIG_DDR_32BIT mode */
  61. #error "Add ECC POST support for CONFIG_DDR_32BIT here!"
  62. #else
  63. for (addr = (u64*)CONFIG_SYS_POST_ECC_START_ADDR, errbit=0;
  64. addr < (u64*)CONFIG_SYS_POST_ECC_STOP_ADDR; addr++, errbit++ ) {
  65. WATCHDOG_RESET();
  66. ecc_clear(ddr);
  67. /* Enable error injection */
  68. setbits_be32(&ddr->ecc_err_inject, ECC_ERR_INJECT_EIEN);
  69. sync();
  70. isync();
  71. /* Set bit to be injected */
  72. if (errbit < 32) {
  73. __raw_writel(1 << errbit, &ddr->data_err_inject_lo);
  74. __raw_writel(0, &ddr->data_err_inject_hi);
  75. } else {
  76. __raw_writel(0, &ddr->data_err_inject_lo);
  77. __raw_writel(1<<(errbit-32), &ddr->data_err_inject_hi);
  78. }
  79. sync();
  80. isync();
  81. /* Write memory location injecting SBE */
  82. ppcDWstore((u32*)addr, pattern);
  83. sync();
  84. /* Disable error injection */
  85. clrbits_be32(&ddr->ecc_err_inject, ECC_ERR_INJECT_EIEN);
  86. sync();
  87. isync();
  88. /* Data read should generate SBE */
  89. ppcDWload((u32*)addr, retval);
  90. sync();
  91. if (!(__raw_readl(&ddr->err_detect) & ECC_ERROR_DETECT_SBE) ||
  92. (__raw_readl(&ddr->data_err_inject_hi) !=
  93. (__raw_readl(&ddr->capture_data_hi) ^ pattern[0])) ||
  94. (__raw_readl(&ddr->data_err_inject_lo) !=
  95. (__raw_readl(&ddr->capture_data_lo) ^ pattern[1]))) {
  96. post_log("ECC failed to detect SBE error at %08x, "
  97. "SBE injection mask %08x-%08x, wrote "
  98. "%08x-%08x, read %08x-%08x\n", addr,
  99. ddr->data_err_inject_hi,
  100. ddr->data_err_inject_lo,
  101. pattern[0], pattern[1],
  102. retval[0], retval[1]);
  103. printf("ERR_DETECT Reg: %08x\n", ddr->err_detect);
  104. printf("ECC CAPTURE_DATA Reg: %08x-%08x\n",
  105. ddr->capture_data_hi, ddr->capture_data_lo);
  106. ret = 1;
  107. break;
  108. }
  109. /* Re-initialize the ECC memory */
  110. ppcDWstore((u32*)addr, writeback);
  111. sync();
  112. isync();
  113. errbit %= 63;
  114. }
  115. #endif /* !CONFIG_DDR_32BIT */
  116. ecc_clear(ddr);
  117. icache_disable();
  118. if (int_state)
  119. enable_interrupts();
  120. return ret;
  121. }
  122. #endif