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 static const ARMSSEDeviceInfo sse300_devices
[] = {
343 .type
= TYPE_SSE_TIMER
,
352 .type
= TYPE_SSE_TIMER
,
361 .type
= TYPE_SSE_TIMER
,
370 .type
= TYPE_SSE_TIMER
,
379 .type
= TYPE_CMSDK_APB_TIMER
,
388 .name
= "s32kwatchdog",
389 .type
= TYPE_CMSDK_APB_WATCHDOG
,
398 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
406 .name
= "armsse-sysinfo",
407 .type
= TYPE_IOTKIT_SYSINFO
,
414 .name
= "armsse-sysctl",
415 .type
= TYPE_IOTKIT_SYSCTL
,
423 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
431 .name
= "CPU0CORE_PPU",
432 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
441 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
450 .type
= TYPE_UNIMPLEMENTED_DEVICE
,
462 /* Is internal IRQ n shared between CPUs in a multi-core SSE ? */
463 static const bool sse200_irq_is_common
[32] = {
465 /* 6, 7: per-CPU MHU interrupts */
467 /* 13: per-CPU icache interrupt */
473 /* 28, 29: per-CPU CTI interrupts */
474 /* 30, 31: reserved */
477 static const bool sse300_irq_is_common
[32] = {
479 /* 6, 7: per-CPU MHU interrupts */
483 /* 17-25: reserved */
485 /* 28, 29: per-CPU CTI interrupts */
486 /* 30, 31: reserved */
489 static const ARMSSEInfo armsse_variants
[] = {
492 .sse_version
= ARMSSE_IOTKIT
,
495 .sys_version
= 0x41743,
499 .has_cachectrl
= false,
500 .has_cpusecctrl
= false,
502 .has_cpu_pwrctrl
= false,
503 .has_sse_counter
= false,
504 .props
= iotkit_properties
,
505 .devinfo
= iotkit_devices
,
506 .irq_is_common
= sse200_irq_is_common
,
510 .sse_version
= ARMSSE_SSE200
,
513 .sys_version
= 0x22041743,
517 .has_cachectrl
= true,
518 .has_cpusecctrl
= true,
520 .has_cpu_pwrctrl
= false,
521 .has_sse_counter
= false,
522 .props
= armsse_properties
,
523 .devinfo
= sse200_devices
,
524 .irq_is_common
= sse200_irq_is_common
,
528 .sse_version
= ARMSSE_SSE300
,
531 .sys_version
= 0x7e00043b,
535 .has_cachectrl
= false,
536 .has_cpusecctrl
= true,
538 .has_cpu_pwrctrl
= true,
539 .has_sse_counter
= true,
540 .props
= armsse_properties
,
541 .devinfo
= sse300_devices
,
542 .irq_is_common
= sse300_irq_is_common
,
546 static uint32_t armsse_sys_config_value(ARMSSE
*s
, const ARMSSEInfo
*info
)
548 /* Return the SYS_CONFIG value for this SSE */
551 switch (info
->sse_version
) {
554 sys_config
= deposit32(sys_config
, 0, 4, info
->sram_banks
);
555 sys_config
= deposit32(sys_config
, 4, 4, s
->sram_addr_width
- 12);
559 sys_config
= deposit32(sys_config
, 0, 4, info
->sram_banks
);
560 sys_config
= deposit32(sys_config
, 4, 5, s
->sram_addr_width
);
561 sys_config
= deposit32(sys_config
, 24, 4, 2);
562 if (info
->num_cpus
> 1) {
563 sys_config
= deposit32(sys_config
, 10, 1, 1);
564 sys_config
= deposit32(sys_config
, 20, 4, info
->sram_banks
- 1);
565 sys_config
= deposit32(sys_config
, 28, 4, 2);
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
, 16, 3, 3); /* CPU0 = Cortex-M55 */
575 g_assert_not_reached();
580 /* Clock frequency in HZ of the 32KHz "slow clock" */
581 #define S32KCLK (32 * 1000)
584 * Create an alias region in @container of @size bytes starting at @base
585 * which mirrors the memory starting at @orig.
587 static void make_alias(ARMSSE
*s
, MemoryRegion
*mr
, MemoryRegion
*container
,
588 const char *name
, hwaddr base
, hwaddr size
, hwaddr orig
)
590 memory_region_init_alias(mr
, NULL
, name
, container
, orig
, size
);
591 /* The alias is even lower priority than unimplemented_device regions */
592 memory_region_add_subregion_overlap(container
, base
, mr
, -1500);
595 static void irq_status_forwarder(void *opaque
, int n
, int level
)
597 qemu_irq destirq
= opaque
;
599 qemu_set_irq(destirq
, level
);
602 static void nsccfg_handler(void *opaque
, int n
, int level
)
604 ARMSSE
*s
= ARM_SSE(opaque
);
609 static void armsse_forward_ppc(ARMSSE
*s
, const char *ppcname
, int ppcnum
)
611 /* Each of the 4 AHB and 4 APB PPCs that might be present in a
612 * system using the ARMSSE has a collection of control lines which
613 * are provided by the security controller and which we want to
614 * expose as control lines on the ARMSSE device itself, so the
615 * code using the ARMSSE can wire them up to the PPCs.
617 SplitIRQ
*splitter
= &s
->ppc_irq_splitter
[ppcnum
];
618 DeviceState
*armssedev
= DEVICE(s
);
619 DeviceState
*dev_secctl
= DEVICE(&s
->secctl
);
620 DeviceState
*dev_splitter
= DEVICE(splitter
);
623 name
= g_strdup_printf("%s_nonsec", ppcname
);
624 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
626 name
= g_strdup_printf("%s_ap", ppcname
);
627 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
629 name
= g_strdup_printf("%s_irq_enable", ppcname
);
630 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
632 name
= g_strdup_printf("%s_irq_clear", ppcname
);
633 qdev_pass_gpios(dev_secctl
, armssedev
, name
);
636 /* irq_status is a little more tricky, because we need to
637 * split it so we can send it both to the security controller
638 * and to our OR gate for the NVIC interrupt line.
639 * Connect up the splitter's outputs, and create a GPIO input
640 * which will pass the line state to the input splitter.
642 name
= g_strdup_printf("%s_irq_status", ppcname
);
643 qdev_connect_gpio_out(dev_splitter
, 0,
644 qdev_get_gpio_in_named(dev_secctl
,
646 qdev_connect_gpio_out(dev_splitter
, 1,
647 qdev_get_gpio_in(DEVICE(&s
->ppc_irq_orgate
), ppcnum
));
648 s
->irq_status_in
[ppcnum
] = qdev_get_gpio_in(dev_splitter
, 0);
649 qdev_init_gpio_in_named_with_opaque(armssedev
, irq_status_forwarder
,
650 s
->irq_status_in
[ppcnum
], name
, 1);
654 static void armsse_forward_sec_resp_cfg(ARMSSE
*s
)
656 /* Forward the 3rd output from the splitter device as a
657 * named GPIO output of the armsse object.
659 DeviceState
*dev
= DEVICE(s
);
660 DeviceState
*dev_splitter
= DEVICE(&s
->sec_resp_splitter
);
662 qdev_init_gpio_out_named(dev
, &s
->sec_resp_cfg
, "sec_resp_cfg", 1);
663 s
->sec_resp_cfg_in
= qemu_allocate_irq(irq_status_forwarder
,
665 qdev_connect_gpio_out(dev_splitter
, 2, s
->sec_resp_cfg_in
);
668 static void armsse_mainclk_update(void *opaque
, ClockEvent event
)
670 ARMSSE
*s
= ARM_SSE(opaque
);
673 * Set system_clock_scale from our Clock input; this is what
674 * controls the tick rate of the CPU SysTick timer.
676 system_clock_scale
= clock_ticks_to_ns(s
->mainclk
, 1);
679 static void armsse_init(Object
*obj
)
681 ARMSSE
*s
= ARM_SSE(obj
);
682 ARMSSEClass
*asc
= ARM_SSE_GET_CLASS(obj
);
683 const ARMSSEInfo
*info
= asc
->info
;
684 const ARMSSEDeviceInfo
*devinfo
;
687 assert(info
->sram_banks
<= MAX_SRAM_BANKS
);
688 assert(info
->num_cpus
<= SSE_MAX_CPUS
);
690 s
->mainclk
= qdev_init_clock_in(DEVICE(s
), "MAINCLK",
691 armsse_mainclk_update
, s
, ClockUpdate
);
692 s
->s32kclk
= qdev_init_clock_in(DEVICE(s
), "S32KCLK", NULL
, NULL
, 0);
694 memory_region_init(&s
->container
, obj
, "armsse-container", UINT64_MAX
);
696 for (i
= 0; i
< info
->num_cpus
; i
++) {
698 * We put each CPU in its own cluster as they are logically
699 * distinct and may be configured differently.
703 name
= g_strdup_printf("cluster%d", i
);
704 object_initialize_child(obj
, name
, &s
->cluster
[i
], TYPE_CPU_CLUSTER
);
705 qdev_prop_set_uint32(DEVICE(&s
->cluster
[i
]), "cluster-id", i
);
708 name
= g_strdup_printf("armv7m%d", i
);
709 object_initialize_child(OBJECT(&s
->cluster
[i
]), name
, &s
->armv7m
[i
],
711 qdev_prop_set_string(DEVICE(&s
->armv7m
[i
]), "cpu-type",
712 ARM_CPU_TYPE_NAME("cortex-m33"));
714 name
= g_strdup_printf("arm-sse-cpu-container%d", i
);
715 memory_region_init(&s
->cpu_container
[i
], obj
, name
, UINT64_MAX
);
718 name
= g_strdup_printf("arm-sse-container-alias%d", i
);
719 memory_region_init_alias(&s
->container_alias
[i
- 1], obj
,
720 name
, &s
->container
, 0, UINT64_MAX
);
725 for (devinfo
= info
->devinfo
; devinfo
->name
; devinfo
++) {
726 assert(devinfo
->ppc
== NO_PPC
|| devinfo
->ppc
< ARRAY_SIZE(s
->apb_ppc
));
727 if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_TIMER
)) {
728 assert(devinfo
->index
< ARRAY_SIZE(s
->timer
));
729 object_initialize_child(obj
, devinfo
->name
,
730 &s
->timer
[devinfo
->index
],
731 TYPE_CMSDK_APB_TIMER
);
732 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_DUALTIMER
)) {
733 assert(devinfo
->index
== 0);
734 object_initialize_child(obj
, devinfo
->name
, &s
->dualtimer
,
735 TYPE_CMSDK_APB_DUALTIMER
);
736 } else if (!strcmp(devinfo
->type
, TYPE_SSE_TIMER
)) {
737 assert(devinfo
->index
< ARRAY_SIZE(s
->sse_timer
));
738 object_initialize_child(obj
, devinfo
->name
,
739 &s
->sse_timer
[devinfo
->index
],
741 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_WATCHDOG
)) {
742 assert(devinfo
->index
< ARRAY_SIZE(s
->cmsdk_watchdog
));
743 object_initialize_child(obj
, devinfo
->name
,
744 &s
->cmsdk_watchdog
[devinfo
->index
],
745 TYPE_CMSDK_APB_WATCHDOG
);
746 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSINFO
)) {
747 assert(devinfo
->index
== 0);
748 object_initialize_child(obj
, devinfo
->name
, &s
->sysinfo
,
749 TYPE_IOTKIT_SYSINFO
);
750 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSCTL
)) {
751 assert(devinfo
->index
== 0);
752 object_initialize_child(obj
, devinfo
->name
, &s
->sysctl
,
754 } else if (!strcmp(devinfo
->type
, TYPE_UNIMPLEMENTED_DEVICE
)) {
755 assert(devinfo
->index
< ARRAY_SIZE(s
->unimp
));
756 object_initialize_child(obj
, devinfo
->name
,
757 &s
->unimp
[devinfo
->index
],
758 TYPE_UNIMPLEMENTED_DEVICE
);
760 g_assert_not_reached();
764 object_initialize_child(obj
, "secctl", &s
->secctl
, TYPE_IOTKIT_SECCTL
);
766 for (i
= 0; i
< ARRAY_SIZE(s
->apb_ppc
); i
++) {
767 g_autofree
char *name
= g_strdup_printf("apb-ppc%d", i
);
768 object_initialize_child(obj
, name
, &s
->apb_ppc
[i
], TYPE_TZ_PPC
);
771 for (i
= 0; i
< info
->sram_banks
; i
++) {
772 char *name
= g_strdup_printf("mpc%d", i
);
773 object_initialize_child(obj
, name
, &s
->mpc
[i
], TYPE_TZ_MPC
);
776 object_initialize_child(obj
, "mpc-irq-orgate", &s
->mpc_irq_orgate
,
779 for (i
= 0; i
< IOTS_NUM_EXP_MPC
+ info
->sram_banks
; i
++) {
780 char *name
= g_strdup_printf("mpc-irq-splitter-%d", i
);
781 SplitIRQ
*splitter
= &s
->mpc_irq_splitter
[i
];
783 object_initialize_child(obj
, name
, splitter
, TYPE_SPLIT_IRQ
);
787 if (info
->has_mhus
) {
788 object_initialize_child(obj
, "mhu0", &s
->mhu
[0], TYPE_ARMSSE_MHU
);
789 object_initialize_child(obj
, "mhu1", &s
->mhu
[1], TYPE_ARMSSE_MHU
);
791 if (info
->has_cachectrl
) {
792 for (i
= 0; i
< info
->num_cpus
; i
++) {
793 char *name
= g_strdup_printf("cachectrl%d", i
);
795 object_initialize_child(obj
, name
, &s
->cachectrl
[i
],
796 TYPE_UNIMPLEMENTED_DEVICE
);
800 if (info
->has_cpusecctrl
) {
801 for (i
= 0; i
< info
->num_cpus
; i
++) {
802 char *name
= g_strdup_printf("cpusecctrl%d", i
);
804 object_initialize_child(obj
, name
, &s
->cpusecctrl
[i
],
805 TYPE_UNIMPLEMENTED_DEVICE
);
809 if (info
->has_cpuid
) {
810 for (i
= 0; i
< info
->num_cpus
; i
++) {
811 char *name
= g_strdup_printf("cpuid%d", i
);
813 object_initialize_child(obj
, name
, &s
->cpuid
[i
],
818 if (info
->has_cpu_pwrctrl
) {
819 for (i
= 0; i
< info
->num_cpus
; i
++) {
820 char *name
= g_strdup_printf("cpu_pwrctrl%d", i
);
822 object_initialize_child(obj
, name
, &s
->cpu_pwrctrl
[i
],
823 TYPE_ARMSSE_CPU_PWRCTRL
);
827 if (info
->has_sse_counter
) {
828 object_initialize_child(obj
, "sse-counter", &s
->sse_counter
,
832 object_initialize_child(obj
, "nmi-orgate", &s
->nmi_orgate
, TYPE_OR_IRQ
);
833 object_initialize_child(obj
, "ppc-irq-orgate", &s
->ppc_irq_orgate
,
835 object_initialize_child(obj
, "sec-resp-splitter", &s
->sec_resp_splitter
,
837 for (i
= 0; i
< ARRAY_SIZE(s
->ppc_irq_splitter
); i
++) {
838 char *name
= g_strdup_printf("ppc-irq-splitter-%d", i
);
839 SplitIRQ
*splitter
= &s
->ppc_irq_splitter
[i
];
841 object_initialize_child(obj
, name
, splitter
, TYPE_SPLIT_IRQ
);
844 if (info
->num_cpus
> 1) {
845 for (i
= 0; i
< ARRAY_SIZE(s
->cpu_irq_splitter
); i
++) {
846 if (info
->irq_is_common
[i
]) {
847 char *name
= g_strdup_printf("cpu-irq-splitter%d", i
);
848 SplitIRQ
*splitter
= &s
->cpu_irq_splitter
[i
];
850 object_initialize_child(obj
, name
, splitter
, TYPE_SPLIT_IRQ
);
857 static void armsse_exp_irq(void *opaque
, int n
, int level
)
859 qemu_irq
*irqarray
= opaque
;
861 qemu_set_irq(irqarray
[n
], level
);
864 static void armsse_mpcexp_status(void *opaque
, int n
, int level
)
866 ARMSSE
*s
= ARM_SSE(opaque
);
867 qemu_set_irq(s
->mpcexp_status_in
[n
], level
);
870 static qemu_irq
armsse_get_common_irq_in(ARMSSE
*s
, int irqno
)
873 * Return a qemu_irq which can be used to signal IRQ n to
874 * all CPUs in the SSE.
876 ARMSSEClass
*asc
= ARM_SSE_GET_CLASS(s
);
877 const ARMSSEInfo
*info
= asc
->info
;
879 assert(info
->irq_is_common
[irqno
]);
881 if (info
->num_cpus
== 1) {
882 /* Only one CPU -- just connect directly to it */
883 return qdev_get_gpio_in(DEVICE(&s
->armv7m
[0]), irqno
);
885 /* Connect to the splitter which feeds all CPUs */
886 return qdev_get_gpio_in(DEVICE(&s
->cpu_irq_splitter
[irqno
]), 0);
890 static void armsse_realize(DeviceState
*dev
, Error
**errp
)
892 ARMSSE
*s
= ARM_SSE(dev
);
893 ARMSSEClass
*asc
= ARM_SSE_GET_CLASS(dev
);
894 const ARMSSEInfo
*info
= asc
->info
;
895 const ARMSSEDeviceInfo
*devinfo
;
899 SysBusDevice
*sbd_apb_ppc0
;
900 SysBusDevice
*sbd_secctl
;
901 DeviceState
*dev_apb_ppc0
;
902 DeviceState
*dev_apb_ppc1
;
903 DeviceState
*dev_secctl
;
904 DeviceState
*dev_splitter
;
905 uint32_t addr_width_max
;
907 if (!s
->board_memory
) {
908 error_setg(errp
, "memory property was not set");
912 if (!clock_has_source(s
->mainclk
)) {
913 error_setg(errp
, "MAINCLK clock was not connected");
915 if (!clock_has_source(s
->s32kclk
)) {
916 error_setg(errp
, "S32KCLK clock was not connected");
919 assert(info
->num_cpus
<= SSE_MAX_CPUS
);
921 /* max SRAM_ADDR_WIDTH: 24 - log2(SRAM_NUM_BANK) */
922 assert(is_power_of_2(info
->sram_banks
));
923 addr_width_max
= 24 - ctz32(info
->sram_banks
);
924 if (s
->sram_addr_width
< 1 || s
->sram_addr_width
> addr_width_max
) {
925 error_setg(errp
, "SRAM_ADDR_WIDTH must be between 1 and %d",
930 /* Handling of which devices should be available only to secure
931 * code is usually done differently for M profile than for A profile.
932 * Instead of putting some devices only into the secure address space,
933 * devices exist in both address spaces but with hard-wired security
934 * permissions that will cause the CPU to fault for non-secure accesses.
936 * The ARMSSE has an IDAU (Implementation Defined Access Unit),
937 * which specifies hard-wired security permissions for different
938 * areas of the physical address space. For the ARMSSE IDAU, the
939 * top 4 bits of the physical address are the IDAU region ID, and
940 * if bit 28 (ie the lowest bit of the ID) is 0 then this is an NS
941 * region, otherwise it is an S region.
943 * The various devices and RAMs are generally all mapped twice,
944 * once into a region that the IDAU defines as secure and once
945 * into a non-secure region. They sit behind either a Memory
946 * Protection Controller (for RAM) or a Peripheral Protection
947 * Controller (for devices), which allow a more fine grained
948 * configuration of whether non-secure accesses are permitted.
950 * (The other place that guest software can configure security
951 * permissions is in the architected SAU (Security Attribution
952 * Unit), which is entirely inside the CPU. The IDAU can upgrade
953 * the security attributes for a region to more restrictive than
954 * the SAU specifies, but cannot downgrade them.)
956 * 0x10000000..0x1fffffff alias of 0x00000000..0x0fffffff
957 * 0x20000000..0x2007ffff 32KB FPGA block RAM
958 * 0x30000000..0x3fffffff alias of 0x20000000..0x2fffffff
959 * 0x40000000..0x4000ffff base peripheral region 1
960 * 0x40010000..0x4001ffff CPU peripherals (none for ARMSSE)
961 * 0x40020000..0x4002ffff system control element peripherals
962 * 0x40080000..0x400fffff base peripheral region 2
963 * 0x50000000..0x5fffffff alias of 0x40000000..0x4fffffff
966 memory_region_add_subregion_overlap(&s
->container
, 0, s
->board_memory
, -2);
968 for (i
= 0; i
< info
->num_cpus
; i
++) {
969 DeviceState
*cpudev
= DEVICE(&s
->armv7m
[i
]);
970 Object
*cpuobj
= OBJECT(&s
->armv7m
[i
]);
974 qdev_prop_set_uint32(cpudev
, "num-irq", s
->exp_numirq
+ NUM_SSE_IRQS
);
976 * In real hardware the initial Secure VTOR is set from the INITSVTOR*
977 * registers in the IoT Kit System Control Register block. In QEMU
978 * we set the initial value here, and also the reset value of the
979 * sysctl register, from this object's QOM init-svtor property.
980 * If the guest changes the INITSVTOR* registers at runtime then the
981 * code in iotkit-sysctl.c will update the CPU init-svtor property
982 * (which will then take effect on the next CPU warm-reset).
984 * Note that typically a board using the SSE-200 will have a system
985 * control processor whose boot firmware initializes the INITSVTOR*
986 * registers before powering up the CPUs. QEMU doesn't emulate
987 * the control processor, so instead we behave in the way that the
988 * firmware does: the initial value should be set by the board code
989 * (using the init-svtor property on the ARMSSE object) to match
990 * whatever its firmware does.
992 qdev_prop_set_uint32(cpudev
, "init-svtor", s
->init_svtor
);
994 * CPUs start powered down if the corresponding bit in the CPUWAIT
995 * register is 1. In real hardware the CPUWAIT register reset value is
996 * a configurable property of the SSE-200 (via the CPUWAIT0_RST and
997 * CPUWAIT1_RST parameters), but since all the boards we care about
998 * start CPU0 and leave CPU1 powered off, we hard-code that in
999 * info->cpuwait_rst for now. We can add QOM properties for this
1000 * later if necessary.
1002 if (extract32(info
->cpuwait_rst
, i
, 1)) {
1003 if (!object_property_set_bool(cpuobj
, "start-powered-off", true,
1008 if (!s
->cpu_fpu
[i
]) {
1009 if (!object_property_set_bool(cpuobj
, "vfp", false, errp
)) {
1013 if (!s
->cpu_dsp
[i
]) {
1014 if (!object_property_set_bool(cpuobj
, "dsp", false, errp
)) {
1020 memory_region_add_subregion_overlap(&s
->cpu_container
[i
], 0,
1021 &s
->container_alias
[i
- 1], -1);
1023 memory_region_add_subregion_overlap(&s
->cpu_container
[i
], 0,
1026 object_property_set_link(cpuobj
, "memory",
1027 OBJECT(&s
->cpu_container
[i
]), &error_abort
);
1028 object_property_set_link(cpuobj
, "idau", OBJECT(s
), &error_abort
);
1029 if (!sysbus_realize(SYS_BUS_DEVICE(cpuobj
), errp
)) {
1033 * The cluster must be realized after the armv7m container, as
1034 * the container's CPU object is only created on realize, and the
1035 * CPU must exist and have been parented into the cluster before
1036 * the cluster is realized.
1038 if (!qdev_realize(DEVICE(&s
->cluster
[i
]), NULL
, errp
)) {
1042 /* Connect EXP_IRQ/EXP_CPUn_IRQ GPIOs to the NVIC's lines 32 and up */
1043 s
->exp_irqs
[i
] = g_new(qemu_irq
, s
->exp_numirq
);
1044 for (j
= 0; j
< s
->exp_numirq
; j
++) {
1045 s
->exp_irqs
[i
][j
] = qdev_get_gpio_in(cpudev
, j
+ NUM_SSE_IRQS
);
1048 gpioname
= g_strdup("EXP_IRQ");
1050 gpioname
= g_strdup_printf("EXP_CPU%d_IRQ", i
);
1052 qdev_init_gpio_in_named_with_opaque(dev
, armsse_exp_irq
,
1054 gpioname
, s
->exp_numirq
);
1058 /* Wire up the splitters that connect common IRQs to all CPUs */
1059 if (info
->num_cpus
> 1) {
1060 for (i
= 0; i
< ARRAY_SIZE(s
->cpu_irq_splitter
); i
++) {
1061 if (info
->irq_is_common
[i
]) {
1062 Object
*splitter
= OBJECT(&s
->cpu_irq_splitter
[i
]);
1063 DeviceState
*devs
= DEVICE(splitter
);
1066 if (!object_property_set_int(splitter
, "num-lines",
1067 info
->num_cpus
, errp
)) {
1070 if (!qdev_realize(DEVICE(splitter
), NULL
, errp
)) {
1073 for (cpunum
= 0; cpunum
< info
->num_cpus
; cpunum
++) {
1074 DeviceState
*cpudev
= DEVICE(&s
->armv7m
[cpunum
]);
1076 qdev_connect_gpio_out(devs
, cpunum
,
1077 qdev_get_gpio_in(cpudev
, i
));
1083 /* Set up the big aliases first */
1084 make_alias(s
, &s
->alias1
, &s
->container
, "alias 1",
1085 0x10000000, 0x10000000, 0x00000000);
1086 make_alias(s
, &s
->alias2
, &s
->container
,
1087 "alias 2", 0x30000000, 0x10000000, 0x20000000);
1088 /* The 0x50000000..0x5fffffff region is not a pure alias: it has
1089 * a few extra devices that only appear there (generally the
1090 * control interfaces for the protection controllers).
1091 * We implement this by mapping those devices over the top of this
1092 * alias MR at a higher priority. Some of the devices in this range
1093 * are per-CPU, so we must put this alias in the per-cpu containers.
1095 for (i
= 0; i
< info
->num_cpus
; i
++) {
1096 make_alias(s
, &s
->alias3
[i
], &s
->cpu_container
[i
],
1097 "alias 3", 0x50000000, 0x10000000, 0x40000000);
1100 /* Security controller */
1101 object_property_set_int(OBJECT(&s
->secctl
), "sse-version",
1102 info
->sse_version
, &error_abort
);
1103 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->secctl
), errp
)) {
1106 sbd_secctl
= SYS_BUS_DEVICE(&s
->secctl
);
1107 dev_secctl
= DEVICE(&s
->secctl
);
1108 sysbus_mmio_map(sbd_secctl
, 0, 0x50080000);
1109 sysbus_mmio_map(sbd_secctl
, 1, 0x40080000);
1111 s
->nsc_cfg_in
= qemu_allocate_irq(nsccfg_handler
, s
, 1);
1112 qdev_connect_gpio_out_named(dev_secctl
, "nsc_cfg", 0, s
->nsc_cfg_in
);
1114 /* The sec_resp_cfg output from the security controller must be split into
1115 * multiple lines, one for each of the PPCs within the ARMSSE and one
1116 * that will be an output from the ARMSSE to the system.
1118 if (!object_property_set_int(OBJECT(&s
->sec_resp_splitter
),
1119 "num-lines", 3, errp
)) {
1122 if (!qdev_realize(DEVICE(&s
->sec_resp_splitter
), NULL
, errp
)) {
1125 dev_splitter
= DEVICE(&s
->sec_resp_splitter
);
1126 qdev_connect_gpio_out_named(dev_secctl
, "sec_resp_cfg", 0,
1127 qdev_get_gpio_in(dev_splitter
, 0));
1129 /* Each SRAM bank lives behind its own Memory Protection Controller */
1130 for (i
= 0; i
< info
->sram_banks
; i
++) {
1131 char *ramname
= g_strdup_printf("armsse.sram%d", i
);
1132 SysBusDevice
*sbd_mpc
;
1133 uint32_t sram_bank_size
= 1 << s
->sram_addr_width
;
1135 memory_region_init_ram(&s
->sram
[i
], NULL
, ramname
,
1136 sram_bank_size
, &err
);
1139 error_propagate(errp
, err
);
1142 object_property_set_link(OBJECT(&s
->mpc
[i
]), "downstream",
1143 OBJECT(&s
->sram
[i
]), &error_abort
);
1144 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->mpc
[i
]), errp
)) {
1147 /* Map the upstream end of the MPC into the right place... */
1148 sbd_mpc
= SYS_BUS_DEVICE(&s
->mpc
[i
]);
1149 memory_region_add_subregion(&s
->container
,
1150 0x20000000 + i
* sram_bank_size
,
1151 sysbus_mmio_get_region(sbd_mpc
, 1));
1152 /* ...and its register interface */
1153 memory_region_add_subregion(&s
->container
, 0x50083000 + i
* 0x1000,
1154 sysbus_mmio_get_region(sbd_mpc
, 0));
1157 /* We must OR together lines from the MPC splitters to go to the NVIC */
1158 if (!object_property_set_int(OBJECT(&s
->mpc_irq_orgate
), "num-lines",
1159 IOTS_NUM_EXP_MPC
+ info
->sram_banks
,
1163 if (!qdev_realize(DEVICE(&s
->mpc_irq_orgate
), NULL
, errp
)) {
1166 qdev_connect_gpio_out(DEVICE(&s
->mpc_irq_orgate
), 0,
1167 armsse_get_common_irq_in(s
, 9));
1169 /* This OR gate wires together outputs from the secure watchdogs to NMI */
1170 if (!object_property_set_int(OBJECT(&s
->nmi_orgate
), "num-lines", 2,
1174 if (!qdev_realize(DEVICE(&s
->nmi_orgate
), NULL
, errp
)) {
1177 qdev_connect_gpio_out(DEVICE(&s
->nmi_orgate
), 0,
1178 qdev_get_gpio_in_named(DEVICE(&s
->armv7m
), "NMI", 0));
1180 /* The SSE-300 has a System Counter / System Timestamp Generator */
1181 if (info
->has_sse_counter
) {
1182 SysBusDevice
*sbd
= SYS_BUS_DEVICE(&s
->sse_counter
);
1184 qdev_connect_clock_in(DEVICE(sbd
), "CLK", s
->mainclk
);
1185 if (!sysbus_realize(sbd
, errp
)) {
1189 * The control frame is only in the Secure region;
1190 * the status frame is in the NS region (and visible in the
1191 * S region via the alias mapping).
1193 memory_region_add_subregion(&s
->container
, 0x58100000,
1194 sysbus_mmio_get_region(sbd
, 0));
1195 memory_region_add_subregion(&s
->container
, 0x48101000,
1196 sysbus_mmio_get_region(sbd
, 1));
1199 /* Devices behind APB PPC0:
1200 * 0x40000000: timer0
1201 * 0x40001000: timer1
1202 * 0x40002000: dual timer
1203 * 0x40003000: MHU0 (SSE-200 only)
1204 * 0x40004000: MHU1 (SSE-200 only)
1205 * We must configure and realize each downstream device and connect
1206 * it to the appropriate PPC port; then we can realize the PPC and
1207 * map its upstream ends to the right place in the container.
1209 for (devinfo
= info
->devinfo
; devinfo
->name
; devinfo
++) {
1213 if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_TIMER
)) {
1214 sbd
= SYS_BUS_DEVICE(&s
->timer
[devinfo
->index
]);
1216 qdev_connect_clock_in(DEVICE(sbd
), "pclk",
1217 devinfo
->slowclk
? s
->s32kclk
: s
->mainclk
);
1218 if (!sysbus_realize(sbd
, errp
)) {
1221 mr
= sysbus_mmio_get_region(sbd
, 0);
1222 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_DUALTIMER
)) {
1223 sbd
= SYS_BUS_DEVICE(&s
->dualtimer
);
1225 qdev_connect_clock_in(DEVICE(sbd
), "TIMCLK", s
->mainclk
);
1226 if (!sysbus_realize(sbd
, errp
)) {
1229 mr
= sysbus_mmio_get_region(sbd
, 0);
1230 } else if (!strcmp(devinfo
->type
, TYPE_SSE_TIMER
)) {
1231 sbd
= SYS_BUS_DEVICE(&s
->sse_timer
[devinfo
->index
]);
1233 assert(info
->has_sse_counter
);
1234 object_property_set_link(OBJECT(sbd
), "counter",
1235 OBJECT(&s
->sse_counter
), &error_abort
);
1236 if (!sysbus_realize(sbd
, errp
)) {
1239 mr
= sysbus_mmio_get_region(sbd
, 0);
1240 } else if (!strcmp(devinfo
->type
, TYPE_CMSDK_APB_WATCHDOG
)) {
1241 sbd
= SYS_BUS_DEVICE(&s
->cmsdk_watchdog
[devinfo
->index
]);
1243 qdev_connect_clock_in(DEVICE(sbd
), "WDOGCLK",
1244 devinfo
->slowclk
? s
->s32kclk
: s
->mainclk
);
1245 if (!sysbus_realize(sbd
, errp
)) {
1248 mr
= sysbus_mmio_get_region(sbd
, 0);
1249 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSINFO
)) {
1250 sbd
= SYS_BUS_DEVICE(&s
->sysinfo
);
1252 object_property_set_int(OBJECT(&s
->sysinfo
), "SYS_VERSION",
1253 info
->sys_version
, &error_abort
);
1254 object_property_set_int(OBJECT(&s
->sysinfo
), "SYS_CONFIG",
1255 armsse_sys_config_value(s
, info
),
1257 object_property_set_int(OBJECT(&s
->sysinfo
), "sse-version",
1258 info
->sse_version
, &error_abort
);
1259 object_property_set_int(OBJECT(&s
->sysinfo
), "IIDR",
1260 info
->iidr
, &error_abort
);
1261 if (!sysbus_realize(sbd
, errp
)) {
1264 mr
= sysbus_mmio_get_region(sbd
, 0);
1265 } else if (!strcmp(devinfo
->type
, TYPE_IOTKIT_SYSCTL
)) {
1266 /* System control registers */
1267 sbd
= SYS_BUS_DEVICE(&s
->sysctl
);
1269 object_property_set_int(OBJECT(&s
->sysctl
), "sse-version",
1270 info
->sse_version
, &error_abort
);
1271 object_property_set_int(OBJECT(&s
->sysctl
), "CPUWAIT_RST",
1272 info
->cpuwait_rst
, &error_abort
);
1273 object_property_set_int(OBJECT(&s
->sysctl
), "INITSVTOR0_RST",
1274 s
->init_svtor
, &error_abort
);
1275 object_property_set_int(OBJECT(&s
->sysctl
), "INITSVTOR1_RST",
1276 s
->init_svtor
, &error_abort
);
1277 if (!sysbus_realize(sbd
, errp
)) {
1280 mr
= sysbus_mmio_get_region(sbd
, 0);
1281 } else if (!strcmp(devinfo
->type
, TYPE_UNIMPLEMENTED_DEVICE
)) {
1282 sbd
= SYS_BUS_DEVICE(&s
->unimp
[devinfo
->index
]);
1284 qdev_prop_set_string(DEVICE(sbd
), "name", devinfo
->name
);
1285 qdev_prop_set_uint64(DEVICE(sbd
), "size", devinfo
->size
);
1286 if (!sysbus_realize(sbd
, errp
)) {
1289 mr
= sysbus_mmio_get_region(sbd
, 0);
1291 g_assert_not_reached();
1294 switch (devinfo
->irq
) {
1298 case 0 ... NUM_SSE_IRQS
- 1:
1299 irq
= armsse_get_common_irq_in(s
, devinfo
->irq
);
1303 irq
= qdev_get_gpio_in(DEVICE(&s
->nmi_orgate
),
1304 devinfo
->irq
- NMI_0
);
1307 g_assert_not_reached();
1311 sysbus_connect_irq(sbd
, 0, irq
);
1315 * Devices connected to a PPC are connected to the port here;
1316 * we will map the upstream end of that port to the right address
1317 * in the container later after the PPC has been realized.
1318 * Devices not connected to a PPC can be mapped immediately.
1320 if (devinfo
->ppc
!= NO_PPC
) {
1321 TZPPC
*ppc
= &s
->apb_ppc
[devinfo
->ppc
];
1322 g_autofree
char *portname
= g_strdup_printf("port[%d]",
1324 object_property_set_link(OBJECT(ppc
), portname
, OBJECT(mr
),
1327 memory_region_add_subregion(&s
->container
, devinfo
->addr
, mr
);
1331 if (info
->has_mhus
) {
1333 * An SSE-200 with only one CPU should have only one MHU created,
1334 * with the region where the second MHU usually is being RAZ/WI.
1335 * We don't implement that SSE-200 config; if we want to support
1336 * it then this code needs to be enhanced to handle creating the
1337 * RAZ/WI region instead of the second MHU.
1339 assert(info
->num_cpus
== ARRAY_SIZE(s
->mhu
));
1341 for (i
= 0; i
< ARRAY_SIZE(s
->mhu
); i
++) {
1344 SysBusDevice
*mhu_sbd
= SYS_BUS_DEVICE(&s
->mhu
[i
]);
1346 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->mhu
[i
]), errp
)) {
1349 port
= g_strdup_printf("port[%d]", i
+ 3);
1350 mr
= sysbus_mmio_get_region(mhu_sbd
, 0);
1351 object_property_set_link(OBJECT(&s
->apb_ppc
[0]), port
, OBJECT(mr
),
1356 * Each MHU has an irq line for each CPU:
1357 * MHU 0 irq line 0 -> CPU 0 IRQ 6
1358 * MHU 0 irq line 1 -> CPU 1 IRQ 6
1359 * MHU 1 irq line 0 -> CPU 0 IRQ 7
1360 * MHU 1 irq line 1 -> CPU 1 IRQ 7
1362 for (cpunum
= 0; cpunum
< info
->num_cpus
; cpunum
++) {
1363 DeviceState
*cpudev
= DEVICE(&s
->armv7m
[cpunum
]);
1365 sysbus_connect_irq(mhu_sbd
, cpunum
,
1366 qdev_get_gpio_in(cpudev
, 6 + i
));
1371 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->apb_ppc
[0]), errp
)) {
1375 sbd_apb_ppc0
= SYS_BUS_DEVICE(&s
->apb_ppc
[0]);
1376 dev_apb_ppc0
= DEVICE(&s
->apb_ppc
[0]);
1378 if (info
->has_mhus
) {
1379 mr
= sysbus_mmio_get_region(sbd_apb_ppc0
, 3);
1380 memory_region_add_subregion(&s
->container
, 0x40003000, mr
);
1381 mr
= sysbus_mmio_get_region(sbd_apb_ppc0
, 4);
1382 memory_region_add_subregion(&s
->container
, 0x40004000, mr
);
1384 for (i
= 0; i
< IOTS_APB_PPC0_NUM_PORTS
; i
++) {
1385 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_nonsec", i
,
1386 qdev_get_gpio_in_named(dev_apb_ppc0
,
1388 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_ap", i
,
1389 qdev_get_gpio_in_named(dev_apb_ppc0
,
1392 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_irq_enable", 0,
1393 qdev_get_gpio_in_named(dev_apb_ppc0
,
1395 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc0_irq_clear", 0,
1396 qdev_get_gpio_in_named(dev_apb_ppc0
,
1398 qdev_connect_gpio_out(dev_splitter
, 0,
1399 qdev_get_gpio_in_named(dev_apb_ppc0
,
1400 "cfg_sec_resp", 0));
1402 /* All the PPC irq lines (from the 2 internal PPCs and the 8 external
1403 * ones) are sent individually to the security controller, and also
1404 * ORed together to give a single combined PPC interrupt to the NVIC.
1406 if (!object_property_set_int(OBJECT(&s
->ppc_irq_orgate
),
1407 "num-lines", NUM_PPCS
, errp
)) {
1410 if (!qdev_realize(DEVICE(&s
->ppc_irq_orgate
), NULL
, errp
)) {
1413 qdev_connect_gpio_out(DEVICE(&s
->ppc_irq_orgate
), 0,
1414 armsse_get_common_irq_in(s
, 10));
1417 * 0x40010000 .. 0x4001ffff (and the 0x5001000... secure-only alias):
1418 * private per-CPU region (all these devices are SSE-200 only):
1419 * 0x50010000: L1 icache control registers
1420 * 0x50011000: CPUSECCTRL (CPU local security control registers)
1421 * 0x4001f000 and 0x5001f000: CPU_IDENTITY register block
1422 * The SSE-300 has an extra:
1423 * 0x40012000 and 0x50012000: CPU_PWRCTRL register block
1425 if (info
->has_cachectrl
) {
1426 for (i
= 0; i
< info
->num_cpus
; i
++) {
1427 char *name
= g_strdup_printf("cachectrl%d", i
);
1430 qdev_prop_set_string(DEVICE(&s
->cachectrl
[i
]), "name", name
);
1432 qdev_prop_set_uint64(DEVICE(&s
->cachectrl
[i
]), "size", 0x1000);
1433 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cachectrl
[i
]), errp
)) {
1437 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cachectrl
[i
]), 0);
1438 memory_region_add_subregion(&s
->cpu_container
[i
], 0x50010000, mr
);
1441 if (info
->has_cpusecctrl
) {
1442 for (i
= 0; i
< info
->num_cpus
; i
++) {
1443 char *name
= g_strdup_printf("CPUSECCTRL%d", i
);
1446 qdev_prop_set_string(DEVICE(&s
->cpusecctrl
[i
]), "name", name
);
1448 qdev_prop_set_uint64(DEVICE(&s
->cpusecctrl
[i
]), "size", 0x1000);
1449 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cpusecctrl
[i
]), errp
)) {
1453 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cpusecctrl
[i
]), 0);
1454 memory_region_add_subregion(&s
->cpu_container
[i
], 0x50011000, mr
);
1457 if (info
->has_cpuid
) {
1458 for (i
= 0; i
< info
->num_cpus
; i
++) {
1461 qdev_prop_set_uint32(DEVICE(&s
->cpuid
[i
]), "CPUID", i
);
1462 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cpuid
[i
]), errp
)) {
1466 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cpuid
[i
]), 0);
1467 memory_region_add_subregion(&s
->cpu_container
[i
], 0x4001F000, mr
);
1470 if (info
->has_cpu_pwrctrl
) {
1471 for (i
= 0; i
< info
->num_cpus
; i
++) {
1474 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->cpu_pwrctrl
[i
]), errp
)) {
1478 mr
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&s
->cpu_pwrctrl
[i
]), 0);
1479 memory_region_add_subregion(&s
->cpu_container
[i
], 0x40012000, mr
);
1483 if (!sysbus_realize(SYS_BUS_DEVICE(&s
->apb_ppc
[1]), errp
)) {
1487 dev_apb_ppc1
= DEVICE(&s
->apb_ppc
[1]);
1488 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_nonsec", 0,
1489 qdev_get_gpio_in_named(dev_apb_ppc1
,
1491 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_ap", 0,
1492 qdev_get_gpio_in_named(dev_apb_ppc1
,
1494 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_irq_enable", 0,
1495 qdev_get_gpio_in_named(dev_apb_ppc1
,
1497 qdev_connect_gpio_out_named(dev_secctl
, "apb_ppc1_irq_clear", 0,
1498 qdev_get_gpio_in_named(dev_apb_ppc1
,
1500 qdev_connect_gpio_out(dev_splitter
, 1,
1501 qdev_get_gpio_in_named(dev_apb_ppc1
,
1502 "cfg_sec_resp", 0));
1505 * Now both PPCs are realized we can map the upstream ends of
1506 * ports which correspond to entries in the devinfo array.
1507 * The ports which are connected to non-devinfo devices have
1508 * already been mapped.
1510 for (devinfo
= info
->devinfo
; devinfo
->name
; devinfo
++) {
1511 SysBusDevice
*ppc_sbd
;
1513 if (devinfo
->ppc
== NO_PPC
) {
1516 ppc_sbd
= SYS_BUS_DEVICE(&s
->apb_ppc
[devinfo
->ppc
]);
1517 mr
= sysbus_mmio_get_region(ppc_sbd
, devinfo
->ppc_port
);
1518 memory_region_add_subregion(&s
->container
, devinfo
->addr
, mr
);
1521 for (i
= 0; i
< ARRAY_SIZE(s
->ppc_irq_splitter
); i
++) {
1522 Object
*splitter
= OBJECT(&s
->ppc_irq_splitter
[i
]);
1524 if (!object_property_set_int(splitter
, "num-lines", 2, errp
)) {
1527 if (!qdev_realize(DEVICE(splitter
), NULL
, errp
)) {
1532 for (i
= 0; i
< IOTS_NUM_AHB_EXP_PPC
; i
++) {
1533 char *ppcname
= g_strdup_printf("ahb_ppcexp%d", i
);
1535 armsse_forward_ppc(s
, ppcname
, i
);
1539 for (i
= 0; i
< IOTS_NUM_APB_EXP_PPC
; i
++) {
1540 char *ppcname
= g_strdup_printf("apb_ppcexp%d", i
);
1542 armsse_forward_ppc(s
, ppcname
, i
+ IOTS_NUM_AHB_EXP_PPC
);
1546 for (i
= NUM_EXTERNAL_PPCS
; i
< NUM_PPCS
; i
++) {
1547 /* Wire up IRQ splitter for internal PPCs */
1548 DeviceState
*devs
= DEVICE(&s
->ppc_irq_splitter
[i
]);
1549 char *gpioname
= g_strdup_printf("apb_ppc%d_irq_status",
1550 i
- NUM_EXTERNAL_PPCS
);
1551 TZPPC
*ppc
= &s
->apb_ppc
[i
- NUM_EXTERNAL_PPCS
];
1553 qdev_connect_gpio_out(devs
, 0,
1554 qdev_get_gpio_in_named(dev_secctl
, gpioname
, 0));
1555 qdev_connect_gpio_out(devs
, 1,
1556 qdev_get_gpio_in(DEVICE(&s
->ppc_irq_orgate
), i
));
1557 qdev_connect_gpio_out_named(DEVICE(ppc
), "irq", 0,
1558 qdev_get_gpio_in(devs
, 0));
1562 /* Wire up the splitters for the MPC IRQs */
1563 for (i
= 0; i
< IOTS_NUM_EXP_MPC
+ info
->sram_banks
; i
++) {
1564 SplitIRQ
*splitter
= &s
->mpc_irq_splitter
[i
];
1565 DeviceState
*dev_splitter
= DEVICE(splitter
);
1567 if (!object_property_set_int(OBJECT(splitter
), "num-lines", 2,
1571 if (!qdev_realize(DEVICE(splitter
), NULL
, errp
)) {
1575 if (i
< IOTS_NUM_EXP_MPC
) {
1576 /* Splitter input is from GPIO input line */
1577 s
->mpcexp_status_in
[i
] = qdev_get_gpio_in(dev_splitter
, 0);
1578 qdev_connect_gpio_out(dev_splitter
, 0,
1579 qdev_get_gpio_in_named(dev_secctl
,
1580 "mpcexp_status", i
));
1582 /* Splitter input is from our own MPC */
1583 qdev_connect_gpio_out_named(DEVICE(&s
->mpc
[i
- IOTS_NUM_EXP_MPC
]),
1585 qdev_get_gpio_in(dev_splitter
, 0));
1586 qdev_connect_gpio_out(dev_splitter
, 0,
1587 qdev_get_gpio_in_named(dev_secctl
,
1589 i
- IOTS_NUM_EXP_MPC
));
1592 qdev_connect_gpio_out(dev_splitter
, 1,
1593 qdev_get_gpio_in(DEVICE(&s
->mpc_irq_orgate
), i
));
1595 /* Create GPIO inputs which will pass the line state for our
1596 * mpcexp_irq inputs to the correct splitter devices.
1598 qdev_init_gpio_in_named(dev
, armsse_mpcexp_status
, "mpcexp_status",
1601 armsse_forward_sec_resp_cfg(s
);
1603 /* Forward the MSC related signals */
1604 qdev_pass_gpios(dev_secctl
, dev
, "mscexp_status");
1605 qdev_pass_gpios(dev_secctl
, dev
, "mscexp_clear");
1606 qdev_pass_gpios(dev_secctl
, dev
, "mscexp_ns");
1607 qdev_connect_gpio_out_named(dev_secctl
, "msc_irq", 0,
1608 armsse_get_common_irq_in(s
, 11));
1611 * Expose our container region to the board model; this corresponds
1612 * to the AHB Slave Expansion ports which allow bus master devices
1613 * (eg DMA controllers) in the board model to make transactions into
1614 * devices in the ARMSSE.
1616 sysbus_init_mmio(SYS_BUS_DEVICE(s
), &s
->container
);
1618 /* Set initial system_clock_scale from MAINCLK */
1619 armsse_mainclk_update(s
, ClockUpdate
);
1622 static void armsse_idau_check(IDAUInterface
*ii
, uint32_t address
,
1623 int *iregion
, bool *exempt
, bool *ns
, bool *nsc
)
1626 * For ARMSSE systems the IDAU responses are simple logical functions
1627 * of the address bits. The NSC attribute is guest-adjustable via the
1628 * NSCCFG register in the security controller.
1630 ARMSSE
*s
= ARM_SSE(ii
);
1631 int region
= extract32(address
, 28, 4);
1633 *ns
= !(region
& 1);
1634 *nsc
= (region
== 1 && (s
->nsccfg
& 1)) || (region
== 3 && (s
->nsccfg
& 2));
1635 /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */
1636 *exempt
= (address
& 0xeff00000) == 0xe0000000;
1640 static const VMStateDescription armsse_vmstate
= {
1643 .minimum_version_id
= 2,
1644 .fields
= (VMStateField
[]) {
1645 VMSTATE_CLOCK(mainclk
, ARMSSE
),
1646 VMSTATE_CLOCK(s32kclk
, ARMSSE
),
1647 VMSTATE_UINT32(nsccfg
, ARMSSE
),
1648 VMSTATE_END_OF_LIST()
1652 static void armsse_reset(DeviceState
*dev
)
1654 ARMSSE
*s
= ARM_SSE(dev
);
1659 static void armsse_class_init(ObjectClass
*klass
, void *data
)
1661 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1662 IDAUInterfaceClass
*iic
= IDAU_INTERFACE_CLASS(klass
);
1663 ARMSSEClass
*asc
= ARM_SSE_CLASS(klass
);
1664 const ARMSSEInfo
*info
= data
;
1666 dc
->realize
= armsse_realize
;
1667 dc
->vmsd
= &armsse_vmstate
;
1668 device_class_set_props(dc
, info
->props
);
1669 dc
->reset
= armsse_reset
;
1670 iic
->check
= armsse_idau_check
;
1674 static const TypeInfo armsse_info
= {
1675 .name
= TYPE_ARM_SSE
,
1676 .parent
= TYPE_SYS_BUS_DEVICE
,
1677 .instance_size
= sizeof(ARMSSE
),
1678 .class_size
= sizeof(ARMSSEClass
),
1679 .instance_init
= armsse_init
,
1681 .interfaces
= (InterfaceInfo
[]) {
1682 { TYPE_IDAU_INTERFACE
},
1687 static void armsse_register_types(void)
1691 type_register_static(&armsse_info
);
1693 for (i
= 0; i
< ARRAY_SIZE(armsse_variants
); i
++) {
1695 .name
= armsse_variants
[i
].name
,
1696 .parent
= TYPE_ARM_SSE
,
1697 .class_init
= armsse_class_init
,
1698 .class_data
= (void *)&armsse_variants
[i
],
1704 type_init(armsse_register_types
);