Statistics
| Branch: | Revision:

root / hw / slavio_intctl.c @ 366c9332

History | View | Annotate | Download (13.4 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 c84a88d8 Peter Maydell
            /* Since there is not really an interrupt 0 (and pil_pending
293 c84a88d8 Peter Maydell
             * and irl_out bit zero are thus always zero) there is no need
294 c84a88d8 Peter Maydell
             * to do anything with cpu_irqs[i][0] and it is OK not to do
295 c84a88d8 Peter Maydell
             * the j=0 iteration of this loop.
296 c84a88d8 Peter Maydell
             */
297 c84a88d8 Peter Maydell
            for (j = MAX_PILS-1; j > 0; j--) {
298 0d0a7e69 Blue Swirl
                if (pil_pending & (1 << j)) {
299 462eda24 Blue Swirl
                    if (!(s->slaves[i].irl_out & (1 << j))) {
300 0d0a7e69 Blue Swirl
                        qemu_irq_raise(s->cpu_irqs[i][j]);
301 0d0a7e69 Blue Swirl
                    }
302 0d0a7e69 Blue Swirl
                } else {
303 462eda24 Blue Swirl
                    if (s->slaves[i].irl_out & (1 << j)) {
304 0d0a7e69 Blue Swirl
                        qemu_irq_lower(s->cpu_irqs[i][j]);
305 0d0a7e69 Blue Swirl
                    }
306 0d0a7e69 Blue Swirl
                }
307 ba3c64fb bellard
            }
308 ba3c64fb bellard
        }
309 462eda24 Blue Swirl
        s->slaves[i].irl_out = pil_pending;
310 ba3c64fb bellard
    }
311 66321a11 bellard
}
312 66321a11 bellard
313 e80cfcfc bellard
/*
314 e80cfcfc bellard
 * "irq" here is the bit number in the system interrupt register to
315 e80cfcfc bellard
 * separate serial and keyboard interrupts sharing a level.
316 e80cfcfc bellard
 */
