Statistics
| Branch: | Revision:

root / hw / slavio_intctl.c @ 368eb5d4

History | View | Annotate | Download (12.5 kB)

1 e80cfcfc bellard
/*
2 e80cfcfc bellard
 * QEMU Sparc SLAVIO interrupt controller emulation
3 5fafdf24 ths
 *
4 66321a11 bellard
 * Copyright (c) 2003-2005 Fabrice Bellard
5 5fafdf24 ths
 *
6 e80cfcfc bellard
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 e80cfcfc bellard
 * of this software and associated documentation files (the "Software"), to deal
8 e80cfcfc bellard
 * in the Software without restriction, including without limitation the rights
9 e80cfcfc bellard
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 e80cfcfc bellard
 * copies of the Software, and to permit persons to whom the Software is
11 e80cfcfc bellard
 * furnished to do so, subject to the following conditions:
12 e80cfcfc bellard
 *
13 e80cfcfc bellard
 * The above copyright notice and this permission notice shall be included in
14 e80cfcfc bellard
 * all copies or substantial portions of the Software.
15 e80cfcfc bellard
 *
16 e80cfcfc bellard
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 e80cfcfc bellard
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 e80cfcfc bellard
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 e80cfcfc bellard
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 e80cfcfc bellard
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 e80cfcfc bellard
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 e80cfcfc bellard
 * THE SOFTWARE.
23 e80cfcfc bellard
 */
