From patchwork Sun Jul 21 17:59:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Auer X-Patchwork-Id: 1134557 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 45sCqC4TtBz9s4Y for ; Mon, 22 Jul 2019 04:25:59 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 55D80C21F7A; Sun, 21 Jul 2019 18:25:58 +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 8202CC21E44; Sun, 21 Jul 2019 18:02:09 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C5666C21E39; Sun, 21 Jul 2019 18:02:07 +0000 (UTC) Received: from mail-edgeKA24.fraunhofer.de (mail-edgeka24.fraunhofer.de [153.96.1.24]) by lists.denx.de (Postfix) with ESMTPS id 92125C21D74 for ; Sun, 21 Jul 2019 18:00:59 +0000 (UTC) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A2EtAAB5pzRd/xmnZsBmGwEBAQEDAQEBBwMBAQGBVAUBAQELAYIWgT8BHzyNGIkYmw2BewkBAQEBAQEBAQEILwEBhEACglMjNQgOAQMBAQUBAQEBBgICaYUqhUwGMgFGEFE9GgYOBYMigguqcohugUgJAYEqAYcHhFeBVz+BEAGDUIURhRYEjBiCLYdalEQHAoE5Yl0Ekx8MG4ItiwWKWI5mlkeBUgM0gVgzGiSDO4JOF44jPQEyAY9UAQE X-IPAS-Result: A2EtAAB5pzRd/xmnZsBmGwEBAQEDAQEBBwMBAQGBVAUBAQELAYIWgT8BHzyNGIkYmw2BewkBAQEBAQEBAQEILwEBhEACglMjNQgOAQMBAQUBAQEBBgICaYUqhUwGMgFGEFE9GgYOBYMigguqcohugUgJAYEqAYcHhFeBVz+BEAGDUIURhRYEjBiCLYdalEQHAoE5Yl0Ekx8MG4ItiwWKWI5mlkeBUgM0gVgzGiSDO4JOF44jPQEyAY9UAQE X-IronPort-AV: E=Sophos;i="5.64,291,1559512800"; d="scan'208";a="16085683" Received: from mail-mtadd25.fraunhofer.de ([192.102.167.25]) by mail-edgeKA24.fraunhofer.de with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Jul 2019 20:00:59 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BKAADrpjRdfRBhWMBmHAEBAQQBAQcEAQGBVAYBAQsBg1UgPI0YpCaBewkBAwEBAQEBCC8BAYRAAoJ1NQgOAQMBAQQBAQIBBhQBARY6hTGFSwMDMgFGEFE9GgYOBYMigguqc4hugUgJAYEqAYcHhi4/gRABg1CFEYUWBIwYgi2HWpREBwKBOWJdBJMfDBuCLYsFiliOZpZHgVIDMoFZMxokgzuCTheOIz0DMAGPVAEB X-IronPort-AV: E=Sophos;i="5.64,291,1559512800"; d="scan'208";a="52897845" Received: from fgdemucivp01ltm.xch.fraunhofer.de (HELO FGDEMUCIMP11EXC.ads.fraunhofer.de) ([192.88.97.16]) by mail-mtaDD25.fraunhofer.de with ESMTP/TLS/AES256-SHA; 21 Jul 2019 20:00:58 +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; Sun, 21 Jul 2019 20:00:58 +0200 From: Lukas Auer To: Date: Sun, 21 Jul 2019 19:59:59 +0200 Message-ID: <20190721180002.26993-8-lukas.auer@aisec.fraunhofer.de> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190721180002.26993-1-lukas.auer@aisec.fraunhofer.de> References: <20190721180002.26993-1-lukas.auer@aisec.fraunhofer.de> MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-11.0.0.4179-8.200.1013-24780.003 X-TM-AS-Result: No--9.137500-8.000000-31 X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No Cc: Marek Vasut , Alistair Francis , Miquel Raynal Subject: [U-Boot] [RFC PATCH 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 --- 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;