gicv2.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
  3. * Portions copyright (c) 2021-2022, ProvenRun S.A.S. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef GICV2_H
  8. #define GICV2_H
  9. #include <drivers/arm/gic_common.h>
  10. #include <platform_def.h>
  11. /*******************************************************************************
  12. * GICv2 miscellaneous definitions
  13. ******************************************************************************/
  14. /* Interrupt group definitions */
  15. #define GICV2_INTR_GROUP0 U(0)
  16. #define GICV2_INTR_GROUP1 U(1)
  17. /* Interrupt IDs reported by the HPPIR and IAR registers */
  18. #define PENDING_G1_INTID U(1022)
  19. /* GICv2 can only target up to 8 PEs */
  20. #define GICV2_MAX_TARGET_PE U(8)
  21. /*******************************************************************************
  22. * GICv2 specific Distributor interface register offsets and constants.
  23. ******************************************************************************/
  24. #define GICD_ITARGETSR U(0x800)
  25. #define GICD_SGIR U(0xF00)
  26. #define GICD_CPENDSGIR U(0xF10)
  27. #define GICD_SPENDSGIR U(0xF20)
  28. /*
  29. * Some GICv2 implementations violate the specification and have this register
  30. * at a different address. Allow overriding it in platform_def.h as workaround.
  31. */
  32. #ifndef GICD_PIDR2_GICV2
  33. #define GICD_PIDR2_GICV2 U(0xFE8)
  34. #endif
  35. #define ITARGETSR_SHIFT 2
  36. #define GIC_TARGET_CPU_MASK U(0xff)
  37. #define CPENDSGIR_SHIFT 2
  38. #define SPENDSGIR_SHIFT CPENDSGIR_SHIFT
  39. #define SGIR_TGTLSTFLT_SHIFT 24
  40. #define SGIR_TGTLSTFLT_MASK U(0x3)
  41. #define SGIR_TGTLST_SHIFT 16
  42. #define SGIR_TGTLST_MASK U(0xff)
  43. #define SGIR_NSATT (U(0x1) << 15)
  44. #define SGIR_INTID_MASK ULL(0xf)
  45. #define SGIR_TGT_SPECIFIC U(0)
  46. #define GICV2_SGIR_VALUE(tgt_lst_flt, tgt, nsatt, intid) \
  47. ((((tgt_lst_flt) & SGIR_TGTLSTFLT_MASK) << SGIR_TGTLSTFLT_SHIFT) | \
  48. (((tgt) & SGIR_TGTLST_MASK) << SGIR_TGTLST_SHIFT) | \
  49. ((nsatt) ? SGIR_NSATT : U(0)) | \
  50. ((intid) & SGIR_INTID_MASK))
  51. /*******************************************************************************
  52. * GICv2 specific CPU interface register offsets and constants.
  53. ******************************************************************************/
  54. /* Physical CPU Interface registers */
  55. #define GICC_CTLR U(0x0)
  56. #define GICC_PMR U(0x4)
  57. #define GICC_BPR U(0x8)
  58. #define GICC_IAR U(0xC)
  59. #define GICC_EOIR U(0x10)
  60. #define GICC_RPR U(0x14)
  61. #define GICC_HPPIR U(0x18)
  62. #define GICC_AHPPIR U(0x28)
  63. #define GICC_IIDR U(0xFC)
  64. #define GICC_DIR U(0x1000)
  65. #define GICC_PRIODROP GICC_EOIR
  66. /* GICC_CTLR bit definitions */
  67. #define EOI_MODE_NS BIT_32(10)
  68. #define EOI_MODE_S BIT_32(9)
  69. #define IRQ_BYP_DIS_GRP1 BIT_32(8)
  70. #define FIQ_BYP_DIS_GRP1 BIT_32(7)
  71. #define IRQ_BYP_DIS_GRP0 BIT_32(6)
  72. #define FIQ_BYP_DIS_GRP0 BIT_32(5)
  73. #define CBPR BIT_32(4)
  74. #define FIQ_EN_SHIFT 3
  75. #define FIQ_EN_BIT BIT_32(FIQ_EN_SHIFT)
  76. #define ACK_CTL BIT_32(2)
  77. /* GICC_IIDR bit masks and shifts */
  78. #define GICC_IIDR_PID_SHIFT 20
  79. #define GICC_IIDR_ARCH_SHIFT 16
  80. #define GICC_IIDR_REV_SHIFT 12
  81. #define GICC_IIDR_IMP_SHIFT 0
  82. #define GICC_IIDR_PID_MASK U(0xfff)
  83. #define GICC_IIDR_ARCH_MASK U(0xf)
  84. #define GICC_IIDR_REV_MASK U(0xf)
  85. #define GICC_IIDR_IMP_MASK U(0xfff)
  86. /* HYP view virtual CPU Interface registers */
  87. #define GICH_CTL U(0x0)
  88. #define GICH_VTR U(0x4)
  89. #define GICH_ELRSR0 U(0x30)
  90. #define GICH_ELRSR1 U(0x34)
  91. #define GICH_APR0 U(0xF0)
  92. #define GICH_LR_BASE U(0x100)
  93. /* Virtual CPU Interface registers */
  94. #define GICV_CTL U(0x0)
  95. #define GICV_PRIMASK U(0x4)
  96. #define GICV_BP U(0x8)
  97. #define GICV_INTACK U(0xC)
  98. #define GICV_EOI U(0x10)
  99. #define GICV_RUNNINGPRI U(0x14)
  100. #define GICV_HIGHESTPEND U(0x18)
  101. #define GICV_DEACTIVATE U(0x1000)
  102. /* GICD_CTLR bit definitions */
  103. #define CTLR_ENABLE_G1_SHIFT 1
  104. #define CTLR_ENABLE_G1_MASK U(0x1)
  105. #define CTLR_ENABLE_G1_BIT BIT_32(CTLR_ENABLE_G1_SHIFT)
  106. /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
  107. #define INT_ID_MASK U(0x3ff)
  108. #ifndef __ASSEMBLER__
  109. #include <cdefs.h>
  110. #include <stdbool.h>
  111. #include <stdint.h>
  112. #include <common/interrupt_props.h>
  113. /*******************************************************************************
  114. * This structure describes some of the implementation defined attributes of
  115. * the GICv2 IP. It is used by the platform port to specify these attributes
  116. * in order to initialize the GICv2 driver. The attributes are described
  117. * below.
  118. *
  119. * The 'gicd_base' field contains the base address of the Distributor interface
  120. * programmer's view.
  121. *
  122. * The 'gicc_base' field contains the base address of the CPU Interface
  123. * programmer's view.
  124. *
  125. * The 'target_masks' is a pointer to an array containing 'target_masks_num'
  126. * elements. The GIC driver will populate the array with per-PE target mask to
  127. * use to when targeting interrupts.
  128. *
  129. * The 'interrupt_props' field is a pointer to an array that enumerates secure
  130. * interrupts and their properties. If this field is not NULL, both
  131. * 'g0_interrupt_array' and 'g1s_interrupt_array' fields are ignored.
  132. *
  133. * The 'interrupt_props_num' field contains the number of entries in the
  134. * 'interrupt_props' array. If this field is non-zero, 'g0_interrupt_num' is
  135. * ignored.
  136. ******************************************************************************/
  137. typedef struct gicv2_driver_data {
  138. uintptr_t gicd_base;
  139. uintptr_t gicc_base;
  140. unsigned int *target_masks;
  141. unsigned int target_masks_num;
  142. const interrupt_prop_t *interrupt_props;
  143. unsigned int interrupt_props_num;
  144. } gicv2_driver_data_t;
  145. /*******************************************************************************
  146. * Function prototypes
  147. ******************************************************************************/
  148. void gicv2_driver_init(const gicv2_driver_data_t *plat_driver_data);
  149. void gicv2_distif_init(void);
  150. void gicv2_pcpu_distif_init(void);
  151. void gicv2_cpuif_enable(void);
  152. void gicv2_cpuif_disable(void);
  153. unsigned int gicv2_is_fiq_enabled(void);
  154. unsigned int gicv2_get_pending_interrupt_type(void);
  155. unsigned int gicv2_get_pending_interrupt_id(void);
  156. unsigned int gicv2_acknowledge_interrupt(void);
  157. void gicv2_end_of_interrupt(unsigned int id);
  158. unsigned int gicv2_get_interrupt_group(unsigned int id);
  159. unsigned int gicv2_get_running_priority(void);
  160. void gicv2_set_pe_target_mask(unsigned int proc_num);
  161. unsigned int gicv2_get_interrupt_active(unsigned int id);
  162. void gicv2_enable_interrupt(unsigned int id);
  163. void gicv2_disable_interrupt(unsigned int id);
  164. void gicv2_set_interrupt_priority(unsigned int id, unsigned int priority);
  165. void gicv2_set_interrupt_group(unsigned int id, unsigned int group);
  166. void gicv2_raise_sgi(int sgi_num, bool ns, int proc_num);
  167. void gicv2_set_spi_routing(unsigned int id, int proc_num);
  168. void gicv2_set_interrupt_pending(unsigned int id);
  169. void gicv2_clear_interrupt_pending(unsigned int id);
  170. unsigned int gicv2_set_pmr(unsigned int mask);
  171. void gicv2_interrupt_set_cfg(unsigned int id, unsigned int cfg);
  172. #endif /* __ASSEMBLER__ */
  173. #endif /* GICV2_H */