24 a1961a4b Blue Swirl
25 87ecb68b pbrook
#include "sun4m.h"
26 376253ec aliguori
#include "monitor.h"
27 a1961a4b Blue Swirl
#include "sysbus.h"
28 87ecb68b pbrook
29 e80cfcfc bellard
//#define DEBUG_IRQ_COUNT
30 66321a11 bellard
//#define DEBUG_IRQ
31 66321a11 bellard
32 66321a11 bellard
#ifdef DEBUG_IRQ
33 001faf32 Blue Swirl
#define DPRINTF(fmt, ...)                                       \
34 001faf32 Blue Swirl
    do { printf("IRQ: " fmt , ## __VA_ARGS__); } while (0)
35 66321a11 bellard
#else
36 001faf32 Blue Swirl
#define DPRINTF(fmt, ...)
37 66321a11 bellard
#endif
38 e80cfcfc bellard
39 e80cfcfc bellard
/*
40 e80cfcfc bellard
 * Registers of interrupt controller in sun4m.
41 e80cfcfc bellard
 *
42 e80cfcfc bellard
 * This is the interrupt controller part of chip STP2001 (Slave I/O), also
43 e80cfcfc bellard
 * produced as NCR89C105. See
44 e80cfcfc bellard
 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
45 e80cfcfc bellard
 *
46 e80cfcfc bellard
 * There is a system master controller and one for each cpu.
47 5fafdf24 ths
 *
48 e80cfcfc bellard
 */
49 e80cfcfc bellard
50 e80cfcfc bellard
#define MAX_CPUS 16
51 b3a23197 blueswir1
#define MAX_PILS 16
52 e80cfcfc bellard
53 a1961a4b Blue Swirl
struct SLAVIO_INTCTLState;
54 a1961a4b Blue Swirl
55 a1961a4b Blue Swirl
typedef struct SLAVIO_CPUINTCTLState {
56 a1961a4b Blue Swirl
    uint32_t intreg_pending;
57 a1961a4b Blue Swirl
    struct SLAVIO_INTCTLState *master;
58 a1961a4b Blue Swirl
    uint32_t cpu;
59 a1961a4b Blue Swirl
} SLAVIO_CPUINTCTLState;
60 a8f48dcc blueswir1
61 e80cfcfc bellard
typedef struct SLAVIO_INTCTLState {
62 a1961a4b Blue Swirl
    SysBusDevice busdev;
63 e80cfcfc bellard
    uint32_t intregm_pending;
64 e80cfcfc bellard
    uint32_t intregm_disabled;
65 e80cfcfc bellard
    uint32_t target_cpu;
66 e80cfcfc bellard
#ifdef DEBUG_IRQ_COUNT
67 e80cfcfc bellard
    uint64_t irq_count[32];
68 e80cfcfc bellard
#endif
69 a1961a4b Blue Swirl
    qemu_irq cpu_irqs[MAX_CPUS][MAX_PILS];
70 e3a79bca blueswir1
    uint32_t cputimer_lbit, cputimer_mbit;
71 ee6847d1 Gerd Hoffmann
    uint32_t cputimer_bit;
72 b3a23197 blueswir1
    uint32_t pil_out[MAX_CPUS];
73 a1961a4b Blue Swirl
    SLAVIO_CPUINTCTLState slaves[MAX_CPUS];
74 e80cfcfc bellard
} SLAVIO_INTCTLState;
75 e80cfcfc bellard
76 e80cfcfc bellard
#define INTCTL_MAXADDR 0xf
77 5aca8c3b blueswir1
#define INTCTL_SIZE (INTCTL_MAXADDR + 1)
78 a8f48dcc blueswir1
#define INTCTLM_SIZE 0x14
79 80be36b8 blueswir1
#define MASTER_IRQ_MASK ~0x0fa2007f
80 9a87ce9b blueswir1
#define MASTER_DISABLE 0x80000000
81 6341fdcb blueswir1
#define CPU_SOFTIRQ_MASK 0xfffe0000
82 9a87ce9b blueswir1
#define CPU_IRQ_INT15_IN 0x0004000
83 9a87ce9b blueswir1
#define CPU_IRQ_INT15_MASK 0x80000000
84 9a87ce9b blueswir1
85 0d0a7e69 Blue Swirl
static void slavio_check_interrupts(SLAVIO_INTCTLState *s, int set_irqs);
86 e80cfcfc bellard
87 e80cfcfc bellard
// per-cpu interrupt controller
88 e80cfcfc bellard
static uint32_t slavio_intctl_mem_readl(void *opaque, target_phys_addr_t addr)
89 e80cfcfc bellard
{
90 a8f48dcc blueswir1
    SLAVIO_CPUINTCTLState *s = opaque;
91 dd4131b3 blueswir1
    uint32_t saddr, ret;
92 e80cfcfc bellard
93 a8f48dcc blueswir1
    saddr = addr >> 2;
94 e80cfcfc bellard
    switch (saddr) {
95 e80cfcfc bellard
    case 0:
96 a8f48dcc blueswir1
        ret = s->intreg_pending;
97 dd4131b3 blueswir1
        break;
98 e80cfcfc bellard
    default:
99 dd4131b3 blueswir1
        ret = 0;
100 dd4131b3 blueswir1
        break;
101 e80cfcfc bellard
    }
102 3c4cf535 blueswir1
    DPRINTF("read cpu %d reg 0x" TARGET_FMT_plx " = %x\n", s->cpu, addr, ret);
103 dd4131b3 blueswir1
104 dd4131b3 blueswir1
    return ret;
105 e80cfcfc bellard
}
106 e80cfcfc bellard
107 77f193da blueswir1
static void slavio_intctl_mem_writel(void *opaque, target_phys_addr_t addr,
108 77f193da blueswir1
                                     uint32_t val)
109 e80cfcfc bellard
{
110 a8f48dcc blueswir1
    SLAVIO_CPUINTCTLState *s = opaque;
111 e80cfcfc bellard
    uint32_t saddr;
112 e80cfcfc bellard
113 a8f48dcc blueswir1
    saddr = addr >> 2;
114 3c4cf535 blueswir1
    DPRINTF("write cpu %d reg 0x" TARGET_FMT_plx " = %x\n", s->cpu, addr, val);
115 e80cfcfc bellard
    switch (saddr) {
116 e80cfcfc bellard
    case 1: // clear pending softints
117 9a87ce9b blueswir1
        if (val & CPU_IRQ_INT15_IN)
118 9a87ce9b blueswir1
            val |= CPU_IRQ_INT15_MASK;
119 6341fdcb blueswir1
        val &= CPU_SOFTIRQ_MASK;
120 a8f48dcc blueswir1
        s->intreg_pending &= ~val;
121 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s->master, 1);
122 a8f48dcc blueswir1
        DPRINTF("Cleared cpu %d irq mask %x, curmask %x\n", s->cpu, val,
123 a8f48dcc blueswir1
                s->intreg_pending);
124 f930d07e blueswir1
        break;
125 e80cfcfc bellard
    case 2: // set softint
126 6341fdcb blueswir1
        val &= CPU_SOFTIRQ_MASK;
127 a8f48dcc blueswir1
        s->intreg_pending |= val;
128 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s->master, 1);
129 a8f48dcc blueswir1
        DPRINTF("Set cpu %d irq mask %x, curmask %x\n", s->cpu, val,
130 a8f48dcc blueswir1
                s->intreg_pending);
131 f930d07e blueswir1
        break;
132 e80cfcfc bellard
    default:
133 f930d07e blueswir1
        break;
134 e80cfcfc bellard
    }
135 e80cfcfc bellard
}
136 e80cfcfc bellard
137 e80cfcfc bellard
static CPUReadMemoryFunc *slavio_intctl_mem_read[3] = {
138 7c560456 blueswir1
    NULL,
139 7c560456 blueswir1
    NULL,
140 e80cfcfc bellard
    slavio_intctl_mem_readl,
141 e80cfcfc bellard
};
142 e80cfcfc bellard
143 e80cfcfc bellard
static CPUWriteMemoryFunc *slavio_intctl_mem_write[3] = {
144 7c560456 blueswir1
    NULL,
145 7c560456 blueswir1
    NULL,
146 e80cfcfc bellard
    slavio_intctl_mem_writel,
147 e80cfcfc bellard
};
148 e80cfcfc bellard
149 e80cfcfc bellard
// master system interrupt controller
150 e80cfcfc bellard
static uint32_t slavio_intctlm_mem_readl(void *opaque, target_phys_addr_t addr)
151 e80cfcfc bellard
{
152 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
153 dd4131b3 blueswir1
    uint32_t saddr, ret;
154 e80cfcfc bellard
155 a8f48dcc blueswir1
    saddr = addr >> 2;
156 e80cfcfc bellard
    switch (saddr) {
157 e80cfcfc bellard
    case 0:
158 9a87ce9b blueswir1
        ret = s->intregm_pending & ~MASTER_DISABLE;
159 dd4131b3 blueswir1
        break;
160 e80cfcfc bellard
    case 1:
161 80be36b8 blueswir1
        ret = s->intregm_disabled & MASTER_IRQ_MASK;
162 dd4131b3 blueswir1
        break;
163 e80cfcfc bellard
    case 4:
164 dd4131b3 blueswir1
        ret = s->target_cpu;
165 dd4131b3 blueswir1
        break;
166 e80cfcfc bellard
    default:
167 dd4131b3 blueswir1
        ret = 0;
168 dd4131b3 blueswir1
        break;
169 e80cfcfc bellard
    }
170 1569fc29 blueswir1
    DPRINTF("read system reg 0x" TARGET_FMT_plx " = %x\n", addr, ret);
171 dd4131b3 blueswir1
172 dd4131b3 blueswir1
    return ret;
173 e80cfcfc bellard
}
174 e80cfcfc bellard
175 77f193da blueswir1
static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr,
176 77f193da blueswir1
                                      uint32_t val)
