2007-12-28 20:59:23 +00:00
|
|
|
/*
|
|
|
|
* QEMU Sparc Sun4c interrupt controller emulation
|
|
|
|
*
|
|
|
|
* Based on slavio_intctl, copyright (c) 2003-2005 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2009-07-21 19:57:32 +00:00
|
|
|
|
2013-02-04 14:40:22 +00:00
|
|
|
#include "hw/hw.h"
|
|
|
|
#include "hw/sun4m.h"
|
2012-12-17 17:19:49 +00:00
|
|
|
#include "monitor/monitor.h"
|
2013-02-04 14:40:22 +00:00
|
|
|
#include "hw/sysbus.h"
|
2009-07-21 19:57:32 +00:00
|
|
|
|
2007-12-28 20:59:23 +00:00
|
|
|
//#define DEBUG_IRQ_COUNT
|
|
|
|
//#define DEBUG_IRQ
|
|
|
|
|
|
|
|
#ifdef DEBUG_IRQ
|
2009-05-13 17:53:17 +00:00
|
|
|
#define DPRINTF(fmt, ...) \
|
|
|
|
do { printf("IRQ: " fmt , ## __VA_ARGS__); } while (0)
|
2007-12-28 20:59:23 +00:00
|
|
|
#else
|
2009-05-13 17:53:17 +00:00
|
|
|
#define DPRINTF(fmt, ...)
|
2007-12-28 20:59:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Registers of interrupt controller in sun4c.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_PILS 16
|
|
|
|
|
|
|
|
typedef struct Sun4c_INTCTLState {
|
2009-07-21 19:57:32 +00:00
|
|
|
SysBusDevice busdev;
|
2011-11-15 09:56:16 +00:00
|
|
|
MemoryRegion iomem;
|
2007-12-28 20:59:23 +00:00
|
|
|
#ifdef DEBUG_IRQ_COUNT
|
|
|
|
uint64_t irq_count;
|
|
|
|
#endif
|
2009-07-21 19:57:32 +00:00
|
|
|
qemu_irq cpu_irqs[MAX_PILS];
|
2007-12-28 20:59:23 +00:00
|
|
|
const uint32_t *intbit_to_level;
|
|
|
|
uint32_t pil_out;
|
|
|
|
uint8_t reg;
|
|
|
|
uint8_t pending;
|
|
|
|
} Sun4c_INTCTLState;
|
|
|
|
|
2008-12-02 17:47:02 +00:00
|
|
|
#define INTCTL_SIZE 1
|
2007-12-28 20:59:23 +00:00
|
|
|
|
|
|
|
static void sun4c_check_interrupts(void *opaque);
|
|
|
|
|
2012-10-23 10:30:10 +00:00
|
|
|
static uint64_t sun4c_intctl_mem_read(void *opaque, hwaddr addr,
|
2011-11-15 09:56:16 +00:00
|
|
|
unsigned size)
|
2007-12-28 20:59:23 +00:00
|
|
|
{
|
|
|
|
Sun4c_INTCTLState *s = opaque;
|
|
|
|
uint32_t ret;
|
|
|
|
|
|
|
|
ret = s->reg;
|
|
|
|
DPRINTF("read reg 0x" TARGET_FMT_plx " = %x\n", addr, ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-23 10:30:10 +00:00
|
|
|
static void sun4c_intctl_mem_write(void *opaque, hwaddr addr,
|
2011-11-15 09:56:16 +00:00
|
|
|
uint64_t val, unsigned size)
|
2007-12-28 20:59:23 +00:00
|
|
|
{
|
|
|
|
Sun4c_INTCTLState *s = opaque;
|
|
|
|
|
2011-11-15 09:56:16 +00:00
|
|
|
DPRINTF("write reg 0x" TARGET_FMT_plx " = %x\n", addr, (unsigned)val);
|
2007-12-28 20:59:23 +00:00
|
|
|
val &= 0xbf;
|
|
|
|
s->reg = val;
|
|
|
|
sun4c_check_interrupts(s);
|
|
|
|
}
|
|
|
|
|
2011-11-15 09:56:16 +00:00
|
|
|
static const MemoryRegionOps sun4c_intctl_mem_ops = {
|
|
|
|
.read = sun4c_intctl_mem_read,
|
|
|
|
.write = sun4c_intctl_mem_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 1,
|
|
|
|
},
|
2007-12-28 20:59:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const uint32_t intbit_to_level[] = { 0, 1, 4, 6, 8, 10, 0, 14, };
|
|
|
|
|
|
|
|
static void sun4c_check_interrupts(void *opaque)
|
|
|
|
{
|
|
|
|
Sun4c_INTCTLState *s = opaque;
|
|
|
|
uint32_t pil_pending;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
pil_pending = 0;
|
|
|
|
if (s->pending && !(s->reg & 0x80000000)) {
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
if (s->pending & (1 << i))
|
|
|
|
pil_pending |= 1 << intbit_to_level[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PILS; i++) {
|
|
|
|
if (pil_pending & (1 << i)) {
|
|
|
|
if (!(s->pil_out & (1 << i)))
|
|
|
|
qemu_irq_raise(s->cpu_irqs[i]);
|
|
|
|
} else {
|
|
|
|
if (s->pil_out & (1 << i))
|
|
|
|
qemu_irq_lower(s->cpu_irqs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->pil_out = pil_pending;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "irq" here is the bit number in the system interrupt register
|
|
|
|
*/
|
|
|
|
static void sun4c_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
Sun4c_INTCTLState *s = opaque;
|
|
|
|
uint32_t mask = 1 << irq;
|
|
|
|
uint32_t pil = intbit_to_level[irq];
|
|
|
|
|
|
|
|
DPRINTF("Set irq %d -> pil %d level %d\n", irq, pil,
|
|
|
|
level);
|
|
|
|
if (pil > 0) {
|
|
|
|
if (level) {
|
|
|
|
#ifdef DEBUG_IRQ_COUNT
|
2009-07-20 17:19:25 +00:00
|
|
|
s->irq_count++;
|
2007-12-28 20:59:23 +00:00
|
|
|
#endif
|
|
|
|
s->pending |= mask;
|
|
|
|
} else {
|
|
|
|
s->pending &= ~mask;
|
|
|
|
}
|
|
|
|
sun4c_check_interrupts(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-31 19:30:21 +00:00
|
|
|
static const VMStateDescription vmstate_sun4c_intctl = {
|
|
|
|
.name ="sun4c_intctl",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.minimum_version_id_old = 1,
|
|
|
|
.fields = (VMStateField []) {
|
|
|
|
VMSTATE_UINT8(reg, Sun4c_INTCTLState),
|
|
|
|
VMSTATE_UINT8(pending, Sun4c_INTCTLState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
2007-12-28 20:59:23 +00:00
|
|
|
|
2009-10-24 19:49:15 +00:00
|
|
|
static void sun4c_intctl_reset(DeviceState *d)
|
2007-12-28 20:59:23 +00:00
|
|
|
{
|
2009-10-24 19:49:15 +00:00
|
|
|
Sun4c_INTCTLState *s = container_of(d, Sun4c_INTCTLState, busdev.qdev);
|
2007-12-28 20:59:23 +00:00
|
|
|
|
|
|
|
s->reg = 1;
|
|
|
|
s->pending = 0;
|
|
|
|
}
|
|
|
|
|
2009-08-14 08:36:05 +00:00
|
|
|
static int sun4c_intctl_init1(SysBusDevice *dev)
|
2009-07-21 19:57:32 +00:00
|
|
|
{
|
|
|
|
Sun4c_INTCTLState *s = FROM_SYSBUS(Sun4c_INTCTLState, dev);
|
|
|
|
unsigned int i;
|
2007-12-28 20:59:23 +00:00
|
|
|
|
2011-11-15 09:56:16 +00:00
|
|
|
memory_region_init_io(&s->iomem, &sun4c_intctl_mem_ops, s,
|
|
|
|
"intctl", INTCTL_SIZE);
|
2011-11-27 09:38:10 +00:00
|
|
|
sysbus_init_mmio(dev, &s->iomem);
|
2009-07-21 19:57:32 +00:00
|
|
|
qdev_init_gpio_in(&dev->qdev, sun4c_set_irq, 8);
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PILS; i++) {
|
|
|
|
sysbus_init_irq(dev, &s->cpu_irqs[i]);
|
|
|
|
}
|
2009-10-24 19:49:15 +00:00
|
|
|
|
2009-08-14 08:36:05 +00:00
|
|
|
return 0;
|
2007-12-28 20:59:23 +00:00
|
|
|
}
|
2009-07-21 19:57:32 +00:00
|
|
|
|
2012-01-24 19:12:29 +00:00
|
|
|
static void sun4c_intctl_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 03:34:16 +00:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 19:12:29 +00:00
|
|
|
SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
k->init = sun4c_intctl_init1;
|
2011-12-08 03:34:16 +00:00
|
|
|
dc->reset = sun4c_intctl_reset;
|
|
|
|
dc->vmsd = &vmstate_sun4c_intctl;
|
2012-01-24 19:12:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 15:19:07 +00:00
|
|
|
static const TypeInfo sun4c_intctl_info = {
|
2011-12-08 03:34:16 +00:00
|
|
|
.name = "sun4c_intctl",
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(Sun4c_INTCTLState),
|
|
|
|
.class_init = sun4c_intctl_class_init,
|
2009-07-21 19:57:32 +00:00
|
|
|
};
|
|
|
|
|
2012-02-09 14:20:55 +00:00
|
|
|
static void sun4c_intctl_register_types(void)
|
2009-07-21 19:57:32 +00:00
|
|
|
{
|
2011-12-08 03:34:16 +00:00
|
|
|
type_register_static(&sun4c_intctl_info);
|
2009-07-21 19:57:32 +00:00
|
|
|
}
|
|
|
|
|
2012-02-09 14:20:55 +00:00
|
|
|
type_init(sun4c_intctl_register_types)
|