reset.S 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 <linux/init.h>
  35. #include <asm/asm.h>
  36. #include <asm/asm-offsets.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(node) CKSEG1ADDR(XLP_DEFAULT_IO_BASE) + \
  49. XLP_IO_SYS_OFFSET(node) + XLP_IO_PCI_HDRSZ + \
  50. SYS_CPU_NONCOHERENT_MODE * 4
  51. #define XLP_AX_WORKAROUND /* enable Ax silicon workarounds */
  52. /* Enable XLP features and workarounds in the LSU */
  53. .macro xlp_config_lsu
  54. li t0, LSU_DEFEATURE
  55. mfcr t1, t0
  56. lui t2, 0xc080 /* SUE, Enable Unaligned Access, L2HPE */
  57. or t1, t1, t2
  58. #ifdef XLP_AX_WORKAROUND
  59. li t2, ~0xe /* S1RCM */
  60. and t1, t1, t2
  61. #endif
  62. mtcr t1, t0
  63. li t0, ICU_DEFEATURE
  64. mfcr t1, t0
  65. ori t1, 0x1000 /* Enable Icache partitioning */
  66. mtcr t1, t0
  67. #ifdef XLP_AX_WORKAROUND
  68. li t0, SCHED_DEFEATURE
  69. lui t1, 0x0100 /* Disable BRU accepting ALU ops */
  70. mtcr t1, t0
  71. #endif
  72. .endm
  73. /*
  74. * Low level flush for L1D cache on XLP, the normal cache ops does
  75. * not do the complete and correct cache flush.
  76. */
  77. .macro xlp_flush_l1_dcache
  78. li t0, LSU_DEBUG_DATA0
  79. li t1, LSU_DEBUG_ADDR
  80. li t2, 0 /* index */
  81. li t3, 0x1000 /* loop count */
  82. 1:
  83. sll v0, t2, 5
  84. mtcr zero, t0
  85. ori v1, v0, 0x3 /* way0 | write_enable | write_active */
  86. mtcr v1, t1
  87. 2:
  88. mfcr v1, t1
  89. andi v1, 0x1 /* wait for write_active == 0 */
  90. bnez v1, 2b
  91. nop
  92. mtcr zero, t0
  93. ori v1, v0, 0x7 /* way1 | write_enable | write_active */
  94. mtcr v1, t1
  95. 3:
  96. mfcr v1, t1
  97. andi v1, 0x1 /* wait for write_active == 0 */
  98. bnez v1, 3b
  99. nop
  100. addi t2, 1
  101. bne t3, t2, 1b
  102. nop
  103. .endm
  104. /*
  105. * nlm_reset_entry will be copied to the reset entry point for
  106. * XLR and XLP. The XLP cores start here when they are woken up. This
  107. * is also the NMI entry point.
  108. *
  109. * We use scratch reg 6/7 to save k0/k1 and check for NMI first.
  110. *
  111. * The data corresponding to reset/NMI is stored at RESET_DATA_PHYS
  112. * location, this will have the thread mask (used when core is woken up)
  113. * and the current NMI handler in case we reached here for an NMI.
  114. *
  115. * When a core or thread is newly woken up, it marks itself ready and
  116. * loops in a 'wait'. When the CPU really needs waking up, we send an NMI
  117. * IPI to it, with the NMI handler set to prom_boot_secondary_cpus
  118. */
  119. .set noreorder
  120. .set noat
  121. .set arch=xlr /* for mfcr/mtcr, XLR is sufficient */
  122. FEXPORT(nlm_reset_entry)
  123. dmtc0 k0, $22, 6
  124. dmtc0 k1, $22, 7
  125. mfc0 k0, CP0_STATUS
  126. li k1, 0x80000
  127. and k1, k0, k1
  128. beqz k1, 1f /* go to real reset entry */
  129. nop
  130. li k1, CKSEG1ADDR(RESET_DATA_PHYS) /* NMI */
  131. ld k0, BOOT_NMI_HANDLER(k1)
  132. jr k0
  133. nop
  134. 1: /* Entry point on core wakeup */
  135. mfc0 t0, CP0_EBASE, 1
  136. mfc0 t1, CP0_EBASE, 1
  137. srl t1, 5
  138. andi t1, 0x3 /* t1 <- node */
  139. li t2, 0x40000
  140. mul t3, t2, t1 /* t3 = node * 0x40000 */
  141. srl t0, t0, 2
  142. and t0, t0, 0x7 /* t0 <- core */
  143. li t1, 0x1
  144. sll t0, t1, t0
  145. nor t0, t0, zero /* t0 <- ~(1 << core) */
  146. li t2, SYS_CPU_COHERENT_BASE(0)
  147. add t2, t2, t3 /* t2 <- SYS offset for node */
  148. lw t1, 0(t2)
  149. and t1, t1, t0
  150. sw t1, 0(t2)
  151. /* read back to ensure complete */
  152. lw t1, 0(t2)
  153. sync
  154. /* Configure LSU on Non-0 Cores. */
  155. xlp_config_lsu
  156. /* FALL THROUGH */
  157. /*
  158. * Wake up sibling threads from the initial thread in
  159. * a core.
  160. */
  161. EXPORT(nlm_boot_siblings)
  162. /* core L1D flush before enable threads */
  163. xlp_flush_l1_dcache
  164. /* Enable hw threads by writing to MAP_THREADMODE of the core */
  165. li t0, CKSEG1ADDR(RESET_DATA_PHYS)
  166. lw t1, BOOT_THREAD_MODE(t0) /* t1 <- thread mode */
  167. li t0, ((CPU_BLOCKID_MAP << 8) | MAP_THREADMODE)
  168. mfcr t2, t0
  169. or t2, t2, t1
  170. mtcr t2, t0
  171. /*
  172. * The new hardware thread starts at the next instruction
  173. * For all the cases other than core 0 thread 0, we will
  174. * jump to the secondary wait function.
  175. */
  176. mfc0 v0, CP0_EBASE, 1
  177. andi v0, 0x3ff /* v0 <- node/core */
  178. /* Init MMU in the first thread after changing THREAD_MODE
  179. * register (Ax Errata?)
  180. */
  181. andi v1, v0, 0x3 /* v1 <- thread id */
  182. bnez v1, 2f
  183. nop
  184. li t0, MMU_SETUP
  185. li t1, 0
  186. mtcr t1, t0
  187. _ehb
  188. 2: beqz v0, 4f /* boot cpu (cpuid == 0)? */
  189. nop
  190. /* setup status reg */
  191. move t1, zero
  192. #ifdef CONFIG_64BIT
  193. ori t1, ST0_KX
  194. #endif
  195. mtc0 t1, CP0_STATUS
  196. /* mark CPU ready, careful here, previous mtcr trashed registers */
  197. li t3, CKSEG1ADDR(RESET_DATA_PHYS)
  198. ADDIU t1, t3, BOOT_CPU_READY
  199. sll v1, v0, 2
  200. PTR_ADDU t1, v1
  201. li t2, 1
  202. sw t2, 0(t1)
  203. /* Wait until NMI hits */
  204. 3: wait
  205. j 3b
  206. nop
  207. /*
  208. * For the boot CPU, we have to restore registers and
  209. * return
  210. */
  211. 4: dmfc0 t0, $4, 2 /* restore SP from UserLocal */
  212. li t1, 0xfadebeef
  213. dmtc0 t1, $4, 2 /* restore SP from UserLocal */
  214. PTR_SUBU sp, t0, PT_SIZE
  215. RESTORE_ALL
  216. jr ra
  217. nop
  218. EXPORT(nlm_reset_entry_end)
  219. LEAF(nlm_init_boot_cpu)
  220. #ifdef CONFIG_CPU_XLP
  221. xlp_config_lsu
  222. #endif
  223. jr ra
  224. nop
  225. END(nlm_init_boot_cpu)