From patchwork Thu Oct 17 09:55:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 13839807 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B0D7CD2126D for ; Thu, 17 Oct 2024 10:20:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4ogCp1ImICNCR8MZ3pMeRCmtYBIUyjbryIzbyVCbAm8=; b=P+Q8U9jqa3wS6ehpkXRjOUwvAv KCybRFKZlTXX7MfKCo7B94F+SiN57KbV77ED3zMA1goSKYXWVODiP/mPASr1w1S0jRHccDZ+Vzv8C lQspZyuMzLasWK722qDZZ3KYrYcaFflAlTOQ52GuCjDpOvsvx5ynZTw/PGvJ1KTuyN4+dZLfSgk/s eTywTGUf2NDX05pkE3XFmkf7O3/zkWHvv57W4jhisLx3dQUBFq2aaATxGTc4wQ7UvKUx9eFh/ar5H HfN6TMm7IkiJh6/SYmNmhsYFVYQUMJZEuQspnIy1gNl+OSHdR3dZ8rxlS7UtLaf9SwxgOaj1RIU2Y ZbXIyzmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1Nc8-0000000EV2Y-11Py; Thu, 17 Oct 2024 10:20:16 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1NEB-0000000ER0v-146g for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 09:55:35 +0000 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 DCAFE1477; Thu, 17 Oct 2024 02:55:58 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9B64E3F71E; Thu, 17 Oct 2024 02:55:28 -0700 (PDT) From: Luca Fancellu To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org Subject: [boot-wrapper v4 1/4] Introduce --with-bw-arch for boot-wrapper compile arch Date: Thu, 17 Oct 2024 10:55:17 +0100 Message-Id: <20241017095520.939464-2-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017095520.939464-1-luca.fancellu@arm.com> References: <20241017095520.939464-1-luca.fancellu@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241017_025531_473563_09316CB3 X-CRM114-Status: UNSURE ( 8.83 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce a new autoconf parameter --with-bw-arch that takes 'aarch64-a' and 'aarch32-a' as compile architecture, the former is selected by default when the parameter is not passed. This new parameter superseed --enable-aarch32-bw, its functionality is now implemented by --with-bw-arch=aarch32-a. Signed-off-by: Luca Fancellu --- v4 changes: - changed help string for --with-bw-arch --- configure.ac | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index ce41daebc378..a1d2846a6865 100644 --- a/configure.ac +++ b/configure.ac @@ -9,9 +9,18 @@ AC_INIT([boot-wrapper], [v0.2]) AM_INIT_AUTOMAKE([foreign]) -AC_ARG_ENABLE([aarch32-bw], - AS_HELP_STRING([--enable-aarch32-bw], [build a 32-bit boot-wrapper]), - [BOOTWRAPPER_ES=32], [BOOTWRAPPER_ES=64]) +# Allow a user to pass --with-bw-arch={aarch64-a,aarch32-a} +AC_ARG_WITH([bw-arch], + AS_HELP_STRING([--with-bw-arch], [specify boot-wrapper architecture: aarch64-a (default) or aarch32-a]), + [case "${withval}" in + no|yes|aarch64-a) USE_ARCH=aarch64-a ;; + aarch32-a) USE_ARCH=aarch32-a ;; + *) AC_MSG_ERROR([Bad value "${withval}" for --with-bw-arch. Use "aarch64-a" or "aarch32-a"]) ;; + esac]) + +AS_IF([test "x$USE_ARCH" = "xaarch32-a"], + [BOOTWRAPPER_ES=32], [BOOTWRAPPER_ES=64] +) AM_CONDITIONAL([BOOTWRAPPER_32], [test "x$BOOTWRAPPER_ES" = "x32"]) AC_ARG_ENABLE([aarch32-kernel], From patchwork Thu Oct 17 09:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 13839813 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77B61D21274 for ; Thu, 17 Oct 2024 10:24:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=KoiKgh88atReQoKLMJPpkZhI2U36NuackzmzHtjaGIM=; b=POrYBudzGImyCoQTpS0psRzLPV H6/NafnCBCgx8w+BjPiDIQ7ilXZrz/GCxCWu6jreHBKfXZz238TS+AiP/wPlTRz5WMVWq78hSjf9r n2xTsuILtHdLx3hHupKh72kpGDgN0WYmkQNOeG2Z87jdpRmecT+/MsKxApQK8d+5LCUSBDD3FSWhC xDB0cuC9KfMDHYEq7rCXt9Xn15otVqKCBOwkiKIqPvM43Sj8t3eDD4GV5OjHo4qnZsDG7WjM3B+V6 i+O7mDjrYBRWEEzfI4fznUriiRpX68qVFrj3jKyP+1jMiKxycG/HTHZ13c+oGw0volwqvEhfeL2Kz fU4ByK3g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1NgN-0000000EVTp-0C1M; Thu, 17 Oct 2024 10:24:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1NEC-0000000ER1C-0vfT for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 09:55:39 +0000 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 C2E1A150C; Thu, 17 Oct 2024 02:55:59 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 814E93F71E; Thu, 17 Oct 2024 02:55:29 -0700 (PDT) From: Luca Fancellu To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org Subject: [boot-wrapper v4 2/4] aarch64: Enable Armv8-R EL2 boot Date: Thu, 17 Oct 2024 10:55:18 +0100 Message-Id: <20241017095520.939464-3-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017095520.939464-1-luca.fancellu@arm.com> References: <20241017095520.939464-1-luca.fancellu@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241017_025532_405974_A740A6A3 X-CRM114-Status: GOOD ( 19.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When booting on Armv8-R, EL3 is not implemented and the Linux kernel needs to be booted in EL1, so initialise EL2 and start the kernel in the expected exception level. To do so, introduce the 'aarch64-r' argument for the --with-bw-arch parameter. PSCI is not yet implemented for aarch64-r. Signed-off-by: Luca Fancellu --- v4 changes: - Remove _NOTRAP from HCR_EL2_*_NOTRAP registers - split checks for Armv8-R inside ID_AA64MMFR0_EL1 - reworked cpu_init_arch code to don't have #ifdef --- Makefile.am | 4 ++ arch/aarch64/boot.S | 5 +++ arch/aarch64/include/asm/cpu.h | 24 ++++++++++++ arch/aarch64/init.c | 68 +++++++++++++++++++++++++++++++++- configure.ac | 8 ++-- 5 files changed, 105 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6ee6afac9535..44ea3f7e0d7b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,6 +39,10 @@ DEFINES += $(if $(SYSREGS_BASE), -DSYSREGS_BASE=$(SYSREGS_BASE), ) DEFINES += -DUART_BASE=$(UART_BASE) DEFINES += -DSTACK_SIZE=256 +if BOOTWRAPPER_64R +DEFINES += -DBOOTWRAPPER_64R +endif + if KERNEL_32 DEFINES += -DKERNEL_32 PSCI_CPU_ON := 0x84000003 diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index 5060a6d5258f..565397823cb4 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -100,7 +100,12 @@ ASM_FUNC(jump_kernel) mov x1, x21 mov x2, x22 mov x3, x23 +#if defined(BOOTWRAPPER_64R) + // On Armv8-R Linux needs to be booted at EL1 + mov x4, #SPSR_KERNEL_EL1 +#else mov x4, #SPSR_KERNEL +#endif /* * If bit 0 of the kernel address is set, we're entering in AArch32 diff --git a/arch/aarch64/include/asm/cpu.h b/arch/aarch64/include/asm/cpu.h index a5744e16e4b2..0a6baa84bd72 100644 --- a/arch/aarch64/include/asm/cpu.h +++ b/arch/aarch64/include/asm/cpu.h @@ -32,10 +32,15 @@ (BIT(29) | BIT(28) | BIT(23) | BIT(22) | BIT(18) | BIT(16) | \ BIT(11) | BIT(5) | BIT(4)) +#define CPTR_EL2_NO_E2H_RES1 \ + (BITS(13,12) | BIT(9) | BITS(7,0)) + #define SCTLR_EL2_RES1 \ (BIT(29) | BIT(28) | BIT(23) | BIT(22) | BIT(18) | BIT(16) | \ BIT(11) | BIT(5) | BIT(4)) +#define VSTCR_EL2_RES1 (BIT(31)) + #define SCTLR_EL1_RES1 \ (BIT(29) | BIT(28) | BIT(23) | BIT(22) | BIT(20) | BIT(11) | \ BIT(8) | BIT(7) | BIT(4)) @@ -64,7 +69,13 @@ #define SCR_EL3_PIEN BIT(45) #define SCR_EL3_D128En BIT(47) +#define VTCR_EL2_MSA BIT(31) + #define HCR_EL2_RES1 BIT(1) +#define HCR_EL2_APK BIT(40) +#define HCR_EL2_API BIT(41) +#define HCR_EL2_FIEN BIT(47) +#define HCR_EL2_EnSCXT BIT(53) #define ID_AA64DFR0_EL1_PMSVER BITS(35, 32) #define ID_AA64DFR0_EL1_TRACEBUFFER BITS(47, 44) @@ -81,6 +92,8 @@ #define ID_AA64ISAR2_EL1_GPA3 BITS(11, 8) #define ID_AA64ISAR2_EL1_APA3 BITS(15, 12) +#define ID_AA64MMFR0_EL1_MSA BITS(51, 48) +#define ID_AA64MMFR0_EL1_MSA_frac BITS(55, 52) #define ID_AA64MMFR0_EL1_FGT BITS(59, 56) #define ID_AA64MMFR0_EL1_ECV BITS(63, 60) @@ -96,8 +109,12 @@ #define ID_AA64PFR1_EL1_MTE BITS(11, 8) #define ID_AA64PFR1_EL1_SME BITS(27, 24) +#define ID_AA64PFR1_EL1_CSV2_frac BITS(35, 32) #define ID_AA64PFR1_EL1_THE BITS(51, 48) + +#define ID_AA64PFR0_EL1_RAS BITS(31, 28) #define ID_AA64PFR0_EL1_SVE BITS(35, 32) +#define ID_AA64PFR0_EL1_CSV2 BITS(59, 56) #define ID_AA64SMFR0_EL1 s3_0_c0_c4_5 #define ID_AA64SMFR0_EL1_FA64 BIT(63) @@ -106,7 +123,9 @@ * Initial register values required for the boot-wrapper to run out-of-reset. */ #define SCTLR_EL3_RESET SCTLR_EL3_RES1 +#define CPTR_EL2_RESET CPTR_EL2_NO_E2H_RES1 #define SCTLR_EL2_RESET SCTLR_EL2_RES1 +#define VSTCR_EL2_RESET VSTCR_EL2_RES1 #define SCTLR_EL1_RESET SCTLR_EL1_RES1 #define HCR_EL2_RESET HCR_EL2_RES1 @@ -123,6 +142,7 @@ #define SPSR_I (1 << 7) /* IRQ masked */ #define SPSR_F (1 << 6) /* FIQ masked */ #define SPSR_T (1 << 5) /* Thumb */ +#define SPSR_EL1H (5 << 0) /* EL1 Handler mode */ #define SPSR_EL2H (9 << 0) /* EL2 Handler mode */ #define SPSR_HYP (0x1a << 0) /* M[3:0] = hyp, M[4] = AArch32 */ @@ -135,6 +155,9 @@ #define ICC_CTLR_EL3 S3_6_C12_C12_4 #define ICC_PMR_EL1 S3_0_C4_C6_0 +#define VSTCR_EL2 s3_4_c2_c6_2 +#define VSCTLR_EL2 s3_4_c2_c0_0 + #define ZCR_EL3 s3_6_c1_c2_0 #define ZCR_EL3_LEN_MAX 0xf @@ -162,6 +185,7 @@ #else #define SCTLR_EL1_KERNEL SCTLR_EL1_RES1 #define SPSR_KERNEL (SPSR_A | SPSR_D | SPSR_I | SPSR_F | SPSR_EL2H) +#define SPSR_KERNEL_EL1 (SPSR_A | SPSR_D | SPSR_I | SPSR_F | SPSR_EL1H) #endif #ifndef __ASSEMBLY__ diff --git a/arch/aarch64/init.c b/arch/aarch64/init.c index 63fa949653ee..9bbfce3aaf34 100644 --- a/arch/aarch64/init.c +++ b/arch/aarch64/init.c @@ -54,6 +54,27 @@ static inline bool cpu_has_permission_indirection(void) return mrs(ID_AA64MMFR3_EL1) & mask; } +static bool cpu_has_scxt(void) +{ + unsigned long csv2 = mrs_field(ID_AA64PFR0_EL1, CSV2); + + if (csv2 >= 2) + return true; + if (csv2 < 1) + return false; + + return mrs_field(ID_AA64PFR1_EL1, CSV2_frac) >= 2; +} + +static inline bool bootwrapper_is_r_class(void) +{ +#ifdef BOOTWRAPPER_64R + return true; +#else + return false; +#endif +} + static void cpu_init_el3(void) { unsigned long scr = SCR_EL3_RES1 | SCR_EL3_NS | SCR_EL3_HCE; @@ -157,6 +178,47 @@ static void cpu_init_el3(void) } } +void cpu_init_el2_armv8r(void) +{ + unsigned long hcr = mrs(hcr_el2); + + /* On Armv8-R ID_AA64MMFR0_EL1[51:48] == 0xF */ + if (mrs_field(ID_AA64MMFR0_EL1, MSA) != 0xF) { + print_string("ID_AA64MMFR0_EL1.MSA != 0xF, not R-class\r\n"); + while (1) + wfe(); + } + + if (mrs_field(ID_AA64MMFR0_EL1, MSA_frac) < 2) { + print_string("ID_AA64MMFR0_EL1.MSA_frac < 2, EL1&0 VMSA not supported\r\n"); + while (1) + wfe(); + } + + msr(vpidr_el2, mrs(midr_el1)); + msr(vmpidr_el2, mrs(mpidr_el1)); + + msr(VSCTLR_EL2, 0); + msr(VSTCR_EL2, VSTCR_EL2_RESET); + msr(vtcr_el2, VTCR_EL2_MSA); + + msr(cntvoff_el2, 0); + msr(cptr_el2, CPTR_EL2_RESET); + msr(mdcr_el2, 0); + + if (cpu_has_scxt()) + hcr |= HCR_EL2_EnSCXT; + + if (mrs_field(ID_AA64PFR0_EL1, RAS) >= 2) + hcr |= HCR_EL2_FIEN; + + if (cpu_has_pauth()) + hcr |= HCR_EL2_APK | HCR_EL2_API; + + msr(hcr_el2, hcr); + isb(); +} + #ifdef PSCI extern char psci_vectors[]; @@ -176,11 +238,15 @@ static void cpu_init_psci_arch(unsigned int cpu) { } void cpu_init_arch(unsigned int cpu) { - if (mrs(CurrentEL) == CURRENTEL_EL3) { + if (!bootwrapper_is_r_class() && mrs(CurrentEL) == CURRENTEL_EL3) { cpu_init_el3(); gic_secure_init(); } + if (bootwrapper_is_r_class() && mrs(CurrentEL) == CURRENTEL_EL2) { + cpu_init_el2_armv8r(); + } + cpu_init_psci_arch(cpu); msr(CNTFRQ_EL0, COUNTER_FREQ); diff --git a/configure.ac b/configure.ac index a1d2846a6865..95e2b7f05756 100644 --- a/configure.ac +++ b/configure.ac @@ -9,14 +9,16 @@ AC_INIT([boot-wrapper], [v0.2]) AM_INIT_AUTOMAKE([foreign]) -# Allow a user to pass --with-bw-arch={aarch64-a,aarch32-a} +# Allow a user to pass --with-bw-arch={aarch64-a,aarch32-a,aarch64-r} AC_ARG_WITH([bw-arch], - AS_HELP_STRING([--with-bw-arch], [specify boot-wrapper architecture: aarch64-a (default) or aarch32-a]), + AS_HELP_STRING([--with-bw-arch], [specify boot-wrapper architecture: aarch64-a (default), aarch32-a or aarch64-r]), [case "${withval}" in no|yes|aarch64-a) USE_ARCH=aarch64-a ;; aarch32-a) USE_ARCH=aarch32-a ;; - *) AC_MSG_ERROR([Bad value "${withval}" for --with-bw-arch. Use "aarch64-a" or "aarch32-a"]) ;; + aarch64-r) USE_ARCH=aarch64-r ;; + *) AC_MSG_ERROR([Bad value "${withval}" for --with-bw-arch. Use "aarch64-a", "aarch32-a" or "aarch64-r"]) ;; esac]) +AM_CONDITIONAL([BOOTWRAPPER_64R], [test "x$USE_ARCH" = "xaarch64-r"]) AS_IF([test "x$USE_ARCH" = "xaarch32-a"], [BOOTWRAPPER_ES=32], [BOOTWRAPPER_ES=64] From patchwork Thu Oct 17 09:55:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 13839808 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73FC4D21274 for ; Thu, 17 Oct 2024 10:21:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9ZVoUsc3gCkSydV+NTS3AUww6pPp0B7Wid62TAZPJus=; b=kuHP30SYjxuAC/Ueldue6fepsy MsMHdL4JS9sgo/tYs+AhIeI1SWPnwePw1/FC/X5lCb0higWz/mt71kbPcCvdP2OEY9o39IQ8xOITg 1aPLQHWMntUjmOSrcAXBt+JZQoyXF0o1yPAVHGo0bbkAvZMiZ9kjcCEHNIzIAq8acgYhTY2mJTkwT BCGiYkTyWdBv+L79RMsptF1Z8B1heoOj8yDqGMTUkf7KXfwwVL1jd5Wd1MupN3zNHG2+qvZBiDLOb UEwo71ljpuL3Vm34OK/6pDoMjkefnYurheV2LeGMIG0hoHWKfKHpxmE86sqGnDMcuMvqlvs6s+irw E4mmiBxg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1NdY-0000000EVDe-16sb; Thu, 17 Oct 2024 10:21:44 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1NEB-0000000ER1c-1pzJ for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 09:55:35 +0000 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 A7EA91570; Thu, 17 Oct 2024 02:56:00 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 66E4E3F71E; Thu, 17 Oct 2024 02:55:30 -0700 (PDT) From: Luca Fancellu To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org Subject: [boot-wrapper v4 3/4] aarch64: Implement PSCI for Armv8-R Date: Thu, 17 Oct 2024 10:55:19 +0100 Message-Id: <20241017095520.939464-4-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017095520.939464-1-luca.fancellu@arm.com> References: <20241017095520.939464-1-luca.fancellu@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241017_025531_616530_AA4F5FCA X-CRM114-Status: GOOD ( 11.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Armv8-R doesn't have EL3, so the PSCI vector needs to be installed in VBAR_EL2 and the conduit needs to be 'hcv' instead of 'smc'. Implement the modifications needed when --with-bw-arch is 'aarch64-r'. Signed-off-by: Luca Fancellu --- v4 changes: - rework cpu_init_psci_arch code to don't have #ifdef --- Makefile.am | 2 +- arch/aarch64/init.c | 15 +++++++++++---- configure.ac | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index 44ea3f7e0d7b..aecda694fd6c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -71,7 +71,7 @@ ARCH_OBJ += psci.o COMMON_OBJ += psci.o PSCI_NODE := psci { \ compatible = \"arm,psci\"; \ - method = \"smc\"; \ + method = \"$(PSCI_METHOD)\"; \ cpu_on = <$(PSCI_CPU_ON)>; \ cpu_off = <$(PSCI_CPU_OFF)>; \ }; diff --git a/arch/aarch64/init.c b/arch/aarch64/init.c index 9bbfce3aaf34..da036bb0b947 100644 --- a/arch/aarch64/init.c +++ b/arch/aarch64/init.c @@ -224,13 +224,20 @@ extern char psci_vectors[]; static void cpu_init_psci_arch(unsigned int cpu) { - if (mrs(CurrentEL) != CURRENTEL_EL3) { - print_cpu_warn(cpu, "PSCI could not be initialized (not booted at EL3).\r\n"); + if (!bootwrapper_is_r_class() && mrs(CurrentEL) == CURRENTEL_EL3) { + msr(VBAR_EL3, (unsigned long)psci_vectors); + isb(); return; } - msr(VBAR_EL3, (unsigned long)psci_vectors); - isb(); + if (bootwrapper_is_r_class() && mrs(CurrentEL) == CURRENTEL_EL2) { + msr(VBAR_EL2, (unsigned long)psci_vectors); + isb(); + return; + } + + print_cpu_warn(cpu, "PSCI could not be initialized (not booted at EL3).\r\n"); + } #else static void cpu_init_psci_arch(unsigned int cpu) { } diff --git a/configure.ac b/configure.ac index 95e2b7f05756..a433c89bd2ae 100644 --- a/configure.ac +++ b/configure.ac @@ -107,6 +107,9 @@ AC_ARG_ENABLE([psci], [USE_PSCI=$enableval], [USE_PSCI="yes"]) AM_CONDITIONAL([PSCI], [test "x$USE_PSCI" = "xyes"]) AS_IF([test "x$USE_PSCI" = "xyes"], [], [USE_PSCI=no]) +AS_IF([test "x$USE_ARCH" = "xaarch64-r"], + AC_SUBST([PSCI_METHOD], [hvc]), AC_SUBST([PSCI_METHOD], [smc]) +) AS_IF([test "x$USE_PSCI" != "xyes" -a "x$KERNEL_ES" = "x32"], [AC_MSG_ERROR([With an AArch32 kernel, boot method must be PSCI.])] From patchwork Thu Oct 17 09:55:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Fancellu X-Patchwork-Id: 13839812 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 611E7D2126D for ; Thu, 17 Oct 2024 10:23:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+2LM/Gh6G6ZmOqRhESdZZWhJZ0Yxqio+A7yy1o9baHk=; b=Iiz1f5LMYBsMOQsqMoBpPTQj+J 0oF4nAld89JEP9jyn/tbjXVLtKIuYaeXouwRD5yLu/C2rTtDyNhBItxGV9KsjsTPen4n3IuKhmMBh OpFJfTapgrCyz3tWkENEtnlxUzESlDfE291Ln079yNRqKDKlnYjm1RBn6QWPbsBJgTsznp8V/I447 BXhymNBKGw0iQ5tf/YaBOYTb/OZmiqMvTMNnoBkYrsqH4T/ch30yzLkflh8hgUHN5GQcnY7l3lAaR YZyCQEIZR+tNnJ7zLX9GxQk6wpUn+lWTe0BSEgFwPKR5B723do9yVbe7vbo5ROlWeHo44kLG44Pvq +vxD4mLA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1Nex-0000000EVM8-0CYN; Thu, 17 Oct 2024 10:23:11 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t1NEC-0000000ER2H-15L5 for linux-arm-kernel@lists.infradead.org; Thu, 17 Oct 2024 09:55:39 +0000 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 8D9F41595; Thu, 17 Oct 2024 02:56:01 -0700 (PDT) Received: from e125770.cambridge.arm.com (e125770.arm.com [10.1.199.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4C4F93F71E; Thu, 17 Oct 2024 02:55:31 -0700 (PDT) From: Luca Fancellu To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org Subject: [boot-wrapper v4 4/4] aarch64: Start Xen on Armv8-R at EL2 Date: Thu, 17 Oct 2024 10:55:20 +0100 Message-Id: <20241017095520.939464-5-luca.fancellu@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017095520.939464-1-luca.fancellu@arm.com> References: <20241017095520.939464-1-luca.fancellu@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241017_025532_379407_409A7EDC X-CRM114-Status: GOOD ( 10.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When bootwrapper is compiled with Xen support and it is started at EL2 on Armv8-R AArch64, keep the current EL and jump to the Xen image using the SPSR_KERNEL as spsr_el2 value. Signed-off-by: Luca Fancellu --- v4 changes: - no changes --- Makefile.am | 1 + arch/aarch64/boot.S | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index aecda694fd6c..a8d5c1b96822 100644 --- a/Makefile.am +++ b/Makefile.am @@ -127,6 +127,7 @@ XEN_CHOSEN := xen,xen-bootargs = \"$(XEN_CMDLINE)\"; \ compatible = \"xen,linux-zimage\", \"xen,multiboot-module\"; \ reg = <0x0 $(DOM0_OFFSET) 0x0 $(KERNEL_SIZE)>; \ }; +DEFINES += -DXEN endif if INITRD diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index 565397823cb4..3fcc63bf2437 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -100,7 +100,7 @@ ASM_FUNC(jump_kernel) mov x1, x21 mov x2, x22 mov x3, x23 -#if defined(BOOTWRAPPER_64R) +#if defined(BOOTWRAPPER_64R) && !defined(XEN) // On Armv8-R Linux needs to be booted at EL1 mov x4, #SPSR_KERNEL_EL1 #else