gic_common.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /*
  2. * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #pragma message __FILE__ " is deprecated, use gicv2.mk instead"
  7. #include <assert.h>
  8. #include <drivers/arm/gic_common.h>
  9. #include <lib/mmio.h>
  10. #include "gic_common_private.h"
  11. /*******************************************************************************
  12. * GIC Distributor interface accessors for reading entire registers
  13. ******************************************************************************/
  14. /*
  15. * Accessor to read the GIC Distributor IGROUPR corresponding to the interrupt
  16. * `id`, 32 interrupt ids at a time.
  17. */
  18. unsigned int gicd_read_igroupr(uintptr_t base, unsigned int id)
  19. {
  20. unsigned int n = id >> IGROUPR_SHIFT;
  21. return mmio_read_32(base + GICD_IGROUPR + (n << 2));
  22. }
  23. /*
  24. * Accessor to read the GIC Distributor ISENABLER corresponding to the
  25. * interrupt `id`, 32 interrupt ids at a time.
  26. */
  27. unsigned int gicd_read_isenabler(uintptr_t base, unsigned int id)
  28. {
  29. unsigned int n = id >> ISENABLER_SHIFT;
  30. return mmio_read_32(base + GICD_ISENABLER + (n << 2));
  31. }
  32. /*
  33. * Accessor to read the GIC Distributor ICENABLER corresponding to the
  34. * interrupt `id`, 32 interrupt IDs at a time.
  35. */
  36. unsigned int gicd_read_icenabler(uintptr_t base, unsigned int id)
  37. {
  38. unsigned int n = id >> ICENABLER_SHIFT;
  39. return mmio_read_32(base + GICD_ICENABLER + (n << 2));
  40. }
  41. /*
  42. * Accessor to read the GIC Distributor ISPENDR corresponding to the
  43. * interrupt `id`, 32 interrupt IDs at a time.
  44. */
  45. unsigned int gicd_read_ispendr(uintptr_t base, unsigned int id)
  46. {
  47. unsigned int n = id >> ISPENDR_SHIFT;
  48. return mmio_read_32(base + GICD_ISPENDR + (n << 2));
  49. }
  50. /*
  51. * Accessor to read the GIC Distributor ICPENDR corresponding to the
  52. * interrupt `id`, 32 interrupt IDs at a time.
  53. */
  54. unsigned int gicd_read_icpendr(uintptr_t base, unsigned int id)
  55. {
  56. unsigned int n = id >> ICPENDR_SHIFT;
  57. return mmio_read_32(base + GICD_ICPENDR + (n << 2));
  58. }
  59. /*
  60. * Accessor to read the GIC Distributor ISACTIVER corresponding to the
  61. * interrupt `id`, 32 interrupt IDs at a time.
  62. */
  63. unsigned int gicd_read_isactiver(uintptr_t base, unsigned int id)
  64. {
  65. unsigned int n = id >> ISACTIVER_SHIFT;
  66. return mmio_read_32(base + GICD_ISACTIVER + (n << 2));
  67. }
  68. /*
  69. * Accessor to read the GIC Distributor ICACTIVER corresponding to the
  70. * interrupt `id`, 32 interrupt IDs at a time.
  71. */
  72. unsigned int gicd_read_icactiver(uintptr_t base, unsigned int id)
  73. {
  74. unsigned int n = id >> ICACTIVER_SHIFT;
  75. return mmio_read_32(base + GICD_ICACTIVER + (n << 2));
  76. }
  77. /*
  78. * Accessor to read the GIC Distributor IPRIORITYR corresponding to the
  79. * interrupt `id`, 4 interrupt IDs at a time.
  80. */
  81. unsigned int gicd_read_ipriorityr(uintptr_t base, unsigned int id)
  82. {
  83. unsigned int n = id >> IPRIORITYR_SHIFT;
  84. return mmio_read_32(base + GICD_IPRIORITYR + (n << 2));
  85. }
  86. /*
  87. * Accessor to read the GIC Distributor ICGFR corresponding to the
  88. * interrupt `id`, 16 interrupt IDs at a time.
  89. */
  90. unsigned int gicd_read_icfgr(uintptr_t base, unsigned int id)
  91. {
  92. unsigned int n = id >> ICFGR_SHIFT;
  93. return mmio_read_32(base + GICD_ICFGR + (n << 2));
  94. }
  95. /*
  96. * Accessor to read the GIC Distributor NSACR corresponding to the
  97. * interrupt `id`, 16 interrupt IDs at a time.
  98. */
  99. unsigned int gicd_read_nsacr(uintptr_t base, unsigned int id)
  100. {
  101. unsigned int n = id >> NSACR_SHIFT;
  102. return mmio_read_32(base + GICD_NSACR + (n << 2));
  103. }
  104. /*******************************************************************************
  105. * GIC Distributor interface accessors for writing entire registers
  106. ******************************************************************************/
  107. /*
  108. * Accessor to write the GIC Distributor IGROUPR corresponding to the
  109. * interrupt `id`, 32 interrupt IDs at a time.
  110. */
  111. void gicd_write_igroupr(uintptr_t base, unsigned int id, unsigned int val)
  112. {
  113. unsigned int n = id >> IGROUPR_SHIFT;
  114. mmio_write_32(base + GICD_IGROUPR + (n << 2), val);
  115. }
  116. /*
  117. * Accessor to write the GIC Distributor ISENABLER corresponding to the
  118. * interrupt `id`, 32 interrupt IDs at a time.
  119. */
  120. void gicd_write_isenabler(uintptr_t base, unsigned int id, unsigned int val)
  121. {
  122. unsigned int n = id >> ISENABLER_SHIFT;
  123. mmio_write_32(base + GICD_ISENABLER + (n << 2), val);
  124. }
  125. /*
  126. * Accessor to write the GIC Distributor ICENABLER corresponding to the
  127. * interrupt `id`, 32 interrupt IDs at a time.
  128. */
  129. void gicd_write_icenabler(uintptr_t base, unsigned int id, unsigned int val)
  130. {
  131. unsigned int n = id >> ICENABLER_SHIFT;
  132. mmio_write_32(base + GICD_ICENABLER + (n << 2), val);
  133. }
  134. /*
  135. * Accessor to write the GIC Distributor ISPENDR corresponding to the
  136. * interrupt `id`, 32 interrupt IDs at a time.
  137. */
  138. void gicd_write_ispendr(uintptr_t base, unsigned int id, unsigned int val)
  139. {
  140. unsigned int n = id >> ISPENDR_SHIFT;
  141. mmio_write_32(base + GICD_ISPENDR + (n << 2), val);
  142. }
  143. /*
  144. * Accessor to write the GIC Distributor ICPENDR corresponding to the
  145. * interrupt `id`, 32 interrupt IDs at a time.
  146. */
  147. void gicd_write_icpendr(uintptr_t base, unsigned int id, unsigned int val)
  148. {
  149. unsigned int n = id >> ICPENDR_SHIFT;
  150. mmio_write_32(base + GICD_ICPENDR + (n << 2), val);
  151. }
  152. /*
  153. * Accessor to write the GIC Distributor ISACTIVER corresponding to the
  154. * interrupt `id`, 32 interrupt IDs at a time.
  155. */
  156. void gicd_write_isactiver(uintptr_t base, unsigned int id, unsigned int val)
  157. {
  158. unsigned int n = id >> ISACTIVER_SHIFT;
  159. mmio_write_32(base + GICD_ISACTIVER + (n << 2), val);
  160. }
  161. /*
  162. * Accessor to write the GIC Distributor ICACTIVER corresponding to the
  163. * interrupt `id`, 32 interrupt IDs at a time.
  164. */
  165. void gicd_write_icactiver(uintptr_t base, unsigned int id, unsigned int val)
  166. {
  167. unsigned int n = id >> ICACTIVER_SHIFT;
  168. mmio_write_32(base + GICD_ICACTIVER + (n << 2), val);
  169. }
  170. /*
  171. * Accessor to write the GIC Distributor IPRIORITYR corresponding to the
  172. * interrupt `id`, 4 interrupt IDs at a time.
  173. */
  174. void gicd_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val)
  175. {
  176. unsigned int n = id >> IPRIORITYR_SHIFT;
  177. mmio_write_32(base + GICD_IPRIORITYR + (n << 2), val);
  178. }
  179. /*
  180. * Accessor to write the GIC Distributor ICFGR corresponding to the
  181. * interrupt `id`, 16 interrupt IDs at a time.
  182. */
  183. void gicd_write_icfgr(uintptr_t base, unsigned int id, unsigned int val)
  184. {
  185. unsigned int n = id >> ICFGR_SHIFT;
  186. mmio_write_32(base + GICD_ICFGR + (n << 2), val);
  187. }
  188. /*
  189. * Accessor to write the GIC Distributor NSACR corresponding to the
  190. * interrupt `id`, 16 interrupt IDs at a time.
  191. */
  192. void gicd_write_nsacr(uintptr_t base, unsigned int id, unsigned int val)
  193. {
  194. unsigned int n = id >> NSACR_SHIFT;
  195. mmio_write_32(base + GICD_NSACR + (n << 2), val);
  196. }
  197. /*******************************************************************************
  198. * GIC Distributor functions for accessing the GIC registers
  199. * corresponding to a single interrupt ID. These functions use bitwise
  200. * operations or appropriate register accesses to modify or return
  201. * the bit-field corresponding the single interrupt ID.
  202. ******************************************************************************/
  203. unsigned int gicd_get_igroupr(uintptr_t base, unsigned int id)
  204. {
  205. unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U);
  206. unsigned int reg_val = gicd_read_igroupr(base, id);
  207. return (reg_val >> bit_num) & 0x1U;
  208. }
  209. void gicd_set_igroupr(uintptr_t base, unsigned int id)
  210. {
  211. unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U);
  212. unsigned int reg_val = gicd_read_igroupr(base, id);
  213. gicd_write_igroupr(base, id, reg_val | (1U << bit_num));
  214. }
  215. void gicd_clr_igroupr(uintptr_t base, unsigned int id)
  216. {
  217. unsigned int bit_num = id & ((1U << IGROUPR_SHIFT) - 1U);
  218. unsigned int reg_val = gicd_read_igroupr(base, id);
  219. gicd_write_igroupr(base, id, reg_val & ~(1U << bit_num));
  220. }
  221. void gicd_set_isenabler(uintptr_t base, unsigned int id)
  222. {
  223. unsigned int bit_num = id & ((1U << ISENABLER_SHIFT) - 1U);
  224. gicd_write_isenabler(base, id, (1U << bit_num));
  225. }
  226. void gicd_set_icenabler(uintptr_t base, unsigned int id)
  227. {
  228. unsigned int bit_num = id & ((1U << ICENABLER_SHIFT) - 1U);
  229. gicd_write_icenabler(base, id, (1U << bit_num));
  230. }
  231. void gicd_set_ispendr(uintptr_t base, unsigned int id)
  232. {
  233. unsigned int bit_num = id & ((1U << ISPENDR_SHIFT) - 1U);
  234. gicd_write_ispendr(base, id, (1U << bit_num));
  235. }
  236. void gicd_set_icpendr(uintptr_t base, unsigned int id)
  237. {
  238. unsigned int bit_num = id & ((1U << ICPENDR_SHIFT) - 1U);
  239. gicd_write_icpendr(base, id, (1U << bit_num));
  240. }
  241. unsigned int gicd_get_isactiver(uintptr_t base, unsigned int id)
  242. {
  243. unsigned int bit_num = id & ((1U << ISACTIVER_SHIFT) - 1U);
  244. unsigned int reg_val = gicd_read_isactiver(base, id);
  245. return (reg_val >> bit_num) & 0x1U;
  246. }
  247. void gicd_set_isactiver(uintptr_t base, unsigned int id)
  248. {
  249. unsigned int bit_num = id & ((1U << ISACTIVER_SHIFT) - 1U);
  250. gicd_write_isactiver(base, id, (1U << bit_num));
  251. }
  252. void gicd_set_icactiver(uintptr_t base, unsigned int id)
  253. {
  254. unsigned int bit_num = id & ((1U << ICACTIVER_SHIFT) - 1U);
  255. gicd_write_icactiver(base, id, (1U << bit_num));
  256. }
  257. void gicd_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri)
  258. {
  259. uint8_t val = pri & GIC_PRI_MASK;
  260. mmio_write_8(base + GICD_IPRIORITYR + id, val);
  261. }
  262. void gicd_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg)
  263. {
  264. /* Interrupt configuration is a 2-bit field */
  265. unsigned int bit_num = id & ((1U << ICFGR_SHIFT) - 1U);
  266. unsigned int bit_shift = bit_num << 1;
  267. uint32_t reg_val = gicd_read_icfgr(base, id);
  268. /* Clear the field, and insert required configuration */
  269. reg_val &= ~(GIC_CFG_MASK << bit_shift);
  270. reg_val |= ((cfg & GIC_CFG_MASK) << bit_shift);
  271. gicd_write_icfgr(base, id, reg_val);
  272. }