ecc.c 3.7 KB

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