]> git.proxmox.com Git - mirror_qemu.git/blame - hw/heathrow_pic.c
sd.c build fix.
[mirror_qemu.git] / hw / 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 */
25#include "vl.h"
3cbee15b 26#include "ppc_mac.h"
e68b9b2b
FB
27
28//#define DEBUG
29
30typedef struct HeathrowPIC {
31 uint32_t events;
32 uint32_t mask;
33 uint32_t levels;
34 uint32_t level_triggered;
35} HeathrowPIC;
36
d537cf6c 37typedef struct HeathrowPICS {
e68b9b2b 38 HeathrowPIC pics[2];
3cbee15b 39 qemu_irq *irqs;
d537cf6c 40} HeathrowPICS;
e68b9b2b
FB
41
42static inline int check_irq(HeathrowPIC *pic)
43{
44 return (pic->events | (pic->levels & pic->level_triggered)) & pic->mask;
45}
46
47/* update the CPU irq state */
48static void heathrow_pic_update(HeathrowPICS *s)
49{
50 if (check_irq(&s->pics[0]) || check_irq(&s->pics[1])) {
3cbee15b 51 qemu_irq_raise(s->irqs[0]);
e68b9b2b 52 } else {
3cbee15b 53 qemu_irq_lower(s->irqs[0]);
e68b9b2b
FB
54 }
55}
56
57static void pic_writel (void *opaque, target_phys_addr_t addr, uint32_t value)
58{
59 HeathrowPICS *s = opaque;
60 HeathrowPIC *pic;
61 unsigned int n;
62
3cbee15b 63#ifdef TARGET_WORDS_BIGENDIAN
e68b9b2b 64 value = bswap32(value);
e68b9b2b
FB
65#endif
66 n = ((addr & 0xfff) - 0x10) >> 4;
3cbee15b
JM
67#ifdef DEBUG
68 printf("pic_writel: " PADDRX " %u: %08x\n", addr, n, value);
69#endif
e68b9b2b
FB
70 if (n >= 2)
71 return;
72 pic = &s->pics[n];
73 switch(addr & 0xf) {
74 case 0x04:
75 pic->mask = value;
76 heathrow_pic_update(s);
77 break;
78 case 0x08:
79 /* do not reset level triggered IRQs */
80 value &= ~pic->level_triggered;
81 pic->events &= ~value;
82 heathrow_pic_update(s);
83 break;
84 default:
85 break;
86 }
87}
88
89static uint32_t pic_readl (void *opaque, target_phys_addr_t addr)
90{
91 HeathrowPICS *s = opaque;
92 HeathrowPIC *pic;
93 unsigned int n;
94 uint32_t value;
3b46e624 95
e68b9b2b
FB
96 n = ((addr & 0xfff) - 0x10) >> 4;
97 if (n >= 2) {
98 value = 0;
99 } else {
100 pic = &s->pics[n];
101 switch(addr & 0xf) {
102 case 0x0:
103 value = pic->events;
104 break;
105 case 0x4:
106 value = pic->mask;
107 break;
108 case 0xc:
109 value = pic->levels;
110 break;
111 default:
112 value = 0;
113 break;
114 }
115 }
116#ifdef DEBUG
3cbee15b 117 printf("pic_readl: " PADDRX " %u: %08x\n", addr, n, value);
e68b9b2b 118#endif
3cbee15b 119#ifdef TARGET_WORDS_BIGENDIAN
e68b9b2b 120 value = bswap32(value);
3cbee15b 121#endif
e68b9b2b
FB
122 return value;
123}
124
125static CPUWriteMemoryFunc *pic_write[] = {
126 &pic_writel,
127 &pic_writel,
128 &pic_writel,
129};
130
131static CPUReadMemoryFunc *pic_read[] = {
132 &pic_readl,
133 &pic_readl,
134 &pic_readl,
135};
136
137
d537cf6c 138static void heathrow_pic_set_irq(void *opaque, int num, int level)
e68b9b2b
FB
139{
140 HeathrowPICS *s = opaque;
141 HeathrowPIC *pic;
142 unsigned int irq_bit;
143
144#if defined(DEBUG)
145 {
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;
150 }
151 }
152#endif
153 pic = &s->pics[1 - (num >> 5)];
154 irq_bit = 1 << (num & 0x1f);
155 if (level) {
156 pic->events |= irq_bit & ~pic->level_triggered;
157 pic->levels |= irq_bit;
158 } else {
159 pic->levels &= ~irq_bit;
160 }
161 heathrow_pic_update(s);
162}
163
3cbee15b
JM
164qemu_irq *heathrow_pic_init(int *pmem_index,
165 int nb_cpus, qemu_irq **irqs)
e68b9b2b
FB
166{
167 HeathrowPICS *s;
3b46e624 168
e68b9b2b
FB
169 s = qemu_mallocz(sizeof(HeathrowPICS));
170 s->pics[0].level_triggered = 0;
171 s->pics[1].level_triggered = 0x1ff00000;
3cbee15b
JM
172 /* only 1 CPU */
173 s->irqs = irqs[0];
e68b9b2b 174 *pmem_index = cpu_register_io_memory(0, pic_read, pic_write, s);
3cbee15b 175
d537cf6c 176 return qemu_allocate_irqs(heathrow_pic_set_irq, s, 64);
e68b9b2b 177}