2012-05-02 20:49:42 +04:00
|
|
|
/*
|
|
|
|
* ARM GIC support - common bits of emulated and KVM kernel model
|
|
|
|
*
|
|
|
|
* Copyright (c) 2012 Linaro Limited
|
|
|
|
* Written by Peter Maydell
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-03-18 20:36:02 +04:00
|
|
|
#include "gic_internal.h"
|
2012-05-02 20:49:42 +04:00
|
|
|
|
2013-04-05 19:18:00 +04:00
|
|
|
static void gic_pre_save(void *opaque)
|
2012-05-02 20:49:42 +04:00
|
|
|
{
|
2012-10-12 14:54:39 +04:00
|
|
|
GICState *s = (GICState *)opaque;
|
2013-03-05 04:34:41 +04:00
|
|
|
ARMGICCommonClass *c = ARM_GIC_COMMON_GET_CLASS(s);
|
2012-05-02 20:49:42 +04:00
|
|
|
|
2013-03-05 04:34:41 +04:00
|
|
|
if (c->pre_save) {
|
|
|
|
c->pre_save(s);
|
|
|
|
}
|
2012-05-02 20:49:42 +04:00
|
|
|
}
|
|
|
|
|
2013-04-05 19:18:00 +04:00
|
|
|
static int gic_post_load(void *opaque, int version_id)
|
2012-05-02 20:49:42 +04:00
|
|
|
{
|
2012-10-12 14:54:39 +04:00
|
|
|
GICState *s = (GICState *)opaque;
|
2013-03-05 04:34:41 +04:00
|
|
|
ARMGICCommonClass *c = ARM_GIC_COMMON_GET_CLASS(s);
|
2012-05-02 20:49:42 +04:00
|
|
|
|
2013-03-05 04:34:41 +04:00
|
|
|
if (c->post_load) {
|
|
|
|
c->post_load(s);
|
|
|
|
}
|
2012-05-02 20:49:42 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-05 19:18:00 +04:00
|
|
|
static const VMStateDescription vmstate_gic_irq_state = {
|
|
|
|
.name = "arm_gic_irq_state",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT8(enabled, gic_irq_state),
|
|
|
|
VMSTATE_UINT8(pending, gic_irq_state),
|
|
|
|
VMSTATE_UINT8(active, gic_irq_state),
|
|
|
|
VMSTATE_UINT8(level, gic_irq_state),
|
|
|
|
VMSTATE_BOOL(model, gic_irq_state),
|
|
|
|
VMSTATE_BOOL(trigger, gic_irq_state),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_gic = {
|
|
|
|
.name = "arm_gic",
|
|
|
|
.version_id = 4,
|
|
|
|
.minimum_version_id = 4,
|
|
|
|
.pre_save = gic_pre_save,
|
|
|
|
.post_load = gic_post_load,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_BOOL(enabled, GICState),
|
|
|
|
VMSTATE_BOOL_ARRAY(cpu_enabled, GICState, NCPU),
|
|
|
|
VMSTATE_STRUCT_ARRAY(irq_state, GICState, GIC_MAXIRQ, 1,
|
|
|
|
vmstate_gic_irq_state, gic_irq_state),
|
|
|
|
VMSTATE_UINT8_ARRAY(irq_target, GICState, GIC_MAXIRQ),
|
|
|
|
VMSTATE_UINT8_2DARRAY(priority1, GICState, GIC_INTERNAL, NCPU),
|
|
|
|
VMSTATE_UINT8_ARRAY(priority2, GICState, GIC_MAXIRQ - GIC_INTERNAL),
|
|
|
|
VMSTATE_UINT16_2DARRAY(last_active, GICState, GIC_MAXIRQ, NCPU),
|
|
|
|
VMSTATE_UINT16_ARRAY(priority_mask, GICState, NCPU),
|
|
|
|
VMSTATE_UINT16_ARRAY(running_irq, GICState, NCPU),
|
|
|
|
VMSTATE_UINT16_ARRAY(running_priority, GICState, NCPU),
|
|
|
|
VMSTATE_UINT16_ARRAY(current_pending, GICState, NCPU),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-03-05 04:34:42 +04:00
|
|
|
static void arm_gic_common_realize(DeviceState *dev, Error **errp)
|
2012-05-02 20:49:42 +04:00
|
|
|
{
|
2013-03-05 04:34:42 +04:00
|
|
|
GICState *s = ARM_GIC_COMMON(dev);
|
2012-05-02 20:49:42 +04:00
|
|
|
int num_irq = s->num_irq;
|
|
|
|
|
|
|
|
if (s->num_cpu > NCPU) {
|
2013-03-05 04:34:42 +04:00
|
|
|
error_setg(errp, "requested %u CPUs exceeds GIC maximum %d",
|
|
|
|
s->num_cpu, NCPU);
|
|
|
|
return;
|
2012-05-02 20:49:42 +04:00
|
|
|
}
|
|
|
|
s->num_irq += GIC_BASE_IRQ;
|
|
|
|
if (s->num_irq > GIC_MAXIRQ) {
|
2013-03-05 04:34:42 +04:00
|
|
|
error_setg(errp,
|
|
|
|
"requested %u interrupt lines exceeds GIC maximum %d",
|
|
|
|
num_irq, GIC_MAXIRQ);
|
|
|
|
return;
|
2012-05-02 20:49:42 +04:00
|
|
|
}
|
|
|
|
/* ITLinesNumber is represented as (N / 32) - 1 (see
|
|
|
|
* gic_dist_readb) so this is an implementation imposed
|
|
|
|
* restriction, not an architectural one:
|
|
|
|
*/
|
|
|
|
if (s->num_irq < 32 || (s->num_irq % 32)) {
|
2013-03-05 04:34:42 +04:00
|
|
|
error_setg(errp,
|
|
|
|
"%d interrupt lines unsupported: not divisible by 32",
|
|
|
|
num_irq);
|
|
|
|
return;
|
2012-05-02 20:49:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void arm_gic_common_reset(DeviceState *dev)
|
|
|
|
{
|
2013-01-20 05:47:33 +04:00
|
|
|
GICState *s = FROM_SYSBUS(GICState, SYS_BUS_DEVICE(dev));
|
2012-05-02 20:49:42 +04:00
|
|
|
int i;
|
|
|
|
memset(s->irq_state, 0, GIC_MAXIRQ * sizeof(gic_irq_state));
|
|
|
|
for (i = 0 ; i < s->num_cpu; i++) {
|
2012-12-11 15:30:37 +04:00
|
|
|
if (s->revision == REV_11MPCORE) {
|
|
|
|
s->priority_mask[i] = 0xf0;
|
|
|
|
} else {
|
|
|
|
s->priority_mask[i] = 0;
|
|
|
|
}
|
2012-05-02 20:49:42 +04:00
|
|
|
s->current_pending[i] = 1023;
|
|
|
|
s->running_irq[i] = 1023;
|
|
|
|
s->running_priority[i] = 0x100;
|
2013-04-05 19:17:59 +04:00
|
|
|
s->cpu_enabled[i] = false;
|
2012-05-02 20:49:42 +04:00
|
|
|
}
|
|
|
|
for (i = 0; i < 16; i++) {
|
|
|
|
GIC_SET_ENABLED(i, ALL_CPU_MASK);
|
|
|
|
GIC_SET_TRIGGER(i);
|
|
|
|
}
|
|
|
|
if (s->num_cpu == 1) {
|
|
|
|
/* For uniprocessor GICs all interrupts always target the sole CPU */
|
|
|
|
for (i = 0; i < GIC_MAXIRQ; i++) {
|
|
|
|
s->irq_target[i] = 1;
|
|
|
|
}
|
|
|
|
}
|
2013-04-05 19:17:59 +04:00
|
|
|
s->enabled = false;
|
2012-05-02 20:49:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static Property arm_gic_common_properties[] = {
|
2012-10-12 14:54:39 +04:00
|
|
|
DEFINE_PROP_UINT32("num-cpu", GICState, num_cpu, 1),
|
|
|
|
DEFINE_PROP_UINT32("num-irq", GICState, num_irq, 32),
|
2012-05-02 20:49:42 +04:00
|
|
|
/* Revision can be 1 or 2 for GIC architecture specification
|
|
|
|
* versions 1 or 2, or 0 to indicate the legacy 11MPCore GIC.
|
|
|
|
* (Internally, 0xffffffff also indicates "not a GIC but an NVIC".)
|
|
|
|
*/
|
2012-10-12 14:54:39 +04:00
|
|
|
DEFINE_PROP_UINT32("revision", GICState, revision, 1),
|
2012-05-02 20:49:42 +04:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void arm_gic_common_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2013-03-05 04:34:42 +04:00
|
|
|
|
2012-05-02 20:49:42 +04:00
|
|
|
dc->reset = arm_gic_common_reset;
|
2013-03-05 04:34:42 +04:00
|
|
|
dc->realize = arm_gic_common_realize;
|
2012-05-02 20:49:42 +04:00
|
|
|
dc->props = arm_gic_common_properties;
|
2013-04-05 19:18:00 +04:00
|
|
|
dc->vmsd = &vmstate_gic;
|
2012-05-02 20:49:42 +04:00
|
|
|
dc->no_user = 1;
|
|
|
|
}
|
|
|
|
|
2013-01-10 19:19:07 +04:00
|
|
|
static const TypeInfo arm_gic_common_type = {
|
2012-05-02 20:49:42 +04:00
|
|
|
.name = TYPE_ARM_GIC_COMMON,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2012-10-12 14:54:39 +04:00
|
|
|
.instance_size = sizeof(GICState),
|
2012-05-02 20:49:42 +04:00
|
|
|
.class_size = sizeof(ARMGICCommonClass),
|
|
|
|
.class_init = arm_gic_common_class_init,
|
|
|
|
.abstract = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&arm_gic_common_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(register_types)
|