]> git.proxmox.com Git - mirror_qemu.git/blame - hw/cpu/a9mpcore.c
typedefs: Separate incomplete types and function types
[mirror_qemu.git] / hw / cpu / a9mpcore.c
CommitLineData
f7c70325
PB
1/*
2 * Cortex-A9MPCore internal peripheral emulation.
3 *
4 * Copyright (c) 2009 CodeSourcery.
b12080cd
PM
5 * Copyright (c) 2011 Linaro Limited.
6 * Written by Paul Brook, Peter Maydell.
f7c70325 7 *
8e31bf38 8 * This code is licensed under the GPL.
f7c70325
PB
9 */
10
17b7f2db 11#include "qemu/osdep.h"
da34e65c 12#include "qapi/error.h"
0b8fa32f 13#include "qemu/module.h"
de4c2dcf 14#include "hw/cpu/a9mpcore.h"
7d0c99a9 15#include "qom/cpu.h"
b12080cd 16
ddd76165
PM
17static void a9mp_priv_set_irq(void *opaque, int irq, int level)
18{
845769fc 19 A9MPPrivState *s = (A9MPPrivState *)opaque;
9b5f952b
AF
20
21 qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level);
ddd76165
PM
22}
23
753bc6e9
AF
24static void a9mp_priv_initfn(Object *obj)
25{
26 A9MPPrivState *s = A9MPCORE_PRIV(obj);
27
28 memory_region_init(&s->container, obj, "a9mp-priv-container", 0x2000);
29 sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->container);
9b5f952b 30
2ba486e7 31 sysbus_init_child_obj(obj, "scu", &s->scu, sizeof(s->scu), TYPE_A9_SCU);
eb110bd8 32
2ba486e7 33 sysbus_init_child_obj(obj, "gic", &s->gic, sizeof(s->gic), TYPE_ARM_GIC);
4c25f365 34
2ba486e7
TH
35 sysbus_init_child_obj(obj, "gtimer", &s->gtimer, sizeof(s->gtimer),
36 TYPE_A9_GTIMER);
57e72f2a 37
2ba486e7
TH
38 sysbus_init_child_obj(obj, "mptimer", &s->mptimer, sizeof(s->mptimer),
39 TYPE_ARM_MPTIMER);
eb110bd8 40
2ba486e7
TH
41 sysbus_init_child_obj(obj, "wdt", &s->wdt, sizeof(s->wdt),
42 TYPE_ARM_MPTIMER);
753bc6e9
AF
43}
44
837cf101 45static void a9mp_priv_realize(DeviceState *dev, Error **errp)
b12080cd 46{
837cf101 47 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
5126fec7 48 A9MPPrivState *s = A9MPCORE_PRIV(dev);
57e72f2a
FL
49 DeviceState *scudev, *gicdev, *gtimerdev, *mptimerdev, *wdtdev;
50 SysBusDevice *scubusdev, *gicbusdev, *gtimerbusdev, *mptimerbusdev,
51 *wdtbusdev;
837cf101 52 Error *err = NULL;
b12080cd 53 int i;
4182bbb1
PM
54 bool has_el3;
55 Object *cpuobj;
b12080cd 56
4c25f365
PC
57 scudev = DEVICE(&s->scu);
58 qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu);
59 object_property_set_bool(OBJECT(&s->scu), true, "realized", &err);
60 if (err != NULL) {
61 error_propagate(errp, err);
62 return;
63 }
64 scubusdev = SYS_BUS_DEVICE(&s->scu);
65
9b5f952b
AF
66 gicdev = DEVICE(&s->gic);
67 qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
68 qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
4182bbb1
PM
69
70 /* Make the GIC's TZ support match the CPUs. We assume that
71 * either all the CPUs have TZ, or none do.
72 */
73 cpuobj = OBJECT(qemu_get_cpu(0));
6533a1fc 74 has_el3 = object_property_find(cpuobj, "has_el3", NULL) &&
4182bbb1
PM
75 object_property_get_bool(cpuobj, "has_el3", &error_abort);
76 qdev_prop_set_bit(gicdev, "has-security-extensions", has_el3);
77
837cf101
AF
78 object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
79 if (err != NULL) {
80 error_propagate(errp, err);
81 return;
82 }
9b5f952b 83 gicbusdev = SYS_BUS_DEVICE(&s->gic);
ddd76165
PM
84
85 /* Pass through outbound IRQ lines from the GIC */
837cf101 86 sysbus_pass_irq(sbd, gicbusdev);
ddd76165
PM
87
88 /* Pass through inbound GPIO lines to the GIC */
837cf101 89 qdev_init_gpio_in(dev, a9mp_priv_set_irq, s->num_irq - 32);
b12080cd 90
57e72f2a
FL
91 gtimerdev = DEVICE(&s->gtimer);
92 qdev_prop_set_uint32(gtimerdev, "num-cpu", s->num_cpu);
93 object_property_set_bool(OBJECT(&s->gtimer), true, "realized", &err);
94 if (err != NULL) {
95 error_propagate(errp, err);
96 return;
97 }
98 gtimerbusdev = SYS_BUS_DEVICE(&s->gtimer);
99
eb110bd8
AF
100 mptimerdev = DEVICE(&s->mptimer);
101 qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu);
837cf101
AF
102 object_property_set_bool(OBJECT(&s->mptimer), true, "realized", &err);
103 if (err != NULL) {
104 error_propagate(errp, err);
105 return;
106 }
d3053e6b 107 mptimerbusdev = SYS_BUS_DEVICE(&s->mptimer);
cde4577f 108
eb110bd8
AF
109 wdtdev = DEVICE(&s->wdt);
110 qdev_prop_set_uint32(wdtdev, "num-cpu", s->num_cpu);
837cf101
AF
111 object_property_set_bool(OBJECT(&s->wdt), true, "realized", &err);
112 if (err != NULL) {
113 error_propagate(errp, err);
114 return;
115 }
eb110bd8 116 wdtbusdev = SYS_BUS_DEVICE(&s->wdt);
b12080cd
PM
117
118 /* Memory map (addresses are offsets from PERIPHBASE):
119 * 0x0000-0x00ff -- Snoop Control Unit
120 * 0x0100-0x01ff -- GIC CPU interface
121 * 0x0200-0x02ff -- Global Timer
122 * 0x0300-0x05ff -- nothing
123 * 0x0600-0x06ff -- private timers and watchdogs
124 * 0x0700-0x0fff -- nothing
125 * 0x1000-0x1fff -- GIC Distributor
b12080cd 126 */
353575f0
PC
127 memory_region_add_subregion(&s->container, 0,
128 sysbus_mmio_get_region(scubusdev, 0));
b12080cd 129 /* GIC CPU interface */
ddd76165
PM
130 memory_region_add_subregion(&s->container, 0x100,
131 sysbus_mmio_get_region(gicbusdev, 1));
57e72f2a
FL
132 memory_region_add_subregion(&s->container, 0x200,
133 sysbus_mmio_get_region(gtimerbusdev, 0));
b12080cd
PM
134 /* Note that the A9 exposes only the "timer/watchdog for this core"
135 * memory region, not the "timer/watchdog for core X" ones 11MPcore has.
136 */
137 memory_region_add_subregion(&s->container, 0x600,
d3053e6b 138 sysbus_mmio_get_region(mptimerbusdev, 0));
b12080cd 139 memory_region_add_subregion(&s->container, 0x620,
cde4577f 140 sysbus_mmio_get_region(wdtbusdev, 0));
ddd76165
PM
141 memory_region_add_subregion(&s->container, 0x1000,
142 sysbus_mmio_get_region(gicbusdev, 0));
b12080cd 143
ddd76165 144 /* Wire up the interrupt from each watchdog and timer.
57e72f2a
FL
145 * For each core the global timer is PPI 27, the private
146 * timer is PPI 29 and the watchdog PPI 30.
ddd76165
PM
147 */
148 for (i = 0; i < s->num_cpu; i++) {
149 int ppibase = (s->num_irq - 32) + i * 32;
57e72f2a
FL
150 sysbus_connect_irq(gtimerbusdev, i,
151 qdev_get_gpio_in(gicdev, ppibase + 27));
d3053e6b 152 sysbus_connect_irq(mptimerbusdev, i,
9b5f952b 153 qdev_get_gpio_in(gicdev, ppibase + 29));
cde4577f 154 sysbus_connect_irq(wdtbusdev, i,
9b5f952b 155 qdev_get_gpio_in(gicdev, ppibase + 30));
b12080cd 156 }
b12080cd
PM
157}
158
39bffca2 159static Property a9mp_priv_properties[] = {
845769fc 160 DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1),
39bffca2
AL
161 /* The Cortex-A9MP may have anything from 0 to 224 external interrupt
162 * IRQ lines (with another 32 internal). We default to 64+32, which
163 * is the number provided by the Cortex-A9MP test chip in the
164 * Realview PBX-A9 and Versatile Express A9 development boards.
165 * Other boards may differ and should set this property appropriately.
166 */
845769fc 167 DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96),
39bffca2
AL
168 DEFINE_PROP_END_OF_LIST(),
169};
170
999e12bb
AL
171static void a9mp_priv_class_init(ObjectClass *klass, void *data)
172{
39bffca2 173 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 174
837cf101 175 dc->realize = a9mp_priv_realize;
39bffca2 176 dc->props = a9mp_priv_properties;
999e12bb
AL
177}
178
8c43a6f0 179static const TypeInfo a9mp_priv_info = {
5126fec7 180 .name = TYPE_A9MPCORE_PRIV,
39bffca2 181 .parent = TYPE_SYS_BUS_DEVICE,
845769fc 182 .instance_size = sizeof(A9MPPrivState),
753bc6e9 183 .instance_init = a9mp_priv_initfn,
39bffca2 184 .class_init = a9mp_priv_class_init,
f7c70325
PB
185};
186
83f7d43a 187static void a9mp_register_types(void)
f7c70325 188{
39bffca2 189 type_register_static(&a9mp_priv_info);
f7c70325
PB
190}
191
83f7d43a 192type_init(a9mp_register_types)