2
0

mips_gic.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2000, 07 MIPS Technologies, Inc.
  7. * Copyright (C) 2016 Imagination Technologies
  8. *
  9. */
  10. #ifndef MIPS_GIC_H
  11. #define MIPS_GIC_H
  12. #include "qemu/units.h"
  13. #include "hw/timer/mips_gictimer.h"
  14. #include "hw/sysbus.h"
  15. #include "cpu.h"
  16. #include "qom/object.h"
  17. /*
  18. * GIC Specific definitions
  19. */
  20. /* The MIPS default location */
  21. #define GIC_BASE_ADDR 0x1bdc0000ULL
  22. #define GIC_ADDRSPACE_SZ (128 * KiB)
  23. /* Constants */
  24. #define GIC_POL_POS 1
  25. #define GIC_POL_NEG 0
  26. #define GIC_TRIG_EDGE 1
  27. #define GIC_TRIG_LEVEL 0
  28. #define MSK(n) ((1ULL << (n)) - 1)
  29. /* GIC Address Space */
  30. #define SHARED_SECTION_OFS 0x0000
  31. #define SHARED_SECTION_SIZE 0x8000
  32. #define VP_LOCAL_SECTION_OFS 0x8000
  33. #define VP_LOCAL_SECTION_SIZE 0x4000
  34. #define VP_OTHER_SECTION_OFS 0xc000
  35. #define VP_OTHER_SECTION_SIZE 0x4000
  36. #define USM_VISIBLE_SECTION_OFS 0x10000
  37. #define USM_VISIBLE_SECTION_SIZE 0x10000
  38. /* Register Map for Shared Section */
  39. #define GIC_SH_CONFIG_OFS 0x0000
  40. /* Shared Global Counter */
  41. #define GIC_SH_COUNTERLO_OFS 0x0010
  42. #define GIC_SH_COUNTERHI_OFS 0x0014
  43. #define GIC_SH_REVISIONID_OFS 0x0020
  44. /* Set/Clear corresponding bit in Edge Detect Register */
  45. #define GIC_SH_WEDGE_OFS 0x0280
  46. /* Reset Mask - Disables Interrupt */
  47. #define GIC_SH_RMASK_OFS 0x0300
  48. #define GIC_SH_RMASK_LAST_OFS 0x031c
  49. /* Set Mask (WO) - Enables Interrupt */
  50. #define GIC_SH_SMASK_OFS 0x0380
  51. #define GIC_SH_SMASK_LAST_OFS 0x039c
  52. /* Global Interrupt Mask Register (RO) - Bit Set == Interrupt enabled */
  53. #define GIC_SH_MASK_OFS 0x0400
  54. #define GIC_SH_MASK_LAST_OFS 0x041c
  55. /* Pending Global Interrupts (RO) */
  56. #define GIC_SH_PEND_OFS 0x0480
  57. #define GIC_SH_PEND_LAST_OFS 0x049c
  58. #define GIC_SH_MAP0_PIN_OFS 0x0500
  59. #define GIC_SH_MAP255_PIN_OFS 0x08fc
  60. #define GIC_SH_MAP0_VP_OFS 0x2000
  61. #define GIC_SH_MAP255_VP_LAST_OFS 0x3fe4
  62. /* Register Map for Local Section */
  63. #define GIC_VP_CTL_OFS 0x0000
  64. #define GIC_VP_PEND_OFS 0x0004
  65. #define GIC_VP_MASK_OFS 0x0008
  66. #define GIC_VP_RMASK_OFS 0x000c
  67. #define GIC_VP_SMASK_OFS 0x0010
  68. #define GIC_VP_WD_MAP_OFS 0x0040
  69. #define GIC_VP_COMPARE_MAP_OFS 0x0044
  70. #define GIC_VP_TIMER_MAP_OFS 0x0048
  71. #define GIC_VP_FDC_MAP_OFS 0x004c
  72. #define GIC_VP_PERFCTR_MAP_OFS 0x0050
  73. #define GIC_VP_SWINT0_MAP_OFS 0x0054
  74. #define GIC_VP_SWINT1_MAP_OFS 0x0058
  75. #define GIC_VP_OTHER_ADDR_OFS 0x0080
  76. #define GIC_VP_IDENT_OFS 0x0088
  77. #define GIC_VP_WD_CONFIG0_OFS 0x0090
  78. #define GIC_VP_WD_COUNT0_OFS 0x0094
  79. #define GIC_VP_WD_INITIAL0_OFS 0x0098
  80. #define GIC_VP_COMPARE_LO_OFS 0x00a0
  81. #define GIC_VP_COMPARE_HI_OFS 0x00a4
  82. #define GIC_VL_BRK_GROUP 0x3080
  83. /* User-Mode Visible Section Register */
  84. /* Read-only alias for GIC Shared CounterLo */
  85. #define GIC_USER_MODE_COUNTERLO 0x0000
  86. /* Read-only alias for GIC Shared CounterHi */
  87. #define GIC_USER_MODE_COUNTERHI 0x0004
  88. /* Masks */
  89. #define GIC_SH_CONFIG_COUNTSTOP_SHF 28
  90. #define GIC_SH_CONFIG_COUNTSTOP_MSK (MSK(1) << GIC_SH_CONFIG_COUNTSTOP_SHF)
  91. #define GIC_SH_CONFIG_COUNTBITS_SHF 24
  92. #define GIC_SH_CONFIG_COUNTBITS_MSK (MSK(4) << GIC_SH_CONFIG_COUNTBITS_SHF)
  93. #define GIC_SH_CONFIG_NUMINTRS_SHF 16
  94. #define GIC_SH_CONFIG_NUMINTRS_MSK (MSK(8) << GIC_SH_CONFIG_NUMINTRS_SHF)
  95. #define GIC_SH_CONFIG_PVPS_SHF 0
  96. #define GIC_SH_CONFIG_PVPS_MSK (MSK(8) << GIC_SH_CONFIG_NUMVPS_SHF)
  97. #define GIC_SH_WEDGE_RW_SHF 31
  98. #define GIC_SH_WEDGE_RW_MSK (MSK(1) << GIC_SH_WEDGE_RW_SHF)
  99. #define GIC_MAP_TO_PIN_SHF 31
  100. #define GIC_MAP_TO_PIN_MSK (MSK(1) << GIC_MAP_TO_PIN_SHF)
  101. #define GIC_MAP_TO_NMI_SHF 30
  102. #define GIC_MAP_TO_NMI_MSK (MSK(1) << GIC_MAP_TO_NMI_SHF)
  103. #define GIC_MAP_TO_YQ_SHF 29
  104. #define GIC_MAP_TO_YQ_MSK (MSK(1) << GIC_MAP_TO_YQ_SHF)
  105. #define GIC_MAP_SHF 0
  106. #define GIC_MAP_MSK (MSK(6) << GIC_MAP_SHF)
  107. #define GIC_MAP_TO_PIN_REG_MSK \
  108. (GIC_MAP_TO_PIN_MSK | GIC_MAP_TO_NMI_MSK | GIC_MAP_TO_YQ_MSK | GIC_MAP_MSK)
  109. /* GIC_VP_CTL Masks */
  110. #define GIC_VP_CTL_FDC_RTBL_SHF 4
  111. #define GIC_VP_CTL_FDC_RTBL_MSK (MSK(1) << GIC_VP_CTL_FDC_RTBL_SHF)
  112. #define GIC_VP_CTL_SWINT_RTBL_SHF 3
  113. #define GIC_VP_CTL_SWINT_RTBL_MSK (MSK(1) << GIC_VP_CTL_SWINT_RTBL_SHF)
  114. #define GIC_VP_CTL_PERFCNT_RTBL_SHF 2
  115. #define GIC_VP_CTL_PERFCNT_RTBL_MSK (MSK(1) << GIC_VP_CTL_PERFCNT_RTBL_SHF)
  116. #define GIC_VP_CTL_TIMER_RTBL_SHF 1
  117. #define GIC_VP_CTL_TIMER_RTBL_MSK (MSK(1) << GIC_VP_CTL_TIMER_RTBL_SHF)
  118. #define GIC_VP_CTL_EIC_MODE_SHF 0
  119. #define GIC_VP_CTL_EIC_MODE_MSK (MSK(1) << GIC_VP_CTL_EIC_MODE_SHF)
  120. /* GIC_VP_MASK Masks */
  121. #define GIC_VP_MASK_FDC_SHF 6
  122. #define GIC_VP_MASK_FDC_MSK (MSK(1) << GIC_VP_MASK_FDC_SHF)
  123. #define GIC_VP_MASK_SWINT1_SHF 5
  124. #define GIC_VP_MASK_SWINT1_MSK (MSK(1) << GIC_VP_MASK_SWINT1_SHF)
  125. #define GIC_VP_MASK_SWINT0_SHF 4
  126. #define GIC_VP_MASK_SWINT0_MSK (MSK(1) << GIC_VP_MASK_SWINT0_SHF)
  127. #define GIC_VP_MASK_PERFCNT_SHF 3
  128. #define GIC_VP_MASK_PERFCNT_MSK (MSK(1) << GIC_VP_MASK_PERFCNT_SHF)
  129. #define GIC_VP_MASK_TIMER_SHF 2
  130. #define GIC_VP_MASK_TIMER_MSK (MSK(1) << GIC_VP_MASK_TIMER_SHF)
  131. #define GIC_VP_MASK_CMP_SHF 1
  132. #define GIC_VP_MASK_CMP_MSK (MSK(1) << GIC_VP_MASK_CMP_SHF)
  133. #define GIC_VP_MASK_WD_SHF 0
  134. #define GIC_VP_MASK_WD_MSK (MSK(1) << GIC_VP_MASK_WD_SHF)
  135. #define GIC_VP_SET_RESET_MSK (MSK(7) << GIC_VP_MASK_WD_SHF)
  136. #define GIC_CPU_INT_MAX 5 /* Core Interrupt 7 */
  137. #define GIC_CPU_PIN_OFFSET 2
  138. /* Local GIC interrupts. */
  139. #define GIC_NUM_LOCAL_INTRS 7
  140. #define GIC_LOCAL_INT_FDC 6 /* CPU fast debug channel */
  141. #define GIC_LOCAL_INT_SWINT1 5 /* CPU software interrupt 1 */
  142. #define GIC_LOCAL_INT_SWINT0 4 /* CPU software interrupt 0 */
  143. #define GIC_LOCAL_INT_PERFCTR 3 /* CPU performance counter */
  144. #define GIC_LOCAL_INT_TIMER 2 /* CPU timer interrupt */
  145. #define GIC_LOCAL_INT_COMPARE 1 /* GIC count and compare timer */
  146. #define GIC_LOCAL_INT_WD 0 /* GIC watchdog */
  147. #define TYPE_MIPS_GIC "mips-gic"
  148. OBJECT_DECLARE_SIMPLE_TYPE(MIPSGICState, MIPS_GIC)
  149. /* Support up to 32 VPs and 256 IRQs */
  150. #define GIC_MAX_VPS 32
  151. #define GIC_MAX_INTRS 256
  152. typedef struct MIPSGICIRQState MIPSGICIRQState;
  153. typedef struct MIPSGICVPState MIPSGICVPState;
  154. struct MIPSGICIRQState {
  155. uint8_t enabled;
  156. uint8_t pending;
  157. uint32_t map_pin;
  158. int32_t map_vp;
  159. qemu_irq irq;
  160. };
  161. struct MIPSGICVPState {
  162. uint32_t ctl;
  163. uint32_t pend;
  164. uint32_t mask;
  165. uint32_t compare_map;
  166. uint32_t other_addr;
  167. CPUMIPSState *env;
  168. };
  169. struct MIPSGICState {
  170. SysBusDevice parent_obj;
  171. MemoryRegion mr;
  172. /* Shared Section Registers */
  173. uint32_t sh_config;
  174. MIPSGICIRQState *irq_state;
  175. /* VP Local/Other Section Registers */
  176. MIPSGICVPState *vps;
  177. /* GIC VP Timer */
  178. MIPSGICTimerState *gic_timer;
  179. uint32_t num_vps;
  180. uint32_t num_irq;
  181. };
  182. #endif /* MIPS_GIC_H */