]>
Commit | Line | Data |
---|---|---|
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 | ||
b12080cd PM |
11 | #include "sysbus.h" |
12 | ||
b12080cd PM |
13 | /* A9MP private memory region. */ |
14 | ||
845769fc | 15 | typedef struct A9MPPrivState { |
ddd76165 | 16 | SysBusDevice busdev; |
b12080cd | 17 | uint32_t scu_control; |
78aca8a7 | 18 | uint32_t scu_status; |
b12080cd | 19 | uint32_t num_cpu; |
b12080cd | 20 | MemoryRegion scu_iomem; |
b12080cd PM |
21 | MemoryRegion container; |
22 | DeviceState *mptimer; | |
cde4577f | 23 | DeviceState *wdt; |
ddd76165 | 24 | DeviceState *gic; |
a32134aa | 25 | uint32_t num_irq; |
845769fc | 26 | } A9MPPrivState; |
b12080cd | 27 | |
a8170e5e | 28 | static uint64_t a9_scu_read(void *opaque, hwaddr offset, |
b12080cd PM |
29 | unsigned size) |
30 | { | |
845769fc | 31 | A9MPPrivState *s = (A9MPPrivState *)opaque; |
b12080cd PM |
32 | switch (offset) { |
33 | case 0x00: /* Control */ | |
34 | return s->scu_control; | |
35 | case 0x04: /* Configuration */ | |
36 | return (((1 << s->num_cpu) - 1) << 4) | (s->num_cpu - 1); | |
37 | case 0x08: /* CPU Power Status */ | |
78aca8a7 RH |
38 | return s->scu_status; |
39 | case 0x09: /* CPU status. */ | |
40 | return s->scu_status >> 8; | |
41 | case 0x0a: /* CPU status. */ | |
42 | return s->scu_status >> 16; | |
43 | case 0x0b: /* CPU status. */ | |
44 | return s->scu_status >> 24; | |
b12080cd PM |
45 | case 0x0c: /* Invalidate All Registers In Secure State */ |
46 | return 0; | |
47 | case 0x40: /* Filtering Start Address Register */ | |
48 | case 0x44: /* Filtering End Address Register */ | |
49 | /* RAZ/WI, like an implementation with only one AXI master */ | |
50 | return 0; | |
51 | case 0x50: /* SCU Access Control Register */ | |
52 | case 0x54: /* SCU Non-secure Access Control Register */ | |
53 | /* unimplemented, fall through */ | |
54 | default: | |
55 | return 0; | |
56 | } | |
57 | } | |
58 | ||
a8170e5e | 59 | static void a9_scu_write(void *opaque, hwaddr offset, |
b12080cd PM |
60 | uint64_t value, unsigned size) |
61 | { | |
845769fc | 62 | A9MPPrivState *s = (A9MPPrivState *)opaque; |
78aca8a7 RH |
63 | uint32_t mask; |
64 | uint32_t shift; | |
65 | switch (size) { | |
66 | case 1: | |
67 | mask = 0xff; | |
68 | break; | |
69 | case 2: | |
70 | mask = 0xffff; | |
71 | break; | |
72 | case 4: | |
73 | mask = 0xffffffff; | |
74 | break; | |
75 | default: | |
76 | fprintf(stderr, "Invalid size %u in write to a9 scu register %x\n", | |
c97338dc | 77 | size, (unsigned)offset); |
78aca8a7 RH |
78 | return; |
79 | } | |
80 | ||
b12080cd PM |
81 | switch (offset) { |
82 | case 0x00: /* Control */ | |
83 | s->scu_control = value & 1; | |
84 | break; | |
85 | case 0x4: /* Configuration: RO */ | |
86 | break; | |
78aca8a7 RH |
87 | case 0x08: case 0x09: case 0x0A: case 0x0B: /* Power Control */ |
88 | shift = (offset - 0x8) * 8; | |
89 | s->scu_status &= ~(mask << shift); | |
90 | s->scu_status |= ((value & mask) << shift); | |
91 | break; | |
b12080cd PM |
92 | case 0x0c: /* Invalidate All Registers In Secure State */ |
93 | /* no-op as we do not implement caches */ | |
94 | break; | |
95 | case 0x40: /* Filtering Start Address Register */ | |
96 | case 0x44: /* Filtering End Address Register */ | |
97 | /* RAZ/WI, like an implementation with only one AXI master */ | |
98 | break; | |
b12080cd PM |
99 | case 0x50: /* SCU Access Control Register */ |
100 | case 0x54: /* SCU Non-secure Access Control Register */ | |
101 | /* unimplemented, fall through */ | |
102 | default: | |
103 | break; | |
104 | } | |
105 | } | |
106 | ||
107 | static const MemoryRegionOps a9_scu_ops = { | |
108 | .read = a9_scu_read, | |
109 | .write = a9_scu_write, | |
110 | .endianness = DEVICE_NATIVE_ENDIAN, | |
111 | }; | |
112 | ||
b12080cd PM |
113 | static void a9mp_priv_reset(DeviceState *dev) |
114 | { | |
845769fc | 115 | A9MPPrivState *s = FROM_SYSBUS(A9MPPrivState, SYS_BUS_DEVICE(dev)); |
95959782 | 116 | |
b12080cd | 117 | s->scu_control = 0; |
b12080cd PM |
118 | } |
119 | ||
ddd76165 PM |
120 | static void a9mp_priv_set_irq(void *opaque, int irq, int level) |
121 | { | |
845769fc | 122 | A9MPPrivState *s = (A9MPPrivState *)opaque; |
ddd76165 PM |
123 | qemu_set_irq(qdev_get_gpio_in(s->gic, irq), level); |
124 | } | |
125 | ||
b12080cd PM |
126 | static int a9mp_priv_init(SysBusDevice *dev) |
127 | { | |
845769fc | 128 | A9MPPrivState *s = FROM_SYSBUS(A9MPPrivState, dev); |
cde4577f | 129 | SysBusDevice *timerbusdev, *wdtbusdev, *gicbusdev; |
b12080cd PM |
130 | int i; |
131 | ||
ddd76165 PM |
132 | s->gic = qdev_create(NULL, "arm_gic"); |
133 | qdev_prop_set_uint32(s->gic, "num-cpu", s->num_cpu); | |
134 | qdev_prop_set_uint32(s->gic, "num-irq", s->num_irq); | |
135 | qdev_init_nofail(s->gic); | |
1356b98d | 136 | gicbusdev = SYS_BUS_DEVICE(s->gic); |
ddd76165 PM |
137 | |
138 | /* Pass through outbound IRQ lines from the GIC */ | |
139 | sysbus_pass_irq(dev, gicbusdev); | |
140 | ||
141 | /* Pass through inbound GPIO lines to the GIC */ | |
142 | qdev_init_gpio_in(&s->busdev.qdev, a9mp_priv_set_irq, s->num_irq - 32); | |
b12080cd PM |
143 | |
144 | s->mptimer = qdev_create(NULL, "arm_mptimer"); | |
145 | qdev_prop_set_uint32(s->mptimer, "num-cpu", s->num_cpu); | |
146 | qdev_init_nofail(s->mptimer); | |
cde4577f PC |
147 | timerbusdev = SYS_BUS_DEVICE(s->mptimer); |
148 | ||
149 | s->wdt = qdev_create(NULL, "arm_mptimer"); | |
150 | qdev_prop_set_uint32(s->wdt, "num-cpu", s->num_cpu); | |
151 | qdev_init_nofail(s->wdt); | |
152 | wdtbusdev = SYS_BUS_DEVICE(s->wdt); | |
b12080cd PM |
153 | |
154 | /* Memory map (addresses are offsets from PERIPHBASE): | |
155 | * 0x0000-0x00ff -- Snoop Control Unit | |
156 | * 0x0100-0x01ff -- GIC CPU interface | |
157 | * 0x0200-0x02ff -- Global Timer | |
158 | * 0x0300-0x05ff -- nothing | |
159 | * 0x0600-0x06ff -- private timers and watchdogs | |
160 | * 0x0700-0x0fff -- nothing | |
161 | * 0x1000-0x1fff -- GIC Distributor | |
162 | * | |
163 | * We should implement the global timer but don't currently do so. | |
164 | */ | |
165 | memory_region_init(&s->container, "a9mp-priv-container", 0x2000); | |
166 | memory_region_init_io(&s->scu_iomem, &a9_scu_ops, s, "a9mp-scu", 0x100); | |
167 | memory_region_add_subregion(&s->container, 0, &s->scu_iomem); | |
168 | /* GIC CPU interface */ | |
ddd76165 PM |
169 | memory_region_add_subregion(&s->container, 0x100, |
170 | sysbus_mmio_get_region(gicbusdev, 1)); | |
b12080cd PM |
171 | /* Note that the A9 exposes only the "timer/watchdog for this core" |
172 | * memory region, not the "timer/watchdog for core X" ones 11MPcore has. | |
173 | */ | |
174 | memory_region_add_subregion(&s->container, 0x600, | |
cde4577f | 175 | sysbus_mmio_get_region(timerbusdev, 0)); |
b12080cd | 176 | memory_region_add_subregion(&s->container, 0x620, |
cde4577f | 177 | sysbus_mmio_get_region(wdtbusdev, 0)); |
ddd76165 PM |
178 | memory_region_add_subregion(&s->container, 0x1000, |
179 | sysbus_mmio_get_region(gicbusdev, 0)); | |
b12080cd PM |
180 | |
181 | sysbus_init_mmio(dev, &s->container); | |
182 | ||
ddd76165 PM |
183 | /* Wire up the interrupt from each watchdog and timer. |
184 | * For each core the timer is PPI 29 and the watchdog PPI 30. | |
185 | */ | |
186 | for (i = 0; i < s->num_cpu; i++) { | |
187 | int ppibase = (s->num_irq - 32) + i * 32; | |
cde4577f | 188 | sysbus_connect_irq(timerbusdev, i, |
ddd76165 | 189 | qdev_get_gpio_in(s->gic, ppibase + 29)); |
cde4577f | 190 | sysbus_connect_irq(wdtbusdev, i, |
ddd76165 | 191 | qdev_get_gpio_in(s->gic, ppibase + 30)); |
b12080cd PM |
192 | } |
193 | return 0; | |
194 | } | |
195 | ||
196 | static const VMStateDescription vmstate_a9mp_priv = { | |
197 | .name = "a9mpcore_priv", | |
95959782 PC |
198 | .version_id = 3, |
199 | .minimum_version_id = 3, | |
b12080cd | 200 | .fields = (VMStateField[]) { |
845769fc | 201 | VMSTATE_UINT32(scu_control, A9MPPrivState), |
845769fc | 202 | VMSTATE_UINT32_V(scu_status, A9MPPrivState, 2), |
b12080cd PM |
203 | VMSTATE_END_OF_LIST() |
204 | } | |
205 | }; | |
f7c70325 | 206 | |
39bffca2 | 207 | static Property a9mp_priv_properties[] = { |
845769fc | 208 | DEFINE_PROP_UINT32("num-cpu", A9MPPrivState, num_cpu, 1), |
39bffca2 AL |
209 | /* The Cortex-A9MP may have anything from 0 to 224 external interrupt |
210 | * IRQ lines (with another 32 internal). We default to 64+32, which | |
211 | * is the number provided by the Cortex-A9MP test chip in the | |
212 | * Realview PBX-A9 and Versatile Express A9 development boards. | |
213 | * Other boards may differ and should set this property appropriately. | |
214 | */ | |
845769fc | 215 | DEFINE_PROP_UINT32("num-irq", A9MPPrivState, num_irq, 96), |
39bffca2 AL |
216 | DEFINE_PROP_END_OF_LIST(), |
217 | }; | |
218 | ||
999e12bb AL |
219 | static void a9mp_priv_class_init(ObjectClass *klass, void *data) |
220 | { | |
39bffca2 | 221 | DeviceClass *dc = DEVICE_CLASS(klass); |
999e12bb AL |
222 | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
223 | ||
224 | k->init = a9mp_priv_init; | |
39bffca2 AL |
225 | dc->props = a9mp_priv_properties; |
226 | dc->vmsd = &vmstate_a9mp_priv; | |
227 | dc->reset = a9mp_priv_reset; | |
999e12bb AL |
228 | } |
229 | ||
8c43a6f0 | 230 | static const TypeInfo a9mp_priv_info = { |
39bffca2 AL |
231 | .name = "a9mpcore_priv", |
232 | .parent = TYPE_SYS_BUS_DEVICE, | |
845769fc | 233 | .instance_size = sizeof(A9MPPrivState), |
39bffca2 | 234 | .class_init = a9mp_priv_class_init, |
f7c70325 PB |
235 | }; |
236 | ||
83f7d43a | 237 | static void a9mp_register_types(void) |
f7c70325 | 238 | { |
39bffca2 | 239 | type_register_static(&a9mp_priv_info); |
f7c70325 PB |
240 | } |
241 | ||
83f7d43a | 242 | type_init(a9mp_register_types) |