177 e80cfcfc bellard
{
178 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
179 e80cfcfc bellard
    uint32_t saddr;
180 e80cfcfc bellard
181 a8f48dcc blueswir1
    saddr = addr >> 2;
182 1569fc29 blueswir1
    DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
183 e80cfcfc bellard
    switch (saddr) {
184 e80cfcfc bellard
    case 2: // clear (enable)
185 f930d07e blueswir1
        // Force clear unused bits
186 9a87ce9b blueswir1
        val &= MASTER_IRQ_MASK;
187 f930d07e blueswir1
        s->intregm_disabled &= ~val;
188 77f193da blueswir1
        DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
189 77f193da blueswir1
                s->intregm_disabled);
190 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
191 f930d07e blueswir1
        break;
192 e80cfcfc bellard
    case 3: // set (disable, clear pending)
193 f930d07e blueswir1
        // Force clear unused bits
194 9a87ce9b blueswir1
        val &= MASTER_IRQ_MASK;
195 f930d07e blueswir1
        s->intregm_disabled |= val;
196 f930d07e blueswir1
        s->intregm_pending &= ~val;
197 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
198 77f193da blueswir1
        DPRINTF("Disabled master irq mask %x, curmask %x\n", val,
199 77f193da blueswir1
                s->intregm_disabled);
200 f930d07e blueswir1
        break;
201 e80cfcfc bellard
    case 4:
202 f930d07e blueswir1
        s->target_cpu = val & (MAX_CPUS - 1);
203 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
204 f930d07e blueswir1
        DPRINTF("Set master irq cpu %d\n", s->target_cpu);
205 f930d07e blueswir1
        break;
206 e80cfcfc bellard
    default:
207 f930d07e blueswir1
        break;
208 e80cfcfc bellard
    }
