root / hw / irq.c @ 3c4cf535
History | View | Annotate | Download (2.2 kB)
1 | d537cf6c | pbrook | /*
|
---|---|---|---|
2 | d537cf6c | pbrook | * QEMU IRQ/GPIO common code.
|
3 | 5fafdf24 | ths | *
|
4 | d537cf6c | pbrook | * Copyright (c) 2007 CodeSourcery.
|
5 | 5fafdf24 | ths | *
|
6 | d537cf6c | pbrook | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | d537cf6c | pbrook | * of this software and associated documentation files (the "Software"), to deal
|
8 | d537cf6c | pbrook | * in the Software without restriction, including without limitation the rights
|
9 | d537cf6c | pbrook | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | d537cf6c | pbrook | * copies of the Software, and to permit persons to whom the Software is
|
11 | d537cf6c | pbrook | * furnished to do so, subject to the following conditions:
|
12 | d537cf6c | pbrook | *
|
13 | d537cf6c | pbrook | * The above copyright notice and this permission notice shall be included in
|
14 | d537cf6c | pbrook | * all copies or substantial portions of the Software.
|
15 | d537cf6c | pbrook | *
|
16 | d537cf6c | pbrook | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | d537cf6c | pbrook | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | d537cf6c | pbrook | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | d537cf6c | pbrook | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | d537cf6c | pbrook | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | d537cf6c | pbrook | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | d537cf6c | pbrook | * THE SOFTWARE.
|
23 | d537cf6c | pbrook | */
|
24 | 87ecb68b | pbrook | #include "qemu-common.h" |
25 | 87ecb68b | pbrook | #include "irq.h" |
26 | d537cf6c | pbrook | |
27 | d537cf6c | pbrook | struct IRQState {
|
28 | d537cf6c | pbrook | qemu_irq_handler handler; |
29 | d537cf6c | pbrook | void *opaque;
|
30 | d537cf6c | pbrook | int n;
|
31 | d537cf6c | pbrook | }; |
32 | d537cf6c | pbrook | |
33 | d537cf6c | pbrook | void qemu_set_irq(qemu_irq irq, int level) |
34 | d537cf6c | pbrook | { |
35 | d537cf6c | pbrook | if (!irq)
|
36 | d537cf6c | pbrook | return;
|
37 | d537cf6c | pbrook | |
38 | d537cf6c | pbrook | irq->handler(irq->opaque, irq->n, level); |
39 | d537cf6c | pbrook | } |
40 | d537cf6c | pbrook | |
41 | d537cf6c | pbrook | qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n) |
42 | d537cf6c | pbrook | { |
43 | d537cf6c | pbrook | qemu_irq *s; |
44 | d537cf6c | pbrook | struct IRQState *p;
|
45 | d537cf6c | pbrook | int i;
|
46 | d537cf6c | pbrook | |
47 | d537cf6c | pbrook | s = (qemu_irq *)qemu_mallocz(sizeof(qemu_irq) * n);
|
48 | d537cf6c | pbrook | p = (struct IRQState *)qemu_mallocz(sizeof(struct IRQState) * n); |
49 | d537cf6c | pbrook | for (i = 0; i < n; i++) { |
50 | d537cf6c | pbrook | p->handler = handler; |
51 | d537cf6c | pbrook | p->opaque = opaque; |
52 | d537cf6c | pbrook | p->n = i; |
53 | d537cf6c | pbrook | s[i] = p; |
54 | d537cf6c | pbrook | p++; |
55 | d537cf6c | pbrook | } |
56 | d537cf6c | pbrook | return s;
|
57 | d537cf6c | pbrook | } |
58 | d537cf6c | pbrook | |
59 | 51bf9e7e | aliguori | void qemu_free_irqs(qemu_irq *s)
|
60 | 51bf9e7e | aliguori | { |
61 | 51bf9e7e | aliguori | qemu_free(s[0]);
|
62 | 51bf9e7e | aliguori | qemu_free(s); |
63 | 51bf9e7e | aliguori | } |
64 | 51bf9e7e | aliguori | |
65 | b50a6563 | balrog | static void qemu_notirq(void *opaque, int line, int level) |
66 | b50a6563 | balrog | { |
67 | b50a6563 | balrog | struct IRQState *irq = opaque;
|
68 | b50a6563 | balrog | |
69 | b50a6563 | balrog | irq->handler(irq->opaque, irq->n, !level); |
70 | b50a6563 | balrog | } |
71 | b50a6563 | balrog | |
72 | b50a6563 | balrog | qemu_irq qemu_irq_invert(qemu_irq irq) |
73 | b50a6563 | balrog | { |
74 | cf0dbb21 | pbrook | /* The default state for IRQs is low, so raise the output now. */
|
75 | cf0dbb21 | pbrook | qemu_irq_raise(irq); |
76 | b50a6563 | balrog | return qemu_allocate_irqs(qemu_notirq, irq, 1)[0]; |
77 | b50a6563 | balrog | } |