2016-01-29 23:50:42 +01:00
|
|
|
/*
|
|
|
|
* Raspberry Pi emulation (c) 2012 Gregory Estrade
|
|
|
|
* Upstreaming code cleanup [including bcm2835_*] (c) 2013 Jan Petrous
|
|
|
|
*
|
|
|
|
* Rasperry Pi 2 emulation and refactoring Copyright (c) 2015, Microsoft
|
|
|
|
* Written by Andrew Baumann
|
|
|
|
*
|
|
|
|
* This code is licensed under the GNU GPLv2 and later.
|
|
|
|
*/
|
|
|
|
|
2016-02-08 20:01:23 +01:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2016-01-19 21:51:44 +01:00
|
|
|
#include "cpu.h"
|
2016-01-29 23:50:42 +01:00
|
|
|
#include "hw/arm/bcm2836.h"
|
|
|
|
#include "hw/arm/raspi_platform.h"
|
|
|
|
#include "hw/sysbus.h"
|
|
|
|
|
2018-03-13 16:34:55 +01:00
|
|
|
struct BCM283XInfo {
|
|
|
|
const char *name;
|
2018-03-13 16:34:57 +01:00
|
|
|
const char *cpu_type;
|
2019-10-20 01:47:04 +02:00
|
|
|
hwaddr peri_base; /* Peripheral base address seen by the CPU */
|
|
|
|
hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
|
2018-03-13 16:34:56 +01:00
|
|
|
int clusterid;
|
2018-03-13 16:34:55 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static const BCM283XInfo bcm283x_socs[] = {
|
|
|
|
{
|
|
|
|
.name = TYPE_BCM2836,
|
2018-03-23 19:26:45 +01:00
|
|
|
.cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"),
|
2019-10-20 01:47:04 +02:00
|
|
|
.peri_base = 0x3f000000,
|
|
|
|
.ctrl_base = 0x40000000,
|
2018-03-13 16:34:56 +01:00
|
|
|
.clusterid = 0xf,
|
2018-03-13 16:34:55 +01:00
|
|
|
},
|
2018-03-13 16:34:57 +01:00
|
|
|
#ifdef TARGET_AARCH64
|
2018-03-13 16:34:55 +01:00
|
|
|
{
|
|
|
|
.name = TYPE_BCM2837,
|
2018-03-13 16:34:57 +01:00
|
|
|
.cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"),
|
2019-10-20 01:47:04 +02:00
|
|
|
.peri_base = 0x3f000000,
|
|
|
|
.ctrl_base = 0x40000000,
|
2018-03-13 16:34:56 +01:00
|
|
|
.clusterid = 0x0,
|
2018-03-13 16:34:55 +01:00
|
|
|
},
|
2018-03-13 16:34:57 +01:00
|
|
|
#endif
|
2018-03-13 16:34:55 +01:00
|
|
|
};
|
|
|
|
|
2016-01-29 23:50:42 +01:00
|
|
|
static void bcm2836_init(Object *obj)
|
|
|
|
{
|
2018-03-13 16:34:54 +01:00
|
|
|
BCM283XState *s = BCM283X(obj);
|
2018-03-13 16:34:57 +01:00
|
|
|
BCM283XClass *bc = BCM283X_GET_CLASS(obj);
|
|
|
|
const BCM283XInfo *info = bc->info;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
for (n = 0; n < BCM283X_NCPUS; n++) {
|
2019-10-20 01:47:05 +02:00
|
|
|
object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
|
|
|
|
sizeof(s->cpu[n].core), info->cpu_type,
|
|
|
|
&error_abort, NULL);
|
2018-03-13 16:34:57 +01:00
|
|
|
}
|
2016-01-29 23:50:42 +01:00
|
|
|
|
hw/arm/bcm2836: Fix crash with device_add bcm2837 on unsupported machines
When trying to "device_add bcm2837" on a machine that is not suitable for
this device, you can quickly crash QEMU afterwards, e.g. with "info qtree":
echo "{'execute':'qmp_capabilities'} {'execute':'device_add', " \
"'arguments':{'driver':'bcm2837'}} {'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
aarch64-softmmu/qemu-system-aarch64 -M integratorcp,accel=qtest -S -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 12, "major": 2},
"package": "build-all"}, "capabilities": []}}
{"return": {}}
{"error": {"class": "GenericError", "desc": "Device 'bcm2837' can not be
hotplugged on this machine"}}
Segmentation fault (core dumped)
The qdev_set_parent_bus() from instance_init adds a link to the child devices
which is not valid anymore after the bcm2837 instance has been destroyed.
Unfortunately, the child devices do not get destroyed / unlinked correctly
because both object_initialize() and object_property_add_child() increase
the reference count of the child objects by one, but only one reference
is dropped when the parent gets removed. So let's use the new functions
object_initialize_child() and sysbus_init_child_obj() instead to create
the objects, which will take care of creating the child objects with the
correct reference count of one.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-id: 1531745974-17187-4-git-send-email-thuth@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2018-07-16 14:59:20 +02:00
|
|
|
sysbus_init_child_obj(obj, "control", &s->control, sizeof(s->control),
|
|
|
|
TYPE_BCM2836_CONTROL);
|
2016-01-29 23:50:42 +01:00
|
|
|
|
hw/arm/bcm2836: Fix crash with device_add bcm2837 on unsupported machines
When trying to "device_add bcm2837" on a machine that is not suitable for
this device, you can quickly crash QEMU afterwards, e.g. with "info qtree":
echo "{'execute':'qmp_capabilities'} {'execute':'device_add', " \
"'arguments':{'driver':'bcm2837'}} {'execute': 'human-monitor-command', " \
"'arguments': {'command-line': 'info qtree'}}" | \
aarch64-softmmu/qemu-system-aarch64 -M integratorcp,accel=qtest -S -qmp stdio
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 12, "major": 2},
"package": "build-all"}, "capabilities": []}}
{"return": {}}
{"error": {"class": "GenericError", "desc": "Device 'bcm2837' can not be
hotplugged on this machine"}}
Segmentation fault (core dumped)
The qdev_set_parent_bus() from instance_init adds a link to the child devices
which is not valid anymore after the bcm2837 instance has been destroyed.
Unfortunately, the child devices do not get destroyed / unlinked correctly
because both object_initialize() and object_property_add_child() increase
the reference count of the child objects by one, but only one reference
is dropped when the parent gets removed. So let's use the new functions
object_initialize_child() and sysbus_init_child_obj() instead to create
the objects, which will take care of creating the child objects with the
correct reference count of one.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-id: 1531745974-17187-4-git-send-email-thuth@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2018-07-16 14:59:20 +02:00
|
|
|
sysbus_init_child_obj(obj, "peripherals", &s->peripherals,
|
|
|
|
sizeof(s->peripherals), TYPE_BCM2835_PERIPHERALS);
|
2016-02-11 12:17:32 +01:00
|
|
|
object_property_add_alias(obj, "board-rev", OBJECT(&s->peripherals),
|
|
|
|
"board-rev", &error_abort);
|
2016-03-16 18:06:01 +01:00
|
|
|
object_property_add_alias(obj, "vcram-size", OBJECT(&s->peripherals),
|
|
|
|
"vcram-size", &error_abort);
|
2016-01-29 23:50:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bcm2836_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
2018-03-13 16:34:54 +01:00
|
|
|
BCM283XState *s = BCM283X(dev);
|
2018-03-13 16:34:56 +01:00
|
|
|
BCM283XClass *bc = BCM283X_GET_CLASS(dev);
|
|
|
|
const BCM283XInfo *info = bc->info;
|
2016-01-29 23:50:42 +01:00
|
|
|
Object *obj;
|
|
|
|
Error *err = NULL;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
/* common peripherals from bcm2835 */
|
|
|
|
|
|
|
|
obj = object_property_get_link(OBJECT(dev), "ram", &err);
|
|
|
|
if (obj == NULL) {
|
|
|
|
error_setg(errp, "%s: required ram link not found: %s",
|
|
|
|
__func__, error_get_pretty(err));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj, &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_property_set_bool(OBJECT(&s->peripherals), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-24 22:58:48 +01:00
|
|
|
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals),
|
|
|
|
"sd-bus", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-29 23:50:42 +01:00
|
|
|
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
|
2019-10-20 01:47:04 +02:00
|
|
|
info->peri_base, 1);
|
2016-01-29 23:50:42 +01:00
|
|
|
|
|
|
|
/* bcm2836 interrupt controller (and mailboxes, etc.) */
|
|
|
|
object_property_set_bool(OBJECT(&s->control), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-20 01:47:04 +02:00
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base);
|
2016-01-29 23:50:42 +01:00
|
|
|
|
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0,
|
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0));
|
|
|
|
sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1,
|
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-fiq", 0));
|
|
|
|
|
2018-03-13 16:34:54 +01:00
|
|
|
for (n = 0; n < BCM283X_NCPUS; n++) {
|
2018-03-13 16:34:56 +01:00
|
|
|
/* TODO: this should be converted to a property of ARM_CPU */
|
2019-10-20 01:47:05 +02:00
|
|
|
s->cpu[n].core.mp_affinity = (info->clusterid << 8) | n;
|
2016-01-29 23:50:42 +01:00
|
|
|
|
|
|
|
/* set periphbase/CBAR value for CPU-local registers */
|
2019-10-20 01:47:05 +02:00
|
|
|
object_property_set_int(OBJECT(&s->cpu[n].core),
|
2019-10-20 01:47:04 +02:00
|
|
|
info->peri_base,
|
2016-01-29 23:50:42 +01:00
|
|
|
"reset-cbar", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start powered off if not enabled */
|
2019-10-20 01:47:05 +02:00
|
|
|
object_property_set_bool(OBJECT(&s->cpu[n].core), n >= s->enabled_cpus,
|
2016-01-29 23:50:42 +01:00
|
|
|
"start-powered-off", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-20 01:47:05 +02:00
|
|
|
object_property_set_bool(OBJECT(&s->cpu[n].core), true,
|
|
|
|
"realized", &err);
|
2016-01-29 23:50:42 +01:00
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Connect irq/fiq outputs from the interrupt controller. */
|
|
|
|
qdev_connect_gpio_out_named(DEVICE(&s->control), "irq", n,
|
2019-10-20 01:47:05 +02:00
|
|
|
qdev_get_gpio_in(DEVICE(&s->cpu[n].core), ARM_CPU_IRQ));
|
2016-01-29 23:50:42 +01:00
|
|
|
qdev_connect_gpio_out_named(DEVICE(&s->control), "fiq", n,
|
2019-10-20 01:47:05 +02:00
|
|
|
qdev_get_gpio_in(DEVICE(&s->cpu[n].core), ARM_CPU_FIQ));
|
2016-01-29 23:50:42 +01:00
|
|
|
|
|
|
|
/* Connect timers from the CPU to the interrupt controller */
|
2019-10-20 01:47:05 +02:00
|
|
|
qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_PHYS,
|
2016-04-04 18:33:51 +02:00
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "cntpnsirq", n));
|
2019-10-20 01:47:05 +02:00
|
|
|
qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_VIRT,
|
2016-01-29 23:50:42 +01:00
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "cntvirq", n));
|
2019-10-20 01:47:05 +02:00
|
|
|
qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_HYP,
|
2016-04-04 18:33:51 +02:00
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "cnthpirq", n));
|
2019-10-20 01:47:05 +02:00
|
|
|
qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_SEC,
|
2016-04-04 18:33:51 +02:00
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "cntpsirq", n));
|
2016-01-29 23:50:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property bcm2836_props[] = {
|
2018-03-13 16:34:54 +01:00
|
|
|
DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus,
|
|
|
|
BCM283X_NCPUS),
|
2016-01-29 23:50:42 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
};
|
|
|
|
|
2018-03-13 16:34:55 +01:00
|
|
|
static void bcm283x_class_init(ObjectClass *oc, void *data)
|
2016-01-29 23:50:42 +01:00
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2018-03-13 16:34:55 +01:00
|
|
|
BCM283XClass *bc = BCM283X_CLASS(oc);
|
2016-01-29 23:50:42 +01:00
|
|
|
|
2018-03-13 16:34:55 +01:00
|
|
|
bc->info = data;
|
2016-01-29 23:50:42 +01:00
|
|
|
dc->realize = bcm2836_realize;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, bcm2836_props);
|
2018-07-16 18:18:41 +02:00
|
|
|
/* Reason: Must be wired up in code (see raspi_init() function) */
|
|
|
|
dc->user_creatable = false;
|
2016-01-29 23:50:42 +01:00
|
|
|
}
|
|
|
|
|
2018-03-13 16:34:55 +01:00
|
|
|
static const TypeInfo bcm283x_type_info = {
|
2018-03-13 16:34:54 +01:00
|
|
|
.name = TYPE_BCM283X,
|
2018-03-13 16:34:53 +01:00
|
|
|
.parent = TYPE_DEVICE,
|
2018-03-13 16:34:54 +01:00
|
|
|
.instance_size = sizeof(BCM283XState),
|
2016-01-29 23:50:42 +01:00
|
|
|
.instance_init = bcm2836_init,
|
2018-03-13 16:34:55 +01:00
|
|
|
.class_size = sizeof(BCM283XClass),
|
|
|
|
.abstract = true,
|
2016-01-29 23:50:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void bcm2836_register_types(void)
|
|
|
|
{
|
2018-03-13 16:34:55 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
type_register_static(&bcm283x_type_info);
|
|
|
|
for (i = 0; i < ARRAY_SIZE(bcm283x_socs); i++) {
|
|
|
|
TypeInfo ti = {
|
|
|
|
.name = bcm283x_socs[i].name,
|
|
|
|
.parent = TYPE_BCM283X,
|
|
|
|
.class_init = bcm283x_class_init,
|
|
|
|
.class_data = (void *) &bcm283x_socs[i],
|
|
|
|
};
|
|
|
|
type_register(&ti);
|
|
|
|
}
|
2016-01-29 23:50:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(bcm2836_register_types)
|