From patchwork Sun Jul 28 15:57:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 1138032 X-Patchwork-Delegate: uboot@andestech.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aisec.fraunhofer.de Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 45xSGJ4xccz9s7T for ; Mon, 29 Jul 2019 02:00:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 18632C21D4A; Sun, 28 Jul 2019 15:59:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 85D9AC21DD4; Sun, 28 Jul 2019 15:59:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BD79BC21DA6; Sun, 28 Jul 2019 15:57:57 +0000 (UTC) Received: from mail-edgeS23.fraunhofer.de (mail-edges23.fraunhofer.de [153.97.7.23]) by lists.denx.de (Postfix) with ESMTPS id B3A3BC21DCA for ; Sun, 28 Jul 2019 15:57:54 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2GhAAB1xT1d/xwBYJllGgEBAQEBAgEBAQEHAgEBAQGBZ4IXgT8BHzyNGogai2ORKAkBAQEBAQEBAQEILwEBhEACgmMjOBMBAwEBBQEBAQEGAgJphR4MhUwGMgFGEFEhHBoGDgWDIoFrAxwBqz6IBw1fgUgJAYEqhwmEV4FXP4EQAYNQghqCd4UWBIwbgi6HXZQRQAcCgTljXQSPPINrDBuCLosGilqObIgOjj+BZyKBWDMaJIM7gk4Xg0eKXD0BMgGPDwEB X-IPAS-Result: A2GhAAB1xT1d/xwBYJllGgEBAQEBAgEBAQEHAgEBAQGBZ4IXgT8BHzyNGogai2ORKAkBAQEBAQEBAQEILwEBhEACgmMjOBMBAwEBBQEBAQEGAgJphR4MhUwGMgFGEFEhHBoGDgWDIoFrAxwBqz6IBw1fgUgJAYEqhwmEV4FXP4EQAYNQghqCd4UWBIwbgi6HXZQRQAcCgTljXQSPPINrDBuCLosGilqObIgOjj+BZyKBWDMaJIM7gk4Xg0eKXD0BMgGPDwEB X-IronPort-AV: E=Sophos;i="5.64,319,1559512800"; d="scan'208";a="12233465" Received: from mail-mtaka28.fraunhofer.de ([153.96.1.28]) by mail-edgeS23.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jul 2019 17:57:54 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CoAACvxD1dfRBhWMBlGgEBAQEBAgEBAQEHAgEBAQGBZ4NWIDyNGpN9kSgJAQMBAQEBAQgvAQGEQAKDBTgTAQMBAQQBAQIBBhQBARY6hSUMhUsDAzIBRhBRIRwaBg4FgyKBawMdqz2IBw1fgUgJAYEqhwmGLj+BEAGDUIIagneFFgSMG4Iuh12UEUAHAoE5Y10EjzyDawwbgi6LBopajmyIDo4/gWcggVkzGiSDO4JOF4NHilw9AzABjw8BAQ X-IronPort-AV: E=Sophos;i="5.64,319,1559512800"; d="scan'208";a="20209990" Received: from fgdemucivp01ltm.xch.fraunhofer.de (HELO FGDEMUCIMP12EXC.ads.fraunhofer.de) ([192.88.97.16]) by mail-mtaKA28.fraunhofer.de with ESMTP/TLS/AES256-SHA; 28 Jul 2019 17:57:54 +0200 Received: from localhost.de (10.80.233.51) by FGDEMUCIMP12EXC.ads.fraunhofer.de (10.80.232.43) with Microsoft SMTP Server (TLS) id 14.3.439.0; Sun, 28 Jul 2019 17:57:53 +0200 From: Lukas Auer To: Date: Sun, 28 Jul 2019 17:57:19 +0200 Message-ID: <20190728155723.3412-8-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190728155723.3412-1-lukas.auer@aisec.fraunhofer.de> References: <20190728155723.3412-1-lukas.auer@aisec.fraunhofer.de> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-24806.001 X-TM-AS-Result: No--7.671100-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No Cc: Marek Vasut , Alistair Francis , Stefan Roese Subject: [U-Boot] [PATCH v2 07/11] riscv: support SPL stack and global data relocation X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" To support relocation of the stack and global data on RISC-V, the secondary harts must be notified of the change using IPIs. We can reuse the hart relocation code for this purpose. It uses global data to store the new stack pointer and global data pointer for the secondary harts. This means that we cannot update the global data pointer of the main hart in spl_relocate_stack_gd(), because the secondary harts have not yet been relocated at this point. It is updated after the secondary harts have been notified. Signed-off-by: Lukas Auer Reviewed-by: Bin Meng Tested-by: Bin Meng Reviewed-by: Anup Patel --- Changes in v2: None arch/riscv/cpu/start.S | 35 ++++++++++++++++++++++++++++++++++- common/spl/spl.c | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index e053197645..e8c65c887a 100644 --- a/arch/riscv/cpu/start.S +++ b/arch/riscv/cpu/start.S @@ -170,13 +170,46 @@ wait_for_gd_init: spl_clear_bss: la t0, __bss_start la t1, __bss_end - beq t0, t1, spl_call_board_init_r + beq t0, t1, spl_stack_gd_setup spl_clear_bss_loop: SREG zero, 0(t0) addi t0, t0, REGBYTES bne t0, t1, spl_clear_bss_loop +spl_stack_gd_setup: + jal spl_relocate_stack_gd + + /* skip setup if we did not relocate */ + beqz a0, spl_call_board_init_r + mv s0, a0 + + /* setup stack on main hart */ +#ifdef CONFIG_SMP + /* tp: hart id */ + slli t0, tp, CONFIG_STACK_SIZE_SHIFT + sub sp, s0, t0 +#else + mv sp, s0 +#endif + + /* set new stack and global data pointer on secondary harts */ +spl_secondary_hart_stack_gd_setup: + la a0, secondary_hart_relocate + mv a1, s0 + mv a2, s0 + jal smp_call_function + + /* hang if relocation of secondary harts has failed */ + beqz a0, 1f + mv a1, a0 + la a0, secondary_harts_relocation_error + jal printf + jal hang + + /* set new global data pointer on main hart */ +1: mv gp, s0 + spl_call_board_init_r: mv a0, zero mv a1, zero diff --git a/common/spl/spl.c b/common/spl/spl.c index 1ed4741bdc..834f39908b 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -756,7 +756,7 @@ ulong spl_relocate_stack_gd(void) #if CONFIG_IS_ENABLED(DM) dm_fixup_for_gd_move(new_gd); #endif -#if !defined(CONFIG_ARM) +#if !defined(CONFIG_ARM) && !defined(CONFIG_RISCV) gd = new_gd; #endif return ptr;