reset.S 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Copyright 2003-2013 Broadcom Corporation.
  3. * All Rights Reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the Broadcom
  9. * license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in
  19. * the documentation and/or other materials provided with the
  20. * distribution.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY BROADCOM ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  24. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  29. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  31. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  32. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <asm/asm.h>
  35. #include <asm/asm-offsets.h>
  36. #include <asm/cacheops.h>
  37. #include <asm/regdef.h>
  38. #include <asm/mipsregs.h>
  39. #include <asm/stackframe.h>
  40. #include <asm/asmmacro.h>
  41. #include <asm/addrspace.h>
  42. #include <asm/netlogic/common.h>
  43. #include <asm/netlogic/xlp-hal/iomap.h>
  44. #include <asm/netlogic/xlp-hal/xlp.h>
  45. #include <asm/netlogic/xlp-hal/sys.h>
  46. #include <asm/netlogic/xlp-hal/cpucontrol.h>
  47. #define CP0_EBASE $15
  48. #define SYS_CPU_COHERENT_BASE CKSEG1ADDR(XLP_DEFAULT_IO_BASE) + \
  49. XLP_IO_SYS_OFFSET(0) + XLP_IO_PCI_HDRSZ + \
  50. SYS_CPU_NONCOHERENT_MODE * 4
  51. /* Enable XLP features and workarounds in the LSU */
  52. .macro xlp_config_lsu
  53. li t0, LSU_DEFEATURE
  54. mfcr t1, t0
  55. lui t2, 0xc080 /* SUE, Enable Unaligned Access, L2HPE */
  56. or t1, t1, t2
  57. mtcr t1, t0
  58. li t0, ICU_DEFEATURE
  59. mfcr t1, t0
  60. ori t1, 0x1000 /* Enable Icache partitioning */
  61. mtcr t1, t0
  62. li t0, SCHED_DEFEATURE
  63. lui t1, 0x0100 /* Disable BRU accepting ALU ops */
  64. mtcr t1, t0
  65. .endm
  66. /*
  67. * L1D cache has to be flushed before enabling threads in XLP.
  68. * On XLP8xx/XLP3xx, we do a low level flush using processor control
  69. * registers. On XLPII CPUs, usual cache instructions work.
  70. */
  71. .macro xlp_flush_l1_dcache
  72. mfc0 t0, CP0_EBASE, 0
  73. andi t0, t0, 0xff00
  74. slt t1, t0, 0x1200
  75. beqz t1, 15f
  76. nop
  77. /* XLP8xx low level cache flush */
  78. li t0, LSU_DEBUG_DATA0
  79. li t1, LSU_DEBUG_ADDR
  80. li t2, 0 /* index */
  81. li t3, 0x1000 /* loop count */
  82. 11:
  83. sll v0, t2, 5
  84. mtcr zero, t0
  85. ori v1, v0, 0x3 /* way0 | write_enable | write_active */
  86. mtcr v1, t1
  87. 12:
  88. mfcr v1, t1
  89. andi v1, 0x1 /* wait for write_active == 0 */
  90. bnez v1, 12b
  91. nop
  92. mtcr zero, t0
  93. ori v1, v0, 0x7 /* way1 | write_enable | write_active */
  94. mtcr v1, t1
  95. 13:
  96. mfcr v1, t1
  97. andi v1, 0x1 /* wait for write_active == 0 */
  98. bnez v1, 13b
  99. nop
  100. addi t2, 1
  101. bne t3, t2, 11b
  102. nop
  103. b 17f
  104. nop
  105. /* XLPII CPUs, Invalidate all 64k of L1 D-cache */
  106. 15:
  107. li t0, 0x80000000
  108. li t1, 0x80010000
  109. 16: cache Index_Writeback_Inv_D, 0(t0)
  110. addiu t0, t0, 32
  111. bne t0, t1, 16b
  112. nop
  113. 17:
  114. .endm
  115. /*
  116. * nlm_reset_entry will be copied to the reset entry point for
  117. * XLR and XLP. The XLP cores start here when they are woken up. This
  118. * is also the NMI entry point.
  119. *
  120. * We use scratch reg 6/7 to save k0/k1 and check for NMI first.
  121. *
  122. * The data corresponding to reset/NMI is stored at RESET_DATA_PHYS
  123. * location, this will have the thread mask (used when core is woken up)
  124. * and the current NMI handler in case we reached here for an NMI.
  125. *
  126. * When a core or thread is newly woken up, it marks itself ready and
  127. * loops in a 'wait'. When the CPU really needs waking up, we send an NMI
  128. * IPI to it, with the NMI handler set to prom_boot_secondary_cpus
  129. */
  130. .set noreorder
  131. .set noat
  132. .set arch=xlr /* for mfcr/mtcr, XLR is sufficient */
  133. FEXPORT(nlm_reset_entry)
  134. dmtc0 k0, $22, 6
  135. dmtc0 k1, $22, 7
  136. mfc0 k0, CP0_STATUS
  137. li k1, 0x80000
  138. and k1, k0, k1
  139. beqz k1, 1f /* go to real reset entry */
  140. nop
  141. li k1, CKSEG1ADDR(RESET_DATA_PHYS) /* NMI */
  142. ld k0, BOOT_NMI_HANDLER(k1)
  143. jr k0
  144. nop
  145. 1: /* Entry point on core wakeup */
  146. mfc0 t0, CP0_EBASE, 0 /* processor ID */
  147. andi t0, 0xff00
  148. li t1, 0x1500 /* XLP 9xx */
  149. beq t0, t1, 2f /* does not need to set coherent */
  150. nop
  151. /* set bit in SYS coherent register for the core */
  152. mfc0 t0, CP0_EBASE, 1
  153. mfc0 t1, CP0_EBASE, 1
  154. srl t1, 5
  155. andi t1, 0x3 /* t1 <- node */
  156. li t2, 0x40000
  157. mul t3, t2, t1 /* t3 = node * 0x40000 */
  158. srl t0, t0, 2
  159. and t0, t0, 0x7 /* t0 <- core */
  160. li t1, 0x1
  161. sll t0, t1, t0
  162. nor t0, t0, zero /* t0 <- ~(1 << core) */
  163. li t2, SYS_CPU_COHERENT_BASE
  164. add t2, t2, t3 /* t2 <- SYS offset for node */
  165. lw t1, 0(t2)
  166. and t1, t1, t0
  167. sw t1, 0(t2)
  168. /* read back to ensure complete */
  169. lw t1, 0(t2)
  170. sync
  171. 2:
  172. /* Configure LSU on Non-0 Cores. */
  173. xlp_config_lsu
  174. /* FALL THROUGH */
  175. /*
  176. * Wake up sibling threads from the initial thread in a core.
  177. */
  178. EXPORT(nlm_boot_siblings)
  179. /* core L1D flush before enable threads */
  180. xlp_flush_l1_dcache
  181. /* Enable hw threads by writing to MAP_THREADMODE of the core */
  182. li t0, CKSEG1ADDR(RESET_DATA_PHYS)
  183. lw t1, BOOT_THREAD_MODE(t0) /* t1 <- thread mode */
  184. li t0, ((CPU_BLOCKID_MAP << 8) | MAP_THREADMODE)
  185. mfcr t2, t0
  186. or t2, t2, t1
  187. mtcr t2, t0
  188. /*
  189. * The new hardware thread starts at the next instruction
  190. * For all the cases other than core 0 thread 0, we will
  191. * jump to the secondary wait function.
  192. * NOTE: All GPR contents are lost after the mtcr above!
  193. */
  194. mfc0 v0, CP0_EBASE, 1
  195. andi v0, 0x3ff /* v0 <- node/core */
  196. beqz v0, 4f /* boot cpu (cpuid == 0)? */
  197. nop
  198. /* setup status reg */
  199. move t1, zero
  200. #ifdef CONFIG_64BIT
  201. ori t1, ST0_KX
  202. #endif
  203. mtc0 t1, CP0_STATUS
  204. /* mark CPU ready */
  205. li t3, CKSEG1ADDR(RESET_DATA_PHYS)
  206. ADDIU t1, t3, BOOT_CPU_READY
  207. sll v1, v0, 2
  208. PTR_ADDU t1, v1
  209. li t2, 1
  210. sw t2, 0(t1)
  211. /* Wait until NMI hits */
  212. 3: wait
  213. b 3b
  214. nop
  215. /*
  216. * For the boot CPU, we have to restore registers and
  217. * return
  218. */
  219. 4: dmfc0 t0, $4, 2 /* restore SP from UserLocal */
  220. li t1, 0xfadebeef
  221. dmtc0 t1, $4, 2 /* restore SP from UserLocal */
  222. PTR_SUBU sp, t0, PT_SIZE
  223. RESTORE_ALL
  224. jr ra
  225. nop
  226. EXPORT(nlm_reset_entry_end)
  227. LEAF(nlm_init_boot_cpu)
  228. #ifdef CONFIG_CPU_XLP
  229. xlp_config_lsu
  230. #endif
  231. jr ra
  232. nop
  233. END(nlm_init_boot_cpu)