Statistics
| Branch: | Revision:

root / hw / slavio_intctl.c @ 9d926598

History | View | Annotate | Download (11.9 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 87ecb68b pbrook
#include "hw.h"
25 87ecb68b pbrook
#include "sun4m.h"
26 87ecb68b pbrook
#include "console.h"
27 87ecb68b pbrook
28 e80cfcfc bellard
//#define DEBUG_IRQ_COUNT
29 66321a11 bellard
//#define DEBUG_IRQ
30 66321a11 bellard
31 66321a11 bellard
#ifdef DEBUG_IRQ
32 66321a11 bellard
#define DPRINTF(fmt, args...) \
33 66321a11 bellard
do { printf("IRQ: " fmt , ##args); } while (0)
34 66321a11 bellard
#else
35 66321a11 bellard
#define DPRINTF(fmt, args...)
36 66321a11 bellard
#endif
37 e80cfcfc bellard
38 e80cfcfc bellard
/*
39 e80cfcfc bellard
 * Registers of interrupt controller in sun4m.
40 e80cfcfc bellard
 *
41 e80cfcfc bellard
 * This is the interrupt controller part of chip STP2001 (Slave I/O), also
42 e80cfcfc bellard
 * produced as NCR89C105. See
43 e80cfcfc bellard
 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
44 e80cfcfc bellard
 *
45 e80cfcfc bellard
 * There is a system master controller and one for each cpu.
46 5fafdf24 ths
 *
47 e80cfcfc bellard
 */
48 e80cfcfc bellard
49 e80cfcfc bellard
#define MAX_CPUS 16
50 b3a23197 blueswir1
#define MAX_PILS 16
51 e80cfcfc bellard
52 e80cfcfc bellard
typedef struct SLAVIO_INTCTLState {
53 e80cfcfc bellard
    uint32_t intreg_pending[MAX_CPUS];
54 e80cfcfc bellard
    uint32_t intregm_pending;
55 e80cfcfc bellard
    uint32_t intregm_disabled;
56 e80cfcfc bellard
    uint32_t target_cpu;
57 e80cfcfc bellard
#ifdef DEBUG_IRQ_COUNT
58 e80cfcfc bellard
    uint64_t irq_count[32];
59 e80cfcfc bellard
#endif
60 b3a23197 blueswir1
    qemu_irq *cpu_irqs[MAX_CPUS];
61 e0353fe2 blueswir1
    const uint32_t *intbit_to_level;
62 e3a79bca blueswir1
    uint32_t cputimer_lbit, cputimer_mbit;
63 b3a23197 blueswir1
    uint32_t pil_out[MAX_CPUS];
64 e80cfcfc bellard
} SLAVIO_INTCTLState;
65 e80cfcfc bellard
66 e80cfcfc bellard
#define INTCTL_MAXADDR 0xf
67 5aca8c3b blueswir1
#define INTCTL_SIZE (INTCTL_MAXADDR + 1)
68 c6fdf5fc blueswir1
#define INTCTLM_MAXADDR 0x13
69 5aca8c3b blueswir1
#define INTCTLM_SIZE (INTCTLM_MAXADDR + 1)
70 c6fdf5fc blueswir1
#define INTCTLM_MASK 0x1f
71 80be36b8 blueswir1
#define MASTER_IRQ_MASK ~0x0fa2007f
72 9a87ce9b blueswir1
#define MASTER_DISABLE 0x80000000
73 6341fdcb blueswir1
#define CPU_SOFTIRQ_MASK 0xfffe0000
74 6341fdcb blueswir1
#define CPU_HARDIRQ_MASK 0x0000fffe
75 9a87ce9b blueswir1
#define CPU_IRQ_INT15_IN 0x0004000
76 9a87ce9b blueswir1
#define CPU_IRQ_INT15_MASK 0x80000000
77 9a87ce9b blueswir1
78 66321a11 bellard
static void slavio_check_interrupts(void *opaque);
79 e80cfcfc bellard
80 e80cfcfc bellard
// per-cpu interrupt controller
81 e80cfcfc bellard
static uint32_t slavio_intctl_mem_readl(void *opaque, target_phys_addr_t addr)
82 e80cfcfc bellard
{
83 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
84 dd4131b3 blueswir1
    uint32_t saddr, ret;
85 e80cfcfc bellard
    int cpu;
86 e80cfcfc bellard
87 e80cfcfc bellard
    cpu = (addr & (MAX_CPUS - 1) * TARGET_PAGE_SIZE) >> 12;
88 e80cfcfc bellard
    saddr = (addr & INTCTL_MAXADDR) >> 2;
89 e80cfcfc bellard
    switch (saddr) {
90 e80cfcfc bellard
    case 0:
91 dd4131b3 blueswir1
        ret = s->intreg_pending[cpu];
92 dd4131b3 blueswir1
        break;
93 e80cfcfc bellard
    default:
94 dd4131b3 blueswir1
        ret = 0;
95 dd4131b3 blueswir1
        break;
96 e80cfcfc bellard
    }
97 1569fc29 blueswir1
    DPRINTF("read cpu %d reg 0x" TARGET_FMT_plx " = %x\n", cpu, addr, ret);
98 dd4131b3 blueswir1
99 dd4131b3 blueswir1
    return ret;
100 e80cfcfc bellard
}
101 e80cfcfc bellard
102 77f193da blueswir1
static void slavio_intctl_mem_writel(void *opaque, target_phys_addr_t addr,
103 77f193da blueswir1
                                     uint32_t val)
104 e80cfcfc bellard
{
105 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
106 e80cfcfc bellard
    uint32_t saddr;
107 e80cfcfc bellard
    int cpu;
108 e80cfcfc bellard
109 e80cfcfc bellard
    cpu = (addr & (MAX_CPUS - 1) * TARGET_PAGE_SIZE) >> 12;
110 e80cfcfc bellard
    saddr = (addr & INTCTL_MAXADDR) >> 2;
111 1569fc29 blueswir1
    DPRINTF("write cpu %d reg 0x" TARGET_FMT_plx " = %x\n", cpu, addr, val);
112 e80cfcfc bellard
    switch (saddr) {
113 e80cfcfc bellard
    case 1: // clear pending softints
114 9a87ce9b blueswir1
        if (val & CPU_IRQ_INT15_IN)
115 9a87ce9b blueswir1
            val |= CPU_IRQ_INT15_MASK;
116 6341fdcb blueswir1
        val &= CPU_SOFTIRQ_MASK;
117 f930d07e blueswir1
        s->intreg_pending[cpu] &= ~val;
118 327ac2e7 blueswir1
        slavio_check_interrupts(s);
119 77f193da blueswir1
        DPRINTF("Cleared cpu %d irq mask %x, curmask %x\n", cpu, val,
120 77f193da blueswir1
                s->intreg_pending[cpu]);
121 f930d07e blueswir1
        break;
122 e80cfcfc bellard
    case 2: // set softint
123 6341fdcb blueswir1
        val &= CPU_SOFTIRQ_MASK;
124 f930d07e blueswir1
        s->intreg_pending[cpu] |= val;
125 ba3c64fb bellard
        slavio_check_interrupts(s);
126 77f193da blueswir1
        DPRINTF("Set cpu %d irq mask %x, curmask %x\n", cpu, val,
127 77f193da blueswir1
                s->intreg_pending[cpu]);
128 f930d07e blueswir1
        break;
129 e80cfcfc bellard
    default:
130 f930d07e blueswir1
        break;
131 e80cfcfc bellard
    }
132 e80cfcfc bellard
}
133 e80cfcfc bellard
134 e80cfcfc bellard
static CPUReadMemoryFunc *slavio_intctl_mem_read[3] = {
135 7c560456 blueswir1
    NULL,
136 7c560456 blueswir1
    NULL,
137 e80cfcfc bellard
    slavio_intctl_mem_readl,
138 e80cfcfc bellard
};
139 e80cfcfc bellard
140 e80cfcfc bellard
static CPUWriteMemoryFunc *slavio_intctl_mem_write[3] = {
141 7c560456 blueswir1
    NULL,
142 7c560456 blueswir1
    NULL,
143 e80cfcfc bellard
    slavio_intctl_mem_writel,
144 e80cfcfc bellard
};
145 e80cfcfc bellard
146 e80cfcfc bellard
// master system interrupt controller
147 e80cfcfc bellard
static uint32_t slavio_intctlm_mem_readl(void *opaque, target_phys_addr_t addr)
148 e80cfcfc bellard
{
149 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
150 dd4131b3 blueswir1
    uint32_t saddr, ret;
151 e80cfcfc bellard
152 cc2acc47 blueswir1
    saddr = (addr & INTCTLM_MASK) >> 2;
153 e80cfcfc bellard
    switch (saddr) {
154 e80cfcfc bellard
    case 0:
155 9a87ce9b blueswir1
        ret = s->intregm_pending & ~MASTER_DISABLE;
156 dd4131b3 blueswir1
        break;
157 e80cfcfc bellard
    case 1:
158 80be36b8 blueswir1
        ret = s->intregm_disabled & MASTER_IRQ_MASK;
159 dd4131b3 blueswir1
        break;
160 e80cfcfc bellard
    case 4:
161 dd4131b3 blueswir1
        ret = s->target_cpu;
162 dd4131b3 blueswir1
        break;
163 e80cfcfc bellard
    default:
164 dd4131b3 blueswir1
        ret = 0;
165 dd4131b3 blueswir1
        break;
166 e80cfcfc bellard
    }
167 1569fc29 blueswir1
    DPRINTF("read system reg 0x" TARGET_FMT_plx " = %x\n", addr, ret);
168 dd4131b3 blueswir1
169 dd4131b3 blueswir1
    return ret;
170 e80cfcfc bellard
}
171 e80cfcfc bellard
172 77f193da blueswir1
static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr,
173 77f193da blueswir1
                                      uint32_t val)
174 e80cfcfc bellard
{
175 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
176 e80cfcfc bellard
    uint32_t saddr;
177 e80cfcfc bellard
178 c6fdf5fc blueswir1
    saddr = (addr & INTCTLM_MASK) >> 2;
179 1569fc29 blueswir1
    DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
180 e80cfcfc bellard
    switch (saddr) {
181 e80cfcfc bellard
    case 2: // clear (enable)
182 f930d07e blueswir1
        // Force clear unused bits
183 9a87ce9b blueswir1
        val &= MASTER_IRQ_MASK;
184 f930d07e blueswir1
        s->intregm_disabled &= ~val;
185 77f193da blueswir1
        DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
186 77f193da blueswir1
                s->intregm_disabled);
187 f930d07e blueswir1
        slavio_check_interrupts(s);
188 f930d07e blueswir1
        break;
189 e80cfcfc bellard
    case 3: // set (disable, clear pending)
190 f930d07e blueswir1
        // Force clear unused bits
191 9a87ce9b blueswir1
        val &= MASTER_IRQ_MASK;
192 f930d07e blueswir1
        s->intregm_disabled |= val;
193 f930d07e blueswir1
        s->intregm_pending &= ~val;
194 327ac2e7 blueswir1
        slavio_check_interrupts(s);
195 77f193da blueswir1
        DPRINTF("Disabled master irq mask %x, curmask %x\n", val,
196 77f193da blueswir1
                s->intregm_disabled);
197 f930d07e blueswir1
        break;
198 e80cfcfc bellard
    case 4:
199 f930d07e blueswir1
        s->target_cpu = val & (MAX_CPUS - 1);
200 327ac2e7 blueswir1
        slavio_check_interrupts(s);
201 f930d07e blueswir1
        DPRINTF("Set master irq cpu %d\n", s->target_cpu);
202 f930d07e blueswir1
        break;
203 e80cfcfc bellard
    default:
204 f930d07e blueswir1
        break;
205 e80cfcfc bellard
    }
206 e80cfcfc bellard
}
207 e80cfcfc bellard
208 e80cfcfc bellard
static CPUReadMemoryFunc *slavio_intctlm_mem_read[3] = {
209 7c560456 blueswir1
    NULL,
210 7c560456 blueswir1
    NULL,
211 e80cfcfc bellard
    slavio_intctlm_mem_readl,
212 e80cfcfc bellard
};
213 e80cfcfc bellard
214 e80cfcfc bellard
static CPUWriteMemoryFunc *slavio_intctlm_mem_write[3] = {
215 7c560456 blueswir1
    NULL,
216 7c560456 blueswir1
    NULL,
217 e80cfcfc bellard
    slavio_intctlm_mem_writel,
218 e80cfcfc bellard
};
219 e80cfcfc bellard
220 e80cfcfc bellard
void slavio_pic_info(void *opaque)
221 e80cfcfc bellard
{
222 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
223 e80cfcfc bellard
    int i;
224 e80cfcfc bellard
225 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
226 f930d07e blueswir1
        term_printf("per-cpu %d: pending 0x%08x\n", i, s->intreg_pending[i]);
227 e80cfcfc bellard
    }
228 77f193da blueswir1
    term_printf("master: pending 0x%08x, disabled 0x%08x\n",
229 77f193da blueswir1
                s->intregm_pending, s->intregm_disabled);
230 e80cfcfc bellard
}
231 e80cfcfc bellard
232 e80cfcfc bellard
void slavio_irq_info(void *opaque)
233 e80cfcfc bellard
{
234 e80cfcfc bellard
#ifndef DEBUG_IRQ_COUNT
235 e80cfcfc bellard
    term_printf("irq statistic code not compiled.\n");
236 e80cfcfc bellard
#else
237 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
238 e80cfcfc bellard
    int i;
239 e80cfcfc bellard
    int64_t count;
240 e80cfcfc bellard
241 e80cfcfc bellard
    term_printf("IRQ statistics:\n");
242 e80cfcfc bellard
    for (i = 0; i < 32; i++) {
243 e80cfcfc bellard
        count = s->irq_count[i];
244 e80cfcfc bellard
        if (count > 0)
245 26a76461 bellard
            term_printf("%2d: %" PRId64 "\n", i, count);
246 e80cfcfc bellard
    }
247 e80cfcfc bellard
#endif
248 e80cfcfc bellard
}
249 e80cfcfc bellard
250 66321a11 bellard
static void slavio_check_interrupts(void *opaque)
251 66321a11 bellard
{
252 66321a11 bellard
    SLAVIO_INTCTLState *s = opaque;
253 327ac2e7 blueswir1
    uint32_t pending = s->intregm_pending, pil_pending;
254 327ac2e7 blueswir1
    unsigned int i, j;
255 66321a11 bellard
256 66321a11 bellard
    pending &= ~s->intregm_disabled;
257 66321a11 bellard
258 b3a23197 blueswir1
    DPRINTF("pending %x disabled %x\n", pending, s->intregm_disabled);
259 ba3c64fb bellard
    for (i = 0; i < MAX_CPUS; i++) {
260 327ac2e7 blueswir1
        pil_pending = 0;
261 9a87ce9b blueswir1
        if (pending && !(s->intregm_disabled & MASTER_DISABLE) &&
262 b3a23197 blueswir1
            (i == s->target_cpu)) {
263 b3a23197 blueswir1
            for (j = 0; j < 32; j++) {
264 327ac2e7 blueswir1
                if (pending & (1 << j))
265 327ac2e7 blueswir1
                    pil_pending |= 1 << s->intbit_to_level[j];
266 b3a23197 blueswir1
            }
267 b3a23197 blueswir1
        }
268 6341fdcb blueswir1
        pil_pending |= (s->intreg_pending[i] & CPU_SOFTIRQ_MASK) >> 16;
269 327ac2e7 blueswir1
270 327ac2e7 blueswir1
        for (j = 0; j < MAX_PILS; j++) {
271 327ac2e7 blueswir1
            if (pil_pending & (1 << j)) {
272 327ac2e7 blueswir1
                if (!(s->pil_out[i] & (1 << j)))
273 327ac2e7 blueswir1
                    qemu_irq_raise(s->cpu_irqs[i][j]);
274 327ac2e7 blueswir1
            } else {
275 327ac2e7 blueswir1
                if (s->pil_out[i] & (1 << j))
276 327ac2e7 blueswir1
                    qemu_irq_lower(s->cpu_irqs[i][j]);
277 ba3c64fb bellard
            }
278 ba3c64fb bellard
        }
279 327ac2e7 blueswir1
        s->pil_out[i] = pil_pending;
280 ba3c64fb bellard
    }
281 66321a11 bellard
}
282 66321a11 bellard
283 e80cfcfc bellard
/*
284 e80cfcfc bellard
 * "irq" here is the bit number in the system interrupt register to
285 e80cfcfc bellard
 * separate serial and keyboard interrupts sharing a level.
286 e80cfcfc bellard
 */
