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