From nobody Sun May 19 03:02:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1588580585; cv=none; d=zohomail.com; s=zohoarc; b=Eoe0IikKfbNOjElk4gTKsG1hyB8M+5ZojvK8NL9S9EfE9/ehU5Lirms2duOQ03pgaMMgegqs4fp7maHR3TRo/5kzcSAsmuTXfmOO/g7SQV+6nryoHthc78PORckY8uCYUhQYh7LzhuPMjmtUz+tWQQQvPcxD82S8LFv3ncWFhQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588580585; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=2XgLZn2sOZOSwpO9/2aZe0zzmrJOCY/4ZyyfR4dE+ic=; b=Yxl9kCvj2GTLqwYHsKhke08h5Kf8rX6deYLr+CPgTSbFnCNUyMbAXtcud0eedCxH1pfjp03ZIXUEwhfK0C6Wl72+mUGhGv34Z8Fvhvij/0qdPJS76DnISYzN40c+hc2B9fIKAk7TGT+w1vjoh0RokeEoKx6az5Urm69VUEVNim0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588580585462576.9374915642958; Mon, 4 May 2020 01:23:05 -0700 (PDT) Received: from localhost ([::1]:47692 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jVWNU-0004by-1t for importer@patchew.org; Mon, 04 May 2020 04:23:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38368) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jVWKc-0001pP-OB; Mon, 04 May 2020 04:20:06 -0400 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:37783) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jVWKb-00049T-Qm; Mon, 04 May 2020 04:20:06 -0400 Received: by mail-pg1-x543.google.com with SMTP id r4so8169541pgg.4; Mon, 04 May 2020 01:20:05 -0700 (PDT) Received: from localhost.localdomain ([45.124.203.15]) by smtp.gmail.com with ESMTPSA id v1sm6144474pjs.36.2020.05.04.01.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2020 01:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2XgLZn2sOZOSwpO9/2aZe0zzmrJOCY/4ZyyfR4dE+ic=; b=lQZBoaK48FjadaNiHlwdXc7HmcfzkRTFxNyAMdUnTz5LvwLFwkVFUCgSInz3PujV6b 16geeZGwSZvyYqiy5PBbyrNo5uh8ahSsFyQzrmHPjAXWETKVixilwGCRY75X/WcX6yO4 h+BtQpY4dsMvwtHaMq5LHkOjJMO9G5wRSal/yuWXQTfulU7+yqENTW02rjed2Rdyk74u 4acfrHIu6pgRiUEHfn4MLtzMrS9Bid5bIWi4rjhV4TCxJOxk+bDBHLUAMG6kkrOejf5m DKgiHKfsxgBMJ1t0xo39MJjPXBj7IzXUaomxfOVGmI7QpJmXfoG9gE7P2N7gSb2Tub3A Mvyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=2XgLZn2sOZOSwpO9/2aZe0zzmrJOCY/4ZyyfR4dE+ic=; b=MFrPLILu4ocv89cZeOBU9M7PbQxA+hEG6Gz365/SRQsWnIbnbUtQ/3/k1CbVTox1Tv LRnR9FZuOjG7InGSh7mN3faJbqB84CsvhNmX1PLJlrv8WxSMRuGf1xI3WxpvaO+sOlsG mm6c8S4jqAr0QArGxkVTvReYxnMVHXGf6Ssqk6DH6vqXopRlcoh+DyhYLIMUPGpvLmXZ xJCXQaTQ9UqyoAySU0otr6Q3ojAJADL9lroVPfFTKQQJ9sirUOEcMpmgE5cFMn+OPfFl MFgkqZyNDlVdoSzdTr71XS/teupQarN8OvsgMVZ4IllSeQRebC7gf5YDl6p4RHLZr3EE R/eQ== X-Gm-Message-State: AGi0PuaR0SXU+GM36oExOJLgcbTffzgEAglB3nFWlYH2ZfUwtgaWCuJt 3WYn/9OA06z/tD3Ru125n2c= X-Google-Smtp-Source: APiQypLVGNwUhjhvO7rq6rIrynBgXSTeRyFOST4CO78hC4VNIUum0uyK5rjLoyVIyPFViw1wZvUSOA== X-Received: by 2002:a63:5b07:: with SMTP id p7mr5094843pgb.218.1588580403966; Mon, 04 May 2020 01:20:03 -0700 (PDT) From: Joel Stanley To: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Peter Maydell Subject: [PATCH v3] aspeed: Add boot stub for smp booting Date: Mon, 4 May 2020 17:49:53 +0930 Message-Id: <20200504081953.245912-1-joel@jms.id.au> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::543; envelope-from=joel.stan@gmail.com; helo=mail-pg1-x543.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery , qemu-arm@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is a boot stub that is similar to the code u-boot runs, allowing the kernel to boot the secondary CPU. u-boot works as follows: 1. Initialises the SMP mailbox area in the SCU at 0x1e6e2180 with default = values 2. Copies a stub named 'mailbox_insn' from flash to the SCU, just above the mailbox area 3. Sets AST_SMP_MBOX_FIELD_READY to a magic value to indicate the secondary can begin execution from the stub 4. The stub waits until the AST_SMP_MBOX_FIELD_GOSIGN register is set to a magic value 5. Jumps to the address in AST_SMP_MBOX_FIELD_ENTRY, starting Linux Linux indicates it is ready by writing the address of its entrypoint function to AST_SMP_MBOX_FIELD_ENTRY and the 'go' magic number to AST_SMP_MBOX_FIELD_GOSIGN. The secondary CPU sees this at step 4 and breaks out of it's loop. To be compatible, a fixed qemu stub is loaded into the mailbox area. As qemu can ensure the stub is loaded before execution starts, we do not need to emulate the AST_SMP_MBOX_FIELD_READY behaviour of u-boot. The secondary CPU's program counter points to the beginning of the stub, allowing qemu to start secondaries at step four. Reboot behaviour is preserved by resetting AST_SMP_MBOX_FIELD_GOSIGN when the secondaries are reset. This is only configured when the system is booted with -kernel and qemu does not execute u-boot first. Reviewed-by: C=C3=A9dric Le Goater Tested-by: C=C3=A9dric Le Goater Signed-off-by: Joel Stanley --- v3: Use WFI instead of WFE v2: test for number of CPUs --- hw/arm/aspeed.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index 88bcd6ff3fbd..93970502b8a6 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -116,6 +116,58 @@ static const MemoryRegionOps max_ram_ops =3D { .endianness =3D DEVICE_NATIVE_ENDIAN, }; =20 +#define AST_SMP_MAILBOX_BASE 0x1e6e2180 +#define AST_SMP_MBOX_FIELD_ENTRY (AST_SMP_MAILBOX_BASE + 0x0) +#define AST_SMP_MBOX_FIELD_GOSIGN (AST_SMP_MAILBOX_BASE + 0x4) +#define AST_SMP_MBOX_FIELD_READY (AST_SMP_MAILBOX_BASE + 0x8) +#define AST_SMP_MBOX_FIELD_POLLINSN (AST_SMP_MAILBOX_BASE + 0xc) +#define AST_SMP_MBOX_CODE (AST_SMP_MAILBOX_BASE + 0x10) +#define AST_SMP_MBOX_GOSIGN 0xabbaab00 + +static void aspeed_write_smpboot(ARMCPU *cpu, + const struct arm_boot_info *info) +{ + static const uint32_t poll_mailbox_ready[] =3D { + /* + * r2 =3D per-cpu go sign value + * r1 =3D AST_SMP_MBOX_FIELD_ENTRY + * r0 =3D AST_SMP_MBOX_FIELD_GOSIGN + */ + 0xee100fb0, /* mrc p15, 0, r0, c0, c0, 5 */ + 0xe21000ff, /* ands r0, r0, #255 */ + 0xe59f201c, /* ldr r2, [pc, #28] */ + 0xe1822000, /* orr r2, r2, r0 */ + + 0xe59f1018, /* ldr r1, [pc, #24] */ + 0xe59f0018, /* ldr r0, [pc, #24] */ + + 0xe320f003, /* wfi */ + 0xe5904000, /* ldr r4, [r0] */ + 0xe1520004, /* cmp r2, r4 */ + 0x1afffffb, /* bne */ + 0xe591f000, /* ldr pc, [r1] */ + AST_SMP_MBOX_GOSIGN, + AST_SMP_MBOX_FIELD_ENTRY, + AST_SMP_MBOX_FIELD_GOSIGN, + }; + + rom_add_blob_fixed("aspeed.smpboot", poll_mailbox_ready, + sizeof(poll_mailbox_ready), + info->smp_loader_start); +} + +static void aspeed_reset_secondary(ARMCPU *cpu, + const struct arm_boot_info *info) +{ + AddressSpace *as =3D arm_boot_address_space(cpu, info); + CPUState *cs =3D CPU(cpu); + + /* info->smp_bootreg_addr */ + address_space_stl_notdirty(as, AST_SMP_MBOX_FIELD_GOSIGN, 0, + MEMTXATTRS_UNSPECIFIED, NULL); + cpu_set_pc(cs, info->smp_loader_start); +} + #define FIRMWARE_ADDR 0x0 =20 static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size, @@ -270,6 +322,19 @@ static void aspeed_machine_init(MachineState *machine) } } =20 + if (machine->kernel_filename && bmc->soc.num_cpus > 1) { + /* With no u-boot we must set up a boot stub for the secondary CPU= */ + MemoryRegion *smpboot =3D g_new(MemoryRegion, 1); + memory_region_init_ram(smpboot, OBJECT(bmc), "aspeed.smpboot", + 0x80, &error_abort); + memory_region_add_subregion(get_system_memory(), + AST_SMP_MAILBOX_BASE, smpboot); + + aspeed_board_binfo.write_secondary_boot =3D aspeed_write_smpboot; + aspeed_board_binfo.secondary_cpu_reset_hook =3D aspeed_reset_secon= dary; + aspeed_board_binfo.smp_loader_start =3D AST_SMP_MBOX_CODE; + } + aspeed_board_binfo.ram_size =3D ram_size; aspeed_board_binfo.loader_start =3D sc->memmap[ASPEED_SDRAM]; aspeed_board_binfo.nb_cpus =3D bmc->soc.num_cpus; --=20 2.26.2