versal_gicv3.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <plat_private.h>
  7. #include <platform_def.h>
  8. #include <common/interrupt_props.h>
  9. #include <drivers/arm/gicv3.h>
  10. #include <lib/utils.h>
  11. #include <plat/common/platform.h>
  12. /******************************************************************************
  13. * The following functions are defined as weak to allow a platform to override
  14. * the way the GICv3 driver is initialised and used.
  15. *****************************************************************************/
  16. #pragma weak plat_versal_gic_driver_init
  17. #pragma weak plat_versal_gic_init
  18. #pragma weak plat_versal_gic_cpuif_enable
  19. #pragma weak plat_versal_gic_cpuif_disable
  20. #pragma weak plat_versal_gic_pcpu_init
  21. #pragma weak plat_versal_gic_redistif_on
  22. #pragma weak plat_versal_gic_redistif_off
  23. /* The GICv3 driver only needs to be initialized in EL3 */
  24. static uintptr_t rdistif_base_addrs[PLATFORM_CORE_COUNT];
  25. static const interrupt_prop_t versal_interrupt_props[] = {
  26. PLAT_VERSAL_G1S_IRQ_PROPS(INTR_GROUP1S),
  27. PLAT_VERSAL_G0_IRQ_PROPS(INTR_GROUP0)
  28. };
  29. /*
  30. * We save and restore the GICv3 context on system suspend. Allocate the
  31. * data in the designated EL3 Secure carve-out memory.
  32. */
  33. static gicv3_redist_ctx_t rdist_ctx __section(".versal_el3_tzc_dram");
  34. static gicv3_dist_ctx_t dist_ctx __section(".versal_el3_tzc_dram");
  35. /*
  36. * MPIDR hashing function for translating MPIDRs read from GICR_TYPER register
  37. * to core position.
  38. *
  39. * Calculating core position is dependent on MPIDR_EL1.MT bit. However, affinity
  40. * values read from GICR_TYPER don't have an MT field. To reuse the same
  41. * translation used for CPUs, we insert MT bit read from the PE's MPIDR into
  42. * that read from GICR_TYPER.
  43. *
  44. * Assumptions:
  45. *
  46. * - All CPUs implemented in the system have MPIDR_EL1.MT bit set;
  47. * - No CPUs implemented in the system use affinity level 3.
  48. */
  49. static uint32_t versal_gicv3_mpidr_hash(u_register_t mpidr)
  50. {
  51. mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);
  52. return versal_calc_core_pos(mpidr);
  53. }
  54. static const gicv3_driver_data_t versal_gic_data __unused = {
  55. .gicd_base = PLAT_VERSAL_GICD_BASE,
  56. .gicr_base = PLAT_VERSAL_GICR_BASE,
  57. .interrupt_props = versal_interrupt_props,
  58. .interrupt_props_num = ARRAY_SIZE(versal_interrupt_props),
  59. .rdistif_num = PLATFORM_CORE_COUNT,
  60. .rdistif_base_addrs = rdistif_base_addrs,
  61. .mpidr_to_core_pos = versal_gicv3_mpidr_hash
  62. };
  63. void __init plat_versal_gic_driver_init(void)
  64. {
  65. /*
  66. * The GICv3 driver is initialized in EL3 and does not need
  67. * to be initialized again in SEL1. This is because the S-EL1
  68. * can use GIC system registers to manage interrupts and does
  69. * not need GIC interface base addresses to be configured.
  70. */
  71. #if IMAGE_BL31
  72. gicv3_driver_init(&versal_gic_data);
  73. #endif
  74. }
  75. /******************************************************************************
  76. * Versal common helper to initialize the GIC. Only invoked by BL31
  77. *****************************************************************************/
  78. void __init plat_versal_gic_init(void)
  79. {
  80. gicv3_distif_init();
  81. gicv3_rdistif_init(plat_my_core_pos());
  82. gicv3_cpuif_enable(plat_my_core_pos());
  83. }
  84. /******************************************************************************
  85. * Versal common helper to enable the GIC CPU interface
  86. *****************************************************************************/
  87. void plat_versal_gic_cpuif_enable(void)
  88. {
  89. gicv3_cpuif_enable(plat_my_core_pos());
  90. }
  91. /******************************************************************************
  92. * Versal common helper to disable the GIC CPU interface
  93. *****************************************************************************/
  94. void plat_versal_gic_cpuif_disable(void)
  95. {
  96. gicv3_cpuif_disable(plat_my_core_pos());
  97. }
  98. /******************************************************************************
  99. * Versal common helper to initialize the per-cpu redistributor interface in
  100. * GICv3
  101. *****************************************************************************/
  102. void plat_versal_gic_pcpu_init(void)
  103. {
  104. gicv3_rdistif_init(plat_my_core_pos());
  105. }
  106. /******************************************************************************
  107. * Versal common helpers to power GIC redistributor interface
  108. *****************************************************************************/
  109. void plat_versal_gic_redistif_on(void)
  110. {
  111. gicv3_rdistif_on(plat_my_core_pos());
  112. }
  113. void plat_versal_gic_redistif_off(void)
  114. {
  115. gicv3_rdistif_off(plat_my_core_pos());
  116. }
  117. /******************************************************************************
  118. * Versal common helper to save & restore the GICv3 on resume from system
  119. * suspend
  120. *****************************************************************************/
  121. void plat_versal_gic_save(void)
  122. {
  123. /*
  124. * If an ITS is available, save its context before
  125. * the Redistributor using:
  126. * gicv3_its_save_disable(gits_base, &its_ctx[i])
  127. * Additionnaly, an implementation-defined sequence may
  128. * be required to save the whole ITS state.
  129. */
  130. /*
  131. * Save the GIC Redistributors and ITS contexts before the
  132. * Distributor context. As we only handle SYSTEM SUSPEND API,
  133. * we only need to save the context of the CPU that is issuing
  134. * the SYSTEM SUSPEND call, i.e. the current CPU.
  135. */
  136. gicv3_rdistif_save(plat_my_core_pos(), &rdist_ctx);
  137. /* Save the GIC Distributor context */
  138. gicv3_distif_save(&dist_ctx);
  139. /*
  140. * From here, all the components of the GIC can be safely powered down
  141. * as long as there is an alternate way to handle wakeup interrupt
  142. * sources.
  143. */
  144. }
  145. void plat_versal_gic_resume(void)
  146. {
  147. /* Restore the GIC Distributor context */
  148. gicv3_distif_init_restore(&dist_ctx);
  149. /*
  150. * Restore the GIC Redistributor and ITS contexts after the
  151. * Distributor context. As we only handle SYSTEM SUSPEND API,
  152. * we only need to restore the context of the CPU that issued
  153. * the SYSTEM SUSPEND call.
  154. */
  155. gicv3_rdistif_init_restore(plat_my_core_pos(), &rdist_ctx);
  156. /*
  157. * If an ITS is available, restore its context after
  158. * the Redistributor using:
  159. * gicv3_its_restore(gits_base, &its_ctx[i])
  160. * An implementation-defined sequence may be required to
  161. * restore the whole ITS state. The ITS must also be
  162. * re-enabled after this sequence has been executed.
  163. */
  164. }