Statistics
| Branch: | Revision:

root / hw / slavio_intctl.c @ e4c7d2ae

History | View | Annotate | Download (13.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 462eda24 Blue Swirl
    uint32_t irl_out;
60 a1961a4b Blue Swirl
} SLAVIO_CPUINTCTLState;
61 a8f48dcc blueswir1
62 e80cfcfc bellard
typedef struct SLAVIO_INTCTLState {
63 a1961a4b Blue Swirl
    SysBusDevice busdev;
64 e80cfcfc bellard
    uint32_t intregm_pending;
65 e80cfcfc bellard
    uint32_t intregm_disabled;
66 e80cfcfc bellard
    uint32_t target_cpu;
67 e80cfcfc bellard
#ifdef DEBUG_IRQ_COUNT
68 e80cfcfc bellard
    uint64_t irq_count[32];
69 e80cfcfc bellard
#endif
70 a1961a4b Blue Swirl
    qemu_irq cpu_irqs[MAX_CPUS][MAX_PILS];
71 a1961a4b Blue Swirl
    SLAVIO_CPUINTCTLState slaves[MAX_CPUS];
72 e80cfcfc bellard
} SLAVIO_INTCTLState;
73 e80cfcfc bellard
74 e80cfcfc bellard
#define INTCTL_MAXADDR 0xf
75 5aca8c3b blueswir1
#define INTCTL_SIZE (INTCTL_MAXADDR + 1)
76 a8f48dcc blueswir1
#define INTCTLM_SIZE 0x14
77 80be36b8 blueswir1
#define MASTER_IRQ_MASK ~0x0fa2007f
78 9a87ce9b blueswir1
#define MASTER_DISABLE 0x80000000
79 6341fdcb blueswir1
#define CPU_SOFTIRQ_MASK 0xfffe0000
80 462eda24 Blue Swirl
#define CPU_IRQ_INT15_IN (1 << 15)
81 462eda24 Blue Swirl
#define CPU_IRQ_TIMER_IN (1 << 14)
82 9a87ce9b blueswir1
83 0d0a7e69 Blue Swirl
static void slavio_check_interrupts(SLAVIO_INTCTLState *s, int set_irqs);
84 e80cfcfc bellard
85 e80cfcfc bellard
// per-cpu interrupt controller
86 c227f099 Anthony Liguori
static uint32_t slavio_intctl_mem_readl(void *opaque, target_phys_addr_t addr)
87 e80cfcfc bellard
{
88 a8f48dcc blueswir1
    SLAVIO_CPUINTCTLState *s = opaque;
89 dd4131b3 blueswir1
    uint32_t saddr, ret;
90 e80cfcfc bellard
91 a8f48dcc blueswir1
    saddr = addr >> 2;
92 e80cfcfc bellard
    switch (saddr) {
93 e80cfcfc bellard
    case 0:
94 a8f48dcc blueswir1
        ret = s->intreg_pending;
95 dd4131b3 blueswir1
        break;
96 e80cfcfc bellard
    default:
97 dd4131b3 blueswir1
        ret = 0;
98 dd4131b3 blueswir1
        break;
99 e80cfcfc bellard
    }
100 3c4cf535 blueswir1
    DPRINTF("read cpu %d reg 0x" TARGET_FMT_plx " = %x\n", s->cpu, addr, ret);
101 dd4131b3 blueswir1
102 dd4131b3 blueswir1
    return ret;
103 e80cfcfc bellard
}
104 e80cfcfc bellard
105 c227f099 Anthony Liguori
static void slavio_intctl_mem_writel(void *opaque, target_phys_addr_t addr,
106 77f193da blueswir1
                                     uint32_t val)
