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 "hw/arm/bcm2835.h"
12 #include "hw/arm/raspi_platform.h"
13 #include "hw/sysbus.h"
14 #include "exec/address-spaces.h"
16 static void bcm2835_init(Object
*obj
)
18 BCM2835State
*s
= BCM2835(obj
);
20 object_initialize(&s
->cpu
, sizeof(s
->cpu
), "arm1176-" TYPE_ARM_CPU
);
21 object_property_add_child(obj
, "cpu", OBJECT(&s
->cpu
), &error_abort
);
23 object_initialize(&s
->peripherals
, sizeof(s
->peripherals
),
24 TYPE_BCM2835_PERIPHERALS
);
25 object_property_add_child(obj
, "peripherals", OBJECT(&s
->peripherals
),
27 qdev_set_parent_bus(DEVICE(&s
->peripherals
), sysbus_get_default());
30 static void bcm2835_realize(DeviceState
*dev
, Error
**errp
)
32 BCM2835State
*s
= BCM2835(dev
);
35 /* common peripherals from bcm2835 */
36 object_property_set_int(OBJECT(&s
->peripherals
), s
->vcram_size
,
39 error_propagate(errp
, err
);
43 object_property_set_bool(OBJECT(&s
->peripherals
), true, "realized", &err
);
45 error_propagate(errp
, err
);
49 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s
->peripherals
), 0,
50 BCM2835_PERI_BASE
, 1);
52 object_property_set_bool(OBJECT(&s
->cpu
), true, "realized", &err
);
54 error_report_err(err
);
58 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 0,
59 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
60 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 1,
61 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
65 static Property bcm2835_props
[] = {
66 DEFINE_PROP_UINT32("vcram-size", BCM2835State
, vcram_size
, 0),
67 DEFINE_PROP_END_OF_LIST()
70 static void bcm2835_class_init(ObjectClass
*oc
, void *data
)
72 DeviceClass
*dc
= DEVICE_CLASS(oc
);
74 dc
->props
= bcm2835_props
;
75 dc
->realize
= bcm2835_realize
;
78 * Reason: creates an ARM CPU, thus use after free(), see
79 * arm_cpu_class_init()
81 dc
->cannot_destroy_with_object_finalize_yet
= true;
84 static const TypeInfo bcm2835_type_info
= {
86 .parent
= TYPE_SYS_BUS_DEVICE
,
87 .instance_size
= sizeof(BCM2835State
),
88 .instance_init
= bcm2835_init
,
89 .class_init
= bcm2835_class_init
,
92 static void bcm2835_register_types(void)
94 type_register_static(&bcm2835_type_info
);
97 type_init(bcm2835_register_types
)