2004-12-20 02:18:01 +03:00
|
|
|
/*
|
|
|
|
* QEMU Sparc SLAVIO interrupt controller emulation
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2005-04-07 00:47:48 +04:00
|
|
|
* Copyright (c) 2003-2005 Fabrice Bellard
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-12-20 02:18:01 +03:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2007-11-17 20:14:51 +03:00
|
|
|
#include "hw.h"
|
|
|
|
#include "sun4m.h"
|
2009-03-06 02:01:23 +03:00
|
|
|
#include "monitor.h"
|
2007-11-17 20:14:51 +03:00
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
//#define DEBUG_IRQ_COUNT
|
2005-04-07 00:47:48 +04:00
|
|
|
//#define DEBUG_IRQ
|
|
|
|
|
|
|
|
#ifdef DEBUG_IRQ
|
2009-05-13 21:53:17 +04:00
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do { printf("IRQ: " fmt , ## __VA_ARGS__); } while (0)
|
2005-04-07 00:47:48 +04:00
|
|
|
#else
|
2009-05-13 21:53:17 +04:00
|
|
|
#define DPRINTF(fmt, ...)
|
2005-04-07 00:47:48 +04:00
|
|
|
#endif
|
2004-12-20 02:18:01 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Registers of interrupt controller in sun4m.
|
|
|
|
*
|
|
|
|
* This is the interrupt controller part of chip STP2001 (Slave I/O), also
|
|
|
|
* produced as NCR89C105. See
|
|
|
|
* http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
|
|
|
|
*
|
|
|
|
* There is a system master controller and one for each cpu.
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2004-12-20 02:18:01 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_CPUS 16
|
2007-05-27 20:42:29 +04:00
|
|
|
#define MAX_PILS 16
|
2004-12-20 02:18:01 +03:00
|
|
|
|
2008-12-02 20:51:19 +03:00
|
|
|
struct SLAVIO_CPUINTCTLState;
|
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
typedef struct SLAVIO_INTCTLState {
|
|
|
|
uint32_t intregm_pending;
|
|
|
|
uint32_t intregm_disabled;
|
|
|
|
uint32_t target_cpu;
|
|
|
|
#ifdef DEBUG_IRQ_COUNT
|
|
|
|
uint64_t irq_count[32];
|
|
|
|
#endif
|
2007-05-27 20:42:29 +04:00
|
|
|
qemu_irq *cpu_irqs[MAX_CPUS];
|
2007-04-01 19:55:28 +04:00
|
|
|
const uint32_t *intbit_to_level;
|
2008-01-01 23:57:25 +03:00
|
|
|
uint32_t cputimer_lbit, cputimer_mbit;
|
2007-05-27 20:42:29 +04:00
|
|
|
uint32_t pil_out[MAX_CPUS];
|
2008-12-02 20:51:19 +03:00
|
|
|
struct SLAVIO_CPUINTCTLState *slaves[MAX_CPUS];
|
2004-12-20 02:18:01 +03:00
|
|
|
} SLAVIO_INTCTLState;
|
|
|
|
|
2008-12-02 20:51:19 +03:00
|
|
|
typedef struct SLAVIO_CPUINTCTLState {
|
|
|
|
uint32_t intreg_pending;
|
|
|
|
SLAVIO_INTCTLState *master;
|
|
|
|
uint32_t cpu;
|
|
|
|
} SLAVIO_CPUINTCTLState;
|
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
#define INTCTL_MAXADDR 0xf
|
2007-05-26 21:39:43 +04:00
|
|
|
#define INTCTL_SIZE (INTCTL_MAXADDR + 1)
|
2008-12-02 20:51:19 +03:00
|
|
|
#define INTCTLM_SIZE 0x14
|
2007-12-28 21:48:39 +03:00
|
|
|
#define MASTER_IRQ_MASK ~0x0fa2007f
|
2007-11-18 00:01:04 +03:00
|
|
|
#define MASTER_DISABLE 0x80000000
|
2007-12-29 23:09:57 +03:00
|
|
|
#define CPU_SOFTIRQ_MASK 0xfffe0000
|
2007-11-18 00:01:04 +03:00
|
|
|
#define CPU_IRQ_INT15_IN 0x0004000
|
|
|
|
#define CPU_IRQ_INT15_MASK 0x80000000
|
|
|
|
|
2008-12-02 20:51:19 +03:00
|
|
|
static void slavio_check_interrupts(SLAVIO_INTCTLState *s);
|
2004-12-20 02:18:01 +03:00
|
|
|
|
|
|
|
// per-cpu interrupt controller
|
|
|
|
static uint32_t slavio_intctl_mem_readl(void *opaque, target_phys_addr_t addr)
|
|
|
|
{
|
2008-12-02 20:51:19 +03:00
|
|
|
SLAVIO_CPUINTCTLState *s = opaque;
|
2007-05-27 23:42:35 +04:00
|
|
|
uint32_t saddr, ret;
|
2004-12-20 02:18:01 +03:00
|
|
|
|
2008-12-02 20:51:19 +03:00
|
|
|
saddr = addr >> 2;
|
2004-12-20 02:18:01 +03:00
|
|
|
switch (saddr) {
|
|
|
|
case 0:
|
2008-12-02 20:51:19 +03:00
|
|
|
ret = s->intreg_pending;
|
2007-05-27 23:42:35 +04:00
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
default:
|
2007-05-27 23:42:35 +04:00
|
|
|
ret = 0;
|
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
2009-03-03 23:11:43 +03:00
|
|
|
DPRINTF("read cpu %d reg 0x" TARGET_FMT_plx " = %x\n", s->cpu, addr, ret);
|
2007-05-27 23:42:35 +04:00
|
|
|
|
|
|
|
return ret;
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
|
2008-05-12 20:13:33 +04:00
|
|
|
static void slavio_intctl_mem_writel(void *opaque, target_phys_addr_t addr,
|
|
|
|
uint32_t val)
|
2004-12-20 02:18:01 +03:00
|
|
|
{
|
2008-12-02 20:51:19 +03:00
|
|
|
SLAVIO_CPUINTCTLState *s = opaque;
|
2004-12-20 02:18:01 +03:00
|
|
|
uint32_t saddr;
|
|
|
|
|
2008-12-02 20:51:19 +03:00
|
|
|
saddr = addr >> 2;
|
2009-03-03 23:11:43 +03:00
|
|
|
DPRINTF("write cpu %d reg 0x" TARGET_FMT_plx " = %x\n", s->cpu, addr, val);
|
2004-12-20 02:18:01 +03:00
|
|
|
switch (saddr) {
|
|
|
|
case 1: // clear pending softints
|
2007-11-18 00:01:04 +03:00
|
|
|
if (val & CPU_IRQ_INT15_IN)
|
|
|
|
val |= CPU_IRQ_INT15_MASK;
|
2007-12-29 23:09:57 +03:00
|
|
|
val &= CPU_SOFTIRQ_MASK;
|
2008-12-02 20:51:19 +03:00
|
|
|
s->intreg_pending &= ~val;
|
|
|
|
slavio_check_interrupts(s->master);
|
|
|
|
DPRINTF("Cleared cpu %d irq mask %x, curmask %x\n", s->cpu, val,
|
|
|
|
s->intreg_pending);
|
2007-10-06 15:28:21 +04:00
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
case 2: // set softint
|
2007-12-29 23:09:57 +03:00
|
|
|
val &= CPU_SOFTIRQ_MASK;
|
2008-12-02 20:51:19 +03:00
|
|
|
s->intreg_pending |= val;
|
|
|
|
slavio_check_interrupts(s->master);
|
|
|
|
DPRINTF("Set cpu %d irq mask %x, curmask %x\n", s->cpu, val,
|
|
|
|
s->intreg_pending);
|
2007-10-06 15:28:21 +04:00
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
default:
|
2007-10-06 15:28:21 +04:00
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static CPUReadMemoryFunc *slavio_intctl_mem_read[3] = {
|
2008-01-01 20:06:38 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-12-20 02:18:01 +03:00
|
|
|
slavio_intctl_mem_readl,
|
|
|
|
};
|
|
|
|
|
|
|
|
static CPUWriteMemoryFunc *slavio_intctl_mem_write[3] = {
|
2008-01-01 20:06:38 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-12-20 02:18:01 +03:00
|
|
|
slavio_intctl_mem_writel,
|
|
|
|
};
|
|
|
|
|
|
|
|
// master system interrupt controller
|
|
|
|
static uint32_t slavio_intctlm_mem_readl(void *opaque, target_phys_addr_t addr)
|
|
|
|
{
|
|
|
|
SLAVIO_INTCTLState *s = opaque;
|
2007-05-27 23:42:35 +04:00
|
|
|
uint32_t saddr, ret;
|
2004-12-20 02:18:01 +03:00
|
|
|
|
2008-12-02 20:51:19 +03:00
|
|
|
saddr = addr >> 2;
|
2004-12-20 02:18:01 +03:00
|
|
|
switch (saddr) {
|
|
|
|
case 0:
|
2007-11-18 00:01:04 +03:00
|
|
|
ret = s->intregm_pending & ~MASTER_DISABLE;
|
2007-05-27 23:42:35 +04:00
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
case 1:
|
2007-12-28 21:48:39 +03:00
|
|
|
ret = s->intregm_disabled & MASTER_IRQ_MASK;
|
2007-05-27 23:42:35 +04:00
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
case 4:
|
2007-05-27 23:42:35 +04:00
|
|
|
ret = s->target_cpu;
|
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
default:
|
2007-05-27 23:42:35 +04:00
|
|
|
ret = 0;
|
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
2007-08-05 21:47:16 +04:00
|
|
|
DPRINTF("read system reg 0x" TARGET_FMT_plx " = %x\n", addr, ret);
|
2007-05-27 23:42:35 +04:00
|
|
|
|
|
|
|
return ret;
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
|
2008-05-12 20:13:33 +04:00
|
|
|
static void slavio_intctlm_mem_writel(void *opaque, target_phys_addr_t addr,
|
|
|
|
uint32_t val)
|
2004-12-20 02:18:01 +03:00
|
|
|
{
|
|
|
|
SLAVIO_INTCTLState *s = opaque;
|
|
|
|
uint32_t saddr;
|
|
|
|
|
2008-12-02 20:51:19 +03:00
|
|
|
saddr = addr >> 2;
|
2007-08-05 21:47:16 +04:00
|
|
|
DPRINTF("write system reg 0x" TARGET_FMT_plx " = %x\n", addr, val);
|
2004-12-20 02:18:01 +03:00
|
|
|
switch (saddr) {
|
|
|
|
case 2: // clear (enable)
|
2007-10-06 15:28:21 +04:00
|
|
|
// Force clear unused bits
|
2007-11-18 00:01:04 +03:00
|
|
|
val &= MASTER_IRQ_MASK;
|
2007-10-06 15:28:21 +04:00
|
|
|
s->intregm_disabled &= ~val;
|
2008-05-12 20:13:33 +04:00
|
|
|
DPRINTF("Enabled master irq mask %x, curmask %x\n", val,
|
|
|
|
s->intregm_disabled);
|
2007-10-06 15:28:21 +04:00
|
|
|
slavio_check_interrupts(s);
|
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
case 3: // set (disable, clear pending)
|
2007-10-06 15:28:21 +04:00
|
|
|
// Force clear unused bits
|
2007-11-18 00:01:04 +03:00
|
|
|
val &= MASTER_IRQ_MASK;
|
2007-10-06 15:28:21 +04:00
|
|
|
s->intregm_disabled |= val;
|
|
|
|
s->intregm_pending &= ~val;
|
2007-08-04 14:50:30 +04:00
|
|
|
slavio_check_interrupts(s);
|
2008-05-12 20:13:33 +04:00
|
|
|
DPRINTF("Disabled master irq mask %x, curmask %x\n", val,
|
|
|
|
s->intregm_disabled);
|
2007-10-06 15:28:21 +04:00
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
case 4:
|
2007-10-06 15:28:21 +04:00
|
|
|
s->target_cpu = val & (MAX_CPUS - 1);
|
2007-08-04 14:50:30 +04:00
|
|
|
slavio_check_interrupts(s);
|
2007-10-06 15:28:21 +04:00
|
|
|
DPRINTF("Set master irq cpu %d\n", s->target_cpu);
|
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
default:
|
2007-10-06 15:28:21 +04:00
|
|
|
break;
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static CPUReadMemoryFunc *slavio_intctlm_mem_read[3] = {
|
2008-01-01 20:06:38 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-12-20 02:18:01 +03:00
|
|
|
slavio_intctlm_mem_readl,
|
|
|
|
};
|
|
|
|
|
|
|
|
static CPUWriteMemoryFunc *slavio_intctlm_mem_write[3] = {
|
2008-01-01 20:06:38 +03:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2004-12-20 02:18:01 +03:00
|
|
|
slavio_intctlm_mem_writel,
|
|
|
|
};
|
|
|
|
|
2009-03-06 02:01:23 +03:00
|
|
|
void slavio_pic_info(Monitor *mon, void *opaque)
|
2004-12-20 02:18:01 +03:00
|
|
|
{
|
|
|
|
SLAVIO_INTCTLState *s = opaque;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CPUS; i++) {
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "per-cpu %d: pending 0x%08x\n", i,
|
|
|
|
s->slaves[i]->intreg_pending);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "master: pending 0x%08x, disabled 0x%08x\n",
|
|
|
|
s->intregm_pending, s->intregm_disabled);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
|
2009-03-06 02:01:23 +03:00
|
|
|
void slavio_irq_info(Monitor *mon, void *opaque)
|
2004-12-20 02:18:01 +03:00
|
|
|
{
|
|
|
|
#ifndef DEBUG_IRQ_COUNT
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "irq statistic code not compiled.\n");
|
2004-12-20 02:18:01 +03:00
|
|
|
#else
|
|
|
|
SLAVIO_INTCTLState *s = opaque;
|
|
|
|
int i;
|
|
|
|
int64_t count;
|
|
|
|
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "IRQ statistics:\n");
|
2004-12-20 02:18:01 +03:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
count = s->irq_count[i];
|
|
|
|
if (count > 0)
|
2009-03-06 02:01:23 +03:00
|
|
|
monitor_printf(mon, "%2d: %" PRId64 "\n", i, count);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-12-02 20:51:19 +03:00
|
|
|
static void slavio_check_interrupts(SLAVIO_INTCTLState *s)
|
2005-04-07 00:47:48 +04:00
|
|
|
{
|
2007-08-04 14:50:30 +04:00
|
|
|
uint32_t pending = s->intregm_pending, pil_pending;
|
|
|
|
unsigned int i, j;
|
2005-04-07 00:47:48 +04:00
|
|
|
|
|
|
|
pending &= ~s->intregm_disabled;
|
|
|
|
|
2007-05-27 20:42:29 +04:00
|
|
|
DPRINTF("pending %x disabled %x\n", pending, s->intregm_disabled);
|
2005-12-05 23:31:52 +03:00
|
|
|
for (i = 0; i < MAX_CPUS; i++) {
|
2007-08-04 14:50:30 +04:00
|
|
|
pil_pending = 0;
|
2007-11-18 00:01:04 +03:00
|
|
|
if (pending && !(s->intregm_disabled & MASTER_DISABLE) &&
|
2007-05-27 20:42:29 +04:00
|
|
|
(i == s->target_cpu)) {
|
|
|
|
for (j = 0; j < 32; j++) {
|
2007-08-04 14:50:30 +04:00
|
|
|
if (pending & (1 << j))
|
|
|
|
pil_pending |= 1 << s->intbit_to_level[j];
|
2007-05-27 20:42:29 +04:00
|
|
|
}
|
|
|
|
}
|
2008-12-02 20:51:19 +03:00
|
|
|
pil_pending |= (s->slaves[i]->intreg_pending & CPU_SOFTIRQ_MASK) >> 16;
|
2007-08-04 14:50:30 +04:00
|
|
|
|
|
|
|
for (j = 0; j < MAX_PILS; j++) {
|
|
|
|
if (pil_pending & (1 << j)) {
|
|
|
|
if (!(s->pil_out[i] & (1 << j)))
|
|
|
|
qemu_irq_raise(s->cpu_irqs[i][j]);
|
|
|
|
} else {
|
|
|
|
if (s->pil_out[i] & (1 << j))
|
|
|
|
qemu_irq_lower(s->cpu_irqs[i][j]);
|
2005-12-05 23:31:52 +03:00
|
|
|
}
|
|
|
|
}
|
2007-08-04 14:50:30 +04:00
|
|
|
s->pil_out[i] = pil_pending;
|
2005-12-05 23:31:52 +03:00
|
|
|
}
|
2005-04-07 00:47:48 +04:00
|
|
|
}
|
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
/*
|
|
|
|
* "irq" here is the bit number in the system interrupt register to
|
|
|
|
* separate serial and keyboard interrupts sharing a level.
|
|
|
|
*/
|
2007-05-27 20:37:49 +04:00
|
|
|
static void slavio_set_irq(void *opaque, int irq, int level)
|
2004-12-20 02:18:01 +03:00
|
|
|
{
|
|
|
|
SLAVIO_INTCTLState *s = opaque;
|
2007-05-27 20:42:29 +04:00
|
|
|
uint32_t mask = 1 << irq;
|
|
|
|
uint32_t pil = s->intbit_to_level[irq];
|
|
|
|
|
|
|
|
DPRINTF("Set cpu %d irq %d -> pil %d level %d\n", s->target_cpu, irq, pil,
|
|
|
|
level);
|
|
|
|
if (pil > 0) {
|
|
|
|
if (level) {
|
2007-08-04 14:50:30 +04:00
|
|
|
#ifdef DEBUG_IRQ_COUNT
|
|
|
|
s->irq_count[pil]++;
|
|
|
|
#endif
|
2007-05-27 20:42:29 +04:00
|
|
|
s->intregm_pending |= mask;
|
2008-12-02 20:51:19 +03:00
|
|
|
s->slaves[s->target_cpu]->intreg_pending |= 1 << pil;
|
2007-05-27 20:42:29 +04:00
|
|
|
} else {
|
|
|
|
s->intregm_pending &= ~mask;
|
2008-12-02 20:51:19 +03:00
|
|
|
s->slaves[s->target_cpu]->intreg_pending &= ~(1 << pil);
|
2007-05-27 20:42:29 +04:00
|
|
|
}
|
|
|
|
slavio_check_interrupts(s);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-27 20:37:49 +04:00
|
|
|
static void slavio_set_timer_irq_cpu(void *opaque, int cpu, int level)
|
2005-12-05 23:31:52 +03:00
|
|
|
{
|
|
|
|
SLAVIO_INTCTLState *s = opaque;
|
|
|
|
|
2007-05-27 20:42:29 +04:00
|
|
|
DPRINTF("Set cpu %d local timer level %d\n", cpu, level);
|
2007-05-27 20:37:49 +04:00
|
|
|
|
2008-01-01 23:57:25 +03:00
|
|
|
if (level) {
|
|
|
|
s->intregm_pending |= s->cputimer_mbit;
|
2008-12-02 20:51:19 +03:00
|
|
|
s->slaves[cpu]->intreg_pending |= s->cputimer_lbit;
|
2008-01-01 23:57:25 +03:00
|
|
|
} else {
|
|
|
|
s->intregm_pending &= ~s->cputimer_mbit;
|
2008-12-02 20:51:19 +03:00
|
|
|
s->slaves[cpu]->intreg_pending &= ~s->cputimer_lbit;
|
2008-01-01 23:57:25 +03:00
|
|
|
}
|
2007-05-27 20:37:49 +04:00
|
|
|
|
2005-12-05 23:31:52 +03:00
|
|
|
slavio_check_interrupts(s);
|
|
|
|
}
|
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
static void slavio_intctl_save(QEMUFile *f, void *opaque)
|
|
|
|
{
|
|
|
|
SLAVIO_INTCTLState *s = opaque;
|
|
|
|
int i;
|
2007-09-17 12:09:54 +04:00
|
|
|
|
2004-12-20 02:18:01 +03:00
|
|
|
for (i = 0; i < MAX_CPUS; i++) {
|
2008-12-02 20:51:19 +03:00
|
|
|
qemu_put_be32s(f, &s->slaves[i]->intreg_pending);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
qemu_put_be32s(f, &s->intregm_pending);
|
|
|
|
qemu_put_be32s(f, &s->intregm_disabled);
|
|
|
|
qemu_put_be32s(f, &s->target_cpu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int slavio_intctl_load(QEMUFile *f, void *opaque, int version_id)
|
|
|
|
{
|
|
|
|
SLAVIO_INTCTLState *s = opaque;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (version_id != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CPUS; i++) {
|
2008-12-02 20:51:19 +03:00
|
|
|
qemu_get_be32s(f, &s->slaves[i]->intreg_pending);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
qemu_get_be32s(f, &s->intregm_pending);
|
|
|
|
qemu_get_be32s(f, &s->intregm_disabled);
|
|
|
|
qemu_get_be32s(f, &s->target_cpu);
|
2007-08-04 14:50:30 +04:00
|
|
|
slavio_check_interrupts(s);
|
2004-12-20 02:18:01 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void slavio_intctl_reset(void *opaque)
|
|
|
|
{
|
|
|
|
SLAVIO_INTCTLState *s = opaque;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_CPUS; i++) {
|
2008-12-02 20:51:19 +03:00
|
|
|
s->slaves[i]->intreg_pending = 0;
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
2007-11-18 00:01:04 +03:00
|
|
|
s->intregm_disabled = ~MASTER_IRQ_MASK;
|
2004-12-20 02:18:01 +03:00
|
|
|
s->intregm_pending = 0;
|
|
|
|
s->target_cpu = 0;
|
2007-08-04 14:50:30 +04:00
|
|
|
slavio_check_interrupts(s);
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
|
2007-05-19 16:58:30 +04:00
|
|
|
void *slavio_intctl_init(target_phys_addr_t addr, target_phys_addr_t addrg,
|
2007-04-07 22:14:41 +04:00
|
|
|
const uint32_t *intbit_to_level,
|
2007-05-27 20:37:49 +04:00
|
|
|
qemu_irq **irq, qemu_irq **cpu_irq,
|
2007-05-27 20:42:29 +04:00
|
|
|
qemu_irq **parent_irq, unsigned int cputimer)
|
2004-12-20 02:18:01 +03:00
|
|
|
{
|
|
|
|
int slavio_intctl_io_memory, slavio_intctlm_io_memory, i;
|
|
|
|
SLAVIO_INTCTLState *s;
|
2008-12-02 20:51:19 +03:00
|
|
|
SLAVIO_CPUINTCTLState *slave;
|
2004-12-20 02:18:01 +03:00
|
|
|
|
|
|
|
s = qemu_mallocz(sizeof(SLAVIO_INTCTLState));
|
|
|
|
|
2007-04-01 19:55:28 +04:00
|
|
|
s->intbit_to_level = intbit_to_level;
|
2004-12-20 02:18:01 +03:00
|
|
|
for (i = 0; i < MAX_CPUS; i++) {
|
2008-12-02 20:51:19 +03:00
|
|
|
slave = qemu_mallocz(sizeof(SLAVIO_CPUINTCTLState));
|
|
|
|
|
|
|
|
slave->cpu = i;
|
|
|
|
slave->master = s;
|
|
|
|
|
2008-05-12 20:13:33 +04:00
|
|
|
slavio_intctl_io_memory = cpu_register_io_memory(0,
|
|
|
|
slavio_intctl_mem_read,
|
|
|
|
slavio_intctl_mem_write,
|
2008-12-02 20:51:19 +03:00
|
|
|
slave);
|
|
|
|
cpu_register_physical_memory(addr + i * TARGET_PAGE_SIZE, INTCTL_SIZE,
|
|
|
|
slavio_intctl_io_memory);
|
|
|
|
|
|
|
|
s->slaves[i] = slave;
|
2007-05-27 20:42:29 +04:00
|
|
|
s->cpu_irqs[i] = parent_irq[i];
|
2004-12-20 02:18:01 +03:00
|
|
|
}
|
|
|
|
|
2008-05-12 20:13:33 +04:00
|
|
|
slavio_intctlm_io_memory = cpu_register_io_memory(0,
|
|
|
|
slavio_intctlm_mem_read,
|
|
|
|
slavio_intctlm_mem_write,
|
|
|
|
s);
|
2007-05-26 21:39:43 +04:00
|
|
|
cpu_register_physical_memory(addrg, INTCTLM_SIZE, slavio_intctlm_io_memory);
|
2004-12-20 02:18:01 +03:00
|
|
|
|
2008-05-12 20:13:33 +04:00
|
|
|
register_savevm("slavio_intctl", addr, 1, slavio_intctl_save,
|
|
|
|
slavio_intctl_load, s);
|
2004-12-20 02:18:01 +03:00
|
|
|
qemu_register_reset(slavio_intctl_reset, s);
|
2007-04-07 22:14:41 +04:00
|
|
|
*irq = qemu_allocate_irqs(slavio_set_irq, s, 32);
|
2007-05-27 20:37:49 +04:00
|
|
|
|
|
|
|
*cpu_irq = qemu_allocate_irqs(slavio_set_timer_irq_cpu, s, MAX_CPUS);
|
2008-01-01 23:57:25 +03:00
|
|
|
s->cputimer_mbit = 1 << cputimer;
|
|
|
|
s->cputimer_lbit = 1 << intbit_to_level[cputimer];
|
2004-12-20 02:18:01 +03:00
|
|
|
slavio_intctl_reset(s);
|
|
|
|
return s;
|
|
|
|
}
|