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