Statistics
| Branch: | Revision:

root / hw / slavio_intctl.c @ 78895427

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