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 #define DEFAULT_VCRAM_SIZE 0x4000000
18 static void bcm2835_init(Object
*obj
)
20 BCM2835State
*s
= BCM2835(obj
);
22 object_initialize(&s
->cpu
, sizeof(s
->cpu
), "arm1176-" TYPE_ARM_CPU
);
23 object_property_add_child(obj
, "cpu", OBJECT(&s
->cpu
), &error_abort
);
25 object_initialize(&s
->peripherals
, sizeof(s
->peripherals
),
26 TYPE_BCM2835_PERIPHERALS
);
27 object_property_add_child(obj
, "peripherals", OBJECT(&s
->peripherals
),
29 qdev_set_parent_bus(DEVICE(&s
->peripherals
), sysbus_get_default());
32 static void bcm2835_realize(DeviceState
*dev
, Error
**errp
)
34 BCM2835State
*s
= BCM2835(dev
);
37 /* common peripherals from bcm2835 */
38 object_property_set_bool(OBJECT(&s
->peripherals
), true, "realized", &err
);
40 error_propagate(errp
, err
);
44 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s
->peripherals
), 0,
45 BCM2835_PERI_BASE
, 1);
47 object_property_set_bool(OBJECT(&s
->cpu
), true, "realized", &err
);
49 error_report_err(err
);
53 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 0,
54 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
55 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 1,
56 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
60 static Property bcm2835_props
[] = {
61 DEFINE_PROP_UINT32("vcram-size", BCM2835State
, vcram_size
, 0),
62 DEFINE_PROP_END_OF_LIST()
65 static void bcm2835_class_init(ObjectClass
*oc
, void *data
)
67 DeviceClass
*dc
= DEVICE_CLASS(oc
);
69 dc
->props
= bcm2835_props
;
70 dc
->realize
= bcm2835_realize
;
73 * Reason: creates an ARM CPU, thus use after free(), see
74 * arm_cpu_class_init()
76 dc
->cannot_destroy_with_object_finalize_yet
= true;
79 static const TypeInfo bcm2835_type_info
= {
81 .parent
= TYPE_SYS_BUS_DEVICE
,
82 .instance_size
= sizeof(BCM2835State
),
83 .instance_init
= bcm2835_init
,
84 .class_init
= bcm2835_class_init
,
87 static void bcm2835_register_types(void)
89 type_register_static(&bcm2835_type_info
);
92 type_init(bcm2835_register_types
)