From patchwork Mon Sep 30 22:12:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 831588 Delivered-To: patch@linaro.org Received: by 2002:a5d:43d2:0:b0:367:895a:4699 with SMTP id v18csp13488wrr; Mon, 30 Sep 2024 15:13:26 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWCL3jrhhHzNRAEkQsigut0ntjFJKKeVx7Ezzujo1VhFmdnmKIq3551LxjHb+Z4K5DPL6bzew==@linaro.org X-Google-Smtp-Source: AGHT+IHk9b4DDvG9pVViIx1cO4MYS2suRkMtiq1Ij2C/5rnIS3ghFdEgiShx+DfjhFFghK8KHaEs X-Received: by 2002:a05:620a:2403:b0:79f:1cf:551e with SMTP id af79cd13be357-7ae37826010mr1703259985a.5.1727734405884; Mon, 30 Sep 2024 15:13:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1727734405; cv=none; d=google.com; s=arc-20240605; b=dm9h4DYjwUhyy6Wt9SBP8AGGDVUdXmxKg28n1jFR66q59TOyuSx5EN0qB/yCZTVtUZ gdu140uiKQRKV56ijLIi+32nSu3YhDs30JVJ21P8AOPswnTHysKxth4sPSnVSFTDT5WH eMIUMF0+8vgGoIG6xUczimz44yVstr65lT99v7vSBA8Tx5mT9Zjnp+TxDFT9I3UkamGB irrJl+jdzFSyLuhPOdjWed/c6KyOSVfXFym/dDIxZAtW0jw1dheWnHZinIOgiyKtZoHf Babip1XA4VUXjLGuk1mSC0sAOgPt70kwMqLdGfgO/+K00yb2uFRlL2EjVg7GTHNlD0Ls lG5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=grjpT5kTsMGjq3j1/lhkj4QBsxYe83DKBpMh5569Dgk=; fh=ANAgQAkGs37PxNAxU2bccxa/SpERQafpMiE9doUlQR0=; b=eE01mynvzV6ZxMY+UMDLybqKlltQY1CXu0JIYv7+gWTuV/idiFOI1GA3tuYL1lXlkh CUwdmyJVP35cZJqEdpjjJaByS4ORA6gYarOHTOBjSMern8sNnWAWuWp2NwaYuVlowoV/ LS1JWf+hZfSQc7FT3xWnfCGV7w9eX2C6Lv7mBSo304qHniGcOyGuMR6zyGXp1d3paSJh Y6pKpK9F5J/6J14Sm3a51WYreNEnvtWzguW1h3JLNzMX/8X7CPMOKhPk6VM5QUoc85tb wLc88A83p2TNkR/3cH/iJUVh5JsZ9o9SogkPHiG2G0ByEXlTvBdVts5kt3bOGmn8Hkhh 78zA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=oSF4xcxe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-7ae37838418si925270385a.279.2024.09.30.15.13.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 30 Sep 2024 15:13:25 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=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=@linaro.org header.s=google header.b=oSF4xcxe; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svOd3-0003NE-UA; Mon, 30 Sep 2024 18:12:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1svOd2-0003MF-Ng for qemu-devel@nongnu.org; Mon, 30 Sep 2024 18:12:28 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1svOd1-0002fi-0s for qemu-devel@nongnu.org; Mon, 30 Sep 2024 18:12:28 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a8d2daa2262so558028366b.1 for ; Mon, 30 Sep 2024 15:12:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727734345; x=1728339145; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=grjpT5kTsMGjq3j1/lhkj4QBsxYe83DKBpMh5569Dgk=; b=oSF4xcxeKpE9rOxFKXgwYX/rgsKqXmEebX3rX+TPysuaXUbwll4HfpAr9tDt8ugRZ1 QbLlLPuC5APuBkiiEpF71ap/Ry8PeWohncBn0Dw4FekV78+YuDOwkMfyz9fotNg1RGb7 Av2+7KEB9zVA+M/TWs+JLLhQ27RGKjjUxRnem1Bwmqy7oc4vuHoeluQHBXQTLgbcWtP/ yMtfv8an3VCF5hAHWco6y3J2bdXCSsv68umCbCp9+1M0OwrknQxkyMZfsSQbQt49iZmd PBTP8BoXKiojN3ghkZzU1eyfeX2XoXuyVWEkAtaXA3gwt5uNYUlGqSnGh7vpJfgeWNWT 0Z6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727734345; x=1728339145; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=grjpT5kTsMGjq3j1/lhkj4QBsxYe83DKBpMh5569Dgk=; b=OKi7Zl/qH9HKov04XGwsy6ohN+34NO/+Bu1YrrHDPcuZjyHzC3UocdSBh8O6HbjeT+ gkltoAiXeuf69ekI0N91TjeICiX4QQ2I8KifVwhXWfucUT+9rvZlw5o7ioDaUVLbhjWD povbnMxt0nGuH69tdmFln32o1kiPyTvjhfx3mSkC1UTBEI8lZVLwPpcNDzBwwkliXQ1x K8hAqtD2cOpgvlfvmxEMxxnoDS841wbgr8J74YJtYfMBh+dhDp4doD8XfFfWo7SaZ99n muTuv5FgYBR2EXiAkDuO8WV+ntDRi5SNxykFvcIUStwxxz0xAr7t0pacj6/wHJMmLimn vZXQ== X-Gm-Message-State: AOJu0YzYAcvJACtVIf3nvTUxS7lPfJbu8ra8Jgp+oLKaKw4DosfDogbG MJjtX7WYgd3hTlZG2o4HGGSLls1qVPcKYNj1qdl9JuJ2mvkLK+jaBlkxxNFutwT3lkf6TLNyi1L DnIE= X-Received: by 2002:a17:907:928b:b0:a89:f5f6:395 with SMTP id a640c23a62f3a-a93c48f0902mr1722277466b.1.1727734344660; Mon, 30 Sep 2024 15:12:24 -0700 (PDT) Received: from localhost.localdomain (46.170.88.92.rev.sfr.net. [92.88.170.46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c299ac60sm596492866b.221.2024.09.30.15.12.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Sep 2024 15:12:24 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Alistair Francis , Peter Maydell , Thomas Huth , Hao Wu , Laurent Vivier , Joel Stanley , qemu-arm@nongnu.org, Andrew Jeffery , Steven Lee , Tyrone Ting , "Edgar E. Iglesias" , Igor Mitsyanko , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Jamin Lin , Troy Lee , Anton Johansson Subject: [PATCH 2/3] hw/arm: Have arm_write_bootloader() take a ARMCPU argument Date: Tue, 1 Oct 2024 00:12:03 +0200 Message-ID: <20240930221205.59101-3-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240930221205.59101-1-philmd@linaro.org> References: <20240930221205.59101-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=philmd@linaro.org; helo=mail-ej1-x62f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org The next commit will replace tswap32() calls by stl_endian_p() ones in bootloader.c. In order to do that, we'll need to know the vCPU endianness. This information is retrievable with arm_cpu_code_is_big_endian(), but we need to access CPUARMState. As a first step, pass ARMCPU as argument to arm_write_bootloader() so it'll be able to access cpu->env. Signed-off-by: Philippe Mathieu-Daudé --- include/hw/arm/boot.h | 9 ++++++--- hw/arm/aspeed.c | 3 +-- hw/arm/boot.c | 9 +++++---- hw/arm/raspi.c | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/hw/arm/boot.h b/include/hw/arm/boot.h index 80c492d742..3d1226ab00 100644 --- a/include/hw/arm/boot.h +++ b/include/hw/arm/boot.h @@ -206,13 +206,15 @@ typedef struct ARMInsnFixup { /** * arm_write_bootloader - write a bootloader to guest memory * @name: name of the bootloader blob - * @as: AddressSpace to write the bootloader + * @cpu: handle to the first CPU object + * @info: handle to the boot info struct * @addr: guest address to write it * @insns: the blob to be loaded * @fixupcontext: context to be used for any fixups in @insns * * Write a bootloader to guest memory at address @addr in the address - * space @as. @name is the name to use for the resulting ROM blob, so + * space returned by @arm_boot_address_space(). + * @name is the name to use for the resulting ROM blob, so * it should be unique in the system and reasonably identifiable for debugging. * * @insns must be an array of ARMInsnFixup structs, each of which has @@ -228,7 +230,8 @@ typedef struct ARMInsnFixup { * the entries that @insns refers to. */ void arm_write_bootloader(const char *name, - AddressSpace *as, hwaddr addr, + ARMCPU *cpu, const struct arm_boot_info *info, + hwaddr addr, const ARMInsnFixup *insns, const uint32_t *fixupcontext); diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index cf0c6c580b..cf5fb92238 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -217,7 +217,6 @@ struct AspeedMachineState { static void aspeed_write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) { - AddressSpace *as = arm_boot_address_space(cpu, info); static const ARMInsnFixup poll_mailbox_ready[] = { /* * r2 = per-cpu go sign value @@ -244,7 +243,7 @@ static void aspeed_write_smpboot(ARMCPU *cpu, }; static const uint32_t fixupcontext[FIXUP_MAX] = { 0 }; - arm_write_bootloader("aspeed.smpboot", as, info->smp_loader_start, + arm_write_bootloader("aspeed.smpboot", cpu, info, info->smp_loader_start, poll_mailbox_ready, fixupcontext); } diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 5301d8d318..6efd21f9c2 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -131,10 +131,12 @@ static const ARMInsnFixup smpboot[] = { }; void arm_write_bootloader(const char *name, - AddressSpace *as, hwaddr addr, + ARMCPU *cpu, const struct arm_boot_info *info, + hwaddr addr, const ARMInsnFixup *insns, const uint32_t *fixupcontext) { + AddressSpace *as = arm_boot_address_space(cpu, info); /* Fix up the specified bootloader fragment and write it into * guest memory using rom_add_blob_fixed(). fixupcontext is * an array giving the values to write in for the fixup types @@ -185,7 +187,6 @@ static void default_write_secondary(ARMCPU *cpu, const struct arm_boot_info *info) { uint32_t fixupcontext[FIXUP_MAX]; - AddressSpace *as = arm_boot_address_space(cpu, info); fixupcontext[FIXUP_GIC_CPU_IF] = info->gic_cpu_if_addr; fixupcontext[FIXUP_BOOTREG] = info->smp_bootreg_addr; @@ -195,7 +196,7 @@ static void default_write_secondary(ARMCPU *cpu, fixupcontext[FIXUP_DSB] = CP15_DSB_INSN; } - arm_write_bootloader("smpboot", as, info->smp_loader_start, + arm_write_bootloader("smpboot", cpu, info, info->smp_loader_start, smpboot, fixupcontext); } @@ -1128,7 +1129,7 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, fixupcontext[FIXUP_ENTRYPOINT_LO] = entry; fixupcontext[FIXUP_ENTRYPOINT_HI] = entry >> 32; - arm_write_bootloader("bootloader", as, info->loader_start, + arm_write_bootloader("bootloader", cpu, info, info->loader_start, primary_loader, fixupcontext); if (info->write_board_setup) { diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index a7a662f40d..84fffe2a02 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -137,7 +137,7 @@ static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) QEMU_BUILD_BUG_ON((BOARDSETUP_ADDR & 0xf) != 0 || (BOARDSETUP_ADDR >> 4) >= 0x100); - arm_write_bootloader("raspi_smpboot", arm_boot_address_space(cpu, info), + arm_write_bootloader("raspi_smpboot", cpu, info, info->smp_loader_start, smpboot, fixupcontext); } @@ -172,7 +172,7 @@ static void write_smpboot64(ARMCPU *cpu, const struct arm_boot_info *info) 0, 0, 0, 0 }; - arm_write_bootloader("raspi_smpboot", as, info->smp_loader_start, + arm_write_bootloader("raspi_smpboot", cpu, info, info->smp_loader_start, smpboot, fixupcontext); rom_add_blob_fixed_as("raspi_spintables", spintables, sizeof(spintables), SPINTABLE_ADDR, as);