]> git.proxmox.com Git - mirror_qemu.git/blame - hw/intc/heathrow_pic.c
heathrow: convert to trace-events
[mirror_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 */
90191d07 25#include "qemu/osdep.h"
83c9f4ca
PB
26#include "hw/hw.h"
27#include "hw/ppc/mac.h"
086df4f3 28#include "hw/intc/heathrow_pic.h"
ec7c2709 29#include "trace.h"
e68b9b2b 30
086df4f3 31static inline int heathrow_check_irq(HeathrowPICState *pic)
e68b9b2b
FB
32{
33 return (pic->events | (pic->levels & pic->level_triggered)) & pic->mask;
34}
35
36/* update the CPU irq state */
086df4f3 37static void heathrow_update_irq(HeathrowState *s)
e68b9b2b 38{
086df4f3
MCA
39 if (heathrow_check_irq(&s->pics[0]) ||
40 heathrow_check_irq(&s->pics[1])) {
3cbee15b 41 qemu_irq_raise(s->irqs[0]);
e68b9b2b 42 } else {
3cbee15b 43 qemu_irq_lower(s->irqs[0]);
e68b9b2b
FB
44 }
45}
46
086df4f3
MCA
47static void heathrow_write(void *opaque, hwaddr addr,
48 uint64_t value, unsigned size)
e68b9b2b 49{
086df4f3
MCA
50 HeathrowState *s = opaque;
51 HeathrowPICState *pic;
e68b9b2b
FB
52 unsigned int n;
53
e68b9b2b 54 n = ((addr & 0xfff) - 0x10) >> 4;
ec7c2709 55 trace_heathrow_write(addr, n, value);
e68b9b2b
FB
56 if (n >= 2)
57 return;
58 pic = &s->pics[n];
59 switch(addr & 0xf) {
60 case 0x04:
61 pic->mask = value;
086df4f3 62 heathrow_update_irq(s);
e68b9b2b
FB
63 break;
64 case 0x08:
65 /* do not reset level triggered IRQs */
66 value &= ~pic->level_triggered;
67 pic->events &= ~value;
086df4f3 68 heathrow_update_irq(s);
e68b9b2b
FB
69 break;
70 default:
71 break;
72 }
73}
74
086df4f3
MCA
75static uint64_t heathrow_read(void *opaque, hwaddr addr,
76 unsigned size)
e68b9b2b 77{
086df4f3
MCA
78 HeathrowState *s = opaque;
79 HeathrowPICState *pic;
e68b9b2b
FB
80 unsigned int n;
81 uint32_t value;
3b46e624 82
e68b9b2b
FB
83 n = ((addr & 0xfff) - 0x10) >> 4;
84 if (n >= 2) {
85 value = 0;
86 } else {
87 pic = &s->pics[n];
88 switch(addr & 0xf) {
89 case 0x0:
90 value = pic->events;
91 break;
92 case 0x4:
93 value = pic->mask;
94 break;
95 case 0xc:
96 value = pic->levels;
97 break;
98 default:
99 value = 0;
100 break;
101 }
102 }
ec7c2709 103 trace_heathrow_read(addr, n, value);
e68b9b2b
FB
104 return value;
105}
106
086df4f3
MCA
107static const MemoryRegionOps heathrow_ops = {
108 .read = heathrow_read,
109 .write = heathrow_write,
0157644c 110 .endianness = DEVICE_LITTLE_ENDIAN,
e68b9b2b
FB
111};
112
086df4f3 113static void heathrow_set_irq(void *opaque, int num, int level)
e68b9b2b 114{
086df4f3
MCA
115 HeathrowState *s = opaque;
116 HeathrowPICState *pic;
e68b9b2b 117 unsigned int irq_bit;
ec7c2709 118 int last_level;
e68b9b2b 119
e68b9b2b
FB
120 pic = &s->pics[1 - (num >> 5)];
121 irq_bit = 1 << (num & 0x1f);
ec7c2709
MCA
122 last_level = (pic->levels & irq_bit) ? 1 : 0;
123
e68b9b2b
FB
124 if (level) {
125 pic->events |= irq_bit & ~pic->level_triggered;
126 pic->levels |= irq_bit;
127 } else {
128 pic->levels &= ~irq_bit;
129 }
ec7c2709
MCA
130
131 if (last_level != level) {
132 trace_heathrow_set_irq(num, level);
133 }
134
086df4f3 135 heathrow_update_irq(s);
e68b9b2b
FB
136}
137
4acd38ce
JQ
138static const VMStateDescription vmstate_heathrow_pic_one = {
139 .name = "heathrow_pic_one",
140 .version_id = 0,
141 .minimum_version_id = 0,
3aff6c2f 142 .fields = (VMStateField[]) {
086df4f3
MCA
143 VMSTATE_UINT32(events, HeathrowPICState),
144 VMSTATE_UINT32(mask, HeathrowPICState),
145 VMSTATE_UINT32(levels, HeathrowPICState),
146 VMSTATE_UINT32(level_triggered, HeathrowPICState),
4acd38ce
JQ
147 VMSTATE_END_OF_LIST()
148 }
149};
9b64997f 150
086df4f3 151static const VMStateDescription vmstate_heathrow = {
4acd38ce
JQ
152 .name = "heathrow_pic",
153 .version_id = 1,
154 .minimum_version_id = 1,
3aff6c2f 155 .fields = (VMStateField[]) {
086df4f3
MCA
156 VMSTATE_STRUCT_ARRAY(pics, HeathrowState, 2, 1,
157 vmstate_heathrow_pic_one, HeathrowPICState),
4acd38ce
JQ
158 VMSTATE_END_OF_LIST()
159 }
160};
9b64997f 161
086df4f3 162static void heathrow_reset(DeviceState *d)
6e6b7363 163{
086df4f3
MCA
164 HeathrowState *s = HEATHROW(d);
165
166 s->pics[0].level_triggered = 0;
167 s->pics[1].level_triggered = 0x1ff00000;
6e6b7363
BS
168}
169
086df4f3 170static void heathrow_init(Object *obj)
6e6b7363 171{
086df4f3 172 HeathrowState *s = HEATHROW(obj);
6e6b7363 173
086df4f3
MCA
174 memory_region_init_io(&s->mem, OBJECT(s), &heathrow_ops, s,
175 "heathrow-pic", 0x1000);
6e6b7363
BS
176}
177
23c5e4ca 178qemu_irq *heathrow_pic_init(MemoryRegion **pmem,
3cbee15b 179 int nb_cpus, qemu_irq **irqs)
e68b9b2b 180{
086df4f3
MCA
181 DeviceState *d;
182 HeathrowState *s;
3b46e624 183
086df4f3
MCA
184 d = qdev_create(NULL, TYPE_HEATHROW);
185 qdev_init_nofail(d);
186
187 s = HEATHROW(d);
3cbee15b
JM
188 /* only 1 CPU */
189 s->irqs = irqs[0];
086df4f3 190
23c5e4ca 191 *pmem = &s->mem;
3cbee15b 192
086df4f3
MCA
193 return qemu_allocate_irqs(heathrow_set_irq, s, HEATHROW_NUM_IRQS);
194}
195
196static void heathrow_class_init(ObjectClass *oc, void *data)
197{
198 DeviceClass *dc = DEVICE_CLASS(oc);
199
200 dc->reset = heathrow_reset;
201 dc->vmsd = &vmstate_heathrow;
202 set_bit(DEVICE_CATEGORY_MISC, dc->categories);
e68b9b2b 203}
086df4f3
MCA
204
205static const TypeInfo heathrow_type_info = {
206 .name = TYPE_HEATHROW,
207 .parent = TYPE_SYS_BUS_DEVICE,
208 .instance_size = sizeof(HeathrowState),
209 .instance_init = heathrow_init,
210 .class_init = heathrow_class_init,
211};
212
213static void heathrow_register_types(void)
214{
215 type_register_static(&heathrow_type_info);
216}
217
218type_init(heathrow_register_types)