[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH target-arm v5 2/5] arm: zynq: added SMP support
From: |
Peter Crosthwaite |
Subject: |
[Qemu-devel] [PATCH target-arm v5 2/5] arm: zynq: added SMP support |
Date: |
Wed, 15 Jan 2014 01:13:41 -0800 |
Added Linux SMP support for the Xilinx Zynq platform (2x CPUs are
supported)
Signed-off-by: Peter Crosthwaite <address@hidden>
---
Changed from v4:
Removed dummy bootreg addr (PMM review)
Implemented custom secondary cpu reset (PMM review)
Changed from v3:
Author reset
s/zynq_cpus/cpus
simplified custom secondary bootloader
Rebased
Changed from v2:
macro defined the maximum number of CPUS
Changed from v1:
Addressed PMM review
Shorted secondary bootloop using MVN instruction.
Used default reset secondary instead of custom one.
Rebased against QOM cpu developments.
Few whitespace fixes.
hw/arm/xilinx_zynq.c | 75 +++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 59 insertions(+), 16 deletions(-)
diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c
index 33a47e0..63390f7 100644
--- a/hw/arm/xilinx_zynq.c
+++ b/hw/arm/xilinx_zynq.c
@@ -27,6 +27,8 @@
#include "hw/ssi.h"
#include "qemu/error-report.h"
+#define MAX_CPUS 2
+
#define NUM_SPI_FLASHES 4
#define NUM_QSPI_FLASHES 2
#define NUM_QSPI_BUSSES 2
@@ -40,10 +42,43 @@
#define OCM_BASE 0xfffc0000
#define OCM_SIZE (256 << 10)
+/* Put SMP bootloader up top of OCM */
+#define SMP_BOOT_ADDR ((uint64_t)OCM_BASE + OCM_SIZE - sizeof(zynq_smpboot))
+
static const int dma_irqs[8] = {
46, 47, 48, 49, 72, 73, 74, 75
};
+/* Entry point for secondary CPU. Zynq Linux SMP protocol is to just reset
+ * the secondary to unpen, so any infinite loop will do the trick. Use a WFI
+ * loop as that will cause the emulated CPU to halt (and remove itself from
+ * the work queue pending an interrupt that never comes).
+ */
+static uint32_t zynq_smpboot[] = {
+ 0xe320f003, /* wfi */
+ 0xeafffffd, /* b <b wfi> */
+};
+
+static void zynq_write_secondary_boot(ARMCPU *cpu,
+ const struct arm_boot_info *info)
+{
+ int n;
+
+ for (n = 0; n < ARRAY_SIZE(zynq_smpboot); n++) {
+ zynq_smpboot[n] = tswap32(zynq_smpboot[n]);
+ }
+ rom_add_blob_fixed("smpboot", zynq_smpboot, sizeof(zynq_smpboot),
+ SMP_BOOT_ADDR);
+}
+
+static void zynq_reset_secondary(ARMCPU *cpu,
+ const struct arm_boot_info *info)
+{
+ CPUARMState *env = &cpu->env;
+
+ env->regs[15] = info->smp_loader_start;
+}
+
static struct arm_boot_info zynq_binfo = {};
static void gem_init(NICInfo *nd, uint32_t base, qemu_irq irq)
@@ -110,7 +145,7 @@ static void zynq_init(QEMUMachineInitArgs *args)
const char *kernel_cmdline = args->kernel_cmdline;
const char *initrd_filename = args->initrd_filename;
ObjectClass *cpu_oc;
- ARMCPU *cpu;
+ ARMCPU *cpu[MAX_CPUS];
MemoryRegion *address_space_mem = get_system_memory();
MemoryRegion *ext_ram = g_new(MemoryRegion, 1);
MemoryRegion *ocm_ram = g_new(MemoryRegion, 1);
@@ -125,17 +160,20 @@ static void zynq_init(QEMUMachineInitArgs *args)
}
cpu_oc = cpu_class_by_name(TYPE_ARM_CPU, cpu_model);
- cpu = ARM_CPU(object_new(object_class_get_name(cpu_oc)));
+ for (n = 0; n < smp_cpus; n++) {
+ cpu[n] = ARM_CPU(object_new(object_class_get_name(cpu_oc)));
- object_property_set_int(OBJECT(cpu), MPCORE_PERIPHBASE, "reset-cbar",
&err);
- if (err) {
- error_report("%s", error_get_pretty(err));
- exit(1);
- }
- object_property_set_bool(OBJECT(cpu), true, "realized", &err);
- if (err) {
- error_report("%s", error_get_pretty(err));
- exit(1);
+ object_property_set_int(OBJECT(cpu[n]), MPCORE_PERIPHBASE,
"reset-cbar",
+ &err);
+ if (err) {
+ error_report("%s", error_get_pretty(err));
+ exit(1);
+ }
+ object_property_set_bool(OBJECT(cpu[n]), true, "realized", &err);
+ if (err) {
+ error_report("%s", error_get_pretty(err));
+ exit(1);
+ }
}
/* max 2GB ram */
@@ -167,12 +205,14 @@ static void zynq_init(QEMUMachineInitArgs *args)
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xF8000000);
dev = qdev_create(NULL, "a9mpcore_priv");
- qdev_prop_set_uint32(dev, "num-cpu", 1);
+ qdev_prop_set_uint32(dev, "num-cpu", smp_cpus);
qdev_init_nofail(dev);
busdev = SYS_BUS_DEVICE(dev);
sysbus_mmio_map(busdev, 0, MPCORE_PERIPHBASE);
- sysbus_connect_irq(busdev, 0,
- qdev_get_gpio_in(DEVICE(cpu), ARM_CPU_IRQ));
+ for (n = 0; n < smp_cpus; n++) {
+ sysbus_connect_irq(busdev, n,
+ qdev_get_gpio_in(DEVICE(cpu[n]), ARM_CPU_IRQ));
+ }
for (n = 0; n < 64; n++) {
pic[n] = qdev_get_gpio_in(dev, n);
@@ -230,7 +270,10 @@ static void zynq_init(QEMUMachineInitArgs *args)
zynq_binfo.kernel_filename = kernel_filename;
zynq_binfo.kernel_cmdline = kernel_cmdline;
zynq_binfo.initrd_filename = initrd_filename;
- zynq_binfo.nb_cpus = 1;
+ zynq_binfo.nb_cpus = smp_cpus;
+ zynq_binfo.write_secondary_boot = zynq_write_secondary_boot;
+ zynq_binfo.secondary_cpu_reset_hook = zynq_reset_secondary;
+ zynq_binfo.smp_loader_start = SMP_BOOT_ADDR;
zynq_binfo.board_id = 0xd32;
zynq_binfo.loader_start = 0;
arm_load_kernel(ARM_CPU(first_cpu), &zynq_binfo);
@@ -241,7 +284,7 @@ static QEMUMachine zynq_machine = {
.desc = "Xilinx Zynq Platform Baseboard for Cortex-A9",
.init = zynq_init,
.block_default_type = IF_SCSI,
- .max_cpus = 1,
+ .max_cpus = MAX_CPUS,
.no_sdcard = 1,
};
--
1.8.5.3