2 * Heathrow PIC support (OldWorld PowerMac)
4 * Copyright (c) 2005-2007 Fabrice Bellard
5 * Copyright (c) 2007 Jocelyn Mayer
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
25 #include "qemu/osdep.h"
27 #include "hw/ppc/mac.h"
28 #include "hw/intc/heathrow_pic.h"
31 static inline int heathrow_check_irq(HeathrowPICState
*pic
)
33 return (pic
->events
| (pic
->levels
& pic
->level_triggered
)) & pic
->mask
;
36 /* update the CPU irq state */
37 static void heathrow_update_irq(HeathrowState
*s
)
39 if (heathrow_check_irq(&s
->pics
[0]) ||
40 heathrow_check_irq(&s
->pics
[1])) {
41 qemu_irq_raise(s
->irqs
[0]);
43 qemu_irq_lower(s
->irqs
[0]);
47 static void heathrow_write(void *opaque
, hwaddr addr
,
48 uint64_t value
, unsigned size
)
50 HeathrowState
*s
= opaque
;
51 HeathrowPICState
*pic
;
54 n
= ((addr
& 0xfff) - 0x10) >> 4;
55 trace_heathrow_write(addr
, n
, value
);
62 heathrow_update_irq(s
);
65 /* do not reset level triggered IRQs */
66 value
&= ~pic
->level_triggered
;
67 pic
->events
&= ~value
;
68 heathrow_update_irq(s
);
75 static uint64_t heathrow_read(void *opaque
, hwaddr addr
,
78 HeathrowState
*s
= opaque
;
79 HeathrowPICState
*pic
;
83 n
= ((addr
& 0xfff) - 0x10) >> 4;
103 trace_heathrow_read(addr
, n
, value
);
107 static const MemoryRegionOps heathrow_ops
= {
108 .read
= heathrow_read
,
109 .write
= heathrow_write
,
110 .endianness
= DEVICE_LITTLE_ENDIAN
,
113 static void heathrow_set_irq(void *opaque
, int num
, int level
)
115 HeathrowState
*s
= opaque
;
116 HeathrowPICState
*pic
;
117 unsigned int irq_bit
;
120 pic
= &s
->pics
[1 - (num
>> 5)];
121 irq_bit
= 1 << (num
& 0x1f);
122 last_level
= (pic
->levels
& irq_bit
) ? 1 : 0;
125 pic
->events
|= irq_bit
& ~pic
->level_triggered
;
126 pic
->levels
|= irq_bit
;
128 pic
->levels
&= ~irq_bit
;
131 if (last_level
!= level
) {
132 trace_heathrow_set_irq(num
, level
);
135 heathrow_update_irq(s
);
138 static const VMStateDescription vmstate_heathrow_pic_one
= {
139 .name
= "heathrow_pic_one",
141 .minimum_version_id
= 0,
142 .fields
= (VMStateField
[]) {
143 VMSTATE_UINT32(events
, HeathrowPICState
),
144 VMSTATE_UINT32(mask
, HeathrowPICState
),
145 VMSTATE_UINT32(levels
, HeathrowPICState
),
146 VMSTATE_UINT32(level_triggered
, HeathrowPICState
),
147 VMSTATE_END_OF_LIST()
151 static const VMStateDescription vmstate_heathrow
= {
152 .name
= "heathrow_pic",
154 .minimum_version_id
= 1,
155 .fields
= (VMStateField
[]) {
156 VMSTATE_STRUCT_ARRAY(pics
, HeathrowState
, 2, 1,
157 vmstate_heathrow_pic_one
, HeathrowPICState
),
158 VMSTATE_END_OF_LIST()
162 static void heathrow_reset(DeviceState
*d
)
164 HeathrowState
*s
= HEATHROW(d
);
166 s
->pics
[0].level_triggered
= 0;
167 s
->pics
[1].level_triggered
= 0x1ff00000;
170 static void heathrow_init(Object
*obj
)
172 HeathrowState
*s
= HEATHROW(obj
);
173 SysBusDevice
*sbd
= SYS_BUS_DEVICE(obj
);
175 memory_region_init_io(&s
->mem
, OBJECT(s
), &heathrow_ops
, s
,
176 "heathrow-pic", 0x1000);
177 sysbus_init_mmio(sbd
, &s
->mem
);
180 DeviceState
*heathrow_pic_init(int nb_cpus
, qemu_irq
**irqs
,
186 d
= qdev_create(NULL
, TYPE_HEATHROW
);
193 *pic_irqs
= qemu_allocate_irqs(heathrow_set_irq
, s
, HEATHROW_NUM_IRQS
);
198 static void heathrow_class_init(ObjectClass
*oc
, void *data
)
200 DeviceClass
*dc
= DEVICE_CLASS(oc
);
202 dc
->reset
= heathrow_reset
;
203 dc
->vmsd
= &vmstate_heathrow
;
204 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
207 static const TypeInfo heathrow_type_info
= {
208 .name
= TYPE_HEATHROW
,
209 .parent
= TYPE_SYS_BUS_DEVICE
,
210 .instance_size
= sizeof(HeathrowState
),
211 .instance_init
= heathrow_init
,
212 .class_init
= heathrow_class_init
,
215 static void heathrow_register_types(void)
217 type_register_static(&heathrow_type_info
);
220 type_init(heathrow_register_types
)