root / hw / heathrow_pic.c @ 4b816985
History | View | Annotate | Download (6 kB)
1 | e68b9b2b | bellard | /*
|
---|---|---|---|
2 | 3cbee15b | j_mayer | * Heathrow PIC support (OldWorld PowerMac)
|
3 | 5fafdf24 | ths | *
|
4 | 3cbee15b | j_mayer | * Copyright (c) 2005-2007 Fabrice Bellard
|
5 | 3cbee15b | j_mayer | * Copyright (c) 2007 Jocelyn Mayer
|
6 | 5fafdf24 | ths | *
|
7 | e68b9b2b | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 | e68b9b2b | bellard | * of this software and associated documentation files (the "Software"), to deal
|
9 | e68b9b2b | bellard | * in the Software without restriction, including without limitation the rights
|
10 | e68b9b2b | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 | e68b9b2b | bellard | * copies of the Software, and to permit persons to whom the Software is
|
12 | e68b9b2b | bellard | * furnished to do so, subject to the following conditions:
|
13 | e68b9b2b | bellard | *
|
14 | e68b9b2b | bellard | * The above copyright notice and this permission notice shall be included in
|
15 | e68b9b2b | bellard | * all copies or substantial portions of the Software.
|
16 | e68b9b2b | bellard | *
|
17 | e68b9b2b | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 | e68b9b2b | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 | e68b9b2b | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
20 | e68b9b2b | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 | e68b9b2b | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 | e68b9b2b | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 | e68b9b2b | bellard | * THE SOFTWARE.
|
24 | e68b9b2b | bellard | */
|
25 | 87ecb68b | pbrook | #include "hw.h" |
26 | 3cbee15b | j_mayer | #include "ppc_mac.h" |
27 | e68b9b2b | bellard | |
28 | ea026b2f | blueswir1 | /* debug PIC */
|
29 | ea026b2f | blueswir1 | //#define DEBUG_PIC
|
30 | ea026b2f | blueswir1 | |
31 | ea026b2f | blueswir1 | #ifdef DEBUG_PIC
|
32 | 001faf32 | Blue Swirl | #define PIC_DPRINTF(fmt, ...) \
|
33 | 001faf32 | Blue Swirl | do { printf("PIC: " fmt , ## __VA_ARGS__); } while (0) |
34 | ea026b2f | blueswir1 | #else
|
35 | 001faf32 | Blue Swirl | #define PIC_DPRINTF(fmt, ...)
|
36 | ea026b2f | blueswir1 | #endif
|
37 | e68b9b2b | bellard | |
38 | e68b9b2b | bellard | typedef struct HeathrowPIC { |
39 | e68b9b2b | bellard | uint32_t events; |
40 | e68b9b2b | bellard | uint32_t mask; |
41 | e68b9b2b | bellard | uint32_t levels; |
42 | e68b9b2b | bellard | uint32_t level_triggered; |
43 | e68b9b2b | bellard | } HeathrowPIC; |
44 | e68b9b2b | bellard | |
45 | d537cf6c | pbrook | typedef struct HeathrowPICS { |
46 | e68b9b2b | bellard | HeathrowPIC pics[2];
|
47 | 3cbee15b | j_mayer | qemu_irq *irqs; |
48 | d537cf6c | pbrook | } HeathrowPICS; |
49 | e68b9b2b | bellard | |
50 | e68b9b2b | bellard | static inline int check_irq(HeathrowPIC *pic) |
51 | e68b9b2b | bellard | { |
52 | e68b9b2b | bellard | return (pic->events | (pic->levels & pic->level_triggered)) & pic->mask;
|
53 | e68b9b2b | bellard | } |
54 | e68b9b2b | bellard | |
55 | e68b9b2b | bellard | /* update the CPU irq state */
|
56 | e68b9b2b | bellard | static void heathrow_pic_update(HeathrowPICS *s) |
57 | e68b9b2b | bellard | { |
58 | e68b9b2b | bellard | if (check_irq(&s->pics[0]) || check_irq(&s->pics[1])) { |
59 | 3cbee15b | j_mayer | qemu_irq_raise(s->irqs[0]);
|
60 | e68b9b2b | bellard | } else {
|
61 | 3cbee15b | j_mayer | qemu_irq_lower(s->irqs[0]);
|
62 | e68b9b2b | bellard | } |
63 | e68b9b2b | bellard | } |
64 | e68b9b2b | bellard | |
65 | e68b9b2b | bellard | static void pic_writel (void *opaque, target_phys_addr_t addr, uint32_t value) |
66 | e68b9b2b | bellard | { |
67 | e68b9b2b | bellard | HeathrowPICS *s = opaque; |
68 | e68b9b2b | bellard | HeathrowPIC *pic; |
69 | e68b9b2b | bellard | unsigned int n; |
70 | e68b9b2b | bellard | |
71 | 3cbee15b | j_mayer | #ifdef TARGET_WORDS_BIGENDIAN
|
72 | e68b9b2b | bellard | value = bswap32(value); |
73 | e68b9b2b | bellard | #endif
|
74 | e68b9b2b | bellard | n = ((addr & 0xfff) - 0x10) >> 4; |
75 | ea026b2f | blueswir1 | PIC_DPRINTF("writel: " TARGET_FMT_plx " %u: %08x\n", addr, n, value); |
76 | e68b9b2b | bellard | if (n >= 2) |
77 | e68b9b2b | bellard | return;
|
78 | e68b9b2b | bellard | pic = &s->pics[n]; |
79 | e68b9b2b | bellard | switch(addr & 0xf) { |
80 | e68b9b2b | bellard | case 0x04: |
81 | e68b9b2b | bellard | pic->mask = value; |
82 | e68b9b2b | bellard | heathrow_pic_update(s); |
83 | e68b9b2b | bellard | break;
|
84 | e68b9b2b | bellard | case 0x08: |
85 | e68b9b2b | bellard | /* do not reset level triggered IRQs */
|
86 | e68b9b2b | bellard | value &= ~pic->level_triggered; |
87 | e68b9b2b | bellard | pic->events &= ~value; |
88 | e68b9b2b | bellard | heathrow_pic_update(s); |
89 | e68b9b2b | bellard | break;
|
90 | e68b9b2b | bellard | default:
|
91 | e68b9b2b | bellard | break;
|
92 | e68b9b2b | bellard | } |
93 | e68b9b2b | bellard | } |
94 | e68b9b2b | bellard | |
95 | e68b9b2b | bellard | static uint32_t pic_readl (void *opaque, target_phys_addr_t addr) |
96 | e68b9b2b | bellard | { |
97 | e68b9b2b | bellard | HeathrowPICS *s = opaque; |
98 | e68b9b2b | bellard | HeathrowPIC *pic; |
99 | e68b9b2b | bellard | unsigned int n; |
100 | e68b9b2b | bellard | uint32_t value; |
101 | 3b46e624 | ths | |
102 | e68b9b2b | bellard | n = ((addr & 0xfff) - 0x10) >> 4; |
103 | e68b9b2b | bellard | if (n >= 2) { |
104 | e68b9b2b | bellard | value = 0;
|
105 | e68b9b2b | bellard | } else {
|
106 | e68b9b2b | bellard | pic = &s->pics[n]; |
107 | e68b9b2b | bellard | switch(addr & 0xf) { |
108 | e68b9b2b | bellard | case 0x0: |
109 | e68b9b2b | bellard | value = pic->events; |
110 | e68b9b2b | bellard | break;
|
111 | e68b9b2b | bellard | case 0x4: |
112 | e68b9b2b | bellard | value = pic->mask; |
113 | e68b9b2b | bellard | break;
|
114 | e68b9b2b | bellard | case 0xc: |
115 | e68b9b2b | bellard | value = pic->levels; |
116 | e68b9b2b | bellard | break;
|
117 | e68b9b2b | bellard | default:
|
118 | e68b9b2b | bellard | value = 0;
|
119 | e68b9b2b | bellard | break;
|
120 | e68b9b2b | bellard | } |
121 | e68b9b2b | bellard | } |
122 | ea026b2f | blueswir1 | PIC_DPRINTF("readl: " TARGET_FMT_plx " %u: %08x\n", addr, n, value); |
123 | 3cbee15b | j_mayer | #ifdef TARGET_WORDS_BIGENDIAN
|
124 | e68b9b2b | bellard | value = bswap32(value); |
125 | 3cbee15b | j_mayer | #endif
|
126 | e68b9b2b | bellard | return value;
|
127 | e68b9b2b | bellard | } |
128 | e68b9b2b | bellard | |
129 | e68b9b2b | bellard | static CPUWriteMemoryFunc *pic_write[] = {
|
130 | e68b9b2b | bellard | &pic_writel, |
131 | e68b9b2b | bellard | &pic_writel, |
132 | e68b9b2b | bellard | &pic_writel, |
133 | e68b9b2b | bellard | }; |
134 | e68b9b2b | bellard | |
135 | e68b9b2b | bellard | static CPUReadMemoryFunc *pic_read[] = {
|
136 | e68b9b2b | bellard | &pic_readl, |
137 | e68b9b2b | bellard | &pic_readl, |
138 | e68b9b2b | bellard | &pic_readl, |
139 | e68b9b2b | bellard | }; |
140 | e68b9b2b | bellard | |
141 | e68b9b2b | bellard | |
142 | d537cf6c | pbrook | static void heathrow_pic_set_irq(void *opaque, int num, int level) |
143 | e68b9b2b | bellard | { |
144 | e68b9b2b | bellard | HeathrowPICS *s = opaque; |
145 | e68b9b2b | bellard | HeathrowPIC *pic; |
146 | e68b9b2b | bellard | unsigned int irq_bit; |
147 | e68b9b2b | bellard | |
148 | e68b9b2b | bellard | #if defined(DEBUG)
|
149 | e68b9b2b | bellard | { |
150 | e68b9b2b | bellard | static int last_level[64]; |
151 | e68b9b2b | bellard | if (last_level[num] != level) {
|
152 | ea026b2f | blueswir1 | PIC_DPRINTF("set_irq: num=0x%02x level=%d\n", num, level);
|
153 | e68b9b2b | bellard | last_level[num] = level; |
154 | e68b9b2b | bellard | } |
155 | e68b9b2b | bellard | } |
156 | e68b9b2b | bellard | #endif
|
157 | e68b9b2b | bellard | pic = &s->pics[1 - (num >> 5)]; |
158 | e68b9b2b | bellard | irq_bit = 1 << (num & 0x1f); |
159 | e68b9b2b | bellard | if (level) {
|
160 | e68b9b2b | bellard | pic->events |= irq_bit & ~pic->level_triggered; |
161 | e68b9b2b | bellard | pic->levels |= irq_bit; |
162 | e68b9b2b | bellard | } else {
|
163 | e68b9b2b | bellard | pic->levels &= ~irq_bit; |
164 | e68b9b2b | bellard | } |
165 | e68b9b2b | bellard | heathrow_pic_update(s); |
166 | e68b9b2b | bellard | } |
167 | e68b9b2b | bellard | |
168 | 9b64997f | blueswir1 | static void heathrow_pic_save_one(QEMUFile *f, HeathrowPIC *s) |
169 | 9b64997f | blueswir1 | { |
170 | 9b64997f | blueswir1 | qemu_put_be32s(f, &s->events); |
171 | 9b64997f | blueswir1 | qemu_put_be32s(f, &s->mask); |
172 | 9b64997f | blueswir1 | qemu_put_be32s(f, &s->levels); |
173 | 9b64997f | blueswir1 | qemu_put_be32s(f, &s->level_triggered); |
174 | 9b64997f | blueswir1 | } |
175 | 9b64997f | blueswir1 | |
176 | 9b64997f | blueswir1 | static void heathrow_pic_save(QEMUFile *f, void *opaque) |
177 | 9b64997f | blueswir1 | { |
178 | 9b64997f | blueswir1 | HeathrowPICS *s = (HeathrowPICS *)opaque; |
179 | 9b64997f | blueswir1 | |
180 | 9b64997f | blueswir1 | heathrow_pic_save_one(f, &s->pics[0]);
|
181 | 9b64997f | blueswir1 | heathrow_pic_save_one(f, &s->pics[1]);
|
182 | 9b64997f | blueswir1 | } |
183 | 9b64997f | blueswir1 | |
184 | 9b64997f | blueswir1 | static void heathrow_pic_load_one(QEMUFile *f, HeathrowPIC *s) |
185 | 9b64997f | blueswir1 | { |
186 | 9b64997f | blueswir1 | qemu_get_be32s(f, &s->events); |
187 | 9b64997f | blueswir1 | qemu_get_be32s(f, &s->mask); |
188 | 9b64997f | blueswir1 | qemu_get_be32s(f, &s->levels); |
189 | 9b64997f | blueswir1 | qemu_get_be32s(f, &s->level_triggered); |
190 | 9b64997f | blueswir1 | } |
191 | 9b64997f | blueswir1 | |
192 | 9b64997f | blueswir1 | static int heathrow_pic_load(QEMUFile *f, void *opaque, int version_id) |
193 | 9b64997f | blueswir1 | { |
194 | 9b64997f | blueswir1 | HeathrowPICS *s = (HeathrowPICS *)opaque; |
195 | 9b64997f | blueswir1 | |
196 | 9b64997f | blueswir1 | if (version_id != 1) |
197 | 9b64997f | blueswir1 | return -EINVAL;
|
198 | 9b64997f | blueswir1 | |
199 | 9b64997f | blueswir1 | heathrow_pic_load_one(f, &s->pics[0]);
|
200 | 9b64997f | blueswir1 | heathrow_pic_load_one(f, &s->pics[1]);
|
201 | 9b64997f | blueswir1 | |
202 | 9b64997f | blueswir1 | return 0; |
203 | 9b64997f | blueswir1 | } |
204 | 9b64997f | blueswir1 | |
205 | 6e6b7363 | blueswir1 | static void heathrow_pic_reset_one(HeathrowPIC *s) |
206 | 6e6b7363 | blueswir1 | { |
207 | 6e6b7363 | blueswir1 | memset(s, '\0', sizeof(HeathrowPIC)); |
208 | 6e6b7363 | blueswir1 | } |
209 | 6e6b7363 | blueswir1 | |
210 | 6e6b7363 | blueswir1 | static void heathrow_pic_reset(void *opaque) |
211 | 6e6b7363 | blueswir1 | { |
212 | 6e6b7363 | blueswir1 | HeathrowPICS *s = opaque; |
213 | 6e6b7363 | blueswir1 | |
214 | 6e6b7363 | blueswir1 | heathrow_pic_reset_one(&s->pics[0]);
|
215 | 6e6b7363 | blueswir1 | heathrow_pic_reset_one(&s->pics[1]);
|
216 | 6e6b7363 | blueswir1 | |
217 | 6e6b7363 | blueswir1 | s->pics[0].level_triggered = 0; |
218 | 6e6b7363 | blueswir1 | s->pics[1].level_triggered = 0x1ff00000; |
219 | 6e6b7363 | blueswir1 | } |
220 | 6e6b7363 | blueswir1 | |
221 | 3cbee15b | j_mayer | qemu_irq *heathrow_pic_init(int *pmem_index,
|
222 | 3cbee15b | j_mayer | int nb_cpus, qemu_irq **irqs)
|
223 | e68b9b2b | bellard | { |
224 | e68b9b2b | bellard | HeathrowPICS *s; |
225 | 3b46e624 | ths | |
226 | e68b9b2b | bellard | s = qemu_mallocz(sizeof(HeathrowPICS));
|
227 | 3cbee15b | j_mayer | /* only 1 CPU */
|
228 | 3cbee15b | j_mayer | s->irqs = irqs[0];
|
229 | e68b9b2b | bellard | *pmem_index = cpu_register_io_memory(0, pic_read, pic_write, s);
|
230 | 3cbee15b | j_mayer | |
231 | 9b64997f | blueswir1 | register_savevm("heathrow_pic", -1, 1, heathrow_pic_save, |
232 | 9b64997f | blueswir1 | heathrow_pic_load, s); |
233 | 6e6b7363 | blueswir1 | qemu_register_reset(heathrow_pic_reset, s); |
234 | 6e6b7363 | blueswir1 | heathrow_pic_reset(s); |
235 | d537cf6c | pbrook | return qemu_allocate_irqs(heathrow_pic_set_irq, s, 64); |
236 | e68b9b2b | bellard | } |