gicrv3_helpers.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) 2015-2020, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <arch_helpers.h>
  8. #include <common/debug.h>
  9. #include <common/interrupt_props.h>
  10. #include <drivers/arm/gicv3.h>
  11. #include "gicv3_private.h"
  12. /*******************************************************************************
  13. * GIC Redistributor functions
  14. * Note: The raw register values correspond to multiple interrupt `id`s and
  15. * the number of interrupt `id`s involved depends on the register accessed.
  16. ******************************************************************************/
  17. /*
  18. * Accessors to read/write the GIC Redistributor IPRIORITYR and IPRIORITYRE
  19. * register corresponding to the interrupt `id`, 4 interrupts IDs at a time.
  20. */
  21. unsigned int gicr_read_ipriorityr(uintptr_t base, unsigned int id)
  22. {
  23. return GICR_READ(IPRIORITY, base, id);
  24. }
  25. void gicr_write_ipriorityr(uintptr_t base, unsigned int id, unsigned int val)
  26. {
  27. GICR_WRITE(IPRIORITY, base, id, val);
  28. }
  29. /*
  30. * Accessor to set the byte corresponding to interrupt `id`
  31. * in GIC Redistributor IPRIORITYR and IPRIORITYRE.
  32. */
  33. void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri)
  34. {
  35. GICR_WRITE_8(IPRIORITY, base, id, (uint8_t)(pri & GIC_PRI_MASK));
  36. }
  37. /*
  38. * Accessors to get/set/clear the bit corresponding to interrupt `id`
  39. * from GIC Redistributor IGROUPR0 and IGROUPRE
  40. */
  41. unsigned int gicr_get_igroupr(uintptr_t base, unsigned int id)
  42. {
  43. return GICR_GET_BIT(IGROUP, base, id);
  44. }
  45. void gicr_set_igroupr(uintptr_t base, unsigned int id)
  46. {
  47. GICR_SET_BIT(IGROUP, base, id);
  48. }
  49. void gicr_clr_igroupr(uintptr_t base, unsigned int id)
  50. {
  51. GICR_CLR_BIT(IGROUP, base, id);
  52. }
  53. /*
  54. * Accessors to get/set/clear the bit corresponding to interrupt `id`
  55. * from GIC Redistributor IGRPMODR0 and IGRPMODRE
  56. */
  57. unsigned int gicr_get_igrpmodr(uintptr_t base, unsigned int id)
  58. {
  59. return GICR_GET_BIT(IGRPMOD, base, id);
  60. }
  61. void gicr_set_igrpmodr(uintptr_t base, unsigned int id)
  62. {
  63. GICR_SET_BIT(IGRPMOD, base, id);
  64. }
  65. void gicr_clr_igrpmodr(uintptr_t base, unsigned int id)
  66. {
  67. GICR_CLR_BIT(IGRPMOD, base, id);
  68. }
  69. /*
  70. * Accessor to write the bit corresponding to interrupt `id`
  71. * in GIC Redistributor ISENABLER0 and ISENABLERE
  72. */
  73. void gicr_set_isenabler(uintptr_t base, unsigned int id)
  74. {
  75. GICR_WRITE_BIT(ISENABLE, base, id);
  76. }
  77. /*
  78. * Accessor to write the bit corresponding to interrupt `id`
  79. * in GIC Redistributor ICENABLER0 and ICENABLERE
  80. */
  81. void gicr_set_icenabler(uintptr_t base, unsigned int id)
  82. {
  83. GICR_WRITE_BIT(ICENABLE, base, id);
  84. }
  85. /*
  86. * Accessor to get the bit corresponding to interrupt `id`
  87. * in GIC Redistributor ISACTIVER0 and ISACTIVERE
  88. */
  89. unsigned int gicr_get_isactiver(uintptr_t base, unsigned int id)
  90. {
  91. return GICR_GET_BIT(ISACTIVE, base, id);
  92. }
  93. /*
  94. * Accessor to clear the bit corresponding to interrupt `id`
  95. * in GIC Redistributor ICPENDR0 and ICPENDRE
  96. */
  97. void gicr_set_icpendr(uintptr_t base, unsigned int id)
  98. {
  99. GICR_WRITE_BIT(ICPEND, base, id);
  100. }
  101. /*
  102. * Accessor to write the bit corresponding to interrupt `id`
  103. * in GIC Redistributor ISPENDR0 and ISPENDRE
  104. */
  105. void gicr_set_ispendr(uintptr_t base, unsigned int id)
  106. {
  107. GICR_WRITE_BIT(ISPEND, base, id);
  108. }
  109. /*
  110. * Accessor to set the bit fields corresponding to interrupt `id`
  111. * in GIC Redistributor ICFGR0, ICFGR1 and ICFGRE
  112. */
  113. void gicr_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg)
  114. {
  115. /* Interrupt configuration is a 2-bit field */
  116. unsigned int bit_shift = BIT_NUM(ICFG, id) << 1U;
  117. /* Clear the field, and insert required configuration */
  118. mmio_clrsetbits_32(base + GICR_OFFSET(ICFG, id),
  119. (uint32_t)GIC_CFG_MASK << bit_shift,
  120. (cfg & GIC_CFG_MASK) << bit_shift);
  121. }