Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6487887pxb; Tue, 15 Feb 2022 03:38:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJwWtoUOUYrANATRnmRCUn47xP1qkloRDHrWGIVXTTUWhBsVtPl42e6zhMKLDRXlMQ81BrLR X-Received: by 2002:a17:90a:8006:b0:1b8:c25b:ba8a with SMTP id b6-20020a17090a800600b001b8c25bba8amr3904990pjn.220.1644925117967; Tue, 15 Feb 2022 03:38:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644925117; cv=none; d=google.com; s=arc-20160816; b=V2Gk3hVuzwnpcpJ4p9hMm/1r2chmgyCmPTyxhkBgHaSdgcwa1/o9M4g/RC38XT3vQM rcuasuDeEcoqZMChCMaiyT7Zl3RL/wEJLwqxM5Lc5INQAcvjxFiNdlrCQusiMgB9Madi SDV7XfX3BaqKlFdHKs8e/SJqdwN58qDCzApwr2KeJF6J8p9P90MrN/JpBvyDQf0lvhc+ 7KE6lnw95SYq6mTQPK9oPqUGYPsVuQe1EE7D7JP9dSk6Z8oWV8uwbORYiniqKYWhEK9W jTXvPw7k2j6Nq+8+FxAGx6ztSJrPHEjxTxBFiG4WbslODo3EE7gdwpwF9/osxyL7uFDC 4pKA== 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=PZTGGlFqOOOyiaN6gxsek+e4rLg8IgrL4zDsxITUV58=; b=ozelJWoK+hw2O/SzYay419i8B4xhoKWAiGkywGCL1VPoeGO3vpfrtlTiZbGkg70/zV 4jACwD5B3KIqABs5qnVGia+eqURyniXSdqWSU6ZmL09rDI1oABPRo7CozLt3ZSnrWVbM /u7sFEXpNq04OnsFRTmE2wZLI/BC7A4jH1m6QuF6M2Poqx6vu3LS1TXfmgWtc8A28/t+ QzKUdmRZyY/fioWGObBIYWW/ylUmOsuZjgH8kyMPxHhZS/FKo+SMDj5ujr5VInIjfbW0 DBegBSvX82huPI+9vdZDorvGjznMX9pv5WF9WXQsVvtIc52A7eY1LBeXxiGnJrIrKe7l dS8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=gOICOmC4; 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 h184si2311433pge.208.2022.02.15.03.38.22; Tue, 15 Feb 2022 03:38:37 -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=gOICOmC4; 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 S235569AbiBOJCz (ORCPT + 99 others); Tue, 15 Feb 2022 04:02:55 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:41496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235544AbiBOJCq (ORCPT ); Tue, 15 Feb 2022 04:02:46 -0500 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 714E7B54D1 for ; Tue, 15 Feb 2022 01:02:37 -0800 (PST) Received: by mail-qv1-xf36.google.com with SMTP id a19so17089392qvm.4 for ; Tue, 15 Feb 2022 01:02:37 -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=PZTGGlFqOOOyiaN6gxsek+e4rLg8IgrL4zDsxITUV58=; b=gOICOmC4IxU3X4MSsiyEWM8HxOs/j/5mUyNV4SqSm8mbgryc6hcSAyRYKiMAKb21Cw CsnNzdrkCsv6rcH/9wILxHZWjwEGCaojBEUp67oc0qGRCrBgdUODQlQ5YjZ0gna9zMWA 6FfOeIaDQH1mY7dRYm9KK0qBYX9tTq0tVr/UVAWPQMQZaOVjtjcVnTO3blVbEcRMI9iY Jakd730gszKr8ibDUuEGKyA0BfHwN4wGL36ZpFRgQvrotS0TQuTUBjuyPerOD0Rnl6Aq duWdRplQ8y7EokINuJqpCrO9+RY2eyqxJ287GvW+WylZcV4o/P3bij/VAXexWlkJ2oGY aC8w== 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=PZTGGlFqOOOyiaN6gxsek+e4rLg8IgrL4zDsxITUV58=; b=K5E64jzXrrnM8ONILhjJNz8PDn9fo7Ppq2a66Qvt7Ta0bvqeL/J9nqp1pZ7K2LlPoq BBm1z0vJkEJO5jKw2L1x5BNKeOvkl4u3aKrTBsDxRXlK/UEE76PGqd9Jcox32EPHMyuV 6WW+EAzEFFFX0BVwELGlmY+hvHNU0hpqNpNzTfmV4OIpyQ7eaIZ/kh0Ge5cU8wn/F2XG 4Ink8tyCwRzwLj88Jz7kc62rHDpzWaFwD7bb+Ycbwj2oXf1oz8BDBlgojH5FlVnRx9EA +EF+fHT6GiPxERytgUVVY485lCPT/S5OCowtlBJJP/qSbEVMsFMc0ik9UY6s/nHwjFqM dR2A== X-Gm-Message-State: AOAM532hyJ+9BzsV/2F2HxTFqO2ac939G2xr8NrWH1jnxZWXpEPWQNZp tDvj7Qm6RyWcCnLw659dnjT6TEO+ib8sGRqn X-Received: by 2002:ad4:5941:: with SMTP id eo1mr1976230qvb.50.1644915756363; Tue, 15 Feb 2022 01:02:36 -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 w4sm17711158qko.123.2022.02.15.01.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 01:02:35 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Tsukasa OI , Atish Patra , Heiko Stuebner , 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 , Rob Herring Subject: [PATCH v3 3/6] RISC-V: Extract multi-letter extension names from "riscv, isa" Date: Tue, 15 Feb 2022 01:02:08 -0800 Message-Id: <20220215090211.911366-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220215090211.911366-1-atishp@rivosinc.com> References: <20220215090211.911366-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. Signed-off-by: Tsukasa OI [Improved commit text and comments] Signed-off-by: Atish Patra Tested-by: Heiko Stuebner --- arch/riscv/kernel/cpufeature.c | 38 ++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 9d5448542226..cd9eb34f8d11 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -119,9 +119,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; - /* ... but must be ignored. */ + /* 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))) { @@ -131,6 +150,7 @@ void __init riscv_fill_hwcap(void) /* Find next extension */ if (!isdigit(*isa)) break; + /* Skip the minor version */ while (isdigit(*++isa)) ; if (*isa != 'p') @@ -139,20 +159,20 @@ void __init riscv_fill_hwcap(void) --isa; break; } + /* Skip the major version */ while (isdigit(*++isa)) ; break; } 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