Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8942C4338F for ; Fri, 20 Aug 2021 16:58:05 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 24D626103A for ; Fri, 20 Aug 2021 16:58:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 24D626103A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1E15D82C0C; Fri, 20 Aug 2021 18:58:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 0664482D13; Fri, 20 Aug 2021 18:58:00 +0200 (CEST) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 7A83782999 for ; Fri, 20 Aug 2021 18:57:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=andre.przywara@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3E5B211FB; Fri, 20 Aug 2021 09:57:54 -0700 (PDT) Received: from [10.1.37.15] (e110479.cambridge.arm.com [10.1.37.15]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 087B63F70D; Fri, 20 Aug 2021 09:57:52 -0700 (PDT) Subject: Re: [PATCH v2 5/6] arm: Use armv8_switch_to_el1 env to switch to EL1 To: Peter Hoyes , u-boot@lists.denx.de Cc: patrick.delaunay@foss.st.com, sjg@chromium.org, diego.sueiro@arm.com, Tom Rini , Michael Walle , Priyanka Singh References: <20210819155314.1787973-1-peter.hoyes@arm.com> <20210819155314.1787973-6-peter.hoyes@arm.com> From: Andre Przywara Message-ID: <54bb4bcb-5c77-d5e5-50e2-9699424e8e9a@arm.com> Date: Fri, 20 Aug 2021 17:57:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210819155314.1787973-6-peter.hoyes@arm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On 8/19/21 4:53 PM, Peter Hoyes wrote: Hi, > From: Peter Hoyes > > Use the environment variable armv8_switch_to_el1 to determine whether > to switch to EL1 at runtime. This is an alternative to the > CONFIG_ARMV8_SWITCH_TO_EL1 compile-time option. This might be useful outside of the v8-R64 FVP. I cannot find CONFIG_ARMV8_SWITCH_TO_EL1 being set anywhere, which makes me wonder how this is used? Are there certain custom builds which define this somehow? In any case forcing "kernel" entry in either EL1 or EL2, and deciding this at runtime sounds useful for certain scenarios in general, and be it for debugging and testing. So shall we get rid of this compile time option at all, or shall this be retained to avoid extra code? > The environment variable will be ineffective if the ARMV8_MULTIENTRY > config is used. > > This is required by the Armv8r64 architecture, which must be able to > boot at S-EL1 for Linux but may need to boot at other ELs for other > systems. > > Signed-off-by: Peter Hoyes > --- > arch/arm/lib/bootm.c | 40 +++++++++++++++++++++++++--------------- > 1 file changed, 25 insertions(+), 15 deletions(-) > > diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c > index f60ee3a7e6..ea9bfe7570 100644 > --- a/arch/arm/lib/bootm.c > +++ b/arch/arm/lib/bootm.c > @@ -317,7 +317,6 @@ __weak void update_os_arch_secondary_cores(uint8_t os_arch) > { > } > > -#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 > static void switch_to_el1(void) > { > if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && > @@ -332,7 +331,6 @@ static void switch_to_el1(void) > ES_TO_AARCH64); > } > #endif > -#endif > > /* Subcommand: GO */ > static void boot_jump_linux(bootm_headers_t *images, int flag) > @@ -359,21 +357,33 @@ static void boot_jump_linux(bootm_headers_t *images, int flag) > > update_os_arch_secondary_cores(images->os.arch); > > -#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 > - armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, > - (u64)switch_to_el1, ES_TO_AARCH64); > +#ifdef CONFIG_ARMV8_MULTIENTRY > + int armv8_switch_to_el1 = -1; > #else > - if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && > - (images->os.arch == IH_ARCH_ARM)) > - armv8_switch_to_el2(0, (u64)gd->bd->bi_arch_number, > - (u64)images->ft_addr, 0, > - (u64)images->ep, > - ES_TO_AARCH32); > - else > - armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, > - images->ep, > - ES_TO_AARCH64); > + int armv8_switch_to_el1 = env_get_yesno("armv8_switch_to_el1"); > #endif > +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 > + if (armv8_switch_to_el1 == -1) { > + armv8_switch_to_el1 = 1; > + } > +#endif > + if (armv8_switch_to_el1 == 1) { This looks confusing. Can't we use CONFIG_IS_ENABLED() and override armv8_switch_to_el1, then use this one variable to trigger the action? Cheers, Andre > + armv8_switch_to_el2((u64)images->ft_addr, 0, 0, 0, > + (u64)switch_to_el1, ES_TO_AARCH64); > + } else { > + if ((IH_ARCH_DEFAULT == IH_ARCH_ARM64) && > + (images->os.arch == IH_ARCH_ARM)) > + armv8_switch_to_el2(0, > + (u64)gd->bd->bi_arch_number, > + (u64)images->ft_addr, 0, > + (u64)images->ep, > + ES_TO_AARCH32); > + else > + armv8_switch_to_el2((u64)images->ft_addr, > + 0, 0, 0, > + images->ep, > + ES_TO_AARCH64); > + } > } > #else > unsigned long machid = gd->bd->bi_arch_number; >