From patchwork Wed Aug 7 21:12:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 1143694 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 463kkK04mrz9sMr for ; Thu, 8 Aug 2019 07:13:11 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 8A64DC21E1A; Wed, 7 Aug 2019 21:13:01 +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 9A903C21E13; Wed, 7 Aug 2019 21:12:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1A590C21E1D; Wed, 7 Aug 2019 21:12:58 +0000 (UTC) Received: from mail-edgeS23.fraunhofer.de (mail-edges23.fraunhofer.de [153.97.7.23]) by lists.denx.de (Postfix) with ESMTPS id 7654BC21DA2 for ; Wed, 7 Aug 2019 21:12:57 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2FvFwB5Pktd/xoBYJlmHAEBAQQBAQcEAQGBZ4IYgT8BW40ahkuLaJEtCQEBAQEBAQEBAQgvAQGEPwKCUyM4EwEEAQEFAQECAQoCAmmFJwyFTAYyAUYQUSEcGgYOBYMigWsDHAGtGogQDV+BSQkBgSqHC4RZgVc/gRABg1CCGoJ3hRYEjCeCL4dmlDBABwKBOWVdBI9Lg2sMG4IwixSKbo8BiB6OSoFnIoFYMxokgzuCTheDR4pcPQEyAY8gAQE X-IPAS-Result: A2FvFwB5Pktd/xoBYJlmHAEBAQQBAQcEAQGBZ4IYgT8BW40ahkuLaJEtCQEBAQEBAQEBAQgvAQGEPwKCUyM4EwEEAQEFAQECAQoCAmmFJwyFTAYyAUYQUSEcGgYOBYMigWsDHAGtGogQDV+BSQkBgSqHC4RZgVc/gRABg1CCGoJ3hRYEjCeCL4dmlDBABwKBOWVdBI9Lg2sMG4IwixSKbo8BiB6OSoFnIoFYMxokgzuCTheDR4pcPQEyAY8gAQE X-IronPort-AV: E=Sophos;i="5.64,358,1559512800"; d="scan'208";a="12425736" Received: from mail-mtaka26.fraunhofer.de ([153.96.1.26]) by mail-edgeS23.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Aug 2019 23:12:42 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BJBwAbPktdfRBhWMBmHAEBAQQBAQcEAQGBZ4NXIDyNGpIzkS0JAQMBAQEBAQgvAQGEPwKCdTgTAQQBAQQBAQMBChQBARY6hS4MhUsDAzIBRhBRIRwaBg4FgyKBawMdrRqIEA1fgUkJAYEqhwuGMD+BEAGDUIIagneFFgSMJ4Ivh2aUMEAHAoE5ZV0Ej0uDawwbgjCLFIpujwGIHo5KgWcggVkzGiSDO4JOF4NHilw9AzABjyABAQ X-IronPort-AV: E=Sophos;i="5.64,358,1559512800"; d="scan'208";a="52930271" Received: from fgdemucivp01ltm.xch.fraunhofer.de (HELO FGDEMUCIMP11EXC.ads.fraunhofer.de) ([192.88.97.16]) by mail-mtaKA26.fraunhofer.de with ESMTP/TLS/AES256-SHA; 07 Aug 2019 23:12:42 +0200 Received: from localhost.de (10.80.233.50) by FGDEMUCIMP11EXC.ads.fraunhofer.de (10.80.232.42) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 7 Aug 2019 23:15:20 +0200 From: Lukas Auer To: Date: Wed, 7 Aug 2019 23:12:09 +0200 Message-ID: <20190807211213.21849-8-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190807211213.21849-1-lukas.auer@aisec.fraunhofer.de> References: <20190807211213.21849-1-lukas.auer@aisec.fraunhofer.de> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-24824.005 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 , Stefan Roese , Alistair Francis , Miquel Raynal Subject: [U-Boot] [PATCH v3 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 v3: None 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 66c603906d..b15209d623 100644 --- a/arch/riscv/cpu/start.S +++ b/arch/riscv/cpu/start.S @@ -169,13 +169,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 133b179675..ea7f01baaf 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;