From mboxrd@z Thu Jan 1 00:00:00 1970 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.8 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,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 B8D28C433B4 for ; Tue, 20 Apr 2021 07:27:51 +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 06A6D61154 for ; Tue, 20 Apr 2021 07:27:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06A6D61154 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=B3pk2IzqJq5UQbQy0wwEpcgoxig/w/Dke846hG/0M/Q=; b=a9PPApPt+CH2B2SYAra7K5NYu jk1HjaRHxsIou1W4rKFYHb7RbYQ0yfFgPbrihF/MzEwEFdaHdApN0FlSpYI9y5F2mNRkmfG/h9qiX RZCzi8GAE9TYHzzvqWajC3g/ERwLt8aTRZ+Vm6Hw9uuvH/+rLzWxr177GFqrl6YNn5rntYDIImcAU rGtacnDaFv6TLfaAzW8YhR8K1g2rXX90k8yOUNv72qZxf4w7Gh9QUKjaoXsQXtLFtGYAwDwAlvUKU VeuUWbPFJCYLa5HRxiVxVYpAi1BIyNZ+prDO6oUANWN6ZnXUnDQ3yE+81OZkk+gYMVhB655AJBdVp CbnajTr9Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lYklZ-00BSUD-Kc; Tue, 20 Apr 2021 07:25:49 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lYkkx-00BSPR-Lj for linux-arm-kernel@desiato.infradead.org; Tue, 20 Apr 2021 07:25:12 +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=NReSiKhBxoRPzh8mls+LT6HLZhDKYA4ybr6k5twwXDw=; b=QwUT5S+6ZnR9MSxlxune4bGQBJ TtdQvm5XWCe21kPVxYEr+g8mkgRsRUUJvFMTwVEgyrqmtAfHcC9dm0IsK13t1Liw/hbhmqc4sJuW5 WYmwRNFZScwggFhxX4IZ+nuHv/Cn3pFnooNIx1Yoxwc71Ep5nOYHKYPm3mmcUkayGHwUD9dDUICUV iXNZyIBonYeIAofbe4A12T/654GdW67Ra/i/O0l67xTjH1KNhUmq89yCftCSh5Tb3nxLAs6YdPfFO S9RYfakjZV3533UaWFEm2Phws3rC/YWdeD2O7UCaLyvWeSkQN5HccG7NK5lM17gB4vlMTZ0KCsXlv hHxtVvDw==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lYkkr-00BsUe-Qm for linux-arm-kernel@lists.infradead.org; Tue, 20 Apr 2021 07:25:10 +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 34D5A1713; Tue, 20 Apr 2021 00:25:04 -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 604213F85F; Tue, 20 Apr 2021 00:25:02 -0700 (PDT) From: Jaxson Han To: mark.rutland@arm.com Cc: linux-arm-kernel@lists.infradead.org, wei.chen@arm.com, andre.przywara@arm.com, jaxson.han@arm.com Subject: [boot-wrapper PATCH 5/5] aarch64: Introduce EL2 boot code for Armv8-R AArch64 Date: Tue, 20 Apr 2021 15:24:38 +0800 Message-Id: <20210420072438.183086-6-jaxson.han@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210420072438.183086-1-jaxson.han@arm.com> References: <20210420072438.183086-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-20210420_002505_931230_53F40CA1 X-CRM114-Status: GOOD ( 11.31 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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. 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), then goto Armv8-R AArch64 initialisation and drop to EL1 before entering the kernel. Else, no initialisation and keep the current EL before entering the kernel. Signed-off-by: Jaxson Han --- arch/aarch64/boot.S | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index f7dbf3f..6961a2a 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -25,16 +25,22 @@ _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 goto + * Armv8-R AArch64 initialisation and drop to EL1 before + * entering the kernel. * 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 + 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] @@ -112,6 +118,43 @@ 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 + ubfx x1, x1, #48, #4 // MSA + /* 0xf means Armv8-R AArch64 */ + cmp x1, 0xf + bne keep_el + + 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 + + /* Enable pointer authentication if present */ + mrs x1, id_aa64isar1_el1 + ldr x2, =(((0xff) << 24) | (0xff << 4)) + and x1, x1, x2 + cbz x1, 1f + + mrs x0, hcr_el2 + orr x0, x0, #(1 << 40) // AP key enable + orr x0, x0, #(1 << 41) // AP insn enable + msr hcr_el2, x0 + +1: isb + mov w0, #SPSR_KERNEL_EL1 + ldr x1, =spsr_to_elx + str w0, [x1] + b el_max_init + el_max_init: ldr x0, =CNTFRQ msr cntfrq_el0, x0 @@ -169,10 +212,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 -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel