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 code is licensed under the GNU GPLv2 and later.
11 #include "qemu/osdep.h"
12 #include "qapi/error.h"
13 #include "qemu-common.h"
15 #include "hw/arm/bcm2836.h"
16 #include "hw/arm/raspi_platform.h"
17 #include "hw/sysbus.h"
18 #include "exec/address-spaces.h"
20 /* Peripheral base address seen by the CPU */
21 #define BCM2836_PERI_BASE 0x3F000000
23 /* "QA7" (Pi2) interrupt controller and mailboxes etc. */
24 #define BCM2836_CONTROL_BASE 0x40000000
32 static const BCM283XInfo bcm283x_socs
[] = {
35 .cpu_type
= ARM_CPU_TYPE_NAME("cortex-a7"),
41 .cpu_type
= ARM_CPU_TYPE_NAME("cortex-a53"),
47 static void bcm2836_init(Object
*obj
)
49 BCM283XState
*s
= BCM283X(obj
);
50 BCM283XClass
*bc
= BCM283X_GET_CLASS(obj
);
51 const BCM283XInfo
*info
= bc
->info
;
54 for (n
= 0; n
< BCM283X_NCPUS
; n
++) {
55 object_initialize(&s
->cpus
[n
], sizeof(s
->cpus
[n
]),
57 object_property_add_child(obj
, "cpu[*]", OBJECT(&s
->cpus
[n
]),
61 object_initialize(&s
->control
, sizeof(s
->control
), TYPE_BCM2836_CONTROL
);
62 object_property_add_child(obj
, "control", OBJECT(&s
->control
), NULL
);
63 qdev_set_parent_bus(DEVICE(&s
->control
), sysbus_get_default());
65 object_initialize(&s
->peripherals
, sizeof(s
->peripherals
),
66 TYPE_BCM2835_PERIPHERALS
);
67 object_property_add_child(obj
, "peripherals", OBJECT(&s
->peripherals
),
69 object_property_add_alias(obj
, "board-rev", OBJECT(&s
->peripherals
),
70 "board-rev", &error_abort
);
71 object_property_add_alias(obj
, "vcram-size", OBJECT(&s
->peripherals
),
72 "vcram-size", &error_abort
);
73 qdev_set_parent_bus(DEVICE(&s
->peripherals
), sysbus_get_default());
76 static void bcm2836_realize(DeviceState
*dev
, Error
**errp
)
78 BCM283XState
*s
= BCM283X(dev
);
79 BCM283XClass
*bc
= BCM283X_GET_CLASS(dev
);
80 const BCM283XInfo
*info
= bc
->info
;
85 /* common peripherals from bcm2835 */
87 obj
= object_property_get_link(OBJECT(dev
), "ram", &err
);
89 error_setg(errp
, "%s: required ram link not found: %s",
90 __func__
, error_get_pretty(err
));
94 object_property_add_const_link(OBJECT(&s
->peripherals
), "ram", obj
, &err
);
96 error_propagate(errp
, err
);
100 object_property_set_bool(OBJECT(&s
->peripherals
), true, "realized", &err
);
102 error_propagate(errp
, err
);
106 object_property_add_alias(OBJECT(s
), "sd-bus", OBJECT(&s
->peripherals
),
109 error_propagate(errp
, err
);
113 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s
->peripherals
), 0,
114 BCM2836_PERI_BASE
, 1);
116 /* bcm2836 interrupt controller (and mailboxes, etc.) */
117 object_property_set_bool(OBJECT(&s
->control
), true, "realized", &err
);
119 error_propagate(errp
, err
);
123 sysbus_mmio_map(SYS_BUS_DEVICE(&s
->control
), 0, BCM2836_CONTROL_BASE
);
125 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 0,
126 qdev_get_gpio_in_named(DEVICE(&s
->control
), "gpu-irq", 0));
127 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 1,
128 qdev_get_gpio_in_named(DEVICE(&s
->control
), "gpu-fiq", 0));
130 for (n
= 0; n
< BCM283X_NCPUS
; n
++) {
131 /* TODO: this should be converted to a property of ARM_CPU */
132 s
->cpus
[n
].mp_affinity
= (info
->clusterid
<< 8) | n
;
134 /* set periphbase/CBAR value for CPU-local registers */
135 object_property_set_int(OBJECT(&s
->cpus
[n
]),
136 BCM2836_PERI_BASE
+ MCORE_OFFSET
,
139 error_propagate(errp
, err
);
143 /* start powered off if not enabled */
144 object_property_set_bool(OBJECT(&s
->cpus
[n
]), n
>= s
->enabled_cpus
,
145 "start-powered-off", &err
);
147 error_propagate(errp
, err
);
151 object_property_set_bool(OBJECT(&s
->cpus
[n
]), true, "realized", &err
);
153 error_propagate(errp
, err
);
157 /* Connect irq/fiq outputs from the interrupt controller. */
158 qdev_connect_gpio_out_named(DEVICE(&s
->control
), "irq", n
,
159 qdev_get_gpio_in(DEVICE(&s
->cpus
[n
]), ARM_CPU_IRQ
));
160 qdev_connect_gpio_out_named(DEVICE(&s
->control
), "fiq", n
,
161 qdev_get_gpio_in(DEVICE(&s
->cpus
[n
]), ARM_CPU_FIQ
));
163 /* Connect timers from the CPU to the interrupt controller */
164 qdev_connect_gpio_out(DEVICE(&s
->cpus
[n
]), GTIMER_PHYS
,
165 qdev_get_gpio_in_named(DEVICE(&s
->control
), "cntpnsirq", n
));
166 qdev_connect_gpio_out(DEVICE(&s
->cpus
[n
]), GTIMER_VIRT
,
167 qdev_get_gpio_in_named(DEVICE(&s
->control
), "cntvirq", n
));
168 qdev_connect_gpio_out(DEVICE(&s
->cpus
[n
]), GTIMER_HYP
,
169 qdev_get_gpio_in_named(DEVICE(&s
->control
), "cnthpirq", n
));
170 qdev_connect_gpio_out(DEVICE(&s
->cpus
[n
]), GTIMER_SEC
,
171 qdev_get_gpio_in_named(DEVICE(&s
->control
), "cntpsirq", n
));
175 static Property bcm2836_props
[] = {
176 DEFINE_PROP_UINT32("enabled-cpus", BCM283XState
, enabled_cpus
,
178 DEFINE_PROP_END_OF_LIST()
181 static void bcm283x_class_init(ObjectClass
*oc
, void *data
)
183 DeviceClass
*dc
= DEVICE_CLASS(oc
);
184 BCM283XClass
*bc
= BCM283X_CLASS(oc
);
187 dc
->realize
= bcm2836_realize
;
188 dc
->props
= bcm2836_props
;
191 static const TypeInfo bcm283x_type_info
= {
192 .name
= TYPE_BCM283X
,
193 .parent
= TYPE_DEVICE
,
194 .instance_size
= sizeof(BCM283XState
),
195 .instance_init
= bcm2836_init
,
196 .class_size
= sizeof(BCM283XClass
),
200 static void bcm2836_register_types(void)
204 type_register_static(&bcm283x_type_info
);
205 for (i
= 0; i
< ARRAY_SIZE(bcm283x_socs
); i
++) {
207 .name
= bcm283x_socs
[i
].name
,
208 .parent
= TYPE_BCM283X
,
209 .class_init
= bcm283x_class_init
,
210 .class_data
= (void *) &bcm283x_socs
[i
],
216 type_init(bcm2836_register_types
)