From patchwork Mon Mar 27 16:49:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13189640 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 156BCC76195 for ; Mon, 27 Mar 2023 16:50:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232484AbjC0Quh (ORCPT ); Mon, 27 Mar 2023 12:50:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232489AbjC0Qud (ORCPT ); Mon, 27 Mar 2023 12:50:33 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18D3230D8 for ; Mon, 27 Mar 2023 09:50:29 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id c18so8986175ple.11 for ; Mon, 27 Mar 2023 09:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1679935828; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=N6sthDjw4vtxdvhOKIkR5X0eOJXk5+GMCZ4mTQ3uH3I=; b=hyfL3p5Zx4BC1YGV46tkxRRFY1JI4uKQXaB6Sj1JY3obGwCHKHGSaVzHl8qpQDk6hJ txcpi/4v9Bpj1bq/KCjgl2VjwXyixOEXfi6EdbysJovJNuO6Cy3ssWnp03yrYG8se3jl 9uu3/OknqS3LVqDYU1ZyI+GjwjUjdCnxkzvfvzzB3tjEn2SCazpnuwfWmLOTbLpDkEiM 0R9ozqEPnZICWywp/lvIHghpT/1kxr9cOTYpgmULsUmI0IjUhRECeBSrJNscz4LQdbNA g7yRccRUV+00apCH/Pjvrt/+VJBbKMPrx/vlN5Dv1clBY1r8o1iZKrBVZEN6YUBa/BM4 Iz1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679935828; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=N6sthDjw4vtxdvhOKIkR5X0eOJXk5+GMCZ4mTQ3uH3I=; b=crgU9TWlsdFROpt3WWzyRFrXyReBH03ERL+7WTMKk08P08j2C8cZqFjuEEHYYb/yC4 lZk3zF8PxT5Mef+clMdoYDeaf/r06CAZAZRqX4DJwU/aZ3pUa7TFjhwcGooB8pTtX/7H fZmqf5ua0f8H+V6LRcdXR86gwMCJoEsusRvCjhEM2LTb3zTRJG37308v7QEjxbMvQ0Vx Kz4AAlxMalMcvPPE3X636Ab0/qEvAGcnvy3YEKdrJBlKQqr3dA3QoJwSOmgn8gpTFsUZ cTNFOYwStNf5zpaZmLmXhOFVyBDMoHyUNB9IkjsuxGnOYmytSngNnspZWr7v8IXyAAhi 3uPw== X-Gm-Message-State: AO0yUKVEYnJEZuOcOMVSrccSas15jSSSR7g2rmqFpZ0KosKvFNjBrssM g1N6AqWZTViPpFzqYWDqLL1FAA== X-Google-Smtp-Source: AK7set+HTiH3bTe7e73jKAH2xQz5pm4TlSvwviQzdS0shICWtkwJECuVyMeWQarDFMOXapXsK8LtYw== X-Received: by 2002:a05:6a20:a82a:b0:db:1b41:704 with SMTP id cb42-20020a056a20a82a00b000db1b410704mr10369163pzb.16.1679935828496; Mon, 27 Mar 2023 09:50:28 -0700 (PDT) Received: from hsinchu25.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id q20-20020a62e114000000b0061949fe3beasm19310550pfh.22.2023.03.27.09.50.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Mar 2023 09:50:27 -0700 (PDT) From: Andy Chiu To: linux-riscv@lists.infradead.org, palmer@dabbelt.com, anup@brainfault.org, atishp@atishpatra.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: vineetg@rivosinc.com, greentime.hu@sifive.com, guoren@linux.alibaba.com, Vincent Chen , Andy Chiu , Paul Walmsley , Albert Ou , Guo Ren , Conor Dooley , Heiko Stuebner , Li Zhengyu , Xianting Tian , Masahiro Yamada , Jisheng Zhang , Andrew Jones , Richard Henderson Subject: [PATCH -next v17 07/20] riscv: Introduce riscv_v_vsize to record size of Vector context Date: Mon, 27 Mar 2023 16:49:27 +0000 Message-Id: <20230327164941.20491-8-andy.chiu@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230327164941.20491-1-andy.chiu@sifive.com> References: <20230327164941.20491-1-andy.chiu@sifive.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Greentime Hu This patch is used to detect the size of CPU vector registers and use riscv_v_vsize to save the size of all the vector registers. It assumes all harts has the same capabilities in a SMP system. Co-developed-by: Guo Ren Signed-off-by: Guo Ren Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Signed-off-by: Greentime Hu Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Tested-by: Heiko Stuebner --- arch/riscv/include/asm/vector.h | 5 +++++ arch/riscv/kernel/Makefile | 1 + arch/riscv/kernel/cpufeature.c | 2 ++ arch/riscv/kernel/vector.c | 20 ++++++++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 arch/riscv/kernel/vector.c diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index dfe5a321b2b4..e433ba3cd4da 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -13,6 +13,9 @@ #include #include +extern unsigned long riscv_v_vsize; +void riscv_v_setup_vsize(void); + static __always_inline bool has_vector(void) { return riscv_has_extension_likely(RISCV_ISA_EXT_v); @@ -31,6 +34,8 @@ static __always_inline void riscv_v_disable(void) #else /* ! CONFIG_RISCV_ISA_V */ static __always_inline bool has_vector(void) { return false; } +#define riscv_v_vsize (0) +#define riscv_v_setup_vsize() do {} while (0) #endif /* CONFIG_RISCV_ISA_V */ diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index 392fa6e35d4a..be23a021ec32 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -55,6 +55,7 @@ obj-$(CONFIG_MMU) += vdso.o vdso/ obj-$(CONFIG_RISCV_M_MODE) += traps_misaligned.o obj-$(CONFIG_FPU) += fpu.o +obj-$(CONFIG_RISCV_ISA_V) += vector.o obj-$(CONFIG_SMP) += smpboot.o obj-$(CONFIG_SMP) += smp.o obj-$(CONFIG_SMP) += cpu_ops.o diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 923ca75f2192..267070f3cc9e 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -17,6 +17,7 @@ #include #include #include +#include #define NUM_ALPHA_EXTS ('z' - 'a' + 1) @@ -263,6 +264,7 @@ void __init riscv_fill_hwcap(void) } if (elf_hwcap & COMPAT_HWCAP_ISA_V) { + riscv_v_setup_vsize(); /* * ISA string in device tree might have 'v' flag, but * CONFIG_RISCV_ISA_V is disabled in kernel. diff --git a/arch/riscv/kernel/vector.c b/arch/riscv/kernel/vector.c new file mode 100644 index 000000000000..03582e2ade83 --- /dev/null +++ b/arch/riscv/kernel/vector.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2023 SiFive + * Author: Andy Chiu + */ +#include + +#include +#include + +unsigned long riscv_v_vsize __read_mostly; +EXPORT_SYMBOL_GPL(riscv_v_vsize); + +void riscv_v_setup_vsize(void) +{ + /* There are 32 vector registers with vlenb length. */ + riscv_v_enable(); + riscv_v_vsize = csr_read(CSR_VLENB) * 32; + riscv_v_disable(); +}