209 e80cfcfc bellard
}
210 e80cfcfc bellard
211 e80cfcfc bellard
static CPUReadMemoryFunc *slavio_intctlm_mem_read[3] = {
212 7c560456 blueswir1
    NULL,
213 7c560456 blueswir1
    NULL,
214 e80cfcfc bellard
    slavio_intctlm_mem_readl,
215 e80cfcfc bellard
};
216 e80cfcfc bellard
217 e80cfcfc bellard
static CPUWriteMemoryFunc *slavio_intctlm_mem_write[3] = {
218 7c560456 blueswir1
    NULL,
219 7c560456 blueswir1
    NULL,
220 e80cfcfc bellard
    slavio_intctlm_mem_writel,
221 e80cfcfc bellard
};
222 e80cfcfc bellard
223 376253ec aliguori
void slavio_pic_info(Monitor *mon, void *opaque)
224 e80cfcfc bellard
{
225 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
226 e80cfcfc bellard
    int i;
227 e80cfcfc bellard
228 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
229 376253ec aliguori
        monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
230 a1961a4b Blue Swirl
                       s->slaves[i].intreg_pending);
231 e80cfcfc bellard
    }
232 376253ec aliguori
    monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
233 376253ec aliguori
                   s->intregm_pending, s->intregm_disabled);
