irq.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef QEMU_IRQ_H
  2. #define QEMU_IRQ_H
  3. #include "qom/object.h"
  4. /* Generic IRQ/GPIO pin infrastructure. */
  5. #define TYPE_IRQ "irq"
  6. OBJECT_DECLARE_SIMPLE_TYPE(IRQState, IRQ)
  7. struct IRQState {
  8. Object parent_obj;
  9. qemu_irq_handler handler;
  10. void *opaque;
  11. int n;
  12. };
  13. void qemu_set_irq(qemu_irq irq, int level);
  14. static inline void qemu_irq_raise(qemu_irq irq)
  15. {
  16. qemu_set_irq(irq, 1);
  17. }
  18. static inline void qemu_irq_lower(qemu_irq irq)
  19. {
  20. qemu_set_irq(irq, 0);
  21. }
  22. static inline void qemu_irq_pulse(qemu_irq irq)
  23. {
  24. qemu_set_irq(irq, 1);
  25. qemu_set_irq(irq, 0);
  26. }
  27. /*
  28. * Init a single IRQ. The irq is assigned with a handler, an opaque data
  29. * and the interrupt number.
  30. */
  31. void qemu_init_irq(IRQState *irq, qemu_irq_handler handler, void *opaque,
  32. int n);
  33. /**
  34. * qemu_init_irqs: Initialize an array of IRQs.
  35. *
  36. * @irq: Array of IRQs to initialize
  37. * @count: number of IRQs to initialize
  38. * @handler: handler to assign to each IRQ
  39. * @opaque: opaque data to pass to @handler
  40. */
  41. void qemu_init_irqs(IRQState irq[], size_t count,
  42. qemu_irq_handler handler, void *opaque);
  43. /* Returns an array of N IRQs. Each IRQ is assigned the argument handler and
  44. * opaque data.
  45. */
  46. qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n);
  47. /*
  48. * Allocates a single IRQ. The irq is assigned with a handler, an opaque
  49. * data and the interrupt number.
  50. */
  51. qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n);
  52. /* Extends an Array of IRQs. Old IRQs have their handlers and opaque data
  53. * preserved. New IRQs are assigned the argument handler and opaque data.
  54. */
  55. qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
  56. void *opaque, int n);
  57. void qemu_free_irqs(qemu_irq *s, int n);
  58. void qemu_free_irq(qemu_irq irq);
  59. /* Returns a new IRQ with opposite polarity. */
  60. qemu_irq qemu_irq_invert(qemu_irq irq);
  61. /* For internal use in qtest. Similar to qemu_irq_split, but operating
  62. on an existing vector of qemu_irq. */
  63. void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq_handler handler, int n);
  64. /**
  65. * qemu_irq_is_connected: Return true if IRQ line is wired up
  66. *
  67. * If a qemu_irq has a device on the other (receiving) end of it,
  68. * return true; otherwise return false.
  69. *
  70. * Usually device models don't need to care whether the machine model
  71. * has wired up their outbound qemu_irq lines, because functions like
  72. * qemu_set_irq() silently do nothing if there is nothing on the other
  73. * end of the line. However occasionally a device model will want to
  74. * provide default behaviour if its output is left floating, and
  75. * it can use this function to identify when that is the case.
  76. */
  77. static inline bool qemu_irq_is_connected(qemu_irq irq)
  78. {
  79. return irq != NULL;
  80. }
  81. #endif