317 d7edfd27 blueswir1
static void slavio_set_irq(void *opaque, int irq, int level)
318 e80cfcfc bellard
{
319 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
320 b3a23197 blueswir1
    uint32_t mask = 1 << irq;
321 68556e2e Blue Swirl
    uint32_t pil = intbit_to_level[irq];
322 462eda24 Blue Swirl
    unsigned int i;
323 b3a23197 blueswir1
324 97bf4851 Blue Swirl
    trace_slavio_set_irq(s->target_cpu, irq, pil, level);
325 b3a23197 blueswir1
    if (pil > 0) {
326 b3a23197 blueswir1
        if (level) {
327 327ac2e7 blueswir1
#ifdef DEBUG_IRQ_COUNT
328 327ac2e7 blueswir1
            s->irq_count[pil]++;
329 327ac2e7 blueswir1
#endif
330 b3a23197 blueswir1
            s->intregm_pending |= mask;
331 462eda24 Blue Swirl
            if (pil == 15) {
332 462eda24 Blue Swirl
                for (i = 0; i < MAX_CPUS; i++) {
333 462eda24 Blue Swirl
                    s->slaves[i].intreg_pending |= 1 << pil;
334 462eda24 Blue Swirl
                }
335 462eda24 Blue Swirl
            }
336 b3a23197 blueswir1
        } else {
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
        }
344 0d0a7e69 Blue Swirl
        slavio_check_interrupts(s, 1);
345 e80cfcfc bellard
    }
346 e80cfcfc bellard
}
347 e80cfcfc bellard
348 d7edfd27 blueswir1
static void slavio_set_timer_irq_cpu(void *opaque, int cpu, int level)
349 ba3c64fb bellard
{
350 ba3c64fb bellard
    SLAVIO_INTCTLState *s = opaque;
351 ba3c64fb bellard
352 97bf4851 Blue Swirl
    trace_slavio_set_timer_irq_cpu(cpu, level);
353 d7edfd27 blueswir1
354 e3a79bca blueswir1
    if (level) {
355 462eda24 Blue Swirl
        s->slaves[cpu].intreg_pending |= CPU_IRQ_TIMER_IN;
356 e3a79bca blueswir1
    } else {
357 462eda24 Blue Swirl
        s->slaves[cpu].intreg_pending &= ~CPU_IRQ_TIMER_IN;
358 e3a79bca blueswir1
    }
359 d7edfd27 blueswir1
360 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 1);
361 ba3c64fb bellard
}
362 ba3c64fb bellard
363 a1961a4b Blue Swirl
static void slavio_set_irq_all(void *opaque, int irq, int level)
364 a1961a4b Blue Swirl
{
365 a1961a4b Blue Swirl
    if (irq < 32) {
366 a1961a4b Blue Swirl
        slavio_set_irq(opaque, irq, level);
367 a1961a4b Blue Swirl
    } else {
368 a1961a4b Blue Swirl
        slavio_set_timer_irq_cpu(opaque, irq - 32, level);
369 a1961a4b Blue Swirl
    }
370 a1961a4b Blue Swirl
}
371 a1961a4b Blue Swirl
372 e59fb374 Juan Quintela
static int vmstate_intctl_post_load(void *opaque, int version_id)
373 e80cfcfc bellard
{
374 e80cfcfc bellard
    SLAVIO_INTCTLState *s = opaque;
375 3b46e624 ths
376 c9e95029 Blue Swirl
    slavio_check_interrupts(s, 0);
377 c9e95029 Blue Swirl
    return 0;
378 e80cfcfc bellard
}
379 e80cfcfc bellard
380 c9e95029 Blue Swirl
static const VMStateDescription vmstate_intctl_cpu = {
381 c9e95029 Blue Swirl
    .name ="slavio_intctl_cpu",
382 c9e95029 Blue Swirl
    .version_id = 1,
383 c9e95029 Blue Swirl
    .minimum_version_id = 1,
384 c9e95029 Blue Swirl
    .minimum_version_id_old = 1,
385 c9e95029 Blue Swirl
    .fields      = (VMStateField []) {
386 c9e95029 Blue Swirl
        VMSTATE_UINT32(intreg_pending, SLAVIO_CPUINTCTLState),
387 c9e95029 Blue Swirl
        VMSTATE_END_OF_LIST()
388 c9e95029 Blue Swirl
    }
389 c9e95029 Blue Swirl
};
390 e80cfcfc bellard
391 c9e95029 Blue Swirl
static const VMStateDescription vmstate_intctl = {
392 c9e95029 Blue Swirl
    .name ="slavio_intctl",
393 c9e95029 Blue Swirl
    .version_id = 1,
394 c9e95029 Blue Swirl
    .minimum_version_id = 1,
395 c9e95029 Blue Swirl
    .minimum_version_id_old = 1,
396 752ff2fa Juan Quintela
    .post_load = vmstate_intctl_post_load,
397 c9e95029 Blue Swirl
    .fields      = (VMStateField []) {
398 c9e95029 Blue Swirl
        VMSTATE_STRUCT_ARRAY(slaves, SLAVIO_INTCTLState, MAX_CPUS, 1,
399 c9e95029 Blue Swirl
                             vmstate_intctl_cpu, SLAVIO_CPUINTCTLState),
400 c9e95029 Blue Swirl
        VMSTATE_UINT32(intregm_pending, SLAVIO_INTCTLState),
401 c9e95029 Blue Swirl
        VMSTATE_UINT32(intregm_disabled, SLAVIO_INTCTLState),
402 c9e95029 Blue Swirl
        VMSTATE_UINT32(target_cpu, SLAVIO_INTCTLState),
403 c9e95029 Blue Swirl
        VMSTATE_END_OF_LIST()
404 e80cfcfc bellard
    }
405 c9e95029 Blue Swirl
};
406 e80cfcfc bellard
407 78971d57 Blue Swirl
static void slavio_intctl_reset(DeviceState *d)
408 e80cfcfc bellard
{
409 78971d57 Blue Swirl
    SLAVIO_INTCTLState *s = container_of(d, SLAVIO_INTCTLState, busdev.qdev);
410 e80cfcfc bellard
    int i;
411 e80cfcfc bellard
412 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
413 a1961a4b Blue Swirl
        s->slaves[i].intreg_pending = 0;
414 462eda24 Blue Swirl
        s->slaves[i].irl_out = 0;
415 e80cfcfc bellard
    }
