master
h 121 lines 3.61 KB
Raw
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 qemu_irq_handler observer;
18 };
19
20 void qemu_set_irq(qemu_irq irq, int level);
21
22 static inline void qemu_irq_raise(qemu_irq irq)
23 {
24 qemu_set_irq(irq, 1);
25 }
26
27 static inline void qemu_irq_lower(qemu_irq irq)
28 {
29 qemu_set_irq(irq, 0);
30 }
31
32 static inline void qemu_irq_pulse(qemu_irq irq)
33 {
34 qemu_set_irq(irq, 1);
35 qemu_set_irq(irq, 0);
36 }
37
38 /*
39 * Init a single IRQ. The irq is assigned with a handler, an opaque data
40 * and the interrupt number. The caller must free this with qemu_free_irq().
41 * If you are using this inside a device's init or realize method, then
42 * qemu_init_irq_child() is probably a better choice to avoid the need
43 * to manually clean up the IRQ.
44 */
45 void qemu_init_irq(IRQState *irq, qemu_irq_handler handler, void *opaque,
46 int n);
47
48 /**
49 * qemu_init_irq_child: Initialize IRQ and make it a QOM child
50 * @parent: QOM object which owns this IRQ
51 * @propname: child property name
52 * @irq: pointer to IRQState to initialize
53 * @handler: handler function for incoming interrupts
54 * @opaque: opaque data to pass to @handler
55 * @n: interrupt number to pass to @handler
56 *
57 * Init a single IRQ and make the IRQ object a child of @parent with
58 * the child-property name @propname. The IRQ object will thus be
59 * automatically freed when @parent is destroyed.
60 */
61 void qemu_init_irq_child(Object *parent, const char *propname,
62 IRQState *irq, qemu_irq_handler handler,
63 void *opaque, int n);
64
65
66 /**
67 * qemu_init_irqs: Initialize an array of IRQs.
68 *
69 * @irq: Array of IRQs to initialize
70 * @count: number of IRQs to initialize
71 * @handler: handler to assign to each IRQ
72 * @opaque: opaque data to pass to @handler
73 */
74 void qemu_init_irqs(IRQState irq[], size_t count,
75 qemu_irq_handler handler, void *opaque);
76
77 /* Returns an array of N IRQs. Each IRQ is assigned the argument handler and
78 * opaque data.
79 */
80 qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n);
81
82 /*
83 * Allocates a single IRQ. The irq is assigned with a handler, an opaque
84 * data and the interrupt number.
85 */
86 qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n);
87
88 /* Extends an Array of IRQs. Old IRQs have their handlers and opaque data
89 * preserved. New IRQs are assigned the argument handler and opaque data.
90 */
91 qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
92 void *opaque, int n);
93
94 void qemu_free_irqs(qemu_irq *s, int n);
95 void qemu_free_irq(qemu_irq irq);
96
97 /* Returns a new IRQ with opposite polarity. */
98 qemu_irq qemu_irq_invert(qemu_irq irq);
99
100 /* For internal use in qtest. */
101 void qemu_irq_set_observer(qemu_irq *gpio_in, qemu_irq_handler handler, int n);
102
103 /**
104 * qemu_irq_is_connected: Return true if IRQ line is wired up
105 *
106 * If a qemu_irq has a device on the other (receiving) end of it,
107 * return true; otherwise return false.
108 *
109 * Usually device models don't need to care whether the machine model
110 * has wired up their outbound qemu_irq lines, because functions like
111 * qemu_set_irq() silently do nothing if there is nothing on the other
112 * end of the line. However occasionally a device model will want to
113 * provide default behaviour if its output is left floating, and
114 * it can use this function to identify when that is the case.
115 */
116 static inline bool qemu_irq_is_connected(qemu_irq irq)
117 {
118 return irq != NULL;
119 }
120
121 #endif