Statistics
| Branch: | Revision:

root / hw / slavio_intctl.c @ 4a1418e0

History | View | Annotate | Download (12.6 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 d453c2c3 Blue Swirl
void slavio_pic_info(Monitor *mon, DeviceState *dev)
224 e80cfcfc bellard
{
225 d453c2c3 Blue Swirl
    SysBusDevice *sd;
226 d453c2c3 Blue Swirl
    SLAVIO_INTCTLState *s;
227 e80cfcfc bellard
    int i;
228 e80cfcfc bellard
229 d453c2c3 Blue Swirl
    sd = sysbus_from_qdev(dev);
230 d453c2c3 Blue Swirl
    s = FROM_SYSBUS(SLAVIO_INTCTLState, sd);
231 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
232 376253ec aliguori
        monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
233 a1961a4b Blue Swirl
                       s->slaves[i].intreg_pending);
234 e80cfcfc bellard
    }
235 376253ec aliguori
    monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
236 376253ec aliguori
                   s->intregm_pending, s->intregm_disabled);
237 e80cfcfc bellard
}
238 e80cfcfc bellard
239 d453c2c3 Blue Swirl
void slavio_irq_info(Monitor *mon, DeviceState *dev)
240 e80cfcfc bellard
{
241 e80cfcfc bellard
#ifndef DEBUG_IRQ_COUNT
242 376253ec aliguori
    monitor_printf(mon, "irq statistic code not compiled.\n");
243 e80cfcfc bellard
#else
244 d453c2c3 Blue Swirl
    SysBusDevice *sd;
245 d453c2c3 Blue Swirl
    SLAVIO_INTCTLState *s;
246 e80cfcfc bellard
    int i;
247 e80cfcfc bellard
    int64_t count;
248 e80cfcfc bellard
249 d453c2c3 Blue Swirl
    sd = sysbus_from_qdev(dev);
250 d453c2c3 Blue Swirl
    s = FROM_SYSBUS(SLAVIO_INTCTLState, sd);
251 376253ec aliguori
    monitor_printf(mon, "IRQ statistics:\n");
252 e80cfcfc bellard
    for (i = 0; i < 32; i++) {
253 e80cfcfc bellard
        count = s->irq_count[i];
254 e80cfcfc bellard
        if (count > 0)
255 376253ec aliguori
            monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
256 e80cfcfc bellard
    }
257 e80cfcfc bellard
#endif
258 e80cfcfc bellard
}
259 e80cfcfc bellard
260 68556e2e Blue Swirl
static const uint32_t intbit_to_level[] = {
261 68556e2e Blue Swirl
    2, 3, 5, 7, 9, 11, 0, 14,   3, 5, 7, 9, 11, 13, 12, 12,
262 68556e2e Blue Swirl
    6, 0, 4, 10, 8, 0, 11, 0,   0, 0, 0, 0, 15, 0, 15, 0,
263 68556e2e Blue Swirl
};
264 68556e2e Blue Swirl
265 0d0a7e69 Blue Swirl
static void slavio_check_interrupts(SLAVIO_INTCTLState *s, int set_irqs)
266 66321a11 bellard
{
267 327ac2e7 blueswir1
    uint32_t pending = s->intregm_pending, pil_pending;
268 327ac2e7 blueswir1
    unsigned int i, j;
269 66321a11 bellard
270 66321a11 bellard
    pending &= ~s->intregm_disabled;
271 66321a11 bellard
272 b3a23197 blueswir1
    DPRINTF("pending %x disabled %x\n", pending, s->intregm_disabled);
273 ba3c64fb bellard
    for (i = 0; i < MAX_CPUS; i++) {
274 327ac2e7 blueswir1
        pil_pending = 0;
275 9a87ce9b blueswir1
        if (pending && !(s->intregm_disabled & MASTER_DISABLE) &&
276 b3a23197 blueswir1
            (i == s->target_cpu)) {
277 b3a23197 blueswir1
            for (j = 0; j < 32; j++) {
278 327ac2e7 blueswir1
                if (pending & (1 << j))
279 68556e2e Blue Swirl
                    pil_pending |= 1 << intbit_to_level[j];
280 b3a23197 blueswir1
            }
281 b3a23197 blueswir1
        }
282 a1961a4b Blue Swirl
        pil_pending |= (s->slaves[i].intreg_pending & CPU_SOFTIRQ_MASK) >> 16;
283 327ac2e7 blueswir1
284 0d0a7e69 Blue Swirl
        if (set_irqs) {
285 0d0a7e69 Blue Swirl
            for (j = 0; j < MAX_PILS; j++) {
286 0d0a7e69 Blue Swirl
                if (pil_pending & (1 << j)) {
287 0d0a7e69 Blue Swirl
                    if (!(s->pil_out[i] & (1 << j))) {
288 0d0a7e69 Blue Swirl
                        qemu_irq_raise(s->cpu_irqs[i][j]);
289 0d0a7e69 Blue Swirl
                    }
290 0d0a7e69 Blue Swirl
                } else {
291 0d0a7e69 Blue Swirl
                    if (s->pil_out[i] & (1 << j)) {
292 0d0a7e69 Blue Swirl
                        qemu_irq_lower(s->cpu_irqs[i][j]);
293 0d0a7e69 Blue Swirl
                    }
294 0d0a7e69 Blue Swirl
                }
295 ba3c64fb bellard
            }
296 ba3c64fb bellard
        }
297 327ac2e7 blueswir1
        s->pil_out[i] = pil_pending;
298 ba3c64fb bellard
    }
299 66321a11 bellard
}
300 66321a11 bellard
301 e80cfcfc bellard
/*
302 e80cfcfc bellard
 * "irq" here is the bit number in the system interrupt register to
303 e80cfcfc bellard
 * separate serial and keyboard interrupts sharing a level.
304 e80cfcfc bellard
 */
