gic_64.S 4.9 KB

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