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
32 #define PIC_DPRINTF(fmt, ...) \
33 do { printf("PIC: " fmt , ## __VA_ARGS__); } while (0)
35 #define PIC_DPRINTF(fmt, ...)
38 typedef struct HeathrowPIC
{
42 uint32_t level_triggered
;
45 typedef struct HeathrowPICS
{
50 static inline int check_irq(HeathrowPIC
*pic
)
52 return (pic
->events
| (pic
->levels
& pic
->level_triggered
)) & pic
->mask
;
55 /* update the CPU irq state */
56 static void heathrow_pic_update(HeathrowPICS
*s
)
58 if (check_irq(&s
->pics
[0]) || check_irq(&s
->pics
[1])) {
59 qemu_irq_raise(s
->irqs
[0]);
61 qemu_irq_lower(s
->irqs
[0]);
65 static void pic_writel (void *opaque
, target_phys_addr_t addr
, uint32_t value
)
67 HeathrowPICS
*s
= opaque
;
71 n
= ((addr
& 0xfff) - 0x10) >> 4;
72 PIC_DPRINTF("writel: " TARGET_FMT_plx
" %u: %08x\n", addr
, n
, value
);
79 heathrow_pic_update(s
);
82 /* do not reset level triggered IRQs */
83 value
&= ~pic
->level_triggered
;
84 pic
->events
&= ~value
;
85 heathrow_pic_update(s
);
92 static uint32_t pic_readl (void *opaque
, target_phys_addr_t addr
)
94 HeathrowPICS
*s
= opaque
;
99 n
= ((addr
& 0xfff) - 0x10) >> 4;
119 PIC_DPRINTF("readl: " TARGET_FMT_plx
" %u: %08x\n", addr
, n
, value
);
123 static CPUWriteMemoryFunc
* const pic_write
[] = {
129 static CPUReadMemoryFunc
* const pic_read
[] = {
136 static void heathrow_pic_set_irq(void *opaque
, int num
, int level
)
138 HeathrowPICS
*s
= opaque
;
140 unsigned int irq_bit
;
144 static int last_level
[64];
145 if (last_level
[num
] != level
) {
146 PIC_DPRINTF("set_irq: num=0x%02x level=%d\n", num
, level
);
147 last_level
[num
] = level
;
151 pic
= &s
->pics
[1 - (num
>> 5)];
152 irq_bit
= 1 << (num
& 0x1f);
154 pic
->events
|= irq_bit
& ~pic
->level_triggered
;
155 pic
->levels
|= irq_bit
;
157 pic
->levels
&= ~irq_bit
;
159 heathrow_pic_update(s
);
162 static const VMStateDescription vmstate_heathrow_pic_one
= {
163 .name
= "heathrow_pic_one",
165 .minimum_version_id
= 0,
166 .minimum_version_id_old
= 0,
167 .fields
= (VMStateField
[]) {
168 VMSTATE_UINT32(events
, HeathrowPIC
),
169 VMSTATE_UINT32(mask
, HeathrowPIC
),
170 VMSTATE_UINT32(levels
, HeathrowPIC
),
171 VMSTATE_UINT32(level_triggered
, HeathrowPIC
),
172 VMSTATE_END_OF_LIST()
176 static const VMStateDescription vmstate_heathrow_pic
= {
177 .name
= "heathrow_pic",
179 .minimum_version_id
= 1,
180 .minimum_version_id_old
= 1,
181 .fields
= (VMStateField
[]) {
182 VMSTATE_STRUCT_ARRAY(pics
, HeathrowPICS
, 2, 1,
183 vmstate_heathrow_pic_one
, HeathrowPIC
),
184 VMSTATE_END_OF_LIST()
188 static void heathrow_pic_reset_one(HeathrowPIC
*s
)
190 memset(s
, '\0', sizeof(HeathrowPIC
));
193 static void heathrow_pic_reset(void *opaque
)
195 HeathrowPICS
*s
= opaque
;
197 heathrow_pic_reset_one(&s
->pics
[0]);
198 heathrow_pic_reset_one(&s
->pics
[1]);
200 s
->pics
[0].level_triggered
= 0;
201 s
->pics
[1].level_triggered
= 0x1ff00000;
204 qemu_irq
*heathrow_pic_init(int *pmem_index
,
205 int nb_cpus
, qemu_irq
**irqs
)
209 s
= qemu_mallocz(sizeof(HeathrowPICS
));
212 *pmem_index
= cpu_register_io_memory(pic_read
, pic_write
, s
,
213 DEVICE_LITTLE_ENDIAN
);
215 vmstate_register(NULL
, -1, &vmstate_heathrow_pic
, s
);
216 qemu_register_reset(heathrow_pic_reset
, s
);
217 return qemu_allocate_irqs(heathrow_pic_set_irq
, s
, 64);