305 d7edfd27 blueswir1
static void slavio_set_irq(void *opaque, int irq, int level)
306 e80cfcfc bellard
{
307 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
308 b3a23197 blueswir1
    uint32_t mask = 1 << irq;
309 68556e2e Blue Swirl
    uint32_t pil = intbit_to_level[irq];
310 b3a23197 blueswir1
311 b3a23197 blueswir1
    DPRINTF("Set cpu %d irq %d -> pil %d level %d\n", s->target_cpu, irq, pil,
312 b3a23197 blueswir1
            level);
313 b3a23197 blueswir1
    if (pil > 0) {
314 b3a23197 blueswir1
        if (level) {
315 327ac2e7 blueswir1
#ifdef DEBUG_IRQ_COUNT
316 327ac2e7 blueswir1
            s->irq_count[pil]++;
317 327ac2e7 blueswir1
#endif
318 b3a23197 blueswir1
            s->intregm_pending |= mask;
319 a1961a4b Blue Swirl
            s->slaves[s->target_cpu].intreg_pending |= 1 << pil;
320 b3a23197 blueswir1
        } else {
321 b3a23197 blueswir1
            s->intregm_pending &= ~mask;
322 a1961a4b Blue Swirl
            s->slaves[s->target_cpu].intreg_pending &= ~(1 << pil);
323 b3a23197 blueswir1
        }
324 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
325 e80cfcfc bellard
    }
326 e80cfcfc bellard
}
327 e80cfcfc bellard
328 d7edfd27 blueswir1
static void slavio_set_timer_irq_cpu(void *opaque, int cpu, int level)
329 ba3c64fb bellard
{
330 ba3c64fb bellard
    SLAVIO_INTCTLState *s = opaque;
331 ba3c64fb bellard
332 b3a23197 blueswir1
    DPRINTF("Set cpu %d local timer level %d\n", cpu, level);
333 d7edfd27 blueswir1
334 e3a79bca blueswir1
    if (level) {
335 e3a79bca blueswir1
        s->intregm_pending |= s->cputimer_mbit;
336 a1961a4b Blue Swirl
        s->slaves[cpu].intreg_pending |= s->cputimer_lbit;
337 e3a79bca blueswir1
    } else {
338 e3a79bca blueswir1
        s->intregm_pending &= ~s->cputimer_mbit;
339 a1961a4b Blue Swirl
        s->slaves[cpu].intreg_pending &= ~s->cputimer_lbit;
340 e3a79bca blueswir1
    }
341 d7edfd27 blueswir1
342 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 1);
343 ba3c64fb bellard
}
344 ba3c64fb bellard
345 a1961a4b Blue Swirl
static void slavio_set_irq_all(void *opaque, int irq, int level)
346 a1961a4b Blue Swirl
{
347 a1961a4b Blue Swirl
    if (irq < 32) {
348 a1961a4b Blue Swirl
        slavio_set_irq(opaque, irq, level);
349 a1961a4b Blue Swirl
    } else {
350 a1961a4b Blue Swirl
        slavio_set_timer_irq_cpu(opaque, irq - 32, level);
351 a1961a4b Blue Swirl
    }
352 a1961a4b Blue Swirl
}
353 a1961a4b Blue Swirl
354 e80cfcfc bellard
static void slavio_intctl_save(QEMUFile *f, void *opaque)
355 e80cfcfc bellard
{
356 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
357 e80cfcfc bellard
    int i;
358 3b46e624 ths
359 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
360 a1961a4b Blue Swirl
        qemu_put_be32s(f, &s->slaves[i].intreg_pending);
361 e80cfcfc bellard
    }
362 e80cfcfc bellard
    qemu_put_be32s(f, &s->intregm_pending);
363 e80cfcfc bellard
    qemu_put_be32s(f, &s->intregm_disabled);
364 e80cfcfc bellard
    qemu_put_be32s(f, &s->target_cpu);
365 e80cfcfc bellard
}
366 e80cfcfc bellard
367 e80cfcfc bellard
static int slavio_intctl_load(QEMUFile *f, void *opaque, int version_id)
368 e80cfcfc bellard
{
369 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
370 e80cfcfc bellard
    int i;
371 e80cfcfc bellard
372 e80cfcfc bellard
    if (version_id != 1)
373 e80cfcfc bellard
        return -EINVAL;
374 e80cfcfc bellard
375 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
376 a1961a4b Blue Swirl
        qemu_get_be32s(f, &s->slaves[i].intreg_pending);
377 e80cfcfc bellard
    }
