From mboxrd@z Thu Jan 1 00:00:00 1970 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 98391C4332F for ; Wed, 16 Feb 2022 00:29:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245080AbiBPA3r (ORCPT ); Tue, 15 Feb 2022 19:29:47 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:51564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245054AbiBPA3k (ORCPT ); Tue, 15 Feb 2022 19:29:40 -0500 Received: from mail-qt1-x82e.google.com (mail-qt1-x82e.google.com [IPv6:2607:f8b0:4864:20::82e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D343F70FC for ; Tue, 15 Feb 2022 16:29:28 -0800 (PST) Received: by mail-qt1-x82e.google.com with SMTP id o3so546388qtm.12 for ; Tue, 15 Feb 2022 16:29:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+mccZjH8NSKhWBiWsNwtOYrEp5jTHyxoNdNyuVqRQ88=; b=mDyg+hQZjMQDU9Uq7wsWXXtGXQt/Kj3wzuz1/ouJ/1Wf9LjhMW6HW/T5utJ7R+WoUO 8ZXqbkqpEOb7GH1YMqNDIXq+OW1lM5Ma7mLStdU64iy/UHbzDEKDPbQjJ3HcCvwwdlbI bsswUsWe0lxui3GYvtDlMTQKfDytGV898nYDWDOQANRtVJSQ1Kv35c7mkzYzj5MRe47v RRGq65bEr75KzZdsUYEPWi1htw2XehtkmyS9FwVO5wnnBz6H/lkp6qAEkHXXQI54eeQt Z/NDyijOhyhwoQBNpbyY6YKCoQU5JfwFIcTXE+jrErWVabp3/EAv827jBRw0BggzjQ41 FXMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+mccZjH8NSKhWBiWsNwtOYrEp5jTHyxoNdNyuVqRQ88=; b=OACcaZqDWEM5OSmrpnPFKbJGWfSajf5jWOa6K7XKLTrG9M6tBGnbfyYpXlpwwPQCdU 0Z5cBPIj7vBlzIezN5x+Ug2DCj9BQEHypUR/E3B3Ipdce+81MGrX+p4Ak5/qo51fr+Tz gyFUxcmyeHy0MUq63MK5K7An9siB+D3F5iqF2p/t8x0Vz6ZueqZzXeo/pEDBAZauVu06 j0hc+FG6v/z0mzvbmpe7RaYmB/0vS7PPhOh3D8L8r0lj4tkmC0J/AwfaqBrDX1dh9a9z 0Md3xa+WBELBhcXtHCFI5pxRw1Ut9UISxOuaDwlZF5M1zsR0sjqzPV7KvsYuGA13LAiz oHRA== X-Gm-Message-State: AOAM531WVIfl7KVgekCtM8Ae7yOKIWFGBAdvGwRJIWCLM+inEZKwXJvS Hl3U1Tk12HMOIdwjgfaLOcvTszNeC7Yd1rS0 X-Google-Smtp-Source: ABdhPJxX/1iKDISaumVfrJKyBSCp+qB9sw5uGTWszMRMIRfujWc3uyE9wjTNu2++q4autCmibTBZPQ== X-Received: by 2002:a05:622a:4d2:b0:2d7:1d2e:6dd0 with SMTP id q18-20020a05622a04d200b002d71d2e6dd0mr372899qtx.615.1644971367357; Tue, 15 Feb 2022 16:29:27 -0800 (PST) Received: from rivos-atish.. (adsl-70-228-75-190.dsl.akrnoh.ameritech.net. [70.228.75.190]) by smtp.gmail.com with ESMTPSA id g21sm20882584qtb.70.2022.02.15.16.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 16:29:26 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Albert Ou , Atish Patra , Anup Patel , Damien Le Moal , devicetree@vger.kernel.org, Jisheng Zhang , Krzysztof Kozlowski , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , heiko@sntech.de, Rob Herring Subject: [PATCH v4 4/6] RISC-V: Implement multi-letter ISA extension probing framework Date: Tue, 15 Feb 2022 16:29:09 -0800 Message-Id: <20220216002911.1219593-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220216002911.1219593-1-atishp@rivosinc.com> References: <20220216002911.1219593-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Multi-letter extensions can be probed using exising riscv_isa_extension_available API now. It doesn't support versioning right now as there is no use case for it. Individual extension specific implementation will be added during each extension support. Signed-off-by: Atish Patra --- arch/riscv/include/asm/hwcap.h | 18 ++++++++++++++++++ arch/riscv/kernel/cpufeature.c | 24 ++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 5ce50468aff1..170bd80da520 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -34,7 +34,25 @@ extern unsigned long elf_hwcap; #define RISCV_ISA_EXT_s ('s' - 'a') #define RISCV_ISA_EXT_u ('u' - 'a') +/* + * Increse this to higher value as kernel support more ISA extensions. + */ #define RISCV_ISA_EXT_MAX 64 +#define RISCV_ISA_EXT_NAME_LEN_MAX 32 + +/* The base ID for multi-letter ISA extensions */ +#define RISCV_ISA_EXT_BASE 26 + +/* + * This enum represent the logical ID for each multi-letter RISC-V ISA extension. + * The logical ID should start from RISCV_ISA_EXT_BASE and must not exceed + * RISCV_ISA_EXT_MAX. 0-25 range is reserved for single letter + * extensions while all the multi-letter extensions should define the next + * available logical extension id. + */ +enum riscv_isa_ext_id { + RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, +}; unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap); diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index cd9eb34f8d11..59c70c104256 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -83,7 +83,7 @@ void __init riscv_fill_hwcap(void) for_each_of_cpu_node(node) { unsigned long this_hwcap = 0; - unsigned long this_isa = 0; + DECLARE_BITMAP(this_isa, RISCV_ISA_EXT_MAX); if (riscv_of_processor_hartid(node) < 0) continue; @@ -100,6 +100,7 @@ void __init riscv_fill_hwcap(void) if (!strncmp(isa, "rv64", 4)) isa += 4; #endif + bitmap_zero(this_isa, RISCV_ISA_EXT_MAX); for (; *isa; ++isa) { const char *ext = isa++; const char *ext_end = isa; @@ -167,12 +168,22 @@ void __init riscv_fill_hwcap(void) if (*isa != '_') --isa; +#define SET_ISA_EXT_MAP(name, bit) \ + do { \ + if ((ext_end - ext == sizeof(name) - 1) && \ + !memcmp(ext, name, sizeof(name) - 1)) { \ + set_bit(bit, this_isa); \ + pr_info("Found ISA extension %s", name);\ + } \ + } while (false) \ + if (unlikely(ext_err)) continue; if (!ext_long) { this_hwcap |= isa2hwcap[(unsigned char)(*ext)]; - this_isa |= (1UL << (*ext - 'a')); + set_bit(*ext - 'a', this_isa); } +#undef SET_ISA_EXT_MAP } /* @@ -185,10 +196,11 @@ void __init riscv_fill_hwcap(void) else elf_hwcap = this_hwcap; - if (riscv_isa[0]) - riscv_isa[0] &= this_isa; + if (bitmap_weight(riscv_isa, RISCV_ISA_EXT_MAX)) + bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX); else - riscv_isa[0] = this_isa; + bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX); + } /* We don't support systems with F but without D, so mask those out @@ -202,7 +214,7 @@ void __init riscv_fill_hwcap(void) for (i = 0, j = 0; i < NUM_ALPHA_EXTS; i++) if (riscv_isa[0] & BIT_MASK(i)) print_str[j++] = (char)('a' + i); - pr_info("riscv: ISA extensions %s\n", print_str); + pr_info("riscv: base ISA extensions %s\n", print_str); memset(print_str, 0, sizeof(print_str)); for (i = 0, j = 0; i < NUM_ALPHA_EXTS; i++) -- 2.30.2