qdev: Convert bus-less devices to qdev_realize() with Coccinelle
[qemu/ar7.git] / hw / arm / armsse.c
blob9ddde339ec3ef54dbb63575e94d67022a2094431
1 /*
2 * Arm SSE (Subsystems for Embedded): IoTKit
4 * Copyright (c) 2018 Linaro Limited
5 * Written by Peter Maydell
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 or
9 * (at your option) any later version.
12 #include "qemu/osdep.h"
13 #include "qemu/log.h"
14 #include "qemu/module.h"
15 #include "qemu/bitops.h"
16 #include "qapi/error.h"
17 #include "trace.h"
18 #include "hw/sysbus.h"
19 #include "migration/vmstate.h"
20 #include "hw/registerfields.h"
21 #include "hw/arm/armsse.h"
22 #include "hw/arm/boot.h"
23 #include "hw/irq.h"
25 /* Format of the System Information block SYS_CONFIG register */
26 typedef enum SysConfigFormat {
27 IoTKitFormat,
28 SSE200Format,
29 } SysConfigFormat;
31 struct ARMSSEInfo {
32 const char *name;
33 int sram_banks;
34 int num_cpus;
35 uint32_t sys_version;
36 uint32_t cpuwait_rst;
37 SysConfigFormat sys_config_format;
38 bool has_mhus;
39 bool has_ppus;
40 bool has_cachectrl;
41 bool has_cpusecctrl;
42 bool has_cpuid;
43 Property *props;
46 static Property iotkit_properties[] = {
47 DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION,
48 MemoryRegion *),
49 DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64),
50 DEFINE_PROP_UINT32("MAINCLK", ARMSSE, mainclk_frq, 0),
51 DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 15),
52 DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000),
53 DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], true),
54 DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE, cpu_dsp[0], true),
55 DEFINE_PROP_END_OF_LIST()
58 static Property armsse_properties[] = {
59 DEFINE_PROP_LINK("memory", ARMSSE, board_memory, TYPE_MEMORY_REGION,
60 MemoryRegion *),
61 DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE, exp_numirq, 64),
62 DEFINE_PROP_UINT32("MAINCLK", ARMSSE, mainclk_frq, 0),
63 DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE, sram_addr_width, 15),
64 DEFINE_PROP_UINT32("init-svtor", ARMSSE, init_svtor, 0x10000000),
65 DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE, cpu_fpu[0], false),
66 DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE, cpu_dsp[0], false),
67 DEFINE_PROP_BOOL("CPU1_FPU", ARMSSE, cpu_fpu[1], true),
68 DEFINE_PROP_BOOL("CPU1_DSP", ARMSSE, cpu_dsp[1], true),
69 DEFINE_PROP_END_OF_LIST()
72 static const ARMSSEInfo armsse_variants[] = {
74 .name = TYPE_IOTKIT,
75 .sram_banks = 1,
76 .num_cpus = 1,
77 .sys_version = 0x41743,
78 .cpuwait_rst = 0,
79 .sys_config_format = IoTKitFormat,
80 .has_mhus = false,
81 .has_ppus = false,
82 .has_cachectrl = false,
83 .has_cpusecctrl = false,
84 .has_cpuid = false,
85 .props = iotkit_properties,
88 .name = TYPE_SSE200,
89 .sram_banks = 4,
90 .num_cpus = 2,
91 .sys_version = 0x22041743,
92 .cpuwait_rst = 2,
93 .sys_config_format = SSE200Format,
94 .has_mhus = true,
95 .has_ppus = true,
96 .has_cachectrl = true,
97 .has_cpusecctrl = true,
98 .has_cpuid = true,
99 .props = armsse_properties,
103 static uint32_t armsse_sys_config_value(ARMSSE *s, const ARMSSEInfo *info)
105 /* Return the SYS_CONFIG value for this SSE */
106 uint32_t sys_config;
108 switch (info->sys_config_format) {
109 case IoTKitFormat:
110 sys_config = 0;
111 sys_config = deposit32(sys_config, 0, 4, info->sram_banks);
112 sys_config = deposit32(sys_config, 4, 4, s->sram_addr_width - 12);
113 break;
114 case SSE200Format:
115 sys_config = 0;
116 sys_config = deposit32(sys_config, 0, 4, info->sram_banks);
117 sys_config = deposit32(sys_config, 4, 5, s->sram_addr_width);
118 sys_config = deposit32(sys_config, 24, 4, 2);
119 if (info->num_cpus > 1) {
120 sys_config = deposit32(sys_config, 10, 1, 1);
121 sys_config = deposit32(sys_config, 20, 4, info->sram_banks - 1);
122 sys_config = deposit32(sys_config, 28, 4, 2);
124 break;
125 default:
126 g_assert_not_reached();
128 return sys_config;
131 /* Clock frequency in HZ of the 32KHz "slow clock" */
132 #define S32KCLK (32 * 1000)
134 /* Is internal IRQ n shared between CPUs in a multi-core SSE ? */
135 static bool irq_is_common[32] = {
136 [0 ... 5] = true,
137 /* 6, 7: per-CPU MHU interrupts */
138 [8 ... 12] = true,
139 /* 13: per-CPU icache interrupt */
140 /* 14: reserved */
141 [15 ... 20] = true,
142 /* 21: reserved */
143 [22 ... 26] = true,
144 /* 27: reserved */
145 /* 28, 29: per-CPU CTI interrupts */
146 /* 30, 31: reserved */
150 * Create an alias region in @container of @size bytes starting at @base
151 * which mirrors the memory starting at @orig.
153 static void make_alias(ARMSSE *s, MemoryRegion *mr, MemoryRegion *container,
154 const char *name, hwaddr base, hwaddr size, hwaddr orig)
156 memory_region_init_alias(mr, NULL, name, container, orig, size);
157 /* The alias is even lower priority than unimplemented_device regions */
158 memory_region_add_subregion_overlap(container, base, mr, -1500);
161 static void irq_status_forwarder(void *opaque, int n, int level)
163 qemu_irq destirq = opaque;
165 qemu_set_irq(destirq, level);
168 static void nsccfg_handler(void *opaque, int n, int level)
170 ARMSSE *s = ARMSSE(opaque);
172 s->nsccfg = level;
175 static void armsse_forward_ppc(ARMSSE *s, const char *ppcname, int ppcnum)
177 /* Each of the 4 AHB and 4 APB PPCs that might be present in a
178 * system using the ARMSSE has a collection of control lines which
179 * are provided by the security controller and which we want to
180 * expose as control lines on the ARMSSE device itself, so the
181 * code using the ARMSSE can wire them up to the PPCs.
183 SplitIRQ *splitter = &s->ppc_irq_splitter[ppcnum];
184 DeviceState *armssedev = DEVICE(s);
185 DeviceState *dev_secctl = DEVICE(&s->secctl);
186 DeviceState *dev_splitter = DEVICE(splitter);
187 char *name;
189 name = g_strdup_printf("%s_nonsec", ppcname);
190 qdev_pass_gpios(dev_secctl, armssedev, name);
191 g_free(name);
192 name = g_strdup_printf("%s_ap", ppcname);
193 qdev_pass_gpios(dev_secctl, armssedev, name);
194 g_free(name);
195 name = g_strdup_printf("%s_irq_enable", ppcname);
196 qdev_pass_gpios(dev_secctl, armssedev, name);
197 g_free(name);
198 name = g_strdup_printf("%s_irq_clear", ppcname);
199 qdev_pass_gpios(dev_secctl, armssedev, name);
200 g_free(name);
202 /* irq_status is a little more tricky, because we need to
203 * split it so we can send it both to the security controller
204 * and to our OR gate for the NVIC interrupt line.
205 * Connect up the splitter's outputs, and create a GPIO input
206 * which will pass the line state to the input splitter.
208 name = g_strdup_printf("%s_irq_status", ppcname);
209 qdev_connect_gpio_out(dev_splitter, 0,
210 qdev_get_gpio_in_named(dev_secctl,
211 name, 0));
212 qdev_connect_gpio_out(dev_splitter, 1,
213 qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), ppcnum));
214 s->irq_status_in[ppcnum] = qdev_get_gpio_in(dev_splitter, 0);
215 qdev_init_gpio_in_named_with_opaque(armssedev, irq_status_forwarder,
216 s->irq_status_in[ppcnum], name, 1);
217 g_free(name);
220 static void armsse_forward_sec_resp_cfg(ARMSSE *s)
222 /* Forward the 3rd output from the splitter device as a
223 * named GPIO output of the armsse object.
225 DeviceState *dev = DEVICE(s);
226 DeviceState *dev_splitter = DEVICE(&s->sec_resp_splitter);
228 qdev_init_gpio_out_named(dev, &s->sec_resp_cfg, "sec_resp_cfg", 1);
229 s->sec_resp_cfg_in = qemu_allocate_irq(irq_status_forwarder,
230 s->sec_resp_cfg, 1);
231 qdev_connect_gpio_out(dev_splitter, 2, s->sec_resp_cfg_in);
234 static void armsse_init(Object *obj)
236 ARMSSE *s = ARMSSE(obj);
237 ARMSSEClass *asc = ARMSSE_GET_CLASS(obj);
238 const ARMSSEInfo *info = asc->info;
239 int i;
241 assert(info->sram_banks <= MAX_SRAM_BANKS);
242 assert(info->num_cpus <= SSE_MAX_CPUS);
244 memory_region_init(&s->container, obj, "armsse-container", UINT64_MAX);
246 for (i = 0; i < info->num_cpus; i++) {
248 * We put each CPU in its own cluster as they are logically
249 * distinct and may be configured differently.
251 char *name;
253 name = g_strdup_printf("cluster%d", i);
254 object_initialize_child(obj, name, &s->cluster[i], TYPE_CPU_CLUSTER);
255 qdev_prop_set_uint32(DEVICE(&s->cluster[i]), "cluster-id", i);
256 g_free(name);
258 name = g_strdup_printf("armv7m%d", i);
259 object_initialize_child(OBJECT(&s->cluster[i]), name, &s->armv7m[i],
260 TYPE_ARMV7M);
261 qdev_prop_set_string(DEVICE(&s->armv7m[i]), "cpu-type",
262 ARM_CPU_TYPE_NAME("cortex-m33"));
263 g_free(name);
264 name = g_strdup_printf("arm-sse-cpu-container%d", i);
265 memory_region_init(&s->cpu_container[i], obj, name, UINT64_MAX);
266 g_free(name);
267 if (i > 0) {
268 name = g_strdup_printf("arm-sse-container-alias%d", i);
269 memory_region_init_alias(&s->container_alias[i - 1], obj,
270 name, &s->container, 0, UINT64_MAX);
271 g_free(name);
275 object_initialize_child(obj, "secctl", &s->secctl, TYPE_IOTKIT_SECCTL);
276 object_initialize_child(obj, "apb-ppc0", &s->apb_ppc0, TYPE_TZ_PPC);
277 object_initialize_child(obj, "apb-ppc1", &s->apb_ppc1, TYPE_TZ_PPC);
278 for (i = 0; i < info->sram_banks; i++) {
279 char *name = g_strdup_printf("mpc%d", i);
280 object_initialize_child(obj, name, &s->mpc[i], TYPE_TZ_MPC);
281 g_free(name);
283 object_initialize_child(obj, "mpc-irq-orgate", &s->mpc_irq_orgate,
284 TYPE_OR_IRQ);
286 for (i = 0; i < IOTS_NUM_EXP_MPC + info->sram_banks; i++) {
287 char *name = g_strdup_printf("mpc-irq-splitter-%d", i);
288 SplitIRQ *splitter = &s->mpc_irq_splitter[i];
290 object_initialize_child(obj, name, splitter, TYPE_SPLIT_IRQ);
291 g_free(name);
293 object_initialize_child(obj, "timer0", &s->timer0, TYPE_CMSDK_APB_TIMER);
294 object_initialize_child(obj, "timer1", &s->timer1, TYPE_CMSDK_APB_TIMER);
295 object_initialize_child(obj, "s32ktimer", &s->s32ktimer,
296 TYPE_CMSDK_APB_TIMER);
297 object_initialize_child(obj, "dualtimer", &s->dualtimer,
298 TYPE_CMSDK_APB_DUALTIMER);
299 object_initialize_child(obj, "s32kwatchdog", &s->s32kwatchdog,
300 TYPE_CMSDK_APB_WATCHDOG);
301 object_initialize_child(obj, "nswatchdog", &s->nswatchdog,
302 TYPE_CMSDK_APB_WATCHDOG);
303 object_initialize_child(obj, "swatchdog", &s->swatchdog,
304 TYPE_CMSDK_APB_WATCHDOG);
305 object_initialize_child(obj, "armsse-sysctl", &s->sysctl,
306 TYPE_IOTKIT_SYSCTL);
307 object_initialize_child(obj, "armsse-sysinfo", &s->sysinfo,
308 TYPE_IOTKIT_SYSINFO);
309 if (info->has_mhus) {
310 object_initialize_child(obj, "mhu0", &s->mhu[0], TYPE_ARMSSE_MHU);
311 object_initialize_child(obj, "mhu1", &s->mhu[1], TYPE_ARMSSE_MHU);
313 if (info->has_ppus) {
314 for (i = 0; i < info->num_cpus; i++) {
315 char *name = g_strdup_printf("CPU%dCORE_PPU", i);
316 int ppuidx = CPU0CORE_PPU + i;
318 object_initialize_child(obj, name, &s->ppu[ppuidx],
319 TYPE_UNIMPLEMENTED_DEVICE);
320 g_free(name);
322 object_initialize_child(obj, "DBG_PPU", &s->ppu[DBG_PPU],
323 TYPE_UNIMPLEMENTED_DEVICE);
324 for (i = 0; i < info->sram_banks; i++) {
325 char *name = g_strdup_printf("RAM%d_PPU", i);
326 int ppuidx = RAM0_PPU + i;
328 object_initialize_child(obj, name, &s->ppu[ppuidx],
329 TYPE_UNIMPLEMENTED_DEVICE);
330 g_free(name);
333 if (info->has_cachectrl) {
334 for (i = 0; i < info->num_cpus; i++) {
335 char *name = g_strdup_printf("cachectrl%d", i);
337 object_initialize_child(obj, name, &s->cachectrl[i],
338 TYPE_UNIMPLEMENTED_DEVICE);
339 g_free(name);
342 if (info->has_cpusecctrl) {
343 for (i = 0; i < info->num_cpus; i++) {
344 char *name = g_strdup_printf("cpusecctrl%d", i);
346 object_initialize_child(obj, name, &s->cpusecctrl[i],
347 TYPE_UNIMPLEMENTED_DEVICE);
348 g_free(name);
351 if (info->has_cpuid) {
352 for (i = 0; i < info->num_cpus; i++) {
353 char *name = g_strdup_printf("cpuid%d", i);
355 object_initialize_child(obj, name, &s->cpuid[i],
356 TYPE_ARMSSE_CPUID);
357 g_free(name);
360 object_initialize_child(obj, "nmi-orgate", &s->nmi_orgate, TYPE_OR_IRQ);
361 object_initialize_child(obj, "ppc-irq-orgate", &s->ppc_irq_orgate,
362 TYPE_OR_IRQ);
363 object_initialize_child(obj, "sec-resp-splitter", &s->sec_resp_splitter,
364 TYPE_SPLIT_IRQ);
365 for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) {
366 char *name = g_strdup_printf("ppc-irq-splitter-%d", i);
367 SplitIRQ *splitter = &s->ppc_irq_splitter[i];
369 object_initialize_child(obj, name, splitter, TYPE_SPLIT_IRQ);
370 g_free(name);
372 if (info->num_cpus > 1) {
373 for (i = 0; i < ARRAY_SIZE(s->cpu_irq_splitter); i++) {
374 if (irq_is_common[i]) {
375 char *name = g_strdup_printf("cpu-irq-splitter%d", i);
376 SplitIRQ *splitter = &s->cpu_irq_splitter[i];
378 object_initialize_child(obj, name, splitter, TYPE_SPLIT_IRQ);
379 g_free(name);
385 static void armsse_exp_irq(void *opaque, int n, int level)
387 qemu_irq *irqarray = opaque;
389 qemu_set_irq(irqarray[n], level);
392 static void armsse_mpcexp_status(void *opaque, int n, int level)
394 ARMSSE *s = ARMSSE(opaque);
395 qemu_set_irq(s->mpcexp_status_in[n], level);
398 static qemu_irq armsse_get_common_irq_in(ARMSSE *s, int irqno)
401 * Return a qemu_irq which can be used to signal IRQ n to
402 * all CPUs in the SSE.
404 ARMSSEClass *asc = ARMSSE_GET_CLASS(s);
405 const ARMSSEInfo *info = asc->info;
407 assert(irq_is_common[irqno]);
409 if (info->num_cpus == 1) {
410 /* Only one CPU -- just connect directly to it */
411 return qdev_get_gpio_in(DEVICE(&s->armv7m[0]), irqno);
412 } else {
413 /* Connect to the splitter which feeds all CPUs */
414 return qdev_get_gpio_in(DEVICE(&s->cpu_irq_splitter[irqno]), 0);
418 static void map_ppu(ARMSSE *s, int ppuidx, const char *name, hwaddr addr)
420 /* Map a PPU unimplemented device stub */
421 DeviceState *dev = DEVICE(&s->ppu[ppuidx]);
423 qdev_prop_set_string(dev, "name", name);
424 qdev_prop_set_uint64(dev, "size", 0x1000);
425 sysbus_realize(SYS_BUS_DEVICE(dev), &error_fatal);
426 sysbus_mmio_map(SYS_BUS_DEVICE(&s->ppu[ppuidx]), 0, addr);
429 static void armsse_realize(DeviceState *dev, Error **errp)
431 ARMSSE *s = ARMSSE(dev);
432 ARMSSEClass *asc = ARMSSE_GET_CLASS(dev);
433 const ARMSSEInfo *info = asc->info;
434 int i;
435 MemoryRegion *mr;
436 Error *err = NULL;
437 SysBusDevice *sbd_apb_ppc0;
438 SysBusDevice *sbd_secctl;
439 DeviceState *dev_apb_ppc0;
440 DeviceState *dev_apb_ppc1;
441 DeviceState *dev_secctl;
442 DeviceState *dev_splitter;
443 uint32_t addr_width_max;
445 if (!s->board_memory) {
446 error_setg(errp, "memory property was not set");
447 return;
450 if (!s->mainclk_frq) {
451 error_setg(errp, "MAINCLK property was not set");
452 return;
455 /* max SRAM_ADDR_WIDTH: 24 - log2(SRAM_NUM_BANK) */
456 assert(is_power_of_2(info->sram_banks));
457 addr_width_max = 24 - ctz32(info->sram_banks);
458 if (s->sram_addr_width < 1 || s->sram_addr_width > addr_width_max) {
459 error_setg(errp, "SRAM_ADDR_WIDTH must be between 1 and %d",
460 addr_width_max);
461 return;
464 /* Handling of which devices should be available only to secure
465 * code is usually done differently for M profile than for A profile.
466 * Instead of putting some devices only into the secure address space,
467 * devices exist in both address spaces but with hard-wired security
468 * permissions that will cause the CPU to fault for non-secure accesses.
470 * The ARMSSE has an IDAU (Implementation Defined Access Unit),
471 * which specifies hard-wired security permissions for different
472 * areas of the physical address space. For the ARMSSE IDAU, the
473 * top 4 bits of the physical address are the IDAU region ID, and
474 * if bit 28 (ie the lowest bit of the ID) is 0 then this is an NS
475 * region, otherwise it is an S region.
477 * The various devices and RAMs are generally all mapped twice,
478 * once into a region that the IDAU defines as secure and once
479 * into a non-secure region. They sit behind either a Memory
480 * Protection Controller (for RAM) or a Peripheral Protection
481 * Controller (for devices), which allow a more fine grained
482 * configuration of whether non-secure accesses are permitted.
484 * (The other place that guest software can configure security
485 * permissions is in the architected SAU (Security Attribution
486 * Unit), which is entirely inside the CPU. The IDAU can upgrade
487 * the security attributes for a region to more restrictive than
488 * the SAU specifies, but cannot downgrade them.)
490 * 0x10000000..0x1fffffff alias of 0x00000000..0x0fffffff
491 * 0x20000000..0x2007ffff 32KB FPGA block RAM
492 * 0x30000000..0x3fffffff alias of 0x20000000..0x2fffffff
493 * 0x40000000..0x4000ffff base peripheral region 1
494 * 0x40010000..0x4001ffff CPU peripherals (none for ARMSSE)
495 * 0x40020000..0x4002ffff system control element peripherals
496 * 0x40080000..0x400fffff base peripheral region 2
497 * 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff
500 memory_region_add_subregion_overlap(&s->container, 0, s->board_memory, -2);
502 for (i = 0; i < info->num_cpus; i++) {
503 DeviceState *cpudev = DEVICE(&s->armv7m[i]);
504 Object *cpuobj = OBJECT(&s->armv7m[i]);
505 int j;
506 char *gpioname;
508 qdev_prop_set_uint32(cpudev, "num-irq", s->exp_numirq + 32);
510 * In real hardware the initial Secure VTOR is set from the INITSVTOR*
511 * registers in the IoT Kit System Control Register block. In QEMU
512 * we set the initial value here, and also the reset value of the
513 * sysctl register, from this object's QOM init-svtor property.
514 * If the guest changes the INITSVTOR* registers at runtime then the
515 * code in iotkit-sysctl.c will update the CPU init-svtor property
516 * (which will then take effect on the next CPU warm-reset).
518 * Note that typically a board using the SSE-200 will have a system
519 * control processor whose boot firmware initializes the INITSVTOR*
520 * registers before powering up the CPUs. QEMU doesn't emulate
521 * the control processor, so instead we behave in the way that the
522 * firmware does: the initial value should be set by the board code
523 * (using the init-svtor property on the ARMSSE object) to match
524 * whatever its firmware does.
526 qdev_prop_set_uint32(cpudev, "init-svtor", s->init_svtor);
528 * CPUs start powered down if the corresponding bit in the CPUWAIT
529 * register is 1. In real hardware the CPUWAIT register reset value is
530 * a configurable property of the SSE-200 (via the CPUWAIT0_RST and
531 * CPUWAIT1_RST parameters), but since all the boards we care about
532 * start CPU0 and leave CPU1 powered off, we hard-code that in
533 * info->cpuwait_rst for now. We can add QOM properties for this
534 * later if necessary.
536 if (extract32(info->cpuwait_rst, i, 1)) {
537 object_property_set_bool(cpuobj, true, "start-powered-off", &err);
538 if (err) {
539 error_propagate(errp, err);
540 return;
543 if (!s->cpu_fpu[i]) {
544 object_property_set_bool(cpuobj, false, "vfp", &err);
545 if (err) {
546 error_propagate(errp, err);
547 return;
550 if (!s->cpu_dsp[i]) {
551 object_property_set_bool(cpuobj, false, "dsp", &err);
552 if (err) {
553 error_propagate(errp, err);
554 return;
558 if (i > 0) {
559 memory_region_add_subregion_overlap(&s->cpu_container[i], 0,
560 &s->container_alias[i - 1], -1);
561 } else {
562 memory_region_add_subregion_overlap(&s->cpu_container[i], 0,
563 &s->container, -1);
565 object_property_set_link(cpuobj, OBJECT(&s->cpu_container[i]),
566 "memory", &err);
567 if (err) {
568 error_propagate(errp, err);
569 return;
571 object_property_set_link(cpuobj, OBJECT(s), "idau", &err);
572 if (err) {
573 error_propagate(errp, err);
574 return;
576 sysbus_realize(SYS_BUS_DEVICE(cpuobj), &err);
577 if (err) {
578 error_propagate(errp, err);
579 return;
582 * The cluster must be realized after the armv7m container, as
583 * the container's CPU object is only created on realize, and the
584 * CPU must exist and have been parented into the cluster before
585 * the cluster is realized.
587 qdev_realize(DEVICE(&s->cluster[i]), NULL, &err);
588 if (err) {
589 error_propagate(errp, err);
590 return;
593 /* Connect EXP_IRQ/EXP_CPUn_IRQ GPIOs to the NVIC's lines 32 and up */
594 s->exp_irqs[i] = g_new(qemu_irq, s->exp_numirq);
595 for (j = 0; j < s->exp_numirq; j++) {
596 s->exp_irqs[i][j] = qdev_get_gpio_in(cpudev, j + 32);
598 if (i == 0) {
599 gpioname = g_strdup("EXP_IRQ");
600 } else {
601 gpioname = g_strdup_printf("EXP_CPU%d_IRQ", i);
603 qdev_init_gpio_in_named_with_opaque(dev, armsse_exp_irq,
604 s->exp_irqs[i],
605 gpioname, s->exp_numirq);
606 g_free(gpioname);
609 /* Wire up the splitters that connect common IRQs to all CPUs */
610 if (info->num_cpus > 1) {
611 for (i = 0; i < ARRAY_SIZE(s->cpu_irq_splitter); i++) {
612 if (irq_is_common[i]) {
613 Object *splitter = OBJECT(&s->cpu_irq_splitter[i]);
614 DeviceState *devs = DEVICE(splitter);
615 int cpunum;
617 object_property_set_int(splitter, info->num_cpus,
618 "num-lines", &err);
619 if (err) {
620 error_propagate(errp, err);
621 return;
623 qdev_realize(DEVICE(splitter), NULL, &err);
624 if (err) {
625 error_propagate(errp, err);
626 return;
628 for (cpunum = 0; cpunum < info->num_cpus; cpunum++) {
629 DeviceState *cpudev = DEVICE(&s->armv7m[cpunum]);
631 qdev_connect_gpio_out(devs, cpunum,
632 qdev_get_gpio_in(cpudev, i));
638 /* Set up the big aliases first */
639 make_alias(s, &s->alias1, &s->container, "alias 1",
640 0x10000000, 0x10000000, 0x00000000);
641 make_alias(s, &s->alias2, &s->container,
642 "alias 2", 0x30000000, 0x10000000, 0x20000000);
643 /* The 0x50000000..0x5fffffff region is not a pure alias: it has
644 * a few extra devices that only appear there (generally the
645 * control interfaces for the protection controllers).
646 * We implement this by mapping those devices over the top of this
647 * alias MR at a higher priority. Some of the devices in this range
648 * are per-CPU, so we must put this alias in the per-cpu containers.
650 for (i = 0; i < info->num_cpus; i++) {
651 make_alias(s, &s->alias3[i], &s->cpu_container[i],
652 "alias 3", 0x50000000, 0x10000000, 0x40000000);
655 /* Security controller */
656 sysbus_realize(SYS_BUS_DEVICE(&s->secctl), &err);
657 if (err) {
658 error_propagate(errp, err);
659 return;
661 sbd_secctl = SYS_BUS_DEVICE(&s->secctl);
662 dev_secctl = DEVICE(&s->secctl);
663 sysbus_mmio_map(sbd_secctl, 0, 0x50080000);
664 sysbus_mmio_map(sbd_secctl, 1, 0x40080000);
666 s->nsc_cfg_in = qemu_allocate_irq(nsccfg_handler, s, 1);
667 qdev_connect_gpio_out_named(dev_secctl, "nsc_cfg", 0, s->nsc_cfg_in);
669 /* The sec_resp_cfg output from the security controller must be split into
670 * multiple lines, one for each of the PPCs within the ARMSSE and one
671 * that will be an output from the ARMSSE to the system.
673 object_property_set_int(OBJECT(&s->sec_resp_splitter), 3,
674 "num-lines", &err);
675 if (err) {
676 error_propagate(errp, err);
677 return;
679 qdev_realize(DEVICE(&s->sec_resp_splitter), NULL, &err);
680 if (err) {
681 error_propagate(errp, err);
682 return;
684 dev_splitter = DEVICE(&s->sec_resp_splitter);
685 qdev_connect_gpio_out_named(dev_secctl, "sec_resp_cfg", 0,
686 qdev_get_gpio_in(dev_splitter, 0));
688 /* Each SRAM bank lives behind its own Memory Protection Controller */
689 for (i = 0; i < info->sram_banks; i++) {
690 char *ramname = g_strdup_printf("armsse.sram%d", i);
691 SysBusDevice *sbd_mpc;
692 uint32_t sram_bank_size = 1 << s->sram_addr_width;
694 memory_region_init_ram(&s->sram[i], NULL, ramname,
695 sram_bank_size, &err);
696 g_free(ramname);
697 if (err) {
698 error_propagate(errp, err);
699 return;
701 object_property_set_link(OBJECT(&s->mpc[i]), OBJECT(&s->sram[i]),
702 "downstream", &err);
703 if (err) {
704 error_propagate(errp, err);
705 return;
707 sysbus_realize(SYS_BUS_DEVICE(&s->mpc[i]), &err);
708 if (err) {
709 error_propagate(errp, err);
710 return;
712 /* Map the upstream end of the MPC into the right place... */
713 sbd_mpc = SYS_BUS_DEVICE(&s->mpc[i]);
714 memory_region_add_subregion(&s->container,
715 0x20000000 + i * sram_bank_size,
716 sysbus_mmio_get_region(sbd_mpc, 1));
717 /* ...and its register interface */
718 memory_region_add_subregion(&s->container, 0x50083000 + i * 0x1000,
719 sysbus_mmio_get_region(sbd_mpc, 0));
722 /* We must OR together lines from the MPC splitters to go to the NVIC */
723 object_property_set_int(OBJECT(&s->mpc_irq_orgate),
724 IOTS_NUM_EXP_MPC + info->sram_banks,
725 "num-lines", &err);
726 if (err) {
727 error_propagate(errp, err);
728 return;
730 qdev_realize(DEVICE(&s->mpc_irq_orgate), NULL, &err);
731 if (err) {
732 error_propagate(errp, err);
733 return;
735 qdev_connect_gpio_out(DEVICE(&s->mpc_irq_orgate), 0,
736 armsse_get_common_irq_in(s, 9));
738 /* Devices behind APB PPC0:
739 * 0x40000000: timer0
740 * 0x40001000: timer1
741 * 0x40002000: dual timer
742 * 0x40003000: MHU0 (SSE-200 only)
743 * 0x40004000: MHU1 (SSE-200 only)
744 * We must configure and realize each downstream device and connect
745 * it to the appropriate PPC port; then we can realize the PPC and
746 * map its upstream ends to the right place in the container.
748 qdev_prop_set_uint32(DEVICE(&s->timer0), "pclk-frq", s->mainclk_frq);
749 sysbus_realize(SYS_BUS_DEVICE(&s->timer0), &err);
750 if (err) {
751 error_propagate(errp, err);
752 return;
754 sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer0), 0,
755 armsse_get_common_irq_in(s, 3));
756 mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer0), 0);
757 object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[0]", &err);
758 if (err) {
759 error_propagate(errp, err);
760 return;
763 qdev_prop_set_uint32(DEVICE(&s->timer1), "pclk-frq", s->mainclk_frq);
764 sysbus_realize(SYS_BUS_DEVICE(&s->timer1), &err);
765 if (err) {
766 error_propagate(errp, err);
767 return;
769 sysbus_connect_irq(SYS_BUS_DEVICE(&s->timer1), 0,
770 armsse_get_common_irq_in(s, 4));
771 mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->timer1), 0);
772 object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[1]", &err);
773 if (err) {
774 error_propagate(errp, err);
775 return;
779 qdev_prop_set_uint32(DEVICE(&s->dualtimer), "pclk-frq", s->mainclk_frq);
780 sysbus_realize(SYS_BUS_DEVICE(&s->dualtimer), &err);
781 if (err) {
782 error_propagate(errp, err);
783 return;
785 sysbus_connect_irq(SYS_BUS_DEVICE(&s->dualtimer), 0,
786 armsse_get_common_irq_in(s, 5));
787 mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dualtimer), 0);
788 object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr), "port[2]", &err);
789 if (err) {
790 error_propagate(errp, err);
791 return;
794 if (info->has_mhus) {
796 * An SSE-200 with only one CPU should have only one MHU created,
797 * with the region where the second MHU usually is being RAZ/WI.
798 * We don't implement that SSE-200 config; if we want to support
799 * it then this code needs to be enhanced to handle creating the
800 * RAZ/WI region instead of the second MHU.
802 assert(info->num_cpus == ARRAY_SIZE(s->mhu));
804 for (i = 0; i < ARRAY_SIZE(s->mhu); i++) {
805 char *port;
806 int cpunum;
807 SysBusDevice *mhu_sbd = SYS_BUS_DEVICE(&s->mhu[i]);
809 sysbus_realize(SYS_BUS_DEVICE(&s->mhu[i]), &err);
810 if (err) {
811 error_propagate(errp, err);
812 return;
814 port = g_strdup_printf("port[%d]", i + 3);
815 mr = sysbus_mmio_get_region(mhu_sbd, 0);
816 object_property_set_link(OBJECT(&s->apb_ppc0), OBJECT(mr),
817 port, &err);
818 g_free(port);
819 if (err) {
820 error_propagate(errp, err);
821 return;
825 * Each MHU has an irq line for each CPU:
826 * MHU 0 irq line 0 -> CPU 0 IRQ 6
827 * MHU 0 irq line 1 -> CPU 1 IRQ 6
828 * MHU 1 irq line 0 -> CPU 0 IRQ 7
829 * MHU 1 irq line 1 -> CPU 1 IRQ 7
831 for (cpunum = 0; cpunum < info->num_cpus; cpunum++) {
832 DeviceState *cpudev = DEVICE(&s->armv7m[cpunum]);
834 sysbus_connect_irq(mhu_sbd, cpunum,
835 qdev_get_gpio_in(cpudev, 6 + i));
840 sysbus_realize(SYS_BUS_DEVICE(&s->apb_ppc0), &err);
841 if (err) {
842 error_propagate(errp, err);
843 return;
846 sbd_apb_ppc0 = SYS_BUS_DEVICE(&s->apb_ppc0);
847 dev_apb_ppc0 = DEVICE(&s->apb_ppc0);
849 mr = sysbus_mmio_get_region(sbd_apb_ppc0, 0);
850 memory_region_add_subregion(&s->container, 0x40000000, mr);
851 mr = sysbus_mmio_get_region(sbd_apb_ppc0, 1);
852 memory_region_add_subregion(&s->container, 0x40001000, mr);
853 mr = sysbus_mmio_get_region(sbd_apb_ppc0, 2);
854 memory_region_add_subregion(&s->container, 0x40002000, mr);
855 if (info->has_mhus) {
856 mr = sysbus_mmio_get_region(sbd_apb_ppc0, 3);
857 memory_region_add_subregion(&s->container, 0x40003000, mr);
858 mr = sysbus_mmio_get_region(sbd_apb_ppc0, 4);
859 memory_region_add_subregion(&s->container, 0x40004000, mr);
861 for (i = 0; i < IOTS_APB_PPC0_NUM_PORTS; i++) {
862 qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_nonsec", i,
863 qdev_get_gpio_in_named(dev_apb_ppc0,
864 "cfg_nonsec", i));
865 qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_ap", i,
866 qdev_get_gpio_in_named(dev_apb_ppc0,
867 "cfg_ap", i));
869 qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_enable", 0,
870 qdev_get_gpio_in_named(dev_apb_ppc0,
871 "irq_enable", 0));
872 qdev_connect_gpio_out_named(dev_secctl, "apb_ppc0_irq_clear", 0,
873 qdev_get_gpio_in_named(dev_apb_ppc0,
874 "irq_clear", 0));
875 qdev_connect_gpio_out(dev_splitter, 0,
876 qdev_get_gpio_in_named(dev_apb_ppc0,
877 "cfg_sec_resp", 0));
879 /* All the PPC irq lines (from the 2 internal PPCs and the 8 external
880 * ones) are sent individually to the security controller, and also
881 * ORed together to give a single combined PPC interrupt to the NVIC.
883 object_property_set_int(OBJECT(&s->ppc_irq_orgate),
884 NUM_PPCS, "num-lines", &err);
885 if (err) {
886 error_propagate(errp, err);
887 return;
889 qdev_realize(DEVICE(&s->ppc_irq_orgate), NULL, &err);
890 if (err) {
891 error_propagate(errp, err);
892 return;
894 qdev_connect_gpio_out(DEVICE(&s->ppc_irq_orgate), 0,
895 armsse_get_common_irq_in(s, 10));
898 * 0x40010000 .. 0x4001ffff (and the 0x5001000... secure-only alias):
899 * private per-CPU region (all these devices are SSE-200 only):
900 * 0x50010000: L1 icache control registers
901 * 0x50011000: CPUSECCTRL (CPU local security control registers)
902 * 0x4001f000 and 0x5001f000: CPU_IDENTITY register block
904 if (info->has_cachectrl) {
905 for (i = 0; i < info->num_cpus; i++) {
906 char *name = g_strdup_printf("cachectrl%d", i);
907 MemoryRegion *mr;
909 qdev_prop_set_string(DEVICE(&s->cachectrl[i]), "name", name);
910 g_free(name);
911 qdev_prop_set_uint64(DEVICE(&s->cachectrl[i]), "size", 0x1000);
912 sysbus_realize(SYS_BUS_DEVICE(&s->cachectrl[i]), &err);
913 if (err) {
914 error_propagate(errp, err);
915 return;
918 mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cachectrl[i]), 0);
919 memory_region_add_subregion(&s->cpu_container[i], 0x50010000, mr);
922 if (info->has_cpusecctrl) {
923 for (i = 0; i < info->num_cpus; i++) {
924 char *name = g_strdup_printf("CPUSECCTRL%d", i);
925 MemoryRegion *mr;
927 qdev_prop_set_string(DEVICE(&s->cpusecctrl[i]), "name", name);
928 g_free(name);
929 qdev_prop_set_uint64(DEVICE(&s->cpusecctrl[i]), "size", 0x1000);
930 sysbus_realize(SYS_BUS_DEVICE(&s->cpusecctrl[i]), &err);
931 if (err) {
932 error_propagate(errp, err);
933 return;
936 mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpusecctrl[i]), 0);
937 memory_region_add_subregion(&s->cpu_container[i], 0x50011000, mr);
940 if (info->has_cpuid) {
941 for (i = 0; i < info->num_cpus; i++) {
942 MemoryRegion *mr;
944 qdev_prop_set_uint32(DEVICE(&s->cpuid[i]), "CPUID", i);
945 sysbus_realize(SYS_BUS_DEVICE(&s->cpuid[i]), &err);
946 if (err) {
947 error_propagate(errp, err);
948 return;
951 mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpuid[i]), 0);
952 memory_region_add_subregion(&s->cpu_container[i], 0x4001F000, mr);
956 /* 0x40020000 .. 0x4002ffff : ARMSSE system control peripheral region */
957 /* Devices behind APB PPC1:
958 * 0x4002f000: S32K timer
960 qdev_prop_set_uint32(DEVICE(&s->s32ktimer), "pclk-frq", S32KCLK);
961 sysbus_realize(SYS_BUS_DEVICE(&s->s32ktimer), &err);
962 if (err) {
963 error_propagate(errp, err);
964 return;
966 sysbus_connect_irq(SYS_BUS_DEVICE(&s->s32ktimer), 0,
967 armsse_get_common_irq_in(s, 2));
968 mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->s32ktimer), 0);
969 object_property_set_link(OBJECT(&s->apb_ppc1), OBJECT(mr), "port[0]", &err);
970 if (err) {
971 error_propagate(errp, err);
972 return;
975 sysbus_realize(SYS_BUS_DEVICE(&s->apb_ppc1), &err);
976 if (err) {
977 error_propagate(errp, err);
978 return;
980 mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->apb_ppc1), 0);
981 memory_region_add_subregion(&s->container, 0x4002f000, mr);
983 dev_apb_ppc1 = DEVICE(&s->apb_ppc1);
984 qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_nonsec", 0,
985 qdev_get_gpio_in_named(dev_apb_ppc1,
986 "cfg_nonsec", 0));
987 qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_ap", 0,
988 qdev_get_gpio_in_named(dev_apb_ppc1,
989 "cfg_ap", 0));
990 qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_enable", 0,
991 qdev_get_gpio_in_named(dev_apb_ppc1,
992 "irq_enable", 0));
993 qdev_connect_gpio_out_named(dev_secctl, "apb_ppc1_irq_clear", 0,
994 qdev_get_gpio_in_named(dev_apb_ppc1,
995 "irq_clear", 0));
996 qdev_connect_gpio_out(dev_splitter, 1,
997 qdev_get_gpio_in_named(dev_apb_ppc1,
998 "cfg_sec_resp", 0));
1000 object_property_set_int(OBJECT(&s->sysinfo), info->sys_version,
1001 "SYS_VERSION", &err);
1002 if (err) {
1003 error_propagate(errp, err);
1004 return;
1006 object_property_set_int(OBJECT(&s->sysinfo),
1007 armsse_sys_config_value(s, info),
1008 "SYS_CONFIG", &err);
1009 if (err) {
1010 error_propagate(errp, err);
1011 return;
1013 sysbus_realize(SYS_BUS_DEVICE(&s->sysinfo), &err);
1014 if (err) {
1015 error_propagate(errp, err);
1016 return;
1018 /* System information registers */
1019 sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysinfo), 0, 0x40020000);
1020 /* System control registers */
1021 object_property_set_int(OBJECT(&s->sysctl), info->sys_version,
1022 "SYS_VERSION", &err);
1023 object_property_set_int(OBJECT(&s->sysctl), info->cpuwait_rst,
1024 "CPUWAIT_RST", &err);
1025 object_property_set_int(OBJECT(&s->sysctl), s->init_svtor,
1026 "INITSVTOR0_RST", &err);
1027 object_property_set_int(OBJECT(&s->sysctl), s->init_svtor,
1028 "INITSVTOR1_RST", &err);
1029 sysbus_realize(SYS_BUS_DEVICE(&s->sysctl), &err);
1030 if (err) {
1031 error_propagate(errp, err);
1032 return;
1034 sysbus_mmio_map(SYS_BUS_DEVICE(&s->sysctl), 0, 0x50021000);
1036 if (info->has_ppus) {
1037 /* CPUnCORE_PPU for each CPU */
1038 for (i = 0; i < info->num_cpus; i++) {
1039 char *name = g_strdup_printf("CPU%dCORE_PPU", i);
1041 map_ppu(s, CPU0CORE_PPU + i, name, 0x50023000 + i * 0x2000);
1043 * We don't support CPU debug so don't create the
1044 * CPU0DEBUG_PPU at 0x50024000 and 0x50026000.
1046 g_free(name);
1048 map_ppu(s, DBG_PPU, "DBG_PPU", 0x50029000);
1050 for (i = 0; i < info->sram_banks; i++) {
1051 char *name = g_strdup_printf("RAM%d_PPU", i);
1053 map_ppu(s, RAM0_PPU + i, name, 0x5002a000 + i * 0x1000);
1054 g_free(name);
1058 /* This OR gate wires together outputs from the secure watchdogs to NMI */
1059 object_property_set_int(OBJECT(&s->nmi_orgate), 2, "num-lines", &err);
1060 if (err) {
1061 error_propagate(errp, err);
1062 return;
1064 qdev_realize(DEVICE(&s->nmi_orgate), NULL, &err);
1065 if (err) {
1066 error_propagate(errp, err);
1067 return;
1069 qdev_connect_gpio_out(DEVICE(&s->nmi_orgate), 0,
1070 qdev_get_gpio_in_named(DEVICE(&s->armv7m), "NMI", 0));
1072 qdev_prop_set_uint32(DEVICE(&s->s32kwatchdog), "wdogclk-frq", S32KCLK);
1073 sysbus_realize(SYS_BUS_DEVICE(&s->s32kwatchdog), &err);
1074 if (err) {
1075 error_propagate(errp, err);
1076 return;
1078 sysbus_connect_irq(SYS_BUS_DEVICE(&s->s32kwatchdog), 0,
1079 qdev_get_gpio_in(DEVICE(&s->nmi_orgate), 0));
1080 sysbus_mmio_map(SYS_BUS_DEVICE(&s->s32kwatchdog), 0, 0x5002e000);
1082 /* 0x40080000 .. 0x4008ffff : ARMSSE second Base peripheral region */
1084 qdev_prop_set_uint32(DEVICE(&s->nswatchdog), "wdogclk-frq", s->mainclk_frq);
1085 sysbus_realize(SYS_BUS_DEVICE(&s->nswatchdog), &err);
1086 if (err) {
1087 error_propagate(errp, err);
1088 return;
1090 sysbus_connect_irq(SYS_BUS_DEVICE(&s->nswatchdog), 0,
1091 armsse_get_common_irq_in(s, 1));
1092 sysbus_mmio_map(SYS_BUS_DEVICE(&s->nswatchdog), 0, 0x40081000);
1094 qdev_prop_set_uint32(DEVICE(&s->swatchdog), "wdogclk-frq", s->mainclk_frq);
1095 sysbus_realize(SYS_BUS_DEVICE(&s->swatchdog), &err);
1096 if (err) {
1097 error_propagate(errp, err);
1098 return;
1100 sysbus_connect_irq(SYS_BUS_DEVICE(&s->swatchdog), 0,
1101 qdev_get_gpio_in(DEVICE(&s->nmi_orgate), 1));
1102 sysbus_mmio_map(SYS_BUS_DEVICE(&s->swatchdog), 0, 0x50081000);
1104 for (i = 0; i < ARRAY_SIZE(s->ppc_irq_splitter); i++) {
1105 Object *splitter = OBJECT(&s->ppc_irq_splitter[i]);
1107 object_property_set_int(splitter, 2, "num-lines", &err);
1108 if (err) {
1109 error_propagate(errp, err);
1110 return;
1112 qdev_realize(DEVICE(splitter), NULL, &err);
1113 if (err) {
1114 error_propagate(errp, err);
1115 return;
1119 for (i = 0; i < IOTS_NUM_AHB_EXP_PPC; i++) {
1120 char *ppcname = g_strdup_printf("ahb_ppcexp%d", i);
1122 armsse_forward_ppc(s, ppcname, i);
1123 g_free(ppcname);
1126 for (i = 0; i < IOTS_NUM_APB_EXP_PPC; i++) {
1127 char *ppcname = g_strdup_printf("apb_ppcexp%d", i);
1129 armsse_forward_ppc(s, ppcname, i + IOTS_NUM_AHB_EXP_PPC);
1130 g_free(ppcname);
1133 for (i = NUM_EXTERNAL_PPCS; i < NUM_PPCS; i++) {
1134 /* Wire up IRQ splitter for internal PPCs */
1135 DeviceState *devs = DEVICE(&s->ppc_irq_splitter[i]);
1136 char *gpioname = g_strdup_printf("apb_ppc%d_irq_status",
1137 i - NUM_EXTERNAL_PPCS);
1138 TZPPC *ppc = (i == NUM_EXTERNAL_PPCS) ? &s->apb_ppc0 : &s->apb_ppc1;
1140 qdev_connect_gpio_out(devs, 0,
1141 qdev_get_gpio_in_named(dev_secctl, gpioname, 0));
1142 qdev_connect_gpio_out(devs, 1,
1143 qdev_get_gpio_in(DEVICE(&s->ppc_irq_orgate), i));
1144 qdev_connect_gpio_out_named(DEVICE(ppc), "irq", 0,
1145 qdev_get_gpio_in(devs, 0));
1146 g_free(gpioname);
1149 /* Wire up the splitters for the MPC IRQs */
1150 for (i = 0; i < IOTS_NUM_EXP_MPC + info->sram_banks; i++) {
1151 SplitIRQ *splitter = &s->mpc_irq_splitter[i];
1152 DeviceState *dev_splitter = DEVICE(splitter);
1154 object_property_set_int(OBJECT(splitter), 2, "num-lines", &err);
1155 if (err) {
1156 error_propagate(errp, err);
1157 return;
1159 qdev_realize(DEVICE(splitter), NULL, &err);
1160 if (err) {
1161 error_propagate(errp, err);
1162 return;
1165 if (i < IOTS_NUM_EXP_MPC) {
1166 /* Splitter input is from GPIO input line */
1167 s->mpcexp_status_in[i] = qdev_get_gpio_in(dev_splitter, 0);
1168 qdev_connect_gpio_out(dev_splitter, 0,
1169 qdev_get_gpio_in_named(dev_secctl,
1170 "mpcexp_status", i));
1171 } else {
1172 /* Splitter input is from our own MPC */
1173 qdev_connect_gpio_out_named(DEVICE(&s->mpc[i - IOTS_NUM_EXP_MPC]),
1174 "irq", 0,
1175 qdev_get_gpio_in(dev_splitter, 0));
1176 qdev_connect_gpio_out(dev_splitter, 0,
1177 qdev_get_gpio_in_named(dev_secctl,
1178 "mpc_status", 0));
1181 qdev_connect_gpio_out(dev_splitter, 1,
1182 qdev_get_gpio_in(DEVICE(&s->mpc_irq_orgate), i));
1184 /* Create GPIO inputs which will pass the line state for our
1185 * mpcexp_irq inputs to the correct splitter devices.
1187 qdev_init_gpio_in_named(dev, armsse_mpcexp_status, "mpcexp_status",
1188 IOTS_NUM_EXP_MPC);
1190 armsse_forward_sec_resp_cfg(s);
1192 /* Forward the MSC related signals */
1193 qdev_pass_gpios(dev_secctl, dev, "mscexp_status");
1194 qdev_pass_gpios(dev_secctl, dev, "mscexp_clear");
1195 qdev_pass_gpios(dev_secctl, dev, "mscexp_ns");
1196 qdev_connect_gpio_out_named(dev_secctl, "msc_irq", 0,
1197 armsse_get_common_irq_in(s, 11));
1200 * Expose our container region to the board model; this corresponds
1201 * to the AHB Slave Expansion ports which allow bus master devices
1202 * (eg DMA controllers) in the board model to make transactions into
1203 * devices in the ARMSSE.
1205 sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->container);
1207 system_clock_scale = NANOSECONDS_PER_SECOND / s->mainclk_frq;
1210 static void armsse_idau_check(IDAUInterface *ii, uint32_t address,
1211 int *iregion, bool *exempt, bool *ns, bool *nsc)
1214 * For ARMSSE systems the IDAU responses are simple logical functions
1215 * of the address bits. The NSC attribute is guest-adjustable via the
1216 * NSCCFG register in the security controller.
1218 ARMSSE *s = ARMSSE(ii);
1219 int region = extract32(address, 28, 4);
1221 *ns = !(region & 1);
1222 *nsc = (region == 1 && (s->nsccfg & 1)) || (region == 3 && (s->nsccfg & 2));
1223 /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */
1224 *exempt = (address & 0xeff00000) == 0xe0000000;
1225 *iregion = region;
1228 static const VMStateDescription armsse_vmstate = {
1229 .name = "iotkit",
1230 .version_id = 1,
1231 .minimum_version_id = 1,
1232 .fields = (VMStateField[]) {
1233 VMSTATE_UINT32(nsccfg, ARMSSE),
1234 VMSTATE_END_OF_LIST()
1238 static void armsse_reset(DeviceState *dev)
1240 ARMSSE *s = ARMSSE(dev);
1242 s->nsccfg = 0;
1245 static void armsse_class_init(ObjectClass *klass, void *data)
1247 DeviceClass *dc = DEVICE_CLASS(klass);
1248 IDAUInterfaceClass *iic = IDAU_INTERFACE_CLASS(klass);
1249 ARMSSEClass *asc = ARMSSE_CLASS(klass);
1250 const ARMSSEInfo *info = data;
1252 dc->realize = armsse_realize;
1253 dc->vmsd = &armsse_vmstate;
1254 device_class_set_props(dc, info->props);
1255 dc->reset = armsse_reset;
1256 iic->check = armsse_idau_check;
1257 asc->info = info;
1260 static const TypeInfo armsse_info = {
1261 .name = TYPE_ARMSSE,
1262 .parent = TYPE_SYS_BUS_DEVICE,
1263 .instance_size = sizeof(ARMSSE),
1264 .instance_init = armsse_init,
1265 .abstract = true,
1266 .interfaces = (InterfaceInfo[]) {
1267 { TYPE_IDAU_INTERFACE },
1272 static void armsse_register_types(void)
1274 int i;
1276 type_register_static(&armsse_info);
1278 for (i = 0; i < ARRAY_SIZE(armsse_variants); i++) {
1279 TypeInfo ti = {
1280 .name = armsse_variants[i].name,
1281 .parent = TYPE_ARMSSE,
1282 .class_init = armsse_class_init,
1283 .class_data = (void *)&armsse_variants[i],
1285 type_register(&ti);
1289 type_init(armsse_register_types);