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"
14 #include "qemu/module.h"
15 #include "qemu/bitops.h"
16 #include "qapi/error.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/armsse-version.h"
23 #include "hw/arm/boot.h"
25 #include "hw/qdev-clock.h"
28 * The SSE-300 puts some devices in different places to the
29 * SSE-200 (and original IoTKit). We use an array of these structs
30 * to define how each variant lays out these devices. (Parts of the
31 * SoC that are the same for all variants aren't handled via these
38 * Special values for ARMSSEDeviceInfo::irq to indicate that this
39 * device uses one of the inputs to the OR gate that feeds into the
45 typedef struct ARMSSEDeviceInfo
{
46 const char *name
; /* name to use for the QOM object; NULL terminates list */
47 const char *type
; /* QOM type name */
48 unsigned int index
; /* Which of the N devices of this type is this ? */
50 hwaddr size
; /* only needed for TYPE_UNIMPLEMENTED_DEVICE */
51 int ppc
; /* Index of APB PPC this device is wired up to, or NO_PPC */
52 int ppc_port
; /* Port number of this device on the PPC */
53 int irq
; /* NO_IRQ, or 0..NUM_SSE_IRQS-1, or NMI_0 or NMI_1 */
54 bool slowclk
; /* true if device uses the slow 32KHz clock */
72 const ARMSSEDeviceInfo
*devinfo
;
73 const bool *irq_is_common
;
76 static Property iotkit_properties
[] = {
77 DEFINE_PROP_LINK("memory", ARMSSE
, board_memory
, TYPE_MEMORY_REGION
,
79 DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE
, exp_numirq
, 64),
80 DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE
, sram_addr_width
, 15),
81 DEFINE_PROP_UINT32("init-svtor", ARMSSE
, init_svtor
, 0x10000000),
82 DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE
, cpu_fpu
[0], true),
83 DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE
, cpu_dsp
[0], true),
84 DEFINE_PROP_END_OF_LIST()
87 static Property armsse_properties
[] = {
88 DEFINE_PROP_LINK("memory", ARMSSE
, board_memory
, TYPE_MEMORY_REGION
,
90 DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE
, exp_numirq
, 64),
91 DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE
, sram_addr_width
, 15),
92 DEFINE_PROP_UINT32("init-svtor", ARMSSE
, init_svtor
, 0x10000000),
93 DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE
, cpu_fpu
[0], false),
94 DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE
, cpu_dsp
[0], false),
95 DEFINE_PROP_BOOL("CPU1_FPU", ARMSSE
, cpu_fpu
[1], true),
96 DEFINE_PROP_BOOL("CPU1_DSP", ARMSSE
, cpu_dsp
[1], true),
97 DEFINE_PROP_END_OF_LIST()
100 static const ARMSSEDeviceInfo iotkit_devices
[] = {
103 .type
= TYPE_CMSDK_APB_TIMER
,
112 .type
= TYPE_CMSDK_APB_TIMER
,
121 .type
= TYPE_CMSDK_APB_TIMER
,
131 .type
= TYPE_CMSDK_APB_DUALTIMER
,
139 .name
= "s32kwatchdog",
140 .type
= TYPE_CMSDK_APB_WATCHDOG
,
148 .name
= "nswatchdog",
149 .type
= TYPE_CMSDK_APB_WATCHDOG
,
157 .type
= TYPE_CMSDK_APB_WATCHDOG
,
164 .name
= "armsse-sysinfo",
165 .type
= TYPE_IOTKIT_SYSINFO
,
172 .name
= "armsse-sysctl",
173 .type
= TYPE_IOTKIT_SYSCTL
,
184 static const ARMSSEDeviceInfo sse200_devices
[] = {
187 .type
= TYPE_CMSDK_APB_TIMER
,
196 .type
= TYPE_CMSDK_APB_TIMER
,
205 .type
= TYPE_CMSDK_APB_TIMER
,
215 .type
= TYPE_CMSDK_APB_DUALTIMER
,
223 .name
= "s32kwatchdog",
224 .type
= TYPE_CMSDK_APB_WATCHDOG
,
232 .name
= "nswatchdog",
233 .type
= TYPE_CMSDK_APB_WATCHDOG
,
241 .type
= TYPE_CMSDK_APB_WATCHDOG
,
248 .name
= "armsse-sysinfo",
249 .type
= TYPE_IOTKIT_SYSINFO
,
256 .name
= "armsse-sysctl",
257 .type
= TYPE_IOTKIT_SYSCTL
,
264 .name
= "CPU0CORE_PPU",
265 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
273 .name
= "CPU1CORE_PPU",
274 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
283 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
292 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
301 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
310 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
319 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
328 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
340 /* Is internal IRQ n shared between CPUs in a multi-core SSE ? */
341 static const bool sse200_irq_is_common
[32] = {
343 /* 6, 7: per-CPU MHU interrupts */
345 /* 13: per-CPU icache interrupt */
351 /* 28, 29: per-CPU CTI interrupts */
352 /* 30, 31: reserved */
355 static const ARMSSEInfo armsse_variants
[] = {
358 .sse_version
= ARMSSE_IOTKIT
,
361 .sys_version
= 0x41743,
365 .has_cachectrl
= false,
366 .has_cpusecctrl
= false,
368 .has_cpu_pwrctrl
= false,
369 .has_sse_counter
= false,
370 .props
= iotkit_properties
,
371 .devinfo
= iotkit_devices
,
372 .irq_is_common
= sse200_irq_is_common
,
376 .sse_version
= ARMSSE_SSE200
,
379 .sys_version
= 0x22041743,
383 .has_cachectrl
= true,
384 .has_cpusecctrl
= true,
386 .has_cpu_pwrctrl
= false,
387 .has_sse_counter
= false,
388 .props
= armsse_properties
,
389 .devinfo
= sse200_devices
,
390 .irq_is_common
= sse200_irq_is_common
,
394 static uint32_t armsse_sys_config_value(ARMSSE
*s
, const ARMSSEInfo
*info
)
396 /* Return the SYS_CONFIG value for this SSE */
399 switch (info
->sse_version
) {
402 sys_config
= deposit32(sys_config
, 0, 4, info
->sram_banks
);
403 sys_config
= deposit32(sys_config
, 4, 4, s
->sram_addr_width
- 12);
407 sys_config
= deposit32(sys_config
, 0, 4, info
->sram_banks
);
408 sys_config
= deposit32(sys_config
, 4, 5, s
->sram_addr_width
);
409 sys_config
= deposit32(sys_config
, 24, 4, 2);
410 if (info
->num_cpus
> 1) {
411 sys_config
= deposit32(sys_config
, 10, 1, 1);
412 sys_config
= deposit32(sys_config
, 20, 4, info
->sram_banks
- 1);
413 sys_config
= deposit32(sys_config
, 28, 4, 2);
418 sys_config
= deposit32(sys_config
, 0, 4, info
->sram_banks
);
419 sys_config
= deposit32(sys_config
, 4, 5, s
->sram_addr_width
);
420 sys_config
= deposit32(sys_config
, 16, 3, 3); /* CPU0 = Cortex-M55 */
423 g_assert_not_reached();
428 /* Clock frequency in HZ of the 32KHz "slow clock" */
429 #define S32KCLK (32 * 1000)
432 * Create an alias region in @container of @size bytes starting at @base
433 * which mirrors the memory starting at @orig.
435 static void make_alias(ARMSSE
*s
, MemoryRegion
*mr
, MemoryRegion
*container
,
436 const char *name
, hwaddr base
, hwaddr size
, hwaddr orig
)
438 memory_region_init_alias(mr
, NULL
, name
, container
, orig
, size
);
439 /* The alias is even lower priority than unimplemented_device regions */
440 memory_region_add_subregion_overlap(container
, base
, mr
, -1500);
443 static void irq_status_forwarder(void *opaque
, int n
, int level
)
445 qemu_irq destirq
= opaque
;
447 qemu_set_irq(destirq
, level
);
450 static void nsccfg_handler(void *opaque
, int n
, int level
)
452 ARMSSE
*s
= ARM_SSE(opaque
);
457 static void armsse_forward_ppc(ARMSSE
*s
, const char *ppcname
, int ppcnum
)
459 /* Each of the 4 AHB and 4 APB PPCs that might be present in a
460 * system using the ARMSSE has a collection of control lines which
461 * are provided by the security controller and which we want to
462 * expose as control lines on the ARMSSE device itself, so the
463 * code using the ARMSSE can wire them up to the PPCs.
465 SplitIRQ
*splitter
= &s
->ppc_irq_splitter
[ppcnum
];
466 DeviceState
*armssedev
= DEVICE(s
);
467 DeviceState
*dev_secctl
= DEVICE(&s
->secctl
);
468 DeviceState
*dev_splitter
= DEVICE(splitter
);
471 name
= g_strdup_printf("%s_nonsec", ppcname
);
472 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
474 name
= g_strdup_printf("%s_ap", ppcname
);
475 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
477 name
= g_strdup_printf("%s_irq_enable", ppcname
);
478 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
480 name
= g_strdup_printf("%s_irq_clear", ppcname
);
481 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
484 /* irq_status is a little more tricky, because we need to
485 * split it so we can send it both to the security controller
486 * and to our OR gate for the NVIC interrupt line.
487 * Connect up the splitter's outputs, and create a GPIO input
488 * which will pass the line state to the input splitter.
490 name
= g_strdup_printf("%s_irq_status", ppcname
);
491 qdev_connect_gpio_out(dev_splitter
, 0,
492 qdev_get_gpio_in_named(dev_secctl
,
494 qdev_connect_gpio_out(dev_splitter
, 1,
495 qdev_get_gpio_in(DEVICE(&s
->ppc_irq_orgate
), ppcnum
));
496 s
->irq_status_in
[ppcnum
] = qdev_get_gpio_in(dev_splitter
, 0);
497 qdev_init_gpio_in_named_with_opaque(armssedev
, irq_status_forwarder
,
498 s
->irq_status_in
[ppcnum
], name
, 1);
502 static void armsse_forward_sec_resp_cfg(ARMSSE
*s
)
504 /* Forward the 3rd output from the splitter device as a
505 * named GPIO output of the armsse object.
507 DeviceState
*dev
= DEVICE(s
);
508 DeviceState
*dev_splitter
= DEVICE(&s
->sec_resp_splitter
);
510 qdev_init_gpio_out_named(dev
, &s
->sec_resp_cfg
, "sec_resp_cfg", 1);
511 s
->sec_resp_cfg_in
= qemu_allocate_irq(irq_status_forwarder
,
513 qdev_connect_gpio_out(dev_splitter
, 2, s
->sec_resp_cfg_in
);
516 static void armsse_mainclk_update(void *opaque
, ClockEvent event
)
518 ARMSSE
*s
= ARM_SSE(opaque
);
521 * Set system_clock_scale from our Clock input; this is what
522 * controls the tick rate of the CPU SysTick timer.
524 system_clock_scale
= clock_ticks_to_ns(s
->mainclk
, 1);
527 static void armsse_init(Object
*obj
)
529 ARMSSE
*s
= ARM_SSE(obj
);
530 ARMSSEClass
*asc
= ARM_SSE_GET_CLASS(obj
);
531 const ARMSSEInfo
*info
= asc
->info
;
532 const ARMSSEDeviceInfo
*devinfo
;
535 assert(info
->sram_banks
<= MAX_SRAM_BANKS
);
536 assert(info
->num_cpus
<= SSE_MAX_CPUS
);
538 s
->mainclk
= qdev_init_clock_in(DEVICE(s
), "MAINCLK",
539 armsse_mainclk_update
, s
, ClockUpdate
);
540 s
->s32kclk
= qdev_init_clock_in(DEVICE(s
), "S32KCLK", NULL
, NULL
, 0);
542 memory_region_init(&s
->container
, obj
, "armsse-container", UINT64_MAX
);
544 for (i
= 0; i
< info
->num_cpus
; i
++) {
546 * We put each CPU in its own cluster as they are logically
547 * distinct and may be configured differently.
551 name
= g_strdup_printf("cluster%d", i
);
552 object_initialize_child(obj
, name
, &s
->cluster
[i
], TYPE_CPU_CLUSTER
);
553 qdev_prop_set_uint32(DEVICE(&s
->cluster
[i
]), "cluster-id", i
);
556 name
= g_strdup_printf("armv7m%d", i
);
557 object_initialize_child(OBJECT(&s
->cluster
[i
]), name
, &s
->armv7m
[i
],
559 qdev_prop_set_string(DEVICE(&s
->armv7m
[i
]), "cpu-type",
560 ARM_CPU_TYPE_NAME("cortex-m33"));
562 name
= g_strdup_printf("arm-sse-cpu-container%d", i
);
563 memory_region_init(&s
->cpu_container
[i
], obj
, name
, UINT64_MAX
);
566 name
= g_strdup_printf("arm-sse-container-alias%d", i
);
567 memory_region_init_alias(&s
->container_alias
[i
- 1], obj
,
568 name
, &s
->container
, 0, UINT64_MAX
);
573 for (devinfo
= info
->devinfo
; devinfo
->name
; devinfo
++) {
574 assert(devinfo
->ppc
== NO_PPC
|| devinfo
->ppc
< ARRAY_SIZE(s
->apb_ppc
));
575 if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_TIMER
)) {
576 assert(devinfo
->index
< ARRAY_SIZE(s
->timer
));
577 object_initialize_child(obj
, devinfo
->name
,
578 &s
->timer
[devinfo
->index
],
579 TYPE_CMSDK_APB_TIMER
);
580 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_DUALTIMER
)) {
581 assert(devinfo
->index
== 0);
582 object_initialize_child(obj
, devinfo
->name
, &s
->dualtimer
,
583 TYPE_CMSDK_APB_DUALTIMER
);
584 } else if (!strcmp(devinfo
->type
, TYPE_SSE_TIMER
)) {
585 assert(devinfo
->index
< ARRAY_SIZE(s
->sse_timer
));
586 object_initialize_child(obj
, devinfo
->name
,
587 &s
->sse_timer
[devinfo
->index
],
589 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_WATCHDOG
)) {
590 assert(devinfo
->index
< ARRAY_SIZE(s
->cmsdk_watchdog
));
591 object_initialize_child(obj
, devinfo
->name
,
592 &s
->cmsdk_watchdog
[devinfo
->index
],
593 TYPE_CMSDK_APB_WATCHDOG
);
594 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSINFO
)) {
595 assert(devinfo
->index
== 0);
596 object_initialize_child(obj
, devinfo
->name
, &s
->sysinfo
,
597 TYPE_IOTKIT_SYSINFO
);
598 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSCTL
)) {
599 assert(devinfo
->index
== 0);
600 object_initialize_child(obj
, devinfo
->name
, &s
->sysctl
,
602 } else if (!strcmp(devinfo
->type
, TYPE_UNIMPLEMENTED_DEVICE
)) {
603 assert(devinfo
->index
< ARRAY_SIZE(s
->unimp
));
604 object_initialize_child(obj
, devinfo
->name
,
605 &s
->unimp
[devinfo
->index
],
606 TYPE_UNIMPLEMENTED_DEVICE
);
608 g_assert_not_reached();
612 object_initialize_child(obj
, "secctl", &s
->secctl
, TYPE_IOTKIT_SECCTL
);
614 for (i
= 0; i
< ARRAY_SIZE(s
->apb_ppc
); i
++) {
615 g_autofree
char *name
= g_strdup_printf("apb-ppc%d", i
);
616 object_initialize_child(obj
, name
, &s
->apb_ppc
[i
], TYPE_TZ_PPC
);
619 for (i
= 0; i
< info
->sram_banks
; i
++) {
620 char *name
= g_strdup_printf("mpc%d", i
);
621 object_initialize_child(obj
, name
, &s
->mpc
[i
], TYPE_TZ_MPC
);
624 object_initialize_child(obj
, "mpc-irq-orgate", &s
->mpc_irq_orgate
,
627 for (i
= 0; i
< IOTS_NUM_EXP_MPC
+ info
->sram_banks
; i
++) {
628 char *name
= g_strdup_printf("mpc-irq-splitter-%d", i
);
629 SplitIRQ
*splitter
= &s
->mpc_irq_splitter
[i
];
631 object_initialize_child(obj
, name
, splitter
, TYPE_SPLIT_IRQ
);
635 if (info
->has_mhus
) {
636 object_initialize_child(obj
, "mhu0", &s
->mhu
[0], TYPE_ARMSSE_MHU
);
637 object_initialize_child(obj
, "mhu1", &s
->mhu
[1], TYPE_ARMSSE_MHU
);
639 if (info
->has_cachectrl
) {
640 for (i
= 0; i
< info
->num_cpus
; i
++) {
641 char *name
= g_strdup_printf("cachectrl%d", i
);
643 object_initialize_child(obj
, name
, &s
->cachectrl
[i
],
644 TYPE_UNIMPLEMENTED_DEVICE
);
648 if (info
->has_cpusecctrl
) {
649 for (i
= 0; i
< info
->num_cpus
; i
++) {
650 char *name
= g_strdup_printf("cpusecctrl%d", i
);
652 object_initialize_child(obj
, name
, &s
->cpusecctrl
[i
],
653 TYPE_UNIMPLEMENTED_DEVICE
);
657 if (info
->has_cpuid
) {
658 for (i
= 0; i
< info
->num_cpus
; i
++) {
659 char *name
= g_strdup_printf("cpuid%d", i
);
661 object_initialize_child(obj
, name
, &s
->cpuid
[i
],
666 if (info
->has_cpu_pwrctrl
) {
667 for (i
= 0; i
< info
->num_cpus
; i
++) {
668 char *name
= g_strdup_printf("cpu_pwrctrl%d", i
);
670 object_initialize_child(obj
, name
, &s
->cpu_pwrctrl
[i
],
671 TYPE_ARMSSE_CPU_PWRCTRL
);
675 if (info
->has_sse_counter
) {
676 object_initialize_child(obj
, "sse-counter", &s
->sse_counter
,
680 object_initialize_child(obj
, "nmi-orgate", &s
->nmi_orgate
, TYPE_OR_IRQ
);
681 object_initialize_child(obj
, "ppc-irq-orgate", &s
->ppc_irq_orgate
,
683 object_initialize_child(obj
, "sec-resp-splitter", &s
->sec_resp_splitter
,
685 for (i
= 0; i
< ARRAY_SIZE(s
->ppc_irq_splitter
); i
++) {
686 char *name
= g_strdup_printf("ppc-irq-splitter-%d", i
);
687 SplitIRQ
*splitter
= &s
->ppc_irq_splitter
[i
];
689 object_initialize_child(obj
, name
, splitter
, TYPE_SPLIT_IRQ
);
692 if (info
->num_cpus
> 1) {
693 for (i
= 0; i
< ARRAY_SIZE(s
->cpu_irq_splitter
); i
++) {
694 if (info
->irq_is_common
[i
]) {
695 char *name
= g_strdup_printf("cpu-irq-splitter%d", i
);
696 SplitIRQ
*splitter
= &s
->cpu_irq_splitter
[i
];
698 object_initialize_child(obj
, name
, splitter
, TYPE_SPLIT_IRQ
);
705 static void armsse_exp_irq(void *opaque
, int n
, int level
)
707 qemu_irq
*irqarray
= opaque
;
709 qemu_set_irq(irqarray
[n
], level
);
712 static void armsse_mpcexp_status(void *opaque
, int n
, int level
)
714 ARMSSE
*s
= ARM_SSE(opaque
);
715 qemu_set_irq(s
->mpcexp_status_in
[n
], level
);
718 static qemu_irq
armsse_get_common_irq_in(ARMSSE
*s
, int irqno
)
721 * Return a qemu_irq which can be used to signal IRQ n to
722 * all CPUs in the SSE.
724 ARMSSEClass
*asc
= ARM_SSE_GET_CLASS(s
);
725 const ARMSSEInfo
*info
= asc
->info
;
727 assert(info
->irq_is_common
[irqno
]);
729 if (info
->num_cpus
== 1) {
730 /* Only one CPU -- just connect directly to it */
731 return qdev_get_gpio_in(DEVICE(&s
->armv7m
[0]), irqno
);
733 /* Connect to the splitter which feeds all CPUs */
734 return qdev_get_gpio_in(DEVICE(&s
->cpu_irq_splitter
[irqno
]), 0);
738 static void armsse_realize(DeviceState
*dev
, Error
**errp
)
740 ARMSSE
*s
= ARM_SSE(dev
);
741 ARMSSEClass
*asc
= ARM_SSE_GET_CLASS(dev
);
742 const ARMSSEInfo
*info
= asc
->info
;
743 const ARMSSEDeviceInfo
*devinfo
;
747 SysBusDevice
*sbd_apb_ppc0
;
748 SysBusDevice
*sbd_secctl
;
749 DeviceState
*dev_apb_ppc0
;
750 DeviceState
*dev_apb_ppc1
;
751 DeviceState
*dev_secctl
;
752 DeviceState
*dev_splitter
;
753 uint32_t addr_width_max
;
755 if (!s
->board_memory
) {
756 error_setg(errp
, "memory property was not set");
760 if (!clock_has_source(s
->mainclk
)) {
761 error_setg(errp
, "MAINCLK clock was not connected");
763 if (!clock_has_source(s
->s32kclk
)) {
764 error_setg(errp
, "S32KCLK clock was not connected");
767 assert(info
->num_cpus
<= SSE_MAX_CPUS
);
769 /* max SRAM_ADDR_WIDTH: 24 - log2(SRAM_NUM_BANK) */
770 assert(is_power_of_2(info
->sram_banks
));
771 addr_width_max
= 24 - ctz32(info
->sram_banks
);
772 if (s
->sram_addr_width
< 1 || s
->sram_addr_width
> addr_width_max
) {
773 error_setg(errp
, "SRAM_ADDR_WIDTH must be between 1 and %d",
778 /* Handling of which devices should be available only to secure
779 * code is usually done differently for M profile than for A profile.
780 * Instead of putting some devices only into the secure address space,
781 * devices exist in both address spaces but with hard-wired security
782 * permissions that will cause the CPU to fault for non-secure accesses.
784 * The ARMSSE has an IDAU (Implementation Defined Access Unit),
785 * which specifies hard-wired security permissions for different
786 * areas of the physical address space. For the ARMSSE IDAU, the
787 * top 4 bits of the physical address are the IDAU region ID, and
788 * if bit 28 (ie the lowest bit of the ID) is 0 then this is an NS
789 * region, otherwise it is an S region.
791 * The various devices and RAMs are generally all mapped twice,
792 * once into a region that the IDAU defines as secure and once
793 * into a non-secure region. They sit behind either a Memory
794 * Protection Controller (for RAM) or a Peripheral Protection
795 * Controller (for devices), which allow a more fine grained
796 * configuration of whether non-secure accesses are permitted.
798 * (The other place that guest software can configure security
799 * permissions is in the architected SAU (Security Attribution
800 * Unit), which is entirely inside the CPU. The IDAU can upgrade
801 * the security attributes for a region to more restrictive than
802 * the SAU specifies, but cannot downgrade them.)
804 * 0x10000000..0x1fffffff alias of 0x00000000..0x0fffffff
805 * 0x20000000..0x2007ffff 32KB FPGA block RAM
806 * 0x30000000..0x3fffffff alias of 0x20000000..0x2fffffff
807 * 0x40000000..0x4000ffff base peripheral region 1
808 * 0x40010000..0x4001ffff CPU peripherals (none for ARMSSE)
809 * 0x40020000..0x4002ffff system control element peripherals
810 * 0x40080000..0x400fffff base peripheral region 2
811 * 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff
814 memory_region_add_subregion_overlap(&s
->container
, 0, s
->board_memory
, -2);
816 for (i
= 0; i
< info
->num_cpus
; i
++) {
817 DeviceState
*cpudev
= DEVICE(&s
->armv7m
[i
]);
818 Object
*cpuobj
= OBJECT(&s
->armv7m
[i
]);
822 qdev_prop_set_uint32(cpudev
, "num-irq", s
->exp_numirq
+ NUM_SSE_IRQS
);
824 * In real hardware the initial Secure VTOR is set from the INITSVTOR*
825 * registers in the IoT Kit System Control Register block. In QEMU
826 * we set the initial value here, and also the reset value of the
827 * sysctl register, from this object's QOM init-svtor property.
828 * If the guest changes the INITSVTOR* registers at runtime then the
829 * code in iotkit-sysctl.c will update the CPU init-svtor property
830 * (which will then take effect on the next CPU warm-reset).
832 * Note that typically a board using the SSE-200 will have a system
833 * control processor whose boot firmware initializes the INITSVTOR*
834 * registers before powering up the CPUs. QEMU doesn't emulate
835 * the control processor, so instead we behave in the way that the
836 * firmware does: the initial value should be set by the board code
837 * (using the init-svtor property on the ARMSSE object) to match
838 * whatever its firmware does.
840 qdev_prop_set_uint32(cpudev
, "init-svtor", s
->init_svtor
);
842 * CPUs start powered down if the corresponding bit in the CPUWAIT
843 * register is 1. In real hardware the CPUWAIT register reset value is
844 * a configurable property of the SSE-200 (via the CPUWAIT0_RST and
845 * CPUWAIT1_RST parameters), but since all the boards we care about
846 * start CPU0 and leave CPU1 powered off, we hard-code that in
847 * info->cpuwait_rst for now. We can add QOM properties for this
848 * later if necessary.
850 if (extract32(info
->cpuwait_rst
, i
, 1)) {
851 if (!object_property_set_bool(cpuobj
, "start-powered-off", true,
856 if (!s
->cpu_fpu
[i
]) {
857 if (!object_property_set_bool(cpuobj
, "vfp", false, errp
)) {
861 if (!s
->cpu_dsp
[i
]) {
862 if (!object_property_set_bool(cpuobj
, "dsp", false, errp
)) {
868 memory_region_add_subregion_overlap(&s
->cpu_container
[i
], 0,
869 &s
->container_alias
[i
- 1], -1);
871 memory_region_add_subregion_overlap(&s
->cpu_container
[i
], 0,
874 object_property_set_link(cpuobj
, "memory",
875 OBJECT(&s
->cpu_container
[i
]), &error_abort
);
876 object_property_set_link(cpuobj
, "idau", OBJECT(s
), &error_abort
);
877 if (!sysbus_realize(SYS_BUS_DEVICE(cpuobj
), errp
)) {
881 * The cluster must be realized after the armv7m container, as
882 * the container's CPU object is only created on realize, and the
883 * CPU must exist and have been parented into the cluster before
884 * the cluster is realized.
886 if (!qdev_realize(DEVICE(&s
->cluster
[i
]), NULL
, errp
)) {
890 /* Connect EXP_IRQ/EXP_CPUn_IRQ GPIOs to the NVIC's lines 32 and up */
891 s
->exp_irqs
[i
] = g_new(qemu_irq
, s
->exp_numirq
);
892 for (j
= 0; j
< s
->exp_numirq
; j
++) {
893 s
->exp_irqs
[i
][j
] = qdev_get_gpio_in(cpudev
, j
+ NUM_SSE_IRQS
);
896 gpioname
= g_strdup("EXP_IRQ");
898 gpioname
= g_strdup_printf("EXP_CPU%d_IRQ", i
);
900 qdev_init_gpio_in_named_with_opaque(dev
, armsse_exp_irq
,
902 gpioname
, s
->exp_numirq
);
906 /* Wire up the splitters that connect common IRQs to all CPUs */
907 if (info
->num_cpus
> 1) {
908 for (i
= 0; i
< ARRAY_SIZE(s
->cpu_irq_splitter
); i
++) {
909 if (info
->irq_is_common
[i
]) {
910 Object
*splitter
= OBJECT(&s
->cpu_irq_splitter
[i
]);
911 DeviceState
*devs
= DEVICE(splitter
);
914 if (!object_property_set_int(splitter
, "num-lines",
915 info
->num_cpus
, errp
)) {
918 if (!qdev_realize(DEVICE(splitter
), NULL
, errp
)) {
921 for (cpunum
= 0; cpunum
< info
->num_cpus
; cpunum
++) {
922 DeviceState
*cpudev
= DEVICE(&s
->armv7m
[cpunum
]);
924 qdev_connect_gpio_out(devs
, cpunum
,
925 qdev_get_gpio_in(cpudev
, i
));
931 /* Set up the big aliases first */
932 make_alias(s
, &s
->alias1
, &s
->container
, "alias 1",
933 0x10000000, 0x10000000, 0x00000000);
934 make_alias(s
, &s
->alias2
, &s
->container
,
935 "alias 2", 0x30000000, 0x10000000, 0x20000000);
936 /* The 0x50000000..0x5fffffff region is not a pure alias: it has
937 * a few extra devices that only appear there (generally the
938 * control interfaces for the protection controllers).
939 * We implement this by mapping those devices over the top of this
940 * alias MR at a higher priority. Some of the devices in this range
941 * are per-CPU, so we must put this alias in the per-cpu containers.
943 for (i
= 0; i
< info
->num_cpus
; i
++) {
944 make_alias(s
, &s
->alias3
[i
], &s
->cpu_container
[i
],
945 "alias 3", 0x50000000, 0x10000000, 0x40000000);
948 /* Security controller */
949 object_property_set_int(OBJECT(&s
->secctl
), "sse-version",
950 info
->sse_version
, &error_abort
);
951 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->secctl
), errp
)) {
954 sbd_secctl
= SYS_BUS_DEVICE(&s
->secctl
);
955 dev_secctl
= DEVICE(&s
->secctl
);
956 sysbus_mmio_map(sbd_secctl
, 0, 0x50080000);
957 sysbus_mmio_map(sbd_secctl
, 1, 0x40080000);
959 s
->nsc_cfg_in
= qemu_allocate_irq(nsccfg_handler
, s
, 1);
960 qdev_connect_gpio_out_named(dev_secctl
, "nsc_cfg", 0, s
->nsc_cfg_in
);
962 /* The sec_resp_cfg output from the security controller must be split into
963 * multiple lines, one for each of the PPCs within the ARMSSE and one
964 * that will be an output from the ARMSSE to the system.
966 if (!object_property_set_int(OBJECT(&s
->sec_resp_splitter
),
967 "num-lines", 3, errp
)) {
970 if (!qdev_realize(DEVICE(&s
->sec_resp_splitter
), NULL
, errp
)) {
973 dev_splitter
= DEVICE(&s
->sec_resp_splitter
);
974 qdev_connect_gpio_out_named(dev_secctl
, "sec_resp_cfg", 0,
975 qdev_get_gpio_in(dev_splitter
, 0));
977 /* Each SRAM bank lives behind its own Memory Protection Controller */
978 for (i
= 0; i
< info
->sram_banks
; i
++) {
979 char *ramname
= g_strdup_printf("armsse.sram%d", i
);
980 SysBusDevice
*sbd_mpc
;
981 uint32_t sram_bank_size
= 1 << s
->sram_addr_width
;
983 memory_region_init_ram(&s
->sram
[i
], NULL
, ramname
,
984 sram_bank_size
, &err
);
987 error_propagate(errp
, err
);
990 object_property_set_link(OBJECT(&s
->mpc
[i
]), "downstream",
991 OBJECT(&s
->sram
[i
]), &error_abort
);
992 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->mpc
[i
]), errp
)) {
995 /* Map the upstream end of the MPC into the right place... */
996 sbd_mpc
= SYS_BUS_DEVICE(&s
->mpc
[i
]);
997 memory_region_add_subregion(&s
->container
,
998 0x20000000 + i
* sram_bank_size
,
999 sysbus_mmio_get_region(sbd_mpc
, 1));
1000 /* ...and its register interface */
1001 memory_region_add_subregion(&s
->container
, 0x50083000 + i
* 0x1000,
1002 sysbus_mmio_get_region(sbd_mpc
, 0));
1005 /* We must OR together lines from the MPC splitters to go to the NVIC */
1006 if (!object_property_set_int(OBJECT(&s
->mpc_irq_orgate
), "num-lines",
1007 IOTS_NUM_EXP_MPC
+ info
->sram_banks
,
1011 if (!qdev_realize(DEVICE(&s
->mpc_irq_orgate
), NULL
, errp
)) {
1014 qdev_connect_gpio_out(DEVICE(&s
->mpc_irq_orgate
), 0,
1015 armsse_get_common_irq_in(s
, 9));
1017 /* This OR gate wires together outputs from the secure watchdogs to NMI */
1018 if (!object_property_set_int(OBJECT(&s
->nmi_orgate
), "num-lines", 2,
1022 if (!qdev_realize(DEVICE(&s
->nmi_orgate
), NULL
, errp
)) {
1025 qdev_connect_gpio_out(DEVICE(&s
->nmi_orgate
), 0,
1026 qdev_get_gpio_in_named(DEVICE(&s
->armv7m
), "NMI", 0));
1028 /* The SSE-300 has a System Counter / System Timestamp Generator */
1029 if (info
->has_sse_counter
) {
1030 SysBusDevice
*sbd
= SYS_BUS_DEVICE(&s
->sse_counter
);
1032 qdev_connect_clock_in(DEVICE(sbd
), "CLK", s
->mainclk
);
1033 if (!sysbus_realize(sbd
, errp
)) {
1037 * The control frame is only in the Secure region;
1038 * the status frame is in the NS region (and visible in the
1039 * S region via the alias mapping).
1041 memory_region_add_subregion(&s
->container
, 0x58100000,
1042 sysbus_mmio_get_region(sbd
, 0));
1043 memory_region_add_subregion(&s
->container
, 0x48101000,
1044 sysbus_mmio_get_region(sbd
, 1));
1047 /* Devices behind APB PPC0:
1048 * 0x40000000: timer0
1049 * 0x40001000: timer1
1050 * 0x40002000: dual timer
1051 * 0x40003000: MHU0 (SSE-200 only)
1052 * 0x40004000: MHU1 (SSE-200 only)
1053 * We must configure and realize each downstream device and connect
1054 * it to the appropriate PPC port; then we can realize the PPC and
1055 * map its upstream ends to the right place in the container.
1057 for (devinfo
= info
->devinfo
; devinfo
->name
; devinfo
++) {
1061 if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_TIMER
)) {
1062 sbd
= SYS_BUS_DEVICE(&s
->timer
[devinfo
->index
]);
1064 qdev_connect_clock_in(DEVICE(sbd
), "pclk",
1065 devinfo
->slowclk
? s
->s32kclk
: s
->mainclk
);
1066 if (!sysbus_realize(sbd
, errp
)) {
1069 mr
= sysbus_mmio_get_region(sbd
, 0);
1070 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_DUALTIMER
)) {
1071 sbd
= SYS_BUS_DEVICE(&s
->dualtimer
);
1073 qdev_connect_clock_in(DEVICE(sbd
), "TIMCLK", s
->mainclk
);
1074 if (!sysbus_realize(sbd
, errp
)) {
1077 mr
= sysbus_mmio_get_region(sbd
, 0);
1078 } else if (!strcmp(devinfo
->type
, TYPE_SSE_TIMER
)) {
1079 sbd
= SYS_BUS_DEVICE(&s
->sse_timer
[devinfo
->index
]);
1081 assert(info
->has_sse_counter
);
1082 object_property_set_link(OBJECT(sbd
), "counter",
1083 OBJECT(&s
->sse_counter
), &error_abort
);
1084 if (!sysbus_realize(sbd
, errp
)) {
1087 mr
= sysbus_mmio_get_region(sbd
, 0);
1088 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_WATCHDOG
)) {
1089 sbd
= SYS_BUS_DEVICE(&s
->cmsdk_watchdog
[devinfo
->index
]);
1091 qdev_connect_clock_in(DEVICE(sbd
), "WDOGCLK",
1092 devinfo
->slowclk
? s
->s32kclk
: s
->mainclk
);
1093 if (!sysbus_realize(sbd
, errp
)) {
1096 mr
= sysbus_mmio_get_region(sbd
, 0);
1097 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSINFO
)) {
1098 sbd
= SYS_BUS_DEVICE(&s
->sysinfo
);
1100 object_property_set_int(OBJECT(&s
->sysinfo
), "SYS_VERSION",
1101 info
->sys_version
, &error_abort
);
1102 object_property_set_int(OBJECT(&s
->sysinfo
), "SYS_CONFIG",
1103 armsse_sys_config_value(s
, info
),
1105 object_property_set_int(OBJECT(&s
->sysinfo
), "sse-version",
1106 info
->sse_version
, &error_abort
);
1107 object_property_set_int(OBJECT(&s
->sysinfo
), "IIDR",
1108 info
->iidr
, &error_abort
);
1109 if (!sysbus_realize(sbd
, errp
)) {
1112 mr
= sysbus_mmio_get_region(sbd
, 0);
1113 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSCTL
)) {
1114 /* System control registers */
1115 sbd
= SYS_BUS_DEVICE(&s
->sysctl
);
1117 object_property_set_int(OBJECT(&s
->sysctl
), "sse-version",
1118 info
->sse_version
, &error_abort
);
1119 object_property_set_int(OBJECT(&s
->sysctl
), "CPUWAIT_RST",
1120 info
->cpuwait_rst
, &error_abort
);
1121 object_property_set_int(OBJECT(&s
->sysctl
), "INITSVTOR0_RST",
1122 s
->init_svtor
, &error_abort
);
1123 object_property_set_int(OBJECT(&s
->sysctl
), "INITSVTOR1_RST",
1124 s
->init_svtor
, &error_abort
);
1125 if (!sysbus_realize(sbd
, errp
)) {
1128 mr
= sysbus_mmio_get_region(sbd
, 0);
1129 } else if (!strcmp(devinfo
->type
, TYPE_UNIMPLEMENTED_DEVICE
)) {
1130 sbd
= SYS_BUS_DEVICE(&s
->unimp
[devinfo
->index
]);
1132 qdev_prop_set_string(DEVICE(sbd
), "name", devinfo
->name
);
1133 qdev_prop_set_uint64(DEVICE(sbd
), "size", devinfo
->size
);
1134 if (!sysbus_realize(sbd
, errp
)) {
1137 mr
= sysbus_mmio_get_region(sbd
, 0);
1139 g_assert_not_reached();
1142 switch (devinfo
->irq
) {
1146 case 0 ... NUM_SSE_IRQS
- 1:
1147 irq
= armsse_get_common_irq_in(s
, devinfo
->irq
);
1151 irq
= qdev_get_gpio_in(DEVICE(&s
->nmi_orgate
),
1152 devinfo
->irq
- NMI_0
);
1155 g_assert_not_reached();
1159 sysbus_connect_irq(sbd
, 0, irq
);
1163 * Devices connected to a PPC are connected to the port here;
1164 * we will map the upstream end of that port to the right address
1165 * in the container later after the PPC has been realized.
1166 * Devices not connected to a PPC can be mapped immediately.
1168 if (devinfo
->ppc
!= NO_PPC
) {
1169 TZPPC
*ppc
= &s
->apb_ppc
[devinfo
->ppc
];
1170 g_autofree
char *portname
= g_strdup_printf("port[%d]",
1172 object_property_set_link(OBJECT(ppc
), portname
, OBJECT(mr
),
1175 memory_region_add_subregion(&s
->container
, devinfo
->addr
, mr
);
1179 if (info
->has_mhus
) {
1181 * An SSE-200 with only one CPU should have only one MHU created,
1182 * with the region where the second MHU usually is being RAZ/WI.
1183 * We don't implement that SSE-200 config; if we want to support
1184 * it then this code needs to be enhanced to handle creating the
1185 * RAZ/WI region instead of the second MHU.
1187 assert(info
->num_cpus
== ARRAY_SIZE(s
->mhu
));
1189 for (i
= 0; i
< ARRAY_SIZE(s
->mhu
); i
++) {
1192 SysBusDevice
*mhu_sbd
= SYS_BUS_DEVICE(&s
->mhu
[i
]);
1194 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->mhu
[i
]), errp
)) {
1197 port
= g_strdup_printf("port[%d]", i
+ 3);
1198 mr
= sysbus_mmio_get_region(mhu_sbd
, 0);
1199 object_property_set_link(OBJECT(&s
->apb_ppc
[0]), port
, OBJECT(mr
),
1204 * Each MHU has an irq line for each CPU:
1205 * MHU 0 irq line 0 -> CPU 0 IRQ 6
1206 * MHU 0 irq line 1 -> CPU 1 IRQ 6
1207 * MHU 1 irq line 0 -> CPU 0 IRQ 7
1208 * MHU 1 irq line 1 -> CPU 1 IRQ 7
1210 for (cpunum
= 0; cpunum
< info
->num_cpus
; cpunum
++) {
1211 DeviceState
*cpudev
= DEVICE(&s
->armv7m
[cpunum
]);
1213 sysbus_connect_irq(mhu_sbd
, cpunum
,
1214 qdev_get_gpio_in(cpudev
, 6 + i
));
1219 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->apb_ppc
[0]), errp
)) {
1223 sbd_apb_ppc0
= SYS_BUS_DEVICE(&s
->apb_ppc
[0]);
1224 dev_apb_ppc0
= DEVICE(&s
->apb_ppc
[0]);
1226 if (info
->has_mhus
) {
1227 mr
= sysbus_mmio_get_region(sbd_apb_ppc0
, 3);
1228 memory_region_add_subregion(&s
->container
, 0x40003000, mr
);
1229 mr
= sysbus_mmio_get_region(sbd_apb_ppc0
, 4);
1230 memory_region_add_subregion(&s
->container
, 0x40004000, mr
);
1232 for (i
= 0; i
< IOTS_APB_PPC0_NUM_PORTS
; i
++) {
1233 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_nonsec", i
,
1234 qdev_get_gpio_in_named(dev_apb_ppc0
,
1236 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_ap", i
,
1237 qdev_get_gpio_in_named(dev_apb_ppc0
,
1240 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_irq_enable", 0,
1241 qdev_get_gpio_in_named(dev_apb_ppc0
,
1243 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_irq_clear", 0,
1244 qdev_get_gpio_in_named(dev_apb_ppc0
,
1246 qdev_connect_gpio_out(dev_splitter
, 0,
1247 qdev_get_gpio_in_named(dev_apb_ppc0
,
1248 "cfg_sec_resp", 0));
1250 /* All the PPC irq lines (from the 2 internal PPCs and the 8 external
1251 * ones) are sent individually to the security controller, and also
1252 * ORed together to give a single combined PPC interrupt to the NVIC.
1254 if (!object_property_set_int(OBJECT(&s
->ppc_irq_orgate
),
1255 "num-lines", NUM_PPCS
, errp
)) {
1258 if (!qdev_realize(DEVICE(&s
->ppc_irq_orgate
), NULL
, errp
)) {
1261 qdev_connect_gpio_out(DEVICE(&s
->ppc_irq_orgate
), 0,
1262 armsse_get_common_irq_in(s
, 10));
1265 * 0x40010000 .. 0x4001ffff (and the 0x5001000... secure-only alias):
1266 * private per-CPU region (all these devices are SSE-200 only):
1267 * 0x50010000: L1 icache control registers
1268 * 0x50011000: CPUSECCTRL (CPU local security control registers)
1269 * 0x4001f000 and 0x5001f000: CPU_IDENTITY register block
1270 * The SSE-300 has an extra:
1271 * 0x40012000 and 0x50012000: CPU_PWRCTRL register block
1273 if (info
->has_cachectrl
) {
1274 for (i
= 0; i
< info
->num_cpus
; i
++) {
1275 char *name
= g_strdup_printf("cachectrl%d", i
);
1278 qdev_prop_set_string(DEVICE(&s
->cachectrl
[i
]), "name", name
);
1280 qdev_prop_set_uint64(DEVICE(&s
->cachectrl
[i
]), "size", 0x1000);
1281 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cachectrl
[i
]), errp
)) {
1285 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cachectrl
[i
]), 0);
1286 memory_region_add_subregion(&s
->cpu_container
[i
], 0x50010000, mr
);
1289 if (info
->has_cpusecctrl
) {
1290 for (i
= 0; i
< info
->num_cpus
; i
++) {
1291 char *name
= g_strdup_printf("CPUSECCTRL%d", i
);
1294 qdev_prop_set_string(DEVICE(&s
->cpusecctrl
[i
]), "name", name
);
1296 qdev_prop_set_uint64(DEVICE(&s
->cpusecctrl
[i
]), "size", 0x1000);
1297 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cpusecctrl
[i
]), errp
)) {
1301 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cpusecctrl
[i
]), 0);
1302 memory_region_add_subregion(&s
->cpu_container
[i
], 0x50011000, mr
);
1305 if (info
->has_cpuid
) {
1306 for (i
= 0; i
< info
->num_cpus
; i
++) {
1309 qdev_prop_set_uint32(DEVICE(&s
->cpuid
[i
]), "CPUID", i
);
1310 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cpuid
[i
]), errp
)) {
1314 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cpuid
[i
]), 0);
1315 memory_region_add_subregion(&s
->cpu_container
[i
], 0x4001F000, mr
);
1318 if (info
->has_cpu_pwrctrl
) {
1319 for (i
= 0; i
< info
->num_cpus
; i
++) {
1322 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cpu_pwrctrl
[i
]), errp
)) {
1326 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cpu_pwrctrl
[i
]), 0);
1327 memory_region_add_subregion(&s
->cpu_container
[i
], 0x40012000, mr
);
1331 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->apb_ppc
[1]), errp
)) {
1335 dev_apb_ppc1
= DEVICE(&s
->apb_ppc
[1]);
1336 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_nonsec", 0,
1337 qdev_get_gpio_in_named(dev_apb_ppc1
,
1339 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_ap", 0,
1340 qdev_get_gpio_in_named(dev_apb_ppc1
,
1342 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_irq_enable", 0,
1343 qdev_get_gpio_in_named(dev_apb_ppc1
,
1345 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_irq_clear", 0,
1346 qdev_get_gpio_in_named(dev_apb_ppc1
,
1348 qdev_connect_gpio_out(dev_splitter
, 1,
1349 qdev_get_gpio_in_named(dev_apb_ppc1
,
1350 "cfg_sec_resp", 0));
1353 * Now both PPCs are realized we can map the upstream ends of
1354 * ports which correspond to entries in the devinfo array.
1355 * The ports which are connected to non-devinfo devices have
1356 * already been mapped.
1358 for (devinfo
= info
->devinfo
; devinfo
->name
; devinfo
++) {
1359 SysBusDevice
*ppc_sbd
;
1361 if (devinfo
->ppc
== NO_PPC
) {
1364 ppc_sbd
= SYS_BUS_DEVICE(&s
->apb_ppc
[devinfo
->ppc
]);
1365 mr
= sysbus_mmio_get_region(ppc_sbd
, devinfo
->ppc_port
);
1366 memory_region_add_subregion(&s
->container
, devinfo
->addr
, mr
);
1369 for (i
= 0; i
< ARRAY_SIZE(s
->ppc_irq_splitter
); i
++) {
1370 Object
*splitter
= OBJECT(&s
->ppc_irq_splitter
[i
]);
1372 if (!object_property_set_int(splitter
, "num-lines", 2, errp
)) {
1375 if (!qdev_realize(DEVICE(splitter
), NULL
, errp
)) {
1380 for (i
= 0; i
< IOTS_NUM_AHB_EXP_PPC
; i
++) {
1381 char *ppcname
= g_strdup_printf("ahb_ppcexp%d", i
);
1383 armsse_forward_ppc(s
, ppcname
, i
);
1387 for (i
= 0; i
< IOTS_NUM_APB_EXP_PPC
; i
++) {
1388 char *ppcname
= g_strdup_printf("apb_ppcexp%d", i
);
1390 armsse_forward_ppc(s
, ppcname
, i
+ IOTS_NUM_AHB_EXP_PPC
);
1394 for (i
= NUM_EXTERNAL_PPCS
; i
< NUM_PPCS
; i
++) {
1395 /* Wire up IRQ splitter for internal PPCs */
1396 DeviceState
*devs
= DEVICE(&s
->ppc_irq_splitter
[i
]);
1397 char *gpioname
= g_strdup_printf("apb_ppc%d_irq_status",
1398 i
- NUM_EXTERNAL_PPCS
);
1399 TZPPC
*ppc
= &s
->apb_ppc
[i
- NUM_EXTERNAL_PPCS
];
1401 qdev_connect_gpio_out(devs
, 0,
1402 qdev_get_gpio_in_named(dev_secctl
, gpioname
, 0));
1403 qdev_connect_gpio_out(devs
, 1,
1404 qdev_get_gpio_in(DEVICE(&s
->ppc_irq_orgate
), i
));
1405 qdev_connect_gpio_out_named(DEVICE(ppc
), "irq", 0,
1406 qdev_get_gpio_in(devs
, 0));
1410 /* Wire up the splitters for the MPC IRQs */
1411 for (i
= 0; i
< IOTS_NUM_EXP_MPC
+ info
->sram_banks
; i
++) {
1412 SplitIRQ
*splitter
= &s
->mpc_irq_splitter
[i
];
1413 DeviceState
*dev_splitter
= DEVICE(splitter
);
1415 if (!object_property_set_int(OBJECT(splitter
), "num-lines", 2,
1419 if (!qdev_realize(DEVICE(splitter
), NULL
, errp
)) {
1423 if (i
< IOTS_NUM_EXP_MPC
) {
1424 /* Splitter input is from GPIO input line */
1425 s
->mpcexp_status_in
[i
] = qdev_get_gpio_in(dev_splitter
, 0);
1426 qdev_connect_gpio_out(dev_splitter
, 0,
1427 qdev_get_gpio_in_named(dev_secctl
,
1428 "mpcexp_status", i
));
1430 /* Splitter input is from our own MPC */
1431 qdev_connect_gpio_out_named(DEVICE(&s
->mpc
[i
- IOTS_NUM_EXP_MPC
]),
1433 qdev_get_gpio_in(dev_splitter
, 0));
1434 qdev_connect_gpio_out(dev_splitter
, 0,
1435 qdev_get_gpio_in_named(dev_secctl
,
1437 i
- IOTS_NUM_EXP_MPC
));
1440 qdev_connect_gpio_out(dev_splitter
, 1,
1441 qdev_get_gpio_in(DEVICE(&s
->mpc_irq_orgate
), i
));
1443 /* Create GPIO inputs which will pass the line state for our
1444 * mpcexp_irq inputs to the correct splitter devices.
1446 qdev_init_gpio_in_named(dev
, armsse_mpcexp_status
, "mpcexp_status",
1449 armsse_forward_sec_resp_cfg(s
);
1451 /* Forward the MSC related signals */
1452 qdev_pass_gpios(dev_secctl
, dev
, "mscexp_status");
1453 qdev_pass_gpios(dev_secctl
, dev
, "mscexp_clear");
1454 qdev_pass_gpios(dev_secctl
, dev
, "mscexp_ns");
1455 qdev_connect_gpio_out_named(dev_secctl
, "msc_irq", 0,
1456 armsse_get_common_irq_in(s
, 11));
1459 * Expose our container region to the board model; this corresponds
1460 * to the AHB Slave Expansion ports which allow bus master devices
1461 * (eg DMA controllers) in the board model to make transactions into
1462 * devices in the ARMSSE.
1464 sysbus_init_mmio(SYS_BUS_DEVICE(s
), &s
->container
);
1466 /* Set initial system_clock_scale from MAINCLK */
1467 armsse_mainclk_update(s
, ClockUpdate
);
1470 static void armsse_idau_check(IDAUInterface
*ii
, uint32_t address
,
1471 int *iregion
, bool *exempt
, bool *ns
, bool *nsc
)
1474 * For ARMSSE systems the IDAU responses are simple logical functions
1475 * of the address bits. The NSC attribute is guest-adjustable via the
1476 * NSCCFG register in the security controller.
1478 ARMSSE
*s
= ARM_SSE(ii
);
1479 int region
= extract32(address
, 28, 4);
1481 *ns
= !(region
& 1);
1482 *nsc
= (region
== 1 && (s
->nsccfg
& 1)) || (region
== 3 && (s
->nsccfg
& 2));
1483 /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */
1484 *exempt
= (address
& 0xeff00000) == 0xe0000000;
1488 static const VMStateDescription armsse_vmstate
= {
1491 .minimum_version_id
= 2,
1492 .fields
= (VMStateField
[]) {
1493 VMSTATE_CLOCK(mainclk
, ARMSSE
),
1494 VMSTATE_CLOCK(s32kclk
, ARMSSE
),
1495 VMSTATE_UINT32(nsccfg
, ARMSSE
),
1496 VMSTATE_END_OF_LIST()
1500 static void armsse_reset(DeviceState
*dev
)
1502 ARMSSE
*s
= ARM_SSE(dev
);
1507 static void armsse_class_init(ObjectClass
*klass
, void *data
)
1509 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1510 IDAUInterfaceClass
*iic
= IDAU_INTERFACE_CLASS(klass
);
1511 ARMSSEClass
*asc
= ARM_SSE_CLASS(klass
);
1512 const ARMSSEInfo
*info
= data
;
1514 dc
->realize
= armsse_realize
;
1515 dc
->vmsd
= &armsse_vmstate
;
1516 device_class_set_props(dc
, info
->props
);
1517 dc
->reset
= armsse_reset
;
1518 iic
->check
= armsse_idau_check
;
1522 static const TypeInfo armsse_info
= {
1523 .name
= TYPE_ARM_SSE
,
1524 .parent
= TYPE_SYS_BUS_DEVICE
,
1525 .instance_size
= sizeof(ARMSSE
),
1526 .class_size
= sizeof(ARMSSEClass
),
1527 .instance_init
= armsse_init
,
1529 .interfaces
= (InterfaceInfo
[]) {
1530 { TYPE_IDAU_INTERFACE
},
1535 static void armsse_register_types(void)
1539 type_register_static(&armsse_info
);
1541 for (i
= 0; i
< ARRAY_SIZE(armsse_variants
); i
++) {
1543 .name
= armsse_variants
[i
].name
,
1544 .parent
= TYPE_ARM_SSE
,
1545 .class_init
= armsse_class_init
,
1546 .class_data
= (void *)&armsse_variants
[i
],
1552 type_init(armsse_register_types
);