From patchwork Mon Feb 13 08:43:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Liang X-Patchwork-Id: 1741463 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PFdDS6p8Mz23hX for ; Mon, 13 Feb 2023 19:44:08 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C8E2380AE6; Mon, 13 Feb 2023 09:43:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=andestech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id CE97E80AE0; Mon, 13 Feb 2023 09:43:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, PDS_RDNS_DYNAMIC_FP, RDNS_DYNAMIC,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from Atcsqr.andestech.com (60-248-80-70.hinet-ip.hinet.net [60.248.80.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9D8F380AE3 for ; Mon, 13 Feb 2023 09:43:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=andestech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ycliang@andestech.com Received: from mail.andestech.com (ATCPCS16.andestech.com [10.0.1.222]) by Atcsqr.andestech.com with ESMTP id 31D8hJGG082000; Mon, 13 Feb 2023 16:43:19 +0800 (+08) (envelope-from ycliang@andestech.com) Received: from atcfdc88.andestech.com (10.0.15.158) by ATCPCS16.andestech.com (10.0.1.222) with Microsoft SMTP Server id 14.3.498.0; Mon, 13 Feb 2023 16:43:21 +0800 From: Leo Yu-Chi Liang To: , , CC: Subject: [V3,1/1] riscv: Increase the upper bound of NR_CPUS to 4095 Date: Mon, 13 Feb 2023 16:43:13 +0800 Message-ID: <20230213084313.10419-1-ycliang@andestech.com> X-Mailer: git-send-email 2.38.0.68.ge85701b4af.dirty MIME-Version: 1.0 X-Originating-IP: [10.0.15.158] X-DNSRBL: X-MAIL: Atcsqr.andestech.com 31D8hJGG082000 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean From: Xiang W The maximum hart number is 32 and is determined by the type of gd->arch.available_harts. However, various RISC-V specifications allow the hart number to be greater than 32. We can eliminate this limitation through bitmaps. The patch modifies the upper bound of the hart number to 4095, which is also the maximum hart number RISC-V Advanced Core Local Interruptor Specification gives. Some defconfigs, (e.g. qemu-riscv32_smode_defconfig, qemu-riscv64_smode_defconfig, openpiton_riscv64_defconfig, ...) do not define CONFIG_NR_CPUS, and may result in compile error, so define CONFIG_NR_CPUS to be 1 if CONFIG_NR_CPUS is not defined. Tested on sifive unmatched. Signed-off-by: Xiang W Signed-off-by: Leo Yu-Chi Liang --- Changes v2 -> v3: - Fix the calculation of the GD_AVAILABLE_HARTS start address - Fix compilation error for defconfigs that do not define CONFIG_NR_CPUS --- arch/riscv/Kconfig | 4 ++-- arch/riscv/cpu/start.S | 20 +++++++++++++++----- arch/riscv/include/asm/global_data.h | 8 +++++++- arch/riscv/lib/smp.c | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index ebc4bef220..063734cbb9 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -232,8 +232,8 @@ config SPL_SMP all, single processor machines. config NR_CPUS - int "Maximum number of CPUs (2-32)" - range 2 32 + int "Maximum number of CPUs (2-4095)" + range 2 4095 depends on SMP || SPL_SMP default 8 help diff --git a/arch/riscv/cpu/start.S b/arch/riscv/cpu/start.S index 4687bca3c9..ae19c2b43d 100644 --- a/arch/riscv/cpu/start.S +++ b/arch/riscv/cpu/start.S @@ -172,11 +172,21 @@ wait_for_gd_init: bnez t1, 1b /* register available harts in the available_harts mask */ - li t1, 1 - sll t1, t1, tp - LREG t2, GD_AVAILABLE_HARTS(gp) - or t2, t2, t1 - SREG t2, GD_AVAILABLE_HARTS(gp) + li t1, GD_AVAILABLE_HARTS + add t1, t1, gp +#if defined(CONFIG_ARCH_RV64I) + srli t2, tp, 6 + slli t2, t2, 3 +#elif defined(CONFIG_ARCH_RV32I) + srli t2, tp, 5 + slli t2, t2, 2 +#endif + add t1, t1, t2 + LREG t2, 0(t1) + li t3, 1 + sll t3, t3, tp + or t2, t2, t3 + SREG t2, 0(t1) amoswap.w.rl zero, zero, 0(t0) #endif diff --git a/arch/riscv/include/asm/global_data.h b/arch/riscv/include/asm/global_data.h index 6fdc86dd8b..7e37e90db0 100644 --- a/arch/riscv/include/asm/global_data.h +++ b/arch/riscv/include/asm/global_data.h @@ -10,9 +10,15 @@ #ifndef __ASM_GBL_DATA_H #define __ASM_GBL_DATA_H +#include #include #include #include +#include + +#ifndef CONFIG_NR_CPUS +#define CONFIG_NR_CPUS 1 +#endif /* Architecture-specific global data */ struct arch_global_data { @@ -29,7 +35,7 @@ struct arch_global_data { #endif #if !CONFIG_IS_ENABLED(XIP) #ifdef CONFIG_AVAILABLE_HARTS - ulong available_harts; + ulong available_harts[BITS_TO_LONGS(CONFIG_NR_CPUS)]; #endif #endif }; diff --git a/arch/riscv/lib/smp.c b/arch/riscv/lib/smp.c index 4f073a016f..511e3ed98d 100644 --- a/arch/riscv/lib/smp.c +++ b/arch/riscv/lib/smp.c @@ -48,7 +48,7 @@ static int send_ipi_many(struct ipi_data *ipi, int wait) #if !CONFIG_IS_ENABLED(XIP) #ifdef CONFIG_AVAILABLE_HARTS /* skip if hart is not available */ - if (!(gd->arch.available_harts & (1 << reg))) + if (!test_bit(reg, gd->arch.available_harts)) continue; #endif #endif