gic_internal.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "hw/intc/arm_gic.h"
  23. #define ALL_CPU_MASK ((unsigned)(((1 << GIC_NCPU) - 1)))
  24. /* The NVIC has 16 internal vectors. However these are not exposed
  25. through the normal GIC interface. */
  26. #define GIC_BASE_IRQ ((s->revision == REV_NVIC) ? 32 : 0)
  27. #define GIC_SET_ENABLED(irq, cm) s->irq_state[irq].enabled |= (cm)
  28. #define GIC_CLEAR_ENABLED(irq, cm) s->irq_state[irq].enabled &= ~(cm)
  29. #define GIC_TEST_ENABLED(irq, cm) ((s->irq_state[irq].enabled & (cm)) != 0)
  30. #define GIC_SET_PENDING(irq, cm) s->irq_state[irq].pending |= (cm)
  31. #define GIC_CLEAR_PENDING(irq, cm) s->irq_state[irq].pending &= ~(cm)
  32. #define GIC_SET_ACTIVE(irq, cm) s->irq_state[irq].active |= (cm)
  33. #define GIC_CLEAR_ACTIVE(irq, cm) s->irq_state[irq].active &= ~(cm)
  34. #define GIC_TEST_ACTIVE(irq, cm) ((s->irq_state[irq].active & (cm)) != 0)
  35. #define GIC_SET_MODEL(irq) s->irq_state[irq].model = true
  36. #define GIC_CLEAR_MODEL(irq) s->irq_state[irq].model = false
  37. #define GIC_TEST_MODEL(irq) s->irq_state[irq].model
  38. #define GIC_SET_LEVEL(irq, cm) s->irq_state[irq].level |= (cm)
  39. #define GIC_CLEAR_LEVEL(irq, cm) s->irq_state[irq].level &= ~(cm)
  40. #define GIC_TEST_LEVEL(irq, cm) ((s->irq_state[irq].level & (cm)) != 0)
  41. #define GIC_SET_EDGE_TRIGGER(irq) s->irq_state[irq].edge_trigger = true
  42. #define GIC_CLEAR_EDGE_TRIGGER(irq) s->irq_state[irq].edge_trigger = false
  43. #define GIC_TEST_EDGE_TRIGGER(irq) (s->irq_state[irq].edge_trigger)
  44. #define GIC_GET_PRIORITY(irq, cpu) (((irq) < GIC_INTERNAL) ? \
  45. s->priority1[irq][cpu] : \
  46. s->priority2[(irq) - GIC_INTERNAL])
  47. #define GIC_TARGET(irq) s->irq_target[irq]
  48. /* The special cases for the revision property: */
  49. #define REV_11MPCORE 0
  50. #define REV_NVIC 0xffffffff
  51. void gic_set_pending_private(GICState *s, int cpu, int irq);
  52. uint32_t gic_acknowledge_irq(GICState *s, int cpu);
  53. void gic_complete_irq(GICState *s, int cpu, int irq);
  54. void gic_update(GICState *s);
  55. void gic_init_irqs_and_distributor(GICState *s, int num_irq);
  56. void gic_set_priority(GICState *s, int cpu, int irq, uint8_t val);
  57. static inline bool gic_test_pending(GICState *s, int irq, int cm)
  58. {
  59. if (s->revision == REV_NVIC || s->revision == REV_11MPCORE) {
  60. return s->irq_state[irq].pending & cm;
  61. } else {
  62. /* Edge-triggered interrupts are marked pending on a rising edge, but
  63. * level-triggered interrupts are either considered pending when the
  64. * level is active or if software has explicitly written to
  65. * GICD_ISPENDR to set the state pending.
  66. */
  67. return (s->irq_state[irq].pending & cm) ||
  68. (!GIC_TEST_EDGE_TRIGGER(irq) && GIC_TEST_LEVEL(irq, cm));
  69. }
  70. }
  71. #endif /* !QEMU_ARM_GIC_INTERNAL_H */