2007-09-16 21:08:06 +00:00
|
|
|
/*
|
2006-04-09 01:32:52 +00:00
|
|
|
* Arm PrimeCell PL190 Vector Interrupt Controller
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 CodeSourcery.
|
|
|
|
* Written by Paul Brook
|
|
|
|
*
|
2011-06-26 02:21:35 +00:00
|
|
|
* This code is licensed under the GPL.
|
2006-04-09 01:32:52 +00:00
|
|
|
*/
|
|
|
|
|
2013-02-04 14:40:22 +00:00
|
|
|
#include "hw/sysbus.h"
|
2006-04-09 01:32:52 +00:00
|
|
|
|
|
|
|
/* The number of virtual priority levels. 16 user vectors plus the
|
|
|
|
unvectored IRQ. Chained interrupts would require an additional level
|
|
|
|
if implemented. */
|
|
|
|
|
|
|
|
#define PL190_NUM_PRIO 17
|
|
|
|
|
2013-07-26 18:23:57 +00:00
|
|
|
#define TYPE_PL190 "pl190"
|
|
|
|
#define PL190(obj) OBJECT_CHECK(PL190State, (obj), TYPE_PL190)
|
|
|
|
|
2013-07-26 18:18:42 +00:00
|
|
|
typedef struct PL190State {
|
2013-07-26 18:23:57 +00:00
|
|
|
SysBusDevice parent_obj;
|
|
|
|
|
2011-10-11 11:54:48 +00:00
|
|
|
MemoryRegion iomem;
|
2006-04-09 01:32:52 +00:00
|
|
|
uint32_t level;
|
|
|
|
uint32_t soft_level;
|
|
|
|
uint32_t irq_enable;
|
|
|
|
uint32_t fiq_select;
|
|
|
|
uint8_t vect_control[16];
|
|
|
|
uint32_t vect_addr[PL190_NUM_PRIO];
|
|
|
|
/* Mask containing interrupts with higher priority than this one. */
|
|
|
|
uint32_t prio_mask[PL190_NUM_PRIO + 1];
|
|
|
|
int protected;
|
|
|
|
/* Current priority level. */
|
|
|
|
int priority;
|
|
|
|
int prev_prio[PL190_NUM_PRIO];
|
2007-04-07 18:14:41 +00:00
|
|
|
qemu_irq irq;
|
|
|
|
qemu_irq fiq;
|
2013-07-26 18:18:42 +00:00
|
|
|
} PL190State;
|
2006-04-09 01:32:52 +00:00
|
|
|
|
|
|
|
static const unsigned char pl190_id[] =
|
|
|
|
{ 0x90, 0x11, 0x04, 0x00, 0x0D, 0xf0, 0x05, 0xb1 };
|
|
|
|
|
2013-07-26 18:18:42 +00:00
|
|
|
static inline uint32_t pl190_irq_level(PL190State *s)
|
2006-04-09 01:32:52 +00:00
|
|
|
{
|
|
|
|
return (s->level | s->soft_level) & s->irq_enable & ~s->fiq_select;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update interrupts. */
|
2013-07-26 18:18:42 +00:00
|
|
|
static void pl190_update(PL190State *s)
|
2006-04-09 01:32:52 +00:00
|
|
|
{
|
|
|
|
uint32_t level = pl190_irq_level(s);
|
|
|
|
int set;
|
|
|
|
|
|
|
|
set = (level & s->prio_mask[s->priority]) != 0;
|
2007-04-07 18:14:41 +00:00
|
|
|
qemu_set_irq(s->irq, set);
|
2006-04-09 01:32:52 +00:00
|
|
|
set = ((s->level | s->soft_level) & s->fiq_select) != 0;
|
2007-04-07 18:14:41 +00:00
|
|
|
qemu_set_irq(s->fiq, set);
|
2006-04-09 01:32:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void pl190_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
2013-07-26 18:18:42 +00:00
|
|
|
PL190State *s = (PL190State *)opaque;
|
2006-04-09 01:32:52 +00:00
|
|
|
|
|
|
|
if (level)
|
|
|
|
s->level |= 1u << irq;
|
|
|
|
else
|
|
|
|
s->level &= ~(1u << irq);
|
|
|
|
pl190_update(s);
|
|
|
|
}
|
|
|
|
|
2013-07-26 18:18:42 +00:00
|
|
|
static void pl190_update_vectors(PL190State *s)
|
2006-04-09 01:32:52 +00:00
|
|
|
{
|
|
|
|
uint32_t mask;
|
|
|
|
int i;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
mask = 0;
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
{
|
|
|
|
s->prio_mask[i] = mask;
|
|
|
|
if (s->vect_control[i] & 0x20)
|
|
|
|
{
|
|
|
|
n = s->vect_control[i] & 0x1f;
|
|
|
|
mask |= 1 << n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s->prio_mask[16] = mask;
|
|
|
|
pl190_update(s);
|
|
|
|
}
|
|
|
|
|
2012-10-23 10:30:10 +00:00
|
|
|
static uint64_t pl190_read(void *opaque, hwaddr offset,
|
2011-10-11 11:54:48 +00:00
|
|
|
unsigned size)
|
2006-04-09 01:32:52 +00:00
|
|
|
{
|
2013-07-26 18:18:42 +00:00
|
|
|
PL190State *s = (PL190State *)opaque;
|
2006-04-09 01:32:52 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (offset >= 0xfe0 && offset < 0x1000) {
|
|
|
|
return pl190_id[(offset - 0xfe0) >> 2];
|
|
|
|
}
|
|
|
|
if (offset >= 0x100 && offset < 0x140) {
|
|
|
|
return s->vect_addr[(offset - 0x100) >> 2];
|
|
|
|
}
|
|
|
|
if (offset >= 0x200 && offset < 0x240) {
|
|
|
|
return s->vect_control[(offset - 0x200) >> 2];
|
|
|
|
}
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* IRQSTATUS */
|
|
|
|
return pl190_irq_level(s);
|
|
|
|
case 1: /* FIQSATUS */
|
|
|
|
return (s->level | s->soft_level) & s->fiq_select;
|
|
|
|
case 2: /* RAWINTR */
|
|
|
|
return s->level | s->soft_level;
|
|
|
|
case 3: /* INTSELECT */
|
|
|
|
return s->fiq_select;
|
|
|
|
case 4: /* INTENABLE */
|
|
|
|
return s->irq_enable;
|
|
|
|
case 6: /* SOFTINT */
|
|
|
|
return s->soft_level;
|
|
|
|
case 8: /* PROTECTION */
|
|
|
|
return s->protected;
|
|
|
|
case 12: /* VECTADDR */
|
|
|
|
/* Read vector address at the start of an ISR. Increases the
|
2012-09-26 15:46:28 +00:00
|
|
|
* current priority level to that of the current interrupt.
|
|
|
|
*
|
|
|
|
* Since an enabled interrupt X at priority P causes prio_mask[Y]
|
|
|
|
* to have bit X set for all Y > P, this loop will stop with
|
|
|
|
* i == the priority of the highest priority set interrupt.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < s->priority; i++) {
|
|
|
|
if ((s->level | s->soft_level) & s->prio_mask[i + 1]) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-09 01:32:52 +00:00
|
|
|
/* Reading this value with no pending interrupts is undefined.
|
|
|
|
We return the default address. */
|
|
|
|
if (i == PL190_NUM_PRIO)
|
|
|
|
return s->vect_addr[16];
|
|
|
|
if (i < s->priority)
|
|
|
|
{
|
|
|
|
s->prev_prio[i] = s->priority;
|
|
|
|
s->priority = i;
|
|
|
|
pl190_update(s);
|
|
|
|
}
|
|
|
|
return s->vect_addr[s->priority];
|
|
|
|
case 13: /* DEFVECTADDR */
|
|
|
|
return s->vect_addr[16];
|
|
|
|
default:
|
2012-10-18 13:11:39 +00:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"pl190_read: Bad offset %x\n", (int)offset);
|
2006-04-09 01:32:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 10:30:10 +00:00
|
|
|
static void pl190_write(void *opaque, hwaddr offset,
|
2011-10-11 11:54:48 +00:00
|
|
|
uint64_t val, unsigned size)
|
2006-04-09 01:32:52 +00:00
|
|
|
{
|
2013-07-26 18:18:42 +00:00
|
|
|
PL190State *s = (PL190State *)opaque;
|
2006-04-09 01:32:52 +00:00
|
|
|
|
|
|
|
if (offset >= 0x100 && offset < 0x140) {
|
|
|
|
s->vect_addr[(offset - 0x100) >> 2] = val;
|
|
|
|
pl190_update_vectors(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (offset >= 0x200 && offset < 0x240) {
|
|
|
|
s->vect_control[(offset - 0x200) >> 2] = val;
|
|
|
|
pl190_update_vectors(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (offset >> 2) {
|
|
|
|
case 0: /* SELECT */
|
|
|
|
/* This is a readonly register, but linux tries to write to it
|
|
|
|
anyway. Ignore the write. */
|
|
|
|
break;
|
|
|
|
case 3: /* INTSELECT */
|
|
|
|
s->fiq_select = val;
|
|
|
|
break;
|
|
|
|
case 4: /* INTENABLE */
|
|
|
|
s->irq_enable |= val;
|
|
|
|
break;
|
|
|
|
case 5: /* INTENCLEAR */
|
|
|
|
s->irq_enable &= ~val;
|
|
|
|
break;
|
|
|
|
case 6: /* SOFTINT */
|
|
|
|
s->soft_level |= val;
|
|
|
|
break;
|
|
|
|
case 7: /* SOFTINTCLEAR */
|
|
|
|
s->soft_level &= ~val;
|
|
|
|
break;
|
|
|
|
case 8: /* PROTECTION */
|
|
|
|
/* TODO: Protection (supervisor only access) is not implemented. */
|
|
|
|
s->protected = val & 1;
|
|
|
|
break;
|
|
|
|
case 12: /* VECTADDR */
|
|
|
|
/* Restore the previous priority level. The value written is
|
|
|
|
ignored. */
|
|
|
|
if (s->priority < PL190_NUM_PRIO)
|
|
|
|
s->priority = s->prev_prio[s->priority];
|
|
|
|
break;
|
|
|
|
case 13: /* DEFVECTADDR */
|
2011-01-20 16:04:52 +00:00
|
|
|
s->vect_addr[16] = val;
|
2006-04-09 01:32:52 +00:00
|
|
|
break;
|
|
|
|
case 0xc0: /* ITCR */
|
2009-05-08 01:35:15 +00:00
|
|
|
if (val) {
|
2012-10-30 07:45:09 +00:00
|
|
|
qemu_log_mask(LOG_UNIMP, "pl190: Test mode not implemented\n");
|
2009-05-08 01:35:15 +00:00
|
|
|
}
|
2006-04-09 01:32:52 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-10-18 13:11:39 +00:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"pl190_write: Bad offset %x\n", (int)offset);
|
2006-04-09 01:32:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
pl190_update(s);
|
|
|
|
}
|
|
|
|
|
2011-10-11 11:54:48 +00:00
|
|
|
static const MemoryRegionOps pl190_ops = {
|
|
|
|
.read = pl190_read,
|
|
|
|
.write = pl190_write,
|
|
|
|
.endianness = DEVICE_NATIVE_ENDIAN,
|
2006-04-09 01:32:52 +00:00
|
|
|
};
|
|
|
|
|
2010-12-23 17:19:51 +00:00
|
|
|
static void pl190_reset(DeviceState *d)
|
2006-04-09 01:32:52 +00:00
|
|
|
{
|
2013-07-26 18:23:57 +00:00
|
|
|
PL190State *s = PL190(d);
|
|
|
|
int i;
|
2006-04-09 01:32:52 +00:00
|
|
|
|
2013-07-26 18:23:57 +00:00
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
s->vect_addr[i] = 0;
|
|
|
|
s->vect_control[i] = 0;
|
2006-04-09 01:32:52 +00:00
|
|
|
}
|
2013-07-26 18:23:57 +00:00
|
|
|
s->vect_addr[16] = 0;
|
|
|
|
s->prio_mask[17] = 0xffffffff;
|
|
|
|
s->priority = PL190_NUM_PRIO;
|
|
|
|
pl190_update_vectors(s);
|
2006-04-09 01:32:52 +00:00
|
|
|
}
|
|
|
|
|
2013-07-26 18:23:57 +00:00
|
|
|
static int pl190_init(SysBusDevice *sbd)
|
2006-04-09 01:32:52 +00:00
|
|
|
{
|
2013-07-26 18:23:57 +00:00
|
|
|
DeviceState *dev = DEVICE(sbd);
|
|
|
|
PL190State *s = PL190(dev);
|
2006-04-09 01:32:52 +00:00
|
|
|
|
2013-06-07 01:25:08 +00:00
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &pl190_ops, s, "pl190", 0x1000);
|
2013-07-26 18:23:57 +00:00
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
|
|
|
qdev_init_gpio_in(dev, pl190_set_irq, 32);
|
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
|
|
|
sysbus_init_irq(sbd, &s->fiq);
|
2009-08-14 08:36:05 +00:00
|
|
|
return 0;
|
2006-04-09 01:32:52 +00:00
|
|
|
}
|
2009-05-14 21:35:07 +00:00
|
|
|
|
2010-12-23 17:19:51 +00:00
|
|
|
static const VMStateDescription vmstate_pl190 = {
|
|
|
|
.name = "pl190",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
2013-07-26 18:18:42 +00:00
|
|
|
VMSTATE_UINT32(level, PL190State),
|
|
|
|
VMSTATE_UINT32(soft_level, PL190State),
|
|
|
|
VMSTATE_UINT32(irq_enable, PL190State),
|
|
|
|
VMSTATE_UINT32(fiq_select, PL190State),
|
|
|
|
VMSTATE_UINT8_ARRAY(vect_control, PL190State, 16),
|
|
|
|
VMSTATE_UINT32_ARRAY(vect_addr, PL190State, PL190_NUM_PRIO),
|
|
|
|
VMSTATE_UINT32_ARRAY(prio_mask, PL190State, PL190_NUM_PRIO+1),
|
|
|
|
VMSTATE_INT32(protected, PL190State),
|
|
|
|
VMSTATE_INT32(priority, PL190State),
|
|
|
|
VMSTATE_INT32_ARRAY(prev_prio, PL190State, PL190_NUM_PRIO),
|
2010-12-23 17:19:51 +00:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-01-24 19:12:29 +00:00
|
|
|
static void pl190_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 = pl190_init;
|
2011-12-08 03:34:16 +00:00
|
|
|
dc->reset = pl190_reset;
|
|
|
|
dc->vmsd = &vmstate_pl190;
|
2012-01-24 19:12:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 15:19:07 +00:00
|
|
|
static const TypeInfo pl190_info = {
|
2013-07-26 18:23:57 +00:00
|
|
|
.name = TYPE_PL190,
|
2011-12-08 03:34:16 +00:00
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2013-07-26 18:18:42 +00:00
|
|
|
.instance_size = sizeof(PL190State),
|
2011-12-08 03:34:16 +00:00
|
|
|
.class_init = pl190_class_init,
|
2010-12-23 17:19:51 +00:00
|
|
|
};
|
|
|
|
|
2012-02-09 14:20:55 +00:00
|
|
|
static void pl190_register_types(void)
|
2009-05-14 21:35:07 +00:00
|
|
|
{
|
2011-12-08 03:34:16 +00:00
|
|
|
type_register_static(&pl190_info);
|
2009-05-14 21:35:07 +00:00
|
|
|
}
|
|
|
|
|
2012-02-09 14:20:55 +00:00
|
|
|
type_init(pl190_register_types)
|