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
30 typedef struct HeathrowPIC {
34 uint32_t level_triggered;
37 typedef struct HeathrowPICS {
42 static inline int check_irq(HeathrowPIC *pic)
44 return (pic->events | (pic->levels & pic->level_triggered)) & pic->mask;
47 /* update the CPU irq state */
48 static void heathrow_pic_update(HeathrowPICS *s)
50 if (check_irq(&s->pics[0]) || check_irq(&s->pics[1])) {
51 qemu_irq_raise(s->irqs[0]);
53 qemu_irq_lower(s->irqs[0]);
57 static void pic_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
59 HeathrowPICS *s = opaque;
63 #ifdef TARGET_WORDS_BIGENDIAN
64 value = bswap32(value);
66 n = ((addr & 0xfff) - 0x10) >> 4;
68 printf("pic_writel: " PADDRX " %u: %08x\n", addr, n, value);
76 heathrow_pic_update(s);
79 /* do not reset level triggered IRQs */
80 value &= ~pic->level_triggered;
81 pic->events &= ~value;
82 heathrow_pic_update(s);
89 static uint32_t pic_readl (void *opaque, target_phys_addr_t addr)
91 HeathrowPICS *s = opaque;
96 n = ((addr & 0xfff) - 0x10) >> 4;
117 printf("pic_readl: " PADDRX " %u: %08x\n", addr, n, value);
119 #ifdef TARGET_WORDS_BIGENDIAN
120 value = bswap32(value);
125 static CPUWriteMemoryFunc *pic_write[] = {
131 static CPUReadMemoryFunc *pic_read[] = {
138 static void heathrow_pic_set_irq(void *opaque, int num, int level)
140 HeathrowPICS *s = opaque;
142 unsigned int irq_bit;
146 static int last_level[64];
147 if (last_level[num] != level) {
148 printf("set_irq: num=0x%02x level=%d\n", num, level);
149 last_level[num] = level;
153 pic = &s->pics[1 - (num >> 5)];
154 irq_bit = 1 << (num & 0x1f);
156 pic->events |= irq_bit & ~pic->level_triggered;
157 pic->levels |= irq_bit;
159 pic->levels &= ~irq_bit;
161 heathrow_pic_update(s);
164 qemu_irq *heathrow_pic_init(int *pmem_index,
165 int nb_cpus, qemu_irq **irqs)
169 s = qemu_mallocz(sizeof(HeathrowPICS));
170 s->pics[0].level_triggered = 0;
171 s->pics[1].level_triggered = 0x1ff00000;
174 *pmem_index = cpu_register_io_memory(0, pic_read, pic_write, s);
176 return qemu_allocate_irqs(heathrow_pic_set_irq, s, 64);