2016-01-30 01:50:42 +03: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 22:01:23 +03: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 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2016-01-19 23:51:44 +03:00
|
|
|
#include "cpu.h"
|
2016-01-30 01:50:42 +03:00
|
|
|
#include "hw/arm/bcm2836.h"
|
|
|
|
#include "hw/arm/raspi_platform.h"
|
|
|
|
#include "hw/sysbus.h"
|
|
|
|
|
|
|
|
/* Peripheral base address seen by the CPU */
|
|
|
|
#define BCM2836_PERI_BASE 0x3F000000
|
|
|
|
|
|
|
|
/* "QA7" (Pi2) interrupt controller and mailboxes etc. */
|
|
|
|
#define BCM2836_CONTROL_BASE 0x40000000
|
|
|
|
|
2018-03-13 18:34:55 +03:00
|
|
|
struct BCM283XInfo {
|
|
|
|
const char *name;
|
2018-03-13 18:34:57 +03:00
|
|
|
const char *cpu_type;
|
2018-03-13 18:34:56 +03:00
|
|
|
int clusterid;
|
2018-03-13 18:34:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static const BCM283XInfo bcm283x_socs[] = {
|
|
|
|
{
|
|
|
|
.name = TYPE_BCM2836,
|
2018-03-23 21:26:45 +03:00
|
|
|
.cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"),
|
2018-03-13 18:34:56 +03:00
|
|
|
.clusterid = 0xf,
|
2018-03-13 18:34:55 +03:00
|
|
|
},
|
2018-03-13 18:34:57 +03:00
|
|
|
#ifdef TARGET_AARCH64
|
2018-03-13 18:34:55 +03:00
|
|
|
{
|
|
|
|
.name = TYPE_BCM2837,
|
2018-03-13 18:34:57 +03:00
|
|
|
.cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"),
|
2018-03-13 18:34:56 +03:00
|
|
|
.clusterid = 0x0,
|
2018-03-13 18:34:55 +03:00
|
|
|
},
|
2018-03-13 18:34:57 +03:00
|
|
|
#endif
|
2018-03-13 18:34:55 +03:00
|
|
|
};
|
|
|
|
|
2016-01-30 01:50:42 +03:00
|
|
|
static void bcm2836_init(Object *obj)
|
|
|
|
{
|
2018-03-13 18:34:54 +03:00
|
|
|
BCM283XState *s = BCM283X(obj);
|
2018-03-13 18:34:57 +03:00
|
|
|
BCM283XClass *bc = BCM283X_GET_CLASS(obj);
|
|
|
|
const BCM283XInfo *info = bc->info;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
for (n = 0; n < BCM283X_NCPUS; n++) {
|
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 15:59:20 +03:00
|
|
|
object_initialize_child(obj, "cpu[*]", &s->cpus[n], sizeof(s->cpus[n]),
|
|
|
|
info->cpu_type, &error_abort, NULL);
|
2018-03-13 18:34:57 +03:00
|
|
|
}
|
2016-01-30 01:50:42 +03: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 15:59:20 +03:00
|
|
|
sysbus_init_child_obj(obj, "control", &s->control, sizeof(s->control),
|
|
|
|
TYPE_BCM2836_CONTROL);
|
2016-01-30 01:50:42 +03: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 15:59:20 +03:00
|
|
|
sysbus_init_child_obj(obj, "peripherals", &s->peripherals,
|
|
|
|
sizeof(s->peripherals), TYPE_BCM2835_PERIPHERALS);
|
2016-02-11 14:17:32 +03:00
|
|
|
object_property_add_alias(obj, "board-rev", OBJECT(&s->peripherals),
|
|
|
|
"board-rev", &error_abort);
|
2016-03-16 20:06:01 +03:00
|
|
|
object_property_add_alias(obj, "vcram-size", OBJECT(&s->peripherals),
|
|
|
|
"vcram-size", &error_abort);
|
2016-01-30 01:50:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void bcm2836_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
2018-03-13 18:34:54 +03:00
|
|
|
BCM283XState *s = BCM283X(dev);
|
2018-03-13 18:34:56 +03:00
|
|
|
BCM283XClass *bc = BCM283X_GET_CLASS(dev);
|
|
|
|
const BCM283XInfo *info = bc->info;
|
2016-01-30 01:50:42 +03: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-25 00:58:48 +03:00
|
|
|
object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals),
|
|
|
|
"sd-bus", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-01-30 01:50:42 +03:00
|
|
|
sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
|
|
|
|
BCM2836_PERI_BASE, 1);
|
|
|
|
|
|
|
|
/* bcm2836 interrupt controller (and mailboxes, etc.) */
|
|
|
|
object_property_set_bool(OBJECT(&s->control), true, "realized", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, BCM2836_CONTROL_BASE);
|
|
|
|
|
|
|
|
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 18:34:54 +03:00
|
|
|
for (n = 0; n < BCM283X_NCPUS; n++) {
|
2018-03-13 18:34:56 +03:00
|
|
|
/* TODO: this should be converted to a property of ARM_CPU */
|
|
|
|
s->cpus[n].mp_affinity = (info->clusterid << 8) | n;
|
2016-01-30 01:50:42 +03:00
|
|
|
|
|
|
|
/* set periphbase/CBAR value for CPU-local registers */
|
|
|
|
object_property_set_int(OBJECT(&s->cpus[n]),
|
|
|
|
BCM2836_PERI_BASE + MCORE_OFFSET,
|
|
|
|
"reset-cbar", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start powered off if not enabled */
|
|
|
|
object_property_set_bool(OBJECT(&s->cpus[n]), n >= s->enabled_cpus,
|
|
|
|
"start-powered-off", &err);
|
|
|
|
if (err) {
|
|
|
|
error_propagate(errp, err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
object_property_set_bool(OBJECT(&s->cpus[n]), true, "realized", &err);
|
|
|
|
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,
|
|
|
|
qdev_get_gpio_in(DEVICE(&s->cpus[n]), ARM_CPU_IRQ));
|
|
|
|
qdev_connect_gpio_out_named(DEVICE(&s->control), "fiq", n,
|
|
|
|
qdev_get_gpio_in(DEVICE(&s->cpus[n]), ARM_CPU_FIQ));
|
|
|
|
|
|
|
|
/* Connect timers from the CPU to the interrupt controller */
|
|
|
|
qdev_connect_gpio_out(DEVICE(&s->cpus[n]), GTIMER_PHYS,
|
2016-04-04 19:33:51 +03:00
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "cntpnsirq", n));
|
2016-01-30 01:50:42 +03:00
|
|
|
qdev_connect_gpio_out(DEVICE(&s->cpus[n]), GTIMER_VIRT,
|
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "cntvirq", n));
|
2016-04-04 19:33:51 +03:00
|
|
|
qdev_connect_gpio_out(DEVICE(&s->cpus[n]), GTIMER_HYP,
|
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "cnthpirq", n));
|
|
|
|
qdev_connect_gpio_out(DEVICE(&s->cpus[n]), GTIMER_SEC,
|
|
|
|
qdev_get_gpio_in_named(DEVICE(&s->control), "cntpsirq", n));
|
2016-01-30 01:50:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property bcm2836_props[] = {
|
2018-03-13 18:34:54 +03:00
|
|
|
DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus,
|
|
|
|
BCM283X_NCPUS),
|
2016-01-30 01:50:42 +03:00
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
};
|
|
|
|
|
2018-03-13 18:34:55 +03:00
|
|
|
static void bcm283x_class_init(ObjectClass *oc, void *data)
|
2016-01-30 01:50:42 +03:00
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
2018-03-13 18:34:55 +03:00
|
|
|
BCM283XClass *bc = BCM283X_CLASS(oc);
|
2016-01-30 01:50:42 +03:00
|
|
|
|
2018-03-13 18:34:55 +03:00
|
|
|
bc->info = data;
|
2016-01-30 01:50:42 +03:00
|
|
|
dc->realize = bcm2836_realize;
|
2018-03-13 18:34:55 +03:00
|
|
|
dc->props = bcm2836_props;
|
2018-07-16 19:18:41 +03:00
|
|
|
/* Reason: Must be wired up in code (see raspi_init() function) */
|
|
|
|
dc->user_creatable = false;
|
2016-01-30 01:50:42 +03:00
|
|
|
}
|
|
|
|
|
2018-03-13 18:34:55 +03:00
|
|
|
static const TypeInfo bcm283x_type_info = {
|
2018-03-13 18:34:54 +03:00
|
|
|
.name = TYPE_BCM283X,
|
2018-03-13 18:34:53 +03:00
|
|
|
.parent = TYPE_DEVICE,
|
2018-03-13 18:34:54 +03:00
|
|
|
.instance_size = sizeof(BCM283XState),
|
2016-01-30 01:50:42 +03:00
|
|
|
.instance_init = bcm2836_init,
|
2018-03-13 18:34:55 +03:00
|
|
|
.class_size = sizeof(BCM283XClass),
|
|
|
|
.abstract = true,
|
2016-01-30 01:50:42 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static void bcm2836_register_types(void)
|
|
|
|
{
|
2018-03-13 18:34:55 +03: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-30 01:50:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(bcm2836_register_types)
|