fvp_gicv3.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <platform_def.h>
  8. #include <common/debug.h>
  9. #include <common/interrupt_props.h>
  10. #include <drivers/arm/gicv3.h>
  11. #include <fconf_hw_config_getter.h>
  12. #include <lib/utils.h>
  13. #include <plat/arm/common/plat_arm.h>
  14. #include <plat/arm/common/fconf_sec_intr_config.h>
  15. #include <plat/common/platform.h>
  16. #if FVP_GICR_REGION_PROTECTION
  17. /* To indicate GICR region of the core initialized as Read-Write */
  18. static bool fvp_gicr_rw_region_init[PLATFORM_CORE_COUNT] = {false};
  19. #endif /* FVP_GICR_REGION_PROTECTION */
  20. /* The GICv3 driver only needs to be initialized in EL3 */
  21. static uintptr_t fvp_rdistif_base_addrs[PLATFORM_CORE_COUNT];
  22. /* Default GICR base address to be used for GICR probe. */
  23. static uint64_t fvp_gicr_base_addrs[2] = { 0U };
  24. /* List of zero terminated GICR frame addresses which CPUs will probe */
  25. static uint64_t *fvp_gicr_frames = fvp_gicr_base_addrs;
  26. #if !(SEC_INT_DESC_IN_FCONF && ((!defined(__aarch64__) && defined(IMAGE_BL32)) || \
  27. (defined(__aarch64__) && defined(IMAGE_BL31))))
  28. static const interrupt_prop_t fvp_interrupt_props[] = {
  29. PLAT_ARM_G1S_IRQ_PROPS(INTR_GROUP1S),
  30. PLAT_ARM_G0_IRQ_PROPS(INTR_GROUP0)
  31. };
  32. #endif
  33. /*
  34. * MPIDR hashing function for translating MPIDRs read from GICR_TYPER register
  35. * to core position.
  36. *
  37. * Calculating core position is dependent on MPIDR_EL1.MT bit. However, affinity
  38. * values read from GICR_TYPER don't have an MT field. To reuse the same
  39. * translation used for CPUs, we insert MT bit read from the PE's MPIDR into
  40. * that read from GICR_TYPER.
  41. *
  42. * Assumptions:
  43. *
  44. * - All CPUs implemented in the system have MPIDR_EL1.MT bit set;
  45. * - No CPUs implemented in the system use affinity level 3.
  46. */
  47. static unsigned int fvp_gicv3_mpidr_hash(u_register_t mpidr)
  48. {
  49. u_register_t temp_mpidr = mpidr;
  50. temp_mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);
  51. return plat_arm_calc_core_pos(temp_mpidr);
  52. }
  53. static gicv3_driver_data_t fvp_gic_data = {
  54. .rdistif_num = PLATFORM_CORE_COUNT,
  55. .rdistif_base_addrs = fvp_rdistif_base_addrs,
  56. .mpidr_to_core_pos = fvp_gicv3_mpidr_hash
  57. };
  58. /******************************************************************************
  59. * This function gets called per core to make its redistributor frame rw
  60. *****************************************************************************/
  61. static void fvp_gicv3_make_rdistrif_rw(void)
  62. {
  63. #if FVP_GICR_REGION_PROTECTION
  64. unsigned int core_pos = plat_my_core_pos();
  65. /* Make the redistributor frame RW if it is not done previously */
  66. if (fvp_gicr_rw_region_init[core_pos] != true) {
  67. int ret = xlat_change_mem_attributes(BASE_GICR_BASE +
  68. (core_pos * BASE_GICR_SIZE),
  69. BASE_GICR_SIZE,
  70. MT_EXECUTE_NEVER |
  71. MT_DEVICE | MT_RW |
  72. MT_SECURE);
  73. if (ret != 0) {
  74. ERROR("Failed to make redistributor frame \
  75. read write = %d\n", ret);
  76. panic();
  77. } else {
  78. fvp_gicr_rw_region_init[core_pos] = true;
  79. }
  80. }
  81. #else
  82. return;
  83. #endif /* FVP_GICR_REGION_PROTECTION */
  84. }
  85. void plat_arm_gic_driver_init(void)
  86. {
  87. fvp_gicv3_make_rdistrif_rw();
  88. /*
  89. * Get GICD and GICR base addressed through FCONF APIs.
  90. * FCONF is not supported in BL32 for FVP.
  91. */
  92. #if (!defined(__aarch64__) && defined(IMAGE_BL32)) || \
  93. (defined(__aarch64__) && defined(IMAGE_BL31))
  94. fvp_gic_data.gicd_base = (uintptr_t)FCONF_GET_PROPERTY(hw_config,
  95. gicv3_config,
  96. gicd_base);
  97. fvp_gicr_base_addrs[0] = FCONF_GET_PROPERTY(hw_config, gicv3_config,
  98. gicr_base);
  99. #if SEC_INT_DESC_IN_FCONF
  100. fvp_gic_data.interrupt_props = FCONF_GET_PROPERTY(hw_config,
  101. sec_intr_prop, descriptor);
  102. fvp_gic_data.interrupt_props_num = FCONF_GET_PROPERTY(hw_config,
  103. sec_intr_prop, count);
  104. #else
  105. fvp_gic_data.interrupt_props = fvp_interrupt_props;
  106. fvp_gic_data.interrupt_props_num = ARRAY_SIZE(fvp_interrupt_props);
  107. #endif
  108. #else
  109. fvp_gic_data.gicd_base = PLAT_ARM_GICD_BASE;
  110. fvp_gicr_base_addrs[0] = PLAT_ARM_GICR_BASE;
  111. fvp_gic_data.interrupt_props = fvp_interrupt_props;
  112. fvp_gic_data.interrupt_props_num = ARRAY_SIZE(fvp_interrupt_props);
  113. #endif
  114. /*
  115. * The GICv3 driver is initialized in EL3 and does not need
  116. * to be initialized again in SEL1. This is because the S-EL1
  117. * can use GIC system registers to manage interrupts and does
  118. * not need GIC interface base addresses to be configured.
  119. */
  120. #if (!defined(__aarch64__) && defined(IMAGE_BL32)) || \
  121. (defined(__aarch64__) && defined(IMAGE_BL31))
  122. gicv3_driver_init(&fvp_gic_data);
  123. if (gicv3_rdistif_probe((uintptr_t)fvp_gicr_base_addrs[0]) == -1) {
  124. ERROR("No GICR base frame found for Primary CPU\n");
  125. panic();
  126. }
  127. #endif
  128. }
  129. /******************************************************************************
  130. * Function to iterate over all GICR frames and discover the corresponding
  131. * per-cpu redistributor frame as well as initialize the corresponding
  132. * interface in GICv3.
  133. *****************************************************************************/
  134. void plat_arm_gic_pcpu_init(void)
  135. {
  136. int result;
  137. const uint64_t *plat_gicr_frames = fvp_gicr_frames;
  138. fvp_gicv3_make_rdistrif_rw();
  139. do {
  140. result = gicv3_rdistif_probe(*plat_gicr_frames);
  141. /* If the probe is successful, no need to proceed further */
  142. if (result == 0)
  143. break;
  144. plat_gicr_frames++;
  145. } while (*plat_gicr_frames != 0U);
  146. if (result == -1) {
  147. ERROR("No GICR base frame found for CPU 0x%lx\n", read_mpidr());
  148. panic();
  149. }
  150. gicv3_rdistif_init(plat_my_core_pos());
  151. }