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"
13 #include "hw/arm/bcm2835.h"
14 #include "hw/arm/raspi_platform.h"
15 #include "hw/sysbus.h"
16 #include "exec/address-spaces.h"
17 #include "qapi/error.h" /* error_abort */
19 /* Peripheral base address seen by the CPU */
20 #define BCM2835_PERI_BASE 0x20000000
22 static void bcm2835_init(Object
*obj
)
24 BCM2835State
*s
= BCM2835(obj
);
26 object_initialize(&s
->cpu
, sizeof(s
->cpu
), "arm1176-" TYPE_ARM_CPU
);
27 object_property_add_child(obj
, "cpu", OBJECT(&s
->cpu
), &error_abort
);
29 object_initialize(&s
->peripherals
, sizeof(s
->peripherals
),
30 TYPE_BCM2835_PERIPHERALS
);
31 object_property_add_child(obj
, "peripherals", OBJECT(&s
->peripherals
),
33 object_property_add_alias(obj
, "board-rev", OBJECT(&s
->peripherals
),
34 "board-rev", &error_abort
);
35 object_property_add_alias(obj
, "vcram-size", OBJECT(&s
->peripherals
),
36 "vcram-size", &error_abort
);
37 qdev_set_parent_bus(DEVICE(&s
->peripherals
), sysbus_get_default());
40 static void bcm2835_realize(DeviceState
*dev
, Error
**errp
)
42 BCM2835State
*s
= BCM2835(dev
);
46 /* common peripherals from bcm2835 */
47 obj
= object_property_get_link(OBJECT(dev
), "ram", &err
);
49 error_setg(errp
, "%s: required ram link not found: %s",
50 __func__
, error_get_pretty(err
));
54 object_property_add_const_link(OBJECT(&s
->peripherals
), "ram", obj
, &err
);
56 error_propagate(errp
, err
);
60 object_property_set_bool(OBJECT(&s
->peripherals
), true, "realized", &err
);
62 error_propagate(errp
, err
);
66 object_property_add_alias(OBJECT(s
), "sd-bus", OBJECT(&s
->peripherals
),
69 error_propagate(errp
, err
);
73 sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s
->peripherals
), 0,
74 BCM2835_PERI_BASE
, 1);
76 object_property_set_bool(OBJECT(&s
->cpu
), true, "realized", &err
);
78 error_report_err(err
);
82 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 0,
83 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_IRQ
));
84 sysbus_connect_irq(SYS_BUS_DEVICE(&s
->peripherals
), 1,
85 qdev_get_gpio_in(DEVICE(&s
->cpu
), ARM_CPU_FIQ
));
89 static void bcm2835_class_init(ObjectClass
*oc
, void *data
)
91 DeviceClass
*dc
= DEVICE_CLASS(oc
);
93 dc
->realize
= bcm2835_realize
;
96 * Reason: creates an ARM CPU, thus use after free(), see
97 * arm_cpu_class_init()
99 dc
->cannot_destroy_with_object_finalize_yet
= true;
102 static const TypeInfo bcm2835_type_info
= {
103 .name
= TYPE_BCM2835
,
104 .parent
= TYPE_SYS_BUS_DEVICE
,
105 .instance_size
= sizeof(BCM2835State
),
106 .instance_init
= bcm2835_init
,
107 .class_init
= bcm2835_class_init
,
110 static void bcm2835_register_types(void)
112 type_register_static(&bcm2835_type_info
);
115 type_init(bcm2835_register_types
)