gicv3.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /*
  2. * Copyright (c) 2015-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef GICV3_H
  7. #define GICV3_H
  8. /*******************************************************************************
  9. * GICv3 and 3.1 miscellaneous definitions
  10. ******************************************************************************/
  11. /* Interrupt group definitions */
  12. #define INTR_GROUP1S U(0)
  13. #define INTR_GROUP0 U(1)
  14. #define INTR_GROUP1NS U(2)
  15. /* Interrupt IDs reported by the HPPIR and IAR registers */
  16. #define PENDING_G1S_INTID U(1020)
  17. #define PENDING_G1NS_INTID U(1021)
  18. /* Constant to categorize LPI interrupt */
  19. #define MIN_LPI_ID U(8192)
  20. /* GICv3 can only target up to 16 PEs with SGI */
  21. #define GICV3_MAX_SGI_TARGETS U(16)
  22. /* PPIs INTIDs 16-31 */
  23. #define MAX_PPI_ID U(31)
  24. #if GIC_EXT_INTID
  25. /* GICv3.1 extended PPIs INTIDs 1056-1119 */
  26. #define MIN_EPPI_ID U(1056)
  27. #define MAX_EPPI_ID U(1119)
  28. /* Total number of GICv3.1 EPPIs */
  29. #define TOTAL_EPPI_INTR_NUM (MAX_EPPI_ID - MIN_EPPI_ID + U(1))
  30. /* Total number of GICv3.1 PPIs and EPPIs */
  31. #define TOTAL_PRIVATE_INTR_NUM (TOTAL_PCPU_INTR_NUM + TOTAL_EPPI_INTR_NUM)
  32. /* GICv3.1 extended SPIs INTIDs 4096 - 5119 */
  33. #define MIN_ESPI_ID U(4096)
  34. #define MAX_ESPI_ID U(5119)
  35. /* Total number of GICv3.1 ESPIs */
  36. #define TOTAL_ESPI_INTR_NUM (MAX_ESPI_ID - MIN_ESPI_ID + U(1))
  37. /* Total number of GICv3.1 SPIs and ESPIs */
  38. #define TOTAL_SHARED_INTR_NUM (TOTAL_SPI_INTR_NUM + TOTAL_ESPI_INTR_NUM)
  39. /* SGIs: 0-15, PPIs: 16-31, EPPIs: 1056-1119 */
  40. #define IS_SGI_PPI(id) (((id) <= MAX_PPI_ID) || \
  41. (((id) >= MIN_EPPI_ID) && \
  42. ((id) <= MAX_EPPI_ID)))
  43. /* SPIs: 32-1019, ESPIs: 4096-5119 */
  44. #define IS_SPI(id) ((((id) >= MIN_SPI_ID) && \
  45. ((id) <= MAX_SPI_ID)) || \
  46. (((id) >= MIN_ESPI_ID) && \
  47. ((id) <= MAX_ESPI_ID)))
  48. #else /* GICv3 */
  49. /* Total number of GICv3 PPIs */
  50. #define TOTAL_PRIVATE_INTR_NUM TOTAL_PCPU_INTR_NUM
  51. /* Total number of GICv3 SPIs */
  52. #define TOTAL_SHARED_INTR_NUM TOTAL_SPI_INTR_NUM
  53. /* SGIs: 0-15, PPIs: 16-31 */
  54. #define IS_SGI_PPI(id) ((id) <= MAX_PPI_ID)
  55. /* SPIs: 32-1019 */
  56. #define IS_SPI(id) (((id) >= MIN_SPI_ID) && ((id) <= MAX_SPI_ID))
  57. #endif /* GIC_EXT_INTID */
  58. #define GIC_REV(r, p) ((r << 4) | p)
  59. /*******************************************************************************
  60. * GICv3 and 3.1 specific Distributor interface register offsets and constants
  61. ******************************************************************************/
  62. #define GICD_TYPER2 U(0x0c)
  63. #define GICD_STATUSR U(0x10)
  64. #define GICD_SETSPI_NSR U(0x40)
  65. #define GICD_CLRSPI_NSR U(0x48)
  66. #define GICD_SETSPI_SR U(0x50)
  67. #define GICD_CLRSPI_SR U(0x58)
  68. #define GICD_IGRPMODR U(0xd00)
  69. #define GICD_IGROUPRE U(0x1000)
  70. #define GICD_ISENABLERE U(0x1200)
  71. #define GICD_ICENABLERE U(0x1400)
  72. #define GICD_ISPENDRE U(0x1600)
  73. #define GICD_ICPENDRE U(0x1800)
  74. #define GICD_ISACTIVERE U(0x1a00)
  75. #define GICD_ICACTIVERE U(0x1c00)
  76. #define GICD_IPRIORITYRE U(0x2000)
  77. #define GICD_ICFGRE U(0x3000)
  78. #define GICD_IGRPMODRE U(0x3400)
  79. #define GICD_NSACRE U(0x3600)
  80. /*
  81. * GICD_IROUTER<n> register is at 0x6000 + 8n, where n is the interrupt ID
  82. * and n >= 32, making the effective offset as 0x6100
  83. */
  84. #define GICD_IROUTER U(0x6000)
  85. #define GICD_IROUTERE U(0x8000)
  86. #define GICD_PIDR0_GICV3 U(0xffe0)
  87. #define GICD_PIDR1_GICV3 U(0xffe4)
  88. #define GICD_PIDR2_GICV3 U(0xffe8)
  89. #define IGRPMODR_SHIFT 5
  90. /* GICD_CTLR bit definitions */
  91. #define CTLR_ENABLE_G1NS_SHIFT 1
  92. #define CTLR_ENABLE_G1S_SHIFT 2
  93. #define CTLR_ARE_S_SHIFT 4
  94. #define CTLR_ARE_NS_SHIFT 5
  95. #define CTLR_DS_SHIFT 6
  96. #define CTLR_E1NWF_SHIFT 7
  97. #define GICD_CTLR_RWP_SHIFT 31
  98. #define CTLR_ENABLE_G1NS_MASK U(0x1)
  99. #define CTLR_ENABLE_G1S_MASK U(0x1)
  100. #define CTLR_ARE_S_MASK U(0x1)
  101. #define CTLR_ARE_NS_MASK U(0x1)
  102. #define CTLR_DS_MASK U(0x1)
  103. #define CTLR_E1NWF_MASK U(0x1)
  104. #define GICD_CTLR_RWP_MASK U(0x1)
  105. #define CTLR_ENABLE_G1NS_BIT BIT_32(CTLR_ENABLE_G1NS_SHIFT)
  106. #define CTLR_ENABLE_G1S_BIT BIT_32(CTLR_ENABLE_G1S_SHIFT)
  107. #define CTLR_ARE_S_BIT BIT_32(CTLR_ARE_S_SHIFT)
  108. #define CTLR_ARE_NS_BIT BIT_32(CTLR_ARE_NS_SHIFT)
  109. #define CTLR_DS_BIT BIT_32(CTLR_DS_SHIFT)
  110. #define CTLR_E1NWF_BIT BIT_32(CTLR_E1NWF_SHIFT)
  111. #define GICD_CTLR_RWP_BIT BIT_32(GICD_CTLR_RWP_SHIFT)
  112. /* GICD_IROUTER shifts and masks */
  113. #define IROUTER_SHIFT 0
  114. #define IROUTER_IRM_SHIFT 31
  115. #define IROUTER_IRM_MASK U(0x1)
  116. #define GICV3_IRM_PE U(0)
  117. #define GICV3_IRM_ANY U(1)
  118. #define NUM_OF_DIST_REGS 30
  119. /* GICD_TYPER shifts and masks */
  120. #define TYPER_ESPI U(1 << 8)
  121. #define TYPER_DVIS U(1 << 18)
  122. #define TYPER_ESPI_RANGE_MASK U(0x1f)
  123. #define TYPER_ESPI_RANGE_SHIFT U(27)
  124. #define TYPER_ESPI_RANGE U(TYPER_ESPI_MASK << TYPER_ESPI_SHIFT)
  125. /*******************************************************************************
  126. * Common GIC Redistributor interface registers & constants
  127. ******************************************************************************/
  128. #define GICR_V4_PCPUBASE_SHIFT 0x12
  129. #define GICR_V3_PCPUBASE_SHIFT 0x11
  130. #define GICR_SGIBASE_OFFSET U(65536) /* 64 KB */
  131. #define GICR_CTLR U(0x0)
  132. #define GICR_IIDR U(0x04)
  133. #define GICR_TYPER U(0x08)
  134. #define GICR_STATUSR U(0x10)
  135. #define GICR_WAKER U(0x14)
  136. #define GICR_PROPBASER U(0x70)
  137. #define GICR_PENDBASER U(0x78)
  138. #define GICR_IGROUPR0 (GICR_SGIBASE_OFFSET + U(0x80))
  139. #define GICR_ISENABLER0 (GICR_SGIBASE_OFFSET + U(0x100))
  140. #define GICR_ICENABLER0 (GICR_SGIBASE_OFFSET + U(0x180))
  141. #define GICR_ISPENDR0 (GICR_SGIBASE_OFFSET + U(0x200))
  142. #define GICR_ICPENDR0 (GICR_SGIBASE_OFFSET + U(0x280))
  143. #define GICR_ISACTIVER0 (GICR_SGIBASE_OFFSET + U(0x300))
  144. #define GICR_ICACTIVER0 (GICR_SGIBASE_OFFSET + U(0x380))
  145. #define GICR_IPRIORITYR (GICR_SGIBASE_OFFSET + U(0x400))
  146. #define GICR_ICFGR0 (GICR_SGIBASE_OFFSET + U(0xc00))
  147. #define GICR_ICFGR1 (GICR_SGIBASE_OFFSET + U(0xc04))
  148. #define GICR_IGRPMODR0 (GICR_SGIBASE_OFFSET + U(0xd00))
  149. #define GICR_NSACR (GICR_SGIBASE_OFFSET + U(0xe00))
  150. #define GICR_IGROUPR GICR_IGROUPR0
  151. #define GICR_ISENABLER GICR_ISENABLER0
  152. #define GICR_ICENABLER GICR_ICENABLER0
  153. #define GICR_ISPENDR GICR_ISPENDR0
  154. #define GICR_ICPENDR GICR_ICPENDR0
  155. #define GICR_ISACTIVER GICR_ISACTIVER0
  156. #define GICR_ICACTIVER GICR_ICACTIVER0
  157. #define GICR_ICFGR GICR_ICFGR0
  158. #define GICR_IGRPMODR GICR_IGRPMODR0
  159. /* GICR_CTLR bit definitions */
  160. #define GICR_CTLR_UWP_SHIFT 31
  161. #define GICR_CTLR_UWP_MASK U(0x1)
  162. #define GICR_CTLR_UWP_BIT BIT_32(GICR_CTLR_UWP_SHIFT)
  163. #define GICR_CTLR_DPG1S_SHIFT 26
  164. #define GICR_CTLR_DPG1S_MASK U(0x1)
  165. #define GICR_CTLR_DPG1S_BIT BIT_32(GICR_CTLR_DPG1S_SHIFT)
  166. #define GICR_CTLR_DPG1NS_SHIFT 25
  167. #define GICR_CTLR_DPG1NS_MASK U(0x1)
  168. #define GICR_CTLR_DPG1NS_BIT BIT_32(GICR_CTLR_DPG1NS_SHIFT)
  169. #define GICR_CTLR_DPG0_SHIFT 24
  170. #define GICR_CTLR_DPG0_MASK U(0x1)
  171. #define GICR_CTLR_DPG0_BIT BIT_32(GICR_CTLR_DPG0_SHIFT)
  172. #define GICR_CTLR_RWP_SHIFT 3
  173. #define GICR_CTLR_RWP_MASK U(0x1)
  174. #define GICR_CTLR_RWP_BIT BIT_32(GICR_CTLR_RWP_SHIFT)
  175. #define GICR_CTLR_EN_LPIS_BIT BIT_32(0)
  176. /* GICR_WAKER bit definitions */
  177. #define WAKER_CA_SHIFT 2
  178. #define WAKER_PS_SHIFT 1
  179. #define WAKER_CA_MASK U(0x1)
  180. #define WAKER_PS_MASK U(0x1)
  181. #define WAKER_CA_BIT BIT_32(WAKER_CA_SHIFT)
  182. #define WAKER_PS_BIT BIT_32(WAKER_PS_SHIFT)
  183. /* GICR_TYPER bit definitions */
  184. #define TYPER_AFF_VAL_SHIFT 32
  185. #define TYPER_PROC_NUM_SHIFT 8
  186. #define TYPER_LAST_SHIFT 4
  187. #define TYPER_VLPI_SHIFT 1
  188. #define TYPER_AFF_VAL_MASK U(0xffffffff)
  189. #define TYPER_PROC_NUM_MASK U(0xffff)
  190. #define TYPER_LAST_MASK U(0x1)
  191. #define TYPER_LAST_BIT BIT_32(TYPER_LAST_SHIFT)
  192. #define TYPER_VLPI_BIT BIT_32(TYPER_VLPI_SHIFT)
  193. #define TYPER_PPI_NUM_SHIFT U(27)
  194. #define TYPER_PPI_NUM_MASK U(0x1f)
  195. /* GICR_IIDR bit definitions */
  196. #define IIDR_PRODUCT_ID_MASK U(0xff)
  197. #define IIDR_VARIANT_MASK U(0xf)
  198. #define IIDR_REV_MASK U(0xf)
  199. #define IIDR_IMPLEMENTER_MASK U(0xfff)
  200. #define IIDR_PRODUCT_ID_SHIFT 24
  201. #define IIDR_VARIANT_SHIFT 16
  202. #define IIDR_REV_SHIFT 12
  203. #define IIDR_IMPLEMENTER_SHIFT 0
  204. #define IIDR_PRODUCT_ID_BIT BIT_32(IIDR_PRODUCT_ID_SHIFT)
  205. #define IIDR_VARIANT_BIT BIT_32(IIDR_VARIANT_SHIFT)
  206. #define IIDR_REV_BIT BIT_32(IIDR_REVISION_SHIFT)
  207. #define IIDR_IMPLEMENTER_BIT BIT_32(IIDR_IMPLEMENTER_SHIFT)
  208. #define IIDR_MODEL_MASK (IIDR_PRODUCT_ID_MASK << IIDR_PRODUCT_ID_SHIFT | \
  209. IIDR_IMPLEMENTER_MASK << IIDR_IMPLEMENTER_SHIFT)
  210. #define GIC_PRODUCT_ID_GIC600 U(0x2)
  211. #define GIC_PRODUCT_ID_GIC600AE U(0x3)
  212. #define GIC_PRODUCT_ID_GIC700 U(0x4)
  213. /*
  214. * Note that below revisions and variants definations are as per GIC600/GIC600AE
  215. * specification.
  216. */
  217. #define GIC_REV_P0 U(0x1)
  218. #define GIC_REV_P1 U(0x3)
  219. #define GIC_REV_P2 U(0x4)
  220. #define GIC_REV_P3 U(0x5)
  221. #define GIC_REV_P4 U(0x6)
  222. #define GIC_REV_P6 U(0x7)
  223. #define GIC_VARIANT_R0 U(0x0)
  224. #define GIC_VARIANT_R1 U(0x1)
  225. #define GIC_VARIANT_R2 U(0x2)
  226. /*******************************************************************************
  227. * GICv3 and 3.1 CPU interface registers & constants
  228. ******************************************************************************/
  229. /* ICC_SRE bit definitions */
  230. #define ICC_SRE_EN_BIT BIT_32(3)
  231. #define ICC_SRE_DIB_BIT BIT_32(2)
  232. #define ICC_SRE_DFB_BIT BIT_32(1)
  233. #define ICC_SRE_SRE_BIT BIT_32(0)
  234. /* ICC_IGRPEN1_EL3 bit definitions */
  235. #define IGRPEN1_EL3_ENABLE_G1NS_SHIFT 0
  236. #define IGRPEN1_EL3_ENABLE_G1S_SHIFT 1
  237. #define IGRPEN1_EL3_ENABLE_G1NS_BIT BIT_32(IGRPEN1_EL3_ENABLE_G1NS_SHIFT)
  238. #define IGRPEN1_EL3_ENABLE_G1S_BIT BIT_32(IGRPEN1_EL3_ENABLE_G1S_SHIFT)
  239. /* ICC_IGRPEN0_EL1 bit definitions */
  240. #define IGRPEN1_EL1_ENABLE_G0_SHIFT 0
  241. #define IGRPEN1_EL1_ENABLE_G0_BIT BIT_32(IGRPEN1_EL1_ENABLE_G0_SHIFT)
  242. /* ICC_HPPIR0_EL1 bit definitions */
  243. #define HPPIR0_EL1_INTID_SHIFT 0
  244. #define HPPIR0_EL1_INTID_MASK U(0xffffff)
  245. /* ICC_HPPIR1_EL1 bit definitions */
  246. #define HPPIR1_EL1_INTID_SHIFT 0
  247. #define HPPIR1_EL1_INTID_MASK U(0xffffff)
  248. /* ICC_IAR0_EL1 bit definitions */
  249. #define IAR0_EL1_INTID_SHIFT 0
  250. #define IAR0_EL1_INTID_MASK U(0xffffff)
  251. /* ICC_IAR1_EL1 bit definitions */
  252. #define IAR1_EL1_INTID_SHIFT 0
  253. #define IAR1_EL1_INTID_MASK U(0xffffff)
  254. /* ICC SGI macros */
  255. #define SGIR_TGT_MASK ULL(0xffff)
  256. #define SGIR_AFF1_SHIFT 16
  257. #define SGIR_INTID_SHIFT 24
  258. #define SGIR_INTID_MASK ULL(0xf)
  259. #define SGIR_AFF2_SHIFT 32
  260. #define SGIR_IRM_SHIFT 40
  261. #define SGIR_IRM_MASK ULL(0x1)
  262. #define SGIR_AFF3_SHIFT 48
  263. #define SGIR_AFF_MASK ULL(0xff)
  264. #define SGIR_IRM_TO_AFF U(0)
  265. #define GICV3_SGIR_VALUE(_aff3, _aff2, _aff1, _intid, _irm, _tgt) \
  266. ((((uint64_t) (_aff3) & SGIR_AFF_MASK) << SGIR_AFF3_SHIFT) | \
  267. (((uint64_t) (_irm) & SGIR_IRM_MASK) << SGIR_IRM_SHIFT) | \
  268. (((uint64_t) (_aff2) & SGIR_AFF_MASK) << SGIR_AFF2_SHIFT) | \
  269. (((_intid) & SGIR_INTID_MASK) << SGIR_INTID_SHIFT) | \
  270. (((_aff1) & SGIR_AFF_MASK) << SGIR_AFF1_SHIFT) | \
  271. ((_tgt) & SGIR_TGT_MASK))
  272. /*****************************************************************************
  273. * GICv3 and 3.1 ITS registers and constants
  274. *****************************************************************************/
  275. #define GITS_CTLR U(0x0)
  276. #define GITS_IIDR U(0x4)
  277. #define GITS_TYPER U(0x8)
  278. #define GITS_CBASER U(0x80)
  279. #define GITS_CWRITER U(0x88)
  280. #define GITS_CREADR U(0x90)
  281. #define GITS_BASER U(0x100)
  282. /* GITS_CTLR bit definitions */
  283. #define GITS_CTLR_ENABLED_BIT BIT_32(0)
  284. #define GITS_CTLR_QUIESCENT_BIT BIT_32(1)
  285. #define GITS_TYPER_VSGI BIT_64(39)
  286. #ifndef __ASSEMBLER__
  287. #include <stdbool.h>
  288. #include <stdint.h>
  289. #include <arch_helpers.h>
  290. #include <common/interrupt_props.h>
  291. #include <drivers/arm/gic_common.h>
  292. #include <lib/utils_def.h>
  293. typedef enum {
  294. GICV3_G1S,
  295. GICV3_G1NS,
  296. GICV3_G0
  297. } gicv3_irq_group_t;
  298. static inline uintptr_t gicv3_redist_size(uint64_t typer_val)
  299. {
  300. #if GIC_ENABLE_V4_EXTN
  301. if ((typer_val & TYPER_VLPI_BIT) != 0U) {
  302. return 1U << GICR_V4_PCPUBASE_SHIFT;
  303. } else {
  304. return 1U << GICR_V3_PCPUBASE_SHIFT;
  305. }
  306. #else
  307. return 1U << GICR_V3_PCPUBASE_SHIFT;
  308. #endif
  309. }
  310. unsigned int gicv3_get_component_partnum(const uintptr_t gic_frame);
  311. static inline bool gicv3_is_intr_id_special_identifier(unsigned int id)
  312. {
  313. return (id >= PENDING_G1S_INTID) && (id <= GIC_SPURIOUS_INTERRUPT);
  314. }
  315. /*******************************************************************************
  316. * Helper GICv3 and 3.1 macros for SEL1
  317. ******************************************************************************/
  318. static inline uint32_t gicv3_acknowledge_interrupt_sel1(void)
  319. {
  320. return (uint32_t)read_icc_iar1_el1() & IAR1_EL1_INTID_MASK;
  321. }
  322. static inline uint32_t gicv3_get_pending_interrupt_id_sel1(void)
  323. {
  324. return (uint32_t)read_icc_hppir1_el1() & HPPIR1_EL1_INTID_MASK;
  325. }
  326. static inline void gicv3_end_of_interrupt_sel1(unsigned int id)
  327. {
  328. /*
  329. * Interrupt request deassertion from peripheral to GIC happens
  330. * by clearing interrupt condition by a write to the peripheral
  331. * register. It is desired that the write transfer is complete
  332. * before the core tries to change GIC state from 'AP/Active' to
  333. * a new state on seeing 'EOI write'.
  334. * Since ICC interface writes are not ordered against Device
  335. * memory writes, a barrier is required to ensure the ordering.
  336. * The dsb will also ensure *completion* of previous writes with
  337. * DEVICE nGnRnE attribute.
  338. */
  339. dsbishst();
  340. write_icc_eoir1_el1(id);
  341. }
  342. /*******************************************************************************
  343. * Helper GICv3 macros for EL3
  344. ******************************************************************************/
  345. static inline uint32_t gicv3_acknowledge_interrupt(void)
  346. {
  347. return (uint32_t)read_icc_iar0_el1() & IAR0_EL1_INTID_MASK;
  348. }
  349. static inline void gicv3_end_of_interrupt(unsigned int id)
  350. {
  351. /*
  352. * Interrupt request deassertion from peripheral to GIC happens
  353. * by clearing interrupt condition by a write to the peripheral
  354. * register. It is desired that the write transfer is complete
  355. * before the core tries to change GIC state from 'AP/Active' to
  356. * a new state on seeing 'EOI write'.
  357. * Since ICC interface writes are not ordered against Device
  358. * memory writes, a barrier is required to ensure the ordering.
  359. * The dsb will also ensure *completion* of previous writes with
  360. * DEVICE nGnRnE attribute.
  361. */
  362. dsbishst();
  363. return write_icc_eoir0_el1(id);
  364. }
  365. /*
  366. * This macro returns the total number of GICD/GICR registers corresponding to
  367. * the register name
  368. */
  369. #define GICD_NUM_REGS(reg_name) \
  370. DIV_ROUND_UP_2EVAL(TOTAL_SHARED_INTR_NUM, (1 << reg_name##_SHIFT))
  371. #define GICR_NUM_REGS(reg_name) \
  372. DIV_ROUND_UP_2EVAL(TOTAL_PRIVATE_INTR_NUM, (1 << reg_name##_SHIFT))
  373. /* Interrupt ID mask for HPPIR, AHPPIR, IAR and AIAR CPU Interface registers */
  374. #define INT_ID_MASK U(0xffffff)
  375. /*******************************************************************************
  376. * This structure describes some of the implementation defined attributes of the
  377. * GICv3 IP. It is used by the platform port to specify these attributes in order
  378. * to initialise the GICV3 driver. The attributes are described below.
  379. *
  380. * The 'gicd_base' field contains the base address of the Distributor interface
  381. * programmer's view.
  382. *
  383. * The 'gicr_base' field contains the base address of the Re-distributor
  384. * interface programmer's view.
  385. *
  386. * The 'interrupt_props' field is a pointer to an array that enumerates secure
  387. * interrupts and their properties. If this field is not NULL, both
  388. * 'g0_interrupt_array' and 'g1s_interrupt_array' fields are ignored.
  389. *
  390. * The 'interrupt_props_num' field contains the number of entries in the
  391. * 'interrupt_props' array. If this field is non-zero, both 'g0_interrupt_num'
  392. * and 'g1s_interrupt_num' are ignored.
  393. *
  394. * The 'rdistif_num' field contains the number of Redistributor interfaces the
  395. * GIC implements. This is equal to the number of CPUs or CPU interfaces
  396. * instantiated in the GIC.
  397. *
  398. * The 'rdistif_base_addrs' field is a pointer to an array that has an entry for
  399. * storing the base address of the Redistributor interface frame of each CPU in
  400. * the system. The size of the array = 'rdistif_num'. The base addresses are
  401. * detected during driver initialisation.
  402. *
  403. * The 'mpidr_to_core_pos' field is a pointer to a hash function which the
  404. * driver will use to convert an MPIDR value to a linear core index. This index
  405. * will be used for accessing the 'rdistif_base_addrs' array. This is an
  406. * optional field. A GICv3 implementation maps each MPIDR to a linear core index
  407. * as well. This mapping can be found by reading the "Affinity Value" and
  408. * "Processor Number" fields in the GICR_TYPER. It is IMP. DEF. if the
  409. * "Processor Numbers" are suitable to index into an array to access core
  410. * specific information. If this not the case, the platform port must provide a
  411. * hash function. Otherwise, the "Processor Number" field will be used to access
  412. * the array elements.
  413. ******************************************************************************/
  414. typedef unsigned int (*mpidr_hash_fn)(u_register_t mpidr);
  415. typedef struct gicv3_driver_data {
  416. uintptr_t gicd_base;
  417. uintptr_t gicr_base;
  418. const interrupt_prop_t *interrupt_props;
  419. unsigned int interrupt_props_num;
  420. unsigned int rdistif_num;
  421. uintptr_t *rdistif_base_addrs;
  422. mpidr_hash_fn mpidr_to_core_pos;
  423. } gicv3_driver_data_t;
  424. typedef struct gicv3_redist_ctx {
  425. /* 64 bits registers */
  426. uint64_t gicr_propbaser;
  427. uint64_t gicr_pendbaser;
  428. /* 32 bits registers */
  429. uint32_t gicr_ctlr;
  430. uint32_t gicr_igroupr[GICR_NUM_REGS(IGROUPR)];
  431. uint32_t gicr_isenabler[GICR_NUM_REGS(ISENABLER)];
  432. uint32_t gicr_ispendr[GICR_NUM_REGS(ISPENDR)];
  433. uint32_t gicr_isactiver[GICR_NUM_REGS(ISACTIVER)];
  434. uint32_t gicr_ipriorityr[GICR_NUM_REGS(IPRIORITYR)];
  435. uint32_t gicr_icfgr[GICR_NUM_REGS(ICFGR)];
  436. uint32_t gicr_igrpmodr[GICR_NUM_REGS(IGRPMODR)];
  437. uint32_t gicr_nsacr;
  438. } gicv3_redist_ctx_t;
  439. typedef struct gicv3_dist_ctx {
  440. /* 64 bits registers */
  441. uint64_t gicd_irouter[TOTAL_SHARED_INTR_NUM];
  442. /* 32 bits registers */
  443. uint32_t gicd_ctlr;
  444. uint32_t gicd_igroupr[GICD_NUM_REGS(IGROUPR)];
  445. uint32_t gicd_isenabler[GICD_NUM_REGS(ISENABLER)];
  446. uint32_t gicd_ispendr[GICD_NUM_REGS(ISPENDR)];
  447. uint32_t gicd_isactiver[GICD_NUM_REGS(ISACTIVER)];
  448. uint32_t gicd_ipriorityr[GICD_NUM_REGS(IPRIORITYR)];
  449. uint32_t gicd_icfgr[GICD_NUM_REGS(ICFGR)];
  450. uint32_t gicd_igrpmodr[GICD_NUM_REGS(IGRPMODR)];
  451. uint32_t gicd_nsacr[GICD_NUM_REGS(NSACR)];
  452. } gicv3_dist_ctx_t;
  453. typedef struct gicv3_its_ctx {
  454. /* 64 bits registers */
  455. uint64_t gits_cbaser;
  456. uint64_t gits_cwriter;
  457. uint64_t gits_baser[8];
  458. /* 32 bits registers */
  459. uint32_t gits_ctlr;
  460. } gicv3_its_ctx_t;
  461. /*******************************************************************************
  462. * GICv3 EL3 driver API
  463. ******************************************************************************/
  464. void gicv3_driver_init(const gicv3_driver_data_t *plat_driver_data);
  465. int gicv3_rdistif_probe(const uintptr_t gicr_frame);
  466. void gicv3_distif_init(void);
  467. void gicv3_rdistif_init(unsigned int proc_num);
  468. void gicv3_rdistif_on(unsigned int proc_num);
  469. void gicv3_rdistif_off(unsigned int proc_num);
  470. unsigned int gicv3_rdistif_get_number_frames(const uintptr_t gicr_frame);
  471. void gicv3_cpuif_enable(unsigned int proc_num);
  472. void gicv3_cpuif_disable(unsigned int proc_num);
  473. unsigned int gicv3_get_pending_interrupt_type(void);
  474. unsigned int gicv3_get_pending_interrupt_id(void);
  475. unsigned int gicv3_get_interrupt_group(unsigned int id,
  476. unsigned int proc_num);
  477. void gicv3_distif_init_restore(const gicv3_dist_ctx_t * const dist_ctx);
  478. void gicv3_distif_save(gicv3_dist_ctx_t * const dist_ctx);
  479. /*
  480. * gicv3_distif_post_restore and gicv3_distif_pre_save must be implemented if
  481. * gicv3_distif_save and gicv3_rdistif_init_restore are used. If no
  482. * implementation-defined sequence is needed at these steps, an empty function
  483. * can be provided.
  484. */
  485. void gicv3_distif_post_restore(unsigned int proc_num);
  486. void gicv3_distif_pre_save(unsigned int proc_num);
  487. void gicv3_rdistif_init_restore(unsigned int proc_num, const gicv3_redist_ctx_t * const rdist_ctx);
  488. void gicv3_rdistif_save(unsigned int proc_num, gicv3_redist_ctx_t * const rdist_ctx);
  489. void gicv3_its_save_disable(uintptr_t gits_base, gicv3_its_ctx_t * const its_ctx);
  490. void gicv3_its_restore(uintptr_t gits_base, const gicv3_its_ctx_t * const its_ctx);
  491. unsigned int gicv3_get_running_priority(void);
  492. unsigned int gicv3_get_interrupt_active(unsigned int id, unsigned int proc_num);
  493. void gicv3_enable_interrupt(unsigned int id, unsigned int proc_num);
  494. void gicv3_disable_interrupt(unsigned int id, unsigned int proc_num);
  495. void gicv3_set_interrupt_priority(unsigned int id, unsigned int proc_num,
  496. unsigned int priority);
  497. void gicv3_set_interrupt_group(unsigned int id, unsigned int proc_num,
  498. unsigned int group);
  499. void gicv3_raise_sgi(unsigned int sgi_num, gicv3_irq_group_t group,
  500. u_register_t target);
  501. void gicv3_set_spi_routing(unsigned int id, unsigned int irm,
  502. u_register_t mpidr);
  503. void gicv3_set_interrupt_pending(unsigned int id, unsigned int proc_num);
  504. void gicv3_clear_interrupt_pending(unsigned int id, unsigned int proc_num);
  505. unsigned int gicv3_set_pmr(unsigned int mask);
  506. unsigned int gicv3_deactivate_priority(unsigned int mask);
  507. void gicv3_get_component_prodid_rev(const uintptr_t gicd_base,
  508. unsigned int *gic_prod_id,
  509. uint8_t *gic_rev);
  510. void gicv3_check_erratas_applies(const uintptr_t gicd_base);
  511. #if GIC600_ERRATA_WA_2384374
  512. void gicv3_apply_errata_wa_2384374(const uintptr_t gicr_base);
  513. #else
  514. static inline void gicv3_apply_errata_wa_2384374(const uintptr_t gicr_base)
  515. {
  516. }
  517. #endif /* GIC600_ERRATA_WA_2384374 */
  518. #endif /* __ASSEMBLER__ */
  519. #endif /* GICV3_H */