287 d7edfd27 blueswir1
static void slavio_set_irq(void *opaque, int irq, int level)
288 e80cfcfc bellard
{
289 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
290 b3a23197 blueswir1
    uint32_t mask = 1 << irq;
291 b3a23197 blueswir1
    uint32_t pil = s->intbit_to_level[irq];
292 b3a23197 blueswir1
293 b3a23197 blueswir1
    DPRINTF("Set cpu %d irq %d -> pil %d level %d\n", s->target_cpu, irq, pil,
294 b3a23197 blueswir1
            level);
295 b3a23197 blueswir1
    if (pil > 0) {
296 b3a23197 blueswir1
        if (level) {
297 327ac2e7 blueswir1
#ifdef DEBUG_IRQ_COUNT
298 327ac2e7 blueswir1
            s->irq_count[pil]++;
299 327ac2e7 blueswir1
#endif
300 b3a23197 blueswir1
            s->intregm_pending |= mask;
301 b3a23197 blueswir1
            s->intreg_pending[s->target_cpu] |= 1 << pil;
302 b3a23197 blueswir1
        } else {
303 b3a23197 blueswir1
            s->intregm_pending &= ~mask;
304 b3a23197 blueswir1
            s->intreg_pending[s->target_cpu] &= ~(1 << pil);
305 b3a23197 blueswir1
        }
306 b3a23197 blueswir1
        slavio_check_interrupts(s);
307 e80cfcfc bellard
    }
308 e80cfcfc bellard
}
309 e80cfcfc bellard
310 d7edfd27 blueswir1
static void slavio_set_timer_irq_cpu(void *opaque, int cpu, int level)
311 ba3c64fb bellard
{
312 ba3c64fb bellard
    SLAVIO_INTCTLState *s = opaque;
313 ba3c64fb bellard
314 b3a23197 blueswir1
    DPRINTF("Set cpu %d local timer level %d\n", cpu, level);
315 d7edfd27 blueswir1
316 e3a79bca blueswir1
    if (level) {
317 e3a79bca blueswir1
        s->intregm_pending |= s->cputimer_mbit;
318 e3a79bca blueswir1
        s->intreg_pending[cpu] |= s->cputimer_lbit;
319 e3a79bca blueswir1
    } else {
320 e3a79bca blueswir1
        s->intregm_pending &= ~s->cputimer_mbit;
321 e3a79bca blueswir1
        s->intreg_pending[cpu] &= ~s->cputimer_lbit;
322 e3a79bca blueswir1
    }
323 d7edfd27 blueswir1
324 ba3c64fb bellard
    slavio_check_interrupts(s);
325 ba3c64fb bellard
}
326 ba3c64fb bellard
327 e80cfcfc bellard
static void slavio_intctl_save(QEMUFile *f, void *opaque)
328 e80cfcfc bellard
{
329 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
330 e80cfcfc bellard
    int i;
331 3b46e624 ths
332 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
333 f930d07e blueswir1
        qemu_put_be32s(f, &s->intreg_pending[i]);
334 e80cfcfc bellard
    }