234 e80cfcfc bellard
}
235 e80cfcfc bellard
236 376253ec aliguori
void slavio_irq_info(Monitor *mon, void *opaque)
237 e80cfcfc bellard
{
238 e80cfcfc bellard
#ifndef DEBUG_IRQ_COUNT
239 376253ec aliguori
    monitor_printf(mon, "irq statistic code not compiled.\n");
240 e80cfcfc bellard
#else
241 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
242 e80cfcfc bellard
    int i;
243 e80cfcfc bellard
    int64_t count;
244 e80cfcfc bellard
245 376253ec aliguori
    monitor_printf(mon, "IRQ statistics:\n");
246 e80cfcfc bellard
    for (i = 0; i < 32; i++) {
247 e80cfcfc bellard
        count = s->irq_count[i];
248 e80cfcfc bellard
        if (count > 0)
249 376253ec aliguori
            monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
250 e80cfcfc bellard
    }
251 e80cfcfc bellard
#endif
252 e80cfcfc bellard
}
253 e80cfcfc bellard
254 68556e2e Blue Swirl
static const uint32_t intbit_to_level[] = {
255 68556e2e Blue Swirl
    2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
256 68556e2e Blue Swirl
    6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
257 68556e2e Blue Swirl
};
258 68556e2e Blue Swirl
259 0d0a7e69 Blue Swirl
static void slavio_check_interrupts(SLAVIO_INTCTLState *s, int set_irqs)
260 66321a11 bellard
{
261 327ac2e7 blueswir1
    uint32_t pending = s->intregm_pending, pil_pending;
262 327ac2e7 blueswir1
    unsigned int i, j;
263 66321a11 bellard
264 66321a11 bellard
    pending &= ~s->intregm_disabled;
265 66321a11 bellard
266 b3a23197 blueswir1
    DPRINTF("pending %x disabled %x\n", pending, s->intregm_disabled);
267 ba3c64fb bellard
    for (i = 0; i < MAX_CPUS; i++) {
268 327ac2e7 blueswir1
        pil_pending = 0;
269 9a87ce9b blueswir1
        if (pending && !(s->intregm_disabled & MASTER_DISABLE) &&
270 b3a23197 blueswir1
            (i == s->target_cpu)) {
271 b3a23197 blueswir1
            for (j = 0; j < 32; j++) {
272 327ac2e7 blueswir1
                if (pending & (1 << j))
273 68556e2e Blue Swirl
                    pil_pending |= 1 << intbit_to_level[j];
274 b3a23197 blueswir1
            }
275 b3a23197 blueswir1
        }
276 a1961a4b Blue Swirl
        pil_pending |= (s->slaves[i].intreg_pending & CPU_SOFTIRQ_MASK) >> 16;
277 327ac2e7 blueswir1
278 0d0a7e69 Blue Swirl
        if (set_irqs) {
279 0d0a7e69 Blue Swirl
            for (j = 0; j < MAX_PILS; j++) {
280 0d0a7e69 Blue Swirl
                if (pil_pending & (1 << j)) {
281 0d0a7e69 Blue Swirl
                    if (!(s->pil_out[i] & (1 << j))) {
282 0d0a7e69 Blue Swirl
                        qemu_irq_raise(s->cpu_irqs[i][j]);
283 0d0a7e69 Blue Swirl
                    }
284 0d0a7e69 Blue Swirl
                } else {
285 0d0a7e69 Blue Swirl
                    if (s->pil_out[i] & (1 << j)) {
286 0d0a7e69 Blue Swirl
                        qemu_irq_lower(s->cpu_irqs[i][j]);
287 0d0a7e69 Blue Swirl
                    }
288 0d0a7e69 Blue Swirl
                }
289 ba3c64fb bellard
            }
290 ba3c64fb bellard
        }
291 327ac2e7 blueswir1
        s->pil_out[i] = pil_pending;
292 ba3c64fb bellard
    }
293 66321a11 bellard
}
294 66321a11 bellard
295 e80cfcfc bellard
/*
296 e80cfcfc bellard
 * "irq" here is the bit number in the system interrupt register to
297 e80cfcfc bellard
 * separate serial and keyboard interrupts sharing a level.
298 e80cfcfc bellard
 */