416 9a87ce9b blueswir1
    s->intregm_disabled = ~MASTER_IRQ_MASK;
417 e80cfcfc bellard
    s->intregm_pending = 0;
418 e80cfcfc bellard
    s->target_cpu = 0;
419 0d0a7e69 Blue Swirl
    slavio_check_interrupts(s, 0);
420 e80cfcfc bellard
}
421 e80cfcfc bellard
422 81a322d4 Gerd Hoffmann
static int slavio_intctl_init1(SysBusDevice *dev)
423 e80cfcfc bellard
{
424 a1961a4b Blue Swirl
    SLAVIO_INTCTLState *s = FROM_SYSBUS(SLAVIO_INTCTLState, dev);
425 ee6847d1 Gerd Hoffmann
    int io_memory;
426 a1961a4b Blue Swirl
    unsigned int i, j;
427 e80cfcfc bellard
428 a1961a4b Blue Swirl
    qdev_init_gpio_in(&dev->qdev, slavio_set_irq_all, 32 + MAX_CPUS);
429 a1961a4b Blue Swirl
    io_memory = cpu_register_io_memory(slavio_intctlm_mem_read,
430 2507c12a Alexander Graf
                                       slavio_intctlm_mem_write, s,
431 2507c12a Alexander Graf
                                       DEVICE_NATIVE_ENDIAN);
432 a1961a4b Blue Swirl
    sysbus_init_mmio(dev, INTCTLM_SIZE, io_memory);
433 e80cfcfc bellard
434 e80cfcfc bellard
    for (i = 0; i < MAX_CPUS; i++) {
435 a1961a4b Blue Swirl
        for (j = 0; j < MAX_PILS; j++) {
436 a1961a4b Blue Swirl
            sysbus_init_irq(dev, &s->cpu_irqs[i][j]);
437 a1961a4b Blue Swirl
        }
438 a1961a4b Blue Swirl
        io_memory = cpu_register_io_memory(slavio_intctl_mem_read,
439 a1961a4b Blue Swirl
                                           slavio_intctl_mem_write,
440 2507c12a Alexander Graf
                                           &s->slaves[i],
441 2507c12a Alexander Graf
                                           DEVICE_NATIVE_ENDIAN);
442 a1961a4b Blue Swirl
        sysbus_init_mmio(dev, INTCTL_SIZE, io_memory);
443 a1961a4b Blue Swirl
        s->slaves[i].cpu = i;
444 a1961a4b Blue Swirl
        s->slaves[i].master = s;
445 a1961a4b Blue Swirl
    }
446 78971d57 Blue Swirl
447 81a322d4 Gerd Hoffmann
    return 0;
448 a1961a4b Blue Swirl
}
449 a1961a4b Blue Swirl
450 a1961a4b Blue Swirl
static SysBusDeviceInfo slavio_intctl_info = {
451 a1961a4b Blue Swirl
    .init = slavio_intctl_init1,
452 a1961a4b Blue Swirl
    .qdev.name  = "slavio_intctl",
453 a1961a4b Blue Swirl
    .qdev.size  = sizeof(SLAVIO_INTCTLState),
454 78971d57 Blue Swirl
    .qdev.vmsd  = &vmstate_intctl,
455 78971d57 Blue Swirl
    .qdev.reset = slavio_intctl_reset,
456 a1961a4b Blue Swirl
};
457 d7edfd27 blueswir1
458 a1961a4b Blue Swirl
static void slavio_intctl_register_devices(void)
459 a1961a4b Blue Swirl
{
460 a1961a4b Blue Swirl
    sysbus_register_withprop(&slavio_intctl_info);
461 e80cfcfc bellard
}
462 a1961a4b Blue Swirl
463 a1961a4b Blue Swirl
device_init(slavio_intctl_register_devices)