]> Git Repo - qemu.git/blame - hw/intc/heathrow_pic.c
Include hw/irq.h a lot less
[qemu.git] / hw / intc / heathrow_pic.c
CommitLineData
e68b9b2b 1/*
3cbee15b 2 * Heathrow PIC support (OldWorld PowerMac)
5fafdf24 3 *
3cbee15b
JM
4 * Copyright (c) 2005-2007 Fabrice Bellard
5 * Copyright (c) 2007 Jocelyn Mayer
5fafdf24 6 *
e68b9b2b
FB
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
0b8fa32f 25
90191d07 26#include "qemu/osdep.h"
83c9f4ca
PB
27#include "hw/hw.h"
28#include "hw/ppc/mac.h"
0b8fa32f 29#include "qemu/module.h"
086df4f3 30#include "hw/intc/heathrow_pic.h"
64552b6b 31#include "hw/irq.h"
ec7c2709 32#include "trace.h"
e68b9b2b 33
086df4f3 34static inline int heathrow_check_irq(HeathrowPICState *pic)
e68b9b2b
FB
35{
36 return (pic->events | (pic->levels & pic->level_triggered)) & pic->mask;
37}
38
39/* update the CPU irq state */
086df4f3 40static void heathrow_update_irq(HeathrowState *s)
e68b9b2b 41{
086df4f3
MCA
42 if (heathrow_check_irq(&s->pics[0]) ||
43 heathrow_check_irq(&s->pics[1])) {
3cbee15b 44 qemu_irq_raise(s->irqs[0]);
e68b9b2b 45 } else {
3cbee15b 46 qemu_irq_lower(s->irqs[0]);
e68b9b2b
FB
47 }
48}
49
086df4f3
MCA
50static void heathrow_write(void *opaque, hwaddr addr,
51 uint64_t value, unsigned size)
e68b9b2b 52{
086df4f3
MCA
53 HeathrowState *s = opaque;
54 HeathrowPICState *pic;
e68b9b2b
FB
55 unsigned int n;
56
e68b9b2b 57 n = ((addr & 0xfff) - 0x10) >> 4;
ec7c2709 58 trace_heathrow_write(addr, n, value);
e68b9b2b
FB
59 if (n >= 2)
60 return;
61 pic = &s->pics[n];
62 switch(addr & 0xf) {
63 case 0x04:
64 pic->mask = value;
086df4f3 65 heathrow_update_irq(s);
e68b9b2b
FB
66 break;
67 case 0x08:
68 /* do not reset level triggered IRQs */
69 value &= ~pic->level_triggered;
70 pic->events &= ~value;
086df4f3 71 heathrow_update_irq(s);
e68b9b2b
FB
72 break;
73 default:
74 break;
75 }
76}
77
086df4f3
MCA
78static uint64_t heathrow_read(void *opaque, hwaddr addr,
79 unsigned size)
e68b9b2b 80{
086df4f3
MCA
81 HeathrowState *s = opaque;
82 HeathrowPICState *pic;
e68b9b2b
FB
83 unsigned int n;
84 uint32_t value;
3b46e624 85
e68b9b2b
FB
86 n = ((addr & 0xfff) - 0x10) >> 4;
87 if (n >= 2) {
88 value = 0;
89 } else {
90 pic = &s->pics[n];
91 switch(addr & 0xf) {
92 case 0x0:
93 value = pic->events;
94 break;
95 case 0x4:
96 value = pic->mask;
97 break;
98 case 0xc:
99 value = pic->levels;
100 break;
101 default:
102 value = 0;
103 break;
104 }
105 }
ec7c2709 106 trace_heathrow_read(addr, n, value);
e68b9b2b
FB
107 return value;
108}
109
086df4f3
MCA
110static const MemoryRegionOps heathrow_ops = {
111 .read = heathrow_read,
112 .write = heathrow_write,
0157644c 113 .endianness = DEVICE_LITTLE_ENDIAN,
e68b9b2b
FB
114};
115
086df4f3 116static void heathrow_set_irq(void *opaque, int num, int level)
e68b9b2b 117{
086df4f3
MCA
118 HeathrowState *s = opaque;
119 HeathrowPICState *pic;
e68b9b2b 120 unsigned int irq_bit;
ec7c2709 121 int last_level;
e68b9b2b 122
e68b9b2b
FB
123 pic = &s->pics[1 - (num >> 5)];
124 irq_bit = 1 << (num & 0x1f);
ec7c2709
MCA
125 last_level = (pic->levels & irq_bit) ? 1 : 0;
126
e68b9b2b
FB
127 if (level) {
128 pic->events |= irq_bit & ~pic->level_triggered;
129 pic->levels |= irq_bit;
130 } else {
131 pic->levels &= ~irq_bit;
132 }
ec7c2709
MCA
133
134 if (last_level != level) {
135 trace_heathrow_set_irq(num, level);
136 }
137
086df4f3 138 heathrow_update_irq(s);
e68b9b2b
FB
139}
140
4acd38ce
JQ
141static const VMStateDescription vmstate_heathrow_pic_one = {
142 .name = "heathrow_pic_one",
143 .version_id = 0,
144 .minimum_version_id = 0,
3aff6c2f 145 .fields = (VMStateField[]) {
086df4f3
MCA
146 VMSTATE_UINT32(events, HeathrowPICState),
147 VMSTATE_UINT32(mask, HeathrowPICState),
148 VMSTATE_UINT32(levels, HeathrowPICState),
149 VMSTATE_UINT32(level_triggered, HeathrowPICState),
4acd38ce
JQ
150 VMSTATE_END_OF_LIST()
151 }
152};
9b64997f 153
086df4f3 154static const VMStateDescription vmstate_heathrow = {
4acd38ce
JQ
155 .name = "heathrow_pic",
156 .version_id = 1,
157 .minimum_version_id = 1,
3aff6c2f 158 .fields = (VMStateField[]) {
086df4f3
MCA
159 VMSTATE_STRUCT_ARRAY(pics, HeathrowState, 2, 1,
160 vmstate_heathrow_pic_one, HeathrowPICState),
4acd38ce
JQ
161 VMSTATE_END_OF_LIST()
162 }
163};
9b64997f 164
086df4f3 165static void heathrow_reset(DeviceState *d)
6e6b7363 166{
086df4f3
MCA
167 HeathrowState *s = HEATHROW(d);
168
169 s->pics[0].level_triggered = 0;
170 s->pics[1].level_triggered = 0x1ff00000;
6e6b7363
BS
171}
172
086df4f3 173static void heathrow_init(Object *obj)
6e6b7363 174{
086df4f3 175 HeathrowState *s = HEATHROW(obj);
c2964600 176 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
6e6b7363 177
3cbee15b 178 /* only 1 CPU */
a5ed75fe 179 qdev_init_gpio_out(DEVICE(obj), s->irqs, 1);
086df4f3 180
a5ed75fe 181 qdev_init_gpio_in(DEVICE(obj), heathrow_set_irq, HEATHROW_NUM_IRQS);
3cbee15b 182
a5ed75fe
MCA
183 memory_region_init_io(&s->mem, OBJECT(s), &heathrow_ops, s,
184 "heathrow-pic", 0x1000);
185 sysbus_init_mmio(sbd, &s->mem);
086df4f3
MCA
186}
187
188static void heathrow_class_init(ObjectClass *oc, void *data)
189{
190 DeviceClass *dc = DEVICE_CLASS(oc);
191
192 dc->reset = heathrow_reset;
193 dc->vmsd = &vmstate_heathrow;
194 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
e68b9b2b 195}
086df4f3
MCA
196
197static const TypeInfo heathrow_type_info = {
198 .name = TYPE_HEATHROW,
199 .parent = TYPE_SYS_BUS_DEVICE,
200 .instance_size = sizeof(HeathrowState),
201 .instance_init = heathrow_init,
202 .class_init = heathrow_class_init,
203};
204
205static void heathrow_register_types(void)
206{
207 type_register_static(&heathrow_type_info);
208}
209
210type_init(heathrow_register_types)
This page took 0.889026 seconds and 4 git commands to generate.