107 e80cfcfc bellard
{
108 a8f48dcc blueswir1
    SLAVIO_CPUINTCTLState *s = opaque;
109 e80cfcfc bellard
    uint32_t saddr;
110 e80cfcfc bellard
111 a8f48dcc blueswir1
    saddr = addr >> 2;
112 3c4cf535 blueswir1
    DPRINTF("write cpu %d reg 0x" TARGET_FMT_plx " = %x\n", s->cpu, addr, val);
113 e80cfcfc bellard
    switch (saddr) {
114 e80cfcfc bellard
    case 1: // clear pending softints
115 462eda24 Blue Swirl
        val &= CPU_SOFTIRQ_MASK | CPU_IRQ_INT15_IN;
116 a8f48dcc blueswir1
        s->intreg_pending &= ~val;
117 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s->master, 1);
118 a8f48dcc blueswir1
        DPRINTF("Cleared cpu %d irq mask %x, curmask %x\n", s->cpu, val,
119 a8f48dcc blueswir1
                s->intreg_pending);
120 f930d07e blueswir1
        break;
121 e80cfcfc bellard
    case 2: // set softint
122 6341fdcb blueswir1
        val &= CPU_SOFTIRQ_MASK;
123 a8f48dcc blueswir1
        s->intreg_pending |= val;
124 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s->master, 1);
125 a8f48dcc blueswir1
        DPRINTF("Set cpu %d irq mask %x, curmask %x\n", s->cpu, val,
126 a8f48dcc blueswir1
                s->intreg_pending);
127 f930d07e blueswir1
        break;
128 e80cfcfc bellard
    default:
129 f930d07e blueswir1
        break;
130 e80cfcfc bellard
    }
131 e80cfcfc bellard
}
132 e80cfcfc bellard
133 d60efc6b Blue Swirl
static CPUReadMemoryFunc * const slavio_intctl_mem_read[3] = {
134 7c560456 blueswir1
    NULL,
135 7c560456 blueswir1
    NULL,
136 e80cfcfc bellard
    slavio_intctl_mem_readl,
137 e80cfcfc bellard
};
138 e80cfcfc bellard
139 d60efc6b Blue Swirl
static CPUWriteMemoryFunc * const slavio_intctl_mem_write[3] = {
140 7c560456 blueswir1
    NULL,
141 7c560456 blueswir1
    NULL,
142 e80cfcfc bellard
    slavio_intctl_mem_writel,
143 e80cfcfc bellard
};
144 e80cfcfc bellard
145 e80cfcfc bellard
// master system interrupt controller
146 c227f099 Anthony Liguori
static uint32_t slavio_intctlm_mem_readl(void *opaque, target_phys_addr_t addr)
147 e80cfcfc bellard
{
148 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
149 dd4131b3 blueswir1
    uint32_t saddr, ret;
150 e80cfcfc bellard
151 a8f48dcc blueswir1
    saddr = addr >> 2;
152 e80cfcfc bellard
    switch (saddr) {
153 e80cfcfc bellard
    case 0:
154 9a87ce9b blueswir1
        ret = s->intregm_pending & ~MASTER_DISABLE;
155 dd4131b3 blueswir1
        break;
156 e80cfcfc bellard
    case 1:
157 80be36b8 blueswir1
        ret = s->intregm_disabled & MASTER_IRQ_MASK;
158 dd4131b3 blueswir1
        break;
159 e80cfcfc bellard
    case 4:
160 dd4131b3 blueswir1
        ret = s->target_cpu;
161 dd4131b3 blueswir1
        break;
162 e80cfcfc bellard
    default:
163 dd4131b3 blueswir1
        ret = 0;
164 dd4131b3 blueswir1
        break;
165 e80cfcfc bellard
    }
166 1569fc29 blueswir1
    DPRINTF("read system reg 0x" TARGET_FMT_plx " = %x\n", addr, ret);
167 dd4131b3 blueswir1
168 dd4131b3 blueswir1
    return ret;
169 e80cfcfc bellard
}
170 e80cfcfc bellard
171 c227f099 Anthony Liguori
static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr,
172 77f193da blueswir1
                                      uint32_t val)
