reset.S 6.1 KB

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