]> git.proxmox.com Git - mirror_qemu.git/blame - hw/cpu/arm11mpcore.c
arm11mpcore: Split off RealView MPCore
[mirror_qemu.git] / hw / cpu / arm11mpcore.c
CommitLineData
f7c70325
PB
1/*
2 * ARM11MPCore internal peripheral emulation.
3 *
4 * Copyright (c) 2006-2007 CodeSourcery.
5 * Written by Paul Brook
6 *
8e31bf38 7 * This code is licensed under the GPL.
f7c70325
PB
8 */
9
7b960dc3 10#include "hw/cpu/arm11mpcore.h"
306476ea 11#include "hw/intc/realview_gic.h"
2a6ab1e3 12
2a6ab1e3 13
2e9dfe20 14static void mpcore_priv_set_irq(void *opaque, int irq, int level)
2a6ab1e3 15{
845769fc 16 ARM11MPCorePriveState *s = (ARM11MPCorePriveState *)opaque;
08602ac5
AF
17
18 qemu_set_irq(qdev_get_gpio_in(DEVICE(&s->gic), irq), level);
2a6ab1e3
PM
19}
20
845769fc 21static void mpcore_priv_map_setup(ARM11MPCorePriveState *s)
2a6ab1e3
PM
22{
23 int i;
53cb9a1c 24 SysBusDevice *scubusdev = SYS_BUS_DEVICE(&s->scu);
08602ac5
AF
25 DeviceState *gicdev = DEVICE(&s->gic);
26 SysBusDevice *gicbusdev = SYS_BUS_DEVICE(&s->gic);
27 SysBusDevice *timerbusdev = SYS_BUS_DEVICE(&s->mptimer);
28 SysBusDevice *wdtbusdev = SYS_BUS_DEVICE(&s->wdtimer);
53cb9a1c
AF
29
30 memory_region_add_subregion(&s->container, 0,
31 sysbus_mmio_get_region(scubusdev, 0));
2a6ab1e3
PM
32 /* GIC CPU interfaces: "current CPU" at 0x100, then specific CPUs
33 * at 0x200, 0x300...
34 */
35 for (i = 0; i < (s->num_cpu + 1); i++) {
a8170e5e 36 hwaddr offset = 0x100 + (i * 0x100);
2e9dfe20
PM
37 memory_region_add_subregion(&s->container, offset,
38 sysbus_mmio_get_region(gicbusdev, i + 1));
2a6ab1e3
PM
39 }
40 /* Add the regions for timer and watchdog for "current CPU" and
41 * for each specific CPU.
42 */
cde4577f 43 for (i = 0; i < (s->num_cpu + 1); i++) {
2a6ab1e3 44 /* Timers at 0x600, 0x700, ...; watchdogs at 0x620, 0x720, ... */
cde4577f 45 hwaddr offset = 0x600 + i * 0x100;
2a6ab1e3 46 memory_region_add_subregion(&s->container, offset,
cde4577f
PC
47 sysbus_mmio_get_region(timerbusdev, i));
48 memory_region_add_subregion(&s->container, offset + 0x20,
49 sysbus_mmio_get_region(wdtbusdev, i));
2a6ab1e3 50 }
2e9dfe20
PM
51 memory_region_add_subregion(&s->container, 0x1000,
52 sysbus_mmio_get_region(gicbusdev, 0));
53 /* Wire up the interrupt from each watchdog and timer.
54 * For each core the timer is PPI 29 and the watchdog PPI 30.
55 */
56 for (i = 0; i < s->num_cpu; i++) {
57 int ppibase = (s->num_irq - 32) + i * 32;
cde4577f 58 sysbus_connect_irq(timerbusdev, i,
08602ac5 59 qdev_get_gpio_in(gicdev, ppibase + 29));
cde4577f 60 sysbus_connect_irq(wdtbusdev, i,
08602ac5 61 qdev_get_gpio_in(gicdev, ppibase + 30));
2a6ab1e3
PM
62 }
63}
64
08602ac5 65static void mpcore_priv_realize(DeviceState *dev, Error **errp)
2a6ab1e3 66{
08602ac5 67 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
56fc0281 68 ARM11MPCorePriveState *s = ARM11MPCORE_PRIV(dev);
53cb9a1c 69 DeviceState *scudev = DEVICE(&s->scu);
08602ac5
AF
70 DeviceState *gicdev = DEVICE(&s->gic);
71 DeviceState *mptimerdev = DEVICE(&s->mptimer);
72 DeviceState *wdtimerdev = DEVICE(&s->wdtimer);
73 Error *err = NULL;
53cb9a1c
AF
74
75 qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu);
08602ac5
AF
76 object_property_set_bool(OBJECT(&s->scu), true, "realized", &err);
77 if (err != NULL) {
78 error_propagate(errp, err);
79 return;
80 }
2e9dfe20 81
08602ac5
AF
82 qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
83 qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
84 object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
85 if (err != NULL) {
86 error_propagate(errp, err);
87 return;
88 }
2e9dfe20
PM
89
90 /* Pass through outbound IRQ lines from the GIC */
08602ac5 91 sysbus_pass_irq(sbd, SYS_BUS_DEVICE(&s->gic));
2e9dfe20
PM
92
93 /* Pass through inbound GPIO lines to the GIC */
56fc0281 94 qdev_init_gpio_in(dev, mpcore_priv_set_irq, s->num_irq - 32);
2a6ab1e3 95
08602ac5
AF
96 qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu);
97 object_property_set_bool(OBJECT(&s->mptimer), true, "realized", &err);
98 if (err != NULL) {
99 error_propagate(errp, err);
100 return;
101 }
cde4577f 102
08602ac5
AF
103 qdev_prop_set_uint32(wdtimerdev, "num-cpu", s->num_cpu);
104 object_property_set_bool(OBJECT(&s->wdtimer), true, "realized", &err);
105 if (err != NULL) {
106 error_propagate(errp, err);
107 return;
108 }
cde4577f 109
2a6ab1e3 110 mpcore_priv_map_setup(s);
2a6ab1e3 111}
f7c70325 112
2c42c3a0
AF
113static void mpcore_priv_initfn(Object *obj)
114{
115 SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
116 ARM11MPCorePriveState *s = ARM11MPCORE_PRIV(obj);
117
118 memory_region_init(&s->container, OBJECT(s),
119 "mpcore-priv-container", 0x2000);
120 sysbus_init_mmio(sbd, &s->container);
53cb9a1c
AF
121
122 object_initialize(&s->scu, sizeof(s->scu), TYPE_ARM11_SCU);
123 qdev_set_parent_bus(DEVICE(&s->scu), sysbus_get_default());
08602ac5
AF
124
125 object_initialize(&s->gic, sizeof(s->gic), TYPE_ARM_GIC);
126 qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
127 /* Request the legacy 11MPCore GIC behaviour: */
128 qdev_prop_set_uint32(DEVICE(&s->gic), "revision", 0);
129
130 object_initialize(&s->mptimer, sizeof(s->mptimer), TYPE_ARM_MPTIMER);
131 qdev_set_parent_bus(DEVICE(&s->mptimer), sysbus_get_default());
132
133 object_initialize(&s->wdtimer, sizeof(s->wdtimer), TYPE_ARM_MPTIMER);
134 qdev_set_parent_bus(DEVICE(&s->wdtimer), sysbus_get_default());
2c42c3a0
AF
135}
136
999e12bb 137static Property mpcore_priv_properties[] = {
845769fc 138 DEFINE_PROP_UINT32("num-cpu", ARM11MPCorePriveState, num_cpu, 1),
0f58a188
PM
139 /* The ARM11 MPCORE TRM says the on-chip controller may have
140 * anything from 0 to 224 external interrupt IRQ lines (with another
141 * 32 internal). We default to 32+32, which is the number provided by
142 * the ARM11 MPCore test chip in the Realview Versatile Express
143 * coretile. Other boards may differ and should set this property
144 * appropriately. Some Linux kernels may not boot if the hardware
145 * has more IRQ lines than the kernel expects.
146 */
845769fc 147 DEFINE_PROP_UINT32("num-irq", ARM11MPCorePriveState, num_irq, 64),
999e12bb
AL
148 DEFINE_PROP_END_OF_LIST(),
149};
150
151static void mpcore_priv_class_init(ObjectClass *klass, void *data)
152{
39bffca2 153 DeviceClass *dc = DEVICE_CLASS(klass);
999e12bb 154
08602ac5 155 dc->realize = mpcore_priv_realize;
39bffca2 156 dc->props = mpcore_priv_properties;
999e12bb
AL
157}
158
8c43a6f0 159static const TypeInfo mpcore_priv_info = {
56fc0281 160 .name = TYPE_ARM11MPCORE_PRIV,
39bffca2 161 .parent = TYPE_SYS_BUS_DEVICE,
845769fc 162 .instance_size = sizeof(ARM11MPCorePriveState),
2c42c3a0 163 .instance_init = mpcore_priv_initfn,
39bffca2 164 .class_init = mpcore_priv_class_init,
f7c70325
PB
165};
166
83f7d43a 167static void arm11mpcore_register_types(void)
f7c70325 168{
39bffca2 169 type_register_static(&mpcore_priv_info);
f7c70325
PB
170}
171
83f7d43a 172type_init(arm11mpcore_register_types)