173 e80cfcfc bellard
{
174 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
175 e80cfcfc bellard
    uint32_t saddr;
176 e80cfcfc bellard
177 a8f48dcc blueswir1
    saddr = addr >> 2;
178 1569fc29 blueswir1
    DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
179 e80cfcfc bellard
    switch (saddr) {
180 e80cfcfc bellard
    case 2: // clear (enable)
181 f930d07e blueswir1
        // Force clear unused bits
182 9a87ce9b blueswir1
        val &= MASTER_IRQ_MASK;
183 f930d07e blueswir1
        s->intregm_disabled &= ~val;
184 77f193da blueswir1
        DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
185 77f193da blueswir1
                s->intregm_disabled);
186 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
187 f930d07e blueswir1
        break;
188 10760f0f Artyom Tarasenko
    case 3: // set (disable; doesn't affect pending)
189 f930d07e blueswir1
        // Force clear unused bits
190 9a87ce9b blueswir1
        val &= MASTER_IRQ_MASK;
191 f930d07e blueswir1
        s->intregm_disabled |= val;
192 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
193 77f193da blueswir1
        DPRINTF("Disabled master irq mask %x, curmask %x\n", val,
194 77f193da blueswir1
                s->intregm_disabled);
195 f930d07e blueswir1
        break;
196 e80cfcfc bellard
    case 4:
197 f930d07e blueswir1
        s->target_cpu = val & (MAX_CPUS - 1);
198 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
199 f930d07e blueswir1
        DPRINTF("Set master irq cpu %d\n", s->target_cpu);
200 f930d07e blueswir1
        break;
201 e80cfcfc bellard
    default:
202 f930d07e blueswir1
        break;
203 e80cfcfc bellard
    }
204 e80cfcfc bellard
}
205 e80cfcfc bellard
206 d60efc6b Blue Swirl
static CPUReadMemoryFunc * const slavio_intctlm_mem_read[3] = {
207 7c560456 blueswir1
    NULL,
208 7c560456 blueswir1
    NULL,
209 e80cfcfc bellard
    slavio_intctlm_mem_readl,
210 e80cfcfc bellard
};
211 e80cfcfc bellard
212 d60efc6b Blue Swirl
static CPUWriteMemoryFunc * const slavio_intctlm_mem_write[3] = {
213 7c560456 blueswir1
    NULL,
214 7c560456 blueswir1
    NULL,
215 e80cfcfc bellard
    slavio_intctlm_mem_writel,
216 e80cfcfc bellard
};
217 e80cfcfc bellard
218 d453c2c3 Blue Swirl
void slavio_pic_info(Monitor *mon, DeviceState *dev)
219 e80cfcfc bellard
{
220 d453c2c3 Blue Swirl
    SysBusDevice *sd;
221 d453c2c3 Blue Swirl
    SLAVIO_INTCTLState *s;
222 e80cfcfc bellard
    int i;
223 e80cfcfc bellard
224 d453c2c3 Blue Swirl
    sd = sysbus_from_qdev(dev);
225 d453c2c3 Blue Swirl
    s = FROM_SYSBUS(SLAVIO_INTCTLState, sd);
226 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
227 376253ec aliguori
        monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
228 a1961a4b Blue Swirl
                       s->slaves[i].intreg_pending);
229 e80cfcfc bellard
    }
230 376253ec aliguori
    monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
231 376253ec aliguori
                   s->intregm_pending, s->intregm_disabled);