378 e80cfcfc bellard
    qemu_get_be32s(f, &s->intregm_pending);
379 e80cfcfc bellard
    qemu_get_be32s(f, &s->intregm_disabled);
380 e80cfcfc bellard
    qemu_get_be32s(f, &s->target_cpu);
381 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 0);
382 e80cfcfc bellard
    return 0;
383 e80cfcfc bellard
}
384 e80cfcfc bellard
385 e80cfcfc bellard
static void slavio_intctl_reset(void *opaque)
386 e80cfcfc bellard
{
387 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
388 e80cfcfc bellard
    int i;
389 e80cfcfc bellard
390 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
391 a1961a4b Blue Swirl
        s->slaves[i].intreg_pending = 0;
392 e80cfcfc bellard
    }
393 9a87ce9b blueswir1
    s->intregm_disabled = ~MASTER_IRQ_MASK;
394 e80cfcfc bellard
    s->intregm_pending = 0;
395 e80cfcfc bellard
    s->target_cpu = 0;
396 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 0);
397 e80cfcfc bellard
}
398 e80cfcfc bellard
399 a1961a4b Blue Swirl
static void slavio_intctl_init1(SysBusDevice *dev)
400 e80cfcfc bellard
{
401 a1961a4b Blue Swirl
    SLAVIO_INTCTLState *s = FROM_SYSBUS(SLAVIO_INTCTLState, dev);
402 ee6847d1 Gerd Hoffmann
    int io_memory;
403 a1961a4b Blue Swirl
    unsigned int i, j;
404 e80cfcfc bellard
405 a1961a4b Blue Swirl
    qdev_init_gpio_in(&dev->qdev, slavio_set_irq_all, 32 + MAX_CPUS);
406 a1961a4b Blue Swirl
    io_memory = cpu_register_io_memory(slavio_intctlm_mem_read,
407 a1961a4b Blue Swirl
                                       slavio_intctlm_mem_write, s);
408 a1961a4b Blue Swirl
    sysbus_init_mmio(dev, INTCTLM_SIZE, io_memory);
409 ee6847d1 Gerd Hoffmann
    s->cputimer_mbit = 1 << s->cputimer_bit;
410 68556e2e Blue Swirl
    s->cputimer_lbit = 1 << intbit_to_level[s->cputimer_bit];
411 e80cfcfc bellard
412 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
413 a1961a4b Blue Swirl
        for (j = 0; j < MAX_PILS; j++) {
414 a1961a4b Blue Swirl
            sysbus_init_irq(dev, &s->cpu_irqs[i][j]);
415 a1961a4b Blue Swirl
        }
416 a1961a4b Blue Swirl
        io_memory = cpu_register_io_memory(slavio_intctl_mem_read,
417 a1961a4b Blue Swirl
                                           slavio_intctl_mem_write,
418 a1961a4b Blue Swirl
                                           &s->slaves[i]);
419 a1961a4b Blue Swirl
        sysbus_init_mmio(dev, INTCTL_SIZE, io_memory);
420 a1961a4b Blue Swirl
        s->slaves[i].cpu = i;
421 a1961a4b Blue Swirl
        s->slaves[i].master = s;
422 a1961a4b Blue Swirl
    }
423 a1961a4b Blue Swirl
    register_savevm("slavio_intctl", -1, 1, slavio_intctl_save,
424 a1961a4b Blue Swirl
                    slavio_intctl_load, s);
425 a1961a4b Blue Swirl
    qemu_register_reset(slavio_intctl_reset, s);
426 a1961a4b Blue Swirl
    slavio_intctl_reset(s);
427 a1961a4b Blue Swirl
}
428 a1961a4b Blue Swirl
429 a1961a4b Blue Swirl
static SysBusDeviceInfo slavio_intctl_info = {
430 a1961a4b Blue Swirl
    .init = slavio_intctl_init1,
431 a1961a4b Blue Swirl
    .qdev.name  = "slavio_intctl",
432 a1961a4b Blue Swirl
    .qdev.size  = sizeof(SLAVIO_INTCTLState),
433 ee6847d1 Gerd Hoffmann
    .qdev.props = (Property[]) {
434 7fdaf611 Gerd Hoffmann
        DEFINE_PROP_UINT32("cputimer_bit", SLAVIO_INTCTLState, cputimer_bit, 0),
435 7fdaf611 Gerd Hoffmann
        DEFINE_PROP_END_OF_LIST(),
436 a1961a4b Blue Swirl
    }
437 a1961a4b Blue Swirl
};
438 d7edfd27 blueswir1
439 a1961a4b Blue Swirl
static void slavio_intctl_register_devices(void)
440 a1961a4b Blue Swirl
{
441 a1961a4b Blue Swirl
    sysbus_register_withprop(&slavio_intctl_info);
442 e80cfcfc bellard
}
443 a1961a4b Blue Swirl
444 a1961a4b Blue Swirl
device_init(slavio_intctl_register_devices)