blob: 9ee5ff89b0118d6639409122828cb55c301225d6 [file] [log] [blame]
bellarde80cfcf2004-12-19 23:18:01 +00001/*
2 * QEMU Sparc SLAVIO interrupt controller emulation
ths5fafdf22007-09-16 21:08:06 +00003 *
bellard66321a12005-04-06 20:47:48 +00004 * Copyright (c) 2003-2005 Fabrice Bellard
ths5fafdf22007-09-16 21:08:06 +00005 *
bellarde80cfcf2004-12-19 23:18:01 +00006 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
pbrook87ecb682007-11-17 17:14:51 +000024#include "hw.h"
25#include "sun4m.h"
aliguori376253e2009-03-05 23:01:23 +000026#include "monitor.h"
pbrook87ecb682007-11-17 17:14:51 +000027
bellarde80cfcf2004-12-19 23:18:01 +000028//#define DEBUG_IRQ_COUNT
bellard66321a12005-04-06 20:47:48 +000029//#define DEBUG_IRQ
30
31#ifdef DEBUG_IRQ
32#define DPRINTF(fmt, args...) \
33do { printf("IRQ: " fmt , ##args); } while (0)
34#else
35#define DPRINTF(fmt, args...)
36#endif
bellarde80cfcf2004-12-19 23:18:01 +000037
38/*
39 * Registers of interrupt controller in sun4m.
40 *
41 * This is the interrupt controller part of chip STP2001 (Slave I/O), also
42 * produced as NCR89C105. See
43 * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
44 *
45 * There is a system master controller and one for each cpu.
ths5fafdf22007-09-16 21:08:06 +000046 *
bellarde80cfcf2004-12-19 23:18:01 +000047 */
48
49#define MAX_CPUS 16
blueswir1b3a23192007-05-27 16:42:29 +000050#define MAX_PILS 16
bellarde80cfcf2004-12-19 23:18:01 +000051
blueswir1a8f48dc2008-12-02 17:51:19 +000052struct SLAVIO_CPUINTCTLState;
53
bellarde80cfcf2004-12-19 23:18:01 +000054typedef struct SLAVIO_INTCTLState {
bellarde80cfcf2004-12-19 23:18:01 +000055 uint32_t intregm_pending;
56 uint32_t intregm_disabled;
57 uint32_t target_cpu;
58#ifdef DEBUG_IRQ_COUNT
59 uint64_t irq_count[32];
60#endif
blueswir1b3a23192007-05-27 16:42:29 +000061 qemu_irq *cpu_irqs[MAX_CPUS];
blueswir1e0353fe2007-04-01 15:55:28 +000062 const uint32_t *intbit_to_level;
blueswir1e3a79bc2008-01-01 20:57:25 +000063 uint32_t cputimer_lbit, cputimer_mbit;
blueswir1b3a23192007-05-27 16:42:29 +000064 uint32_t pil_out[MAX_CPUS];
blueswir1a8f48dc2008-12-02 17:51:19 +000065 struct SLAVIO_CPUINTCTLState *slaves[MAX_CPUS];
bellarde80cfcf2004-12-19 23:18:01 +000066} SLAVIO_INTCTLState;
67
blueswir1a8f48dc2008-12-02 17:51:19 +000068typedef struct SLAVIO_CPUINTCTLState {
69 uint32_t intreg_pending;
70 SLAVIO_INTCTLState *master;
71 uint32_t cpu;
72} SLAVIO_CPUINTCTLState;
73
bellarde80cfcf2004-12-19 23:18:01 +000074#define INTCTL_MAXADDR 0xf
blueswir15aca8c32007-05-26 17:39:43 +000075#define INTCTL_SIZE (INTCTL_MAXADDR + 1)
blueswir1a8f48dc2008-12-02 17:51:19 +000076#define INTCTLM_SIZE 0x14
blueswir180be36b2007-12-28 18:48:39 +000077#define MASTER_IRQ_MASK ~0x0fa2007f
blueswir19a87ce92007-11-17 21:01:04 +000078#define MASTER_DISABLE 0x80000000
blueswir16341fdc2007-12-29 20:09:57 +000079#define CPU_SOFTIRQ_MASK 0xfffe0000
blueswir19a87ce92007-11-17 21:01:04 +000080#define CPU_IRQ_INT15_IN 0x0004000
81#define CPU_IRQ_INT15_MASK 0x80000000
82
blueswir1a8f48dc2008-12-02 17:51:19 +000083static void slavio_check_interrupts(SLAVIO_INTCTLState *s);
bellarde80cfcf2004-12-19 23:18:01 +000084
85// per-cpu interrupt controller
86static uint32_t slavio_intctl_mem_readl(void *opaque, target_phys_addr_t addr)
87{
blueswir1a8f48dc2008-12-02 17:51:19 +000088 SLAVIO_CPUINTCTLState *s = opaque;
blueswir1dd4131b2007-05-27 19:42:35 +000089 uint32_t saddr, ret;
bellarde80cfcf2004-12-19 23:18:01 +000090
blueswir1a8f48dc2008-12-02 17:51:19 +000091 saddr = addr >> 2;
bellarde80cfcf2004-12-19 23:18:01 +000092 switch (saddr) {
93 case 0:
blueswir1a8f48dc2008-12-02 17:51:19 +000094 ret = s->intreg_pending;
blueswir1dd4131b2007-05-27 19:42:35 +000095 break;
bellarde80cfcf2004-12-19 23:18:01 +000096 default:
blueswir1dd4131b2007-05-27 19:42:35 +000097 ret = 0;
98 break;
bellarde80cfcf2004-12-19 23:18:01 +000099 }
blueswir13c4cf532009-03-03 20:11:43 +0000100 DPRINTF("read cpu %d reg 0x" TARGET_FMT_plx " = %x\n", s->cpu, addr, ret);
blueswir1dd4131b2007-05-27 19:42:35 +0000101
102 return ret;
bellarde80cfcf2004-12-19 23:18:01 +0000103}
104
blueswir177f193d2008-05-12 16:13:33 +0000105static void slavio_intctl_mem_writel(void *opaque, target_phys_addr_t addr,
106 uint32_t val)
bellarde80cfcf2004-12-19 23:18:01 +0000107{
blueswir1a8f48dc2008-12-02 17:51:19 +0000108 SLAVIO_CPUINTCTLState *s = opaque;
bellarde80cfcf2004-12-19 23:18:01 +0000109 uint32_t saddr;
bellarde80cfcf2004-12-19 23:18:01 +0000110
blueswir1a8f48dc2008-12-02 17:51:19 +0000111 saddr = addr >> 2;
blueswir13c4cf532009-03-03 20:11:43 +0000112 DPRINTF("write cpu %d reg 0x" TARGET_FMT_plx " = %x\n", s->cpu, addr, val);
bellarde80cfcf2004-12-19 23:18:01 +0000113 switch (saddr) {
114 case 1: // clear pending softints
blueswir19a87ce92007-11-17 21:01:04 +0000115 if (val & CPU_IRQ_INT15_IN)
116 val |= CPU_IRQ_INT15_MASK;
blueswir16341fdc2007-12-29 20:09:57 +0000117 val &= CPU_SOFTIRQ_MASK;
blueswir1a8f48dc2008-12-02 17:51:19 +0000118 s->intreg_pending &= ~val;
119 slavio_check_interrupts(s->master);
120 DPRINTF("Cleared cpu %d irq mask %x, curmask %x\n", s->cpu, val,
121 s->intreg_pending);
blueswir1f930d072007-10-06 11:28:21 +0000122 break;
bellarde80cfcf2004-12-19 23:18:01 +0000123 case 2: // set softint
blueswir16341fdc2007-12-29 20:09:57 +0000124 val &= CPU_SOFTIRQ_MASK;
blueswir1a8f48dc2008-12-02 17:51:19 +0000125 s->intreg_pending |= val;
126 slavio_check_interrupts(s->master);
127 DPRINTF("Set cpu %d irq mask %x, curmask %x\n", s->cpu, val,
128 s->intreg_pending);
blueswir1f930d072007-10-06 11:28:21 +0000129 break;
bellarde80cfcf2004-12-19 23:18:01 +0000130 default:
blueswir1f930d072007-10-06 11:28:21 +0000131 break;
bellarde80cfcf2004-12-19 23:18:01 +0000132 }
133}
134
135static CPUReadMemoryFunc *slavio_intctl_mem_read[3] = {
blueswir17c560452008-01-01 17:06:38 +0000136 NULL,
137 NULL,
bellarde80cfcf2004-12-19 23:18:01 +0000138 slavio_intctl_mem_readl,
139};
140
141static CPUWriteMemoryFunc *slavio_intctl_mem_write[3] = {
blueswir17c560452008-01-01 17:06:38 +0000142 NULL,
143 NULL,
bellarde80cfcf2004-12-19 23:18:01 +0000144 slavio_intctl_mem_writel,
145};
146
147// master system interrupt controller
148static uint32_t slavio_intctlm_mem_readl(void *opaque, target_phys_addr_t addr)
149{
150 SLAVIO_INTCTLState *s = opaque;
blueswir1dd4131b2007-05-27 19:42:35 +0000151 uint32_t saddr, ret;
bellarde80cfcf2004-12-19 23:18:01 +0000152
blueswir1a8f48dc2008-12-02 17:51:19 +0000153 saddr = addr >> 2;
bellarde80cfcf2004-12-19 23:18:01 +0000154 switch (saddr) {
155 case 0:
blueswir19a87ce92007-11-17 21:01:04 +0000156 ret = s->intregm_pending & ~MASTER_DISABLE;
blueswir1dd4131b2007-05-27 19:42:35 +0000157 break;
bellarde80cfcf2004-12-19 23:18:01 +0000158 case 1:
blueswir180be36b2007-12-28 18:48:39 +0000159 ret = s->intregm_disabled & MASTER_IRQ_MASK;
blueswir1dd4131b2007-05-27 19:42:35 +0000160 break;
bellarde80cfcf2004-12-19 23:18:01 +0000161 case 4:
blueswir1dd4131b2007-05-27 19:42:35 +0000162 ret = s->target_cpu;
163 break;
bellarde80cfcf2004-12-19 23:18:01 +0000164 default:
blueswir1dd4131b2007-05-27 19:42:35 +0000165 ret = 0;
166 break;
bellarde80cfcf2004-12-19 23:18:01 +0000167 }
blueswir11569fc22007-08-05 17:47:16 +0000168 DPRINTF("read system reg 0x" TARGET_FMT_plx " = %x\n", addr, ret);
blueswir1dd4131b2007-05-27 19:42:35 +0000169
170 return ret;
bellarde80cfcf2004-12-19 23:18:01 +0000171}
172
blueswir177f193d2008-05-12 16:13:33 +0000173static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr,
174 uint32_t val)
bellarde80cfcf2004-12-19 23:18:01 +0000175{
176 SLAVIO_INTCTLState *s = opaque;
177 uint32_t saddr;
178
blueswir1a8f48dc2008-12-02 17:51:19 +0000179 saddr = addr >> 2;
blueswir11569fc22007-08-05 17:47:16 +0000180 DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
bellarde80cfcf2004-12-19 23:18:01 +0000181 switch (saddr) {
182 case 2: // clear (enable)
blueswir1f930d072007-10-06 11:28:21 +0000183 // Force clear unused bits
blueswir19a87ce92007-11-17 21:01:04 +0000184 val &= MASTER_IRQ_MASK;
blueswir1f930d072007-10-06 11:28:21 +0000185 s->intregm_disabled &= ~val;
blueswir177f193d2008-05-12 16:13:33 +0000186 DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
187 s->intregm_disabled);
blueswir1f930d072007-10-06 11:28:21 +0000188 slavio_check_interrupts(s);
189 break;
bellarde80cfcf2004-12-19 23:18:01 +0000190 case 3: // set (disable, clear pending)
blueswir1f930d072007-10-06 11:28:21 +0000191 // Force clear unused bits
blueswir19a87ce92007-11-17 21:01:04 +0000192 val &= MASTER_IRQ_MASK;
blueswir1f930d072007-10-06 11:28:21 +0000193 s->intregm_disabled |= val;
194 s->intregm_pending &= ~val;
blueswir1327ac2e2007-08-04 10:50:30 +0000195 slavio_check_interrupts(s);
blueswir177f193d2008-05-12 16:13:33 +0000196 DPRINTF("Disabled master irq mask %x, curmask %x\n", val,
197 s->intregm_disabled);
blueswir1f930d072007-10-06 11:28:21 +0000198 break;
bellarde80cfcf2004-12-19 23:18:01 +0000199 case 4:
blueswir1f930d072007-10-06 11:28:21 +0000200 s->target_cpu = val & (MAX_CPUS - 1);
blueswir1327ac2e2007-08-04 10:50:30 +0000201 slavio_check_interrupts(s);
blueswir1f930d072007-10-06 11:28:21 +0000202 DPRINTF("Set master irq cpu %d\n", s->target_cpu);
203 break;
bellarde80cfcf2004-12-19 23:18:01 +0000204 default:
blueswir1f930d072007-10-06 11:28:21 +0000205 break;
bellarde80cfcf2004-12-19 23:18:01 +0000206 }
207}
208
209static CPUReadMemoryFunc *slavio_intctlm_mem_read[3] = {
blueswir17c560452008-01-01 17:06:38 +0000210 NULL,
211 NULL,
bellarde80cfcf2004-12-19 23:18:01 +0000212 slavio_intctlm_mem_readl,
213};
214
215static CPUWriteMemoryFunc *slavio_intctlm_mem_write[3] = {
blueswir17c560452008-01-01 17:06:38 +0000216 NULL,
217 NULL,
bellarde80cfcf2004-12-19 23:18:01 +0000218 slavio_intctlm_mem_writel,
219};
220
aliguori376253e2009-03-05 23:01:23 +0000221void slavio_pic_info(Monitor *mon, void *opaque)
bellarde80cfcf2004-12-19 23:18:01 +0000222{
223 SLAVIO_INTCTLState *s = opaque;
224 int i;
225
226 for (i = 0; i < MAX_CPUS; i++) {
aliguori376253e2009-03-05 23:01:23 +0000227 monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
228 s->slaves[i]->intreg_pending);
bellarde80cfcf2004-12-19 23:18:01 +0000229 }
aliguori376253e2009-03-05 23:01:23 +0000230 monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
231 s->intregm_pending, s->intregm_disabled);
bellarde80cfcf2004-12-19 23:18:01 +0000232}
233
aliguori376253e2009-03-05 23:01:23 +0000234void slavio_irq_info(Monitor *mon, void *opaque)
bellarde80cfcf2004-12-19 23:18:01 +0000235{
236#ifndef DEBUG_IRQ_COUNT
aliguori376253e2009-03-05 23:01:23 +0000237 monitor_printf(mon, "irq statistic code not compiled.\n");
bellarde80cfcf2004-12-19 23:18:01 +0000238#else
239 SLAVIO_INTCTLState *s = opaque;
240 int i;
241 int64_t count;
242
aliguori376253e2009-03-05 23:01:23 +0000243 monitor_printf(mon, "IRQ statistics:\n");
bellarde80cfcf2004-12-19 23:18:01 +0000244 for (i = 0; i < 32; i++) {
245 count = s->irq_count[i];
246 if (count > 0)
aliguori376253e2009-03-05 23:01:23 +0000247 monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
bellarde80cfcf2004-12-19 23:18:01 +0000248 }
249#endif
250}
251
blueswir1a8f48dc2008-12-02 17:51:19 +0000252static void slavio_check_interrupts(SLAVIO_INTCTLState *s)
bellard66321a12005-04-06 20:47:48 +0000253{
blueswir1327ac2e2007-08-04 10:50:30 +0000254 uint32_t pending = s->intregm_pending, pil_pending;
255 unsigned int i, j;
bellard66321a12005-04-06 20:47:48 +0000256
257 pending &= ~s->intregm_disabled;
258
blueswir1b3a23192007-05-27 16:42:29 +0000259 DPRINTF("pending %x disabled %x\n", pending, s->intregm_disabled);
bellardba3c64f2005-12-05 20:31:52 +0000260 for (i = 0; i < MAX_CPUS; i++) {
blueswir1327ac2e2007-08-04 10:50:30 +0000261 pil_pending = 0;
blueswir19a87ce92007-11-17 21:01:04 +0000262 if (pending && !(s->intregm_disabled & MASTER_DISABLE) &&
blueswir1b3a23192007-05-27 16:42:29 +0000263 (i == s->target_cpu)) {
264 for (j = 0; j < 32; j++) {
blueswir1327ac2e2007-08-04 10:50:30 +0000265 if (pending & (1 << j))
266 pil_pending |= 1 << s->intbit_to_level[j];
blueswir1b3a23192007-05-27 16:42:29 +0000267 }
268 }
blueswir1a8f48dc2008-12-02 17:51:19 +0000269 pil_pending |= (s->slaves[i]->intreg_pending & CPU_SOFTIRQ_MASK) >> 16;
blueswir1327ac2e2007-08-04 10:50:30 +0000270
271 for (j = 0; j < MAX_PILS; j++) {
272 if (pil_pending & (1 << j)) {
273 if (!(s->pil_out[i] & (1 << j)))
274 qemu_irq_raise(s->cpu_irqs[i][j]);
275 } else {
276 if (s->pil_out[i] & (1 << j))
277 qemu_irq_lower(s->cpu_irqs[i][j]);
bellardba3c64f2005-12-05 20:31:52 +0000278 }
279 }
blueswir1327ac2e2007-08-04 10:50:30 +0000280 s->pil_out[i] = pil_pending;
bellardba3c64f2005-12-05 20:31:52 +0000281 }
bellard66321a12005-04-06 20:47:48 +0000282}
283
bellarde80cfcf2004-12-19 23:18:01 +0000284/*
285 * "irq" here is the bit number in the system interrupt register to
286 * separate serial and keyboard interrupts sharing a level.
287 */
blueswir1d7edfd22007-05-27 16:37:49 +0000288static void slavio_set_irq(void *opaque, int irq, int level)
bellarde80cfcf2004-12-19 23:18:01 +0000289{
290 SLAVIO_INTCTLState *s = opaque;
blueswir1b3a23192007-05-27 16:42:29 +0000291 uint32_t mask = 1 << irq;
292 uint32_t pil = s->intbit_to_level[irq];
bellarde80cfcf2004-12-19 23:18:01 +0000293
blueswir1b3a23192007-05-27 16:42:29 +0000294 DPRINTF("Set cpu %d irq %d -> pil %d level %d\n", s->target_cpu, irq, pil,
295 level);
296 if (pil > 0) {
297 if (level) {
blueswir1327ac2e2007-08-04 10:50:30 +0000298#ifdef DEBUG_IRQ_COUNT
299 s->irq_count[pil]++;
300#endif
blueswir1b3a23192007-05-27 16:42:29 +0000301 s->intregm_pending |= mask;
blueswir1a8f48dc2008-12-02 17:51:19 +0000302 s->slaves[s->target_cpu]->intreg_pending |= 1 << pil;
blueswir1b3a23192007-05-27 16:42:29 +0000303 } else {
304 s->intregm_pending &= ~mask;
blueswir1a8f48dc2008-12-02 17:51:19 +0000305 s->slaves[s->target_cpu]->intreg_pending &= ~(1 << pil);
blueswir1b3a23192007-05-27 16:42:29 +0000306 }
307 slavio_check_interrupts(s);
bellarde80cfcf2004-12-19 23:18:01 +0000308 }
309}
310
blueswir1d7edfd22007-05-27 16:37:49 +0000311static void slavio_set_timer_irq_cpu(void *opaque, int cpu, int level)
bellardba3c64f2005-12-05 20:31:52 +0000312{
313 SLAVIO_INTCTLState *s = opaque;
314
blueswir1b3a23192007-05-27 16:42:29 +0000315 DPRINTF("Set cpu %d local timer level %d\n", cpu, level);
blueswir1d7edfd22007-05-27 16:37:49 +0000316
blueswir1e3a79bc2008-01-01 20:57:25 +0000317 if (level) {
318 s->intregm_pending |= s->cputimer_mbit;
blueswir1a8f48dc2008-12-02 17:51:19 +0000319 s->slaves[cpu]->intreg_pending |= s->cputimer_lbit;
blueswir1e3a79bc2008-01-01 20:57:25 +0000320 } else {
321 s->intregm_pending &= ~s->cputimer_mbit;
blueswir1a8f48dc2008-12-02 17:51:19 +0000322 s->slaves[cpu]->intreg_pending &= ~s->cputimer_lbit;
blueswir1e3a79bc2008-01-01 20:57:25 +0000323 }
blueswir1d7edfd22007-05-27 16:37:49 +0000324
bellardba3c64f2005-12-05 20:31:52 +0000325 slavio_check_interrupts(s);
326}
327
bellarde80cfcf2004-12-19 23:18:01 +0000328static void slavio_intctl_save(QEMUFile *f, void *opaque)
329{
330 SLAVIO_INTCTLState *s = opaque;
331 int i;
ths3b46e622007-09-17 08:09:54 +0000332
bellarde80cfcf2004-12-19 23:18:01 +0000333 for (i = 0; i < MAX_CPUS; i++) {
blueswir1a8f48dc2008-12-02 17:51:19 +0000334 qemu_put_be32s(f, &s->slaves[i]->intreg_pending);
bellarde80cfcf2004-12-19 23:18:01 +0000335 }
336 qemu_put_be32s(f, &s->intregm_pending);
337 qemu_put_be32s(f, &s->intregm_disabled);
338 qemu_put_be32s(f, &s->target_cpu);
339}
340
341static int slavio_intctl_load(QEMUFile *f, void *opaque, int version_id)
342{
343 SLAVIO_INTCTLState *s = opaque;
344 int i;
345
346 if (version_id != 1)
347 return -EINVAL;
348
349 for (i = 0; i < MAX_CPUS; i++) {
blueswir1a8f48dc2008-12-02 17:51:19 +0000350 qemu_get_be32s(f, &s->slaves[i]->intreg_pending);
bellarde80cfcf2004-12-19 23:18:01 +0000351 }
352 qemu_get_be32s(f, &s->intregm_pending);
353 qemu_get_be32s(f, &s->intregm_disabled);
354 qemu_get_be32s(f, &s->target_cpu);
blueswir1327ac2e2007-08-04 10:50:30 +0000355 slavio_check_interrupts(s);
bellarde80cfcf2004-12-19 23:18:01 +0000356 return 0;
357}
358
359static void slavio_intctl_reset(void *opaque)
360{
361 SLAVIO_INTCTLState *s = opaque;
362 int i;
363
364 for (i = 0; i < MAX_CPUS; i++) {
blueswir1a8f48dc2008-12-02 17:51:19 +0000365 s->slaves[i]->intreg_pending = 0;
bellarde80cfcf2004-12-19 23:18:01 +0000366 }
blueswir19a87ce92007-11-17 21:01:04 +0000367 s->intregm_disabled = ~MASTER_IRQ_MASK;
bellarde80cfcf2004-12-19 23:18:01 +0000368 s->intregm_pending = 0;
369 s->target_cpu = 0;
blueswir1327ac2e2007-08-04 10:50:30 +0000370 slavio_check_interrupts(s);
bellarde80cfcf2004-12-19 23:18:01 +0000371}
372
blueswir15dcb6b92007-05-19 12:58:30 +0000373void *slavio_intctl_init(target_phys_addr_t addr, target_phys_addr_t addrg,
pbrookd537cf62007-04-07 18:14:41 +0000374 const uint32_t *intbit_to_level,
blueswir1d7edfd22007-05-27 16:37:49 +0000375 qemu_irq **irq, qemu_irq **cpu_irq,
blueswir1b3a23192007-05-27 16:42:29 +0000376 qemu_irq **parent_irq, unsigned int cputimer)
bellarde80cfcf2004-12-19 23:18:01 +0000377{
378 int slavio_intctl_io_memory, slavio_intctlm_io_memory, i;
379 SLAVIO_INTCTLState *s;
blueswir1a8f48dc2008-12-02 17:51:19 +0000380 SLAVIO_CPUINTCTLState *slave;
bellarde80cfcf2004-12-19 23:18:01 +0000381
382 s = qemu_mallocz(sizeof(SLAVIO_INTCTLState));
bellarde80cfcf2004-12-19 23:18:01 +0000383
blueswir1e0353fe2007-04-01 15:55:28 +0000384 s->intbit_to_level = intbit_to_level;
bellarde80cfcf2004-12-19 23:18:01 +0000385 for (i = 0; i < MAX_CPUS; i++) {
blueswir1a8f48dc2008-12-02 17:51:19 +0000386 slave = qemu_mallocz(sizeof(SLAVIO_CPUINTCTLState));
blueswir1a8f48dc2008-12-02 17:51:19 +0000387
388 slave->cpu = i;
389 slave->master = s;
390
blueswir177f193d2008-05-12 16:13:33 +0000391 slavio_intctl_io_memory = cpu_register_io_memory(0,
392 slavio_intctl_mem_read,
393 slavio_intctl_mem_write,
blueswir1a8f48dc2008-12-02 17:51:19 +0000394 slave);
395 cpu_register_physical_memory(addr + i * TARGET_PAGE_SIZE, INTCTL_SIZE,
396 slavio_intctl_io_memory);
397
398 s->slaves[i] = slave;
blueswir1b3a23192007-05-27 16:42:29 +0000399 s->cpu_irqs[i] = parent_irq[i];
bellarde80cfcf2004-12-19 23:18:01 +0000400 }
401
blueswir177f193d2008-05-12 16:13:33 +0000402 slavio_intctlm_io_memory = cpu_register_io_memory(0,
403 slavio_intctlm_mem_read,
404 slavio_intctlm_mem_write,
405 s);
blueswir15aca8c32007-05-26 17:39:43 +0000406 cpu_register_physical_memory(addrg, INTCTLM_SIZE, slavio_intctlm_io_memory);
bellarde80cfcf2004-12-19 23:18:01 +0000407
blueswir177f193d2008-05-12 16:13:33 +0000408 register_savevm("slavio_intctl", addr, 1, slavio_intctl_save,
409 slavio_intctl_load, s);
bellarde80cfcf2004-12-19 23:18:01 +0000410 qemu_register_reset(slavio_intctl_reset, s);
pbrookd537cf62007-04-07 18:14:41 +0000411 *irq = qemu_allocate_irqs(slavio_set_irq, s, 32);
blueswir1d7edfd22007-05-27 16:37:49 +0000412
413 *cpu_irq = qemu_allocate_irqs(slavio_set_timer_irq_cpu, s, MAX_CPUS);
blueswir1e3a79bc2008-01-01 20:57:25 +0000414 s->cputimer_mbit = 1 << cputimer;
415 s->cputimer_lbit = 1 << intbit_to_level[cputimer];
bellarde80cfcf2004-12-19 23:18:01 +0000416 slavio_intctl_reset(s);
417 return s;
418}