cex-sb1.S 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2001,2002,2003 Broadcom Corporation
  4. */
  5. #include <asm/asm.h>
  6. #include <asm/regdef.h>
  7. #include <asm/mipsregs.h>
  8. #include <asm/stackframe.h>
  9. #include <asm/cacheops.h>
  10. #include <asm/sibyte/board.h>
  11. #define C0_ERRCTL $26 /* CP0: Error info */
  12. #define C0_CERR_I $27 /* CP0: Icache error */
  13. #define C0_CERR_D $27,1 /* CP0: Dcache error */
  14. /*
  15. * Based on SiByte sample software cache-err/cerr.S
  16. * CVS revision 1.8. Only the 'unrecoverable' case
  17. * is changed.
  18. */
  19. .set mips64
  20. .set noreorder
  21. .set noat
  22. /*
  23. * sb1_cerr_vec: code to be copied to the Cache Error
  24. * Exception vector. The code must be pushed out to memory
  25. * (either by copying to Kseg0 and Kseg1 both, or by flushing
  26. * the L1 and L2) since it is fetched as 0xa0000100.
  27. *
  28. * NOTE: Be sure this handler is at most 28 instructions long
  29. * since the final 16 bytes of the exception vector memory
  30. * (0x170-0x17f) are used to preserve k0, k1, and ra.
  31. */
  32. LEAF(except_vec2_sb1)
  33. /*
  34. * If this error is recoverable, we need to exit the handler
  35. * without having dirtied any registers. To do this,
  36. * save/restore k0 and k1 from low memory (Useg is direct
  37. * mapped while ERL=1). Note that we can't save to a
  38. * CPU-specific location without ruining a register in the
  39. * process. This means we are vulnerable to data corruption
  40. * whenever the handler is reentered by a second CPU.
  41. */
  42. sd k0,0x170($0)
  43. sd k1,0x178($0)
  44. #ifdef CONFIG_SB1_CEX_ALWAYS_FATAL
  45. j handle_vec2_sb1
  46. nop
  47. #else
  48. /*
  49. * M_ERRCTL_RECOVERABLE is bit 31, which makes it easy to tell
  50. * if we can fast-path out of here for a h/w-recovered error.
  51. */
  52. mfc0 k1,C0_ERRCTL
  53. bgtz k1,attempt_recovery
  54. sll k0,k1,1
  55. recovered_dcache:
  56. /*
  57. * Unlock CacheErr-D (which in turn unlocks CacheErr-DPA).
  58. * Ought to log the occurrence of this recovered dcache error.
  59. */
  60. b recovered
  61. mtc0 $0,C0_CERR_D
  62. attempt_recovery:
  63. /*
  64. * k0 has C0_ERRCTL << 1, which puts 'DC' at bit 31. Any
  65. * Dcache errors we can recover from will take more extensive
  66. * processing. For now, they are considered "unrecoverable".
  67. * Note that 'DC' becoming set (outside of ERL mode) will
  68. * cause 'IC' to clear; so if there's an Icache error, we'll
  69. * only find out about it if we recover from this error and
  70. * continue executing.
  71. */
  72. bltz k0,unrecoverable
  73. sll k0,1
  74. /*
  75. * k0 has C0_ERRCTL << 2, which puts 'IC' at bit 31. If an
  76. * Icache error isn't indicated, I'm not sure why we got here.
  77. * Consider that case "unrecoverable" for now.
  78. */
  79. bgez k0,unrecoverable
  80. attempt_icache_recovery:
  81. /*
  82. * External icache errors are due to uncorrectable ECC errors
  83. * in the L2 cache or Memory Controller and cannot be
  84. * recovered here.
  85. */
  86. mfc0 k0,C0_CERR_I /* delay slot */
  87. li k1,1 << 26 /* ICACHE_EXTERNAL */
  88. and k1,k0
  89. bnez k1,unrecoverable
  90. andi k0,0x1fe0
  91. /*
  92. * Since the error is internal, the 'IDX' field from
  93. * CacheErr-I is valid and we can just invalidate all blocks
  94. * in that set.
  95. */
  96. cache Index_Invalidate_I,(0<<13)(k0)
  97. cache Index_Invalidate_I,(1<<13)(k0)
  98. cache Index_Invalidate_I,(2<<13)(k0)
  99. cache Index_Invalidate_I,(3<<13)(k0)
  100. /* Ought to log this recovered icache error */
  101. recovered:
  102. /* Restore the saved registers */
  103. ld k0,0x170($0)
  104. ld k1,0x178($0)
  105. eret
  106. unrecoverable:
  107. /* Unrecoverable Icache or Dcache error; log it and/or fail */
  108. j handle_vec2_sb1
  109. nop
  110. #endif
  111. END(except_vec2_sb1)
  112. LEAF(handle_vec2_sb1)
  113. mfc0 k0,CP0_CONFIG
  114. li k1,~CONF_CM_CMASK
  115. and k0,k0,k1
  116. ori k0,k0,CONF_CM_UNCACHED
  117. mtc0 k0,CP0_CONFIG
  118. SSNOP
  119. SSNOP
  120. SSNOP
  121. SSNOP
  122. bnezl $0, 1f
  123. 1:
  124. mfc0 k0, CP0_STATUS
  125. sll k0, k0, 3 # check CU0 (kernel?)
  126. bltz k0, 2f
  127. nop
  128. /* Get a valid Kseg0 stack pointer. Any task's stack pointer
  129. * will do, although if we ever want to resume execution we
  130. * better not have corrupted any state. */
  131. get_saved_sp
  132. move sp, k1
  133. 2:
  134. j sb1_cache_error
  135. nop
  136. END(handle_vec2_sb1)