335 e80cfcfc bellard
    qemu_put_be32s(f, &s->intregm_pending);
336 e80cfcfc bellard
    qemu_put_be32s(f, &s->intregm_disabled);
337 e80cfcfc bellard
    qemu_put_be32s(f, &s->target_cpu);
338 e80cfcfc bellard
}
339 e80cfcfc bellard
340 e80cfcfc bellard
static int slavio_intctl_load(QEMUFile *f, void *opaque, int version_id)
341 e80cfcfc bellard
{
342 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
343 e80cfcfc bellard
    int i;
344 e80cfcfc bellard
345 e80cfcfc bellard
    if (version_id != 1)
346 e80cfcfc bellard
        return -EINVAL;
347 e80cfcfc bellard
348 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
349 f930d07e blueswir1
        qemu_get_be32s(f, &s->intreg_pending[i]);
350 e80cfcfc bellard
    }
351 e80cfcfc bellard
    qemu_get_be32s(f, &s->intregm_pending);
352 e80cfcfc bellard
    qemu_get_be32s(f, &s->intregm_disabled);
353 e80cfcfc bellard
    qemu_get_be32s(f, &s->target_cpu);
354 327ac2e7 blueswir1
    slavio_check_interrupts(s);
355 e80cfcfc bellard
    return 0;
