reset.S 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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/cpu.h>
  37. #include <asm/cacheops.h>
  38. #include <asm/regdef.h>
  39. #include <asm/mipsregs.h>
  40. #include <asm/stackframe.h>
  41. #include <asm/asmmacro.h>
  42. #include <asm/addrspace.h>
  43. #include <asm/netlogic/common.h>
  44. #include <asm/netlogic/xlp-hal/iomap.h>
  45. #include <asm/netlogic/xlp-hal/xlp.h>
  46. #include <asm/netlogic/xlp-hal/sys.h>
  47. #include <asm/netlogic/xlp-hal/cpucontrol.h>
  48. #define CP0_EBASE $15
  49. #define SYS_CPU_COHERENT_BASE CKSEG1ADDR(XLP_DEFAULT_IO_BASE) + \
  50. XLP_IO_SYS_OFFSET(0) + XLP_IO_PCI_HDRSZ + \
  51. SYS_CPU_NONCOHERENT_MODE * 4
  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, 0x4080 /* Enable Unaligned Access, L2HPE */
  57. or t1, t1, t2
  58. mtcr t1, t0
  59. li t0, ICU_DEFEATURE
  60. mfcr t1, t0
  61. ori t1, 0x1000 /* Enable Icache partitioning */
  62. mtcr t1, t0
  63. li t0, SCHED_DEFEATURE
  64. lui t1, 0x0100 /* Disable BRU accepting ALU ops */
  65. mtcr t1, t0
  66. .endm
  67. /*
  68. * Allow access to physical mem >64G by enabling ELPA in PAGEGRAIN
  69. * register. This is needed before going to C code since the SP can
  70. * in this region. Called from all HW threads.
  71. */
  72. .macro xlp_early_mmu_init
  73. mfc0 t0, CP0_PAGEMASK, 1
  74. li t1, (1 << 29) /* ELPA bit */
  75. or t0, t1
  76. mtc0 t0, CP0_PAGEMASK, 1
  77. .endm
  78. /*
  79. * L1D cache has to be flushed before enabling threads in XLP.
  80. * On XLP8xx/XLP3xx, we do a low level flush using processor control
  81. * registers. On XLPII CPUs, usual cache instructions work.
  82. */
  83. .macro xlp_flush_l1_dcache
  84. mfc0 t0, CP0_EBASE, 0
  85. andi t0, t0, PRID_IMP_MASK
  86. slt t1, t0, 0x1200
  87. beqz t1, 15f
  88. nop
  89. /* XLP8xx low level cache flush */
  90. li t0, LSU_DEBUG_DATA0
  91. li t1, LSU_DEBUG_ADDR
  92. li t2, 0 /* index */
  93. li t3, 0x1000 /* loop count */
  94. 11:
  95. sll v0, t2, 5
  96. mtcr zero, t0
  97. ori v1, v0, 0x3 /* way0 | write_enable | write_active */
  98. mtcr v1, t1
  99. 12:
  100. mfcr v1, t1
  101. andi v1, 0x1 /* wait for write_active == 0 */
  102. bnez v1, 12b
  103. nop
  104. mtcr zero, t0
  105. ori v1, v0, 0x7 /* way1 | write_enable | write_active */
  106. mtcr v1, t1
  107. 13:
  108. mfcr v1, t1
  109. andi v1, 0x1 /* wait for write_active == 0 */
  110. bnez v1, 13b
  111. nop
  112. addi t2, 1
  113. bne t3, t2, 11b
  114. nop
  115. b 17f
  116. nop
  117. /* XLPII CPUs, Invalidate all 64k of L1 D-cache */
  118. 15:
  119. li t0, 0x80000000
  120. li t1, 0x80010000
  121. 16: cache Index_Writeback_Inv_D, 0(t0)
  122. addiu t0, t0, 32
  123. bne t0, t1, 16b
  124. nop
  125. 17:
  126. .endm
  127. /*
  128. * nlm_reset_entry will be copied to the reset entry point for
  129. * XLR and XLP. The XLP cores start here when they are woken up. This
  130. * is also the NMI entry point.
  131. *
  132. * We use scratch reg 6/7 to save k0/k1 and check for NMI first.
  133. *
  134. * The data corresponding to reset/NMI is stored at RESET_DATA_PHYS
  135. * location, this will have the thread mask (used when core is woken up)
  136. * and the current NMI handler in case we reached here for an NMI.
  137. *
  138. * When a core or thread is newly woken up, it marks itself ready and
  139. * loops in a 'wait'. When the CPU really needs waking up, we send an NMI
  140. * IPI to it, with the NMI handler set to prom_boot_secondary_cpus
  141. */
  142. .set noreorder
  143. .set noat
  144. .set arch=xlr /* for mfcr/mtcr, XLR is sufficient */
  145. FEXPORT(nlm_reset_entry)
  146. dmtc0 k0, $22, 6
  147. dmtc0 k1, $22, 7
  148. mfc0 k0, CP0_STATUS
  149. li k1, 0x80000
  150. and k1, k0, k1
  151. beqz k1, 1f /* go to real reset entry */
  152. nop
  153. li k1, CKSEG1ADDR(RESET_DATA_PHYS) /* NMI */
  154. ld k0, BOOT_NMI_HANDLER(k1)
  155. jr k0
  156. nop
  157. 1: /* Entry point on core wakeup */
  158. mfc0 t0, CP0_EBASE, 0 /* processor ID */
  159. andi t0, PRID_IMP_MASK
  160. li t1, 0x1500 /* XLP 9xx */
  161. beq t0, t1, 2f /* does not need to set coherent */
  162. nop
  163. li t1, 0x1300 /* XLP 5xx */
  164. beq t0, t1, 2f /* does not need to set coherent */
  165. nop
  166. /* set bit in SYS coherent register for the core */
  167. mfc0 t0, CP0_EBASE, 1
  168. mfc0 t1, CP0_EBASE, 1
  169. srl t1, 5
  170. andi t1, 0x3 /* t1 <- node */
  171. li t2, 0x40000
  172. mul t3, t2, t1 /* t3 = node * 0x40000 */
  173. srl t0, t0, 2
  174. and t0, t0, 0x7 /* t0 <- core */
  175. li t1, 0x1
  176. sll t0, t1, t0
  177. nor t0, t0, zero /* t0 <- ~(1 << core) */
  178. li t2, SYS_CPU_COHERENT_BASE
  179. add t2, t2, t3 /* t2 <- SYS offset for node */
  180. lw t1, 0(t2)
  181. and t1, t1, t0
  182. sw t1, 0(t2)
  183. /* read back to ensure complete */
  184. lw t1, 0(t2)
  185. sync
  186. 2:
  187. /* Configure LSU on Non-0 Cores. */
  188. xlp_config_lsu
  189. /* FALL THROUGH */
  190. /*
  191. * Wake up sibling threads from the initial thread in a core.
  192. */
  193. EXPORT(nlm_boot_siblings)
  194. /* core L1D flush before enable threads */
  195. xlp_flush_l1_dcache
  196. /* save ra and sp, will be used later (only for boot cpu) */
  197. dmtc0 ra, $22, 6
  198. dmtc0 sp, $22, 7
  199. /* Enable hw threads by writing to MAP_THREADMODE of the core */
  200. li t0, CKSEG1ADDR(RESET_DATA_PHYS)
  201. lw t1, BOOT_THREAD_MODE(t0) /* t1 <- thread mode */
  202. li t0, ((CPU_BLOCKID_MAP << 8) | MAP_THREADMODE)
  203. mfcr t2, t0
  204. or t2, t2, t1
  205. mtcr t2, t0
  206. /*
  207. * The new hardware thread starts at the next instruction
  208. * For all the cases other than core 0 thread 0, we will
  209. * jump to the secondary wait function.
  210. * NOTE: All GPR contents are lost after the mtcr above!
  211. */
  212. mfc0 v0, CP0_EBASE, 1
  213. andi v0, 0x3ff /* v0 <- node/core */
  214. /*
  215. * Errata: to avoid potential live lock, setup IFU_BRUB_RESERVE
  216. * when running 4 threads per core
  217. */
  218. andi v1, v0, 0x3 /* v1 <- thread id */
  219. bnez v1, 2f
  220. nop
  221. /* thread 0 of each core. */
  222. li t0, CKSEG1ADDR(RESET_DATA_PHYS)
  223. lw t1, BOOT_THREAD_MODE(t0) /* t1 <- thread mode */
  224. subu t1, 0x3 /* 4-thread per core mode? */
  225. bnez t1, 2f
  226. nop
  227. li t0, IFU_BRUB_RESERVE
  228. li t1, 0x55
  229. mtcr t1, t0
  230. _ehb
  231. 2:
  232. beqz v0, 4f /* boot cpu (cpuid == 0)? */
  233. nop
  234. /* setup status reg */
  235. move t1, zero
  236. #ifdef CONFIG_64BIT
  237. ori t1, ST0_KX
  238. #endif
  239. mtc0 t1, CP0_STATUS
  240. xlp_early_mmu_init
  241. /* mark CPU ready */
  242. li t3, CKSEG1ADDR(RESET_DATA_PHYS)
  243. ADDIU t1, t3, BOOT_CPU_READY
  244. sll v1, v0, 2
  245. PTR_ADDU t1, v1
  246. li t2, 1
  247. sw t2, 0(t1)
  248. /* Wait until NMI hits */
  249. 3: wait
  250. b 3b
  251. nop
  252. /*
  253. * For the boot CPU, we have to restore ra and sp and return, rest
  254. * of the registers will be restored by the caller
  255. */
  256. 4:
  257. dmfc0 ra, $22, 6
  258. dmfc0 sp, $22, 7
  259. jr ra
  260. nop
  261. EXPORT(nlm_reset_entry_end)
  262. LEAF(nlm_init_boot_cpu)
  263. #ifdef CONFIG_CPU_XLP
  264. xlp_config_lsu
  265. xlp_early_mmu_init
  266. #endif
  267. jr ra
  268. nop
  269. END(nlm_init_boot_cpu)