232 e80cfcfc bellard
}
233 e80cfcfc bellard
234 d453c2c3 Blue Swirl
void slavio_irq_info(Monitor *mon, DeviceState *dev)
235 e80cfcfc bellard
{
236 e80cfcfc bellard
#ifndef DEBUG_IRQ_COUNT
237 376253ec aliguori
    monitor_printf(mon, "irq statistic code not compiled.\n");
238 e80cfcfc bellard
#else
239 d453c2c3 Blue Swirl
    SysBusDevice *sd;
240 d453c2c3 Blue Swirl
    SLAVIO_INTCTLState *s;
241 e80cfcfc bellard
    int i;
242 e80cfcfc bellard
    int64_t count;
243 e80cfcfc bellard
244 d453c2c3 Blue Swirl
    sd = sysbus_from_qdev(dev);
245 d453c2c3 Blue Swirl
    s = FROM_SYSBUS(SLAVIO_INTCTLState, sd);
246 376253ec aliguori
    monitor_printf(mon, "IRQ statistics:\n");
247 e80cfcfc bellard
    for (i = 0; i < 32; i++) {
248 e80cfcfc bellard
        count = s->irq_count[i];
249 e80cfcfc bellard
        if (count > 0)
250 376253ec aliguori
            monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
251 e80cfcfc bellard
    }
252 e80cfcfc bellard
#endif
253 e80cfcfc bellard
}
254 e80cfcfc bellard
255 68556e2e Blue Swirl
static const uint32_t intbit_to_level[] = {
256 462eda24 Blue Swirl
    2, 3, 5, 7, 9, 11, 13, 2,   3, 5, 7, 9, 11, 13, 12, 12,
257 462eda24 Blue Swirl
    6, 13, 4, 10, 8, 9, 11, 0,  0, 0, 0, 15, 15, 15, 15, 0,
258 68556e2e Blue Swirl
};
259 68556e2e Blue Swirl
260 0d0a7e69 Blue Swirl
static void slavio_check_interrupts(SLAVIO_INTCTLState *s, int set_irqs)
261 66321a11 bellard
{
262 327ac2e7 blueswir1
    uint32_t pending = s->intregm_pending, pil_pending;
263 327ac2e7 blueswir1
    unsigned int i, j;
264 66321a11 bellard
265 66321a11 bellard
    pending &= ~s->intregm_disabled;
266 66321a11 bellard
267 b3a23197 blueswir1
    DPRINTF("pending %x disabled %x\n", pending, s->intregm_disabled);
268 ba3c64fb bellard
    for (i = 0; i < MAX_CPUS; i++) {
269 327ac2e7 blueswir1
        pil_pending = 0;
270 462eda24 Blue Swirl
271 462eda24 Blue Swirl
        /* If we are the current interrupt target, get hard interrupts */
272 9a87ce9b blueswir1
        if (pending && !(s->intregm_disabled & MASTER_DISABLE) &&
273 b3a23197 blueswir1
            (i == s->target_cpu)) {
274 b3a23197 blueswir1
            for (j = 0; j < 32; j++) {
275 462eda24 Blue Swirl
                if ((pending & (1 << j)) && intbit_to_level[j]) {
276 68556e2e Blue Swirl
                    pil_pending |= 1 << intbit_to_level[j];
277 462eda24 Blue Swirl
                }
278 462eda24 Blue Swirl
            }
279 462eda24 Blue Swirl
        }
280 462eda24 Blue Swirl
281 462eda24 Blue Swirl
        /* Calculate current pending hard interrupts for display */
282 462eda24 Blue Swirl
        s->slaves[i].intreg_pending &= CPU_SOFTIRQ_MASK | CPU_IRQ_INT15_IN |
283 462eda24 Blue Swirl
            CPU_IRQ_TIMER_IN;
284 462eda24 Blue Swirl
        if (i == s->target_cpu) {
285 462eda24 Blue Swirl
            for (j = 0; j < 32; j++) {
286 462eda24 Blue Swirl
                if ((s->intregm_pending & (1 << j)) && intbit_to_level[j]) {
287 462eda24 Blue Swirl
                    s->slaves[i].intreg_pending |= 1 << intbit_to_level[j];
288 462eda24 Blue Swirl
                }
289 b3a23197 blueswir1
            }
290 b3a23197 blueswir1
        }
291 462eda24 Blue Swirl
292 94c5f455 Artyom Tarasenko
        /* Level 15 and CPU timer interrupts are only masked when
293 94c5f455 Artyom Tarasenko
           the MASTER_DISABLE bit is set */
294 94c5f455 Artyom Tarasenko
        if (!(s->intregm_disabled & MASTER_DISABLE)) {
295 94c5f455 Artyom Tarasenko
            pil_pending |= s->slaves[i].intreg_pending &
296 94c5f455 Artyom Tarasenko
                (CPU_IRQ_INT15_IN | CPU_IRQ_TIMER_IN);
297 94c5f455 Artyom Tarasenko
        }
298 462eda24 Blue Swirl
299 462eda24 Blue Swirl
        /* Add soft interrupts */
300 a1961a4b Blue Swirl
        pil_pending |= (s->slaves[i].intreg_pending & CPU_SOFTIRQ_MASK) >> 16;
301 327ac2e7 blueswir1
302 0d0a7e69 Blue Swirl
        if (set_irqs) {
303 462eda24 Blue Swirl
            for (j = MAX_PILS; j > 0; j--) {
304 0d0a7e69 Blue Swirl
                if (pil_pending & (1 << j)) {
305 462eda24 Blue Swirl
                    if (!(s->slaves[i].irl_out & (1 << j))) {
306 0d0a7e69 Blue Swirl
                        qemu_irq_raise(s->cpu_irqs[i][j]);
307 0d0a7e69 Blue Swirl
                    }
308 0d0a7e69 Blue Swirl
                } else {
309 462eda24 Blue Swirl
                    if (s->slaves[i].irl_out & (1 << j)) {
310 0d0a7e69 Blue Swirl
                        qemu_irq_lower(s->cpu_irqs[i][j]);
311 0d0a7e69 Blue Swirl
                    }
312 0d0a7e69 Blue Swirl
                }
313 ba3c64fb bellard
            }
314 ba3c64fb bellard
        }
315 462eda24 Blue Swirl
        s->slaves[i].irl_out = pil_pending;
316 ba3c64fb bellard
    }
317 66321a11 bellard
}
318 66321a11 bellard
319 e80cfcfc bellard
/*
320 e80cfcfc bellard
 * "irq" here is the bit number in the system interrupt register to
321 e80cfcfc bellard
 * separate serial and keyboard interrupts sharing a level.
322 e80cfcfc bellard
 */
