hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs
[qemu.git] / hw / arm / bcm2836.c
1 /*
2 * Raspberry Pi emulation (c) 2012 Gregory Estrade
3 * Upstreaming code cleanup [including bcm2835_*] (c) 2013 Jan Petrous
4 *
5 * Rasperry Pi 2 emulation and refactoring Copyright (c) 2015, Microsoft
6 * Written by Andrew Baumann
7 *
8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 * See the COPYING file in the top-level directory.
10 */
11
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "qemu/module.h"
15 #include "cpu.h"
16 #include "hw/arm/bcm2836.h"
17 #include "hw/arm/raspi_platform.h"
18 #include "hw/sysbus.h"
19
20 typedef struct BCM283XClass {
21 /*< private >*/
22 DeviceClass parent_class;
23 /*< public >*/
24 const char *name;
25 const char *cpu_type;
26 unsigned core_count;
27 hwaddr peri_base; /* Peripheral base address seen by the CPU */
28 hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
29 int clusterid;
30 } BCM283XClass;
31
32 #define BCM283X_CLASS(klass) \
33 OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
34 #define BCM283X_GET_CLASS(obj) \
35 OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
36
37 static Property bcm2836_enabled_cores_property =
38 DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0);
39
40 static void bcm2836_init(Object *obj)
41 {
42 BCM283XState *s = BCM283X(obj);
43 BCM283XClass *bc = BCM283X_GET_CLASS(obj);
44 int n;
45
46 for (n = 0; n < bc->core_count; n++) {
47 object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
48 bc->cpu_type);
49 }
50 if (bc->core_count > 1) {
51 qdev_property_add_static(DEVICE(obj), &bcm2836_enabled_cores_property);
52 qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count);
53 }
54
55 object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL);
56
57 object_initialize_child(obj, "peripherals", &s->peripherals,
58 TYPE_BCM2835_PERIPHERALS);
59 object_property_add_alias(obj, "board-rev", OBJECT(&s->peripherals),
60 "board-rev");
61 object_property_add_alias(obj, "vcram-size", OBJECT(&s->peripherals),
62 "vcram-size");
63 }
64
65 static void bcm2836_realize(DeviceState *dev, Error **errp)
66 {
67 BCM283XState *s = BCM283X(dev);
68 BCM283XClass *bc = BCM283X_GET_CLASS(dev);
69 Object *obj;
70 int n;
71
72 /* common peripherals from bcm2835 */
73
74 obj = object_property_get_link(OBJECT(dev), "ram", &error_abort);
75
76 object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj);
77
78 if (!sysbus_realize(SYS_BUS_DEVICE(&s->peripherals), errp)) {
79 return;
80 }
81
82 object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals),
83 "sd-bus");
84
85 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
86 bc->peri_base, 1);
87
88 /* bcm2836 interrupt controller (and mailboxes, etc.) */
89 if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) {
90 return;
91 }
92
93 sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base);
94
95 sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0,
96 qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0));
97 sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1,
98 qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-fiq", 0));
99
100 for (n = 0; n < BCM283X_NCPUS; n++) {
101 /* TODO: this should be converted to a property of ARM_CPU */
102 s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n;
103
104 /* set periphbase/CBAR value for CPU-local registers */
105 if (!object_property_set_int(OBJECT(&s->cpu[n].core), "reset-cbar",
106 bc->peri_base, errp)) {
107 return;
108 }
109
110 /* start powered off if not enabled */
111 if (!object_property_set_bool(OBJECT(&s->cpu[n].core),
112 "start-powered-off",
113 n >= s->enabled_cpus,
114 errp)) {
115 return;
116 }
117
118 if (!qdev_realize(DEVICE(&s->cpu[n].core), NULL, errp)) {
119 return;
120 }
121
122 /* Connect irq/fiq outputs from the interrupt controller. */
123 qdev_connect_gpio_out_named(DEVICE(&s->control), "irq", n,
124 qdev_get_gpio_in(DEVICE(&s->cpu[n].core), ARM_CPU_IRQ));
125 qdev_connect_gpio_out_named(DEVICE(&s->control), "fiq", n,
126 qdev_get_gpio_in(DEVICE(&s->cpu[n].core), ARM_CPU_FIQ));
127
128 /* Connect timers from the CPU to the interrupt controller */
129 qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_PHYS,
130 qdev_get_gpio_in_named(DEVICE(&s->control), "cntpnsirq", n));
131 qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_VIRT,
132 qdev_get_gpio_in_named(DEVICE(&s->control), "cntvirq", n));
133 qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_HYP,
134 qdev_get_gpio_in_named(DEVICE(&s->control), "cnthpirq", n));
135 qdev_connect_gpio_out(DEVICE(&s->cpu[n].core), GTIMER_SEC,
136 qdev_get_gpio_in_named(DEVICE(&s->control), "cntpsirq", n));
137 }
138 }
139
140 static void bcm283x_class_init(ObjectClass *oc, void *data)
141 {
142 DeviceClass *dc = DEVICE_CLASS(oc);
143
144 /* Reason: Must be wired up in code (see raspi_init() function) */
145 dc->user_creatable = false;
146 }
147
148 static void bcm2836_class_init(ObjectClass *oc, void *data)
149 {
150 DeviceClass *dc = DEVICE_CLASS(oc);
151 BCM283XClass *bc = BCM283X_CLASS(oc);
152
153 bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
154 bc->core_count = BCM283X_NCPUS;
155 bc->peri_base = 0x3f000000;
156 bc->ctrl_base = 0x40000000;
157 bc->clusterid = 0xf;
158 dc->realize = bcm2836_realize;
159 };
160
161 #ifdef TARGET_AARCH64
162 static void bcm2837_class_init(ObjectClass *oc, void *data)
163 {
164 DeviceClass *dc = DEVICE_CLASS(oc);
165 BCM283XClass *bc = BCM283X_CLASS(oc);
166
167 bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
168 bc->core_count = BCM283X_NCPUS;
169 bc->peri_base = 0x3f000000;
170 bc->ctrl_base = 0x40000000;
171 bc->clusterid = 0x0;
172 dc->realize = bcm2836_realize;
173 };
174 #endif
175
176 static const TypeInfo bcm283x_types[] = {
177 {
178 .name = TYPE_BCM2836,
179 .parent = TYPE_BCM283X,
180 .class_init = bcm2836_class_init,
181 #ifdef TARGET_AARCH64
182 }, {
183 .name = TYPE_BCM2837,
184 .parent = TYPE_BCM283X,
185 .class_init = bcm2837_class_init,
186 #endif
187 }, {
188 .name = TYPE_BCM283X,
189 .parent = TYPE_DEVICE,
190 .instance_size = sizeof(BCM283XState),
191 .instance_init = bcm2836_init,
192 .class_size = sizeof(BCM283XClass),
193 .class_init = bcm283x_class_init,
194 .abstract = true,
195 }
196 };
197
198 DEFINE_TYPES(bcm283x_types)