plat_mt_gic.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2019, MediaTek Inc. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <common/bl_common.h>
  8. #include <common/debug.h>
  9. #include <drivers/arm/gicv3.h>
  10. #include <bl31/interrupt_mgmt.h>
  11. #include <mt_gic_v3.h>
  12. #include <mtk_plat_common.h>
  13. #include "../drivers/arm/gic/v3/gicv3_private.h"
  14. #include "plat_private.h"
  15. #include <plat/common/platform.h>
  16. #include <platform_def.h>
  17. #include <stdint.h>
  18. #include <stdio.h>
  19. uintptr_t rdistif_base_addrs[PLATFORM_CORE_COUNT];
  20. static uint32_t rdist_has_saved[PLATFORM_CORE_COUNT];
  21. /* we save and restore the GICv3 context on system suspend */
  22. gicv3_dist_ctx_t dist_ctx;
  23. static unsigned int mt_mpidr_to_core_pos(u_register_t mpidr)
  24. {
  25. return plat_core_pos_by_mpidr(mpidr);
  26. }
  27. gicv3_driver_data_t mt_gicv3_data = {
  28. .gicd_base = MT_GIC_BASE,
  29. .gicr_base = MT_GIC_RDIST_BASE,
  30. .rdistif_num = PLATFORM_CORE_COUNT,
  31. .rdistif_base_addrs = rdistif_base_addrs,
  32. .mpidr_to_core_pos = mt_mpidr_to_core_pos,
  33. };
  34. struct gic_chip_data {
  35. unsigned int saved_group;
  36. unsigned int saved_enable;
  37. unsigned int saved_conf0;
  38. unsigned int saved_conf1;
  39. unsigned int saved_grpmod;
  40. };
  41. static struct gic_chip_data gic_data;
  42. void clear_sec_pol_ctl_en(void)
  43. {
  44. unsigned int i;
  45. /* total 19 polarity ctrl registers */
  46. for (i = 0; i <= NR_INT_POL_CTL - 1; i++) {
  47. mmio_write_32((SEC_POL_CTL_EN0 + (i * 4)), 0);
  48. }
  49. dsb();
  50. }
  51. void mt_gic_driver_init(void)
  52. {
  53. gicv3_driver_init(&mt_gicv3_data);
  54. }
  55. void mt_gic_set_pending(uint32_t irq)
  56. {
  57. gicv3_set_interrupt_pending(irq, plat_my_core_pos());
  58. }
  59. void mt_gic_cpuif_enable(void)
  60. {
  61. gicv3_cpuif_enable(plat_my_core_pos());
  62. }
  63. void mt_gic_cpuif_disable(void)
  64. {
  65. gicv3_cpuif_disable(plat_my_core_pos());
  66. }
  67. void mt_gic_rdistif_init(void)
  68. {
  69. unsigned int proc_num;
  70. unsigned int index;
  71. uintptr_t gicr_base;
  72. proc_num = plat_my_core_pos();
  73. gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
  74. /* set all SGI/PPI as non-secure GROUP1 by default */
  75. mmio_write_32(gicr_base + GICR_IGROUPR0, ~0U);
  76. mmio_write_32(gicr_base + GICR_IGRPMODR0, 0x0);
  77. /* setup the default PPI/SGI priorities */
  78. for (index = 0; index < TOTAL_PCPU_INTR_NUM; index += 4U)
  79. gicr_write_ipriorityr(gicr_base, index,
  80. GICD_IPRIORITYR_DEF_VAL);
  81. }
  82. void mt_gic_distif_save(void)
  83. {
  84. gicv3_distif_save(&dist_ctx);
  85. }
  86. void mt_gic_distif_restore(void)
  87. {
  88. gicv3_distif_init_restore(&dist_ctx);
  89. }
  90. void mt_gic_rdistif_save(void)
  91. {
  92. unsigned int proc_num;
  93. uintptr_t gicr_base;
  94. proc_num = plat_my_core_pos();
  95. gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
  96. gic_data.saved_group = mmio_read_32(gicr_base + GICR_IGROUPR0);
  97. gic_data.saved_enable = mmio_read_32(gicr_base + GICR_ISENABLER0);
  98. gic_data.saved_conf0 = mmio_read_32(gicr_base + GICR_ICFGR0);
  99. gic_data.saved_conf1 = mmio_read_32(gicr_base + GICR_ICFGR1);
  100. gic_data.saved_grpmod = mmio_read_32(gicr_base + GICR_IGRPMODR0);
  101. rdist_has_saved[proc_num] = 1;
  102. }
  103. void mt_gic_rdistif_restore(void)
  104. {
  105. unsigned int proc_num;
  106. uintptr_t gicr_base;
  107. proc_num = plat_my_core_pos();
  108. if (rdist_has_saved[proc_num] == 1) {
  109. gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
  110. mmio_write_32(gicr_base + GICR_IGROUPR0, gic_data.saved_group);
  111. mmio_write_32(gicr_base + GICR_ISENABLER0, gic_data.saved_enable);
  112. mmio_write_32(gicr_base + GICR_ICFGR0, gic_data.saved_conf0);
  113. mmio_write_32(gicr_base + GICR_ICFGR1, gic_data.saved_conf1);
  114. mmio_write_32(gicr_base + GICR_IGRPMODR0, gic_data.saved_grpmod);
  115. }
  116. }
  117. void mt_gic_sync_dcm_enable(void)
  118. {
  119. mmio_clrsetbits_32(GIC_SYNC_DCM, GIC_SYNC_DCM_MASK, GIC_SYNC_DCM_ON);
  120. }
  121. void mt_gic_sync_dcm_disable(void)
  122. {
  123. mmio_clrsetbits_32(GIC_SYNC_DCM, GIC_SYNC_DCM_MASK, GIC_SYNC_DCM_OFF);
  124. }
  125. void mt_gic_init(void)
  126. {
  127. gicv3_distif_init();
  128. gicv3_cpuif_enable(plat_my_core_pos());
  129. mt_gic_rdistif_init();
  130. clear_sec_pol_ctl_en();
  131. }