Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp579889pxb; Tue, 15 Feb 2022 22:45:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJzny0kwkwHaiRYqLpuLyP8YLhvP5fgI288lVm9uefuPQOOWnr8Voj3MC+U7fh3w4OEVI8Cf X-Received: by 2002:a17:90b:1644:b0:1b9:9986:f740 with SMTP id il4-20020a17090b164400b001b99986f740mr172218pjb.36.1644993904940; Tue, 15 Feb 2022 22:45:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644993904; cv=none; d=google.com; s=arc-20160816; b=x9+5v1AC8xbyMXRTGohg51h9MgF+ljOIOFCFpxHJKhWGLmP/FSqpbOUdJshfblpHy7 EGBLTtMYukA3cyxK8AHNCu/ppDAWLAqFF8GqAZpTCwmSTMXVN7j5oXPksVsKBTaV2onS //AE9Wxx26vt+piw2YmWrbxbNrBdSaNlWBng6iDw9aOEBER15XkSVL0sUG3NYT5+Lmq8 kIlHghSXeGiFFpkt5+D3G3NDBC5O0ZhHJ4vSQWK/uSaQhglxESkZuGYJCtDK70zH+oxL 3I7LyiQ3X48vA15aOBjwZvIfM4CL+1e2f0ty8zRHqmgJOt3ssm2m+sOQJaf0Lgty8tMp cwTQ== 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=yheAniF0b6YkThnNE53f6BLG90+fIq+Lpxxu/aXM9PQ=; b=mzKkPKnkQeN/KXlIGl4IcEufQ/K35xZUmJ2C3QNIUVfCrMcY3amH2Oq00VtMuM9X0x lRVv5BZZK+P2vtqCRu+UAgJFrQAKrYAkNzaLxc462FymVgvQwfYUvWcvgIUPClpVkEP0 Smt1GhVyn54FdTCk42ro/Uckv20jVMoxsscGHNvvj5b7zqwzzODKDDHvU0OiB1GTGBi7 W0VxFgvGqzhUlqnXnzQVtgrDRlQ7/wt/RLwyCl5qYJ2DniaZWxaX5WXV698xLhrWSl5J uqNyFRQw/9hka/oy3tf3vTCVq1HiGIy24lRgL9xeaQDrehzCoWWVTT3E3a+5nqhAP0m7 6Ptw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b="GLyey6r/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id mi9si16944514pjb.163.2022.02.15.22.45.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 22:45:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b="GLyey6r/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 34EBB65414; Tue, 15 Feb 2022 22:31:43 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236478AbiBOKYU (ORCPT + 99 others); Tue, 15 Feb 2022 05:24:20 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236453AbiBOKYR (ORCPT ); Tue, 15 Feb 2022 05:24:17 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D610922B3E for ; Tue, 15 Feb 2022 02:24:07 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id v12so31289673wrv.2 for ; Tue, 15 Feb 2022 02:24:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yheAniF0b6YkThnNE53f6BLG90+fIq+Lpxxu/aXM9PQ=; b=GLyey6r/f9CmsAcYOpwFsXlueKIOjQtPpUvxSmFinLSUTMJN8YvMxrJ0D9vat3hSpp kK5iaUHOP8rUI5Pam3ZQv6YoB45CXbM7o6RWzY1cAmYxgbly5hTZx1W1sL11G6cF+GqN PsKBqxxbV9l5oHrBvH1Ykxv9nE/j6p4vrSrFE0oohrT8Df+RSqNrpnKGYd5ibZBGRMWW f7IDjZVin7/usCk36NfA4QGpIsI7jUe3TJ3+AWmlEFybvti3+LeOy2ot4acVWCeqchJe 12ZnWyW6/t6btNNs6rjJglBxkXmHBwfcGybJBBhY36tSg9wLz0xnxuF2Zj4/H370wbO+ tjJg== 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=yheAniF0b6YkThnNE53f6BLG90+fIq+Lpxxu/aXM9PQ=; b=kzhGFmWKonTNkUmVmfYVqnp+QSld9iIw2G7McsapvM29wLxfZ5L9+QDDsIOUANWwR5 xrlYkDDUkDc9O6ft/JxnF7Z0Zg8c9JguUKgzbfhGNcnVdFkeZ/8rK1ic//WUPyOupIIN NP/eFDGm4nCAOJUJvijaZlu5lj3NrCo8fR3b6m4dXluG/NA+9ybihosdCfk8S0QLeW+u TT3HCnIIJc4RfPelr/IAQSfOg5H/0m6NXR2w3AElIpTod38fJjRULtrLvp4QyTXRkb/i CQpty4OBMh3SfKf+KVTbTIdASwvYdFXZq/FIjMmuE+/zpY5DhiykWi1SNAe6El6Bq1vn iFig== X-Gm-Message-State: AOAM533ML9IpgIb8jE2P9pRE+1LaPqUHzzeu2qbFMqyIdKBOQp4OAbbr kJfiBoTKHWAhuo7N5vzRhqx/A9FsU7M2rDdFtxgKcQ== X-Received: by 2002:a5d:4e45:: with SMTP id r5mr2632030wrt.313.1644920646281; Tue, 15 Feb 2022 02:24:06 -0800 (PST) MIME-Version: 1.0 References: <20220215090211.911366-1-atishp@rivosinc.com> <20220215090211.911366-5-atishp@rivosinc.com> In-Reply-To: <20220215090211.911366-5-atishp@rivosinc.com> From: Anup Patel Date: Tue, 15 Feb 2022 15:53:54 +0530 Message-ID: Subject: Re: [PATCH v3 4/6] RISC-V: Implement multi-letter ISA extension probing framework To: Atish Patra Cc: "linux-kernel@vger.kernel.org List" , Albert Ou , Atish Patra , 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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: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 ? > > 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 ? > + 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