299 d7edfd27 blueswir1
static void slavio_set_irq(void *opaque, int irq, int level)
300 e80cfcfc bellard
{
301 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
302 b3a23197 blueswir1
    uint32_t mask = 1 << irq;
303 68556e2e Blue Swirl
    uint32_t pil = intbit_to_level[irq];
304 b3a23197 blueswir1
305 b3a23197 blueswir1
    DPRINTF("Set cpu %d irq %d -> pil %d level %d\n", s->target_cpu, irq, pil,
306 b3a23197 blueswir1
            level);
307 b3a23197 blueswir1
    if (pil > 0) {
308 b3a23197 blueswir1
        if (level) {
309 327ac2e7 blueswir1
#ifdef DEBUG_IRQ_COUNT
310 327ac2e7 blueswir1
            s->irq_count[pil]++;
311 327ac2e7 blueswir1
#endif
312 b3a23197 blueswir1
            s->intregm_pending |= mask;
313 a1961a4b Blue Swirl
            s->slaves[s->target_cpu].intreg_pending |= 1 << pil;
314 b3a23197 blueswir1
        } else {
315 b3a23197 blueswir1
            s->intregm_pending &= ~mask;
316 a1961a4b Blue Swirl
            s->slaves[s->target_cpu].intreg_pending &= ~(1 << pil);
317 b3a23197 blueswir1
        }
318 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
319 e80cfcfc bellard
    }
320 e80cfcfc bellard
}
321 e80cfcfc bellard
322 d7edfd27 blueswir1
static void slavio_set_timer_irq_cpu(void *opaque, int cpu, int level)
323 ba3c64fb bellard
{
324 ba3c64fb bellard
    SLAVIO_INTCTLState *s = opaque;
325 ba3c64fb bellard
326 b3a23197 blueswir1
    DPRINTF("Set cpu %d local timer level %d\n", cpu, level);
327 d7edfd27 blueswir1
328 e3a79bca blueswir1
    if (level) {
329 e3a79bca blueswir1
        s->intregm_pending |= s->cputimer_mbit;
330 a1961a4b Blue Swirl
        s->slaves[cpu].intreg_pending |= s->cputimer_lbit;
331 e3a79bca blueswir1
    } else {
332 e3a79bca blueswir1
        s->intregm_pending &= ~s->cputimer_mbit;
333 a1961a4b Blue Swirl
        s->slaves[cpu].intreg_pending &= ~s->cputimer_lbit;
334 e3a79bca blueswir1
    }
335 d7edfd27 blueswir1
336 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 1);
337 ba3c64fb bellard
}
338 ba3c64fb bellard
339 a1961a4b Blue Swirl
static void slavio_set_irq_all(void *opaque, int irq, int level)
340 a1961a4b Blue Swirl
{
341 a1961a4b Blue Swirl
    if (irq < 32) {
342 a1961a4b Blue Swirl
        slavio_set_irq(opaque, irq, level);
343 a1961a4b Blue Swirl
    } else {
344 a1961a4b Blue Swirl
        slavio_set_timer_irq_cpu(opaque, irq - 32, level);
345 a1961a4b Blue Swirl
    }
346 a1961a4b Blue Swirl
}
347 a1961a4b Blue Swirl
348 e80cfcfc bellard
static void slavio_intctl_save(QEMUFile *f, void *opaque)
349 e80cfcfc bellard
{
350 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
351 e80cfcfc bellard
    int i;
352 3b46e624 ths
353 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
354 a1961a4b Blue Swirl
        qemu_put_be32s(f, &s->slaves[i].intreg_pending);
355 e80cfcfc bellard
    }
356 e80cfcfc bellard
    qemu_put_be32s(f, &s->intregm_pending);
357 e80cfcfc bellard
    qemu_put_be32s(f, &s->intregm_disabled);
358 e80cfcfc bellard
    qemu_put_be32s(f, &s->target_cpu);
359 e80cfcfc bellard
}
360 e80cfcfc bellard
361 e80cfcfc bellard
static int slavio_intctl_load(QEMUFile *f, void *opaque, int version_id)
362 e80cfcfc bellard
{
363 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
364 e80cfcfc bellard
    int i;
365 e80cfcfc bellard
366 e80cfcfc bellard
    if (version_id != 1)
367 e80cfcfc bellard
        return -EINVAL;
368 e80cfcfc bellard
369 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
370 a1961a4b Blue Swirl
        qemu_get_be32s(f, &s->slaves[i].intreg_pending);
371 e80cfcfc bellard
    }
372 e80cfcfc bellard
    qemu_get_be32s(f, &s->intregm_pending);
373 e80cfcfc bellard
    qemu_get_be32s(f, &s->intregm_disabled);
374 e80cfcfc bellard
    qemu_get_be32s(f, &s->target_cpu);
375 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 0);
376 e80cfcfc bellard
    return 0;
377 e80cfcfc bellard
}
378 e80cfcfc bellard
379 e80cfcfc bellard
static void slavio_intctl_reset(void *opaque)
380 e80cfcfc bellard
{
381 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
382 e80cfcfc bellard
    int i;
383 e80cfcfc bellard
384 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
385 a1961a4b Blue Swirl
        s->slaves[i].intreg_pending = 0;
386 e80cfcfc bellard
    }
387 9a87ce9b blueswir1
    s->intregm_disabled = ~MASTER_IRQ_MASK;
388 e80cfcfc bellard
    s->intregm_pending = 0;
389 e80cfcfc bellard
    s->target_cpu = 0;
