From patchwork Mon Mar 19 18:34:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 132083 Delivered-To: patch@linaro.org Received: by 10.46.84.17 with SMTP id i17csp3062030ljb; Mon, 19 Mar 2018 11:48:37 -0700 (PDT) X-Google-Smtp-Source: AG47ELtHDFvJy1UbXgEN+AS1laICf2mk/3b9aOw/oONHuHZGBHB7DJhhftPk8C/ToC1xLCauX0bN X-Received: by 10.200.61.90 with SMTP id u26mr19319426qtf.168.1521485316951; Mon, 19 Mar 2018 11:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521485316; cv=none; d=google.com; s=arc-20160816; b=zZjWaeeJQbS2dgoaCG8P3FUpiTcGAKGDq4dxUiSqiIi0eRAAVm+hKa+bxXmoK9OVZg B9WSfFcwh7Gv6OYBO82wkSvGnXNsWISWHQ2pZeGobqaDj5CR7R+Lrkwo1UnxOrQfSUD6 2xcUusmJ+uNk3FQdcBH6+xSQ2NnUuId92GkrGG9A7/llBAVLOiaAlC1f/NKPK/cAegE6 HLmMjUfRfAL73HYpvGlbjkX0gyRA+dciXbMgCax/rGAv0CawPTE984eio/G0i5vmELPi eenRwNFsDD5bRN/J+3AOgPEpBHgRdqT90CpTnqjvYwRSG1UdfTFr0swdbctgPomjGHl3 4j6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=tz/MiuafIpI9TOT/oG3WeiLsw+BYkt6tRt2NEA3ytUE=; b=cL798shb4N1+gAIjYaHoVbWnSAOL9nT8IsPTwE0quWvxxa+UJXndAnFR/fVL7JXxaT E2CHnV+uiKRPmMx0ik72VtXn/cmxoRisEDtUdKHZw9OxMMPD86MG9w4uYb/WC0CeH1hD L4u5no+8Bc/3GLxET5WtoBEnMrx4qghNiDW1c9xDE+4v6iaSUldv/anbdbf9YE8Rk+Ut R4y8afer2cGNrPzCiZdwLVGwnnC4gvqzyEummOgsn5Ix7brTfL/Pe4Rl7BEEsjhbkm0/ Y43WeRaE1bbcqO+duyhX+7yLPapXTfPK8cgVoPqOmHZFbQ5JJLk43/4LflKyG1MqrKNw hXxA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d58si644465qta.483.2018.03.19.11.48.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 19 Mar 2018 11:48:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43439 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exzpk-0004k8-Dm for patch@linaro.org; Mon, 19 Mar 2018 14:48:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49808) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1exzc5-0002Qm-CT for qemu-devel@nongnu.org; Mon, 19 Mar 2018 14:34:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1exzc4-0007mg-8K for qemu-devel@nongnu.org; Mon, 19 Mar 2018 14:34:29 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:40466) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1exzc4-0007lN-0R for qemu-devel@nongnu.org; Mon, 19 Mar 2018 14:34:28 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1exzc3-00034Z-10 for qemu-devel@nongnu.org; Mon, 19 Mar 2018 18:34:27 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 19 Mar 2018 18:34:15 +0000 Message-Id: <20180319183415.1976-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180319183415.1976-1-peter.maydell@linaro.org> References: <20180319183415.1976-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 13/13] hw/arm/raspi: Provide spin-loop code for AArch64 CPUs X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The raspi3 has AArch64 CPUs, which means that our smpboot code for keeping the secondary CPUs in a pen needs to have a version for A64 as well as A32. Without this, the secondary CPUs go into an infinite loop of taking undefined instruction exceptions. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 20180313153458.26822-10-peter.maydell@linaro.org --- hw/arm/raspi.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) -- 2.16.2 diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index ae15997669..06f1e08ca9 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -27,6 +27,7 @@ #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */ #define FIRMWARE_ADDR_2 0x8000 /* Pi 2 loads kernel.img here by default */ #define FIRMWARE_ADDR_3 0x80000 /* Pi 3 loads kernel.img here by default */ +#define SPINTABLE_ADDR 0xd8 /* Pi 3 bootloader spintable */ /* Table of Linux board IDs for different Pi versions */ static const int raspi_boardid[] = {[1] = 0xc42, [2] = 0xc43, [3] = 0xc44}; @@ -63,6 +64,40 @@ static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) info->smp_loader_start); } +static void write_smpboot64(ARMCPU *cpu, const struct arm_boot_info *info) +{ + /* Unlike the AArch32 version we don't need to call the board setup hook. + * The mechanism for doing the spin-table is also entirely different. + * We must have four 64-bit fields at absolute addresses + * 0xd8, 0xe0, 0xe8, 0xf0 in RAM, which are the flag variables for + * our CPUs, and which we must ensure are zero initialized before + * the primary CPU goes into the kernel. We put these variables inside + * a rom blob, so that the reset for ROM contents zeroes them for us. + */ + static const uint32_t smpboot[] = { + 0xd2801b05, /* mov x5, 0xd8 */ + 0xd53800a6, /* mrs x6, mpidr_el1 */ + 0x924004c6, /* and x6, x6, #0x3 */ + 0xd503205f, /* spin: wfe */ + 0xf86678a4, /* ldr x4, [x5,x6,lsl #3] */ + 0xb4ffffc4, /* cbz x4, spin */ + 0xd2800000, /* mov x0, #0x0 */ + 0xd2800001, /* mov x1, #0x0 */ + 0xd2800002, /* mov x2, #0x0 */ + 0xd2800003, /* mov x3, #0x0 */ + 0xd61f0080, /* br x4 */ + }; + + static const uint64_t spintables[] = { + 0, 0, 0, 0 + }; + + rom_add_blob_fixed("raspi_smpboot", smpboot, sizeof(smpboot), + info->smp_loader_start); + rom_add_blob_fixed("raspi_spintables", spintables, sizeof(spintables), + SPINTABLE_ADDR); +} + static void write_board_setup(ARMCPU *cpu, const struct arm_boot_info *info) { arm_write_secure_board_setup_dummy_smc(cpu, info, MVBAR_ADDR); @@ -99,7 +134,11 @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) /* Pi2 and Pi3 requires SMP setup */ if (version >= 2) { binfo.smp_loader_start = SMPBOOT_ADDR; - binfo.write_secondary_boot = write_smpboot; + if (version == 2) { + binfo.write_secondary_boot = write_smpboot; + } else { + binfo.write_secondary_boot = write_smpboot64; + } binfo.secondary_cpu_reset_hook = reset_secondary; }