lowlevel.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * (C) Copyright 2014 Freescale Semiconductor
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. *
  6. * Extracted from armv8/start.S
  7. */
  8. #include <config.h>
  9. #include <linux/linkage.h>
  10. #include <asm/gic.h>
  11. #include <asm/macro.h>
  12. #include "mp.h"
  13. ENTRY(lowlevel_init)
  14. mov x29, lr /* Save LR */
  15. /* Set the SMMU page size in the sACR register */
  16. ldr x1, =SMMU_BASE
  17. ldr w0, [x1, #0x10]
  18. orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */
  19. str w0, [x1, #0x10]
  20. /* Initialize GIC Secure Bank Status */
  21. #if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
  22. branch_if_slave x0, 1f
  23. ldr x0, =GICD_BASE
  24. bl gic_init_secure
  25. 1:
  26. #ifdef CONFIG_GICV3
  27. ldr x0, =GICR_BASE
  28. bl gic_init_secure_percpu
  29. #elif defined(CONFIG_GICV2)
  30. ldr x0, =GICD_BASE
  31. ldr x1, =GICC_BASE
  32. bl gic_init_secure_percpu
  33. #endif
  34. #endif
  35. branch_if_master x0, x1, 2f
  36. ldr x0, =secondary_boot_func
  37. blr x0
  38. 2:
  39. #ifdef CONFIG_FSL_TZPC_BP147
  40. /* Set Non Secure access for all devices protected via TZPC */
  41. ldr x1, =TZPCDECPROT_0_SET_BASE /* Decode Protection-0 Set Reg */
  42. orr w0, w0, #1 << 3 /* DCFG_RESET is accessible from NS world */
  43. str w0, [x1]
  44. isb
  45. dsb sy
  46. #endif
  47. #ifdef CONFIG_FSL_TZASC_400
  48. /* Set TZASC so that:
  49. * a. We use only Region0 whose global secure write/read is EN
  50. * b. We use only Region0 whose NSAID write/read is EN
  51. *
  52. * NOTE: As per the CCSR map doc, TZASC 3 and TZASC 4 are just
  53. * placeholders.
  54. */
  55. ldr x1, =TZASC_GATE_KEEPER(0)
  56. ldr x0, [x1] /* Filter 0 Gate Keeper Register */
  57. orr x0, x0, #1 << 0 /* Set open_request for Filter 0 */
  58. str x0, [x1]
  59. ldr x1, =TZASC_GATE_KEEPER(1)
  60. ldr x0, [x1] /* Filter 0 Gate Keeper Register */
  61. orr x0, x0, #1 << 0 /* Set open_request for Filter 0 */
  62. str x0, [x1]
  63. ldr x1, =TZASC_REGION_ATTRIBUTES_0(0)
  64. ldr x0, [x1] /* Region-0 Attributes Register */
  65. orr x0, x0, #1 << 31 /* Set Sec global write en, Bit[31] */
  66. orr x0, x0, #1 << 30 /* Set Sec global read en, Bit[30] */
  67. str x0, [x1]
  68. ldr x1, =TZASC_REGION_ATTRIBUTES_0(1)
  69. ldr x0, [x1] /* Region-1 Attributes Register */
  70. orr x0, x0, #1 << 31 /* Set Sec global write en, Bit[31] */
  71. orr x0, x0, #1 << 30 /* Set Sec global read en, Bit[30] */
  72. str x0, [x1]
  73. ldr x1, =TZASC_REGION_ID_ACCESS_0(0)
  74. ldr w0, [x1] /* Region-0 Access Register */
  75. mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
  76. str w0, [x1]
  77. ldr x1, =TZASC_REGION_ID_ACCESS_0(1)
  78. ldr w0, [x1] /* Region-1 Attributes Register */
  79. mov w0, #0xFFFFFFFF /* Set nsaid_wr_en and nsaid_rd_en */
  80. str w0, [x1]
  81. isb
  82. dsb sy
  83. #endif
  84. mov lr, x29 /* Restore LR */
  85. ret
  86. ENDPROC(lowlevel_init)
  87. /* Keep literals not used by the secondary boot code outside it */
  88. .ltorg
  89. /* Using 64 bit alignment since the spin table is accessed as data */
  90. .align 4
  91. .global secondary_boot_code
  92. /* Secondary Boot Code starts here */
  93. secondary_boot_code:
  94. .global __spin_table
  95. __spin_table:
  96. .space CONFIG_MAX_CPUS*SPIN_TABLE_ELEM_SIZE
  97. .align 2
  98. ENTRY(secondary_boot_func)
  99. /*
  100. * MPIDR_EL1 Fields:
  101. * MPIDR[1:0] = AFF0_CPUID <- Core ID (0,1)
  102. * MPIDR[7:2] = AFF0_RES
  103. * MPIDR[15:8] = AFF1_CLUSTERID <- Cluster ID (0,1,2,3)
  104. * MPIDR[23:16] = AFF2_CLUSTERID
  105. * MPIDR[24] = MT
  106. * MPIDR[29:25] = RES0
  107. * MPIDR[30] = U
  108. * MPIDR[31] = ME
  109. * MPIDR[39:32] = AFF3
  110. *
  111. * Linear Processor ID (LPID) calculation from MPIDR_EL1:
  112. * (We only use AFF0_CPUID and AFF1_CLUSTERID for now
  113. * until AFF2_CLUSTERID and AFF3 have non-zero values)
  114. *
  115. * LPID = MPIDR[15:8] | MPIDR[1:0]
  116. */
  117. mrs x0, mpidr_el1
  118. ubfm x1, x0, #8, #15
  119. ubfm x2, x0, #0, #1
  120. orr x10, x2, x1, lsl #2 /* x10 has LPID */
  121. ubfm x9, x0, #0, #15 /* x9 contains MPIDR[15:0] */
  122. /*
  123. * offset of the spin table element for this core from start of spin
  124. * table (each elem is padded to 64 bytes)
  125. */
  126. lsl x1, x10, #6
  127. ldr x0, =__spin_table
  128. /* physical address of this cpus spin table element */
  129. add x11, x1, x0
  130. str x9, [x11, #16] /* LPID */
  131. mov x4, #1
  132. str x4, [x11, #8] /* STATUS */
  133. dsb sy
  134. #if defined(CONFIG_GICV3)
  135. gic_wait_for_interrupt_m x0
  136. #elif defined(CONFIG_GICV2)
  137. ldr x0, =GICC_BASE
  138. gic_wait_for_interrupt_m x0, w1
  139. #endif
  140. bl secondary_switch_to_el2
  141. #ifdef CONFIG_ARMV8_SWITCH_TO_EL1
  142. bl secondary_switch_to_el1
  143. #endif
  144. slave_cpu:
  145. wfe
  146. ldr x0, [x11]
  147. cbz x0, slave_cpu
  148. #ifndef CONFIG_ARMV8_SWITCH_TO_EL1
  149. mrs x1, sctlr_el2
  150. #else
  151. mrs x1, sctlr_el1
  152. #endif
  153. tbz x1, #25, cpu_is_le
  154. rev x0, x0 /* BE to LE conversion */
  155. cpu_is_le:
  156. br x0 /* branch to the given address */
  157. ENDPROC(secondary_boot_func)
  158. ENTRY(secondary_switch_to_el2)
  159. switch_el x0, 1f, 0f, 0f
  160. 0: ret
  161. 1: armv8_switch_to_el2_m x0
  162. ENDPROC(secondary_switch_to_el2)
  163. ENTRY(secondary_switch_to_el1)
  164. switch_el x0, 0f, 1f, 0f
  165. 0: ret
  166. 1: armv8_switch_to_el1_m x0, x1
  167. ENDPROC(secondary_switch_to_el1)
  168. /* Ensure that the literals used by the secondary boot code are
  169. * assembled within it (this is required so that we can protect
  170. * this area with a single memreserve region
  171. */
  172. .ltorg
  173. /* 64 bit alignment for elements accessed as data */
  174. .align 4
  175. .globl __secondary_boot_code_size
  176. .type __secondary_boot_code_size, %object
  177. /* Secondary Boot Code ends here */
  178. __secondary_boot_code_size:
  179. .quad .-secondary_boot_code