323 d7edfd27 blueswir1
static void slavio_set_irq(void *opaque, int irq, int level)
324 e80cfcfc bellard
{
325 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
326 b3a23197 blueswir1
    uint32_t mask = 1 << irq;
327 68556e2e Blue Swirl
    uint32_t pil = intbit_to_level[irq];
328 462eda24 Blue Swirl
    unsigned int i;
329 b3a23197 blueswir1
330 b3a23197 blueswir1
    DPRINTF("Set cpu %d irq %d -> pil %d level %d\n", s->target_cpu, irq, pil,
331 b3a23197 blueswir1
            level);
332 b3a23197 blueswir1
    if (pil > 0) {
333 b3a23197 blueswir1
        if (level) {
334 327ac2e7 blueswir1
#ifdef DEBUG_IRQ_COUNT
335 327ac2e7 blueswir1
            s->irq_count[pil]++;
336 327ac2e7 blueswir1
#endif
337 b3a23197 blueswir1
            s->intregm_pending |= mask;
338 462eda24 Blue Swirl
            if (pil == 15) {
339 462eda24 Blue Swirl
                for (i = 0; i < MAX_CPUS; i++) {
340 462eda24 Blue Swirl
                    s->slaves[i].intreg_pending |= 1 << pil;
341 462eda24 Blue Swirl
                }
342 462eda24 Blue Swirl
            }
343 b3a23197 blueswir1
        } else {
344 b3a23197 blueswir1
            s->intregm_pending &= ~mask;
345 462eda24 Blue Swirl
            if (pil == 15) {
346 462eda24 Blue Swirl
                for (i = 0; i < MAX_CPUS; i++) {
347 462eda24 Blue Swirl
                    s->slaves[i].intreg_pending &= ~(1 << pil);
348 462eda24 Blue Swirl
                }
349 462eda24 Blue Swirl
            }
350 b3a23197 blueswir1
        }
351 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
352 e80cfcfc bellard
    }
353 e80cfcfc bellard
}
354 e80cfcfc bellard
355 d7edfd27 blueswir1
static void slavio_set_timer_irq_cpu(void *opaque, int cpu, int level)
356 ba3c64fb bellard
{
357 ba3c64fb bellard
    SLAVIO_INTCTLState *s = opaque;
358 ba3c64fb bellard
359 b3a23197 blueswir1
    DPRINTF("Set cpu %d local timer level %d\n", cpu, level);
360 d7edfd27 blueswir1
361 e3a79bca blueswir1
    if (level) {
362 462eda24 Blue Swirl
        s->slaves[cpu].intreg_pending |= CPU_IRQ_TIMER_IN;
363 e3a79bca blueswir1
    } else {
364 462eda24 Blue Swirl
        s->slaves[cpu].intreg_pending &= ~CPU_IRQ_TIMER_IN;
365 e3a79bca blueswir1
    }
366 d7edfd27 blueswir1
367 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 1);
368 ba3c64fb bellard
}
369 ba3c64fb bellard
370 a1961a4b Blue Swirl
static void slavio_set_irq_all(void *opaque, int irq, int level)
371 a1961a4b Blue Swirl
{
372 a1961a4b Blue Swirl
    if (irq < 32) {
373 a1961a4b Blue Swirl
        slavio_set_irq(opaque, irq, level);
374 a1961a4b Blue Swirl
    } else {
375 a1961a4b Blue Swirl
        slavio_set_timer_irq_cpu(opaque, irq - 32, level);
376 a1961a4b Blue Swirl
    }
377 a1961a4b Blue Swirl
}
378 a1961a4b Blue Swirl
379 e59fb374 Juan Quintela
static int vmstate_intctl_post_load(void *opaque, int version_id)
380 e80cfcfc bellard
{
381 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
382 3b46e624 ths
383 c9e95029 Blue Swirl
    slavio_check_interrupts(s, 0);
384 c9e95029 Blue Swirl
    return 0;
385 e80cfcfc bellard
}
386 e80cfcfc bellard
387 c9e95029 Blue Swirl
static const VMStateDescription vmstate_intctl_cpu = {
388 c9e95029 Blue Swirl
    .name ="slavio_intctl_cpu",
389 c9e95029 Blue Swirl
    .version_id = 1,
390 c9e95029 Blue Swirl
    .minimum_version_id = 1,
391 c9e95029 Blue Swirl
    .minimum_version_id_old = 1,
392 c9e95029 Blue Swirl
    .fields      = (VMStateField []) {
393 c9e95029 Blue Swirl
        VMSTATE_UINT32(intreg_pending, SLAVIO_CPUINTCTLState),
394 c9e95029 Blue Swirl
        VMSTATE_END_OF_LIST()
395 c9e95029 Blue Swirl
    }
396 c9e95029 Blue Swirl
};
397 e80cfcfc bellard
398 c9e95029 Blue Swirl
static const VMStateDescription vmstate_intctl = {
399 c9e95029 Blue Swirl
    .name ="slavio_intctl",
400 c9e95029 Blue Swirl
    .version_id = 1,
401 c9e95029 Blue Swirl
    .minimum_version_id = 1,
402 c9e95029 Blue Swirl
    .minimum_version_id_old = 1,
403 752ff2fa Juan Quintela
    .post_load = vmstate_intctl_post_load,
404 c9e95029 Blue Swirl
    .fields      = (VMStateField []) {
405 c9e95029 Blue Swirl
        VMSTATE_STRUCT_ARRAY(slaves, SLAVIO_INTCTLState, MAX_CPUS, 1,
406 c9e95029 Blue Swirl
                             vmstate_intctl_cpu, SLAVIO_CPUINTCTLState),
407 c9e95029 Blue Swirl
        VMSTATE_UINT32(intregm_pending, SLAVIO_INTCTLState),
408 c9e95029 Blue Swirl
        VMSTATE_UINT32(intregm_disabled, SLAVIO_INTCTLState),
409 c9e95029 Blue Swirl
        VMSTATE_UINT32(target_cpu, SLAVIO_INTCTLState),
410 c9e95029 Blue Swirl
        VMSTATE_END_OF_LIST()
411 e80cfcfc bellard
    }
412 c9e95029 Blue Swirl
};
413 e80cfcfc bellard
414 78971d57 Blue Swirl
static void slavio_intctl_reset(DeviceState *d)
415 e80cfcfc bellard
{
416 78971d57 Blue Swirl
    SLAVIO_INTCTLState *s = container_of(d, SLAVIO_INTCTLState, busdev.qdev);
417 e80cfcfc bellard
    int i;
418 e80cfcfc bellard
419 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
420 a1961a4b Blue Swirl
        s->slaves[i].intreg_pending = 0;
421 462eda24 Blue Swirl
        s->slaves[i].irl_out = 0;
422 e80cfcfc bellard
    }
