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 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 C5464C433EF for ; Fri, 14 Jan 2022 11:00:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=Az6fSPt9KN+VY7QFdR3475Mcxxcux5wkPCHH4qczMfo=; b=ek1LU2nswvi/Bt Ua38tmKj4ThLPXNPsEe0ZtLKeXX3z34MrBONfcHywXWmNsP4MnJBYvGt1VCai8T6Cw6IDuRSc+zMd +yI9DkpetoK22Ir/mhnzGpttVpa3MZ6IC2QBAX65/oTDbH5OjrPXfQ8dRfX2lMjr8Bi3JrfBT3Qzb tB2NVTK2tuV1mRz/C/MqdjH9I5S7yQ+f7K4p8dfeKxKV83/yguwNNjMvdL9hqvec9ZKWxsktM63Tj qxAlx45CRorsM2WCtFye7kPxK33OgHjVvnjRavB6uguXURsIVUIQmDvTb6XJIfa4q/IzBYkY5Ts8I /E01Oldx7/VB2QiTNiMQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n8KIE-008otT-Uf; Fri, 14 Jan 2022 10:58:51 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n8KGg-008o5P-LX for linux-arm-kernel@lists.infradead.org; Fri, 14 Jan 2022 10:57: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 5F4B6101E; Fri, 14 Jan 2022 02:57:14 -0800 (PST) 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 5DCB83F766; Fri, 14 Jan 2022 02:57:13 -0800 (PST) From: Mark Rutland To: linux-arm-kernel@lists.infradead.org Cc: andre.przywara@arm.com, Jaxson.Han@arm.com, mark.rutland@arm.com, robin.murphy@arm.com, vladimir.murzin@arm.com, Wei.Chen@arm.com Subject: [bootwrapper PATCH v2 07/13] Rework common init C code Date: Fri, 14 Jan 2022 10:56:47 +0000 Message-Id: <20220114105653.3003399-8-mark.rutland@arm.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220114105653.3003399-1-mark.rutland@arm.com> References: <20220114105653.3003399-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-20220114_025714_828299_B61F7740 X-CRM114-Status: GOOD ( 19.72 ) 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 In init_platform() we initialize a UART and announce the presence of the bootwrapper to the world. We do this relatively late in the boot-flow, and prior to this will silently ignore errors (e.g. in gic_secure_init). To make it possible to provide improved diagnostics, and to allow us to move more initialization into C, this patch reworks the init code to call a C function earlier, where we can announce the presence of the boot-wrapper and perform other initialization. In subsequent patches this will be expanded with more CPU initialization. Signed-off-by: Mark Rutland --- Makefile.am | 2 +- arch/aarch32/boot.S | 5 +++++ arch/aarch64/boot.S | 4 ++++ common/boot.c | 4 ---- common/init.c | 24 ++++++++++++++++++++++++ common/platform.c | 12 +++++++----- include/platform.h | 17 +++++++++++++++++ 7 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 common/init.c create mode 100644 include/platform.h diff --git a/Makefile.am b/Makefile.am index f941b07..0651c38 100644 --- a/Makefile.am +++ b/Makefile.am @@ -34,7 +34,7 @@ endif PSCI_CPU_OFF := 0x84000002 COMMON_SRC := common/ -COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o +COMMON_OBJ := boot.o bakery_lock.o platform.o lib.o init.o ARCH_OBJ := boot.o stack.o utils.o diff --git a/arch/aarch32/boot.S b/arch/aarch32/boot.S index 00c432d..ee073ea 100644 --- a/arch/aarch32/boot.S +++ b/arch/aarch32/boot.S @@ -48,6 +48,9 @@ ASM_FUNC(_start) mov r0, #1 ldr r1, =flag_no_el3 str r0, [r1] + + bl cpu_init_bootwrapper + b start_no_el3 _switch_monitor: @@ -71,6 +74,8 @@ _monitor: ldr r0, =COUNTER_FREQ mcr p15, 0, r0, c14, c0, 0 @ CNTFRQ + bl cpu_init_bootwrapper + bl gic_secure_init /* Initialise boot method */ diff --git a/arch/aarch64/boot.S b/arch/aarch64/boot.S index 45a0367..17b4a75 100644 --- a/arch/aarch64/boot.S +++ b/arch/aarch64/boot.S @@ -141,6 +141,8 @@ reset_at_el3: b.eq err_invalid_id bl setup_stack + bl cpu_init_bootwrapper + bl gic_secure_init b start_el3 @@ -181,6 +183,8 @@ reset_no_el3: ldr x1, =flag_no_el3 str w0, [x1] + bl cpu_init_bootwrapper + b start_no_el3 err_invalid_id: diff --git a/common/boot.c b/common/boot.c index c74d34c..29d53a4 100644 --- a/common/boot.c +++ b/common/boot.c @@ -12,8 +12,6 @@ extern unsigned long entrypoint; extern unsigned long dtb; -void init_platform(void); - void __noreturn jump_kernel(unsigned long address, unsigned long a0, unsigned long a1, @@ -62,8 +60,6 @@ void __noreturn first_spin(unsigned int cpu, unsigned long *mbox, unsigned long invalid) { if (cpu == 0) { - init_platform(); - *mbox = (unsigned long)&entrypoint; sevl(); spin(mbox, invalid, 1); diff --git a/common/init.c b/common/init.c new file mode 100644 index 0000000..9c471c9 --- /dev/null +++ b/common/init.c @@ -0,0 +1,24 @@ +/* + * init.c - common boot-wrapper initialization + * + * Copyright (C) 2021 ARM Limited. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE.txt file. + */ +#include +#include + +static void announce_bootwrapper(void) +{ + print_string("Boot-wrapper v0.2\r\n\r\n"); +} + +void cpu_init_bootwrapper(void) +{ + if (this_cpu_logical_id() == 0) { + init_uart(); + announce_bootwrapper(); + init_platform(); + } +} diff --git a/common/platform.c b/common/platform.c index d11f568..47bf547 100644 --- a/common/platform.c +++ b/common/platform.c @@ -1,5 +1,5 @@ /* - * platform.c - code to initialise everything required when first booting. + * platform.c - Platform initialization and I/O. * * Copyright (C) 2015 ARM Limited. All rights reserved. * @@ -7,6 +7,7 @@ * found in the LICENSE.txt file. */ +#include #include #include @@ -30,7 +31,7 @@ #define V2M_SYS(reg) ((void *)SYSREGS_BASE + V2M_SYS_##reg) #endif -static void print_string(const char *str) +void print_string(const char *str) { uint32_t flags; @@ -47,7 +48,7 @@ static void print_string(const char *str) } } -void init_platform(void) +void init_uart(void) { /* * UART initialisation (38400 8N1) @@ -58,9 +59,10 @@ void init_platform(void) raw_writel(0x70, PL011(UART_LCR_H)); /* Enable the UART, TXen and RXen */ raw_writel(0x301, PL011(UARTCR)); +} - print_string("Boot-wrapper v0.2\r\n\r\n"); - +void init_platform(void) +{ #ifdef SYSREGS_BASE /* * CLCD output site MB diff --git a/include/platform.h b/include/platform.h new file mode 100644 index 0000000..e5248e1 --- /dev/null +++ b/include/platform.h @@ -0,0 +1,17 @@ +/* + * include/platform.h - Platform initialization and I/O. + * + * Copyright (C) 2021 ARM Limited. All rights reserved. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE.txt file. + */ +#ifndef __PLATFORM_H +#define __PLATFORM_H + +void print_string(const char *str); +void init_uart(void); + +void init_platform(void); + +#endif /* __PLATFORM_H */ -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel