bmips_vec.S 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2011 by Kevin Cernekee (cernekee@gmail.com)
  7. *
  8. * Reset/NMI/re-entry vectors for BMIPS processors
  9. */
  10. #include <asm/asm.h>
  11. #include <asm/asmmacro.h>
  12. #include <asm/cacheops.h>
  13. #include <asm/cpu.h>
  14. #include <asm/regdef.h>
  15. #include <asm/mipsregs.h>
  16. #include <asm/stackframe.h>
  17. #include <asm/addrspace.h>
  18. #include <asm/hazards.h>
  19. #include <asm/bmips.h>
  20. .macro BARRIER
  21. .set mips32
  22. _ssnop
  23. _ssnop
  24. _ssnop
  25. .set mips0
  26. .endm
  27. /***********************************************************************
  28. * Alternate CPU1 startup vector for BMIPS4350
  29. *
  30. * On some systems the bootloader has already started CPU1 and configured
  31. * it to resume execution at 0x8000_0200 (!BEV IV vector) when it is
  32. * triggered by the SW1 interrupt. If that is the case we try to move
  33. * it to a more convenient place: BMIPS_WARM_RESTART_VEC @ 0x8000_0380.
  34. ***********************************************************************/
  35. LEAF(bmips_smp_movevec)
  36. la k0, 1f
  37. li k1, CKSEG1
  38. or k0, k1
  39. jr k0
  40. 1:
  41. /* clear IV, pending IPIs */
  42. mtc0 zero, CP0_CAUSE
  43. /* re-enable IRQs to wait for SW1 */
  44. li k0, ST0_IE | ST0_BEV | STATUSF_IP1
  45. mtc0 k0, CP0_STATUS
  46. /* set up CPU1 CBR; move BASE to 0xa000_0000 */
  47. li k0, 0xff400000
  48. mtc0 k0, $22, 6
  49. /* set up relocation vector address based on thread ID */
  50. mfc0 k1, $22, 3
  51. srl k1, 16
  52. andi k1, 0x8000
  53. or k1, CKSEG1 | BMIPS_RELO_VECTOR_CONTROL_0
  54. or k0, k1
  55. li k1, 0xa0080000
  56. sw k1, 0(k0)
  57. /* wait here for SW1 interrupt from bmips_boot_secondary() */
  58. wait
  59. la k0, bmips_reset_nmi_vec
  60. li k1, CKSEG1
  61. or k0, k1
  62. jr k0
  63. END(bmips_smp_movevec)
  64. /***********************************************************************
  65. * Reset/NMI vector
  66. * For BMIPS processors that can relocate their exception vectors, this
  67. * entire function gets copied to 0x8000_0000.
  68. ***********************************************************************/
  69. NESTED(bmips_reset_nmi_vec, PT_SIZE, sp)
  70. .set push
  71. .set noat
  72. .align 4
  73. #ifdef CONFIG_SMP
  74. /* if the NMI bit is clear, assume this is a CPU1 reset instead */
  75. li k1, (1 << 19)
  76. mfc0 k0, CP0_STATUS
  77. and k0, k1
  78. beqz k0, bmips_smp_entry
  79. #if defined(CONFIG_CPU_BMIPS5000)
  80. mfc0 k0, CP0_PRID
  81. li k1, PRID_IMP_BMIPS5000
  82. andi k0, 0xff00
  83. bne k0, k1, 1f
  84. /* if we're not on core 0, this must be the SMP boot signal */
  85. li k1, (3 << 25)
  86. mfc0 k0, $22
  87. and k0, k1
  88. bnez k0, bmips_smp_entry
  89. 1:
  90. #endif /* CONFIG_CPU_BMIPS5000 */
  91. #endif /* CONFIG_SMP */
  92. /* nope, it's just a regular NMI */
  93. SAVE_ALL
  94. move a0, sp
  95. /* clear EXL, ERL, BEV so that TLB refills still work */
  96. mfc0 k0, CP0_STATUS
  97. li k1, ST0_ERL | ST0_EXL | ST0_BEV | ST0_IE
  98. or k0, k1
  99. xor k0, k1
  100. mtc0 k0, CP0_STATUS
  101. BARRIER
  102. /* jump to the NMI handler function */
  103. la k0, nmi_handler
  104. jr k0
  105. RESTORE_ALL
  106. .set arch=r4000
  107. eret
  108. /***********************************************************************
  109. * CPU1 reset vector (used for the initial boot only)
  110. * This is still part of bmips_reset_nmi_vec().
  111. ***********************************************************************/
  112. #ifdef CONFIG_SMP
  113. bmips_smp_entry:
  114. /* set up CP0 STATUS; enable FPU */
  115. li k0, 0x30000000
  116. mtc0 k0, CP0_STATUS
  117. BARRIER
  118. /* set local CP0 CONFIG to make kseg0 cacheable, write-back */
  119. mfc0 k0, CP0_CONFIG
  120. ori k0, 0x07
  121. xori k0, 0x04
  122. mtc0 k0, CP0_CONFIG
  123. mfc0 k0, CP0_PRID
  124. andi k0, 0xff00
  125. #if defined(CONFIG_CPU_BMIPS4350) || defined(CONFIG_CPU_BMIPS4380)
  126. li k1, PRID_IMP_BMIPS43XX
  127. bne k0, k1, 2f
  128. /* initialize CPU1's local I-cache */
  129. li k0, 0x80000000
  130. li k1, 0x80010000
  131. mtc0 zero, $28
  132. mtc0 zero, $28, 1
  133. BARRIER
  134. 1: cache Index_Store_Tag_I, 0(k0)
  135. addiu k0, 16
  136. bne k0, k1, 1b
  137. b 3f
  138. 2:
  139. #endif /* CONFIG_CPU_BMIPS4350 || CONFIG_CPU_BMIPS4380 */
  140. #if defined(CONFIG_CPU_BMIPS5000)
  141. /* set exception vector base */
  142. li k1, PRID_IMP_BMIPS5000
  143. bne k0, k1, 3f
  144. la k0, ebase
  145. lw k0, 0(k0)
  146. mtc0 k0, $15, 1
  147. BARRIER
  148. #endif /* CONFIG_CPU_BMIPS5000 */
  149. 3:
  150. /* jump back to kseg0 in case we need to remap the kseg1 area */
  151. la k0, 1f
  152. jr k0
  153. 1:
  154. la k0, bmips_enable_xks01
  155. jalr k0
  156. /* use temporary stack to set up upper memory TLB */
  157. li sp, BMIPS_WARM_RESTART_VEC
  158. la k0, plat_wired_tlb_setup
  159. jalr k0
  160. /* switch to permanent stack and continue booting */
  161. .global bmips_secondary_reentry
  162. bmips_secondary_reentry:
  163. la k0, bmips_smp_boot_sp
  164. lw sp, 0(k0)
  165. la k0, bmips_smp_boot_gp
  166. lw gp, 0(k0)
  167. la k0, start_secondary
  168. jr k0
  169. #endif /* CONFIG_SMP */
  170. .align 4
  171. .global bmips_reset_nmi_vec_end
  172. bmips_reset_nmi_vec_end:
  173. END(bmips_reset_nmi_vec)
  174. .set pop
  175. /***********************************************************************
  176. * CPU1 warm restart vector (used for second and subsequent boots).
  177. * Also used for S2 standby recovery (PM).
  178. * This entire function gets copied to (BMIPS_WARM_RESTART_VEC)
  179. ***********************************************************************/
  180. LEAF(bmips_smp_int_vec)
  181. .align 4
  182. mfc0 k0, CP0_STATUS
  183. ori k0, 0x01
  184. xori k0, 0x01
  185. mtc0 k0, CP0_STATUS
  186. eret
  187. .align 4
  188. .global bmips_smp_int_vec_end
  189. bmips_smp_int_vec_end:
  190. END(bmips_smp_int_vec)
  191. /***********************************************************************
  192. * XKS01 support
  193. * Certain CPUs support extending kseg0 to 1024MB.
  194. ***********************************************************************/
  195. LEAF(bmips_enable_xks01)
  196. #if defined(CONFIG_XKS01)
  197. mfc0 t0, CP0_PRID
  198. andi t2, t0, 0xff00
  199. #if defined(CONFIG_CPU_BMIPS4380)
  200. li t1, PRID_IMP_BMIPS43XX
  201. bne t2, t1, 1f
  202. andi t0, 0xff
  203. addiu t1, t0, -PRID_REV_BMIPS4380_HI
  204. bgtz t1, 2f
  205. addiu t0, -PRID_REV_BMIPS4380_LO
  206. bltz t0, 2f
  207. mfc0 t0, $22, 3
  208. li t1, 0x1ff0
  209. li t2, (1 << 12) | (1 << 9)
  210. or t0, t1
  211. xor t0, t1
  212. or t0, t2
  213. mtc0 t0, $22, 3
  214. BARRIER
  215. b 2f
  216. 1:
  217. #endif /* CONFIG_CPU_BMIPS4380 */
  218. #if defined(CONFIG_CPU_BMIPS5000)
  219. li t1, PRID_IMP_BMIPS5000
  220. bne t2, t1, 2f
  221. mfc0 t0, $22, 5
  222. li t1, 0x01ff
  223. li t2, (1 << 8) | (1 << 5)
  224. or t0, t1
  225. xor t0, t1
  226. or t0, t2
  227. mtc0 t0, $22, 5
  228. BARRIER
  229. #endif /* CONFIG_CPU_BMIPS5000 */
  230. 2:
  231. #endif /* defined(CONFIG_XKS01) */
  232. jr ra
  233. END(bmips_enable_xks01)