Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp521197pxb; Tue, 15 Feb 2022 20:42:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxCGqHkdaJd/bPxoEddrQxcCxCNod2J8/GvPLQgSG0ylybOHUVr/g/oqrxKdWdY1ungYDpC X-Received: by 2002:a17:906:154c:b0:6ce:21d7:2826 with SMTP id c12-20020a170906154c00b006ce21d72826mr846489ejd.9.1644986526818; Tue, 15 Feb 2022 20:42:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644986526; cv=none; d=google.com; s=arc-20160816; b=AwkGOVFVQqhZkAjKMVbZrfiU4wyXq38xMa51KwrB4E5Vw0ngHLRDjx5zmaPLUD7ar7 5pLRVPQGmuHc6gTUUehAEAlSZlKolh5Z5nZSskXbJiF6xM2S3ZdE8G/uElfdh1OYm9ds gbOi83OcRs8JuWtQDa4JF61Wy73HJ4zzoe+aSEYpO4+CAFXrTPHOMTC+NihNOfyU5+mF MoUcOxwUpk2e4bZ+uHC0XrI6j8QLfiuhF/OXOVWi0/rroamHzfL5AipLZKlg0G9q+iRE KAvw70SbTKHnpP9V3zcMA5BmUuicHn/oeUe4lXMGs9vAQoNZC5bVQgWxAqpIV0497wry O3Rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=loAfDoGLfr/iqSIkMgZ8bYEjmt72BeZCLhtdpL5OIaQ=; b=X+2ppZ9RCE0566QTxLtwFRurZPGEBdj8NXHOqRyR/zhxQNIIKrWIErDZE3+7Uxylam ot1Y2fNqUTXGPk6GcMHJ4VyzVNAlDLgAXDnZ/JKrG+0AK/GJt2ddVE8gumd4ac7RhQCn SBS7u19N5Nc2LmfG5NUEVy2TjXbCKRssNgoWrq+kRVuvSHANkvtlajygR0JEcA6woG8f LTmT7svu/rD8N665+oCJfrbil8+I1+AxjSbupg6IRojOhU8k5GCNKyGrji7i1NXl/G1Q H654HNU6OHNCGRIgt635HEONlJhtNg/LGpVKj/DUM3Zcu/cHWV5KPpsMbH9xS9dcq14l oDzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=gNwn4w1B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3si24938561ejw.731.2022.02.15.20.41.43; Tue, 15 Feb 2022 20:42:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=gNwn4w1B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244734AbiBOXMP (ORCPT + 99 others); Tue, 15 Feb 2022 18:12:15 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244412AbiBOXMO (ORCPT ); Tue, 15 Feb 2022 18:12:14 -0500 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77B4B13F74 for ; Tue, 15 Feb 2022 15:12:03 -0800 (PST) Received: by mail-yb1-xb36.google.com with SMTP id c6so774001ybk.3 for ; Tue, 15 Feb 2022 15:12:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=loAfDoGLfr/iqSIkMgZ8bYEjmt72BeZCLhtdpL5OIaQ=; b=gNwn4w1BBG0QO8d7il/hS7XnsvBv8CEpuRu43msQBQZCnhs9Fnj5h72+hczDMizL64 9MeW8FDditxJs7M787wypzS7HhaJKVRx4aLxywV+pZoSHdANKzvX0JPQx2u6to6zWfDy ZXcynRo469aF4QZX+xgx+6suPf+EIZz6Cfvl8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=loAfDoGLfr/iqSIkMgZ8bYEjmt72BeZCLhtdpL5OIaQ=; b=uWB6E3V/iwYNdUoCxwtNa/NsvRnR7iSXUE3naD/7DnNfpSRr3QU5/6PurfVqw4fDcK lA+9PKaiEsTL/rVxV1Diu+ywuTFUg/uHBIoDr0GInpsAZ/aSU8bD1PJXGCdKdHgv8adO R0JnSlyVi2UrmVlQigKrs3CDRLrbsTBHiDHJi1C9C4EYiWgt6q46+jhd2EWoaipAm68X uEHLMgsJ4eC3fhwJt+/kdAzC7d6GSxbhAP6rbqBmf6P7BJfYJ1aCwnvk7l0+gJF3/Q4s XJzY/He/abpfhFiaGScBwT38s238Ce3xJ+ZUgur0EVuFM3ulcy6xCjSO57oRmv7ksdgl ox8g== X-Gm-Message-State: AOAM5317Y+2xbciVUHynSIuEkIwpPVhZWmAyEKtIcd6HQSEm0UvcMdkS uP7q9Hn+cuSpvI0s3I78u9QJgy6t5K51lp0hR/8n X-Received: by 2002:a25:c794:: with SMTP id w142mr1196085ybe.632.1644966722684; Tue, 15 Feb 2022 15:12:02 -0800 (PST) MIME-Version: 1.0 References: <20220215090211.911366-1-atishp@rivosinc.com> <20220215090211.911366-5-atishp@rivosinc.com> In-Reply-To: From: Atish Patra Date: Tue, 15 Feb 2022 15:11:51 -0800 Message-ID: Subject: Re: [PATCH v3 4/6] RISC-V: Implement multi-letter ISA extension probing framework To: Anup Patel Cc: Atish Patra , "linux-kernel@vger.kernel.org List" , Albert Ou , Damien Le Moal , DTML , Jisheng Zhang , Krzysztof Kozlowski , linux-riscv , Palmer Dabbelt , Paul Walmsley , Rob Herring Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 15, 2022 at 2:24 AM Anup Patel wrote: > > On Tue, Feb 15, 2022 at 2:32 PM Atish Patra wrote: > > > > 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 | 27 ++++++++++++++++++++++++--- > > 2 files changed, 42 insertions(+), 3 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..af9a57ad3d4e 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; > > + uint64_t this_isa = 0; > > Why not use a bitmap here ? > Yeah. That will simplify things for both RV32 & RV64. Thanks. > > > > if (riscv_of_processor_hartid(node) < 0) > > continue; > > @@ -167,12 +167,22 @@ void __init riscv_fill_hwcap(void) > > if (*isa != '_') > > --isa; > > > > +#define SET_ISA_EXT_MAP(name, bit) \ > > Where is this macro used ? It will be used in the future where individual extension support will use it. Here is an example from my debug patch https://github.com/atishp04/linux/commit/e9e240c9a854dceb434ceb53bdbe82a657bee5f2 > > > + do { \ > > + if ((ext_end - ext == sizeof(name) - 1) && \ > > + !memcmp(ext, name, sizeof(name) - 1)) { \ > > + this_isa |= (1UL << bit); \ > > You can use set_bit() here when using bitmap. > > > + 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')); > > } > > +#undef SET_ISA_EXT_MAP > > } > > > > /* > > @@ -185,10 +195,21 @@ void __init riscv_fill_hwcap(void) > > else > > elf_hwcap = this_hwcap; > > > > - if (riscv_isa[0]) > > + if (riscv_isa[0]) { > > You can use bitmap_weight() here > > > +#if IS_ENABLED(CONFIG_32BIT) > > + riscv_isa[0] &= this_isa & 0xFFFFFFFF; > > + riscv_isa[1] &= this_isa >> 32; > > +#else > > riscv_isa[0] &= this_isa; > > - else > > +#endif > > + } else { > > +#if IS_ENABLED(CONFIG_32BIT) > > + riscv_isa[0] = this_isa & 0xFFFFFFFF; > > + riscv_isa[1] = this_isa >> 32; > > +#else > > riscv_isa[0] = this_isa; > > +#endif > > + } > > } > > > > /* We don't support systems with F but without D, so mask those out > > -- > > 2.30.2 > > > > Regards, > Anup -- Regards, Atish