423 9a87ce9b blueswir1
    s->intregm_disabled = ~MASTER_IRQ_MASK;
424 e80cfcfc bellard
    s->intregm_pending = 0;
425 e80cfcfc bellard
    s->target_cpu = 0;
426 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 0);
427 e80cfcfc bellard
}
428 e80cfcfc bellard
429 81a322d4 Gerd Hoffmann
static int slavio_intctl_init1(SysBusDevice *dev)
430 e80cfcfc bellard
{
431 a1961a4b Blue Swirl
    SLAVIO_INTCTLState *s = FROM_SYSBUS(SLAVIO_INTCTLState, dev);
432 ee6847d1 Gerd Hoffmann
    int io_memory;
433 a1961a4b Blue Swirl
    unsigned int i, j;
434 e80cfcfc bellard
435 a1961a4b Blue Swirl
    qdev_init_gpio_in(&dev->qdev, slavio_set_irq_all, 32 + MAX_CPUS);
436 a1961a4b Blue Swirl
    io_memory = cpu_register_io_memory(slavio_intctlm_mem_read,
437 a1961a4b Blue Swirl
                                       slavio_intctlm_mem_write, s);
438 a1961a4b Blue Swirl
    sysbus_init_mmio(dev, INTCTLM_SIZE, io_memory);
439 e80cfcfc bellard
440 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
441 a1961a4b Blue Swirl
        for (j = 0; j < MAX_PILS; j++) {
442 a1961a4b Blue Swirl
            sysbus_init_irq(dev, &s->cpu_irqs[i][j]);
443 a1961a4b Blue Swirl
        }
444 a1961a4b Blue Swirl
        io_memory = cpu_register_io_memory(slavio_intctl_mem_read,
445 a1961a4b Blue Swirl
                                           slavio_intctl_mem_write,
446 a1961a4b Blue Swirl
                                           &s->slaves[i]);
447 a1961a4b Blue Swirl
        sysbus_init_mmio(dev, INTCTL_SIZE, io_memory);
448 a1961a4b Blue Swirl
        s->slaves[i].cpu = i;
449 a1961a4b Blue Swirl
        s->slaves[i].master = s;
450 a1961a4b Blue Swirl
    }
451 78971d57 Blue Swirl
452 81a322d4 Gerd Hoffmann
    return 0;
453 a1961a4b Blue Swirl
}
454 a1961a4b Blue Swirl
455 a1961a4b Blue Swirl
static SysBusDeviceInfo slavio_intctl_info = {
456 a1961a4b Blue Swirl
    .init = slavio_intctl_init1,
457 a1961a4b Blue Swirl
    .qdev.name  = "slavio_intctl",
458 a1961a4b Blue Swirl
    .qdev.size  = sizeof(SLAVIO_INTCTLState),
459 78971d57 Blue Swirl
    .qdev.vmsd  = &vmstate_intctl,
460 78971d57 Blue Swirl
    .qdev.reset = slavio_intctl_reset,
461 a1961a4b Blue Swirl
};
462 d7edfd27 blueswir1
463 a1961a4b Blue Swirl
static void slavio_intctl_register_devices(void)
464 a1961a4b Blue Swirl
{
465 a1961a4b Blue Swirl
    sysbus_register_withprop(&slavio_intctl_info);
466 e80cfcfc bellard
}
467 a1961a4b Blue Swirl
468 a1961a4b Blue Swirl
device_init(slavio_intctl_register_devices)