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