2 * ARM V2M MPS2 board emulation, trustzone aware FPGA images
4 * Copyright (c) 2017 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 /* The MPS2 and MPS2+ dev boards are FPGA based (the 2+ has a bigger
13 * FPGA but is otherwise the same as the 2). Since the CPU itself
14 * and most of the devices are in the FPGA, the details of the board
15 * as seen by the guest depend significantly on the FPGA image.
16 * This source file covers the following FPGA images, for TrustZone cores:
17 * "mps2-an505" -- Cortex-M33 as documented in ARM Application Note AN505
18 * "mps2-an521" -- Dual Cortex-M33 as documented in Application Note AN521
19 * "mps2-an524" -- Dual Cortex-M33 as documented in Application Note AN524
20 * "mps2-an547" -- Single Cortex-M55 as documented in Application Note AN547
22 * Links to the TRM for the board itself and to the various Application
23 * Notes which document the FPGA images can be found here:
24 * https://developer.arm.com/products/system-design/development-boards/fpga-prototyping-boards/mps2
27 * https://developer.arm.com/documentation/100112/latest/
28 * Application Note AN505:
29 * https://developer.arm.com/documentation/dai0505/latest/
30 * Application Note AN521:
31 * https://developer.arm.com/documentation/dai0521/latest/
32 * Application Note AN524:
33 * https://developer.arm.com/documentation/dai0524/latest/
34 * Application Note AN547:
35 * https://developer.arm.com/-/media/Arm%20Developer%20Community/PDF/DAI0547B_SSE300_PLUS_U55_FPGA_for_mps3.pdf
37 * The AN505 defers to the Cortex-M33 processor ARMv8M IoT Kit FVP User Guide
38 * (ARM ECM0601256) for the details of some of the device layout:
39 * https://developer.arm.com/documentation/ecm0601256/latest
40 * Similarly, the AN521 and AN524 use the SSE-200, and the SSE-200 TRM defines
41 * most of the device layout:
42 * https://developer.arm.com/documentation/101104/latest/
43 * and the AN547 uses the SSE-300, whose layout is in the SSE-300 TRM:
44 * https://developer.arm.com/documentation/101773/latest/
47 #include "qemu/osdep.h"
48 #include "qemu/units.h"
49 #include "qemu/cutils.h"
50 #include "qapi/error.h"
51 #include "qemu/error-report.h"
52 #include "hw/arm/boot.h"
53 #include "hw/arm/armv7m.h"
54 #include "hw/or-irq.h"
55 #include "hw/boards.h"
56 #include "exec/address-spaces.h"
57 #include "sysemu/sysemu.h"
58 #include "sysemu/reset.h"
59 #include "hw/misc/unimp.h"
60 #include "hw/char/cmsdk-apb-uart.h"
61 #include "hw/timer/cmsdk-apb-timer.h"
62 #include "hw/misc/mps2-scc.h"
63 #include "hw/misc/mps2-fpgaio.h"
64 #include "hw/misc/tz-mpc.h"
65 #include "hw/misc/tz-msc.h"
66 #include "hw/arm/armsse.h"
67 #include "hw/dma/pl080.h"
68 #include "hw/rtc/pl031.h"
69 #include "hw/ssi/pl022.h"
70 #include "hw/i2c/arm_sbcon_i2c.h"
71 #include "hw/net/lan9118.h"
73 #include "hw/core/split-irq.h"
74 #include "hw/qdev-clock.h"
75 #include "qom/object.h"
78 #define MPS2TZ_NUMIRQ_MAX 96
79 #define MPS2TZ_RAM_MAX 5
81 typedef enum MPS2TZFPGAType
{
89 * Define the layout of RAM in a board, including which parts are
91 * mrindex specifies the index into mms->ram[] to use for the backing RAM;
92 * -1 means "use the system RAM".
94 typedef struct RAMInfo
{
98 int mpc
; /* MPC number, -1 for "not behind an MPC" */
105 * IS_ALIAS: this RAM area is an alias to the upstream end of the
106 * MPC specified by its .mpc value
107 * IS_ROM: this RAM area is read-only
112 struct MPS2TZMachineClass
{
114 MPS2TZFPGAType fpga_type
;
116 uint32_t sysclk_frq
; /* Main SYSCLK frequency in Hz */
117 uint32_t apb_periph_frq
; /* APB peripheral frequency in Hz */
119 const uint32_t *oscclk
;
120 uint32_t fpgaio_num_leds
; /* Number of LEDs in FPGAIO LED0 register */
121 bool fpgaio_has_switches
; /* Does FPGAIO have SWITCH register? */
122 bool fpgaio_has_dbgctrl
; /* Does FPGAIO have DBGCTRL register? */
123 int numirq
; /* Number of external interrupts */
124 int uart_overflow_irq
; /* number of the combined UART overflow IRQ */
125 uint32_t init_svtor
; /* init-svtor setting for SSE */
126 const RAMInfo
*raminfo
;
127 const char *armsse_type
;
130 struct MPS2TZMachineState
{
134 MemoryRegion ram
[MPS2TZ_RAM_MAX
];
135 MemoryRegion eth_usb_container
;
142 ArmSbconI2CState i2c
[5];
143 UnimplementedDeviceState i2s_audio
;
144 UnimplementedDeviceState gpio
[4];
145 UnimplementedDeviceState gfx
;
146 UnimplementedDeviceState cldc
;
147 UnimplementedDeviceState usb
;
151 CMSDKAPBUART uart
[6];
152 SplitIRQ sec_resp_splitter
;
153 qemu_or_irq uart_irq_orgate
;
154 DeviceState
*lan9118
;
155 SplitIRQ cpu_irq_splitter
[MPS2TZ_NUMIRQ_MAX
];
163 #define TYPE_MPS2TZ_MACHINE "mps2tz"
164 #define TYPE_MPS2TZ_AN505_MACHINE MACHINE_TYPE_NAME("mps2-an505")
165 #define TYPE_MPS2TZ_AN521_MACHINE MACHINE_TYPE_NAME("mps2-an521")
166 #define TYPE_MPS3TZ_AN524_MACHINE MACHINE_TYPE_NAME("mps3-an524")
167 #define TYPE_MPS3TZ_AN547_MACHINE MACHINE_TYPE_NAME("mps3-an547")
169 OBJECT_DECLARE_TYPE(MPS2TZMachineState
, MPS2TZMachineClass
, MPS2TZ_MACHINE
)
171 /* Slow 32Khz S32KCLK frequency in Hz */
172 #define S32KCLK_FRQ (32 * 1000)
175 * The MPS3 DDR is 2GiB, but on a 32-bit host QEMU doesn't permit
176 * emulation of that much guest RAM, so artificially make it smaller.
178 #if HOST_LONG_BITS == 32
179 #define MPS3_DDR_SIZE (1 * GiB)
181 #define MPS3_DDR_SIZE (2 * GiB)
184 static const uint32_t an505_oscclk
[] = {
190 static const uint32_t an524_oscclk
[] = {
199 static const RAMInfo an505_raminfo
[] = { {
218 .name
= "ssram-0-alias",
225 /* Use the largest bit of contiguous RAM as our "system memory" */
237 * Note that the addresses and MPC numbering here should match up
238 * with those used in remap_memory(), which can swap the BRAM and QSPI.
240 static const RAMInfo an524_raminfo
[] = { {
249 .size
= 32 * 4 * KiB
,
253 /* We don't model QSPI flash yet; for now expose it as simple ROM */
263 .size
= MPS3_DDR_SIZE
,
271 static const RAMInfo an547_raminfo
[] = { {
286 .size
= 4 * 128 * KiB
,
296 /* We don't model QSPI flash yet; for now expose it as simple ROM */
306 .size
= MPS3_DDR_SIZE
,
314 static const RAMInfo
*find_raminfo_for_mpc(MPS2TZMachineState
*mms
, int mpc
)
316 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_GET_CLASS(mms
);
318 const RAMInfo
*found
= NULL
;
320 for (p
= mmc
->raminfo
; p
->name
; p
++) {
321 if (p
->mpc
== mpc
&& !(p
->flags
& IS_ALIAS
)) {
322 /* There should only be one entry in the array for this MPC */
327 /* if raminfo array doesn't have an entry for each MPC this is a bug */
332 static MemoryRegion
*mr_for_raminfo(MPS2TZMachineState
*mms
,
333 const RAMInfo
*raminfo
)
335 /* Return an initialized MemoryRegion for the RAMInfo. */
338 if (raminfo
->mrindex
< 0) {
339 /* Means this RAMInfo is for QEMU's "system memory" */
340 MachineState
*machine
= MACHINE(mms
);
341 assert(!(raminfo
->flags
& IS_ROM
));
345 assert(raminfo
->mrindex
< MPS2TZ_RAM_MAX
);
346 ram
= &mms
->ram
[raminfo
->mrindex
];
348 memory_region_init_ram(ram
, NULL
, raminfo
->name
,
349 raminfo
->size
, &error_fatal
);
350 if (raminfo
->flags
& IS_ROM
) {
351 memory_region_set_readonly(ram
, true);
356 /* Create an alias of an entire original MemoryRegion @orig
357 * located at @base in the memory map.
359 static void make_ram_alias(MemoryRegion
*mr
, const char *name
,
360 MemoryRegion
*orig
, hwaddr base
)
362 memory_region_init_alias(mr
, NULL
, name
, orig
, 0,
363 memory_region_size(orig
));
364 memory_region_add_subregion(get_system_memory(), base
, mr
);
367 static qemu_irq
get_sse_irq_in(MPS2TZMachineState
*mms
, int irqno
)
370 * Return a qemu_irq which will signal IRQ n to all CPUs in the
371 * SSE. The irqno should be as the CPU sees it, so the first
372 * external-to-the-SSE interrupt is 32.
374 MachineClass
*mc
= MACHINE_GET_CLASS(mms
);
375 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_GET_CLASS(mms
);
377 assert(irqno
>= 32 && irqno
< (mmc
->numirq
+ 32));
380 * Convert from "CPU irq number" (as listed in the FPGA image
381 * documentation) to the SSE external-interrupt number.
385 if (mc
->max_cpus
> 1) {
386 return qdev_get_gpio_in(DEVICE(&mms
->cpu_irq_splitter
[irqno
]), 0);
388 return qdev_get_gpio_in_named(DEVICE(&mms
->iotkit
), "EXP_IRQ", irqno
);
392 /* Most of the devices in the AN505 FPGA image sit behind
393 * Peripheral Protection Controllers. These data structures
394 * define the layout of which devices sit behind which PPCs.
395 * The devfn for each port is a function which creates, configures
396 * and initializes the device, returning the MemoryRegion which
397 * needs to be plugged into the downstream end of the PPC port.
399 typedef MemoryRegion
*MakeDevFn(MPS2TZMachineState
*mms
, void *opaque
,
400 const char *name
, hwaddr size
,
403 typedef struct PPCPortInfo
{
409 int irqs
[3]; /* currently no device needs more IRQ lines than this */
412 typedef struct PPCInfo
{
414 PPCPortInfo ports
[TZ_NUM_PORTS
];
417 static MemoryRegion
*make_unimp_dev(MPS2TZMachineState
*mms
,
419 const char *name
, hwaddr size
,
422 /* Initialize, configure and realize a TYPE_UNIMPLEMENTED_DEVICE,
423 * and return a pointer to its MemoryRegion.
425 UnimplementedDeviceState
*uds
= opaque
;
427 object_initialize_child(OBJECT(mms
), name
, uds
, TYPE_UNIMPLEMENTED_DEVICE
);
428 qdev_prop_set_string(DEVICE(uds
), "name", name
);
429 qdev_prop_set_uint64(DEVICE(uds
), "size", size
);
430 sysbus_realize(SYS_BUS_DEVICE(uds
), &error_fatal
);
431 return sysbus_mmio_get_region(SYS_BUS_DEVICE(uds
), 0);
434 static MemoryRegion
*make_uart(MPS2TZMachineState
*mms
, void *opaque
,
435 const char *name
, hwaddr size
,
438 /* The irq[] array is tx, rx, combined, in that order */
439 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_GET_CLASS(mms
);
440 CMSDKAPBUART
*uart
= opaque
;
441 int i
= uart
- &mms
->uart
[0];
443 DeviceState
*orgate_dev
= DEVICE(&mms
->uart_irq_orgate
);
445 object_initialize_child(OBJECT(mms
), name
, uart
, TYPE_CMSDK_APB_UART
);
446 qdev_prop_set_chr(DEVICE(uart
), "chardev", serial_hd(i
));
447 qdev_prop_set_uint32(DEVICE(uart
), "pclk-frq", mmc
->apb_periph_frq
);
448 sysbus_realize(SYS_BUS_DEVICE(uart
), &error_fatal
);
449 s
= SYS_BUS_DEVICE(uart
);
450 sysbus_connect_irq(s
, 0, get_sse_irq_in(mms
, irqs
[0]));
451 sysbus_connect_irq(s
, 1, get_sse_irq_in(mms
, irqs
[1]));
452 sysbus_connect_irq(s
, 2, qdev_get_gpio_in(orgate_dev
, i
* 2));
453 sysbus_connect_irq(s
, 3, qdev_get_gpio_in(orgate_dev
, i
* 2 + 1));
454 sysbus_connect_irq(s
, 4, get_sse_irq_in(mms
, irqs
[2]));
455 return sysbus_mmio_get_region(SYS_BUS_DEVICE(uart
), 0);
458 static MemoryRegion
*make_scc(MPS2TZMachineState
*mms
, void *opaque
,
459 const char *name
, hwaddr size
,
462 MPS2SCC
*scc
= opaque
;
464 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_GET_CLASS(mms
);
467 object_initialize_child(OBJECT(mms
), "scc", scc
, TYPE_MPS2_SCC
);
468 sccdev
= DEVICE(scc
);
469 qdev_prop_set_uint32(sccdev
, "scc-cfg0", mms
->remap
? 1 : 0);
470 qdev_prop_set_uint32(sccdev
, "scc-cfg4", 0x2);
471 qdev_prop_set_uint32(sccdev
, "scc-aid", 0x00200008);
472 qdev_prop_set_uint32(sccdev
, "scc-id", mmc
->scc_id
);
473 qdev_prop_set_uint32(sccdev
, "len-oscclk", mmc
->len_oscclk
);
474 for (i
= 0; i
< mmc
->len_oscclk
; i
++) {
475 g_autofree
char *propname
= g_strdup_printf("oscclk[%u]", i
);
476 qdev_prop_set_uint32(sccdev
, propname
, mmc
->oscclk
[i
]);
478 sysbus_realize(SYS_BUS_DEVICE(scc
), &error_fatal
);
479 return sysbus_mmio_get_region(SYS_BUS_DEVICE(sccdev
), 0);
482 static MemoryRegion
*make_fpgaio(MPS2TZMachineState
*mms
, void *opaque
,
483 const char *name
, hwaddr size
,
486 MPS2FPGAIO
*fpgaio
= opaque
;
487 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_GET_CLASS(mms
);
489 object_initialize_child(OBJECT(mms
), "fpgaio", fpgaio
, TYPE_MPS2_FPGAIO
);
490 qdev_prop_set_uint32(DEVICE(fpgaio
), "num-leds", mmc
->fpgaio_num_leds
);
491 qdev_prop_set_bit(DEVICE(fpgaio
), "has-switches", mmc
->fpgaio_has_switches
);
492 qdev_prop_set_bit(DEVICE(fpgaio
), "has-dbgctrl", mmc
->fpgaio_has_dbgctrl
);
493 sysbus_realize(SYS_BUS_DEVICE(fpgaio
), &error_fatal
);
494 return sysbus_mmio_get_region(SYS_BUS_DEVICE(fpgaio
), 0);
497 static MemoryRegion
*make_eth_dev(MPS2TZMachineState
*mms
, void *opaque
,
498 const char *name
, hwaddr size
,
502 NICInfo
*nd
= &nd_table
[0];
504 /* In hardware this is a LAN9220; the LAN9118 is software compatible
505 * except that it doesn't support the checksum-offload feature.
507 qemu_check_nic_model(nd
, "lan9118");
508 mms
->lan9118
= qdev_new(TYPE_LAN9118
);
509 qdev_set_nic_properties(mms
->lan9118
, nd
);
511 s
= SYS_BUS_DEVICE(mms
->lan9118
);
512 sysbus_realize_and_unref(s
, &error_fatal
);
513 sysbus_connect_irq(s
, 0, get_sse_irq_in(mms
, irqs
[0]));
514 return sysbus_mmio_get_region(s
, 0);
517 static MemoryRegion
*make_eth_usb(MPS2TZMachineState
*mms
, void *opaque
,
518 const char *name
, hwaddr size
,
522 * The AN524 makes the ethernet and USB share a PPC port.
523 * irqs[] is the ethernet IRQ.
526 NICInfo
*nd
= &nd_table
[0];
528 memory_region_init(&mms
->eth_usb_container
, OBJECT(mms
),
529 "mps2-tz-eth-usb-container", 0x200000);
532 * In hardware this is a LAN9220; the LAN9118 is software compatible
533 * except that it doesn't support the checksum-offload feature.
535 qemu_check_nic_model(nd
, "lan9118");
536 mms
->lan9118
= qdev_new(TYPE_LAN9118
);
537 qdev_set_nic_properties(mms
->lan9118
, nd
);
539 s
= SYS_BUS_DEVICE(mms
->lan9118
);
540 sysbus_realize_and_unref(s
, &error_fatal
);
541 sysbus_connect_irq(s
, 0, get_sse_irq_in(mms
, irqs
[0]));
543 memory_region_add_subregion(&mms
->eth_usb_container
,
544 0, sysbus_mmio_get_region(s
, 0));
546 /* The USB OTG controller is an ISP1763; we don't have a model of it. */
547 object_initialize_child(OBJECT(mms
), "usb-otg",
548 &mms
->usb
, TYPE_UNIMPLEMENTED_DEVICE
);
549 qdev_prop_set_string(DEVICE(&mms
->usb
), "name", "usb-otg");
550 qdev_prop_set_uint64(DEVICE(&mms
->usb
), "size", 0x100000);
551 s
= SYS_BUS_DEVICE(&mms
->usb
);
552 sysbus_realize(s
, &error_fatal
);
554 memory_region_add_subregion(&mms
->eth_usb_container
,
555 0x100000, sysbus_mmio_get_region(s
, 0));
557 return &mms
->eth_usb_container
;
560 static MemoryRegion
*make_mpc(MPS2TZMachineState
*mms
, void *opaque
,
561 const char *name
, hwaddr size
,
565 int i
= mpc
- &mms
->mpc
[0];
566 MemoryRegion
*upstream
;
567 const RAMInfo
*raminfo
= find_raminfo_for_mpc(mms
, i
);
568 MemoryRegion
*ram
= mr_for_raminfo(mms
, raminfo
);
570 object_initialize_child(OBJECT(mms
), name
, mpc
, TYPE_TZ_MPC
);
571 object_property_set_link(OBJECT(mpc
), "downstream", OBJECT(ram
),
573 sysbus_realize(SYS_BUS_DEVICE(mpc
), &error_fatal
);
574 /* Map the upstream end of the MPC into system memory */
575 upstream
= sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc
), 1);
576 memory_region_add_subregion(get_system_memory(), raminfo
->base
, upstream
);
577 /* and connect its interrupt to the IoTKit */
578 qdev_connect_gpio_out_named(DEVICE(mpc
), "irq", 0,
579 qdev_get_gpio_in_named(DEVICE(&mms
->iotkit
),
580 "mpcexp_status", i
));
582 /* Return the register interface MR for our caller to map behind the PPC */
583 return sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc
), 0);
586 static hwaddr
boot_mem_base(MPS2TZMachineState
*mms
)
589 * Return the canonical address of the block which will be mapped
590 * at address 0x0 (i.e. where the vector table is).
591 * This is usually 0, but if the AN524 alternate memory map is
592 * enabled it will be the base address of the QSPI block.
594 return mms
->remap
? 0x28000000 : 0;
597 static void remap_memory(MPS2TZMachineState
*mms
, int map
)
600 * Remap the memory for the AN524. 'map' is the value of
601 * SCC CFG_REG0 bit 0, i.e. 0 for the default map and 1
602 * for the "option 1" mapping where QSPI is at address 0.
604 * Effectively we need to swap around the "upstream" ends of
607 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_GET_CLASS(mms
);
610 if (mmc
->fpga_type
!= FPGA_AN524
) {
614 memory_region_transaction_begin();
615 for (i
= 0; i
< 2; i
++) {
616 TZMPC
*mpc
= &mms
->mpc
[i
];
617 MemoryRegion
*upstream
= sysbus_mmio_get_region(SYS_BUS_DEVICE(mpc
), 1);
618 hwaddr addr
= (i
^ map
) ? 0x28000000 : 0;
620 memory_region_set_address(upstream
, addr
);
622 memory_region_transaction_commit();
625 static void remap_irq_fn(void *opaque
, int n
, int level
)
627 MPS2TZMachineState
*mms
= opaque
;
629 remap_memory(mms
, level
);
632 static MemoryRegion
*make_dma(MPS2TZMachineState
*mms
, void *opaque
,
633 const char *name
, hwaddr size
,
636 /* The irq[] array is DMACINTR, DMACINTERR, DMACINTTC, in that order */
637 PL080State
*dma
= opaque
;
638 int i
= dma
- &mms
->dma
[0];
640 char *mscname
= g_strdup_printf("%s-msc", name
);
641 TZMSC
*msc
= &mms
->msc
[i
];
642 DeviceState
*iotkitdev
= DEVICE(&mms
->iotkit
);
643 MemoryRegion
*msc_upstream
;
644 MemoryRegion
*msc_downstream
;
647 * Each DMA device is a PL081 whose transaction master interface
648 * is guarded by a Master Security Controller. The downstream end of
649 * the MSC connects to the IoTKit AHB Slave Expansion port, so the
650 * DMA devices can see all devices and memory that the CPU does.
652 object_initialize_child(OBJECT(mms
), mscname
, msc
, TYPE_TZ_MSC
);
653 msc_downstream
= sysbus_mmio_get_region(SYS_BUS_DEVICE(&mms
->iotkit
), 0);
654 object_property_set_link(OBJECT(msc
), "downstream",
655 OBJECT(msc_downstream
), &error_fatal
);
656 object_property_set_link(OBJECT(msc
), "idau", OBJECT(mms
), &error_fatal
);
657 sysbus_realize(SYS_BUS_DEVICE(msc
), &error_fatal
);
659 qdev_connect_gpio_out_named(DEVICE(msc
), "irq", 0,
660 qdev_get_gpio_in_named(iotkitdev
,
661 "mscexp_status", i
));
662 qdev_connect_gpio_out_named(iotkitdev
, "mscexp_clear", i
,
663 qdev_get_gpio_in_named(DEVICE(msc
),
665 qdev_connect_gpio_out_named(iotkitdev
, "mscexp_ns", i
,
666 qdev_get_gpio_in_named(DEVICE(msc
),
668 qdev_connect_gpio_out(DEVICE(&mms
->sec_resp_splitter
),
669 ARRAY_SIZE(mms
->ppc
) + i
,
670 qdev_get_gpio_in_named(DEVICE(msc
),
672 msc_upstream
= sysbus_mmio_get_region(SYS_BUS_DEVICE(msc
), 0);
674 object_initialize_child(OBJECT(mms
), name
, dma
, TYPE_PL081
);
675 object_property_set_link(OBJECT(dma
), "downstream", OBJECT(msc_upstream
),
677 sysbus_realize(SYS_BUS_DEVICE(dma
), &error_fatal
);
679 s
= SYS_BUS_DEVICE(dma
);
680 /* Wire up DMACINTR, DMACINTERR, DMACINTTC */
681 sysbus_connect_irq(s
, 0, get_sse_irq_in(mms
, irqs
[0]));
682 sysbus_connect_irq(s
, 1, get_sse_irq_in(mms
, irqs
[1]));
683 sysbus_connect_irq(s
, 2, get_sse_irq_in(mms
, irqs
[2]));
686 return sysbus_mmio_get_region(s
, 0);
689 static MemoryRegion
*make_spi(MPS2TZMachineState
*mms
, void *opaque
,
690 const char *name
, hwaddr size
,
694 * The AN505 has five PL022 SPI controllers.
695 * One of these should have the LCD controller behind it; the others
696 * are connected only to the FPGA's "general purpose SPI connector"
697 * or "shield" expansion connectors.
698 * Note that if we do implement devices behind SPI, the chip select
699 * lines are set via the "MISC" register in the MPS2 FPGAIO device.
701 PL022State
*spi
= opaque
;
704 object_initialize_child(OBJECT(mms
), name
, spi
, TYPE_PL022
);
705 sysbus_realize(SYS_BUS_DEVICE(spi
), &error_fatal
);
706 s
= SYS_BUS_DEVICE(spi
);
707 sysbus_connect_irq(s
, 0, get_sse_irq_in(mms
, irqs
[0]));
708 return sysbus_mmio_get_region(s
, 0);
711 static MemoryRegion
*make_i2c(MPS2TZMachineState
*mms
, void *opaque
,
712 const char *name
, hwaddr size
,
715 ArmSbconI2CState
*i2c
= opaque
;
718 object_initialize_child(OBJECT(mms
), name
, i2c
, TYPE_ARM_SBCON_I2C
);
719 s
= SYS_BUS_DEVICE(i2c
);
720 sysbus_realize(s
, &error_fatal
);
721 return sysbus_mmio_get_region(s
, 0);
724 static MemoryRegion
*make_rtc(MPS2TZMachineState
*mms
, void *opaque
,
725 const char *name
, hwaddr size
,
728 PL031State
*pl031
= opaque
;
731 object_initialize_child(OBJECT(mms
), name
, pl031
, TYPE_PL031
);
732 s
= SYS_BUS_DEVICE(pl031
);
733 sysbus_realize(s
, &error_fatal
);
735 * The board docs don't give an IRQ number for the PL031, so
736 * presumably it is not connected.
738 return sysbus_mmio_get_region(s
, 0);
741 static void create_non_mpc_ram(MPS2TZMachineState
*mms
)
744 * Handle the RAMs which are either not behind MPCs or which are
745 * aliases to another MPC.
748 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_GET_CLASS(mms
);
750 for (p
= mmc
->raminfo
; p
->name
; p
++) {
751 if (p
->flags
& IS_ALIAS
) {
752 SysBusDevice
*mpc_sbd
= SYS_BUS_DEVICE(&mms
->mpc
[p
->mpc
]);
753 MemoryRegion
*upstream
= sysbus_mmio_get_region(mpc_sbd
, 1);
754 make_ram_alias(&mms
->ram
[p
->mrindex
], p
->name
, upstream
, p
->base
);
755 } else if (p
->mpc
== -1) {
756 /* RAM not behind an MPC */
757 MemoryRegion
*mr
= mr_for_raminfo(mms
, p
);
758 memory_region_add_subregion(get_system_memory(), p
->base
, mr
);
763 static uint32_t boot_ram_size(MPS2TZMachineState
*mms
)
765 /* Return the size of the RAM block at guest address zero */
767 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_GET_CLASS(mms
);
769 for (p
= mmc
->raminfo
; p
->name
; p
++) {
770 if (p
->base
== boot_mem_base(mms
)) {
774 g_assert_not_reached();
777 static void mps2tz_common_init(MachineState
*machine
)
779 MPS2TZMachineState
*mms
= MPS2TZ_MACHINE(machine
);
780 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_GET_CLASS(mms
);
781 MachineClass
*mc
= MACHINE_GET_CLASS(machine
);
782 MemoryRegion
*system_memory
= get_system_memory();
783 DeviceState
*iotkitdev
;
784 DeviceState
*dev_splitter
;
789 if (strcmp(machine
->cpu_type
, mc
->default_cpu_type
) != 0) {
790 error_report("This board can only be used with CPU %s",
791 mc
->default_cpu_type
);
795 if (machine
->ram_size
!= mc
->default_ram_size
) {
796 char *sz
= size_to_str(mc
->default_ram_size
);
797 error_report("Invalid RAM size, should be %s", sz
);
802 /* These clocks don't need migration because they are fixed-frequency */
803 mms
->sysclk
= clock_new(OBJECT(machine
), "SYSCLK");
804 clock_set_hz(mms
->sysclk
, mmc
->sysclk_frq
);
805 mms
->s32kclk
= clock_new(OBJECT(machine
), "S32KCLK");
806 clock_set_hz(mms
->s32kclk
, S32KCLK_FRQ
);
808 object_initialize_child(OBJECT(machine
), TYPE_IOTKIT
, &mms
->iotkit
,
810 iotkitdev
= DEVICE(&mms
->iotkit
);
811 object_property_set_link(OBJECT(&mms
->iotkit
), "memory",
812 OBJECT(system_memory
), &error_abort
);
813 qdev_prop_set_uint32(iotkitdev
, "EXP_NUMIRQ", mmc
->numirq
);
814 qdev_prop_set_uint32(iotkitdev
, "init-svtor", mmc
->init_svtor
);
815 qdev_connect_clock_in(iotkitdev
, "MAINCLK", mms
->sysclk
);
816 qdev_connect_clock_in(iotkitdev
, "S32KCLK", mms
->s32kclk
);
817 sysbus_realize(SYS_BUS_DEVICE(&mms
->iotkit
), &error_fatal
);
820 * If this board has more than one CPU, then we need to create splitters
821 * to feed the IRQ inputs for each CPU in the SSE from each device in the
822 * board. If there is only one CPU, we can just wire the device IRQ
823 * directly to the SSE's IRQ input.
825 assert(mmc
->numirq
<= MPS2TZ_NUMIRQ_MAX
);
826 if (mc
->max_cpus
> 1) {
827 for (i
= 0; i
< mmc
->numirq
; i
++) {
828 char *name
= g_strdup_printf("mps2-irq-splitter%d", i
);
829 SplitIRQ
*splitter
= &mms
->cpu_irq_splitter
[i
];
831 object_initialize_child_with_props(OBJECT(machine
), name
,
832 splitter
, sizeof(*splitter
),
833 TYPE_SPLIT_IRQ
, &error_fatal
,
837 object_property_set_int(OBJECT(splitter
), "num-lines", 2,
839 qdev_realize(DEVICE(splitter
), NULL
, &error_fatal
);
840 qdev_connect_gpio_out(DEVICE(splitter
), 0,
841 qdev_get_gpio_in_named(DEVICE(&mms
->iotkit
),
843 qdev_connect_gpio_out(DEVICE(splitter
), 1,
844 qdev_get_gpio_in_named(DEVICE(&mms
->iotkit
),
849 /* The sec_resp_cfg output from the IoTKit must be split into multiple
850 * lines, one for each of the PPCs we create here, plus one per MSC.
852 object_initialize_child(OBJECT(machine
), "sec-resp-splitter",
853 &mms
->sec_resp_splitter
, TYPE_SPLIT_IRQ
);
854 object_property_set_int(OBJECT(&mms
->sec_resp_splitter
), "num-lines",
855 ARRAY_SIZE(mms
->ppc
) + ARRAY_SIZE(mms
->msc
),
857 qdev_realize(DEVICE(&mms
->sec_resp_splitter
), NULL
, &error_fatal
);
858 dev_splitter
= DEVICE(&mms
->sec_resp_splitter
);
859 qdev_connect_gpio_out_named(iotkitdev
, "sec_resp_cfg", 0,
860 qdev_get_gpio_in(dev_splitter
, 0));
863 * The IoTKit sets up much of the memory layout, including
864 * the aliases between secure and non-secure regions in the
865 * address space, and also most of the devices in the system.
866 * The FPGA itself contains various RAMs and some additional devices.
867 * The FPGA images have an odd combination of different RAMs,
868 * because in hardware they are different implementations and
869 * connected to different buses, giving varying performance/size
870 * tradeoffs. For QEMU they're all just RAM, though. We arbitrarily
871 * call the largest lump our "system memory".
875 * The overflow IRQs for all UARTs are ORed together.
876 * Tx, Rx and "combined" IRQs are sent to the NVIC separately.
877 * Create the OR gate for this: it has one input for the TX overflow
878 * and one for the RX overflow for each UART we might have.
879 * (If the board has fewer than the maximum possible number of UARTs
880 * those inputs are never wired up and are treated as always-zero.)
882 object_initialize_child(OBJECT(mms
), "uart-irq-orgate",
883 &mms
->uart_irq_orgate
, TYPE_OR_IRQ
);
884 object_property_set_int(OBJECT(&mms
->uart_irq_orgate
), "num-lines",
885 2 * ARRAY_SIZE(mms
->uart
),
887 qdev_realize(DEVICE(&mms
->uart_irq_orgate
), NULL
, &error_fatal
);
888 qdev_connect_gpio_out(DEVICE(&mms
->uart_irq_orgate
), 0,
889 get_sse_irq_in(mms
, mmc
->uart_overflow_irq
));
891 /* Most of the devices in the FPGA are behind Peripheral Protection
892 * Controllers. The required order for initializing things is:
893 * + initialize the PPC
894 * + initialize, configure and realize downstream devices
895 * + connect downstream device MemoryRegions to the PPC
897 * + map the PPC's MemoryRegions to the places in the address map
898 * where the downstream devices should appear
899 * + wire up the PPC's control lines to the IoTKit object
902 const PPCInfo an505_ppcs
[] = { {
903 .name
= "apb_ppcexp0",
905 { "ssram-0-mpc", make_mpc
, &mms
->mpc
[0], 0x58007000, 0x1000 },
906 { "ssram-1-mpc", make_mpc
, &mms
->mpc
[1], 0x58008000, 0x1000 },
907 { "ssram-2-mpc", make_mpc
, &mms
->mpc
[2], 0x58009000, 0x1000 },
910 .name
= "apb_ppcexp1",
912 { "spi0", make_spi
, &mms
->spi
[0], 0x40205000, 0x1000, { 51 } },
913 { "spi1", make_spi
, &mms
->spi
[1], 0x40206000, 0x1000, { 52 } },
914 { "spi2", make_spi
, &mms
->spi
[2], 0x40209000, 0x1000, { 53 } },
915 { "spi3", make_spi
, &mms
->spi
[3], 0x4020a000, 0x1000, { 54 } },
916 { "spi4", make_spi
, &mms
->spi
[4], 0x4020b000, 0x1000, { 55 } },
917 { "uart0", make_uart
, &mms
->uart
[0], 0x40200000, 0x1000, { 32, 33, 42 } },
918 { "uart1", make_uart
, &mms
->uart
[1], 0x40201000, 0x1000, { 34, 35, 43 } },
919 { "uart2", make_uart
, &mms
->uart
[2], 0x40202000, 0x1000, { 36, 37, 44 } },
920 { "uart3", make_uart
, &mms
->uart
[3], 0x40203000, 0x1000, { 38, 39, 45 } },
921 { "uart4", make_uart
, &mms
->uart
[4], 0x40204000, 0x1000, { 40, 41, 46 } },
922 { "i2c0", make_i2c
, &mms
->i2c
[0], 0x40207000, 0x1000 },
923 { "i2c1", make_i2c
, &mms
->i2c
[1], 0x40208000, 0x1000 },
924 { "i2c2", make_i2c
, &mms
->i2c
[2], 0x4020c000, 0x1000 },
925 { "i2c3", make_i2c
, &mms
->i2c
[3], 0x4020d000, 0x1000 },
928 .name
= "apb_ppcexp2",
930 { "scc", make_scc
, &mms
->scc
, 0x40300000, 0x1000 },
931 { "i2s-audio", make_unimp_dev
, &mms
->i2s_audio
,
932 0x40301000, 0x1000 },
933 { "fpgaio", make_fpgaio
, &mms
->fpgaio
, 0x40302000, 0x1000 },
936 .name
= "ahb_ppcexp0",
938 { "gfx", make_unimp_dev
, &mms
->gfx
, 0x41000000, 0x140000 },
939 { "gpio0", make_unimp_dev
, &mms
->gpio
[0], 0x40100000, 0x1000 },
940 { "gpio1", make_unimp_dev
, &mms
->gpio
[1], 0x40101000, 0x1000 },
941 { "gpio2", make_unimp_dev
, &mms
->gpio
[2], 0x40102000, 0x1000 },
942 { "gpio3", make_unimp_dev
, &mms
->gpio
[3], 0x40103000, 0x1000 },
943 { "eth", make_eth_dev
, NULL
, 0x42000000, 0x100000, { 48 } },
946 .name
= "ahb_ppcexp1",
948 { "dma0", make_dma
, &mms
->dma
[0], 0x40110000, 0x1000, { 58, 56, 57 } },
949 { "dma1", make_dma
, &mms
->dma
[1], 0x40111000, 0x1000, { 61, 59, 60 } },
950 { "dma2", make_dma
, &mms
->dma
[2], 0x40112000, 0x1000, { 64, 62, 63 } },
951 { "dma3", make_dma
, &mms
->dma
[3], 0x40113000, 0x1000, { 67, 65, 66 } },
956 const PPCInfo an524_ppcs
[] = { {
957 .name
= "apb_ppcexp0",
959 { "bram-mpc", make_mpc
, &mms
->mpc
[0], 0x58007000, 0x1000 },
960 { "qspi-mpc", make_mpc
, &mms
->mpc
[1], 0x58008000, 0x1000 },
961 { "ddr-mpc", make_mpc
, &mms
->mpc
[2], 0x58009000, 0x1000 },
964 .name
= "apb_ppcexp1",
966 { "i2c0", make_i2c
, &mms
->i2c
[0], 0x41200000, 0x1000 },
967 { "i2c1", make_i2c
, &mms
->i2c
[1], 0x41201000, 0x1000 },
968 { "spi0", make_spi
, &mms
->spi
[0], 0x41202000, 0x1000, { 52 } },
969 { "spi1", make_spi
, &mms
->spi
[1], 0x41203000, 0x1000, { 53 } },
970 { "spi2", make_spi
, &mms
->spi
[2], 0x41204000, 0x1000, { 54 } },
971 { "i2c2", make_i2c
, &mms
->i2c
[2], 0x41205000, 0x1000 },
972 { "i2c3", make_i2c
, &mms
->i2c
[3], 0x41206000, 0x1000 },
973 { /* port 7 reserved */ },
974 { "i2c4", make_i2c
, &mms
->i2c
[4], 0x41208000, 0x1000 },
977 .name
= "apb_ppcexp2",
979 { "scc", make_scc
, &mms
->scc
, 0x41300000, 0x1000 },
980 { "i2s-audio", make_unimp_dev
, &mms
->i2s_audio
,
981 0x41301000, 0x1000 },
982 { "fpgaio", make_fpgaio
, &mms
->fpgaio
, 0x41302000, 0x1000 },
983 { "uart0", make_uart
, &mms
->uart
[0], 0x41303000, 0x1000, { 32, 33, 42 } },
984 { "uart1", make_uart
, &mms
->uart
[1], 0x41304000, 0x1000, { 34, 35, 43 } },
985 { "uart2", make_uart
, &mms
->uart
[2], 0x41305000, 0x1000, { 36, 37, 44 } },
986 { "uart3", make_uart
, &mms
->uart
[3], 0x41306000, 0x1000, { 38, 39, 45 } },
987 { "uart4", make_uart
, &mms
->uart
[4], 0x41307000, 0x1000, { 40, 41, 46 } },
988 { "uart5", make_uart
, &mms
->uart
[5], 0x41308000, 0x1000, { 124, 125, 126 } },
990 { /* port 9 reserved */ },
991 { "clcd", make_unimp_dev
, &mms
->cldc
, 0x4130a000, 0x1000 },
992 { "rtc", make_rtc
, &mms
->rtc
, 0x4130b000, 0x1000 },
995 .name
= "ahb_ppcexp0",
997 { "gpio0", make_unimp_dev
, &mms
->gpio
[0], 0x41100000, 0x1000 },
998 { "gpio1", make_unimp_dev
, &mms
->gpio
[1], 0x41101000, 0x1000 },
999 { "gpio2", make_unimp_dev
, &mms
->gpio
[2], 0x41102000, 0x1000 },
1000 { "gpio3", make_unimp_dev
, &mms
->gpio
[3], 0x41103000, 0x1000 },
1001 { "eth-usb", make_eth_usb
, NULL
, 0x41400000, 0x200000, { 48 } },
1006 const PPCInfo an547_ppcs
[] = { {
1007 .name
= "apb_ppcexp0",
1009 { "ssram-mpc", make_mpc
, &mms
->mpc
[0], 0x57000000, 0x1000 },
1010 { "qspi-mpc", make_mpc
, &mms
->mpc
[1], 0x57001000, 0x1000 },
1011 { "ddr-mpc", make_mpc
, &mms
->mpc
[2], 0x57002000, 0x1000 },
1014 .name
= "apb_ppcexp1",
1016 { "i2c0", make_i2c
, &mms
->i2c
[0], 0x49200000, 0x1000 },
1017 { "i2c1", make_i2c
, &mms
->i2c
[1], 0x49201000, 0x1000 },
1018 { "spi0", make_spi
, &mms
->spi
[0], 0x49202000, 0x1000, { 53 } },
1019 { "spi1", make_spi
, &mms
->spi
[1], 0x49203000, 0x1000, { 54 } },
1020 { "spi2", make_spi
, &mms
->spi
[2], 0x49204000, 0x1000, { 55 } },
1021 { "i2c2", make_i2c
, &mms
->i2c
[2], 0x49205000, 0x1000 },
1022 { "i2c3", make_i2c
, &mms
->i2c
[3], 0x49206000, 0x1000 },
1023 { /* port 7 reserved */ },
1024 { "i2c4", make_i2c
, &mms
->i2c
[4], 0x49208000, 0x1000 },
1027 .name
= "apb_ppcexp2",
1029 { "scc", make_scc
, &mms
->scc
, 0x49300000, 0x1000 },
1030 { "i2s-audio", make_unimp_dev
, &mms
->i2s_audio
, 0x49301000, 0x1000 },
1031 { "fpgaio", make_fpgaio
, &mms
->fpgaio
, 0x49302000, 0x1000 },
1032 { "uart0", make_uart
, &mms
->uart
[0], 0x49303000, 0x1000, { 33, 34, 43 } },
1033 { "uart1", make_uart
, &mms
->uart
[1], 0x49304000, 0x1000, { 35, 36, 44 } },
1034 { "uart2", make_uart
, &mms
->uart
[2], 0x49305000, 0x1000, { 37, 38, 45 } },
1035 { "uart3", make_uart
, &mms
->uart
[3], 0x49306000, 0x1000, { 39, 40, 46 } },
1036 { "uart4", make_uart
, &mms
->uart
[4], 0x49307000, 0x1000, { 41, 42, 47 } },
1037 { "uart5", make_uart
, &mms
->uart
[5], 0x49308000, 0x1000, { 125, 126, 127 } },
1039 { /* port 9 reserved */ },
1040 { "clcd", make_unimp_dev
, &mms
->cldc
, 0x4930a000, 0x1000 },
1041 { "rtc", make_rtc
, &mms
->rtc
, 0x4930b000, 0x1000 },
1044 .name
= "ahb_ppcexp0",
1046 { "gpio0", make_unimp_dev
, &mms
->gpio
[0], 0x41100000, 0x1000 },
1047 { "gpio1", make_unimp_dev
, &mms
->gpio
[1], 0x41101000, 0x1000 },
1048 { "gpio2", make_unimp_dev
, &mms
->gpio
[2], 0x41102000, 0x1000 },
1049 { "gpio3", make_unimp_dev
, &mms
->gpio
[3], 0x41103000, 0x1000 },
1050 { "eth-usb", make_eth_usb
, NULL
, 0x41400000, 0x200000, { 49 } },
1055 switch (mmc
->fpga_type
) {
1059 num_ppcs
= ARRAY_SIZE(an505_ppcs
);
1063 num_ppcs
= ARRAY_SIZE(an524_ppcs
);
1067 num_ppcs
= ARRAY_SIZE(an547_ppcs
);
1070 g_assert_not_reached();
1073 for (i
= 0; i
< num_ppcs
; i
++) {
1074 const PPCInfo
*ppcinfo
= &ppcs
[i
];
1075 TZPPC
*ppc
= &mms
->ppc
[i
];
1076 DeviceState
*ppcdev
;
1080 object_initialize_child(OBJECT(machine
), ppcinfo
->name
, ppc
,
1082 ppcdev
= DEVICE(ppc
);
1084 for (port
= 0; port
< TZ_NUM_PORTS
; port
++) {
1085 const PPCPortInfo
*pinfo
= &ppcinfo
->ports
[port
];
1089 if (!pinfo
->devfn
) {
1093 mr
= pinfo
->devfn(mms
, pinfo
->opaque
, pinfo
->name
, pinfo
->size
,
1095 portname
= g_strdup_printf("port[%d]", port
);
1096 object_property_set_link(OBJECT(ppc
), portname
, OBJECT(mr
),
1101 sysbus_realize(SYS_BUS_DEVICE(ppc
), &error_fatal
);
1103 for (port
= 0; port
< TZ_NUM_PORTS
; port
++) {
1104 const PPCPortInfo
*pinfo
= &ppcinfo
->ports
[port
];
1106 if (!pinfo
->devfn
) {
1109 sysbus_mmio_map(SYS_BUS_DEVICE(ppc
), port
, pinfo
->addr
);
1111 gpioname
= g_strdup_printf("%s_nonsec", ppcinfo
->name
);
1112 qdev_connect_gpio_out_named(iotkitdev
, gpioname
, port
,
1113 qdev_get_gpio_in_named(ppcdev
,
1117 gpioname
= g_strdup_printf("%s_ap", ppcinfo
->name
);
1118 qdev_connect_gpio_out_named(iotkitdev
, gpioname
, port
,
1119 qdev_get_gpio_in_named(ppcdev
,
1124 gpioname
= g_strdup_printf("%s_irq_enable", ppcinfo
->name
);
1125 qdev_connect_gpio_out_named(iotkitdev
, gpioname
, 0,
1126 qdev_get_gpio_in_named(ppcdev
,
1129 gpioname
= g_strdup_printf("%s_irq_clear", ppcinfo
->name
);
1130 qdev_connect_gpio_out_named(iotkitdev
, gpioname
, 0,
1131 qdev_get_gpio_in_named(ppcdev
,
1134 gpioname
= g_strdup_printf("%s_irq_status", ppcinfo
->name
);
1135 qdev_connect_gpio_out_named(ppcdev
, "irq", 0,
1136 qdev_get_gpio_in_named(iotkitdev
,
1140 qdev_connect_gpio_out(dev_splitter
, i
,
1141 qdev_get_gpio_in_named(ppcdev
,
1142 "cfg_sec_resp", 0));
1145 create_unimplemented_device("FPGA NS PC", 0x48007000, 0x1000);
1147 if (mmc
->fpga_type
== FPGA_AN547
) {
1148 create_unimplemented_device("U55 timing adapter 0", 0x48102000, 0x1000);
1149 create_unimplemented_device("U55 timing adapter 1", 0x48103000, 0x1000);
1152 create_non_mpc_ram(mms
);
1154 if (mmc
->fpga_type
== FPGA_AN524
) {
1156 * Connect the line from the SCC so that we can remap when the
1157 * guest updates that register.
1159 mms
->remap_irq
= qemu_allocate_irq(remap_irq_fn
, mms
, 0);
1160 qdev_connect_gpio_out_named(DEVICE(&mms
->scc
), "remap", 0,
1164 armv7m_load_kernel(ARM_CPU(first_cpu
), machine
->kernel_filename
,
1165 boot_ram_size(mms
));
1168 static void mps2_tz_idau_check(IDAUInterface
*ii
, uint32_t address
,
1169 int *iregion
, bool *exempt
, bool *ns
, bool *nsc
)
1172 * The MPS2 TZ FPGA images have IDAUs in them which are connected to
1173 * the Master Security Controllers. Thes have the same logic as
1174 * is used by the IoTKit for the IDAU connected to the CPU, except
1175 * that MSCs don't care about the NSC attribute.
1177 int region
= extract32(address
, 28, 4);
1179 *ns
= !(region
& 1);
1181 /* 0xe0000000..0xe00fffff and 0xf0000000..0xf00fffff are exempt */
1182 *exempt
= (address
& 0xeff00000) == 0xe0000000;
1186 static char *mps2_get_remap(Object
*obj
, Error
**errp
)
1188 MPS2TZMachineState
*mms
= MPS2TZ_MACHINE(obj
);
1189 const char *val
= mms
->remap
? "QSPI" : "BRAM";
1190 return g_strdup(val
);
1193 static void mps2_set_remap(Object
*obj
, const char *value
, Error
**errp
)
1195 MPS2TZMachineState
*mms
= MPS2TZ_MACHINE(obj
);
1197 if (!strcmp(value
, "BRAM")) {
1199 } else if (!strcmp(value
, "QSPI")) {
1202 error_setg(errp
, "Invalid remap value");
1203 error_append_hint(errp
, "Valid values are BRAM and QSPI.\n");
1207 static void mps2_machine_reset(MachineState
*machine
)
1209 MPS2TZMachineState
*mms
= MPS2TZ_MACHINE(machine
);
1212 * Set the initial memory mapping before triggering the reset of
1213 * the rest of the system, so that the guest image loader and CPU
1214 * reset see the correct mapping.
1216 remap_memory(mms
, mms
->remap
);
1217 qemu_devices_reset();
1220 static void mps2tz_class_init(ObjectClass
*oc
, void *data
)
1222 MachineClass
*mc
= MACHINE_CLASS(oc
);
1223 IDAUInterfaceClass
*iic
= IDAU_INTERFACE_CLASS(oc
);
1225 mc
->init
= mps2tz_common_init
;
1226 mc
->reset
= mps2_machine_reset
;
1227 iic
->check
= mps2_tz_idau_check
;
1230 static void mps2tz_set_default_ram_info(MPS2TZMachineClass
*mmc
)
1233 * Set mc->default_ram_size and default_ram_id from the
1234 * information in mmc->raminfo.
1236 MachineClass
*mc
= MACHINE_CLASS(mmc
);
1239 for (p
= mmc
->raminfo
; p
->name
; p
++) {
1240 if (p
->mrindex
< 0) {
1241 /* Found the entry for "system memory" */
1242 mc
->default_ram_size
= p
->size
;
1243 mc
->default_ram_id
= p
->name
;
1247 g_assert_not_reached();
1250 static void mps2tz_an505_class_init(ObjectClass
*oc
, void *data
)
1252 MachineClass
*mc
= MACHINE_CLASS(oc
);
1253 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_CLASS(oc
);
1255 mc
->desc
= "ARM MPS2 with AN505 FPGA image for Cortex-M33";
1256 mc
->default_cpus
= 1;
1257 mc
->min_cpus
= mc
->default_cpus
;
1258 mc
->max_cpus
= mc
->default_cpus
;
1259 mmc
->fpga_type
= FPGA_AN505
;
1260 mc
->default_cpu_type
= ARM_CPU_TYPE_NAME("cortex-m33");
1261 mmc
->scc_id
= 0x41045050;
1262 mmc
->sysclk_frq
= 20 * 1000 * 1000; /* 20MHz */
1263 mmc
->apb_periph_frq
= mmc
->sysclk_frq
;
1264 mmc
->oscclk
= an505_oscclk
;
1265 mmc
->len_oscclk
= ARRAY_SIZE(an505_oscclk
);
1266 mmc
->fpgaio_num_leds
= 2;
1267 mmc
->fpgaio_has_switches
= false;
1268 mmc
->fpgaio_has_dbgctrl
= false;
1270 mmc
->uart_overflow_irq
= 47;
1271 mmc
->init_svtor
= 0x10000000;
1272 mmc
->raminfo
= an505_raminfo
;
1273 mmc
->armsse_type
= TYPE_IOTKIT
;
1274 mps2tz_set_default_ram_info(mmc
);
1277 static void mps2tz_an521_class_init(ObjectClass
*oc
, void *data
)
1279 MachineClass
*mc
= MACHINE_CLASS(oc
);
1280 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_CLASS(oc
);
1282 mc
->desc
= "ARM MPS2 with AN521 FPGA image for dual Cortex-M33";
1283 mc
->default_cpus
= 2;
1284 mc
->min_cpus
= mc
->default_cpus
;
1285 mc
->max_cpus
= mc
->default_cpus
;
1286 mmc
->fpga_type
= FPGA_AN521
;
1287 mc
->default_cpu_type
= ARM_CPU_TYPE_NAME("cortex-m33");
1288 mmc
->scc_id
= 0x41045210;
1289 mmc
->sysclk_frq
= 20 * 1000 * 1000; /* 20MHz */
1290 mmc
->apb_periph_frq
= mmc
->sysclk_frq
;
1291 mmc
->oscclk
= an505_oscclk
; /* AN521 is the same as AN505 here */
1292 mmc
->len_oscclk
= ARRAY_SIZE(an505_oscclk
);
1293 mmc
->fpgaio_num_leds
= 2;
1294 mmc
->fpgaio_has_switches
= false;
1295 mmc
->fpgaio_has_dbgctrl
= false;
1297 mmc
->uart_overflow_irq
= 47;
1298 mmc
->init_svtor
= 0x10000000;
1299 mmc
->raminfo
= an505_raminfo
; /* AN521 is the same as AN505 here */
1300 mmc
->armsse_type
= TYPE_SSE200
;
1301 mps2tz_set_default_ram_info(mmc
);
1304 static void mps3tz_an524_class_init(ObjectClass
*oc
, void *data
)
1306 MachineClass
*mc
= MACHINE_CLASS(oc
);
1307 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_CLASS(oc
);
1309 mc
->desc
= "ARM MPS3 with AN524 FPGA image for dual Cortex-M33";
1310 mc
->default_cpus
= 2;
1311 mc
->min_cpus
= mc
->default_cpus
;
1312 mc
->max_cpus
= mc
->default_cpus
;
1313 mmc
->fpga_type
= FPGA_AN524
;
1314 mc
->default_cpu_type
= ARM_CPU_TYPE_NAME("cortex-m33");
1315 mmc
->scc_id
= 0x41045240;
1316 mmc
->sysclk_frq
= 32 * 1000 * 1000; /* 32MHz */
1317 mmc
->apb_periph_frq
= mmc
->sysclk_frq
;
1318 mmc
->oscclk
= an524_oscclk
;
1319 mmc
->len_oscclk
= ARRAY_SIZE(an524_oscclk
);
1320 mmc
->fpgaio_num_leds
= 10;
1321 mmc
->fpgaio_has_switches
= true;
1322 mmc
->fpgaio_has_dbgctrl
= false;
1324 mmc
->uart_overflow_irq
= 47;
1325 mmc
->init_svtor
= 0x10000000;
1326 mmc
->raminfo
= an524_raminfo
;
1327 mmc
->armsse_type
= TYPE_SSE200
;
1328 mps2tz_set_default_ram_info(mmc
);
1330 object_class_property_add_str(oc
, "remap", mps2_get_remap
, mps2_set_remap
);
1331 object_class_property_set_description(oc
, "remap",
1332 "Set memory mapping. Valid values "
1333 "are BRAM (default) and QSPI.");
1336 static void mps3tz_an547_class_init(ObjectClass
*oc
, void *data
)
1338 MachineClass
*mc
= MACHINE_CLASS(oc
);
1339 MPS2TZMachineClass
*mmc
= MPS2TZ_MACHINE_CLASS(oc
);
1341 mc
->desc
= "ARM MPS3 with AN547 FPGA image for Cortex-M55";
1342 mc
->default_cpus
= 1;
1343 mc
->min_cpus
= mc
->default_cpus
;
1344 mc
->max_cpus
= mc
->default_cpus
;
1345 mmc
->fpga_type
= FPGA_AN547
;
1346 mc
->default_cpu_type
= ARM_CPU_TYPE_NAME("cortex-m55");
1347 mmc
->scc_id
= 0x41055470;
1348 mmc
->sysclk_frq
= 32 * 1000 * 1000; /* 32MHz */
1349 mmc
->apb_periph_frq
= 25 * 1000 * 1000; /* 25MHz */
1350 mmc
->oscclk
= an524_oscclk
; /* same as AN524 */
1351 mmc
->len_oscclk
= ARRAY_SIZE(an524_oscclk
);
1352 mmc
->fpgaio_num_leds
= 10;
1353 mmc
->fpgaio_has_switches
= true;
1354 mmc
->fpgaio_has_dbgctrl
= true;
1356 mmc
->uart_overflow_irq
= 48;
1357 mmc
->init_svtor
= 0x00000000;
1358 mmc
->raminfo
= an547_raminfo
;
1359 mmc
->armsse_type
= TYPE_SSE300
;
1360 mps2tz_set_default_ram_info(mmc
);
1363 static const TypeInfo mps2tz_info
= {
1364 .name
= TYPE_MPS2TZ_MACHINE
,
1365 .parent
= TYPE_MACHINE
,
1367 .instance_size
= sizeof(MPS2TZMachineState
),
1368 .class_size
= sizeof(MPS2TZMachineClass
),
1369 .class_init
= mps2tz_class_init
,
1370 .interfaces
= (InterfaceInfo
[]) {
1371 { TYPE_IDAU_INTERFACE
},
1376 static const TypeInfo mps2tz_an505_info
= {
1377 .name
= TYPE_MPS2TZ_AN505_MACHINE
,
1378 .parent
= TYPE_MPS2TZ_MACHINE
,
1379 .class_init
= mps2tz_an505_class_init
,
1382 static const TypeInfo mps2tz_an521_info
= {
1383 .name
= TYPE_MPS2TZ_AN521_MACHINE
,
1384 .parent
= TYPE_MPS2TZ_MACHINE
,
1385 .class_init
= mps2tz_an521_class_init
,
1388 static const TypeInfo mps3tz_an524_info
= {
1389 .name
= TYPE_MPS3TZ_AN524_MACHINE
,
1390 .parent
= TYPE_MPS2TZ_MACHINE
,
1391 .class_init
= mps3tz_an524_class_init
,
1394 static const TypeInfo mps3tz_an547_info
= {
1395 .name
= TYPE_MPS3TZ_AN547_MACHINE
,
1396 .parent
= TYPE_MPS2TZ_MACHINE
,
1397 .class_init
= mps3tz_an547_class_init
,
1400 static void mps2tz_machine_init(void)
1402 type_register_static(&mps2tz_info
);
1403 type_register_static(&mps2tz_an505_info
);
1404 type_register_static(&mps2tz_an521_info
);
1405 type_register_static(&mps3tz_an524_info
);
1406 type_register_static(&mps3tz_an547_info
);
1409 type_init(mps2tz_machine_init
);