From patchwork Mon Jul 29 16:14:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 13745387 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 535C3C3DA61 for ; Mon, 29 Jul 2024 16:20:32 +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=JSkr6pa7Oy8WmGb1MBkWW6G/d3jkP4/ph+RUfTKhCIc=; b=tAxQXZxO6OmS+m0PsvYwIwu8b+ ajf4hiS8TanxALJIo0NyZiJY3DOVOunEtkwswbvorWkF2eXlTpkxE1lqEp8QcHB/tU9NKbQrEIRL8 r3am7jMirqNgkpfCi8OLqnVPwkmxAMxyghT8J9Q7uRjyTbIWOZxy9BNM2K6xQVFud00qzKk6he1wD +tod6niwlkmzbg5msrWkaEs7TXszbTCJz8fsyCntfeFhks83vALuzLfsWcluH29H1843omXi4rUqL lUh2OxwvB74w3pdN33lE+QwQO5PN+LkQHiDgWRM/2QkLHaHb13TsY2GcKJ6+nF4dY7SCTjMJNLcxD DJRRI/0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT6m-0000000BzVI-1cr1; Mon, 29 Jul 2024 16:20:24 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sYT1n-0000000ByL3-1KHv for linux-arm-kernel@lists.infradead.org; Mon, 29 Jul 2024 16:15:16 +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 808B91477; Mon, 29 Jul 2024 09:15:40 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 13C223F766; Mon, 29 Jul 2024 09:15:13 -0700 (PDT) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: akos.denke@arm.com, andre.przywara@arm.com, luca.fancellu@arm.com, mark.rutland@arm.com, maz@kernel.org Subject: [BOOT-WRAPPER 03/11] aarch64: Implement cpu_init_arch() Date: Mon, 29 Jul 2024 17:14:53 +0100 Message-Id: <20240729161501.1806271-4-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240729161501.1806271-1-mark.rutland@arm.com> References: <20240729161501.1806271-1-mark.rutland@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240729_091515_571797_64ACE1A5 X-CRM114-Status: GOOD ( 10.60 ) 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 the boot-wrapper is entered at EL2 it does not initialise CNTFRQ_EL0, and in future it may need to initialize other CPU state regardless of the exeption level it was entered at. Use a common cpu_init_arch() function to initialize CPU state regardless of the exception level the boot-wrapper was entered at. Signed-off-by: Mark Rutland Cc: Akos Denke Cc: Andre Przywara Cc: Luca Fancellu Cc: Marc Zyngier Acked-by: Marc Zyngier --- arch/aarch64/boot.S | 4 +++- arch/aarch64/init.c | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index 51ef41b..d8d38dd 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -51,7 +51,7 @@ reset_at_el3: bl cpu_init_bootwrapper - bl cpu_init_el3 + bl cpu_init_arch bl gic_secure_init @@ -82,6 +82,8 @@ reset_at_el2: bl cpu_init_bootwrapper + bl cpu_init_arch + b start_bootmethod err_invalid_id: diff --git a/arch/aarch64/init.c b/arch/aarch64/init.c index c9fc7f1..49abdf7 100644 --- a/arch/aarch64/init.c +++ b/arch/aarch64/init.c @@ -52,7 +52,7 @@ static inline bool cpu_has_permission_indirection(void) return mrs(ID_AA64MMFR3_EL1) & mask; } -void cpu_init_el3(void) +static void cpu_init_el3(void) { unsigned long scr = SCR_EL3_RES1 | SCR_EL3_NS | SCR_EL3_HCE; unsigned long mdcr = 0; @@ -153,8 +153,6 @@ void cpu_init_el3(void) msr(SMCR_EL3, smcr); } - - msr(CNTFRQ_EL0, COUNTER_FREQ); } #ifdef PSCI @@ -171,3 +169,11 @@ bool cpu_init_psci_arch(void) return true; } #endif + +void cpu_init_arch(void) +{ + if (mrs(CurrentEL) == CURRENTEL_EL3) + cpu_init_el3(); + + msr(CNTFRQ_EL0, COUNTER_FREQ); +}