From patchwork Fri May 21 10:48:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaxson Han X-Patchwork-Id: 12272899 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 AD9E5C433B4 for ; Fri, 21 May 2021 10:51:02 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 72DC1613B6 for ; Fri, 21 May 2021 10:51:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 72DC1613B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YU52vQB1TDgw835mH/3VQo1u3RzMrihH54vPbRBjsQQ=; b=JUb2R6tHd4wxAj5vKzr3CozbYF PfkD/Hj4c1e3+aBss4fju6LbcusjnaySYpc8DYxkUUYZhnNiaF0ysM2KBh65A49O+XeLUkCE7St7R 3+Qz+77WZI0wfkPFbOhhcIi952idLK8rQr1dUou3f3Le6p0LjC14D9OfHDM5uIRbozyV2Tprz+k0A 2euYmwxlOU+FGkre9GZiflFiHtZbLTEIxy7+T+5cSokDja9H5AwlSAor0XG+ODekakdwKonfCjRyi JL1uzw9y3HuQdgjTIHf7aJ8sy34CwfeuRZCRXIleunpaRiNjZyRhI72qDdAtCpakDK6XudmStTyDA H4JALtIA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2hm-00506L-5B; Fri, 21 May 2021 10:48:34 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2hi-00505C-VK for linux-arm-kernel@desiato.infradead.org; Fri, 21 May 2021 10:48:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=sd0Bmaqah4VjZKs1fAZMSitNJVLkB5Af5L1JhWa9E14=; b=PW1lm+jGTerm0aKICHe1BnTKwS aefdKFXHWmjkh2d7WVrFQwHqhcrap2e+lUS86klodHvK0uGnQAuGaMIPdISL97Za6QA/tRo1KLPK0 ofRRycbm2FTFOWgchqVGHpCn2jXOpPC3+VFkFzeege8PIGpXiVlIUYrmJrge3oz07YdijYA497TGW +Hmvo9I8nsc4c5D7+TB3DS0mPLIUGwM/pcqKrLDy0dSkwvaC5TdMF73UThnd3i423auSCv/+2RncV bbM0mJIhzkD1xo83LzTQQxtDshlAFQ5qtTQk7Fq3hKvCK2l/vVMk6c20ZWylgjyIwM0QEUwso0qLJ y4ukhRRQ==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lk2he-00H37L-5n for linux-arm-kernel@lists.infradead.org; Fri, 21 May 2021 10:48:29 +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 7E3461480; Fri, 21 May 2021 03:48:23 -0700 (PDT) Received: from optiplex-7070.shanghai.arm.com (optiplex-7070.shanghai.arm.com [10.169.188.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A81323F73D; Fri, 21 May 2021 03:48:21 -0700 (PDT) From: Jaxson Han To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org, wei.chen@arm.com, jaxson.han@arm.com Subject: [boot-wrapper PATCH v2 1/8] Decouple V2M_SYS config by auto-detect dtb node Date: Fri, 21 May 2021 18:48:00 +0800 Message-Id: <20210521104807.138269-2-jaxson.han@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210521104807.138269-1-jaxson.han@arm.com> References: <20210521104807.138269-1-jaxson.han@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210521_034826_283829_7A0022E9 X-CRM114-Status: GOOD ( 11.43 ) 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 An auto-detect switch is added to make it an option to enable/disable 'arm,vexpress-sysreg', because not all platforms support this feature. But the auto-detection generates the side-effect of printing a warning message about the missing node: No matching devices found at ./findbase.pl line 37. In this case, to drop the warning message, add "2> /dev/null" at the end of the findbase.pl call. Signed-off-by: Jaxson Han Reviewed-by: Andre Przywara --- Makefile.am | 4 ++-- platform.c | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index af694b7..ef6b793 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,7 +10,7 @@ # VE PHYS_OFFSET := $(shell perl -I $(top_srcdir) $(top_srcdir)/findmem.pl $(KERNEL_DTB)) UART_BASE := $(shell perl -I $(top_srcdir) $(top_srcdir)/findbase.pl $(KERNEL_DTB) 0 'arm,pl011') -SYSREGS_BASE := $(shell perl -I $(top_srcdir) $(top_srcdir)/findbase.pl $(KERNEL_DTB) 0 'arm,vexpress-sysreg') +SYSREGS_BASE := $(shell perl -I $(top_srcdir) $(top_srcdir)/findbase.pl $(KERNEL_DTB) 0 'arm,vexpress-sysreg' 2> /dev/null) CNTFRQ := 0x01800000 # 24Mhz CPU_IDS := $(shell perl -I $(top_srcdir) $(top_srcdir)/findcpuids.pl $(KERNEL_DTB)) @@ -19,7 +19,7 @@ NR_CPUS := $(shell echo $(CPU_IDS) | tr ',' ' ' | wc -w) DEFINES = -DCNTFRQ=$(CNTFRQ) DEFINES += -DCPU_IDS=$(CPU_IDS) DEFINES += -DNR_CPUS=$(NR_CPUS) -DEFINES += -DSYSREGS_BASE=$(SYSREGS_BASE) +DEFINES += $(if $(SYSREGS_BASE), -DSYSREGS_BASE=$(SYSREGS_BASE), ) DEFINES += -DUART_BASE=$(UART_BASE) DEFINES += -DSTACK_SIZE=256 diff --git a/platform.c b/platform.c index a528a55..d11f568 100644 --- a/platform.c +++ b/platform.c @@ -23,10 +23,12 @@ #define PL011(reg) ((void *)UART_BASE + PL011_##reg) +#ifdef SYSREGS_BASE #define V2M_SYS_CFGDATA 0xa0 #define V2M_SYS_CFGCTRL 0xa4 #define V2M_SYS(reg) ((void *)SYSREGS_BASE + V2M_SYS_##reg) +#endif static void print_string(const char *str) { @@ -59,6 +61,7 @@ void init_platform(void) print_string("Boot-wrapper v0.2\r\n\r\n"); +#ifdef SYSREGS_BASE /* * CLCD output site MB */ @@ -66,4 +69,5 @@ void init_platform(void) /* START | WRITE | MUXFPGA | SITE_MB */ raw_writel((1 << 31) | (1 << 30) | (7 << 20) | (0 << 16), V2M_SYS(CFGCTRL)); +#endif } From patchwork Fri May 21 10:48:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaxson Han X-Patchwork-Id: 12272903 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 6FEB9C433B4 for ; Fri, 21 May 2021 10:51:20 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E0301613B6 for ; Fri, 21 May 2021 10:51:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0301613B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lxs15fx2Q4nAD4tvjX+5vGbvG1jznOejiLdFPpGr284=; b=a9uwW6zyLAgc/9DRbiCBzALiR6 4UmyORU4TQx2tJKxHxDffR+GBTi2vOL+bQJx1ticARAaDOcoCYiPQZdD4fnN6DeoUV7Sby3dVhgu8 dnCWUgSphK7iOMLzi/3wUXOY1XwxUI//l6OBy2AMAt55MRnSrLkNPyOZxbGdxyIw1h98VoKftvw1l b4wKARd5FEt/vpoljeuX4NEHxRMgd9EkufYOpr29wmKXvBYpwPlrVIcZ4Eh8+e6QSNbhi35SQIIM6 bRDwmLRzXgJwLmzD8AUN8fdoHcPrRF88B0qAUlV9APUfwBm+XTH9sFAsfDbLB2SyG/CKlWuOjRyyG 8DlggWgg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2i7-0050Cx-Ge; Fri, 21 May 2021 10:48:55 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2hi-00505I-V1 for linux-arm-kernel@desiato.infradead.org; Fri, 21 May 2021 10:48:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=KiXUhnQj0xz9y9hznwubzQmx28u8Uk55GtMTk/LYj5c=; b=erY4Z5q2UJ/y+cx3H7GGlMiIcq 9JwSQnVjqWH5ljJPOGfAyj50FAvQQEuyEWi5ZkzJScL94e0E4tEmWWK/xQaNgpkKYqDiKFxVYGRKH JT1LP8R9NGfWmY2Jikcmi65E2L8js8CSrfamA8dayeyZ0YS/Kjtb9ciaMCySV1v8Vv2/CscOURubb Di1SJMg0PHSen6vxO66vOMX3Zet1aDZmSwSMxv+N/JniaRJe2lDWg+B36LtHAv2kPPCwDTekuf45q lk7s0sdd5LhKIW9sm5c3ZQxHyeA5BYeatEiyz++KZ5BP2DIEjpwWt0AlFo6CyEfVBfP/rmLNhosQW BXsz4BDw==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lk2he-00H37v-QQ for linux-arm-kernel@lists.infradead.org; Fri, 21 May 2021 10:48:29 +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 CE59E150C; Fri, 21 May 2021 03:48:25 -0700 (PDT) Received: from optiplex-7070.shanghai.arm.com (optiplex-7070.shanghai.arm.com [10.169.188.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 049793F73D; Fri, 21 May 2021 03:48:23 -0700 (PDT) From: Jaxson Han To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org, wei.chen@arm.com, jaxson.han@arm.com Subject: [boot-wrapper PATCH v2 2/8] aarch64: Rename labels and prepare for lower EL booting Date: Fri, 21 May 2021 18:48:01 +0800 Message-Id: <20210521104807.138269-3-jaxson.han@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210521104807.138269-1-jaxson.han@arm.com> References: <20210521104807.138269-1-jaxson.han@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210521_034826_996747_DBA0AF43 X-CRM114-Status: GOOD ( 12.56 ) 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 Prepare for booting from lower EL. Rename *_el3 relavant labels with *_el_max and *_no_el3 with *_keep_el. Since the original _no_el3 means "We neither do init sequence at this highest EL nor drop to lower EL when entering to kernel", we rename it with _keep_el to make it more clear for lower EL initialisation. Signed-off-by: Jaxson Han --- arch/aarch64/boot.S | 33 ++++++++++++++++++++++----------- arch/aarch64/include/asm/cpu.h | 3 +++ arch/aarch64/psci.S | 13 +++++++------ arch/aarch64/spin.S | 8 ++++---- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index a9264de..e4f5f3d 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -12,7 +12,7 @@ .section .init .globl _start - .globl jump_kernel + .globl jump_kernel _start: cpuid x0, x1 @@ -22,20 +22,31 @@ _start: bl setup_stack /* - * EL3 initialisation + * Boot sequence + * If CurrentEL == EL3, then goto EL3 initialisation and drop to + * lower EL before entering the kernel. + * Else, no initialisation and keep the current EL before + * entering the kernel. */ mrs x0, CurrentEL cmp x0, #CURRENTEL_EL3 - b.eq 1f + beq el3_init + /* + * We stay in the current EL for entering the kernel + */ mov w0, #1 - ldr x1, =flag_no_el3 + ldr x1, =flag_keep_el str w0, [x1] bl setup_stack - b start_no_el3 + b start_keep_el -1: mov x0, #0x30 // RES1 + /* + * EL3 initialisation + */ +el3_init: + mov x0, #0x30 // RES1 orr x0, x0, #(1 << 0) // Non-secure EL1 orr x0, x0, #(1 << 8) // HVC enable @@ -114,7 +125,7 @@ _start: bl gic_secure_init - b start_el3 + b start_el_max err_invalid_id: b . @@ -141,7 +152,7 @@ jump_kernel: bl find_logical_id bl setup_stack // Reset stack pointer - ldr w0, flag_no_el3 + ldr w0, flag_keep_el cmp w0, #0 // Prepare Z flag mov x0, x20 @@ -150,9 +161,9 @@ jump_kernel: mov x3, x23 b.eq 1f - br x19 // No EL3 + br x19 // Keep current EL -1: mov x4, #SPSR_KERNEL +1: ldr w4, #SPSR_KERNEL /* * If bit 0 of the kernel address is set, we're entering in AArch32 @@ -168,5 +179,5 @@ jump_kernel: .data .align 3 -flag_no_el3: +flag_keep_el: .long 0 diff --git a/arch/aarch64/include/asm/cpu.h b/arch/aarch64/include/asm/cpu.h index ccb5397..2b3a0a4 100644 --- a/arch/aarch64/include/asm/cpu.h +++ b/arch/aarch64/include/asm/cpu.h @@ -11,6 +11,7 @@ #define MPIDR_ID_BITS 0xff00ffffff +#define CURRENTEL_EL2 (2 << 2) #define CURRENTEL_EL3 (3 << 2) /* @@ -24,6 +25,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 */ @@ -42,6 +44,7 @@ #else #define SCTLR_EL1_RESET 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/psci.S b/arch/aarch64/psci.S index 01ebe7d..ae02fd6 100644 --- a/arch/aarch64/psci.S +++ b/arch/aarch64/psci.S @@ -45,8 +45,8 @@ vector: .text - .globl start_no_el3 - .globl start_el3 + .globl start_keep_el + .globl start_el_max err_exception: b err_exception @@ -101,7 +101,7 @@ smc_exit: eret -start_el3: +start_el_max: ldr x0, =vector bl setup_vector @@ -111,10 +111,11 @@ start_el3: b psci_first_spin /* - * This PSCI implementation requires EL3. Without EL3 we'll only boot the - * primary cpu, all others will be trapped in an infinite loop. + * This PSCI implementation requires the highest EL(EL3 or Armv8-R EL2). + * Without the highest EL, we'll only boot the primary cpu, all others + * will be trapped in an infinite loop. */ -start_no_el3: +start_keep_el: cpuid x0, x1 bl find_logical_id cbz x0, psci_first_spin diff --git a/arch/aarch64/spin.S b/arch/aarch64/spin.S index 72603cf..533177c 100644 --- a/arch/aarch64/spin.S +++ b/arch/aarch64/spin.S @@ -11,11 +11,11 @@ .text - .globl start_no_el3 - .globl start_el3 + .globl start_keep_el + .globl start_el_max -start_el3: -start_no_el3: +start_el_max: +start_keep_el: cpuid x0, x1 bl find_logical_id From patchwork Fri May 21 10:48:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaxson Han X-Patchwork-Id: 12272905 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 782A9C433ED for ; Fri, 21 May 2021 10:51:30 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3BC3360FE3 for ; Fri, 21 May 2021 10:51:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BC3360FE3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Y7iGxj2fTB8Mv8KUhthCkyaNrsvKPV+DPFt2M9UCybQ=; b=GT/kd2jRORhqZfxt4q3A7cX8gP WLXWxHws99p1liemsYeGeemHcZF9r72DuXEvGPOcGOWPvjbJhC0yVk5X+m4oDvPQdGk1zSNPLUuX5 3MMILhNl2e3lQ6l6+sCC+LP8K6ixwOMuVHn0IlPOQB0dgLEbWgWFtT0Y4FfW/ATVbqdvoTl9YUTXJ qAhRqJwFxAmlPSuFccynFq+hSTtn+zpZftwYiSFB28TqtmLb8E0k2k+ktWYKTiEnPmRpDItlvvMUQ HkKUVBeJMPChhyjLEmY9gE5p7NZbF4CHthhruNUNRDTa5ZXf9sFB2hOwrcKLfKgYRnB3cJ3RUciBi awn0YzvQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2iL-0050HC-MD; Fri, 21 May 2021 10:49:09 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2hl-00506K-UI for linux-arm-kernel@desiato.infradead.org; Fri, 21 May 2021 10:48:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=EX8eg+9H7lgsE09e1Cx2sz1jv6vOnJLx9sPbTXcBQF0=; b=ZTvfrd2jbZ4ORrVJSCvKy7tOwM 2BfVNv8g1XJTaT6hOByfiLU9yz30FGeFi8lOJCEw/t/Py+KtH3eXrQ30pLuCeXzwIlgauVssFC1da NJvHwyURv7dKdCTDAzwLpZTvN7+YnAM7Kt2VI0xTisCzXOyOllSdf+8Ltv0ThLYTvgksWGe74K+9y 2dtOu4nVnvmUdOck8J0BeCH76d98/qOgY09hekuh4ro2+cNEQHb8IaAc1czhe+8xYdSY2g9eeMqmv EzaqB+iCctIol8ndVrO+MTieg1z/ZJZN3TKt8mdlokksFXiD/0S1JyugM9YOxCjkEMKpJL+UtmH5K SZKNv0Xg==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lk2hj-00H38f-9K for linux-arm-kernel@lists.infradead.org; Fri, 21 May 2021 10:48:32 +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 336F81515; Fri, 21 May 2021 03:48:28 -0700 (PDT) Received: from optiplex-7070.shanghai.arm.com (optiplex-7070.shanghai.arm.com [10.169.188.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 54BD73F73D; Fri, 21 May 2021 03:48:26 -0700 (PDT) From: Jaxson Han To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org, wei.chen@arm.com, jaxson.han@arm.com Subject: [boot-wrapper PATCH v2 3/8] aarch64: Remove the redundant setup_stack Date: Fri, 21 May 2021 18:48:02 +0800 Message-Id: <20210521104807.138269-4-jaxson.han@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210521104807.138269-1-jaxson.han@arm.com> References: <20210521104807.138269-1-jaxson.han@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210521_034831_388557_C8057F66 X-CRM114-Status: UNSURE ( 7.88 ) 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 Since we already have set up a stack above, there is no need to do it again. Signed-off-by: Jaxson Han Reviewed-by: Andre Przywara --- arch/aarch64/boot.S | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index e4f5f3d..ee9886b 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -39,7 +39,6 @@ _start: ldr x1, =flag_keep_el str w0, [x1] - bl setup_stack b start_keep_el /* From patchwork Fri May 21 10:48:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaxson Han X-Patchwork-Id: 12272907 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=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_GIT 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 59825C433ED for ; Fri, 21 May 2021 10:51:47 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id EB8A26108D for ; Fri, 21 May 2021 10:51:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB8A26108D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=4ClvL43WPiQrxPALxn2fEtWJPGFDN4lDEKReYJanEI4=; b=hZiOInQfzZ9Wk2Lo9ww69x24Py D51yogiOgQxKNUqxk+n8PshLSDE4GhM0VSSUmasqZWRej03uMWDPxGjlRyzuS9vFPhzRtf3D9o97W 9CvTUZtfc71EXogeSi2Qwq+K8b5Qlkv1gjCaTGSpiO+FcqbNGsvJODK8rAcn5rT8yMqDZe+npjxUP lsTFzNKCaB6hJwxqGWwa+Wo0Jioh9g3gTs75eF+gz4h3W4DAU0CvUkQjTbc+94E7y8hfrAJpufsPr cOwtNLydeosGKQ32HF27NSMaTVvfAnOvoa1Iq580ZskMIMOs14lfSUCgPqoB5SgxN+L6HUEbxo46a fm4eELcA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2iW-0050Mf-B7; Fri, 21 May 2021 10:49:20 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2hm-00506Z-Iw for linux-arm-kernel@desiato.infradead.org; Fri, 21 May 2021 10:48:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=hDyN3Cw2MSa5/z0aVgdtUvTNf8//dL1KLzn3s7gGhlg=; b=QBGZcIPRQU0OBtX9Pbny581jkP ZslsnpufVvV2ayQKalgwjJ0gLmknTZsjQ0F+PEktYOPWj+qQPbDaJI7EU09ZH7qRGPela/81ds+Ho r8X9FzS/Zu4PqLpMTFzSfmgdoANH1htUSZgzqKDFHPPmS5lEeTK4ilxMRfRHcCfuk5/59xqLEXP2P /qilGeDF1uPnIpcuNs/sAE8IAkQvDUzBJFI4ysEiVN2KZvNGcbkWFxnXr4OWVAmnKDNor4tGBYi2F A6ADUUahEyfGT26i6jCvgBArLb6bR9WcPrybElsh+5fmv9F2mlMtidyDEasGdFkd6bS7LGjePuO7p hjOqnjfQ==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lk2hj-00H38v-Si for linux-arm-kernel@lists.infradead.org; Fri, 21 May 2021 10:48:33 +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 8D2C91424; Fri, 21 May 2021 03:48:30 -0700 (PDT) Received: from optiplex-7070.shanghai.arm.com (optiplex-7070.shanghai.arm.com [10.169.188.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id ADC9E3F73D; Fri, 21 May 2021 03:48:28 -0700 (PDT) From: Jaxson Han To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org, wei.chen@arm.com, jaxson.han@arm.com Subject: [boot-wrapper PATCH v2 4/8] aarch64: Prepare for EL1 booting Date: Fri, 21 May 2021 18:48:03 +0800 Message-Id: <20210521104807.138269-5-jaxson.han@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210521104807.138269-1-jaxson.han@arm.com> References: <20210521104807.138269-1-jaxson.han@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210521_034831_988685_6BEF5BD1 X-CRM114-Status: UNSURE ( 7.43 ) 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 When booting from EL1, add a check and skip the init of sctlr_el2 in jump_kernel Signed-off-by: Jaxson Han Reviewed-by: Andre Przywara --- arch/aarch64/boot.S | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index ee9886b..b8f9e4e 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -144,10 +144,14 @@ jump_kernel: ldr x0, =SCTLR_EL1_RESET msr sctlr_el1, x0 + mrs x0, CurrentEL + cmp x0, #CURRENTEL_EL2 + b.lt 1f + ldr x0, =SCTLR_EL2_RESET msr sctlr_el2, x0 - cpuid x0, x1 +1: cpuid x0, x1 bl find_logical_id bl setup_stack // Reset stack pointer From patchwork Fri May 21 10:48:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaxson Han X-Patchwork-Id: 12272909 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 2ECA1C433ED for ; Fri, 21 May 2021 10:51:55 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C94936108D for ; Fri, 21 May 2021 10:51:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C94936108D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=NyptQ0AT9aHf+ppKwNY7D3Ozt19Pch/rgS0AWMurX6k=; b=atENihKZB4jCJTD9UvEseUJLXH Jy8lo4FtImlGcWmxh7facpY7JIcArHyNpNozRKpRLKvjcD13H1Pet+ntb0ZArZO0qjLobKMOfE/qA 4Q85u+t+VmwfqdeUMBwOJODtBRAGj7Ad05JRKWxHpBGIpX1XpNTMd6YleIiSaHJNpSc0AJjNR00Av GO9y1kVSv9i+8da2UEIM78zPKPxMkL3I1cO1gAlCixmFk9gdGxBX/qAHdMVPVEhzXne/Kfh/HTx/n QHC3cG8Rqlm7qMxpsJ6kDCFip0RqsnXrSokbFbIC6yWLfH2marpp53SuJ5hNDxMUEVhCZQdfjcOX3 V1NWsPUA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2ii-0050TS-9J; Fri, 21 May 2021 10:49:32 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2ho-005070-Gf for linux-arm-kernel@desiato.infradead.org; Fri, 21 May 2021 10:48:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=5X92pcB78TCtdiHmdQN/7SWTQ87VG7xvJ3LF48iZihg=; b=dXTVaRPAm/3YYpOD8AWpo8glmi puQoCyersy4LKNuqsK/6AWprujrrdiq+lYMoqOzND30d+vTEBoGX/rUtRX/03E0IGdpdBXSj/ySmn snGFo8a+EK5sOXMbpIYRg456CpH0ANi0SfSE9J2zYyuFMz8u0ga0pMbWn0bOFiCGyM35jnntercE2 uGmYS4SneLPsfFBUsMsuQ8q5DPDWjq53hT1R/fbCH1V/WmrcNm/KcWSnCvVUYMOPh2ZvNMGQj1qhu l/rKAv0ZXlFI7wpimSkEryPZoeBUPWyJmqt3hJ5h62FvNYXjesXBr93eYYTWuBCdT/wjXOnpuYVys nvUd3sZQ==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lk2hl-00H38v-PR for linux-arm-kernel@lists.infradead.org; Fri, 21 May 2021 10:48: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 E5F131480; Fri, 21 May 2021 03:48:32 -0700 (PDT) Received: from optiplex-7070.shanghai.arm.com (optiplex-7070.shanghai.arm.com [10.169.188.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 139FA3F73D; Fri, 21 May 2021 03:48:30 -0700 (PDT) From: Jaxson Han To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org, wei.chen@arm.com, jaxson.han@arm.com Subject: [boot-wrapper PATCH v2 5/8] aarch64: Prepare for lower EL booting Date: Fri, 21 May 2021 18:48:04 +0800 Message-Id: <20210521104807.138269-6-jaxson.han@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210521104807.138269-1-jaxson.han@arm.com> References: <20210521104807.138269-1-jaxson.han@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210521_034833_887356_357B450B X-CRM114-Status: UNSURE ( 8.72 ) 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 Save SPSR_KERNEL into spsr_to_elx during el3_init. The jump_kernel will load spsr_to_elx into spsr_el3. This change will make it easier to control whether drop to lower EL before jumping to the kernel. Signed-off-by: Jaxson Han Reviewed-by: Andre Przywara --- arch/aarch64/boot.S | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index b8f9e4e..5600859 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -118,7 +118,16 @@ el3_init: mov x0, #ZCR_EL3_LEN_MASK // SVE: Enable full vector len msr ZCR_EL3, x0 // for EL2. -1: + /* + * Save SPSR_KERNEL into spsr_to_elx. + * The jump_kernel will load spsr_to_elx into spsr_el3 + */ +1: mov w0, #SPSR_KERNEL + ldr x1, =spsr_to_elx + str w0, [x1] + b el_max_init + +el_max_init: ldr x0, =CNTFRQ msr cntfrq_el0, x0 @@ -166,7 +175,7 @@ jump_kernel: b.eq 1f br x19 // Keep current EL -1: ldr w4, #SPSR_KERNEL +1: ldr w4, spsr_to_elx /* * If bit 0 of the kernel address is set, we're entering in AArch32 @@ -184,3 +193,5 @@ jump_kernel: .align 3 flag_keep_el: .long 0 +spsr_to_elx: + .long 0 From patchwork Fri May 21 10:48:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaxson Han X-Patchwork-Id: 12272911 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 52E0BC433B4 for ; Fri, 21 May 2021 10:51:59 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D376E613B6 for ; Fri, 21 May 2021 10:51:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D376E613B6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cRu3tgE8ypqii480Y9fHdUdE6VzBe7OkeUpzQPYqOHM=; b=F5o6sfyNPMJte5VaOFZ15oab0D /QPnAg91PIDenIgOiRy9FW0TVw4sootUoW5hudk3MBjmn7qi6na1E+tNMFYFmyJnG90YexY1Wr5hb 9J17rBpmT3VjmP13ZzthgY9UP6U0NM2McXdmE7N3jCTcA4nDqTB3bgBiE/oG5P88chJ2lYPKiq7+w 5xsoXZeoXpC7hmIINKPDX1pUNgRZlZ4ranAQFB8vDXR2X9pBuvo4nc0/1U0onMIchMOLsG9Uq6N/q Tk4OqIKRkJkeCCiigwrFDuVTZDHHmG+sbG/Xaq/8QX9Z8ExiJxwe4rG7Iol7CE24sypj3W9xRMQ4b 7Y5LPlhA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2iu-0050aX-DL; Fri, 21 May 2021 10:49:44 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2hr-00507r-Qg for linux-arm-kernel@desiato.infradead.org; Fri, 21 May 2021 10:48:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=g6MMtLrug9wwqEAQLY5ubzuxrZnJk3XxTvY+KU8uMQY=; b=CDEz8gHp6DI7Uf9sr9se2Wz/TI jLULlMJR5EC/JxXpcszAHkq1j50CavJ9GxFNzhUtfFODfzuxVwDdokJ9xyX4yoXFpNSHsR7u3DXZG ONW7yAfRjid8dqCufjs6LR9bvkwdwG7Zuf+4ZAYTHipLjraIAPx0iviZherF2r6QmXRnHh+Swzkhy tGBSj5pNyfgpe5DB2AegbZYWm0MQzOXUvS+xtBLY6C2LDf4dlfiful/tDc5h1McCGUzCy+k4fDfY3 74rIgg8qOvxp5gcMUpyT62aPcCX4aNIt8yxq1iaFoZ0vilhyPxnwPwAX4LwKMRMVZov8b5qAMjdfD D5ObDE1Q==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lk2ho-00H39m-Nh for linux-arm-kernel@lists.infradead.org; Fri, 21 May 2021 10:48:38 +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 499EB1424; Fri, 21 May 2021 03:48:35 -0700 (PDT) Received: from optiplex-7070.shanghai.arm.com (optiplex-7070.shanghai.arm.com [10.169.188.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6CEBB3F73D; Fri, 21 May 2021 03:48:33 -0700 (PDT) From: Jaxson Han To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org, wei.chen@arm.com, jaxson.han@arm.com Subject: [boot-wrapper PATCH v2 6/8] gic-v3: Prepare for gicv3 with EL2 Date: Fri, 21 May 2021 18:48:05 +0800 Message-Id: <20210521104807.138269-7-jaxson.han@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210521104807.138269-1-jaxson.han@arm.com> References: <20210521104807.138269-1-jaxson.han@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210521_034836_884465_5FA7F478 X-CRM114-Status: GOOD ( 11.32 ) 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 This is a preparation for allowing boot-wrapper configuring the gicv3 with EL2. When confiuring with EL2, since there is no ICC_CTLR_EL2, the ICC_CTLR_EL3 cannot be replaced with ICC_CTLR_EL2 simply. See [https://developer.arm.com/documentation/ihi0069/latest/]. As the caller, gic_secure_init expects the ICC_CTLR to be written, we change the function into gic_init_icc_ctlr(). In the GIC spec, the r/w bits in this register ([6:0]) either affect EL3 IRQ routing (not applicable since no EL3), non-secure IRQ handling (not applicable since only secure state in Armv8-R aarch64), or are aliased to ICC_CTLR_EL1 bits. So, based on this, the new gic_init_icc_ctlr() would be: When currentEL is EL3, init ICC_CTLR_EL3 as before. When currentEL is not EL3, init ICC_CTLR_EL1 with ICC_CTLR_EL1_RESET. Signed-off-by: Jaxson Han Reviewed-by: Andre Przywara --- arch/aarch32/include/asm/gic-v3.h | 7 ++++++ arch/aarch64/include/asm/gic-v3.h | 38 ++++++++++++++++++++++++++++--- gic-v3.c | 2 +- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/arch/aarch32/include/asm/gic-v3.h b/arch/aarch32/include/asm/gic-v3.h index ec9a327..86abe09 100644 --- a/arch/aarch32/include/asm/gic-v3.h +++ b/arch/aarch32/include/asm/gic-v3.h @@ -9,6 +9,8 @@ #ifndef __ASM_AARCH32_GICV3_H #define __ASM_AARCH32_GICV3_H +#define ICC_CTLR_RESET (0UL) + static inline uint32_t gic_read_icc_sre(void) { uint32_t val; @@ -26,4 +28,9 @@ static inline void gic_write_icc_ctlr(uint32_t val) asm volatile ("mcr p15, 6, %0, c12, c12, 4" : : "r" (val)); } +static inline void gic_init_icc_ctlr() +{ + gic_write_icc_ctlr(ICC_CTLR_RESET); +} + #endif diff --git a/arch/aarch64/include/asm/gic-v3.h b/arch/aarch64/include/asm/gic-v3.h index e743c02..b3dfbd3 100644 --- a/arch/aarch64/include/asm/gic-v3.h +++ b/arch/aarch64/include/asm/gic-v3.h @@ -15,21 +15,53 @@ #define ICC_CTLR_EL3 "S3_6_C12_C12_4" #define ICC_PMR_EL1 "S3_0_C4_C6_0" +#define ICC_CTLR_EL3_RESET (0UL) +#define ICC_CTLR_EL1_RESET (0UL) + +static inline uint32_t current_el(void) +{ + uint32_t val; + + asm volatile ("mrs %0, CurrentEL" : "=r" (val)); + return val; +} + static inline uint32_t gic_read_icc_sre(void) { uint32_t val; - asm volatile ("mrs %0, " ICC_SRE_EL3 : "=r" (val)); + + if(current_el() == CURRENTEL_EL3) + asm volatile ("mrs %0, " ICC_SRE_EL3 : "=r" (val)); + else + asm volatile ("mrs %0, " ICC_SRE_EL2 : "=r" (val)); + return val; } static inline void gic_write_icc_sre(uint32_t val) { - asm volatile ("msr " ICC_SRE_EL3 ", %0" : : "r" (val)); + if(current_el() == CURRENTEL_EL3) + asm volatile ("msr " ICC_SRE_EL3 ", %0" : : "r" (val)); + else + asm volatile ("msr " ICC_SRE_EL2 ", %0" : : "r" (val)); } -static inline void gic_write_icc_ctlr(uint32_t val) +static inline void gic_write_icc_ctlr_el3(uint32_t val) { asm volatile ("msr " ICC_CTLR_EL3 ", %0" : : "r" (val)); } +static inline void gic_write_icc_ctlr_el1(uint32_t val) +{ + asm volatile ("msr " ICC_CTLR_EL1 ", %0" : : "r" (val)); +} + +static inline void gic_init_icc_ctlr() +{ + if(current_el() == CURRENTEL_EL3) + gic_write_icc_ctlr_el3(ICC_CTLR_EL3_RESET); + else + gic_write_icc_ctlr_el1(ICC_CTLR_EL1_RESET); +} + #endif diff --git a/gic-v3.c b/gic-v3.c index ae2d2bc..4850572 100644 --- a/gic-v3.c +++ b/gic-v3.c @@ -121,6 +121,6 @@ void gic_secure_init(void) gic_write_icc_sre(sre); isb(); - gic_write_icc_ctlr(0); + gic_init_icc_ctlr(); isb(); } From patchwork Fri May 21 10:48:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaxson Han X-Patchwork-Id: 12272913 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 A8B08C433B4 for ; Fri, 21 May 2021 10:52:17 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7064F6108D for ; Fri, 21 May 2021 10:52:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7064F6108D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SVql08ccZ+OZs3TgmcYCYZR++XNNNcRx1mH9xtuBEYI=; b=Wd1w/x0r1UZBy5P977k68q76Ss mA7SmgqPmkkFvsfCQH4L7GgUxyyMN/FzJOiviLDAWff64GLq5ZPIJjHnfMsFh0bdAiz2o+QHIC89U cNXWsbv4wBsJZrIZhc4/dD3X4xn92py1tQdbMSV+Qv1wG/3ttl34hRSn1JjhdKuGV3gEi1bzZzhz+ qQBp79xxeBUhCgaoxz+Uwx/nuLCd2gB4sr521e8pbeoSBiG8sfRGqqZW0rz6Dg5RXX1kTL0YekTwq 1nMKCWMhsYtV2w0JfyIUdYroVYFt3K8pa3EHVNrYbeaTIRFE/wgy3leJ0TeM1BKwp45QuYRKG70fV 5o4JmZBQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2j6-0050hw-Ro; Fri, 21 May 2021 10:49:56 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2hw-00509G-6b for linux-arm-kernel@desiato.infradead.org; Fri, 21 May 2021 10:48:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=6br5aAQa1ugsDULTZrf+6uLsWtbh1LC9vxZe8CEJ51w=; b=1BhCPU4Q9yWIhafxiOtw8gRNgU 8FXttMaejHo7q+S6jeQIRMUxGZykposSGs4zZKnx9JeUqRjdmNxw0blFGOOEATrSNUL5M6llNCknE WqPaH+SfCAnBp5xmLPErsOAoKVqX03eGczz4uZNTKlkOK24bEbyZs6kcUcC9+iDeVpmM0tAtB9M8O v9ts45ZKkjjhR2ahrkZUcCoG3aXefkZ1XJYbywOxPqKqRH4Bp5Znx069vP6jBigGFKY20ctf+WAcW qh30vj/QvNZmiE9i3r+43t5uE4GNCUBOCIN7goY9PIo6XA+aVJY/iFlF3wte806Ozeb4hwUL9NQ/o I7GPZy1g==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lk2ht-00H3AV-II for linux-arm-kernel@lists.infradead.org; Fri, 21 May 2021 10:48:43 +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 A2BBC150C; Fri, 21 May 2021 03:48:37 -0700 (PDT) Received: from optiplex-7070.shanghai.arm.com (optiplex-7070.shanghai.arm.com [10.169.188.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C3F1D3F73D; Fri, 21 May 2021 03:48:35 -0700 (PDT) From: Jaxson Han To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org, wei.chen@arm.com, jaxson.han@arm.com Subject: [boot-wrapper PATCH v2 7/8] aarch64: Prepare for booting with EL2 Date: Fri, 21 May 2021 18:48:06 +0800 Message-Id: <20210521104807.138269-8-jaxson.han@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210521104807.138269-1-jaxson.han@arm.com> References: <20210521104807.138269-1-jaxson.han@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210521_034841_667211_BA95CACB X-CRM114-Status: UNSURE ( 8.58 ) 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 Prepare for allowing boot-wrapper to be entered in EL2. Detect current EL and set the corresponding EL registers. Signed-off-by: Jaxson Han Reviewed-by: Andre Przywara --- arch/aarch64/boot.S | 8 ++++++++ arch/aarch64/utils.S | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index 5600859..14fd9cf 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -183,10 +183,18 @@ jump_kernel: */ bfi x4, x19, #5, #1 + mrs x5, CurrentEL + cmp x5, #CURRENTEL_EL2 + b.eq 1f + msr elr_el3, x19 msr spsr_el3, x4 eret +1: msr elr_el2, x19 + msr spsr_el2, x4 + eret + .ltorg .data diff --git a/arch/aarch64/utils.S b/arch/aarch64/utils.S index ae22ea7..94e9931 100644 --- a/arch/aarch64/utils.S +++ b/arch/aarch64/utils.S @@ -37,10 +37,18 @@ find_logical_id: ret /* - * Setup EL3 vectors + * Setup EL3/EL2 vectors * x0: vector address */ setup_vector: + mrs x1, CurrentEL + cmp x1, #CURRENTEL_EL2 + b.eq 1f + msr VBAR_EL3, x0 isb ret + +1: msr VBAR_EL2, x0 + isb + ret From patchwork Fri May 21 10:48:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jaxson Han X-Patchwork-Id: 12272915 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 A01CEC433B4 for ; Fri, 21 May 2021 10:52:33 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2E9E06108D for ; Fri, 21 May 2021 10:52:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2E9E06108D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=SsmQiASAnNcns3537oVqwums4eBuwsrENRQESTcJoQE=; b=V9DC9iuCtSxgDYMI0HFOAB23++ s5Kup4hBYUeF675+XD7QaXL1AMZs/TUHY7ODGZSnHRMYu76JE1BSOXNsk6vyzCCFHZqb2Cq/Glu+q IwwudQMm4NwyuPVcpCw5hAmKeox+952nIB8mTkNNfKhtQj5EIHuy2uwQJIWScnaDo6A9FjoONlBHE gs86YUJF7LZuxqlRQhlG41Z8TTKYIbXSotfs9KkrvSrhcAkhVrxgmH+zs1YNsKoT0TQ0MuF8aw7Nn C1zKMbgi+52bNjapvLrQcIB/tVQO57iz2ZOd97py2CjS8uNm5bNLciwaBsYxjnAGvz8SA0xUnPjkT lLPAdgpg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2jO-0050r5-CF; Fri, 21 May 2021 10:50:14 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lk2hw-00509K-F3 for linux-arm-kernel@desiato.infradead.org; Fri, 21 May 2021 10:48:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=JksnVY4Th+H3URaFlvzWbCgIM9rDZOF5tvGoKmGwd4U=; b=gfnFkt1ZDrtCowgm7LshRfc8Yu bi3M8MXS8Bf0cCAWZL0+uNrqDfr+tOzU5Z+GqH+mXDl73nW5luStj0Oxgp2HAhTq9BlXcCQNmU1l+ iMkx+Ia2m2TIyTKI4BW70BUKDhwDVLDMB6efpxq/O8GN3T/sUUpqF5+iFnyu7/NI1vGctHqKPncJt J8KyUprtcxC3N3SKWTa6jwQfl4VroZvBSuui/l09Bpp6XfsEu8PjNbj1gWFkopST2TuwVuc0lFV34 BOipcHFGtUbxjPDfAeEex453e4lhOv7QWftB2hYC5jU4BiI8506S/sAJLfTzJgn9IZN/CrTfmeMdT 7HkeYoXA==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lk2ht-00H3AS-DV for linux-arm-kernel@lists.infradead.org; Fri, 21 May 2021 10:48:43 +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 F29F91424; Fri, 21 May 2021 03:48:39 -0700 (PDT) Received: from optiplex-7070.shanghai.arm.com (optiplex-7070.shanghai.arm.com [10.169.188.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 27BC93F73D; Fri, 21 May 2021 03:48:37 -0700 (PDT) From: Jaxson Han To: mark.rutland@arm.com, andre.przywara@arm.com Cc: linux-arm-kernel@lists.infradead.org, wei.chen@arm.com, jaxson.han@arm.com Subject: [boot-wrapper PATCH v2 8/8] aarch64: Introduce EL2 boot code for Armv8-R AArch64 Date: Fri, 21 May 2021 18:48:07 +0800 Message-Id: <20210521104807.138269-9-jaxson.han@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210521104807.138269-1-jaxson.han@arm.com> References: <20210521104807.138269-1-jaxson.han@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210521_034841_573205_52B7EF0A X-CRM114-Status: GOOD ( 15.88 ) 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 The Armv8-R AArch64 profile does not support the EL3 exception level. The Armv8-R AArch64 profile allows for an (optional) VMSAv8-64 MMU at EL1, which allows to run off-the-shelf Linux. However EL2 only supports a PMSA, which is not supported by Linux, so we need to drop into EL1 before entering the kernel. We add a new err_invalid_arch symbol as a dead loop. If we detect the current Armv8-R aarch64 only supports with PMSA, meaning we cannot boot Linux anymore, then we jump to err_invalid_arch. During Armv8-R aarch64 init, to make sure nothing unexpected traps into EL2, we auto-detect and config FIEN and EnSCXT in HCR_EL2. The boot sequence is: If CurrentEL == EL3, then goto EL3 initialisation and drop to lower EL before entering the kernel. If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA == 0xf (Armv8-R aarch64), if id_aa64mmfr0_el1.MSA_frac == 0x2, then goto Armv8-R AArch64 initialisation and drop to EL1 before entering the kernel. else, which means VMSA unsupported and cannot boot Linux, goto err_invalid_arch (dead loop). Else, no initialisation and keep the current EL before entering the kernel. Signed-off-by: Jaxson Han --- arch/aarch64/boot.S | 87 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 2 deletions(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index 14fd9cf..0339e19 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -25,16 +25,24 @@ _start: * Boot sequence * If CurrentEL == EL3, then goto EL3 initialisation and drop to * lower EL before entering the kernel. + * If CurrentEL == EL2 && id_aa64mmfr0_el1.MSA == 0xf, then + * If id_aa64mmfr0_el1.MSA_frac == 0x2, then goto + * Armv8-R AArch64 initialisation and drop to EL1 before + * entering the kernel. + * Else, which means VMSA unsupported and cannot boot Linux, + * goto err_invalid_arch (dead loop). * Else, no initialisation and keep the current EL before * entering the kernel. */ mrs x0, CurrentEL - cmp x0, #CURRENTEL_EL3 - beq el3_init + cmp x0, #CURRENTEL_EL2 + bgt el3_init + beq el2_init /* * We stay in the current EL for entering the kernel */ +keep_el: mov w0, #1 ldr x1, =flag_keep_el str w0, [x1] @@ -127,6 +135,80 @@ el3_init: str w0, [x1] b el_max_init + /* + * EL2 Armv8-R AArch64 initialisation + */ +el2_init: + /* Detect Armv8-R AArch64 */ + mrs x1, id_aa64mmfr0_el1 + /* + * Check MSA, bits [51:48]: + * 0xf means Armv8-R AArch64. + * If not 0xf, goto keep_el. + */ + ubfx x0, x1, #48, #4 // MSA + cmp x0, 0xf + bne keep_el + /* + * Check MSA_frac, bits [55:52]: + * 0x2 means EL1&0 translation regime also supports VMSAv8-64. + */ + ubfx x0, x1, #52, #4 // MSA_frac + cmp x0, 0x2 + /* If not 0x2, no VMSA, so cannot boot Linux and dead loop. */ + bne err_invalid_arch + + mrs x0, midr_el1 + msr vpidr_el2, x0 + + mrs x0, mpidr_el1 + msr vmpidr_el2, x0 + + mov x0, #(1 << 31) // VTCR_MSA: VMSAv8-64 support + msr vtcr_el2, x0 + + /* Init HCR_EL2 */ + mov x0, #(1 << 31) // RES1 + + mrs x1, id_aa64pfr0_el1 + ubfx x2, x1, #56, 4 + cmp x2, 0x2 + bne 1f + /* + * Disable trap when accessing SCTXNUM_EL0 or SCTXNUM_EL1 + * if FEAT_CSV2. + */ + orr x0, x0, #(1 << 53) // EnSCXT + +1: ubfx x2, x1, #28, 4 + cmp x2, 0x2 + bne 1f + /* Disable trap when accessing ERXPFGCDN_EL1 if FEAT_RASv1p1. */ + orr x0, x0, #(1 << 47) // FIEN + + /* Enable pointer authentication if present */ +1: mrs x1, id_aa64isar1_el1 + /* + * If ID_AA64ISAR1_EL1.{GPI, GPA, API, APA} == {0000, 0000, 0000, 0000} + * then HCR_EL2.APK and HCR_EL2.API are RES 0. + * Else + * set HCR_EL2.APK and HCR_EL2.API. + */ + ldr x2, =(((0xff) << 24) | (0xff << 4)) + and x1, x1, x2 + cbz x1, 1f + + orr x0, x0, #(1 << 40) // APK + orr x0, x0, #(1 << 41) // API + +1: msr hcr_el2, x0 + isb + + mov w0, #SPSR_KERNEL_EL1 + ldr x1, =spsr_to_elx + str w0, [x1] + // fall through + el_max_init: ldr x0, =CNTFRQ msr cntfrq_el0, x0 @@ -136,6 +218,7 @@ el_max_init: b start_el_max err_invalid_id: +err_invalid_arch: b . /*