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 sse200_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 Property sse300_properties
[] = {
101 DEFINE_PROP_LINK("memory", ARMSSE
, board_memory
, TYPE_MEMORY_REGION
,
103 DEFINE_PROP_UINT32("EXP_NUMIRQ", ARMSSE
, exp_numirq
, 64),
104 DEFINE_PROP_UINT32("SRAM_ADDR_WIDTH", ARMSSE
, sram_addr_width
, 15),
105 DEFINE_PROP_UINT32("init-svtor", ARMSSE
, init_svtor
, 0x10000000),
106 DEFINE_PROP_BOOL("CPU0_FPU", ARMSSE
, cpu_fpu
[0], true),
107 DEFINE_PROP_BOOL("CPU0_DSP", ARMSSE
, cpu_dsp
[0], true),
108 DEFINE_PROP_END_OF_LIST()
111 static const ARMSSEDeviceInfo iotkit_devices
[] = {
114 .type
= TYPE_CMSDK_APB_TIMER
,
123 .type
= TYPE_CMSDK_APB_TIMER
,
132 .type
= TYPE_CMSDK_APB_TIMER
,
142 .type
= TYPE_CMSDK_APB_DUALTIMER
,
150 .name
= "s32kwatchdog",
151 .type
= TYPE_CMSDK_APB_WATCHDOG
,
159 .name
= "nswatchdog",
160 .type
= TYPE_CMSDK_APB_WATCHDOG
,
168 .type
= TYPE_CMSDK_APB_WATCHDOG
,
175 .name
= "armsse-sysinfo",
176 .type
= TYPE_IOTKIT_SYSINFO
,
183 .name
= "armsse-sysctl",
184 .type
= TYPE_IOTKIT_SYSCTL
,
195 static const ARMSSEDeviceInfo sse200_devices
[] = {
198 .type
= TYPE_CMSDK_APB_TIMER
,
207 .type
= TYPE_CMSDK_APB_TIMER
,
216 .type
= TYPE_CMSDK_APB_TIMER
,
226 .type
= TYPE_CMSDK_APB_DUALTIMER
,
234 .name
= "s32kwatchdog",
235 .type
= TYPE_CMSDK_APB_WATCHDOG
,
243 .name
= "nswatchdog",
244 .type
= TYPE_CMSDK_APB_WATCHDOG
,
252 .type
= TYPE_CMSDK_APB_WATCHDOG
,
259 .name
= "armsse-sysinfo",
260 .type
= TYPE_IOTKIT_SYSINFO
,
267 .name
= "armsse-sysctl",
268 .type
= TYPE_IOTKIT_SYSCTL
,
275 .name
= "CPU0CORE_PPU",
276 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
284 .name
= "CPU1CORE_PPU",
285 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
294 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
303 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
312 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
321 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
330 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
339 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
351 static const ARMSSEDeviceInfo sse300_devices
[] = {
354 .type
= TYPE_SSE_TIMER
,
363 .type
= TYPE_SSE_TIMER
,
372 .type
= TYPE_SSE_TIMER
,
381 .type
= TYPE_SSE_TIMER
,
390 .type
= TYPE_CMSDK_APB_TIMER
,
399 .name
= "s32kwatchdog",
400 .type
= TYPE_CMSDK_APB_WATCHDOG
,
409 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
417 .name
= "armsse-sysinfo",
418 .type
= TYPE_IOTKIT_SYSINFO
,
425 .name
= "armsse-sysctl",
426 .type
= TYPE_IOTKIT_SYSCTL
,
434 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
442 .name
= "CPU0CORE_PPU",
443 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
452 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
461 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
473 /* Is internal IRQ n shared between CPUs in a multi-core SSE ? */
474 static const bool sse200_irq_is_common
[32] = {
476 /* 6, 7: per-CPU MHU interrupts */
478 /* 13: per-CPU icache interrupt */
484 /* 28, 29: per-CPU CTI interrupts */
485 /* 30, 31: reserved */
488 static const bool sse300_irq_is_common
[32] = {
490 /* 6, 7: per-CPU MHU interrupts */
494 /* 17-25: reserved */
496 /* 28, 29: per-CPU CTI interrupts */
497 /* 30, 31: reserved */
500 static const ARMSSEInfo armsse_variants
[] = {
503 .sse_version
= ARMSSE_IOTKIT
,
506 .sys_version
= 0x41743,
510 .has_cachectrl
= false,
511 .has_cpusecctrl
= false,
513 .has_cpu_pwrctrl
= false,
514 .has_sse_counter
= false,
515 .props
= iotkit_properties
,
516 .devinfo
= iotkit_devices
,
517 .irq_is_common
= sse200_irq_is_common
,
521 .sse_version
= ARMSSE_SSE200
,
524 .sys_version
= 0x22041743,
528 .has_cachectrl
= true,
529 .has_cpusecctrl
= true,
531 .has_cpu_pwrctrl
= false,
532 .has_sse_counter
= false,
533 .props
= sse200_properties
,
534 .devinfo
= sse200_devices
,
535 .irq_is_common
= sse200_irq_is_common
,
539 .sse_version
= ARMSSE_SSE300
,
542 .sys_version
= 0x7e00043b,
546 .has_cachectrl
= false,
547 .has_cpusecctrl
= true,
549 .has_cpu_pwrctrl
= true,
550 .has_sse_counter
= true,
551 .props
= sse300_properties
,
552 .devinfo
= sse300_devices
,
553 .irq_is_common
= sse300_irq_is_common
,
557 static uint32_t armsse_sys_config_value(ARMSSE
*s
, const ARMSSEInfo
*info
)
559 /* Return the SYS_CONFIG value for this SSE */
562 switch (info
->sse_version
) {
565 sys_config
= deposit32(sys_config
, 0, 4, info
->sram_banks
);
566 sys_config
= deposit32(sys_config
, 4, 4, s
->sram_addr_width
- 12);
570 sys_config
= deposit32(sys_config
, 0, 4, info
->sram_banks
);
571 sys_config
= deposit32(sys_config
, 4, 5, s
->sram_addr_width
);
572 sys_config
= deposit32(sys_config
, 24, 4, 2);
573 if (info
->num_cpus
> 1) {
574 sys_config
= deposit32(sys_config
, 10, 1, 1);
575 sys_config
= deposit32(sys_config
, 20, 4, info
->sram_banks
- 1);
576 sys_config
= deposit32(sys_config
, 28, 4, 2);
581 sys_config
= deposit32(sys_config
, 0, 4, info
->sram_banks
);
582 sys_config
= deposit32(sys_config
, 4, 5, s
->sram_addr_width
);
583 sys_config
= deposit32(sys_config
, 16, 3, 3); /* CPU0 = Cortex-M55 */
586 g_assert_not_reached();
591 /* Clock frequency in HZ of the 32KHz "slow clock" */
592 #define S32KCLK (32 * 1000)
595 * Create an alias region in @container of @size bytes starting at @base
596 * which mirrors the memory starting at @orig.
598 static void make_alias(ARMSSE
*s
, MemoryRegion
*mr
, MemoryRegion
*container
,
599 const char *name
, hwaddr base
, hwaddr size
, hwaddr orig
)
601 memory_region_init_alias(mr
, NULL
, name
, container
, orig
, size
);
602 /* The alias is even lower priority than unimplemented_device regions */
603 memory_region_add_subregion_overlap(container
, base
, mr
, -1500);
606 static void irq_status_forwarder(void *opaque
, int n
, int level
)
608 qemu_irq destirq
= opaque
;
610 qemu_set_irq(destirq
, level
);
613 static void nsccfg_handler(void *opaque
, int n
, int level
)
615 ARMSSE
*s
= ARM_SSE(opaque
);
620 static void armsse_forward_ppc(ARMSSE
*s
, const char *ppcname
, int ppcnum
)
622 /* Each of the 4 AHB and 4 APB PPCs that might be present in a
623 * system using the ARMSSE has a collection of control lines which
624 * are provided by the security controller and which we want to
625 * expose as control lines on the ARMSSE device itself, so the
626 * code using the ARMSSE can wire them up to the PPCs.
628 SplitIRQ
*splitter
= &s
->ppc_irq_splitter
[ppcnum
];
629 DeviceState
*armssedev
= DEVICE(s
);
630 DeviceState
*dev_secctl
= DEVICE(&s
->secctl
);
631 DeviceState
*dev_splitter
= DEVICE(splitter
);
634 name
= g_strdup_printf("%s_nonsec", ppcname
);
635 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
637 name
= g_strdup_printf("%s_ap", ppcname
);
638 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
640 name
= g_strdup_printf("%s_irq_enable", ppcname
);
641 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
643 name
= g_strdup_printf("%s_irq_clear", ppcname
);
644 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
647 /* irq_status is a little more tricky, because we need to
648 * split it so we can send it both to the security controller
649 * and to our OR gate for the NVIC interrupt line.
650 * Connect up the splitter's outputs, and create a GPIO input
651 * which will pass the line state to the input splitter.
653 name
= g_strdup_printf("%s_irq_status", ppcname
);
654 qdev_connect_gpio_out(dev_splitter
, 0,
655 qdev_get_gpio_in_named(dev_secctl
,
657 qdev_connect_gpio_out(dev_splitter
, 1,
658 qdev_get_gpio_in(DEVICE(&s
->ppc_irq_orgate
), ppcnum
));
659 s
->irq_status_in
[ppcnum
] = qdev_get_gpio_in(dev_splitter
, 0);
660 qdev_init_gpio_in_named_with_opaque(armssedev
, irq_status_forwarder
,
661 s
->irq_status_in
[ppcnum
], name
, 1);
665 static void armsse_forward_sec_resp_cfg(ARMSSE
*s
)
667 /* Forward the 3rd output from the splitter device as a
668 * named GPIO output of the armsse object.
670 DeviceState
*dev
= DEVICE(s
);
671 DeviceState
*dev_splitter
= DEVICE(&s
->sec_resp_splitter
);
673 qdev_init_gpio_out_named(dev
, &s
->sec_resp_cfg
, "sec_resp_cfg", 1);
674 s
->sec_resp_cfg_in
= qemu_allocate_irq(irq_status_forwarder
,
676 qdev_connect_gpio_out(dev_splitter
, 2, s
->sec_resp_cfg_in
);
679 static void armsse_mainclk_update(void *opaque
, ClockEvent event
)
681 ARMSSE
*s
= ARM_SSE(opaque
);
684 * Set system_clock_scale from our Clock input; this is what
685 * controls the tick rate of the CPU SysTick timer.
687 system_clock_scale
= clock_ticks_to_ns(s
->mainclk
, 1);
690 static void armsse_init(Object
*obj
)
692 ARMSSE
*s
= ARM_SSE(obj
);
693 ARMSSEClass
*asc
= ARM_SSE_GET_CLASS(obj
);
694 const ARMSSEInfo
*info
= asc
->info
;
695 const ARMSSEDeviceInfo
*devinfo
;
698 assert(info
->sram_banks
<= MAX_SRAM_BANKS
);
699 assert(info
->num_cpus
<= SSE_MAX_CPUS
);
701 s
->mainclk
= qdev_init_clock_in(DEVICE(s
), "MAINCLK",
702 armsse_mainclk_update
, s
, ClockUpdate
);
703 s
->s32kclk
= qdev_init_clock_in(DEVICE(s
), "S32KCLK", NULL
, NULL
, 0);
705 memory_region_init(&s
->container
, obj
, "armsse-container", UINT64_MAX
);
707 for (i
= 0; i
< info
->num_cpus
; i
++) {
709 * We put each CPU in its own cluster as they are logically
710 * distinct and may be configured differently.
714 name
= g_strdup_printf("cluster%d", i
);
715 object_initialize_child(obj
, name
, &s
->cluster
[i
], TYPE_CPU_CLUSTER
);
716 qdev_prop_set_uint32(DEVICE(&s
->cluster
[i
]), "cluster-id", i
);
719 name
= g_strdup_printf("armv7m%d", i
);
720 object_initialize_child(OBJECT(&s
->cluster
[i
]), name
, &s
->armv7m
[i
],
722 qdev_prop_set_string(DEVICE(&s
->armv7m
[i
]), "cpu-type",
723 ARM_CPU_TYPE_NAME("cortex-m33"));
725 name
= g_strdup_printf("arm-sse-cpu-container%d", i
);
726 memory_region_init(&s
->cpu_container
[i
], obj
, name
, UINT64_MAX
);
729 name
= g_strdup_printf("arm-sse-container-alias%d", i
);
730 memory_region_init_alias(&s
->container_alias
[i
- 1], obj
,
731 name
, &s
->container
, 0, UINT64_MAX
);
736 for (devinfo
= info
->devinfo
; devinfo
->name
; devinfo
++) {
737 assert(devinfo
->ppc
== NO_PPC
|| devinfo
->ppc
< ARRAY_SIZE(s
->apb_ppc
));
738 if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_TIMER
)) {
739 assert(devinfo
->index
< ARRAY_SIZE(s
->timer
));
740 object_initialize_child(obj
, devinfo
->name
,
741 &s
->timer
[devinfo
->index
],
742 TYPE_CMSDK_APB_TIMER
);
743 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_DUALTIMER
)) {
744 assert(devinfo
->index
== 0);
745 object_initialize_child(obj
, devinfo
->name
, &s
->dualtimer
,
746 TYPE_CMSDK_APB_DUALTIMER
);
747 } else if (!strcmp(devinfo
->type
, TYPE_SSE_TIMER
)) {
748 assert(devinfo
->index
< ARRAY_SIZE(s
->sse_timer
));
749 object_initialize_child(obj
, devinfo
->name
,
750 &s
->sse_timer
[devinfo
->index
],
752 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_WATCHDOG
)) {
753 assert(devinfo
->index
< ARRAY_SIZE(s
->cmsdk_watchdog
));
754 object_initialize_child(obj
, devinfo
->name
,
755 &s
->cmsdk_watchdog
[devinfo
->index
],
756 TYPE_CMSDK_APB_WATCHDOG
);
757 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSINFO
)) {
758 assert(devinfo
->index
== 0);
759 object_initialize_child(obj
, devinfo
->name
, &s
->sysinfo
,
760 TYPE_IOTKIT_SYSINFO
);
761 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSCTL
)) {
762 assert(devinfo
->index
== 0);
763 object_initialize_child(obj
, devinfo
->name
, &s
->sysctl
,
765 } else if (!strcmp(devinfo
->type
, TYPE_UNIMPLEMENTED_DEVICE
)) {
766 assert(devinfo
->index
< ARRAY_SIZE(s
->unimp
));
767 object_initialize_child(obj
, devinfo
->name
,
768 &s
->unimp
[devinfo
->index
],
769 TYPE_UNIMPLEMENTED_DEVICE
);
771 g_assert_not_reached();
775 object_initialize_child(obj
, "secctl", &s
->secctl
, TYPE_IOTKIT_SECCTL
);
777 for (i
= 0; i
< ARRAY_SIZE(s
->apb_ppc
); i
++) {
778 g_autofree
char *name
= g_strdup_printf("apb-ppc%d", i
);
779 object_initialize_child(obj
, name
, &s
->apb_ppc
[i
], TYPE_TZ_PPC
);
782 for (i
= 0; i
< info
->sram_banks
; i
++) {
783 char *name
= g_strdup_printf("mpc%d", i
);
784 object_initialize_child(obj
, name
, &s
->mpc
[i
], TYPE_TZ_MPC
);
787 object_initialize_child(obj
, "mpc-irq-orgate", &s
->mpc_irq_orgate
,
790 for (i
= 0; i
< IOTS_NUM_EXP_MPC
+ info
->sram_banks
; i
++) {
791 char *name
= g_strdup_printf("mpc-irq-splitter-%d", i
);
792 SplitIRQ
*splitter
= &s
->mpc_irq_splitter
[i
];
794 object_initialize_child(obj
, name
, splitter
, TYPE_SPLIT_IRQ
);
798 if (info
->has_mhus
) {
799 object_initialize_child(obj
, "mhu0", &s
->mhu
[0], TYPE_ARMSSE_MHU
);
800 object_initialize_child(obj
, "mhu1", &s
->mhu
[1], TYPE_ARMSSE_MHU
);
802 if (info
->has_cachectrl
) {
803 for (i
= 0; i
< info
->num_cpus
; i
++) {
804 char *name
= g_strdup_printf("cachectrl%d", i
);
806 object_initialize_child(obj
, name
, &s
->cachectrl
[i
],
807 TYPE_UNIMPLEMENTED_DEVICE
);
811 if (info
->has_cpusecctrl
) {
812 for (i
= 0; i
< info
->num_cpus
; i
++) {
813 char *name
= g_strdup_printf("cpusecctrl%d", i
);
815 object_initialize_child(obj
, name
, &s
->cpusecctrl
[i
],
816 TYPE_UNIMPLEMENTED_DEVICE
);
820 if (info
->has_cpuid
) {
821 for (i
= 0; i
< info
->num_cpus
; i
++) {
822 char *name
= g_strdup_printf("cpuid%d", i
);
824 object_initialize_child(obj
, name
, &s
->cpuid
[i
],
829 if (info
->has_cpu_pwrctrl
) {
830 for (i
= 0; i
< info
->num_cpus
; i
++) {
831 char *name
= g_strdup_printf("cpu_pwrctrl%d", i
);
833 object_initialize_child(obj
, name
, &s
->cpu_pwrctrl
[i
],
834 TYPE_ARMSSE_CPU_PWRCTRL
);
838 if (info
->has_sse_counter
) {
839 object_initialize_child(obj
, "sse-counter", &s
->sse_counter
,
843 object_initialize_child(obj
, "nmi-orgate", &s
->nmi_orgate
, TYPE_OR_IRQ
);
844 object_initialize_child(obj
, "ppc-irq-orgate", &s
->ppc_irq_orgate
,
846 object_initialize_child(obj
, "sec-resp-splitter", &s
->sec_resp_splitter
,
848 for (i
= 0; i
< ARRAY_SIZE(s
->ppc_irq_splitter
); i
++) {
849 char *name
= g_strdup_printf("ppc-irq-splitter-%d", i
);
850 SplitIRQ
*splitter
= &s
->ppc_irq_splitter
[i
];
852 object_initialize_child(obj
, name
, splitter
, TYPE_SPLIT_IRQ
);
855 if (info
->num_cpus
> 1) {
856 for (i
= 0; i
< ARRAY_SIZE(s
->cpu_irq_splitter
); i
++) {
857 if (info
->irq_is_common
[i
]) {
858 char *name
= g_strdup_printf("cpu-irq-splitter%d", i
);
859 SplitIRQ
*splitter
= &s
->cpu_irq_splitter
[i
];
861 object_initialize_child(obj
, name
, splitter
, TYPE_SPLIT_IRQ
);
868 static void armsse_exp_irq(void *opaque
, int n
, int level
)
870 qemu_irq
*irqarray
= opaque
;
872 qemu_set_irq(irqarray
[n
], level
);
875 static void armsse_mpcexp_status(void *opaque
, int n
, int level
)
877 ARMSSE
*s
= ARM_SSE(opaque
);
878 qemu_set_irq(s
->mpcexp_status_in
[n
], level
);
881 static qemu_irq
armsse_get_common_irq_in(ARMSSE
*s
, int irqno
)
884 * Return a qemu_irq which can be used to signal IRQ n to
885 * all CPUs in the SSE.
887 ARMSSEClass
*asc
= ARM_SSE_GET_CLASS(s
);
888 const ARMSSEInfo
*info
= asc
->info
;
890 assert(info
->irq_is_common
[irqno
]);
892 if (info
->num_cpus
== 1) {
893 /* Only one CPU -- just connect directly to it */
894 return qdev_get_gpio_in(DEVICE(&s
->armv7m
[0]), irqno
);
896 /* Connect to the splitter which feeds all CPUs */
897 return qdev_get_gpio_in(DEVICE(&s
->cpu_irq_splitter
[irqno
]), 0);
901 static void armsse_realize(DeviceState
*dev
, Error
**errp
)
903 ARMSSE
*s
= ARM_SSE(dev
);
904 ARMSSEClass
*asc
= ARM_SSE_GET_CLASS(dev
);
905 const ARMSSEInfo
*info
= asc
->info
;
906 const ARMSSEDeviceInfo
*devinfo
;
910 SysBusDevice
*sbd_apb_ppc0
;
911 SysBusDevice
*sbd_secctl
;
912 DeviceState
*dev_apb_ppc0
;
913 DeviceState
*dev_apb_ppc1
;
914 DeviceState
*dev_secctl
;
915 DeviceState
*dev_splitter
;
916 uint32_t addr_width_max
;
918 if (!s
->board_memory
) {
919 error_setg(errp
, "memory property was not set");
923 if (!clock_has_source(s
->mainclk
)) {
924 error_setg(errp
, "MAINCLK clock was not connected");
926 if (!clock_has_source(s
->s32kclk
)) {
927 error_setg(errp
, "S32KCLK clock was not connected");
930 assert(info
->num_cpus
<= SSE_MAX_CPUS
);
932 /* max SRAM_ADDR_WIDTH: 24 - log2(SRAM_NUM_BANK) */
933 assert(is_power_of_2(info
->sram_banks
));
934 addr_width_max
= 24 - ctz32(info
->sram_banks
);
935 if (s
->sram_addr_width
< 1 || s
->sram_addr_width
> addr_width_max
) {
936 error_setg(errp
, "SRAM_ADDR_WIDTH must be between 1 and %d",
941 /* Handling of which devices should be available only to secure
942 * code is usually done differently for M profile than for A profile.
943 * Instead of putting some devices only into the secure address space,
944 * devices exist in both address spaces but with hard-wired security
945 * permissions that will cause the CPU to fault for non-secure accesses.
947 * The ARMSSE has an IDAU (Implementation Defined Access Unit),
948 * which specifies hard-wired security permissions for different
949 * areas of the physical address space. For the ARMSSE IDAU, the
950 * top 4 bits of the physical address are the IDAU region ID, and
951 * if bit 28 (ie the lowest bit of the ID) is 0 then this is an NS
952 * region, otherwise it is an S region.
954 * The various devices and RAMs are generally all mapped twice,
955 * once into a region that the IDAU defines as secure and once
956 * into a non-secure region. They sit behind either a Memory
957 * Protection Controller (for RAM) or a Peripheral Protection
958 * Controller (for devices), which allow a more fine grained
959 * configuration of whether non-secure accesses are permitted.
961 * (The other place that guest software can configure security
962 * permissions is in the architected SAU (Security Attribution
963 * Unit), which is entirely inside the CPU. The IDAU can upgrade
964 * the security attributes for a region to more restrictive than
965 * the SAU specifies, but cannot downgrade them.)
967 * 0x10000000..0x1fffffff alias of 0x00000000..0x0fffffff
968 * 0x20000000..0x2007ffff 32KB FPGA block RAM
969 * 0x30000000..0x3fffffff alias of 0x20000000..0x2fffffff
970 * 0x40000000..0x4000ffff base peripheral region 1
971 * 0x40010000..0x4001ffff CPU peripherals (none for ARMSSE)
972 * 0x40020000..0x4002ffff system control element peripherals
973 * 0x40080000..0x400fffff base peripheral region 2
974 * 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff
977 memory_region_add_subregion_overlap(&s
->container
, 0, s
->board_memory
, -2);
979 for (i
= 0; i
< info
->num_cpus
; i
++) {
980 DeviceState
*cpudev
= DEVICE(&s
->armv7m
[i
]);
981 Object
*cpuobj
= OBJECT(&s
->armv7m
[i
]);
985 qdev_prop_set_uint32(cpudev
, "num-irq", s
->exp_numirq
+ NUM_SSE_IRQS
);
987 * In real hardware the initial Secure VTOR is set from the INITSVTOR*
988 * registers in the IoT Kit System Control Register block. In QEMU
989 * we set the initial value here, and also the reset value of the
990 * sysctl register, from this object's QOM init-svtor property.
991 * If the guest changes the INITSVTOR* registers at runtime then the
992 * code in iotkit-sysctl.c will update the CPU init-svtor property
993 * (which will then take effect on the next CPU warm-reset).
995 * Note that typically a board using the SSE-200 will have a system
996 * control processor whose boot firmware initializes the INITSVTOR*
997 * registers before powering up the CPUs. QEMU doesn't emulate
998 * the control processor, so instead we behave in the way that the
999 * firmware does: the initial value should be set by the board code
1000 * (using the init-svtor property on the ARMSSE object) to match
1001 * whatever its firmware does.
1003 qdev_prop_set_uint32(cpudev
, "init-svtor", s
->init_svtor
);
1005 * CPUs start powered down if the corresponding bit in the CPUWAIT
1006 * register is 1. In real hardware the CPUWAIT register reset value is
1007 * a configurable property of the SSE-200 (via the CPUWAIT0_RST and
1008 * CPUWAIT1_RST parameters), but since all the boards we care about
1009 * start CPU0 and leave CPU1 powered off, we hard-code that in
1010 * info->cpuwait_rst for now. We can add QOM properties for this
1011 * later if necessary.
1013 if (extract32(info
->cpuwait_rst
, i
, 1)) {
1014 if (!object_property_set_bool(cpuobj
, "start-powered-off", true,
1019 if (!s
->cpu_fpu
[i
]) {
1020 if (!object_property_set_bool(cpuobj
, "vfp", false, errp
)) {
1024 if (!s
->cpu_dsp
[i
]) {
1025 if (!object_property_set_bool(cpuobj
, "dsp", false, errp
)) {
1031 memory_region_add_subregion_overlap(&s
->cpu_container
[i
], 0,
1032 &s
->container_alias
[i
- 1], -1);
1034 memory_region_add_subregion_overlap(&s
->cpu_container
[i
], 0,
1037 object_property_set_link(cpuobj
, "memory",
1038 OBJECT(&s
->cpu_container
[i
]), &error_abort
);
1039 object_property_set_link(cpuobj
, "idau", OBJECT(s
), &error_abort
);
1040 if (!sysbus_realize(SYS_BUS_DEVICE(cpuobj
), errp
)) {
1044 * The cluster must be realized after the armv7m container, as
1045 * the container's CPU object is only created on realize, and the
1046 * CPU must exist and have been parented into the cluster before
1047 * the cluster is realized.
1049 if (!qdev_realize(DEVICE(&s
->cluster
[i
]), NULL
, errp
)) {
1053 /* Connect EXP_IRQ/EXP_CPUn_IRQ GPIOs to the NVIC's lines 32 and up */
1054 s
->exp_irqs
[i
] = g_new(qemu_irq
, s
->exp_numirq
);
1055 for (j
= 0; j
< s
->exp_numirq
; j
++) {
1056 s
->exp_irqs
[i
][j
] = qdev_get_gpio_in(cpudev
, j
+ NUM_SSE_IRQS
);
1059 gpioname
= g_strdup("EXP_IRQ");
1061 gpioname
= g_strdup_printf("EXP_CPU%d_IRQ", i
);
1063 qdev_init_gpio_in_named_with_opaque(dev
, armsse_exp_irq
,
1065 gpioname
, s
->exp_numirq
);
1069 /* Wire up the splitters that connect common IRQs to all CPUs */
1070 if (info
->num_cpus
> 1) {
1071 for (i
= 0; i
< ARRAY_SIZE(s
->cpu_irq_splitter
); i
++) {
1072 if (info
->irq_is_common
[i
]) {
1073 Object
*splitter
= OBJECT(&s
->cpu_irq_splitter
[i
]);
1074 DeviceState
*devs
= DEVICE(splitter
);
1077 if (!object_property_set_int(splitter
, "num-lines",
1078 info
->num_cpus
, errp
)) {
1081 if (!qdev_realize(DEVICE(splitter
), NULL
, errp
)) {
1084 for (cpunum
= 0; cpunum
< info
->num_cpus
; cpunum
++) {
1085 DeviceState
*cpudev
= DEVICE(&s
->armv7m
[cpunum
]);
1087 qdev_connect_gpio_out(devs
, cpunum
,
1088 qdev_get_gpio_in(cpudev
, i
));
1094 /* Set up the big aliases first */
1095 make_alias(s
, &s
->alias1
, &s
->container
, "alias 1",
1096 0x10000000, 0x10000000, 0x00000000);
1097 make_alias(s
, &s
->alias2
, &s
->container
,
1098 "alias 2", 0x30000000, 0x10000000, 0x20000000);
1099 /* The 0x50000000..0x5fffffff region is not a pure alias: it has
1100 * a few extra devices that only appear there (generally the
1101 * control interfaces for the protection controllers).
1102 * We implement this by mapping those devices over the top of this
1103 * alias MR at a higher priority. Some of the devices in this range
1104 * are per-CPU, so we must put this alias in the per-cpu containers.
1106 for (i
= 0; i
< info
->num_cpus
; i
++) {
1107 make_alias(s
, &s
->alias3
[i
], &s
->cpu_container
[i
],
1108 "alias 3", 0x50000000, 0x10000000, 0x40000000);
1111 /* Security controller */
1112 object_property_set_int(OBJECT(&s
->secctl
), "sse-version",
1113 info
->sse_version
, &error_abort
);
1114 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->secctl
), errp
)) {
1117 sbd_secctl
= SYS_BUS_DEVICE(&s
->secctl
);
1118 dev_secctl
= DEVICE(&s
->secctl
);
1119 sysbus_mmio_map(sbd_secctl
, 0, 0x50080000);
1120 sysbus_mmio_map(sbd_secctl
, 1, 0x40080000);
1122 s
->nsc_cfg_in
= qemu_allocate_irq(nsccfg_handler
, s
, 1);
1123 qdev_connect_gpio_out_named(dev_secctl
, "nsc_cfg", 0, s
->nsc_cfg_in
);
1125 /* The sec_resp_cfg output from the security controller must be split into
1126 * multiple lines, one for each of the PPCs within the ARMSSE and one
1127 * that will be an output from the ARMSSE to the system.
1129 if (!object_property_set_int(OBJECT(&s
->sec_resp_splitter
),
1130 "num-lines", 3, errp
)) {
1133 if (!qdev_realize(DEVICE(&s
->sec_resp_splitter
), NULL
, errp
)) {
1136 dev_splitter
= DEVICE(&s
->sec_resp_splitter
);
1137 qdev_connect_gpio_out_named(dev_secctl
, "sec_resp_cfg", 0,
1138 qdev_get_gpio_in(dev_splitter
, 0));
1140 /* Each SRAM bank lives behind its own Memory Protection Controller */
1141 for (i
= 0; i
< info
->sram_banks
; i
++) {
1142 char *ramname
= g_strdup_printf("armsse.sram%d", i
);
1143 SysBusDevice
*sbd_mpc
;
1144 uint32_t sram_bank_size
= 1 << s
->sram_addr_width
;
1146 memory_region_init_ram(&s
->sram
[i
], NULL
, ramname
,
1147 sram_bank_size
, &err
);
1150 error_propagate(errp
, err
);
1153 object_property_set_link(OBJECT(&s
->mpc
[i
]), "downstream",
1154 OBJECT(&s
->sram
[i
]), &error_abort
);
1155 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->mpc
[i
]), errp
)) {
1158 /* Map the upstream end of the MPC into the right place... */
1159 sbd_mpc
= SYS_BUS_DEVICE(&s
->mpc
[i
]);
1160 memory_region_add_subregion(&s
->container
,
1161 0x20000000 + i
* sram_bank_size
,
1162 sysbus_mmio_get_region(sbd_mpc
, 1));
1163 /* ...and its register interface */
1164 memory_region_add_subregion(&s
->container
, 0x50083000 + i
* 0x1000,
1165 sysbus_mmio_get_region(sbd_mpc
, 0));
1168 /* We must OR together lines from the MPC splitters to go to the NVIC */
1169 if (!object_property_set_int(OBJECT(&s
->mpc_irq_orgate
), "num-lines",
1170 IOTS_NUM_EXP_MPC
+ info
->sram_banks
,
1174 if (!qdev_realize(DEVICE(&s
->mpc_irq_orgate
), NULL
, errp
)) {
1177 qdev_connect_gpio_out(DEVICE(&s
->mpc_irq_orgate
), 0,
1178 armsse_get_common_irq_in(s
, 9));
1180 /* This OR gate wires together outputs from the secure watchdogs to NMI */
1181 if (!object_property_set_int(OBJECT(&s
->nmi_orgate
), "num-lines", 2,
1185 if (!qdev_realize(DEVICE(&s
->nmi_orgate
), NULL
, errp
)) {
1188 qdev_connect_gpio_out(DEVICE(&s
->nmi_orgate
), 0,
1189 qdev_get_gpio_in_named(DEVICE(&s
->armv7m
), "NMI", 0));
1191 /* The SSE-300 has a System Counter / System Timestamp Generator */
1192 if (info
->has_sse_counter
) {
1193 SysBusDevice
*sbd
= SYS_BUS_DEVICE(&s
->sse_counter
);
1195 qdev_connect_clock_in(DEVICE(sbd
), "CLK", s
->mainclk
);
1196 if (!sysbus_realize(sbd
, errp
)) {
1200 * The control frame is only in the Secure region;
1201 * the status frame is in the NS region (and visible in the
1202 * S region via the alias mapping).
1204 memory_region_add_subregion(&s
->container
, 0x58100000,
1205 sysbus_mmio_get_region(sbd
, 0));
1206 memory_region_add_subregion(&s
->container
, 0x48101000,
1207 sysbus_mmio_get_region(sbd
, 1));
1210 /* Devices behind APB PPC0:
1211 * 0x40000000: timer0
1212 * 0x40001000: timer1
1213 * 0x40002000: dual timer
1214 * 0x40003000: MHU0 (SSE-200 only)
1215 * 0x40004000: MHU1 (SSE-200 only)
1216 * We must configure and realize each downstream device and connect
1217 * it to the appropriate PPC port; then we can realize the PPC and
1218 * map its upstream ends to the right place in the container.
1220 for (devinfo
= info
->devinfo
; devinfo
->name
; devinfo
++) {
1224 if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_TIMER
)) {
1225 sbd
= SYS_BUS_DEVICE(&s
->timer
[devinfo
->index
]);
1227 qdev_connect_clock_in(DEVICE(sbd
), "pclk",
1228 devinfo
->slowclk
? s
->s32kclk
: s
->mainclk
);
1229 if (!sysbus_realize(sbd
, errp
)) {
1232 mr
= sysbus_mmio_get_region(sbd
, 0);
1233 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_DUALTIMER
)) {
1234 sbd
= SYS_BUS_DEVICE(&s
->dualtimer
);
1236 qdev_connect_clock_in(DEVICE(sbd
), "TIMCLK", s
->mainclk
);
1237 if (!sysbus_realize(sbd
, errp
)) {
1240 mr
= sysbus_mmio_get_region(sbd
, 0);
1241 } else if (!strcmp(devinfo
->type
, TYPE_SSE_TIMER
)) {
1242 sbd
= SYS_BUS_DEVICE(&s
->sse_timer
[devinfo
->index
]);
1244 assert(info
->has_sse_counter
);
1245 object_property_set_link(OBJECT(sbd
), "counter",
1246 OBJECT(&s
->sse_counter
), &error_abort
);
1247 if (!sysbus_realize(sbd
, errp
)) {
1250 mr
= sysbus_mmio_get_region(sbd
, 0);
1251 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_WATCHDOG
)) {
1252 sbd
= SYS_BUS_DEVICE(&s
->cmsdk_watchdog
[devinfo
->index
]);
1254 qdev_connect_clock_in(DEVICE(sbd
), "WDOGCLK",
1255 devinfo
->slowclk
? s
->s32kclk
: s
->mainclk
);
1256 if (!sysbus_realize(sbd
, errp
)) {
1259 mr
= sysbus_mmio_get_region(sbd
, 0);
1260 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSINFO
)) {
1261 sbd
= SYS_BUS_DEVICE(&s
->sysinfo
);
1263 object_property_set_int(OBJECT(&s
->sysinfo
), "SYS_VERSION",
1264 info
->sys_version
, &error_abort
);
1265 object_property_set_int(OBJECT(&s
->sysinfo
), "SYS_CONFIG",
1266 armsse_sys_config_value(s
, info
),
1268 object_property_set_int(OBJECT(&s
->sysinfo
), "sse-version",
1269 info
->sse_version
, &error_abort
);
1270 object_property_set_int(OBJECT(&s
->sysinfo
), "IIDR",
1271 info
->iidr
, &error_abort
);
1272 if (!sysbus_realize(sbd
, errp
)) {
1275 mr
= sysbus_mmio_get_region(sbd
, 0);
1276 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSCTL
)) {
1277 /* System control registers */
1278 sbd
= SYS_BUS_DEVICE(&s
->sysctl
);
1280 object_property_set_int(OBJECT(&s
->sysctl
), "sse-version",
1281 info
->sse_version
, &error_abort
);
1282 object_property_set_int(OBJECT(&s
->sysctl
), "CPUWAIT_RST",
1283 info
->cpuwait_rst
, &error_abort
);
1284 object_property_set_int(OBJECT(&s
->sysctl
), "INITSVTOR0_RST",
1285 s
->init_svtor
, &error_abort
);
1286 object_property_set_int(OBJECT(&s
->sysctl
), "INITSVTOR1_RST",
1287 s
->init_svtor
, &error_abort
);
1288 if (!sysbus_realize(sbd
, errp
)) {
1291 mr
= sysbus_mmio_get_region(sbd
, 0);
1292 } else if (!strcmp(devinfo
->type
, TYPE_UNIMPLEMENTED_DEVICE
)) {
1293 sbd
= SYS_BUS_DEVICE(&s
->unimp
[devinfo
->index
]);
1295 qdev_prop_set_string(DEVICE(sbd
), "name", devinfo
->name
);
1296 qdev_prop_set_uint64(DEVICE(sbd
), "size", devinfo
->size
);
1297 if (!sysbus_realize(sbd
, errp
)) {
1300 mr
= sysbus_mmio_get_region(sbd
, 0);
1302 g_assert_not_reached();
1305 switch (devinfo
->irq
) {
1309 case 0 ... NUM_SSE_IRQS
- 1:
1310 irq
= armsse_get_common_irq_in(s
, devinfo
->irq
);
1314 irq
= qdev_get_gpio_in(DEVICE(&s
->nmi_orgate
),
1315 devinfo
->irq
- NMI_0
);
1318 g_assert_not_reached();
1322 sysbus_connect_irq(sbd
, 0, irq
);
1326 * Devices connected to a PPC are connected to the port here;
1327 * we will map the upstream end of that port to the right address
1328 * in the container later after the PPC has been realized.
1329 * Devices not connected to a PPC can be mapped immediately.
1331 if (devinfo
->ppc
!= NO_PPC
) {
1332 TZPPC
*ppc
= &s
->apb_ppc
[devinfo
->ppc
];
1333 g_autofree
char *portname
= g_strdup_printf("port[%d]",
1335 object_property_set_link(OBJECT(ppc
), portname
, OBJECT(mr
),
1338 memory_region_add_subregion(&s
->container
, devinfo
->addr
, mr
);
1342 if (info
->has_mhus
) {
1344 * An SSE-200 with only one CPU should have only one MHU created,
1345 * with the region where the second MHU usually is being RAZ/WI.
1346 * We don't implement that SSE-200 config; if we want to support
1347 * it then this code needs to be enhanced to handle creating the
1348 * RAZ/WI region instead of the second MHU.
1350 assert(info
->num_cpus
== ARRAY_SIZE(s
->mhu
));
1352 for (i
= 0; i
< ARRAY_SIZE(s
->mhu
); i
++) {
1355 SysBusDevice
*mhu_sbd
= SYS_BUS_DEVICE(&s
->mhu
[i
]);
1357 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->mhu
[i
]), errp
)) {
1360 port
= g_strdup_printf("port[%d]", i
+ 3);
1361 mr
= sysbus_mmio_get_region(mhu_sbd
, 0);
1362 object_property_set_link(OBJECT(&s
->apb_ppc
[0]), port
, OBJECT(mr
),
1367 * Each MHU has an irq line for each CPU:
1368 * MHU 0 irq line 0 -> CPU 0 IRQ 6
1369 * MHU 0 irq line 1 -> CPU 1 IRQ 6
1370 * MHU 1 irq line 0 -> CPU 0 IRQ 7
1371 * MHU 1 irq line 1 -> CPU 1 IRQ 7
1373 for (cpunum
= 0; cpunum
< info
->num_cpus
; cpunum
++) {
1374 DeviceState
*cpudev
= DEVICE(&s
->armv7m
[cpunum
]);
1376 sysbus_connect_irq(mhu_sbd
, cpunum
,
1377 qdev_get_gpio_in(cpudev
, 6 + i
));
1382 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->apb_ppc
[0]), errp
)) {
1386 sbd_apb_ppc0
= SYS_BUS_DEVICE(&s
->apb_ppc
[0]);
1387 dev_apb_ppc0
= DEVICE(&s
->apb_ppc
[0]);
1389 if (info
->has_mhus
) {
1390 mr
= sysbus_mmio_get_region(sbd_apb_ppc0
, 3);
1391 memory_region_add_subregion(&s
->container
, 0x40003000, mr
);
1392 mr
= sysbus_mmio_get_region(sbd_apb_ppc0
, 4);
1393 memory_region_add_subregion(&s
->container
, 0x40004000, mr
);
1395 for (i
= 0; i
< IOTS_APB_PPC0_NUM_PORTS
; i
++) {
1396 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_nonsec", i
,
1397 qdev_get_gpio_in_named(dev_apb_ppc0
,
1399 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_ap", i
,
1400 qdev_get_gpio_in_named(dev_apb_ppc0
,
1403 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_irq_enable", 0,
1404 qdev_get_gpio_in_named(dev_apb_ppc0
,
1406 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_irq_clear", 0,
1407 qdev_get_gpio_in_named(dev_apb_ppc0
,
1409 qdev_connect_gpio_out(dev_splitter
, 0,
1410 qdev_get_gpio_in_named(dev_apb_ppc0
,
1411 "cfg_sec_resp", 0));
1413 /* All the PPC irq lines (from the 2 internal PPCs and the 8 external
1414 * ones) are sent individually to the security controller, and also
1415 * ORed together to give a single combined PPC interrupt to the NVIC.
1417 if (!object_property_set_int(OBJECT(&s
->ppc_irq_orgate
),
1418 "num-lines", NUM_PPCS
, errp
)) {
1421 if (!qdev_realize(DEVICE(&s
->ppc_irq_orgate
), NULL
, errp
)) {
1424 qdev_connect_gpio_out(DEVICE(&s
->ppc_irq_orgate
), 0,
1425 armsse_get_common_irq_in(s
, 10));
1428 * 0x40010000 .. 0x4001ffff (and the 0x5001000... secure-only alias):
1429 * private per-CPU region (all these devices are SSE-200 only):
1430 * 0x50010000: L1 icache control registers
1431 * 0x50011000: CPUSECCTRL (CPU local security control registers)
1432 * 0x4001f000 and 0x5001f000: CPU_IDENTITY register block
1433 * The SSE-300 has an extra:
1434 * 0x40012000 and 0x50012000: CPU_PWRCTRL register block
1436 if (info
->has_cachectrl
) {
1437 for (i
= 0; i
< info
->num_cpus
; i
++) {
1438 char *name
= g_strdup_printf("cachectrl%d", i
);
1441 qdev_prop_set_string(DEVICE(&s
->cachectrl
[i
]), "name", name
);
1443 qdev_prop_set_uint64(DEVICE(&s
->cachectrl
[i
]), "size", 0x1000);
1444 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cachectrl
[i
]), errp
)) {
1448 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cachectrl
[i
]), 0);
1449 memory_region_add_subregion(&s
->cpu_container
[i
], 0x50010000, mr
);
1452 if (info
->has_cpusecctrl
) {
1453 for (i
= 0; i
< info
->num_cpus
; i
++) {
1454 char *name
= g_strdup_printf("CPUSECCTRL%d", i
);
1457 qdev_prop_set_string(DEVICE(&s
->cpusecctrl
[i
]), "name", name
);
1459 qdev_prop_set_uint64(DEVICE(&s
->cpusecctrl
[i
]), "size", 0x1000);
1460 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cpusecctrl
[i
]), errp
)) {
1464 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cpusecctrl
[i
]), 0);
1465 memory_region_add_subregion(&s
->cpu_container
[i
], 0x50011000, mr
);
1468 if (info
->has_cpuid
) {
1469 for (i
= 0; i
< info
->num_cpus
; i
++) {
1472 qdev_prop_set_uint32(DEVICE(&s
->cpuid
[i
]), "CPUID", i
);
1473 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cpuid
[i
]), errp
)) {
1477 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cpuid
[i
]), 0);
1478 memory_region_add_subregion(&s
->cpu_container
[i
], 0x4001F000, mr
);
1481 if (info
->has_cpu_pwrctrl
) {
1482 for (i
= 0; i
< info
->num_cpus
; i
++) {
1485 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cpu_pwrctrl
[i
]), errp
)) {
1489 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cpu_pwrctrl
[i
]), 0);
1490 memory_region_add_subregion(&s
->cpu_container
[i
], 0x40012000, mr
);
1494 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->apb_ppc
[1]), errp
)) {
1498 dev_apb_ppc1
= DEVICE(&s
->apb_ppc
[1]);
1499 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_nonsec", 0,
1500 qdev_get_gpio_in_named(dev_apb_ppc1
,
1502 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_ap", 0,
1503 qdev_get_gpio_in_named(dev_apb_ppc1
,
1505 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_irq_enable", 0,
1506 qdev_get_gpio_in_named(dev_apb_ppc1
,
1508 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_irq_clear", 0,
1509 qdev_get_gpio_in_named(dev_apb_ppc1
,
1511 qdev_connect_gpio_out(dev_splitter
, 1,
1512 qdev_get_gpio_in_named(dev_apb_ppc1
,
1513 "cfg_sec_resp", 0));
1516 * Now both PPCs are realized we can map the upstream ends of
1517 * ports which correspond to entries in the devinfo array.
1518 * The ports which are connected to non-devinfo devices have
1519 * already been mapped.
1521 for (devinfo
= info
->devinfo
; devinfo
->name
; devinfo
++) {
1522 SysBusDevice
*ppc_sbd
;
1524 if (devinfo
->ppc
== NO_PPC
) {
1527 ppc_sbd
= SYS_BUS_DEVICE(&s
->apb_ppc
[devinfo
->ppc
]);
1528 mr
= sysbus_mmio_get_region(ppc_sbd
, devinfo
->ppc_port
);
1529 memory_region_add_subregion(&s
->container
, devinfo
->addr
, mr
);
1532 for (i
= 0; i
< ARRAY_SIZE(s
->ppc_irq_splitter
); i
++) {
1533 Object
*splitter
= OBJECT(&s
->ppc_irq_splitter
[i
]);
1535 if (!object_property_set_int(splitter
, "num-lines", 2, errp
)) {
1538 if (!qdev_realize(DEVICE(splitter
), NULL
, errp
)) {
1543 for (i
= 0; i
< IOTS_NUM_AHB_EXP_PPC
; i
++) {
1544 char *ppcname
= g_strdup_printf("ahb_ppcexp%d", i
);
1546 armsse_forward_ppc(s
, ppcname
, i
);
1550 for (i
= 0; i
< IOTS_NUM_APB_EXP_PPC
; i
++) {
1551 char *ppcname
= g_strdup_printf("apb_ppcexp%d", i
);
1553 armsse_forward_ppc(s
, ppcname
, i
+ IOTS_NUM_AHB_EXP_PPC
);
1557 for (i
= NUM_EXTERNAL_PPCS
; i
< NUM_PPCS
; i
++) {
1558 /* Wire up IRQ splitter for internal PPCs */
1559 DeviceState
*devs
= DEVICE(&s
->ppc_irq_splitter
[i
]);
1560 char *gpioname
= g_strdup_printf("apb_ppc%d_irq_status",
1561 i
- NUM_EXTERNAL_PPCS
);
1562 TZPPC
*ppc
= &s
->apb_ppc
[i
- NUM_EXTERNAL_PPCS
];
1564 qdev_connect_gpio_out(devs
, 0,
1565 qdev_get_gpio_in_named(dev_secctl
, gpioname
, 0));
1566 qdev_connect_gpio_out(devs
, 1,
1567 qdev_get_gpio_in(DEVICE(&s
->ppc_irq_orgate
), i
));
1568 qdev_connect_gpio_out_named(DEVICE(ppc
), "irq", 0,
1569 qdev_get_gpio_in(devs
, 0));
1573 /* Wire up the splitters for the MPC IRQs */
1574 for (i
= 0; i
< IOTS_NUM_EXP_MPC
+ info
->sram_banks
; i
++) {
1575 SplitIRQ
*splitter
= &s
->mpc_irq_splitter
[i
];
1576 DeviceState
*dev_splitter
= DEVICE(splitter
);
1578 if (!object_property_set_int(OBJECT(splitter
), "num-lines", 2,
1582 if (!qdev_realize(DEVICE(splitter
), NULL
, errp
)) {
1586 if (i
< IOTS_NUM_EXP_MPC
) {
1587 /* Splitter input is from GPIO input line */
1588 s
->mpcexp_status_in
[i
] = qdev_get_gpio_in(dev_splitter
, 0);
1589 qdev_connect_gpio_out(dev_splitter
, 0,
1590 qdev_get_gpio_in_named(dev_secctl
,
1591 "mpcexp_status", i
));
1593 /* Splitter input is from our own MPC */
1594 qdev_connect_gpio_out_named(DEVICE(&s
->mpc
[i
- IOTS_NUM_EXP_MPC
]),
1596 qdev_get_gpio_in(dev_splitter
, 0));
1597 qdev_connect_gpio_out(dev_splitter
, 0,
1598 qdev_get_gpio_in_named(dev_secctl
,
1600 i
- IOTS_NUM_EXP_MPC
));
1603 qdev_connect_gpio_out(dev_splitter
, 1,
1604 qdev_get_gpio_in(DEVICE(&s
->mpc_irq_orgate
), i
));
1606 /* Create GPIO inputs which will pass the line state for our
1607 * mpcexp_irq inputs to the correct splitter devices.
1609 qdev_init_gpio_in_named(dev
, armsse_mpcexp_status
, "mpcexp_status",
1612 armsse_forward_sec_resp_cfg(s
);
1614 /* Forward the MSC related signals */
1615 qdev_pass_gpios(dev_secctl
, dev
, "mscexp_status");
1616 qdev_pass_gpios(dev_secctl
, dev
, "mscexp_clear");
1617 qdev_pass_gpios(dev_secctl
, dev
, "mscexp_ns");
1618 qdev_connect_gpio_out_named(dev_secctl
, "msc_irq", 0,
1619 armsse_get_common_irq_in(s
, 11));
1622 * Expose our container region to the board model; this corresponds
1623 * to the AHB Slave Expansion ports which allow bus master devices
1624 * (eg DMA controllers) in the board model to make transactions into
1625 * devices in the ARMSSE.
1627 sysbus_init_mmio(SYS_BUS_DEVICE(s
), &s
->container
);
1629 /* Set initial system_clock_scale from MAINCLK */
1630 armsse_mainclk_update(s
, ClockUpdate
);
1633 static void armsse_idau_check(IDAUInterface
*ii
, uint32_t address
,
1634 int *iregion
, bool *exempt
, bool *ns
, bool *nsc
)
1637 * For ARMSSE systems the IDAU responses are simple logical functions
1638 * of the address bits. The NSC attribute is guest-adjustable via the
1639 * NSCCFG register in the security controller.
1641 ARMSSE
*s
= ARM_SSE(ii
);
1642 int region
= extract32(address
, 28, 4);
1644 *ns
= !(region
& 1);
1645 *nsc
= (region
== 1 && (s
->nsccfg
& 1)) || (region
== 3 && (s
->nsccfg
& 2));
1646 /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */
1647 *exempt
= (address
& 0xeff00000) == 0xe0000000;
1651 static const VMStateDescription armsse_vmstate
= {
1654 .minimum_version_id
= 2,
1655 .fields
= (VMStateField
[]) {
1656 VMSTATE_CLOCK(mainclk
, ARMSSE
),
1657 VMSTATE_CLOCK(s32kclk
, ARMSSE
),
1658 VMSTATE_UINT32(nsccfg
, ARMSSE
),
1659 VMSTATE_END_OF_LIST()
1663 static void armsse_reset(DeviceState
*dev
)
1665 ARMSSE
*s
= ARM_SSE(dev
);
1670 static void armsse_class_init(ObjectClass
*klass
, void *data
)
1672 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1673 IDAUInterfaceClass
*iic
= IDAU_INTERFACE_CLASS(klass
);
1674 ARMSSEClass
*asc
= ARM_SSE_CLASS(klass
);
1675 const ARMSSEInfo
*info
= data
;
1677 dc
->realize
= armsse_realize
;
1678 dc
->vmsd
= &armsse_vmstate
;
1679 device_class_set_props(dc
, info
->props
);
1680 dc
->reset
= armsse_reset
;
1681 iic
->check
= armsse_idau_check
;
1685 static const TypeInfo armsse_info
= {
1686 .name
= TYPE_ARM_SSE
,
1687 .parent
= TYPE_SYS_BUS_DEVICE
,
1688 .instance_size
= sizeof(ARMSSE
),
1689 .class_size
= sizeof(ARMSSEClass
),
1690 .instance_init
= armsse_init
,
1692 .interfaces
= (InterfaceInfo
[]) {
1693 { TYPE_IDAU_INTERFACE
},
1698 static void armsse_register_types(void)
1702 type_register_static(&armsse_info
);
1704 for (i
= 0; i
< ARRAY_SIZE(armsse_variants
); i
++) {
1706 .name
= armsse_variants
[i
].name
,
1707 .parent
= TYPE_ARM_SSE
,
1708 .class_init
= armsse_class_init
,
1709 .class_data
= (void *)&armsse_variants
[i
],
1715 type_init(armsse_register_types
);