xref: /qemu/hw/arm/bcm2838_peripherals.c (revision 23c82c1daf30b3ed8d988f3f1d7fbb0557059ac6)
1 /*
2  * BCM2838 peripherals emulation
3  *
4  * Copyright (C) 2022 Ovchinnikov Vitalii <vitalii.ovchinnikov@auriga.com>
5  *
6  * SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #include "qemu/osdep.h"
10 #include "qapi/error.h"
11 #include "qemu/module.h"
12 #include "hw/arm/raspi_platform.h"
13 #include "hw/arm/bcm2838_peripherals.h"
14 
15 /* Lower peripheral base address on the VC (GPU) system bus */
16 #define BCM2838_VC_PERI_LOW_BASE 0x7c000000
17 
18 static void bcm2838_peripherals_init(Object *obj)
19 {
20     BCM2838PeripheralState *s = BCM2838_PERIPHERALS(obj);
21     BCM2838PeripheralClass *bc = BCM2838_PERIPHERALS_GET_CLASS(obj);
22 
23     /* Lower memory region for peripheral devices (exported to the Soc) */
24     memory_region_init(&s->peri_low_mr, obj, "bcm2838-peripherals",
25                        bc->peri_low_size);
26     sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->peri_low_mr);
27 
28 }
29 
30 static void bcm2838_peripherals_realize(DeviceState *dev, Error **errp)
31 {
32     BCM2838PeripheralState *s = BCM2838_PERIPHERALS(dev);
33     BCMSocPeripheralBaseState *s_base = BCM_SOC_PERIPHERALS_BASE(dev);
34 
35     bcm_soc_peripherals_common_realize(dev, errp);
36 
37     /* Map lower peripherals into the GPU address space */
38     memory_region_init_alias(&s->peri_low_mr_alias, OBJECT(s),
39                              "bcm2838-peripherals", &s->peri_low_mr, 0,
40                              memory_region_size(&s->peri_low_mr));
41     memory_region_add_subregion_overlap(&s_base->gpu_bus_mr,
42                                         BCM2838_VC_PERI_LOW_BASE,
43                                         &s->peri_low_mr_alias, 1);
44 
45 }
46 
47 static void bcm2838_peripherals_class_init(ObjectClass *oc, void *data)
48 {
49     DeviceClass *dc = DEVICE_CLASS(oc);
50     BCM2838PeripheralClass *bc = BCM2838_PERIPHERALS_CLASS(oc);
51     BCMSocPeripheralBaseClass *bc_base = BCM_SOC_PERIPHERALS_BASE_CLASS(oc);
52 
53     bc->peri_low_size = 0x2000000;
54     bc_base->peri_size = 0x1800000;
55     dc->realize = bcm2838_peripherals_realize;
56 }
57 
58 static const TypeInfo bcm2838_peripherals_type_info = {
59     .name = TYPE_BCM2838_PERIPHERALS,
60     .parent = TYPE_BCM_SOC_PERIPHERALS_BASE,
61     .instance_size = sizeof(BCM2838PeripheralState),
62     .instance_init = bcm2838_peripherals_init,
63     .class_size = sizeof(BCM2838PeripheralClass),
64     .class_init = bcm2838_peripherals_class_init,
65 };
66 
67 static void bcm2838_peripherals_register_types(void)
68 {
69     type_register_static(&bcm2838_peripherals_type_info);
70 }
71 
72 type_init(bcm2838_peripherals_register_types)
73