Received: by 2002:ac2:5937:0:0:0:0:0 with SMTP id v23csp4918824lfi; Tue, 7 Apr 2020 01:19:21 -0700 (PDT) X-Google-Smtp-Source: APiQypKhff6Qbuh3S/s5hzthc7k2ovU0dqmZwGxHU6lR3SOsazVDxSTWTg3+oahT5EfKwYPZ2h5/ X-Received: by 2002:ac8:18ab:: with SMTP id s40mr1118917qtj.224.1586247561682; Tue, 07 Apr 2020 01:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586247561; cv=none; d=google.com; s=arc-20160816; b=Nx/Orw0Z+c9xi6roMdRbD9sOikbj4q2lTsp/F1hWn5MaVC00PC2RezNjUyeIGQdAL8 9dG4eOqs8LdDgFx5l/WxuBVeOe2o1XYcKkdpphZ6Avm9p0EEOSf+BKwIV6CUOA2Eu+hM W6cV8wSBZzS+o5V4HU//7Ewo/TdkCukXqx+BQJdywlgRvvziCndSyAf0wRGJrahblfOp Hg7aWTMCxjUdwrH7czDzJf+OQjXgbaJQv4ZVQG96tJg6+vQFdVm9ViWkMcxElG4JyZbO +Q/uRbJg6sBow2cXZ6LGVnuYz9wtt0QxWzw4d8QhnVvgudW24NwHlglIr6RtSUlzLdkg dzgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=eMiR9a/9beMjjtj4JxsDbSPWGLbJ2vVD5O+Pfpq8M+s=; b=pLrfeSls+0dDS6dDJtlB+XSEldF6irVbQDBLVbUWxgYnuIe9XfPkT4+zFnviiDgger 9TnX38360XtPJT1WrmtQn2i5CYELOrOmmd0qU0V9ZJjeNk1hk3GsStffhtiwjNefCGBs c7etV72IG+WZtuZK8AhcGqCqcIenMT6gm5x8WddxkO3gFGQ8QVXec0PZSA2TTliVJmZG /UHrjtg+KyQhvQ4Zn8aQFM4zN/xOlglyaGaxN+gb2OF7aiAjeiUsVoV7QqPVcOJO/epC xxvLO5KjI3qNXmtB9DpOfSXGqIQSOpXQdTIis9A2vPykosw+jgwNCIaIUSdLAOV+BFxN pftA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b7E+cpAn; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e15si1325990qtg.100.2020.04.07.01.19.21 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Apr 2020 01:19:21 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=b7E+cpAn; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:42938 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLjS5-0004pH-3g for alex.bennee@linaro.org; Tue, 07 Apr 2020 04:19:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49152) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLjRt-0004oF-JT for qemu-arm@nongnu.org; Tue, 07 Apr 2020 04:19:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLjRr-0003vO-HY for qemu-arm@nongnu.org; Tue, 07 Apr 2020 04:19:08 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:43602 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jLjRr-0003uv-By for qemu-arm@nongnu.org; Tue, 07 Apr 2020 04:19:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586247546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eMiR9a/9beMjjtj4JxsDbSPWGLbJ2vVD5O+Pfpq8M+s=; b=b7E+cpAnObxUEtAbDS/N4pgQcCpRhcOcNf28vrqTfGSguoZD+FGUgO36l37fYEYV+GBboF Y99FJADhjxuIwwzOCHWCMMfQ3JprPQYOQfN/INsgbp0CjPZ0tYxUixNjfle0fWax0wpfQr bl/3kll6uFx3TLzNeGhWvnGZNbSqRnc= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-211-TVJqVSUFPpuOVizB1I0uBQ-1; Tue, 07 Apr 2020 04:19:04 -0400 X-MC-Unique: TVJqVSUFPpuOVizB1I0uBQ-1 Received: by mail-ed1-f69.google.com with SMTP id b9so2379602edj.10 for ; Tue, 07 Apr 2020 01:19:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=eMiR9a/9beMjjtj4JxsDbSPWGLbJ2vVD5O+Pfpq8M+s=; b=iafmM3C6otixwOzmfK5icWgkBjppd8BV6gKnGE/MmX/vzB/5/WXKmnQidcwcXkzDGE V4+U3RNYwNRaO0n8SPNurs7YlXPcoiWW6Ea8EWe60y4aFDvZ6AcVIGvcd2yxK/c++eh2 EZnsgmpLqSRFYDM418iOjclAJ2vJiyBYwo3+4LXsFakrR87KMW7Tr+TVHweZ/Xe05DrS flycLsLpMOwx1nMTEQzTPhWObN5SKyNMHJzztdg1a22aHu0czqXkpHyATLYBxCrcBfjD Dmr1CEEXiqqL330UCo0QJkHTe6yrGpFmEZTgGidPwrHHZM6ldRikatSK3O3TdmpH8get 14YQ== X-Gm-Message-State: AGi0PubIEYE4gduIXuyY8MGPQTutmEG9oJ4KwbmN6+oR6zkZBCuh6o5j pXiydxX2oUsq132tGcCVr3Rv1J1MdKV50NDZBT9NqkJb/JCLms5y4iBiHKE7H/0CZeSxpH7UP3q RZjFeGlGd7c/2 X-Received: by 2002:a17:906:54cd:: with SMTP id c13mr839757ejp.307.1586247543725; Tue, 07 Apr 2020 01:19:03 -0700 (PDT) X-Received: by 2002:a17:906:54cd:: with SMTP id c13mr839729ejp.307.1586247543382; Tue, 07 Apr 2020 01:19:03 -0700 (PDT) Received: from [192.168.1.39] (116.red-83-42-57.dynamicip.rima-tde.net. [83.42.57.116]) by smtp.gmail.com with ESMTPSA id nw21sm2429923ejb.54.2020.04.07.01.19.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Apr 2020 01:19:02 -0700 (PDT) Subject: Re: [PATCH] aspeed: Add boot stub for smp booting To: Joel Stanley , =?UTF-8?Q?C=c3=a9dric_Le_Goater?= , Peter Maydell References: <20200407072517.671521-1-joel@jms.id.au> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= Message-ID: <16f057db-a4d7-889f-344c-930587fc8bf1@redhat.com> Date: Tue, 7 Apr 2020 10:19:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-arm@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 , QEMU Developers Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: FnKjEFAxIePn On 4/7/20 9:38 AM, Joel Stanley wrote: > On Tue, 7 Apr 2020 at 07:25, Joel Stanley wrote: >> >> 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. >> >> Signed-off-by: Joel Stanley >> --- >> hw/arm/aspeed.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 65 insertions(+) >> >> diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c >> index a6a2102a93cb..bc4386cc6174 100644 >> --- a/hw/arm/aspeed.c >> +++ b/hw/arm/aspeed.c >> @@ -116,6 +116,58 @@ static const MemoryRegionOps max_ram_ops = { >> .endianness = DEVICE_NATIVE_ENDIAN, >> }; >> >> +#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[] = { >> + /* >> + * r2 = per-cpu go sign value >> + * r1 = AST_SMP_MBOX_FIELD_ENTRY >> + * r0 = 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] */ >> + >> + 0xe320f002, /* wfe */ >> + 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 = arm_boot_address_space(cpu, info); >> + CPUState *cs = 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 >> >> static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size, >> @@ -270,6 +322,19 @@ static void aspeed_machine_init(MachineState *machine) >> } >> } >> >> + if (machine->kernel_filename) { > > I just realised this shouldn't be executed on non-ast2600 platforms. > We could test for the number of CPUs like this: > > if (machine->kernel_filename && aspeed_board_binfo.nb_cpus > 1) { if (!strcmp(amc->soc_name, "ast2600")) { ? > >> + /* With no u-boot we must set up a boot stub for the secondary CPU */ >> + MemoryRegion *smpboot = 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 = aspeed_write_smpboot; >> + aspeed_board_binfo.secondary_cpu_reset_hook = aspeed_reset_secondary; >> + aspeed_board_binfo.smp_loader_start = AST_SMP_MBOX_CODE; >> + } >> + >> aspeed_board_binfo.ram_size = ram_size; >> aspeed_board_binfo.loader_start = sc->memmap[ASPEED_SDRAM]; >> aspeed_board_binfo.nb_cpus = bmc->soc.num_cpus; >> -- >> 2.25.1 >> >