gicv3_private.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2023, NVIDIA Corporation. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef GICV3_PRIVATE_H
  8. #define GICV3_PRIVATE_H
  9. #include <assert.h>
  10. #include <stdint.h>
  11. #include <drivers/arm/gic_common.h>
  12. #include <drivers/arm/gicv3.h>
  13. #include <lib/mmio.h>
  14. #include "../common/gic_common_private.h"
  15. /*******************************************************************************
  16. * GICv3 private macro definitions
  17. ******************************************************************************/
  18. /* Constants to indicate the status of the RWP bit */
  19. #define RWP_TRUE U(1)
  20. #define RWP_FALSE U(0)
  21. /* Calculate GIC register bit number corresponding to its interrupt ID */
  22. #define BIT_NUM(REG, id) \
  23. ((id) & ((1U << REG##R_SHIFT) - 1U))
  24. /*
  25. * Calculate 8, 32 and 64-bit GICD register offset
  26. * corresponding to its interrupt ID
  27. */
  28. #if GIC_EXT_INTID
  29. /* GICv3.1 */
  30. #define GICD_OFFSET_8(REG, id) \
  31. (((id) <= MAX_SPI_ID) ? \
  32. GICD_##REG##R + (uintptr_t)(id) : \
  33. GICD_##REG##RE + (uintptr_t)(id) - MIN_ESPI_ID)
  34. #define GICD_OFFSET(REG, id) \
  35. (((id) <= MAX_SPI_ID) ? \
  36. GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2) : \
  37. GICD_##REG##RE + ((((uintptr_t)(id) - MIN_ESPI_ID) >> \
  38. REG##R_SHIFT) << 2))
  39. #define GICD_OFFSET_64(REG, id) \
  40. (((id) <= MAX_SPI_ID) ? \
  41. GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 3) : \
  42. GICD_##REG##RE + ((((uintptr_t)(id) - MIN_ESPI_ID) >> \
  43. REG##R_SHIFT) << 3))
  44. #else /* GICv3 */
  45. #define GICD_OFFSET_8(REG, id) \
  46. (GICD_##REG##R + (uintptr_t)(id))
  47. #define GICD_OFFSET(REG, id) \
  48. (GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2))
  49. #define GICD_OFFSET_64(REG, id) \
  50. (GICD_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 3))
  51. #endif /* GIC_EXT_INTID */
  52. /*
  53. * Read/Write 8, 32 and 64-bit GIC Distributor register
  54. * corresponding to its interrupt ID
  55. */
  56. #define GICD_READ(REG, base, id) \
  57. mmio_read_32((base) + GICD_OFFSET(REG, (id)))
  58. #define GICD_READ_64(REG, base, id) \
  59. mmio_read_64((base) + GICD_OFFSET_64(REG, (id)))
  60. #define GICD_WRITE_8(REG, base, id, val) \
  61. mmio_write_8((base) + GICD_OFFSET_8(REG, (id)), (val))
  62. #define GICD_WRITE(REG, base, id, val) \
  63. mmio_write_32((base) + GICD_OFFSET(REG, (id)), (val))
  64. #define GICD_WRITE_64(REG, base, id, val) \
  65. mmio_write_64((base) + GICD_OFFSET_64(REG, (id)), (val))
  66. /*
  67. * Bit operations on GIC Distributor register corresponding
  68. * to its interrupt ID
  69. */
  70. /* Get bit in GIC Distributor register */
  71. #define GICD_GET_BIT(REG, base, id) \
  72. ((mmio_read_32((base) + GICD_OFFSET(REG, (id))) >> \
  73. BIT_NUM(REG, (id))) & 1U)
  74. /* Set bit in GIC Distributor register */
  75. #define GICD_SET_BIT(REG, base, id) \
  76. mmio_setbits_32((base) + GICD_OFFSET(REG, (id)), \
  77. ((uint32_t)1 << BIT_NUM(REG, (id))))
  78. /* Clear bit in GIC Distributor register */
  79. #define GICD_CLR_BIT(REG, base, id) \
  80. mmio_clrbits_32((base) + GICD_OFFSET(REG, (id)), \
  81. ((uint32_t)1 << BIT_NUM(REG, (id))))
  82. /* Write bit in GIC Distributor register */
  83. #define GICD_WRITE_BIT(REG, base, id) \
  84. mmio_write_32((base) + GICD_OFFSET(REG, (id)), \
  85. ((uint32_t)1 << BIT_NUM(REG, (id))))
  86. /*
  87. * Calculate 8 and 32-bit GICR register offset
  88. * corresponding to its interrupt ID
  89. */
  90. #if GIC_EXT_INTID
  91. /* GICv3.1 */
  92. #define GICR_OFFSET_8(REG, id) \
  93. (((id) <= MAX_PPI_ID) ? \
  94. GICR_##REG##R + (uintptr_t)(id) : \
  95. GICR_##REG##R + (uintptr_t)(id) - (MIN_EPPI_ID - MIN_SPI_ID))
  96. #define GICR_OFFSET(REG, id) \
  97. (((id) <= MAX_PPI_ID) ? \
  98. GICR_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2) : \
  99. GICR_##REG##R + ((((uintptr_t)(id) - (MIN_EPPI_ID - MIN_SPI_ID))\
  100. >> REG##R_SHIFT) << 2))
  101. #else /* GICv3 */
  102. #define GICR_OFFSET_8(REG, id) \
  103. (GICR_##REG##R + (uintptr_t)(id))
  104. #define GICR_OFFSET(REG, id) \
  105. (GICR_##REG##R + (((uintptr_t)(id) >> REG##R_SHIFT) << 2))
  106. #endif /* GIC_EXT_INTID */
  107. /* Read/Write GIC Redistributor register corresponding to its interrupt ID */
  108. #define GICR_READ(REG, base, id) \
  109. mmio_read_32((base) + GICR_OFFSET(REG, (id)))
  110. #define GICR_WRITE_8(REG, base, id, val) \
  111. mmio_write_8((base) + GICR_OFFSET_8(REG, (id)), (val))
  112. #define GICR_WRITE(REG, base, id, val) \
  113. mmio_write_32((base) + GICR_OFFSET(REG, (id)), (val))
  114. /*
  115. * Bit operations on GIC Redistributor register
  116. * corresponding to its interrupt ID
  117. */
  118. /* Get bit in GIC Redistributor register */
  119. #define GICR_GET_BIT(REG, base, id) \
  120. ((mmio_read_32((base) + GICR_OFFSET(REG, (id))) >> \
  121. BIT_NUM(REG, (id))) & 1U)
  122. /* Write bit in GIC Redistributor register */
  123. #define GICR_WRITE_BIT(REG, base, id) \
  124. mmio_write_32((base) + GICR_OFFSET(REG, (id)), \
  125. ((uint32_t)1 << BIT_NUM(REG, (id))))
  126. /* Set bit in GIC Redistributor register */
  127. #define GICR_SET_BIT(REG, base, id) \
  128. mmio_setbits_32((base) + GICR_OFFSET(REG, (id)), \
  129. ((uint32_t)1 << BIT_NUM(REG, (id))))
  130. /* Clear bit in GIC Redistributor register */
  131. #define GICR_CLR_BIT(REG, base, id) \
  132. mmio_clrbits_32((base) + GICR_OFFSET(REG, (id)), \
  133. ((uint32_t)1 << BIT_NUM(REG, (id))))
  134. /*
  135. * Macro to convert an mpidr to a value suitable for programming into a
  136. * GICD_IROUTER. Bits[31:24] in the MPIDR are cleared as they are not relevant
  137. * to GICv3.
  138. */
  139. static inline u_register_t gicd_irouter_val_from_mpidr(u_register_t mpidr,
  140. unsigned int irm)
  141. {
  142. return (mpidr & MPIDR_AFFINITY_MASK) |
  143. ((irm & IROUTER_IRM_MASK) << IROUTER_IRM_SHIFT);
  144. }
  145. /*
  146. * Macro to convert a GICR_TYPER affinity value into a MPIDR value. Bits[31:24]
  147. * are zeroes.
  148. */
  149. #ifdef __aarch64__
  150. static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
  151. {
  152. return (((typer_val >> 56) & MPIDR_AFFLVL_MASK) << MPIDR_AFF3_SHIFT) |
  153. ((typer_val >> 32) & U(0xffffff));
  154. }
  155. #else
  156. static inline u_register_t mpidr_from_gicr_typer(uint64_t typer_val)
  157. {
  158. return (((typer_val) >> 32) & U(0xffffff));
  159. }
  160. #endif
  161. /*******************************************************************************
  162. * GICv3 private global variables declarations
  163. ******************************************************************************/
  164. extern const gicv3_driver_data_t *gicv3_driver_data;
  165. /*******************************************************************************
  166. * Private GICv3 function prototypes for accessing entire registers.
  167. * Note: The raw register values correspond to multiple interrupt IDs and
  168. * the number of interrupt IDs involved depends on the register accessed.
  169. ******************************************************************************/
  170. unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id);
  171. unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id);
  172. void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val);
  173. void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val);
  174. /*******************************************************************************
  175. * Private GICv3 function prototypes for accessing the GIC registers
  176. * corresponding to a single interrupt ID. These functions use bitwise
  177. * operations or appropriate register accesses to modify or return
  178. * the bit-field corresponding the single interrupt ID.
  179. ******************************************************************************/
  180. unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id);
  181. unsigned int gicr_get_igrpmodr(uintptr_t base, unsigned int id);
  182. unsigned int gicr_get_igroupr(uintptr_t base, unsigned int id);
  183. unsigned int gicr_get_isactiver(uintptr_t base, unsigned int id);
  184. void gicd_set_igrpmodr(uintptr_t base, unsigned int id);
  185. void gicr_set_igrpmodr(uintptr_t base, unsigned int id);
  186. void gicr_set_isenabler(uintptr_t base, unsigned int id);
  187. void gicr_set_icenabler(uintptr_t base, unsigned int id);
  188. void gicr_set_ispendr(uintptr_t base, unsigned int id);
  189. void gicr_set_icpendr(uintptr_t base, unsigned int id);
  190. void gicr_set_igroupr(uintptr_t base, unsigned int id);
  191. void gicd_clr_igrpmodr(uintptr_t base, unsigned int id);
  192. void gicr_clr_igrpmodr(uintptr_t base, unsigned int id);
  193. void gicr_clr_igroupr(uintptr_t base, unsigned int id);
  194. void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri);
  195. void gicr_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg);
  196. /*******************************************************************************
  197. * Private GICv3 helper function prototypes
  198. ******************************************************************************/
  199. uintptr_t gicv3_get_multichip_base(uint32_t spi_id, uintptr_t gicd_base);
  200. unsigned int gicv3_get_spi_limit(uintptr_t gicd_base);
  201. unsigned int gicv3_get_espi_limit(uintptr_t gicd_base);
  202. void gicv3_spis_config_defaults(uintptr_t gicd_base);
  203. void gicv3_ppi_sgi_config_defaults(uintptr_t gicr_base);
  204. unsigned int gicv3_secure_ppi_sgi_config_props(uintptr_t gicr_base,
  205. const interrupt_prop_t *interrupt_props,
  206. unsigned int interrupt_props_num);
  207. unsigned int gicv3_secure_spis_config_props(uintptr_t gicd_base,
  208. const interrupt_prop_t *interrupt_props,
  209. unsigned int interrupt_props_num);
  210. void gicv3_rdistif_base_addrs_probe(uintptr_t *rdistif_base_addrs,
  211. unsigned int rdistif_num,
  212. uintptr_t gicr_base,
  213. mpidr_hash_fn mpidr_to_core_pos);
  214. void gicv3_rdistif_mark_core_awake(uintptr_t gicr_base);
  215. void gicv3_rdistif_mark_core_asleep(uintptr_t gicr_base);
  216. /*******************************************************************************
  217. * GIC Distributor interface accessors
  218. ******************************************************************************/
  219. /*
  220. * Wait for updates to:
  221. * GICD_CTLR[2:0] - the Group Enables
  222. * GICD_CTLR[7:4] - the ARE bits, E1NWF bit and DS bit
  223. * GICD_ICENABLER<n> - the clearing of enable state for SPIs
  224. */
  225. static inline void gicd_wait_for_pending_write(uintptr_t gicd_base)
  226. {
  227. while ((gicd_read_ctlr(gicd_base) & GICD_CTLR_RWP_BIT) != 0U) {
  228. }
  229. }
  230. static inline uint32_t gicd_read_pidr2(uintptr_t base)
  231. {
  232. return mmio_read_32(base + GICD_PIDR2_GICV3);
  233. }
  234. static inline uint64_t gicd_read_irouter(uintptr_t base, unsigned int id)
  235. {
  236. assert(id >= MIN_SPI_ID);
  237. return GICD_READ_64(IROUTE, base, id);
  238. }
  239. static inline void gicd_write_irouter(uintptr_t base,
  240. unsigned int id,
  241. uint64_t affinity)
  242. {
  243. assert(id >= MIN_SPI_ID);
  244. GICD_WRITE_64(IROUTE, base, id, affinity);
  245. }
  246. static inline void gicd_clr_ctlr(uintptr_t base,
  247. unsigned int bitmap,
  248. unsigned int rwp)
  249. {
  250. gicd_write_ctlr(base, gicd_read_ctlr(base) & ~bitmap);
  251. if (rwp != 0U) {
  252. gicd_wait_for_pending_write(base);
  253. }
  254. }
  255. static inline void gicd_set_ctlr(uintptr_t base,
  256. unsigned int bitmap,
  257. unsigned int rwp)
  258. {
  259. gicd_write_ctlr(base, gicd_read_ctlr(base) | bitmap);
  260. if (rwp != 0U) {
  261. gicd_wait_for_pending_write(base);
  262. }
  263. }
  264. /*******************************************************************************
  265. * GIC Redistributor interface accessors
  266. ******************************************************************************/
  267. static inline uint32_t gicr_read_ctlr(uintptr_t base)
  268. {
  269. return mmio_read_32(base + GICR_CTLR);
  270. }
  271. static inline void gicr_write_ctlr(uintptr_t base, uint32_t val)
  272. {
  273. mmio_write_32(base + GICR_CTLR, val);
  274. }
  275. static inline uint64_t gicr_read_typer(uintptr_t base)
  276. {
  277. return mmio_read_64(base + GICR_TYPER);
  278. }
  279. static inline uint32_t gicr_read_waker(uintptr_t base)
  280. {
  281. return mmio_read_32(base + GICR_WAKER);
  282. }
  283. static inline void gicr_write_waker(uintptr_t base, uint32_t val)
  284. {
  285. mmio_write_32(base + GICR_WAKER, val);
  286. }
  287. /*
  288. * Wait for updates to:
  289. * GICR_ICENABLER0
  290. * GICR_CTLR.DPG1S
  291. * GICR_CTLR.DPG1NS
  292. * GICR_CTLR.DPG0
  293. * GICR_CTLR, which clears EnableLPIs from 1 to 0
  294. */
  295. static inline void gicr_wait_for_pending_write(uintptr_t gicr_base)
  296. {
  297. while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_RWP_BIT) != 0U) {
  298. }
  299. }
  300. static inline void gicr_wait_for_upstream_pending_write(uintptr_t gicr_base)
  301. {
  302. while ((gicr_read_ctlr(gicr_base) & GICR_CTLR_UWP_BIT) != 0U) {
  303. }
  304. }
  305. /* Private implementation of Distributor power control hooks */
  306. void arm_gicv3_distif_pre_save(unsigned int rdist_proc_num);
  307. void arm_gicv3_distif_post_restore(unsigned int rdist_proc_num);
  308. /*******************************************************************************
  309. * GIC Redistributor functions for accessing entire registers.
  310. * Note: The raw register values correspond to multiple interrupt IDs and
  311. * the number of interrupt IDs involved depends on the register accessed.
  312. ******************************************************************************/
  313. /*
  314. * Accessors to read/write GIC Redistributor ICENABLER0 register
  315. */
  316. static inline unsigned int gicr_read_icenabler0(uintptr_t base)
  317. {
  318. return mmio_read_32(base + GICR_ICENABLER0);
  319. }
  320. static inline void gicr_write_icenabler0(uintptr_t base, unsigned int val)
  321. {
  322. mmio_write_32(base + GICR_ICENABLER0, val);
  323. }
  324. /*
  325. * Accessors to read/write GIC Redistributor ICENABLER0 and ICENABLERE
  326. * register corresponding to its number
  327. */
  328. static inline unsigned int gicr_read_icenabler(uintptr_t base,
  329. unsigned int reg_num)
  330. {
  331. return mmio_read_32(base + GICR_ICENABLER + (reg_num << 2));
  332. }
  333. static inline void gicr_write_icenabler(uintptr_t base, unsigned int reg_num,
  334. unsigned int val)
  335. {
  336. mmio_write_32(base + GICR_ICENABLER + (reg_num << 2), val);
  337. }
  338. /*
  339. * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 registers
  340. */
  341. static inline unsigned int gicr_read_icfgr0(uintptr_t base)
  342. {
  343. return mmio_read_32(base + GICR_ICFGR0);
  344. }
  345. static inline unsigned int gicr_read_icfgr1(uintptr_t base)
  346. {
  347. return mmio_read_32(base + GICR_ICFGR1);
  348. }
  349. static inline void gicr_write_icfgr0(uintptr_t base, unsigned int val)
  350. {
  351. mmio_write_32(base + GICR_ICFGR0, val);
  352. }
  353. static inline void gicr_write_icfgr1(uintptr_t base, unsigned int val)
  354. {
  355. mmio_write_32(base + GICR_ICFGR1, val);
  356. }
  357. /*
  358. * Accessors to read/write GIC Redistributor ICFGR0, ICFGR1 and ICFGRE
  359. * register corresponding to its number
  360. */
  361. static inline unsigned int gicr_read_icfgr(uintptr_t base, unsigned int reg_num)
  362. {
  363. return mmio_read_32(base + GICR_ICFGR + (reg_num << 2));
  364. }
  365. static inline void gicr_write_icfgr(uintptr_t base, unsigned int reg_num,
  366. unsigned int val)
  367. {
  368. mmio_write_32(base + GICR_ICFGR + (reg_num << 2), val);
  369. }
  370. /*
  371. * Accessor to write GIC Redistributor ICPENDR0 register
  372. */
  373. static inline void gicr_write_icpendr0(uintptr_t base, unsigned int val)
  374. {
  375. mmio_write_32(base + GICR_ICPENDR0, val);
  376. }
  377. /*
  378. * Accessor to write GIC Redistributor ICPENDR0 and ICPENDRE
  379. * register corresponding to its number
  380. */
  381. static inline void gicr_write_icpendr(uintptr_t base, unsigned int reg_num,
  382. unsigned int val)
  383. {
  384. mmio_write_32(base + GICR_ICPENDR + (reg_num << 2), val);
  385. }
  386. /*
  387. * Accessors to read/write GIC Redistributor IGROUPR0 register
  388. */
  389. static inline unsigned int gicr_read_igroupr0(uintptr_t base)
  390. {
  391. return mmio_read_32(base + GICR_IGROUPR0);
  392. }
  393. static inline void gicr_write_igroupr0(uintptr_t base, unsigned int val)
  394. {
  395. mmio_write_32(base + GICR_IGROUPR0, val);
  396. }
  397. /*
  398. * Accessors to read/write GIC Redistributor IGROUPR0 and IGROUPRE
  399. * register corresponding to its number
  400. */
  401. static inline unsigned int gicr_read_igroupr(uintptr_t base,
  402. unsigned int reg_num)
  403. {
  404. return mmio_read_32(base + GICR_IGROUPR + (reg_num << 2));
  405. }
  406. static inline void gicr_write_igroupr(uintptr_t base, unsigned int reg_num,
  407. unsigned int val)
  408. {
  409. mmio_write_32(base + GICR_IGROUPR + (reg_num << 2), val);
  410. }
  411. /*
  412. * Accessors to read/write GIC Redistributor IGRPMODR0 register
  413. */
  414. static inline unsigned int gicr_read_igrpmodr0(uintptr_t base)
  415. {
  416. return mmio_read_32(base + GICR_IGRPMODR0);
  417. }
  418. static inline void gicr_write_igrpmodr0(uintptr_t base, unsigned int val)
  419. {
  420. mmio_write_32(base + GICR_IGRPMODR0, val);
  421. }
  422. /*
  423. * Accessors to read/write GIC Redistributor IGRPMODR0 and IGRPMODRE
  424. * register corresponding to its number
  425. */
  426. static inline unsigned int gicr_read_igrpmodr(uintptr_t base,
  427. unsigned int reg_num)
  428. {
  429. return mmio_read_32(base + GICR_IGRPMODR + (reg_num << 2));
  430. }
  431. static inline void gicr_write_igrpmodr(uintptr_t base, unsigned int reg_num,
  432. unsigned int val)
  433. {
  434. mmio_write_32(base + GICR_IGRPMODR + (reg_num << 2), val);
  435. }
  436. /*
  437. * Accessors to read/write the GIC Redistributor IPRIORITYR(E) register
  438. * corresponding to its number, 4 interrupts IDs at a time.
  439. */
  440. static inline unsigned int gicr_ipriorityr_read(uintptr_t base,
  441. unsigned int reg_num)
  442. {
  443. return mmio_read_32(base + GICR_IPRIORITYR + (reg_num << 2));
  444. }
  445. static inline void gicr_ipriorityr_write(uintptr_t base, unsigned int reg_num,
  446. unsigned int val)
  447. {
  448. mmio_write_32(base + GICR_IPRIORITYR + (reg_num << 2), val);
  449. }
  450. /*
  451. * Accessors to read/write GIC Redistributor ISACTIVER0 register
  452. */
  453. static inline unsigned int gicr_read_isactiver0(uintptr_t base)
  454. {
  455. return mmio_read_32(base + GICR_ISACTIVER0);
  456. }
  457. static inline void gicr_write_isactiver0(uintptr_t base, unsigned int val)
  458. {
  459. mmio_write_32(base + GICR_ISACTIVER0, val);
  460. }
  461. /*
  462. * Accessors to read/write GIC Redistributor ISACTIVER0 and ISACTIVERE
  463. * register corresponding to its number
  464. */
  465. static inline unsigned int gicr_read_isactiver(uintptr_t base,
  466. unsigned int reg_num)
  467. {
  468. return mmio_read_32(base + GICR_ISACTIVER + (reg_num << 2));
  469. }
  470. static inline void gicr_write_isactiver(uintptr_t base, unsigned int reg_num,
  471. unsigned int val)
  472. {
  473. mmio_write_32(base + GICR_ISACTIVER + (reg_num << 2), val);
  474. }
  475. /*
  476. * Accessors to read/write GIC Redistributor ISENABLER0 register
  477. */
  478. static inline unsigned int gicr_read_isenabler0(uintptr_t base)
  479. {
  480. return mmio_read_32(base + GICR_ISENABLER0);
  481. }
  482. static inline void gicr_write_isenabler0(uintptr_t base, unsigned int val)
  483. {
  484. mmio_write_32(base + GICR_ISENABLER0, val);
  485. }
  486. /*
  487. * Accessors to read/write GIC Redistributor ISENABLER0 and ISENABLERE
  488. * register corresponding to its number
  489. */
  490. static inline unsigned int gicr_read_isenabler(uintptr_t base,
  491. unsigned int reg_num)
  492. {
  493. return mmio_read_32(base + GICR_ISENABLER + (reg_num << 2));
  494. }
  495. static inline void gicr_write_isenabler(uintptr_t base, unsigned int reg_num,
  496. unsigned int val)
  497. {
  498. mmio_write_32(base + GICR_ISENABLER + (reg_num << 2), val);
  499. }
  500. /*
  501. * Accessors to read/write GIC Redistributor ISPENDR0 register
  502. */
  503. static inline unsigned int gicr_read_ispendr0(uintptr_t base)
  504. {
  505. return mmio_read_32(base + GICR_ISPENDR0);
  506. }
  507. static inline void gicr_write_ispendr0(uintptr_t base, unsigned int val)
  508. {
  509. mmio_write_32(base + GICR_ISPENDR0, val);
  510. }
  511. /*
  512. * Accessors to read/write GIC Redistributor ISPENDR0 and ISPENDRE
  513. * register corresponding to its number
  514. */
  515. static inline unsigned int gicr_read_ispendr(uintptr_t base,
  516. unsigned int reg_num)
  517. {
  518. return mmio_read_32(base + GICR_ISPENDR + (reg_num << 2));
  519. }
  520. static inline void gicr_write_ispendr(uintptr_t base, unsigned int reg_num,
  521. unsigned int val)
  522. {
  523. mmio_write_32(base + GICR_ISPENDR + (reg_num << 2), val);
  524. }
  525. /*
  526. * Accessors to read/write GIC Redistributor NSACR register
  527. */
  528. static inline unsigned int gicr_read_nsacr(uintptr_t base)
  529. {
  530. return mmio_read_32(base + GICR_NSACR);
  531. }
  532. static inline void gicr_write_nsacr(uintptr_t base, unsigned int val)
  533. {
  534. mmio_write_32(base + GICR_NSACR, val);
  535. }
  536. /*
  537. * Accessors to read/write GIC Redistributor PROPBASER register
  538. */
  539. static inline uint64_t gicr_read_propbaser(uintptr_t base)
  540. {
  541. return mmio_read_64(base + GICR_PROPBASER);
  542. }
  543. static inline void gicr_write_propbaser(uintptr_t base, uint64_t val)
  544. {
  545. mmio_write_64(base + GICR_PROPBASER, val);
  546. }
  547. /*
  548. * Accessors to read/write GIC Redistributor PENDBASER register
  549. */
  550. static inline uint64_t gicr_read_pendbaser(uintptr_t base)
  551. {
  552. return mmio_read_64(base + GICR_PENDBASER);
  553. }
  554. static inline void gicr_write_pendbaser(uintptr_t base, uint64_t val)
  555. {
  556. mmio_write_64(base + GICR_PENDBASER, val);
  557. }
  558. /*******************************************************************************
  559. * GIC ITS functions to read and write entire ITS registers.
  560. ******************************************************************************/
  561. static inline uint32_t gits_read_ctlr(uintptr_t base)
  562. {
  563. return mmio_read_32(base + GITS_CTLR);
  564. }
  565. static inline void gits_write_ctlr(uintptr_t base, uint32_t val)
  566. {
  567. mmio_write_32(base + GITS_CTLR, val);
  568. }
  569. static inline uint64_t gits_read_cbaser(uintptr_t base)
  570. {
  571. return mmio_read_64(base + GITS_CBASER);
  572. }
  573. static inline void gits_write_cbaser(uintptr_t base, uint64_t val)
  574. {
  575. mmio_write_64(base + GITS_CBASER, val);
  576. }
  577. static inline uint64_t gits_read_cwriter(uintptr_t base)
  578. {
  579. return mmio_read_64(base + GITS_CWRITER);
  580. }
  581. static inline void gits_write_cwriter(uintptr_t base, uint64_t val)
  582. {
  583. mmio_write_64(base + GITS_CWRITER, val);
  584. }
  585. static inline uint64_t gits_read_baser(uintptr_t base,
  586. unsigned int its_table_id)
  587. {
  588. assert(its_table_id < 8U);
  589. return mmio_read_64(base + GITS_BASER + (8U * its_table_id));
  590. }
  591. static inline void gits_write_baser(uintptr_t base, unsigned int its_table_id,
  592. uint64_t val)
  593. {
  594. assert(its_table_id < 8U);
  595. mmio_write_64(base + GITS_BASER + (8U * its_table_id), val);
  596. }
  597. /*
  598. * Wait for Quiescent bit when GIC ITS is disabled
  599. */
  600. static inline void gits_wait_for_quiescent_bit(uintptr_t gits_base)
  601. {
  602. assert((gits_read_ctlr(gits_base) & GITS_CTLR_ENABLED_BIT) == 0U);
  603. while ((gits_read_ctlr(gits_base) & GITS_CTLR_QUIESCENT_BIT) == 0U) {
  604. }
  605. }
  606. #endif /* GICV3_PRIVATE_H */