cex-sb1.S 4.6 KB

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