Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp127448pxm; Tue, 22 Feb 2022 18:37:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxccVZvcyDrIw5s3+gir5XgR3ODlSSrhlthfeVydXXCjv7t7cEW/RdEnUJefbfID/iBjSMg X-Received: by 2002:a17:90b:1713:b0:1bc:3eca:627c with SMTP id ko19-20020a17090b171300b001bc3eca627cmr7035851pjb.144.1645583831269; Tue, 22 Feb 2022 18:37:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645583831; cv=none; d=google.com; s=arc-20160816; b=VcUBT7sae5MgcN16Cc8aoZQu/WTs1eNfmiJz/xbG+6VGPbPBN8H/0StcGdJnykGdKZ 0qgMSTv45Aj1nk2+Eb89z9Ss0K7i1SZoIbRJcAlo/s/BEpHQFyw764ednzPYbxGF1JDe +z2n+6HtJChzO55uJ5oUYfTwBOdMcGnK19Kh2Vell/NtIg4yR4TYYzgFirXClNo6RfYE +70aIkP7IVJ5ZvlXJrSU2lnrJZ+8xIIWFz25zVFmTZpZQxaIpE1NNmd0wrlkR3m2WzUG ybGOGGIvxMdvngO63FtV/SxNq8TFk5bjSbUFw5P74A+jdNewR8qcbo/V+DfX02iivAoQ 1JfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=c80lDSr4/XrHo4HXuUiUdwW2N5759X0Jr8s3r01G4uw=; b=rwv7rk6ep/2ZremZGku4ZCL3fT49wKDHQYnfE540MNInB8iPx9kYbKVMXSjpglr9bN fXPW61pvxa014HsK5rkIZ0Kommg/Yz41z0WOCggWgjjEx3m0McuYWynrfLol6ZzMp8GO 2JKpxjbCBBrlHJeJ9EAy0oFxelV6Sbw+Fttm2SfMV0Zy3klbta0aDwKwSHSqIAGzNElJ 4Y5j77wTOVNjRLvPAuHo7yg/d8zAlLa42V9oDgEHA1WrNNgB6XbmwsOTcacl78gmsL3k mHY6Ed1NPtWYa2SeGCUy9WlfP6+YnGTUlL46H3Akoi0E9swPNRgAOp8edwRM91hwSeA8 coCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=qi2CLkoT; 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 u14si39121768plh.561.2022.02.22.18.36.55; Tue, 22 Feb 2022 18:37:11 -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=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=qi2CLkoT; 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 S235646AbiBVUtA (ORCPT + 99 others); Tue, 22 Feb 2022 15:49:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235606AbiBVUsy (ORCPT ); Tue, 22 Feb 2022 15:48:54 -0500 Received: from mail-oi1-x22b.google.com (mail-oi1-x22b.google.com [IPv6:2607:f8b0:4864:20::22b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D233AA2F2C for ; Tue, 22 Feb 2022 12:48:28 -0800 (PST) Received: by mail-oi1-x22b.google.com with SMTP id a6so15938848oid.9 for ; Tue, 22 Feb 2022 12:48: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=c80lDSr4/XrHo4HXuUiUdwW2N5759X0Jr8s3r01G4uw=; b=qi2CLkoTpNf+/7KRpxJWRKKedV3ySUp6Hi5CiH/Rl69V/1ZYKrlbplu5LuSaHdhRIr U3qvvNSC3b8wbwX2/jLQsKii0fmBsrukVOjWCg8MHzVUm8SSVTFJXjwemeX/p3d7bn6Q +m87Kf9FB60c/CB+MHLc7aTiHvLqierIr4BTAMkPS7FbbukSEVFc7B/wbjSfrQvOn2Jk E8yxCnUIUCRB+eJ5tkE7gfAvVChYIkBzF1uoQFj7V7qm3IKD0Nr14+iqzwFSYX/sG6p8 N4+OOxN8twd0yzhKVeF35CuuEGVtvYulguhNHU0z+MdnBFRUedC9fBtzQri9+gdN6jNK 01IA== 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=c80lDSr4/XrHo4HXuUiUdwW2N5759X0Jr8s3r01G4uw=; b=3cwrRyKIH/huRtEWLKjHhCMDFDloxA9zFuD2/VFgo6B3Ia/zog7NijOpI0zpLTYUr6 otTDldltn/HaER1MdCGmmygn5T+ELrbp7HIg5cBlmw+loArcJb4vbyo3zQ4mnjrbe1qs WuufYnZ40weyOSjBriAJC+kGkAUJ0KaEYr+NFkpMuQUO8KA6tcNbeIZFD21OIcnY9aXG gG2q5fsKh+pxweW5JW3oygd4uvyTgpWVYbkBOq6XHdlfmoZq2VYkrM09uNzfdup/qODa GC9jnpQLDTQBFx7/aZCV7YJrc0YyXwjf9OHWmtq0iH7XVlJ4iaTnkcdJWr35w1n91PWh vzEQ== X-Gm-Message-State: AOAM530qBH0tIpJF5wQpaFkda+qFcTD6mkuxad/jpivwxkH4n8hZlm3C akk1LJHSyyGG4TILBB7s7DsAfuSZo/xdwA== X-Received: by 2002:a05:6808:2106:b0:2d5:3244:ca43 with SMTP id r6-20020a056808210600b002d53244ca43mr2968470oiw.263.1645562907949; Tue, 22 Feb 2022 12:48: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 o14sm16508197oaq.37.2022.02.22.12.48.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Feb 2022 12:48:27 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Tsukasa OI , Heiko Stuebner , Anup Patel , Atish Patra , Albert Ou , Atish Patra , Damien Le Moal , devicetree@vger.kernel.org, Jisheng Zhang , Krzysztof Kozlowski , linux-riscv@lists.infradead.org, Palmer Dabbelt , Paul Walmsley , Rob Herring Subject: [PATCH v5 3/6] RISC-V: Extract multi-letter extension names from "riscv, isa" Date: Tue, 22 Feb 2022 12:48:08 -0800 Message-Id: <20220222204811.2281949-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220222204811.2281949-1-atishp@rivosinc.com> References: <20220222204811.2281949-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 From: Tsukasa OI Currently, there is no usage for version numbers in extensions as any ratified non base ISA extension will always at v1.0. Extract the extension names in place for future parsing. Tested-by: Heiko Stuebner Reviewed-by: Anup Patel Signed-off-by: Tsukasa OI [Improved commit text and comments] Signed-off-by: Atish Patra --- arch/riscv/kernel/cpufeature.c | 35 ++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 72c5f6ef56b5..b0df7eff47f7 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -124,8 +124,28 @@ void __init riscv_fill_hwcap(void) ext_long = true; /* Multi-letter extension must be delimited */ for (; *isa && *isa != '_'; ++isa) - if (!islower(*isa) && !isdigit(*isa)) + if (unlikely(!islower(*isa) + && !isdigit(*isa))) ext_err = true; + /* Parse backwards */ + ext_end = isa; + if (unlikely(ext_err)) + break; + if (!isdigit(ext_end[-1])) + break; + /* Skip the minor version */ + while (isdigit(*--ext_end)) + ; + if (ext_end[0] != 'p' + || !isdigit(ext_end[-1])) { + /* Advance it to offset the pre-decrement */ + ++ext_end; + break; + } + /* Skip the major version */ + while (isdigit(*--ext_end)) + ; + ++ext_end; break; default: if (unlikely(!islower(*ext))) { @@ -151,14 +171,13 @@ void __init riscv_fill_hwcap(void) } if (*isa != '_') --isa; - /* - * TODO: Full version-aware handling including - * multi-letter extensions will be added in-future. - */ - if (ext_err || ext_long) + + if (unlikely(ext_err)) continue; - this_hwcap |= isa2hwcap[(unsigned char)(*ext)]; - this_isa |= (1UL << (*ext - 'a')); + if (!ext_long) { + this_hwcap |= isa2hwcap[(unsigned char)(*ext)]; + this_isa |= (1UL << (*ext - 'a')); + } } /* -- 2.30.2