arm_gic_internal.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * ARM GIC support - internal interfaces
  3. *
  4. * Copyright (c) 2012 Linaro Limited
  5. * Written by Peter Maydell
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #ifndef QEMU_ARM_GIC_INTERNAL_H
  21. #define QEMU_ARM_GIC_INTERNAL_H
  22. #include "sysbus.h"
  23. /* Maximum number of possible interrupts, determined by the GIC architecture */
  24. #define GIC_MAXIRQ 1020
  25. /* First 32 are private to each CPU (SGIs and PPIs). */
  26. #define GIC_INTERNAL 32
  27. /* Maximum number of possible CPU interfaces, determined by GIC architecture */
  28. #define NCPU 8
  29. #define ALL_CPU_MASK ((unsigned)(((1 << NCPU) - 1)))
  30. /* The NVIC has 16 internal vectors. However these are not exposed
  31. through the normal GIC interface. */
  32. #define GIC_BASE_IRQ ((s->revision == REV_NVIC) ? 32 : 0)
  33. #define GIC_SET_ENABLED(irq, cm) s->irq_state[irq].enabled |= (cm)
  34. #define GIC_CLEAR_ENABLED(irq, cm) s->irq_state[irq].enabled &= ~(cm)
  35. #define GIC_TEST_ENABLED(irq, cm) ((s->irq_state[irq].enabled & (cm)) != 0)
  36. #define GIC_SET_PENDING(irq, cm) s->irq_state[irq].pending |= (cm)
  37. #define GIC_CLEAR_PENDING(irq, cm) s->irq_state[irq].pending &= ~(cm)
  38. #define GIC_TEST_PENDING(irq, cm) ((s->irq_state[irq].pending & (cm)) != 0)
  39. #define GIC_SET_ACTIVE(irq, cm) s->irq_state[irq].active |= (cm)
  40. #define GIC_CLEAR_ACTIVE(irq, cm) s->irq_state[irq].active &= ~(cm)
  41. #define GIC_TEST_ACTIVE(irq, cm) ((s->irq_state[irq].active & (cm)) != 0)
  42. #define GIC_SET_MODEL(irq) s->irq_state[irq].model = 1
  43. #define GIC_CLEAR_MODEL(irq) s->irq_state[irq].model = 0
  44. #define GIC_TEST_MODEL(irq) s->irq_state[irq].model
  45. #define GIC_SET_LEVEL(irq, cm) s->irq_state[irq].level = (cm)
  46. #define GIC_CLEAR_LEVEL(irq, cm) s->irq_state[irq].level &= ~(cm)
  47. #define GIC_TEST_LEVEL(irq, cm) ((s->irq_state[irq].level & (cm)) != 0)
  48. #define GIC_SET_TRIGGER(irq) s->irq_state[irq].trigger = 1
  49. #define GIC_CLEAR_TRIGGER(irq) s->irq_state[irq].trigger = 0
  50. #define GIC_TEST_TRIGGER(irq) s->irq_state[irq].trigger
  51. #define GIC_GET_PRIORITY(irq, cpu) (((irq) < GIC_INTERNAL) ? \
  52. s->priority1[irq][cpu] : \
  53. s->priority2[(irq) - GIC_INTERNAL])
  54. #define GIC_TARGET(irq) s->irq_target[irq]
  55. typedef struct gic_irq_state {
  56. /* The enable bits are only banked for per-cpu interrupts. */
  57. unsigned enabled:NCPU;
  58. unsigned pending:NCPU;
  59. unsigned active:NCPU;
  60. unsigned level:NCPU;
  61. unsigned model:1; /* 0 = N:N, 1 = 1:N */
  62. unsigned trigger:1; /* nonzero = edge triggered. */
  63. } gic_irq_state;
  64. typedef struct GICState {
  65. SysBusDevice busdev;
  66. qemu_irq parent_irq[NCPU];
  67. int enabled;
  68. int cpu_enabled[NCPU];
  69. gic_irq_state irq_state[GIC_MAXIRQ];
  70. int irq_target[GIC_MAXIRQ];
  71. int priority1[GIC_INTERNAL][NCPU];
  72. int priority2[GIC_MAXIRQ - GIC_INTERNAL];
  73. int last_active[GIC_MAXIRQ][NCPU];
  74. int priority_mask[NCPU];
  75. int running_irq[NCPU];
  76. int running_priority[NCPU];
  77. int current_pending[NCPU];
  78. uint32_t num_cpu;
  79. MemoryRegion iomem; /* Distributor */
  80. /* This is just so we can have an opaque pointer which identifies
  81. * both this GIC and which CPU interface we should be accessing.
  82. */
  83. struct GICState *backref[NCPU];
  84. MemoryRegion cpuiomem[NCPU+1]; /* CPU interfaces */
  85. uint32_t num_irq;
  86. uint32_t revision;
  87. } GICState;
  88. /* The special cases for the revision property: */
  89. #define REV_11MPCORE 0
  90. #define REV_NVIC 0xffffffff
  91. void gic_set_pending_private(GICState *s, int cpu, int irq);
  92. uint32_t gic_acknowledge_irq(GICState *s, int cpu);
  93. void gic_complete_irq(GICState *s, int cpu, int irq);
  94. void gic_update(GICState *s);
  95. void gic_init_irqs_and_distributor(GICState *s, int num_irq);
  96. #define TYPE_ARM_GIC_COMMON "arm_gic_common"
  97. #define ARM_GIC_COMMON(obj) \
  98. OBJECT_CHECK(GICState, (obj), TYPE_ARM_GIC_COMMON)
  99. #define ARM_GIC_COMMON_CLASS(klass) \
  100. OBJECT_CLASS_CHECK(ARMGICCommonClass, (klass), TYPE_ARM_GIC_COMMON)
  101. #define ARM_GIC_COMMON_GET_CLASS(obj) \
  102. OBJECT_GET_CLASS(ARMGICCommonClass, (obj), TYPE_ARM_GIC_COMMON)
  103. typedef struct ARMGICCommonClass {
  104. SysBusDeviceClass parent_class;
  105. } ARMGICCommonClass;
  106. #define TYPE_ARM_GIC "arm_gic"
  107. #define ARM_GIC(obj) \
  108. OBJECT_CHECK(GICState, (obj), TYPE_ARM_GIC)
  109. #define ARM_GIC_CLASS(klass) \
  110. OBJECT_CLASS_CHECK(ARMGICClass, (klass), TYPE_ARM_GIC)
  111. #define ARM_GIC_GET_CLASS(obj) \
  112. OBJECT_GET_CLASS(ARMGICClass, (obj), TYPE_ARM_GIC)
  113. typedef struct ARMGICClass {
  114. ARMGICCommonClass parent_class;
  115. int (*parent_init)(SysBusDevice *dev);
  116. } ARMGICClass;
  117. #endif /* !QEMU_ARM_GIC_INTERNAL_H */