390 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 0);
391 e80cfcfc bellard
}
392 e80cfcfc bellard
393 a1961a4b Blue Swirl
static void slavio_intctl_init1(SysBusDevice *dev)
394 e80cfcfc bellard
{
395 a1961a4b Blue Swirl
    SLAVIO_INTCTLState *s = FROM_SYSBUS(SLAVIO_INTCTLState, dev);
396 ee6847d1 Gerd Hoffmann
    int io_memory;
397 a1961a4b Blue Swirl
    unsigned int i, j;
398 e80cfcfc bellard
399 a1961a4b Blue Swirl
    qdev_init_gpio_in(&dev->qdev, slavio_set_irq_all, 32 + MAX_CPUS);
400 a1961a4b Blue Swirl
    io_memory = cpu_register_io_memory(slavio_intctlm_mem_read,
401 a1961a4b Blue Swirl
                                       slavio_intctlm_mem_write, s);
402 a1961a4b Blue Swirl
    sysbus_init_mmio(dev, INTCTLM_SIZE, io_memory);
403 ee6847d1 Gerd Hoffmann
    s->cputimer_mbit = 1 << s->cputimer_bit;
404 68556e2e Blue Swirl
    s->cputimer_lbit = 1 << intbit_to_level[s->cputimer_bit];
405 e80cfcfc bellard
406 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
407 a1961a4b Blue Swirl
        for (j = 0; j < MAX_PILS; j++) {
408 a1961a4b Blue Swirl
            sysbus_init_irq(dev, &s->cpu_irqs[i][j]);
409 a1961a4b Blue Swirl
        }
410 a1961a4b Blue Swirl
        io_memory = cpu_register_io_memory(slavio_intctl_mem_read,
411 a1961a4b Blue Swirl
                                           slavio_intctl_mem_write,
412 a1961a4b Blue Swirl
                                           &s->slaves[i]);
413 a1961a4b Blue Swirl
        sysbus_init_mmio(dev, INTCTL_SIZE, io_memory);
414 a1961a4b Blue Swirl
        s->slaves[i].cpu = i;
415 a1961a4b Blue Swirl
        s->slaves[i].master = s;
416 a1961a4b Blue Swirl
    }
417 a1961a4b Blue Swirl
    register_savevm("slavio_intctl", -1, 1, slavio_intctl_save,
418 a1961a4b Blue Swirl
                    slavio_intctl_load, s);
419 a1961a4b Blue Swirl
    qemu_register_reset(slavio_intctl_reset, s);
420 a1961a4b Blue Swirl
    slavio_intctl_reset(s);
421 a1961a4b Blue Swirl
}
422 a1961a4b Blue Swirl
423 a1961a4b Blue Swirl
static SysBusDeviceInfo slavio_intctl_info = {
424 a1961a4b Blue Swirl
    .init = slavio_intctl_init1,
425 a1961a4b Blue Swirl
    .qdev.name  = "slavio_intctl",
426 a1961a4b Blue Swirl
    .qdev.size  = sizeof(SLAVIO_INTCTLState),
427 ee6847d1 Gerd Hoffmann
    .qdev.props = (Property[]) {
428 ee6847d1 Gerd Hoffmann
        {
429 ee6847d1 Gerd Hoffmann
            .name = "cputimer_bit",
430 ee6847d1 Gerd Hoffmann
            .info = &qdev_prop_uint32,
431 ee6847d1 Gerd Hoffmann
            .offset = offsetof(SLAVIO_INTCTLState, cputimer_bit),
432 ee6847d1 Gerd Hoffmann
        },
433 ee6847d1 Gerd Hoffmann
        {/* end of property list */}
434 a1961a4b Blue Swirl
    }
435 a1961a4b Blue Swirl
};
436 d7edfd27 blueswir1
437 a1961a4b Blue Swirl
static void slavio_intctl_register_devices(void)
438 a1961a4b Blue Swirl
{
439 a1961a4b Blue Swirl
    sysbus_register_withprop(&slavio_intctl_info);
440 e80cfcfc bellard
}
441 a1961a4b Blue Swirl
442 a1961a4b Blue Swirl
device_init(slavio_intctl_register_devices)