mirror of https://github.com/xemu-project/xemu.git
hw/misc/a9scu: Do not allow invalid CPU count
Per the datasheet (DDI0407 r2p0): "The SCU connects one to four Cortex-A9 processors to the memory system through the AXI interfaces." Change the instance_init() handler to a device_realize() one so we can verify the property is in range, and return an error to the caller if not. Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Message-id: 20200901144100.116742-2-f4bug@amsat.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
a68694cd1f
commit
14a560359d
|
@ -12,8 +12,11 @@
|
||||||
#include "hw/misc/a9scu.h"
|
#include "hw/misc/a9scu.h"
|
||||||
#include "hw/qdev-properties.h"
|
#include "hw/qdev-properties.h"
|
||||||
#include "migration/vmstate.h"
|
#include "migration/vmstate.h"
|
||||||
|
#include "qapi/error.h"
|
||||||
#include "qemu/module.h"
|
#include "qemu/module.h"
|
||||||
|
|
||||||
|
#define A9_SCU_CPU_MAX 4
|
||||||
|
|
||||||
static uint64_t a9_scu_read(void *opaque, hwaddr offset,
|
static uint64_t a9_scu_read(void *opaque, hwaddr offset,
|
||||||
unsigned size)
|
unsigned size)
|
||||||
{
|
{
|
||||||
|
@ -105,12 +108,17 @@ static void a9_scu_reset(DeviceState *dev)
|
||||||
s->control = 0;
|
s->control = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void a9_scu_init(Object *obj)
|
static void a9_scu_realize(DeviceState *dev, Error **errp)
|
||||||
{
|
{
|
||||||
A9SCUState *s = A9_SCU(obj);
|
A9SCUState *s = A9_SCU(dev);
|
||||||
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
||||||
|
|
||||||
memory_region_init_io(&s->iomem, obj, &a9_scu_ops, s,
|
if (!s->num_cpu || s->num_cpu > A9_SCU_CPU_MAX) {
|
||||||
|
error_setg(errp, "Illegal CPU count: %u", s->num_cpu);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
memory_region_init_io(&s->iomem, OBJECT(s), &a9_scu_ops, s,
|
||||||
"a9-scu", 0x100);
|
"a9-scu", 0x100);
|
||||||
sysbus_init_mmio(sbd, &s->iomem);
|
sysbus_init_mmio(sbd, &s->iomem);
|
||||||
}
|
}
|
||||||
|
@ -138,13 +146,13 @@ static void a9_scu_class_init(ObjectClass *klass, void *data)
|
||||||
device_class_set_props(dc, a9_scu_properties);
|
device_class_set_props(dc, a9_scu_properties);
|
||||||
dc->vmsd = &vmstate_a9_scu;
|
dc->vmsd = &vmstate_a9_scu;
|
||||||
dc->reset = a9_scu_reset;
|
dc->reset = a9_scu_reset;
|
||||||
|
dc->realize = a9_scu_realize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const TypeInfo a9_scu_info = {
|
static const TypeInfo a9_scu_info = {
|
||||||
.name = TYPE_A9_SCU,
|
.name = TYPE_A9_SCU,
|
||||||
.parent = TYPE_SYS_BUS_DEVICE,
|
.parent = TYPE_SYS_BUS_DEVICE,
|
||||||
.instance_size = sizeof(A9SCUState),
|
.instance_size = sizeof(A9SCUState),
|
||||||
.instance_init = a9_scu_init,
|
|
||||||
.class_init = a9_scu_class_init,
|
.class_init = a9_scu_class_init,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue