root / hw / arm11mpcore.c @ d36b66f7
History | View | Annotate | Download (8.4 kB)
1 | f7c70325 | Paul Brook | /*
|
---|---|---|---|
2 | f7c70325 | Paul Brook | * ARM11MPCore internal peripheral emulation.
|
3 | f7c70325 | Paul Brook | *
|
4 | f7c70325 | Paul Brook | * Copyright (c) 2006-2007 CodeSourcery.
|
5 | f7c70325 | Paul Brook | * Written by Paul Brook
|
6 | f7c70325 | Paul Brook | *
|
7 | 8e31bf38 | Matthew Fernandez | * This code is licensed under the GPL.
|
8 | f7c70325 | Paul Brook | */
|
9 | f7c70325 | Paul Brook | |
10 | 2a6ab1e3 | Peter Maydell | #include "sysbus.h" |
11 | 2a6ab1e3 | Peter Maydell | #include "qemu-timer.h" |
12 | 2a6ab1e3 | Peter Maydell | |
13 | 2a6ab1e3 | Peter Maydell | /* MPCore private memory region. */
|
14 | 2a6ab1e3 | Peter Maydell | |
15 | 2a6ab1e3 | Peter Maydell | typedef struct mpcore_priv_state { |
16 | 2e9dfe20 | Peter Maydell | SysBusDevice busdev; |
17 | 2a6ab1e3 | Peter Maydell | uint32_t scu_control; |
18 | 2a6ab1e3 | Peter Maydell | int iomemtype;
|
19 | 2a6ab1e3 | Peter Maydell | uint32_t old_timer_status[8];
|
20 | 2a6ab1e3 | Peter Maydell | uint32_t num_cpu; |
21 | 2a6ab1e3 | Peter Maydell | MemoryRegion iomem; |
22 | 2a6ab1e3 | Peter Maydell | MemoryRegion container; |
23 | 2a6ab1e3 | Peter Maydell | DeviceState *mptimer; |
24 | 2e9dfe20 | Peter Maydell | DeviceState *gic; |
25 | a32134aa | Mark Langsdorf | uint32_t num_irq; |
26 | 2a6ab1e3 | Peter Maydell | } mpcore_priv_state; |
27 | 2a6ab1e3 | Peter Maydell | |
28 | 2a6ab1e3 | Peter Maydell | /* Per-CPU private memory mapped IO. */
|
29 | 2a6ab1e3 | Peter Maydell | |
30 | a8170e5e | Avi Kivity | static uint64_t mpcore_scu_read(void *opaque, hwaddr offset, |
31 | 2a6ab1e3 | Peter Maydell | unsigned size)
|
32 | 2a6ab1e3 | Peter Maydell | { |
33 | 2a6ab1e3 | Peter Maydell | mpcore_priv_state *s = (mpcore_priv_state *)opaque; |
34 | 2a6ab1e3 | Peter Maydell | int id;
|
35 | 2a6ab1e3 | Peter Maydell | /* SCU */
|
36 | 2a6ab1e3 | Peter Maydell | switch (offset) {
|
37 | 2a6ab1e3 | Peter Maydell | case 0x00: /* Control. */ |
38 | 2a6ab1e3 | Peter Maydell | return s->scu_control;
|
39 | 2a6ab1e3 | Peter Maydell | case 0x04: /* Configuration. */ |
40 | 2a6ab1e3 | Peter Maydell | id = ((1 << s->num_cpu) - 1) << 4; |
41 | 2a6ab1e3 | Peter Maydell | return id | (s->num_cpu - 1); |
42 | 2a6ab1e3 | Peter Maydell | case 0x08: /* CPU status. */ |
43 | 2a6ab1e3 | Peter Maydell | return 0; |
44 | 2a6ab1e3 | Peter Maydell | case 0x0c: /* Invalidate all. */ |
45 | 2a6ab1e3 | Peter Maydell | return 0; |
46 | 2a6ab1e3 | Peter Maydell | default:
|
47 | f9fe7bda | Peter Maydell | qemu_log_mask(LOG_GUEST_ERROR, |
48 | f9fe7bda | Peter Maydell | "mpcore_priv_read: Bad offset %x\n", (int)offset); |
49 | f9fe7bda | Peter Maydell | return 0; |
50 | 2a6ab1e3 | Peter Maydell | } |
51 | 2a6ab1e3 | Peter Maydell | } |
52 | 2a6ab1e3 | Peter Maydell | |
53 | a8170e5e | Avi Kivity | static void mpcore_scu_write(void *opaque, hwaddr offset, |
54 | 2a6ab1e3 | Peter Maydell | uint64_t value, unsigned size)
|
55 | 2a6ab1e3 | Peter Maydell | { |
56 | 2a6ab1e3 | Peter Maydell | mpcore_priv_state *s = (mpcore_priv_state *)opaque; |
57 | 2a6ab1e3 | Peter Maydell | /* SCU */
|
58 | 2a6ab1e3 | Peter Maydell | switch (offset) {
|
59 | 2a6ab1e3 | Peter Maydell | case 0: /* Control register. */ |
60 | 2a6ab1e3 | Peter Maydell | s->scu_control = value & 1;
|
61 | 2a6ab1e3 | Peter Maydell | break;
|
62 | 2a6ab1e3 | Peter Maydell | case 0x0c: /* Invalidate all. */ |
63 | 2a6ab1e3 | Peter Maydell | /* This is a no-op as cache is not emulated. */
|
64 | 2a6ab1e3 | Peter Maydell | break;
|
65 | 2a6ab1e3 | Peter Maydell | default:
|
66 | f9fe7bda | Peter Maydell | qemu_log_mask(LOG_GUEST_ERROR, |
67 | f9fe7bda | Peter Maydell | "mpcore_priv_read: Bad offset %x\n", (int)offset); |
68 | 2a6ab1e3 | Peter Maydell | } |
69 | 2a6ab1e3 | Peter Maydell | } |
70 | 2a6ab1e3 | Peter Maydell | |
71 | 2a6ab1e3 | Peter Maydell | static const MemoryRegionOps mpcore_scu_ops = { |
72 | 2a6ab1e3 | Peter Maydell | .read = mpcore_scu_read, |
73 | 2a6ab1e3 | Peter Maydell | .write = mpcore_scu_write, |
74 | 2a6ab1e3 | Peter Maydell | .endianness = DEVICE_NATIVE_ENDIAN, |
75 | 2a6ab1e3 | Peter Maydell | }; |
76 | 2a6ab1e3 | Peter Maydell | |
77 | 2e9dfe20 | Peter Maydell | static void mpcore_priv_set_irq(void *opaque, int irq, int level) |
78 | 2a6ab1e3 | Peter Maydell | { |
79 | 2a6ab1e3 | Peter Maydell | mpcore_priv_state *s = (mpcore_priv_state *)opaque; |
80 | 2e9dfe20 | Peter Maydell | qemu_set_irq(qdev_get_gpio_in(s->gic, irq), level); |
81 | 2a6ab1e3 | Peter Maydell | } |
82 | 2a6ab1e3 | Peter Maydell | |
83 | 2a6ab1e3 | Peter Maydell | static void mpcore_priv_map_setup(mpcore_priv_state *s) |
84 | 2a6ab1e3 | Peter Maydell | { |
85 | 2a6ab1e3 | Peter Maydell | int i;
|
86 | 2e9dfe20 | Peter Maydell | SysBusDevice *gicbusdev = sysbus_from_qdev(s->gic); |
87 | 2a6ab1e3 | Peter Maydell | SysBusDevice *busdev = sysbus_from_qdev(s->mptimer); |
88 | 2a6ab1e3 | Peter Maydell | memory_region_init(&s->container, "mpcode-priv-container", 0x2000); |
89 | 2a6ab1e3 | Peter Maydell | memory_region_init_io(&s->iomem, &mpcore_scu_ops, s, "mpcore-scu", 0x100); |
90 | 2a6ab1e3 | Peter Maydell | memory_region_add_subregion(&s->container, 0, &s->iomem);
|
91 | 2a6ab1e3 | Peter Maydell | /* GIC CPU interfaces: "current CPU" at 0x100, then specific CPUs
|
92 | 2a6ab1e3 | Peter Maydell | * at 0x200, 0x300...
|
93 | 2a6ab1e3 | Peter Maydell | */
|
94 | 2a6ab1e3 | Peter Maydell | for (i = 0; i < (s->num_cpu + 1); i++) { |
95 | a8170e5e | Avi Kivity | hwaddr offset = 0x100 + (i * 0x100); |
96 | 2e9dfe20 | Peter Maydell | memory_region_add_subregion(&s->container, offset, |
97 | 2e9dfe20 | Peter Maydell | sysbus_mmio_get_region(gicbusdev, i + 1));
|
98 | 2a6ab1e3 | Peter Maydell | } |
99 | 2a6ab1e3 | Peter Maydell | /* Add the regions for timer and watchdog for "current CPU" and
|
100 | 2a6ab1e3 | Peter Maydell | * for each specific CPU.
|
101 | 2a6ab1e3 | Peter Maydell | */
|
102 | 2a6ab1e3 | Peter Maydell | for (i = 0; i < (s->num_cpu + 1) * 2; i++) { |
103 | 2a6ab1e3 | Peter Maydell | /* Timers at 0x600, 0x700, ...; watchdogs at 0x620, 0x720, ... */
|
104 | a8170e5e | Avi Kivity | hwaddr offset = 0x600 + (i >> 1) * 0x100 + (i & 1) * 0x20; |
105 | 2a6ab1e3 | Peter Maydell | memory_region_add_subregion(&s->container, offset, |
106 | 2a6ab1e3 | Peter Maydell | sysbus_mmio_get_region(busdev, i)); |
107 | 2a6ab1e3 | Peter Maydell | } |
108 | 2e9dfe20 | Peter Maydell | memory_region_add_subregion(&s->container, 0x1000,
|
109 | 2e9dfe20 | Peter Maydell | sysbus_mmio_get_region(gicbusdev, 0));
|
110 | 2e9dfe20 | Peter Maydell | /* Wire up the interrupt from each watchdog and timer.
|
111 | 2e9dfe20 | Peter Maydell | * For each core the timer is PPI 29 and the watchdog PPI 30.
|
112 | 2e9dfe20 | Peter Maydell | */
|
113 | 2e9dfe20 | Peter Maydell | for (i = 0; i < s->num_cpu; i++) { |
114 | 2e9dfe20 | Peter Maydell | int ppibase = (s->num_irq - 32) + i * 32; |
115 | 2e9dfe20 | Peter Maydell | sysbus_connect_irq(busdev, i * 2,
|
116 | 2e9dfe20 | Peter Maydell | qdev_get_gpio_in(s->gic, ppibase + 29));
|
117 | 2e9dfe20 | Peter Maydell | sysbus_connect_irq(busdev, i * 2 + 1, |
118 | 2e9dfe20 | Peter Maydell | qdev_get_gpio_in(s->gic, ppibase + 30));
|
119 | 2a6ab1e3 | Peter Maydell | } |
120 | 2a6ab1e3 | Peter Maydell | } |
121 | 2a6ab1e3 | Peter Maydell | |
122 | 2a6ab1e3 | Peter Maydell | static int mpcore_priv_init(SysBusDevice *dev) |
123 | 2a6ab1e3 | Peter Maydell | { |
124 | 2e9dfe20 | Peter Maydell | mpcore_priv_state *s = FROM_SYSBUS(mpcore_priv_state, dev); |
125 | 2e9dfe20 | Peter Maydell | |
126 | 2e9dfe20 | Peter Maydell | s->gic = qdev_create(NULL, "arm_gic"); |
127 | 2e9dfe20 | Peter Maydell | qdev_prop_set_uint32(s->gic, "num-cpu", s->num_cpu);
|
128 | 2e9dfe20 | Peter Maydell | qdev_prop_set_uint32(s->gic, "num-irq", s->num_irq);
|
129 | 306a571a | Peter Maydell | /* Request the legacy 11MPCore GIC behaviour: */
|
130 | 306a571a | Peter Maydell | qdev_prop_set_uint32(s->gic, "revision", 0); |
131 | 2e9dfe20 | Peter Maydell | qdev_init_nofail(s->gic); |
132 | 2e9dfe20 | Peter Maydell | |
133 | 2e9dfe20 | Peter Maydell | /* Pass through outbound IRQ lines from the GIC */
|
134 | 2e9dfe20 | Peter Maydell | sysbus_pass_irq(dev, sysbus_from_qdev(s->gic)); |
135 | 2e9dfe20 | Peter Maydell | |
136 | 2e9dfe20 | Peter Maydell | /* Pass through inbound GPIO lines to the GIC */
|
137 | 2e9dfe20 | Peter Maydell | qdev_init_gpio_in(&s->busdev.qdev, mpcore_priv_set_irq, s->num_irq - 32);
|
138 | 2a6ab1e3 | Peter Maydell | |
139 | 2a6ab1e3 | Peter Maydell | s->mptimer = qdev_create(NULL, "arm_mptimer"); |
140 | 2a6ab1e3 | Peter Maydell | qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu);
|
141 | 2a6ab1e3 | Peter Maydell | qdev_init_nofail(s->mptimer); |
142 | 2a6ab1e3 | Peter Maydell | mpcore_priv_map_setup(s); |
143 | 2a6ab1e3 | Peter Maydell | sysbus_init_mmio(dev, &s->container); |
144 | 2a6ab1e3 | Peter Maydell | return 0; |
145 | 2a6ab1e3 | Peter Maydell | } |
146 | f7c70325 | Paul Brook | |
147 | f7c70325 | Paul Brook | /* Dummy PIC to route IRQ lines. The baseboard has 4 independent IRQ
|
148 | f7c70325 | Paul Brook | controllers. The output of these, plus some of the raw input lines
|
149 | f7c70325 | Paul Brook | are fed into a single SMP-aware interrupt controller on the CPU. */
|
150 | f7c70325 | Paul Brook | typedef struct { |
151 | f7c70325 | Paul Brook | SysBusDevice busdev; |
152 | f7c70325 | Paul Brook | SysBusDevice *priv; |
153 | f7c70325 | Paul Brook | qemu_irq cpuic[32];
|
154 | f7c70325 | Paul Brook | qemu_irq rvic[4][64]; |
155 | f7c70325 | Paul Brook | uint32_t num_cpu; |
156 | f7c70325 | Paul Brook | } mpcore_rirq_state; |
157 | f7c70325 | Paul Brook | |
158 | f7c70325 | Paul Brook | /* Map baseboard IRQs onto CPU IRQ lines. */
|
159 | f7c70325 | Paul Brook | static const int mpcore_irq_map[32] = { |
160 | f7c70325 | Paul Brook | -1, -1, -1, -1, 1, 2, -1, -1, |
161 | f7c70325 | Paul Brook | -1, -1, 6, -1, 4, 5, -1, -1, |
162 | f7c70325 | Paul Brook | -1, 14, 15, 0, 7, 8, -1, -1, |
163 | f7c70325 | Paul Brook | -1, -1, -1, -1, 9, 3, -1, -1, |
164 | f7c70325 | Paul Brook | }; |
165 | f7c70325 | Paul Brook | |
166 | f7c70325 | Paul Brook | static void mpcore_rirq_set_irq(void *opaque, int irq, int level) |
167 | f7c70325 | Paul Brook | { |
168 | f7c70325 | Paul Brook | mpcore_rirq_state *s = (mpcore_rirq_state *)opaque; |
169 | f7c70325 | Paul Brook | int i;
|
170 | f7c70325 | Paul Brook | |
171 | f7c70325 | Paul Brook | for (i = 0; i < 4; i++) { |
172 | f7c70325 | Paul Brook | qemu_set_irq(s->rvic[i][irq], level); |
173 | f7c70325 | Paul Brook | } |
174 | f7c70325 | Paul Brook | if (irq < 32) { |
175 | f7c70325 | Paul Brook | irq = mpcore_irq_map[irq]; |
176 | f7c70325 | Paul Brook | if (irq >= 0) { |
177 | f7c70325 | Paul Brook | qemu_set_irq(s->cpuic[irq], level); |
178 | f7c70325 | Paul Brook | } |
179 | f7c70325 | Paul Brook | } |
180 | f7c70325 | Paul Brook | } |
181 | f7c70325 | Paul Brook | |
182 | f7c70325 | Paul Brook | static int realview_mpcore_init(SysBusDevice *dev) |
183 | f7c70325 | Paul Brook | { |
184 | f7c70325 | Paul Brook | mpcore_rirq_state *s = FROM_SYSBUS(mpcore_rirq_state, dev); |
185 | f7c70325 | Paul Brook | DeviceState *gic; |
186 | f7c70325 | Paul Brook | DeviceState *priv; |
187 | f7c70325 | Paul Brook | int n;
|
188 | f7c70325 | Paul Brook | int i;
|
189 | f7c70325 | Paul Brook | |
190 | f7c70325 | Paul Brook | priv = qdev_create(NULL, "arm11mpcore_priv"); |
191 | f7c70325 | Paul Brook | qdev_prop_set_uint32(priv, "num-cpu", s->num_cpu);
|
192 | f7c70325 | Paul Brook | qdev_init_nofail(priv); |
193 | f7c70325 | Paul Brook | s->priv = sysbus_from_qdev(priv); |
194 | f7c70325 | Paul Brook | sysbus_pass_irq(dev, s->priv); |
195 | f7c70325 | Paul Brook | for (i = 0; i < 32; i++) { |
196 | f7c70325 | Paul Brook | s->cpuic[i] = qdev_get_gpio_in(priv, i); |
197 | f7c70325 | Paul Brook | } |
198 | f7c70325 | Paul Brook | /* ??? IRQ routing is hardcoded to "normal" mode. */
|
199 | f7c70325 | Paul Brook | for (n = 0; n < 4; n++) { |
200 | f7c70325 | Paul Brook | gic = sysbus_create_simple("realview_gic", 0x10040000 + n * 0x10000, |
201 | f7c70325 | Paul Brook | s->cpuic[10 + n]);
|
202 | f7c70325 | Paul Brook | for (i = 0; i < 64; i++) { |
203 | f7c70325 | Paul Brook | s->rvic[n][i] = qdev_get_gpio_in(gic, i); |
204 | f7c70325 | Paul Brook | } |
205 | f7c70325 | Paul Brook | } |
206 | f7c70325 | Paul Brook | qdev_init_gpio_in(&dev->qdev, mpcore_rirq_set_irq, 64);
|
207 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, sysbus_mmio_get_region(s->priv, 0));
|
208 | f7c70325 | Paul Brook | return 0; |
209 | f7c70325 | Paul Brook | } |
210 | f7c70325 | Paul Brook | |
211 | 999e12bb | Anthony Liguori | static Property mpcore_rirq_properties[] = {
|
212 | 0f58a188 | Peter Maydell | DEFINE_PROP_UINT32("num-cpu", mpcore_rirq_state, num_cpu, 1), |
213 | 999e12bb | Anthony Liguori | DEFINE_PROP_END_OF_LIST(), |
214 | f7c70325 | Paul Brook | }; |
215 | f7c70325 | Paul Brook | |
216 | 999e12bb | Anthony Liguori | static void mpcore_rirq_class_init(ObjectClass *klass, void *data) |
217 | 999e12bb | Anthony Liguori | { |
218 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
219 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
220 | 999e12bb | Anthony Liguori | |
221 | 999e12bb | Anthony Liguori | k->init = realview_mpcore_init; |
222 | 39bffca2 | Anthony Liguori | dc->props = mpcore_rirq_properties; |
223 | 999e12bb | Anthony Liguori | } |
224 | 999e12bb | Anthony Liguori | |
225 | 39bffca2 | Anthony Liguori | static TypeInfo mpcore_rirq_info = {
|
226 | 39bffca2 | Anthony Liguori | .name = "realview_mpcore",
|
227 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
228 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(mpcore_rirq_state),
|
229 | 39bffca2 | Anthony Liguori | .class_init = mpcore_rirq_class_init, |
230 | 999e12bb | Anthony Liguori | }; |
231 | 999e12bb | Anthony Liguori | |
232 | 999e12bb | Anthony Liguori | static Property mpcore_priv_properties[] = {
|
233 | 999e12bb | Anthony Liguori | DEFINE_PROP_UINT32("num-cpu", mpcore_priv_state, num_cpu, 1), |
234 | 0f58a188 | Peter Maydell | /* The ARM11 MPCORE TRM says the on-chip controller may have
|
235 | 0f58a188 | Peter Maydell | * anything from 0 to 224 external interrupt IRQ lines (with another
|
236 | 0f58a188 | Peter Maydell | * 32 internal). We default to 32+32, which is the number provided by
|
237 | 0f58a188 | Peter Maydell | * the ARM11 MPCore test chip in the Realview Versatile Express
|
238 | 0f58a188 | Peter Maydell | * coretile. Other boards may differ and should set this property
|
239 | 0f58a188 | Peter Maydell | * appropriately. Some Linux kernels may not boot if the hardware
|
240 | 0f58a188 | Peter Maydell | * has more IRQ lines than the kernel expects.
|
241 | 0f58a188 | Peter Maydell | */
|
242 | 0f58a188 | Peter Maydell | DEFINE_PROP_UINT32("num-irq", mpcore_priv_state, num_irq, 64), |
243 | 999e12bb | Anthony Liguori | DEFINE_PROP_END_OF_LIST(), |
244 | 999e12bb | Anthony Liguori | }; |
245 | 999e12bb | Anthony Liguori | |
246 | 999e12bb | Anthony Liguori | static void mpcore_priv_class_init(ObjectClass *klass, void *data) |
247 | 999e12bb | Anthony Liguori | { |
248 | 39bffca2 | Anthony Liguori | DeviceClass *dc = DEVICE_CLASS(klass); |
249 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
250 | 999e12bb | Anthony Liguori | |
251 | 999e12bb | Anthony Liguori | k->init = mpcore_priv_init; |
252 | 39bffca2 | Anthony Liguori | dc->props = mpcore_priv_properties; |
253 | 999e12bb | Anthony Liguori | } |
254 | 999e12bb | Anthony Liguori | |
255 | 39bffca2 | Anthony Liguori | static TypeInfo mpcore_priv_info = {
|
256 | 39bffca2 | Anthony Liguori | .name = "arm11mpcore_priv",
|
257 | 39bffca2 | Anthony Liguori | .parent = TYPE_SYS_BUS_DEVICE, |
258 | 39bffca2 | Anthony Liguori | .instance_size = sizeof(mpcore_priv_state),
|
259 | 39bffca2 | Anthony Liguori | .class_init = mpcore_priv_class_init, |
260 | f7c70325 | Paul Brook | }; |
261 | f7c70325 | Paul Brook | |
262 | 83f7d43a | Andreas Färber | static void arm11mpcore_register_types(void) |
263 | f7c70325 | Paul Brook | { |
264 | 39bffca2 | Anthony Liguori | type_register_static(&mpcore_rirq_info); |
265 | 39bffca2 | Anthony Liguori | type_register_static(&mpcore_priv_info); |
266 | f7c70325 | Paul Brook | } |
267 | f7c70325 | Paul Brook | |
268 | 83f7d43a | Andreas Färber | type_init(arm11mpcore_register_types) |