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