gic_64.S 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * GIC Initialization Routines.
  4. *
  5. * (C) Copyright 2013
  6. * David Feng <fenghua@phytium.com.cn>
  7. */
  8. #include <asm-offsets.h>
  9. #include <config.h>
  10. #include <linux/linkage.h>
  11. #include <asm/gic.h>
  12. #include <asm/macro.h>
  13. /*************************************************************************
  14. *
  15. * void gic_init_secure(DistributorBase);
  16. *
  17. * Initialize secure copy of GIC at EL3.
  18. *
  19. *************************************************************************/
  20. ENTRY(gic_init_secure)
  21. /*
  22. * Initialize Distributor
  23. * x0: Distributor Base
  24. */
  25. #if defined(CONFIG_GICV3)
  26. mov w9, #0x37 /* EnableGrp0 | EnableGrp1NS */
  27. /* EnableGrp1S | ARE_S | ARE_NS */
  28. str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */
  29. ldr w9, [x0, GICD_TYPER]
  30. and w10, w9, #0x1f /* ITLinesNumber */
  31. cbz w10, 1f /* No SPIs */
  32. add x11, x0, (GICD_IGROUPRn + 4)
  33. add x12, x0, (GICD_IGROUPMODRn + 4)
  34. mov w9, #~0
  35. 0: str w9, [x11], #0x4
  36. str wzr, [x12], #0x4 /* Config SPIs as Group1NS */
  37. sub w10, w10, #0x1
  38. cbnz w10, 0b
  39. #elif defined(CONFIG_GICV2)
  40. mov w9, #0x3 /* EnableGrp0 | EnableGrp1 */
  41. str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */
  42. ldr w9, [x0, GICD_TYPER]
  43. and w10, w9, #0x1f /* ITLinesNumber */
  44. cbz w10, 1f /* No SPIs */
  45. add x11, x0, GICD_IGROUPRn
  46. mov w9, #~0 /* Config SPIs as Grp1 */
  47. str w9, [x11], #0x4
  48. 0: str w9, [x11], #0x4
  49. sub w10, w10, #0x1
  50. cbnz w10, 0b
  51. ldr x1, =GICC_BASE /* GICC_CTLR */
  52. mov w0, #3 /* EnableGrp0 | EnableGrp1 */
  53. str w0, [x1]
  54. mov w0, #1 << 7 /* allow NS access to GICC_PMR */
  55. str w0, [x1, #4] /* GICC_PMR */
  56. #endif
  57. 1:
  58. ret
  59. ENDPROC(gic_init_secure)
  60. /*************************************************************************
  61. * For Gicv2:
  62. * void gic_init_secure_percpu(DistributorBase, CpuInterfaceBase);
  63. * For Gicv3:
  64. * void gic_init_secure_percpu(ReDistributorBase);
  65. *
  66. * Initialize secure copy of GIC at EL3.
  67. *
  68. *************************************************************************/
  69. ENTRY(gic_init_secure_percpu)
  70. #if defined(CONFIG_GICV3)
  71. /*
  72. * Initialize ReDistributor
  73. * x0: ReDistributor Base
  74. */
  75. mrs x10, mpidr_el1
  76. lsr x9, x10, #32
  77. bfi x10, x9, #24, #8 /* w10 is aff3:aff2:aff1:aff0 */
  78. mov x9, x0
  79. 1: ldr x11, [x9, GICR_TYPER]
  80. lsr x11, x11, #32 /* w11 is aff3:aff2:aff1:aff0 */
  81. cmp w10, w11
  82. b.eq 2f
  83. add x9, x9, #(2 << 16)
  84. b 1b
  85. /* x9: ReDistributor Base Address of Current CPU */
  86. 2: mov w10, #~0x2
  87. ldr w11, [x9, GICR_WAKER]
  88. and w11, w11, w10 /* Clear ProcessorSleep */
  89. str w11, [x9, GICR_WAKER]
  90. dsb st
  91. isb
  92. 3: ldr w10, [x9, GICR_WAKER]
  93. tbnz w10, #2, 3b /* Wait Children be Alive */
  94. add x10, x9, #(1 << 16) /* SGI_Base */
  95. mov w11, #~0
  96. str w11, [x10, GICR_IGROUPRn]
  97. str wzr, [x10, GICR_IGROUPMODRn] /* SGIs|PPIs Group1NS */
  98. mov w11, #0x1 /* Enable SGI 0 */
  99. str w11, [x10, GICR_ISENABLERn]
  100. /* Initialize Cpu Interface */
  101. mrs x10, ICC_SRE_EL3
  102. orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */
  103. /* Allow EL2 access to ICC_SRE_EL2 */
  104. msr ICC_SRE_EL3, x10
  105. isb
  106. mrs x10, ICC_SRE_EL2
  107. orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */
  108. /* Allow EL1 access to ICC_SRE_EL1 */
  109. msr ICC_SRE_EL2, x10
  110. isb
  111. mov x10, #0x3 /* EnableGrp1NS | EnableGrp1S */
  112. msr ICC_IGRPEN1_EL3, x10
  113. isb
  114. msr ICC_CTLR_EL3, xzr
  115. isb
  116. msr ICC_CTLR_EL1, xzr /* NonSecure ICC_CTLR_EL1 */
  117. isb
  118. mov x10, #0x1 << 7 /* Non-Secure access to ICC_PMR_EL1 */
  119. msr ICC_PMR_EL1, x10
  120. isb
  121. #elif defined(CONFIG_GICV2)
  122. /*
  123. * Initialize SGIs and PPIs
  124. * x0: Distributor Base
  125. * x1: Cpu Interface Base
  126. */
  127. mov w9, #~0 /* Config SGIs and PPIs as Grp1 */
  128. str w9, [x0, GICD_IGROUPRn] /* GICD_IGROUPR0 */
  129. mov w9, #0x1 /* Enable SGI 0 */
  130. str w9, [x0, GICD_ISENABLERn]
  131. /* Initialize Cpu Interface */
  132. mov w9, #0x1e7 /* Disable IRQ/FIQ Bypass & */
  133. /* Enable Ack Group1 Interrupt & */
  134. /* EnableGrp0 & EnableGrp1 */
  135. str w9, [x1, GICC_CTLR] /* Secure GICC_CTLR */
  136. mov w9, #0x1 << 7 /* Non-Secure access to GICC_PMR */
  137. str w9, [x1, GICC_PMR]
  138. #endif
  139. ret
  140. ENDPROC(gic_init_secure_percpu)
  141. /*************************************************************************
  142. * For Gicv2:
  143. * void gic_kick_secondary_cpus(DistributorBase);
  144. * For Gicv3:
  145. * void gic_kick_secondary_cpus(void);
  146. *
  147. *************************************************************************/
  148. ENTRY(gic_kick_secondary_cpus)
  149. #if defined(CONFIG_GICV3)
  150. mov x9, #(1 << 40)
  151. msr ICC_ASGI1R_EL1, x9
  152. isb
  153. #elif defined(CONFIG_GICV2)
  154. mov w9, #0x8000
  155. movk w9, #0x100, lsl #16
  156. str w9, [x0, GICD_SGIR]
  157. #endif
  158. ret
  159. ENDPROC(gic_kick_secondary_cpus)
  160. /*************************************************************************
  161. * For Gicv2:
  162. * void gic_wait_for_interrupt(CpuInterfaceBase);
  163. * For Gicv3:
  164. * void gic_wait_for_interrupt(void);
  165. *
  166. * Wait for SGI 0 from master.
  167. *
  168. *************************************************************************/
  169. ENTRY(gic_wait_for_interrupt)
  170. #if defined(CONFIG_GICV3)
  171. gic_wait_for_interrupt_m x9
  172. #elif defined(CONFIG_GICV2)
  173. gic_wait_for_interrupt_m x0, w9
  174. #endif
  175. ret
  176. ENDPROC(gic_wait_for_interrupt)