Received: by 2002:ab2:7b86:0:b0:1f7:5705:b850 with SMTP id q6csp1910lqh; Fri, 3 May 2024 11:22:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV6r1KNz3r5ICDAdLB9xbXtx0tvvY4DBbnw0CiAr5vJpKJtgh+AFM/tDZSH9g5INDWeyqkEz/CQFnhaKvCpvQ9cCgYDXhzfN8b90dYzug== X-Google-Smtp-Source: AGHT+IEFDFHpjISoxoiGQ9Q6evKbv2KKS7YcP01630WVp0HbF2KxL2rnC5QOocryd6YtPg5G+YTe X-Received: by 2002:a05:6512:539:b0:51e:24c7:bcd4 with SMTP id o25-20020a056512053900b0051e24c7bcd4mr2268991lfc.41.1714760564226; Fri, 03 May 2024 11:22:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714760564; cv=pass; d=google.com; s=arc-20160816; b=1FJAoB9rPGMUuEJOYhAfzOuLU7gjP2Y63SKWiJHySasyqJqYHQ44SjF5oSDT6wu8og ImVnPCQy/o0seyoA165RmMSUObFmLAMCv/wwPa8vBNOGj0wcn/qNgyCOad+Q5ZtPTusi DgK1+G5z9Us2pZQ3/oXVvGR4SBG26OwSV4lO7E/A/1v1VBZQK+zVPfM7Y/58XQ0TW4P/ 36cSlBLni7K4x7yRaNvxVCXMkjs19y14+DPsUw7AqF8HM6GRG4jufYbidXo/5r2PACRl ST+hi5e3U1e3Zljh/E7qDlD5bOCOhK+wP9ebViWfZ6lmfL1N77mNFqGi8t/BcjJsqYhr bOjw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=RBAtK6yz0tN7qnDVCrHDFDflditCb34tqrZg7A4OIKI=; fh=mX9v3iLjcwODTwZDbrtrdW0alQW2YjuTvaXwBe3PA6k=; b=i+XLJgiDtxBDIQQVaPcIwWsQr4GljkedQI19joGJ4RvI0zlnJeyakxDUEtAEfrptyb c2NHf9UeZTZe5kU9ok6oPutw5kjgpS8lhK7+FgYZ5Z1afy4RKwuiYzcG2/eznOBojp3K MC7QbcpuC8rm50IPbwUgsuioocpwzjoaW51Smw9jZVLtwoOVBCLlt2G/4ZnBMFnHk2Xh tHhGS/STXKvisHyb04Flc9wYrFYY/GSYv7lFib7gR6bBuSWqjcprSDJgTnglSvq7V/KG uZjvKYvEAe2qoeVXdlPWdylclIrS+wve1ZRkzhdFvuGD/cUF7yOgazXE+wgJkmUQef4H rMUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=sNuY3wXt; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-168037-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168037-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b1-20020a05640202c100b005705bc3edcesi1366194edx.84.2024.05.03.11.22.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 11:22:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-168037-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=sNuY3wXt; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-168037-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-168037-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id B50BB1F20F7C for ; Fri, 3 May 2024 18:22:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51BE115AAC9; Fri, 3 May 2024 18:19:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="sNuY3wXt" Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5FBD15A4B3 for ; Fri, 3 May 2024 18:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714760343; cv=none; b=hfS8HvvPDaT+GqKh/YT997enBlDT21hYj5ziPnKR5iPQ0f6fCLf+cJhwEgDkqodez1GsP9W9vm7Uoni9THyfbL5ZlYeKkk34brpVJx9p7lY7Ogxt0sZT74dIMYuHbUn3748kNNjExkv+alJXjcZO/Nb+vhv7UmLrnbL1ObL8exo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714760343; c=relaxed/simple; bh=2AJiZIKU/txIzz8lcRnB5tCco7QN7//SJU1vx5ohkb8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PkckzPrVfIf50gn85wpgX83D2QUd+mQHjl35yKvBURQvrfNWUJdMcs+KxDh0JJoMtkbrRUqSkTJmS3ytpRt9iXEUXNTAkaiKUiFCoEcqbGt0U0Fw8yZ7U26o5kiY5nXMpqIGCESTZI39+unAsxZ+VZGuJGlHMN6IzTjo1kc0X0U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=sNuY3wXt; arc=none smtp.client-ip=209.85.210.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6f30f69a958so8488b3a.1 for ; Fri, 03 May 2024 11:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1714760339; x=1715365139; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=RBAtK6yz0tN7qnDVCrHDFDflditCb34tqrZg7A4OIKI=; b=sNuY3wXtFeqE7BihZ7sM/X93QhDVra1/uW4JDfEtL/4TS9tl1uUhjlschj/ZFaRQsd WNIl3ss5Fr7D2+u6pdl2NsXmNLfujsf6c23wdTF/sdrAMNoPdMvDGXfwxK1mrduieHjN B4iFhLKyzBZIu0ny0/wAGhtcbb8KGJGP81OYNjLX9kBiqe6poULIMMT5xNYccmymjplx odc4SfidROUyDZ+H68X0g1LoREhmjtAXyRfwF0m2S9eX1doGpVHeyHPnf/jnGxDd3jSn zk+WU0rXETm2MAumYx2D2GBLw+N7BhzUGgIbB0daICqJb7/7YYSLsYdL9o5EB7N5d8OD N5eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714760339; x=1715365139; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RBAtK6yz0tN7qnDVCrHDFDflditCb34tqrZg7A4OIKI=; b=WSxQQeVZnz5E3amtK6k5ZyldJZSrvY7E0Fa68GceTqIrxO3Qqt5PIAHegkS+bp5AlH uUMC2tydREyLXDPZYeVGAOwbaP2a8LvM+dDP65h4XYXNxRsb73YcU8FOGZmSbI+jSO4X HjpdNF8l85maf6dHUGsRpD/dmqNmbLLV0U1tG14bO7DVpMHLvarU1lBkK5/jftZ5+NdA MEWOG8rr2lmoASmOL+xZTvLFMbomOfpKeEehkZNgVLZAyhiAF1W5m60jurkvCCUOV8Xw hIYfe2WVjzer/KulodnR+NDVB2D7zQ578JB1rBtoWwMOsxBNzYHqqtA7P69JmJBwZgWW 4KeQ== X-Forwarded-Encrypted: i=1; AJvYcCVF/+ocQJ86wzZUAcOwR0q6T6/Gt3vFZi0x1qw86nVZrkx0rt+LIu6mldtKrZEudu/FgD78Nl+rCDe3Ry5uh0PvjHUCKiQWviYIwfCK X-Gm-Message-State: AOJu0YxN3/J9NKUD6LE4ZjdC6PkM+109odd2uWA/f1H/DB4VgAI7LNmx uig0fIC3GPGNRQcwJBU7o5KrhTZFDqUid9rT8MQqfgEcizjAJ0IZZXJzEgmcxEg= X-Received: by 2002:a05:6a00:464e:b0:6ed:416d:f7c with SMTP id kp14-20020a056a00464e00b006ed416d0f7cmr3624054pfb.6.1714760338995; Fri, 03 May 2024 11:18:58 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id fu6-20020a056a00610600b006f3f5d3595fsm3355421pfb.80.2024.05.03.11.18.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 11:18:58 -0700 (PDT) From: Charlie Jenkins Date: Fri, 03 May 2024 11:18:23 -0700 Subject: [PATCH v6 08/17] riscv: cpufeature: Extract common elements from extension checking Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240503-dev-charlie-support_thead_vector_6_9-v6-8-cb7624e65d82@rivosinc.com> References: <20240503-dev-charlie-support_thead_vector_6_9-v6-0-cb7624e65d82@rivosinc.com> In-Reply-To: <20240503-dev-charlie-support_thead_vector_6_9-v6-0-cb7624e65d82@rivosinc.com> To: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Conor Dooley , Evan Green , =?utf-8?q?Cl=C3=A9ment_L=C3=A9ger?= , Jonathan Corbet , Shuah Khan Cc: linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1714760318; l=7158; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=2AJiZIKU/txIzz8lcRnB5tCco7QN7//SJU1vx5ohkb8=; b=LWLqB7Cfo1l2jPyXw8rQHX/mNnbZym6tL4XotX0hxgtS2JJO8U4lEMPfmckCNTtHJQCYfJrHi S5iJO/ZddEWDtchDwiqEXBcaYNlu5HjrM1q4LVt11Wk3huco5fl7lJf X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= The __riscv_has_extension_likely() and __riscv_has_extension_unlikely() functions from the vendor_extensions.h can be used to simplify the standard extension checking code as well. Migrate those functions to cpufeature.h and reorganize the code in the file to use the functions. Signed-off-by: Charlie Jenkins Reviewed-by: Conor Dooley --- arch/riscv/include/asm/cpufeature.h | 78 +++++++++++++++++------------- arch/riscv/include/asm/vendor_extensions.h | 28 ----------- arch/riscv/kernel/vendor_extensions.c | 16 +++--- 3 files changed, 51 insertions(+), 71 deletions(-) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index fedd479ccfd1..88723ac2d26e 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -98,59 +98,66 @@ extern bool riscv_isa_fallback; unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap); +#define STANDARD_EXT 0 + bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned int bit); #define riscv_isa_extension_available(isa_bitmap, ext) \ __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext) -static __always_inline bool -riscv_has_extension_likely(const unsigned long ext) +static __always_inline bool __riscv_has_extension_likely(const unsigned long vendor, + const unsigned long ext) { - compiletime_assert(ext < RISCV_ISA_EXT_MAX, - "ext must be < RISCV_ISA_EXT_MAX"); - - if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { - asm goto( - ALTERNATIVE("j %l[l_no]", "nop", 0, %[ext], 1) - : - : [ext] "i" (ext) - : - : l_no); - } else { - if (!__riscv_isa_extension_available(NULL, ext)) - goto l_no; - } + asm goto(ALTERNATIVE("j %l[l_no]", "nop", %[vendor], %[ext], 1) + : + : [vendor] "i" (vendor), [ext] "i" (ext) + : + : l_no); return true; l_no: return false; } -static __always_inline bool -riscv_has_extension_unlikely(const unsigned long ext) +static __always_inline bool __riscv_has_extension_unlikely(const unsigned long vendor, + const unsigned long ext) { - compiletime_assert(ext < RISCV_ISA_EXT_MAX, - "ext must be < RISCV_ISA_EXT_MAX"); - - if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { - asm goto( - ALTERNATIVE("nop", "j %l[l_yes]", 0, %[ext], 1) - : - : [ext] "i" (ext) - : - : l_yes); - } else { - if (__riscv_isa_extension_available(NULL, ext)) - goto l_yes; - } + asm goto(ALTERNATIVE("nop", "j %l[l_yes]", %[vendor], %[ext], 1) + : + : [vendor] "i" (vendor), [ext] "i" (ext) + : + : l_yes); return false; l_yes: return true; } +static __always_inline bool riscv_has_extension_unlikely(const unsigned long ext) +{ + compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX"); + + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) + return __riscv_has_extension_unlikely(STANDARD_EXT, ext); + + return __riscv_isa_extension_available(NULL, ext); +} + +static __always_inline bool riscv_has_extension_likely(const unsigned long ext) +{ + compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX"); + + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) + return __riscv_has_extension_likely(STANDARD_EXT, ext); + + return __riscv_isa_extension_available(NULL, ext); +} + static __always_inline bool riscv_cpu_has_extension_likely(int cpu, const unsigned long ext) { - if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && riscv_has_extension_likely(ext)) + compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX"); + + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && + __riscv_has_extension_likely(STANDARD_EXT, ext)) return true; return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); @@ -158,7 +165,10 @@ static __always_inline bool riscv_cpu_has_extension_likely(int cpu, const unsign static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsigned long ext) { - if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && riscv_has_extension_unlikely(ext)) + compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX"); + + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && + __riscv_has_extension_unlikely(STANDARD_EXT, ext)) return true; return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); diff --git a/arch/riscv/include/asm/vendor_extensions.h b/arch/riscv/include/asm/vendor_extensions.h index a6959836f895..d21e411d7338 100644 --- a/arch/riscv/include/asm/vendor_extensions.h +++ b/arch/riscv/include/asm/vendor_extensions.h @@ -47,34 +47,6 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsig __riscv_isa_vendor_extension_available(VENDOR_EXT_ALL_CPUS, vendor, \ RISCV_ISA_VENDOR_EXT_##ext) -static __always_inline bool __riscv_has_extension_likely(const unsigned long vendor, - const unsigned long ext) -{ - asm goto(ALTERNATIVE("j %l[l_no]", "nop", %[vendor], %[ext], 1) - : - : [vendor] "i" (vendor), [ext] "i" (ext) - : - : l_no); - - return true; -l_no: - return false; -} - -static __always_inline bool __riscv_has_extension_unlikely(const unsigned long vendor, - const unsigned long ext) -{ - asm goto(ALTERNATIVE("nop", "j %l[l_yes]", %[vendor], %[ext], 1) - : - : [vendor] "i" (vendor), [ext] "i" (ext) - : - : l_yes); - - return false; -l_yes: - return true; -} - static __always_inline bool riscv_has_vendor_extension_likely(const unsigned long vendor, const unsigned long ext) { diff --git a/arch/riscv/kernel/vendor_extensions.c b/arch/riscv/kernel/vendor_extensions.c index e4ef574b7d08..7910890c17de 100644 --- a/arch/riscv/kernel/vendor_extensions.c +++ b/arch/riscv/kernel/vendor_extensions.c @@ -31,16 +31,14 @@ const size_t riscv_isa_vendor_ext_list_size = ARRAY_SIZE(riscv_isa_vendor_ext_li */ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsigned int bit) { - unsigned long *bmap; - struct riscv_isainfo *cpu_bmap; - size_t bmap_size; + struct riscv_isavendorinfo *bmap; + struct riscv_isavendorinfo *cpu_bmap; switch (vendor) { #ifdef CONFIG_RISCV_ISA_VENDOR_EXT_THEAD case THEAD_VENDOR_ID: - bmap = riscv_isa_vendor_ext_list_thead.vendor_bitmap; - cpu_bmap = riscv_isa_vendor_ext_list_thead.per_hart_vendor_bitmap; - bmap_size = riscv_isa_vendor_ext_list_thead.bitmap_size; + bmap = &riscv_isa_vendor_ext_list_thead.all_harts_isa_bitmap; + cpu_bmap = &riscv_isa_vendor_ext_list_thead.per_hart_isa_bitmap[cpu]; break; #endif default: @@ -48,11 +46,11 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsig } if (cpu != -1) - bmap = cpu_bmap[cpu].isa; + bmap = &cpu_bmap[cpu]; - if (bit >= bmap_size) + if (bit >= RISCV_ISA_VENDOR_EXT_MAX) return false; - return test_bit(bit, bmap) ? true : false; + return test_bit(bit, bmap->isa) ? true : false; } EXPORT_SYMBOL_GPL(__riscv_isa_vendor_extension_available); -- 2.44.0