From patchwork Wed Aug 21 19:14:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 1151137 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 46DHYb2Qx4z9s7T for ; Thu, 22 Aug 2019 05:20:19 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 11112C21FDC; Wed, 21 Aug 2019 19:17:44 +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 E119AC22024; Wed, 21 Aug 2019 19:15:37 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4A31BC21FF3; Wed, 21 Aug 2019 19:15:14 +0000 (UTC) Received: from mail-edgeS23.fraunhofer.de (mail-edges23.fraunhofer.de [153.97.7.23]) by lists.denx.de (Postfix) with ESMTPS id 3FBCDC21F29 for ; Wed, 21 Aug 2019 19:15:11 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2E4AQB4l11d/xoHYZlkHAEBAQQBAQcEAQGBVgQBAQsBgheBPyA8jRuGAottkTAJAQEBAQEBAQEBCC8BAYQ/AoJdIzcGDgIFAQEFAQEBAQEGBAICaYUnDIVMBjIBRhBRIRwaBg4FgyKBawMcAaxQiCANYYFJCQGBKgGHFIRZgVg/gRABg1CCGoJ3hRYEjDOCL4dvlERABwKBOmVfBI9dg20MG4IxixyKeY8RiCeOWYFmI4FYMxokgzuCTheDSIpcPQEyAY1FAQE X-IPAS-Result: A2E4AQB4l11d/xoHYZlkHAEBAQQBAQcEAQGBVgQBAQsBgheBPyA8jRuGAottkTAJAQEBAQEBAQEBCC8BAYQ/AoJdIzcGDgIFAQEFAQEBAQEGBAICaYUnDIVMBjIBRhBRIRwaBg4FgyKBawMcAaxQiCANYYFJCQGBKgGHFIRZgVg/gRABg1CCGoJ3hRYEjDOCL4dvlERABwKBOmVfBI9dg20MG4IxixyKeY8RiCeOWYFmI4FYMxokgzuCTheDSIpcPQEyAY1FAQE X-IronPort-AV: E=Sophos;i="5.64,412,1559512800"; d="scan'208";a="12659895" Received: from mail-mtas26.fraunhofer.de ([153.97.7.26]) by mail-edgeS23.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Aug 2019 21:15:10 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BaAAB4l11dfRBhWMBkGwEBAQEDAQEBBwMBAQGBVgMBAQELAYNWIDyNG5FvkTAJAQMBAQEBAQgvAQGEPwKCfzcGDgIFAQEEAQEBAgEGBBQBARY6hS4MhUsDAzIBRhBRIRwaBg4FgyKBawMdrFCIIA1hgUkJAYEqAYcUhjE/gRABg1CCGoJ3hRYEjDOCL4dvlERABwKBOmVfBI9dg20MG4IxixyKeY8RiCeOWYFmIYFZMxokgzuCTheDSIpcPQMwAY1FAQE X-IronPort-AV: E=Sophos;i="5.64,412,1559512800"; d="scan'208";a="86123332" Received: from fgdemucivp01ltm.xch.fraunhofer.de (HELO FGDEMUCIMP11EXC.ads.fraunhofer.de) ([192.88.97.16]) by mail-mtaS26.fraunhofer.de with ESMTP/TLS/AES256-SHA; 21 Aug 2019 21:15:10 +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, 21 Aug 2019 21:15:10 +0200 From: Lukas Auer To: Date: Wed, 21 Aug 2019 21:14:46 +0200 Message-ID: <20190821191450.14507-8-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190821191450.14507-1-lukas.auer@aisec.fraunhofer.de> References: <20190821191450.14507-1-lukas.auer@aisec.fraunhofer.de> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-24858.003 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: Alistair Francis Subject: [U-Boot] [RESEND PATCH v4 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 v4: None 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 8c9415bedf..082fa2bd94 100644 --- a/common/spl/spl.c +++ b/common/spl/spl.c @@ -781,7 +781,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;