356 e80cfcfc bellard
}
357 e80cfcfc bellard
358 e80cfcfc bellard
static void slavio_intctl_reset(void *opaque)
359 e80cfcfc bellard
{
360 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
361 e80cfcfc bellard
    int i;
362 e80cfcfc bellard
363 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
364 f930d07e blueswir1
        s->intreg_pending[i] = 0;
365 e80cfcfc bellard
    }
366 9a87ce9b blueswir1
    s->intregm_disabled = ~MASTER_IRQ_MASK;
367 e80cfcfc bellard
    s->intregm_pending = 0;
368 e80cfcfc bellard
    s->target_cpu = 0;
369 327ac2e7 blueswir1
    slavio_check_interrupts(s);
370 e80cfcfc bellard
}
371 e80cfcfc bellard
372 5dcb6b91 blueswir1
void *slavio_intctl_init(target_phys_addr_t addr, target_phys_addr_t addrg,
373 d537cf6c pbrook
                         const uint32_t *intbit_to_level,
374 d7edfd27 blueswir1
                         qemu_irq **irq, qemu_irq **cpu_irq,
375 b3a23197 blueswir1
                         qemu_irq **parent_irq, unsigned int cputimer)
376 e80cfcfc bellard
{
377 e80cfcfc bellard
    int slavio_intctl_io_memory, slavio_intctlm_io_memory, i;
378 e80cfcfc bellard
    SLAVIO_INTCTLState *s;
379 e80cfcfc bellard
380 e80cfcfc bellard
    s = qemu_mallocz(sizeof(SLAVIO_INTCTLState));
381 e80cfcfc bellard
    if (!s)
382 e80cfcfc bellard
        return NULL;
383 e80cfcfc bellard
384 e0353fe2 blueswir1
    s->intbit_to_level = intbit_to_level;
385 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
386 77f193da blueswir1
        slavio_intctl_io_memory = cpu_register_io_memory(0,
387 77f193da blueswir1
                                                         slavio_intctl_mem_read,
388 77f193da blueswir1
                                                         slavio_intctl_mem_write,
389 77f193da blueswir1
                                                         s);
390 f930d07e blueswir1
        cpu_register_physical_memory(addr + i * TARGET_PAGE_SIZE, INTCTL_SIZE,
391 5aca8c3b blueswir1
                                     slavio_intctl_io_memory);
392 b3a23197 blueswir1
        s->cpu_irqs[i] = parent_irq[i];
393 e80cfcfc bellard
    }
