2 * Raspberry Pi emulation (c) 2012 Gregory Estrade
3 * Upstreaming code cleanup [including bcm2835_*] (c) 2013 Jan Petrous
5 * Rasperry Pi 2 emulation and refactoring Copyright (c) 2015, Microsoft
6 * Written by Andrew Baumann
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.
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "qemu/module.h"
15 #include "hw/arm/bcm2836.h"
16 #include "hw/arm/raspi_platform.h"
17 #include "hw/sysbus.h"
18 #include "target/arm/cpu-qom.h"
19 #include "target/arm/gtimer.h"
23 DeviceClass parent_class
;
28 hwaddr peri_base
; /* Peripheral base address seen by the CPU */
29 hwaddr ctrl_base
; /* Interrupt controller and mailboxes etc. */
33 static Property bcm2836_enabled_cores_property
=
34 DEFINE_PROP_UINT32("enabled-cpus", BCM283XState
, enabled_cpus
, 0);
36 static void bcm2836_init(Object
*obj
)
38 BCM283XState
*s
= BCM283X(obj
);
39 BCM283XClass
*bc
= BCM283X_GET_CLASS(obj
);
42 for (n
= 0; n
< bc
->core_count
; n
++) {
43 object_initialize_child(obj
, "cpu[*]", &s
->cpu
[n
].core
,
46 if (bc
->core_count
> 1) {
47 qdev_property_add_static(DEVICE(obj
), &bcm2836_enabled_cores_property
);
48 qdev_prop_set_uint32(DEVICE(obj
), "enabled-cpus", bc
->core_count
);
52 object_initialize_child(obj
, "control", &s
->control
,
53 TYPE_BCM2836_CONTROL
);
56 object_initialize_child(obj
, "peripherals", &s
->peripherals
,
57 TYPE_BCM2835_PERIPHERALS
);
58 object_property_add_alias(obj
, "board-rev", OBJECT(&s
->peripherals
),
60 object_property_add_alias(obj
, "command-line", OBJECT(&s
->peripherals
),
62 object_property_add_alias(obj
, "vcram-size", OBJECT(&s
->peripherals
),
66 static bool bcm283x_common_realize(DeviceState
*dev
, Error
**errp
)
68 BCM283XState
*s
= BCM283X(dev
);
69 BCM283XClass
*bc
= BCM283X_GET_CLASS(dev
);
72 /* common peripherals from bcm2835 */
74 obj
= object_property_get_link(OBJECT(dev
), "ram", &error_abort
);
76 object_property_add_const_link(OBJECT(&s
->peripherals
), "ram", obj
);
78 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->peripherals
), errp
)) {
82 object_property_add_alias(OBJECT(s
), "sd-bus", OBJECT(&s
->peripherals
),
85 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s
->peripherals
), 0,
90 static void bcm2835_realize(DeviceState
*dev
, Error
**errp
)
92 BCM283XState
*s
= BCM283X(dev
);
94 if (!bcm283x_common_realize(dev
, errp
)) {
98 if (!qdev_realize(DEVICE(&s
->cpu
[0].core
), NULL
, errp
)) {
102 /* Connect irq/fiq outputs from the interrupt controller. */
103 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 0,
104 qdev_get_gpio_in(DEVICE(&s
->cpu
[0].core
), ARM_CPU_IRQ
));
105 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 1,
106 qdev_get_gpio_in(DEVICE(&s
->cpu
[0].core
), ARM_CPU_FIQ
));
109 static void bcm2836_realize(DeviceState
*dev
, Error
**errp
)
111 BCM283XState
*s
= BCM283X(dev
);
112 BCM283XClass
*bc
= BCM283X_GET_CLASS(dev
);
115 if (!bcm283x_common_realize(dev
, errp
)) {
119 /* bcm2836 interrupt controller (and mailboxes, etc.) */
120 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->control
), errp
)) {
124 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->control
), 0, bc
->ctrl_base
);
126 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 0,
127 qdev_get_gpio_in_named(DEVICE(&s
->control
), "gpu-irq", 0));
128 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 1,
129 qdev_get_gpio_in_named(DEVICE(&s
->control
), "gpu-fiq", 0));
131 for (n
= 0; n
< BCM283X_NCPUS
; n
++) {
132 object_property_set_int(OBJECT(&s
->cpu
[n
].core
), "mp-affinity",
133 (bc
->clusterid
<< 8) | n
, &error_abort
);
135 /* set periphbase/CBAR value for CPU-local registers */
136 object_property_set_int(OBJECT(&s
->cpu
[n
].core
), "reset-cbar",
137 bc
->peri_base
, &error_abort
);
139 /* start powered off if not enabled */
140 object_property_set_bool(OBJECT(&s
->cpu
[n
].core
), "start-powered-off",
141 n
>= s
->enabled_cpus
, &error_abort
);
143 if (!qdev_realize(DEVICE(&s
->cpu
[n
].core
), NULL
, errp
)) {
147 /* Connect irq/fiq outputs from the interrupt controller. */
148 qdev_connect_gpio_out_named(DEVICE(&s
->control
), "irq", n
,
149 qdev_get_gpio_in(DEVICE(&s
->cpu
[n
].core
), ARM_CPU_IRQ
));
150 qdev_connect_gpio_out_named(DEVICE(&s
->control
), "fiq", n
,
151 qdev_get_gpio_in(DEVICE(&s
->cpu
[n
].core
), ARM_CPU_FIQ
));
153 /* Connect timers from the CPU to the interrupt controller */
154 qdev_connect_gpio_out(DEVICE(&s
->cpu
[n
].core
), GTIMER_PHYS
,
155 qdev_get_gpio_in_named(DEVICE(&s
->control
), "cntpnsirq", n
));
156 qdev_connect_gpio_out(DEVICE(&s
->cpu
[n
].core
), GTIMER_VIRT
,
157 qdev_get_gpio_in_named(DEVICE(&s
->control
), "cntvirq", n
));
158 qdev_connect_gpio_out(DEVICE(&s
->cpu
[n
].core
), GTIMER_HYP
,
159 qdev_get_gpio_in_named(DEVICE(&s
->control
), "cnthpirq", n
));
160 qdev_connect_gpio_out(DEVICE(&s
->cpu
[n
].core
), GTIMER_SEC
,
161 qdev_get_gpio_in_named(DEVICE(&s
->control
), "cntpsirq", n
));
165 static void bcm283x_class_init(ObjectClass
*oc
, void *data
)
167 DeviceClass
*dc
= DEVICE_CLASS(oc
);
169 /* Reason: Must be wired up in code (see raspi_init() function) */
170 dc
->user_creatable
= false;
173 static void bcm2835_class_init(ObjectClass
*oc
, void *data
)
175 DeviceClass
*dc
= DEVICE_CLASS(oc
);
176 BCM283XClass
*bc
= BCM283X_CLASS(oc
);
178 bc
->cpu_type
= ARM_CPU_TYPE_NAME("arm1176");
180 bc
->peri_base
= 0x20000000;
181 dc
->realize
= bcm2835_realize
;
184 static void bcm2836_class_init(ObjectClass
*oc
, void *data
)
186 DeviceClass
*dc
= DEVICE_CLASS(oc
);
187 BCM283XClass
*bc
= BCM283X_CLASS(oc
);
189 bc
->cpu_type
= ARM_CPU_TYPE_NAME("cortex-a7");
190 bc
->core_count
= BCM283X_NCPUS
;
191 bc
->peri_base
= 0x3f000000;
192 bc
->ctrl_base
= 0x40000000;
194 dc
->realize
= bcm2836_realize
;
197 #ifdef TARGET_AARCH64
198 static void bcm2837_class_init(ObjectClass
*oc
, void *data
)
200 DeviceClass
*dc
= DEVICE_CLASS(oc
);
201 BCM283XClass
*bc
= BCM283X_CLASS(oc
);
203 bc
->cpu_type
= ARM_CPU_TYPE_NAME("cortex-a53");
204 bc
->core_count
= BCM283X_NCPUS
;
205 bc
->peri_base
= 0x3f000000;
206 bc
->ctrl_base
= 0x40000000;
208 dc
->realize
= bcm2836_realize
;
212 static const TypeInfo bcm283x_types
[] = {
214 .name
= TYPE_BCM2835
,
215 .parent
= TYPE_BCM283X
,
216 .class_init
= bcm2835_class_init
,
218 .name
= TYPE_BCM2836
,
219 .parent
= TYPE_BCM283X
,
220 .class_init
= bcm2836_class_init
,
221 #ifdef TARGET_AARCH64
223 .name
= TYPE_BCM2837
,
224 .parent
= TYPE_BCM283X
,
225 .class_init
= bcm2837_class_init
,
228 .name
= TYPE_BCM283X
,
229 .parent
= TYPE_DEVICE
,
230 .instance_size
= sizeof(BCM283XState
),
231 .instance_init
= bcm2836_init
,
232 .class_size
= sizeof(BCM283XClass
),
233 .class_init
= bcm283x_class_init
,
238 DEFINE_TYPES(bcm283x_types
)