gicdv3_helpers.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <stdint.h>
  7. #include "gicv3_private.h"
  8. /*******************************************************************************
  9. * GIC Distributor functions for accessing the GIC registers
  10. * corresponding to a single interrupt ID. These functions use bitwise
  11. * operations or appropriate register accesses to modify or return
  12. * the bit-field corresponding the single interrupt ID.
  13. ******************************************************************************/
  14. /*
  15. * Accessors to set the bits corresponding to interrupt ID
  16. * in GIC Distributor ICFGR and ICFGRE.
  17. */
  18. void gicd_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg)
  19. {
  20. /* Interrupt configuration is a 2-bit field */
  21. unsigned int bit_shift = BIT_NUM(ICFG, id) << 1U;
  22. /* Clear the field, and insert required configuration */
  23. mmio_clrsetbits_32(base + GICD_OFFSET(ICFG, id),
  24. (uint32_t)GIC_CFG_MASK << bit_shift,
  25. (cfg & GIC_CFG_MASK) << bit_shift);
  26. }
  27. /*
  28. * Accessors to get/set/clear the bit corresponding to interrupt ID
  29. * in GIC Distributor IGROUPR and IGROUPRE.
  30. */
  31. unsigned int gicd_get_igroupr(uintptr_t base, unsigned int id)
  32. {
  33. return GICD_GET_BIT(IGROUP, base, id);
  34. }
  35. void gicd_set_igroupr(uintptr_t base, unsigned int id)
  36. {
  37. GICD_SET_BIT(IGROUP, base, id);
  38. }
  39. void gicd_clr_igroupr(uintptr_t base, unsigned int id)
  40. {
  41. GICD_CLR_BIT(IGROUP, base, id);
  42. }
  43. /*
  44. * Accessors to get/set/clear the bit corresponding to interrupt ID
  45. * in GIC Distributor IGRPMODR and IGRPMODRE.
  46. */
  47. unsigned int gicd_get_igrpmodr(uintptr_t base, unsigned int id)
  48. {
  49. return GICD_GET_BIT(IGRPMOD, base, id);
  50. }
  51. void gicd_set_igrpmodr(uintptr_t base, unsigned int id)
  52. {
  53. GICD_SET_BIT(IGRPMOD, base, id);
  54. }
  55. void gicd_clr_igrpmodr(uintptr_t base, unsigned int id)
  56. {
  57. GICD_CLR_BIT(IGRPMOD, base, id);
  58. }
  59. /*
  60. * Accessors to set the bit corresponding to interrupt ID
  61. * in GIC Distributor ICENABLER and ICENABLERE.
  62. */
  63. void gicd_set_icenabler(uintptr_t base, unsigned int id)
  64. {
  65. GICD_WRITE_BIT(ICENABLE, base, id);
  66. }
  67. /*
  68. * Accessors to set the bit corresponding to interrupt ID
  69. * in GIC Distributor ICPENDR and ICPENDRE.
  70. */
  71. void gicd_set_icpendr(uintptr_t base, unsigned int id)
  72. {
  73. GICD_WRITE_BIT(ICPEND, base, id);
  74. }
  75. /*
  76. * Accessors to get/set the bit corresponding to interrupt ID
  77. * in GIC Distributor ISACTIVER and ISACTIVERE.
  78. */
  79. unsigned int gicd_get_isactiver(uintptr_t base, unsigned int id)
  80. {
  81. return GICD_GET_BIT(ISACTIVE, base, id);
  82. }
  83. void gicd_set_isactiver(uintptr_t base, unsigned int id)
  84. {
  85. GICD_WRITE_BIT(ISACTIVE, base, id);
  86. }
  87. /*
  88. * Accessors to set the bit corresponding to interrupt ID
  89. * in GIC Distributor ISENABLER and ISENABLERE.
  90. */
  91. void gicd_set_isenabler(uintptr_t base, unsigned int id)
  92. {
  93. GICD_WRITE_BIT(ISENABLE, base, id);
  94. }
  95. /*
  96. * Accessors to set the bit corresponding to interrupt ID
  97. * in GIC Distributor ISPENDR and ISPENDRE.
  98. */
  99. void gicd_set_ispendr(uintptr_t base, unsigned int id)
  100. {
  101. GICD_WRITE_BIT(ISPEND, base, id);
  102. }
  103. /*
  104. * Accessors to set the bit corresponding to interrupt ID
  105. * in GIC Distributor IPRIORITYR and IPRIORITYRE.
  106. */
  107. void gicd_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri)
  108. {
  109. GICD_WRITE_8(IPRIORITY, base, id, (uint8_t)(pri & GIC_PRI_MASK));
  110. }
  111. /*******************************************************************************
  112. * GIC Distributor interface accessors for reading/writing entire registers
  113. ******************************************************************************/
  114. /*
  115. * Accessors to read/write the GIC Distributor ICGFR and ICGFRE
  116. * corresponding to the interrupt ID, 16 interrupt IDs at a time.
  117. */
  118. unsigned int gicd_read_icfgr(uintptr_t base, unsigned int id)
  119. {
  120. return GICD_READ(ICFG, base, id);
  121. }
  122. void gicd_write_icfgr(uintptr_t base, unsigned int id, unsigned int val)
  123. {
  124. GICD_WRITE(ICFG, base, id, val);
  125. }
  126. /*
  127. * Accessors to read/write the GIC Distributor IGROUPR and IGROUPRE
  128. * corresponding to the interrupt ID, 32 interrupt IDs at a time.
  129. */
  130. unsigned int gicd_read_igroupr(uintptr_t base, unsigned int id)
  131. {
  132. return GICD_READ(IGROUP, base, id);
  133. }
  134. void gicd_write_igroupr(uintptr_t base, unsigned int id, unsigned int val)
  135. {
  136. GICD_WRITE(IGROUP, base, id, val);
  137. }
  138. /*
  139. * Accessors to read/write the GIC Distributor IGRPMODR and IGRPMODRE
  140. * corresponding to the interrupt ID, 32 interrupt IDs at a time.
  141. */
  142. unsigned int gicd_read_igrpmodr(uintptr_t base, unsigned int id)
  143. {
  144. return GICD_READ(IGRPMOD, base, id);
  145. }
  146. void gicd_write_igrpmodr(uintptr_t base, unsigned int id, unsigned int val)
  147. {
  148. GICD_WRITE(IGRPMOD, base, id, val);
  149. }
  150. /*
  151. * Accessors to read/write the GIC Distributor IPRIORITYR and IPRIORITYRE
  152. * corresponding to the interrupt ID, 4 interrupt IDs at a time.
  153. */
  154. unsigned int gicd_read_ipriorityr(uintptr_t base, unsigned int id)
  155. {
  156. return GICD_READ(IPRIORITY, base, id);
  157. }
  158. void gicd_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val)
  159. {
  160. GICD_WRITE(IPRIORITY, base, id, val);
  161. }
  162. /*
  163. * Accessors to read/write the GIC Distributor ISACTIVER and ISACTIVERE
  164. * corresponding to the interrupt ID, 32 interrupt IDs at a time.
  165. */
  166. unsigned int gicd_read_isactiver(uintptr_t base, unsigned int id)
  167. {
  168. return GICD_READ(ISACTIVE, base, id);
  169. }
  170. void gicd_write_isactiver(uintptr_t base, unsigned int id, unsigned int val)
  171. {
  172. GICD_WRITE(ISACTIVE, base, id, val);
  173. }
  174. /*
  175. * Accessors to read/write the GIC Distributor ISENABLER and ISENABLERE
  176. * corresponding to the interrupt ID, 32 interrupt IDs at a time.
  177. */
  178. unsigned int gicd_read_isenabler(uintptr_t base, unsigned int id)
  179. {
  180. return GICD_READ(ISENABLE, base, id);
  181. }
  182. void gicd_write_isenabler(uintptr_t base, unsigned int id, unsigned int val)
  183. {
  184. GICD_WRITE(ISENABLE, base, id, val);
  185. }
  186. /*
  187. * Accessors to read/write the GIC Distributor ISPENDR and ISPENDRE
  188. * corresponding to the interrupt ID, 32 interrupt IDs at a time.
  189. */
  190. unsigned int gicd_read_ispendr(uintptr_t base, unsigned int id)
  191. {
  192. return GICD_READ(ISPEND, base, id);
  193. }
  194. void gicd_write_ispendr(uintptr_t base, unsigned int id, unsigned int val)
  195. {
  196. GICD_WRITE(ISPEND, base, id, val);
  197. }
  198. /*
  199. * Accessors to read/write the GIC Distributor NSACR and NSACRE
  200. * corresponding to the interrupt ID, 16 interrupt IDs at a time.
  201. */
  202. unsigned int gicd_read_nsacr(uintptr_t base, unsigned int id)
  203. {
  204. return GICD_READ(NSAC, base, id);
  205. }
  206. void gicd_write_nsacr(uintptr_t base, unsigned int id, unsigned int val)
  207. {
  208. GICD_WRITE(NSAC, base, id, val);
  209. }