From patchwork Fri Apr 14 15:58:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13211748 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 804DBC77B71 for ; Fri, 14 Apr 2023 15:59:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230369AbjDNP7P (ORCPT ); Fri, 14 Apr 2023 11:59:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbjDNP7K (ORCPT ); Fri, 14 Apr 2023 11:59:10 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A33862691 for ; Fri, 14 Apr 2023 08:59:07 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id g6so1845002pjx.4 for ; Fri, 14 Apr 2023 08:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1681487947; x=1684079947; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=U7ri8ZSvnPvQyAXJ6dQGQtYIAraNypeWm5i0/GIq5FY=; b=YGmvXm/TuZoti9wweuSje/DwLyT5H6AiJaRqLiuK8jADZAJMP4Th25m4WmcRnYQbh3 WC1CY6kS84eID7rzBNa3mpK+uRN9O4nqQKKiOYyxKNc7OiWGMeWkAsi9wQMirwCNcmp8 k15vupj6hAY+hZ1EXRw/8bxxxxbGYtPq7prx9AagWTmKP5iNBHC9Kgc4j0YC76tK76IO OzmKVA6KRzd9ZAexvU9vOVLfiXvwFp5JdiYvi91oTZOHUQB6oLP9ObWHKUpjdTMYar19 Q4x8TLumG60vSH+2HAmEzgNEm5n8uGGctC7JDTWbImNbUWxdSjjT1GS0bGAPCQJ4d6wM mNIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681487947; x=1684079947; 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=U7ri8ZSvnPvQyAXJ6dQGQtYIAraNypeWm5i0/GIq5FY=; b=Ur/bO8i+bEfWqiR7GhdxuT33aH5ocMfFKO20SOi6VpFVNTjatEGwCvRM9LykziA1bI Palin8yCRfpinzGg/ZG8CbT29NBGaJLuGBTXJOq2t/dG3NsFzsPm4H8LYOeCFdNBdlX3 +VLW+s3M4EauaT6dFO5rX0Dm32kDWCpUJEJFwUllmpi+MjNJkllnP2WY/Au7Ft5g6CA+ 8bdqQUfY8YM2vYbCCNptv0aUxCW1ZnR7WFrGxEhBTxqZlBB/oynoybbhl0Mbgd6QPhYx om79v1gcXtwj4rFA52aWvmkFAFrMJUhDFT70V3Z3UzAyB7Axl4AzdRIRaUaCxamL31zb RJNg== X-Gm-Message-State: AAQBX9dfL5eICPe90Hez58C0WFtzHuPm8rdgAdY3dsQM0SRyAHupO1eb Ym0gouqPp9kfL4u4iv7CEwsyEnKfllX4RMDrb0M= X-Google-Smtp-Source: AKy350YnbAtdYK25WZBT6vEyXz1kqM58xh87+9tiIROkMCKXWs4cw9ZPIPVhDSDuh+/FG9kqtQfPXw== X-Received: by 2002:a17:903:32cd:b0:1a5:2c2e:e41d with SMTP id i13-20020a17090332cd00b001a52c2ee41dmr4492968plr.51.1681487946919; Fri, 14 Apr 2023 08:59:06 -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 br8-20020a17090b0f0800b00240d4521958sm3083584pjb.18.2023.04.14.08.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 08:59:06 -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, Guo Ren , Andy Chiu , Paul Walmsley , Albert Ou , Conor Dooley , Heiko Stuebner , Andrew Jones , Guo Ren , Jisheng Zhang , Dao Lu , Vincent Chen Subject: [PATCH -next v18 02/20] riscv: Extending cpufeature.c to detect V-extension Date: Fri, 14 Apr 2023 15:58:25 +0000 Message-Id: <20230414155843.12963-3-andy.chiu@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230414155843.12963-1-andy.chiu@sifive.com> References: <20230414155843.12963-1-andy.chiu@sifive.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Guo Ren Add V-extension into riscv_isa_ext_keys array and detect it with isa string parsing. Signed-off-by: Guo Ren Signed-off-by: Guo Ren Signed-off-by: Greentime Hu Suggested-by: Vineet Gupta Co-developed-by: Andy Chiu Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- arch/riscv/include/asm/hwcap.h | 1 + arch/riscv/include/asm/vector.h | 26 ++++++++++++++++++++++++++ arch/riscv/include/uapi/asm/hwcap.h | 1 + arch/riscv/kernel/cpufeature.c | 11 +++++++++++ 4 files changed, 39 insertions(+) create mode 100644 arch/riscv/include/asm/vector.h diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 9af793970855..5165588d1e8c 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -22,6 +22,7 @@ #define RISCV_ISA_EXT_m ('m' - 'a') #define RISCV_ISA_EXT_s ('s' - 'a') #define RISCV_ISA_EXT_u ('u' - 'a') +#define RISCV_ISA_EXT_v ('v' - 'a') /* * These macros represent the logical IDs of each multi-letter RISC-V ISA diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h new file mode 100644 index 000000000000..427a3b51df72 --- /dev/null +++ b/arch/riscv/include/asm/vector.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2020 SiFive + */ + +#ifndef __ASM_RISCV_VECTOR_H +#define __ASM_RISCV_VECTOR_H + +#include + +#ifdef CONFIG_RISCV_ISA_V + +#include + +static __always_inline bool has_vector(void) +{ + return riscv_has_extension_likely(RISCV_ISA_EXT_v); +} + +#else /* ! CONFIG_RISCV_ISA_V */ + +static __always_inline bool has_vector(void) { return false; } + +#endif /* CONFIG_RISCV_ISA_V */ + +#endif /* ! __ASM_RISCV_VECTOR_H */ diff --git a/arch/riscv/include/uapi/asm/hwcap.h b/arch/riscv/include/uapi/asm/hwcap.h index 46dc3f5ee99f..c52bb7bbbabe 100644 --- a/arch/riscv/include/uapi/asm/hwcap.h +++ b/arch/riscv/include/uapi/asm/hwcap.h @@ -21,5 +21,6 @@ #define COMPAT_HWCAP_ISA_F (1 << ('F' - 'A')) #define COMPAT_HWCAP_ISA_D (1 << ('D' - 'A')) #define COMPAT_HWCAP_ISA_C (1 << ('C' - 'A')) +#define COMPAT_HWCAP_ISA_V (1 << ('V' - 'A')) #endif /* _UAPI_ASM_RISCV_HWCAP_H */ diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 00d7cd2c9043..923ca75f2192 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -103,6 +103,7 @@ void __init riscv_fill_hwcap(void) isa2hwcap['f' - 'a'] = COMPAT_HWCAP_ISA_F; isa2hwcap['d' - 'a'] = COMPAT_HWCAP_ISA_D; isa2hwcap['c' - 'a'] = COMPAT_HWCAP_ISA_C; + isa2hwcap['v' - 'a'] = COMPAT_HWCAP_ISA_V; elf_hwcap = 0; @@ -261,6 +262,16 @@ void __init riscv_fill_hwcap(void) elf_hwcap &= ~COMPAT_HWCAP_ISA_F; } + if (elf_hwcap & COMPAT_HWCAP_ISA_V) { + /* + * ISA string in device tree might have 'v' flag, but + * CONFIG_RISCV_ISA_V is disabled in kernel. + * Clear V flag in elf_hwcap if CONFIG_RISCV_ISA_V is disabled. + */ + if (!IS_ENABLED(CONFIG_RISCV_ISA_V)) + elf_hwcap &= ~COMPAT_HWCAP_ISA_V; + } + memset(print_str, 0, sizeof(print_str)); for (i = 0, j = 0; i < NUM_ALPHA_EXTS; i++) if (riscv_isa[0] & BIT_MASK(i))