394 e80cfcfc bellard
395 77f193da blueswir1
    slavio_intctlm_io_memory = cpu_register_io_memory(0,
396 77f193da blueswir1
                                                      slavio_intctlm_mem_read,
397 77f193da blueswir1
                                                      slavio_intctlm_mem_write,
398 77f193da blueswir1
                                                      s);
399 5aca8c3b blueswir1
    cpu_register_physical_memory(addrg, INTCTLM_SIZE, slavio_intctlm_io_memory);
400 e80cfcfc bellard
401 77f193da blueswir1
    register_savevm("slavio_intctl", addr, 1, slavio_intctl_save,
402 77f193da blueswir1
                    slavio_intctl_load, s);
403 e80cfcfc bellard
    qemu_register_reset(slavio_intctl_reset, s);
404 d537cf6c pbrook
    *irq = qemu_allocate_irqs(slavio_set_irq, s, 32);
405 d7edfd27 blueswir1
406 d7edfd27 blueswir1
    *cpu_irq = qemu_allocate_irqs(slavio_set_timer_irq_cpu, s, MAX_CPUS);
407 e3a79bca blueswir1
    s->cputimer_mbit = 1 << cputimer;
408 e3a79bca blueswir1
    s->cputimer_lbit = 1 << intbit_to_level[cputimer];
409 e80cfcfc bellard
    slavio_intctl_reset(s);
410 e80cfcfc bellard
    return s;
411 e80cfcfc bellard
}