From patchwork Thu Feb 10 21:40:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12742444 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98570C433EF for ; Thu, 10 Feb 2022 21:40:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Rn6RIkmK2qYw2aOA/NV4r2dQxhnLt40xOlwfj+p0KXw=; b=ez2rHBCePm5V6a WOT29OByriweZJwmqH9bdMkxhV0ymUWjbzlAq75elj7csxmLGJq2rKANoANNsT9qb8+gaMTu29odp SFYhLo3Qf5EOOuwM4bbJTjWDEiwRhGkjbwsNpdWzTNiZInc0xAifpUZWjnbZaxFQwtIj1LJEQU5IK QSss+ukIvTbRiKTVpkgPcSMD0YVqRtY9YaIweHDPGB6RTioAylkWSTKcLWATtn7gIkqxdMo3wW7Bi xYUvMsID3SthkatTs/B/ZfsBnkuYGHTUIP/0h7/un+Yr0hnLvEvqYRWFSw/5H8CZcihyg8AwVp/ux 49Pgw3nmUcj5DJUSaoAQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHB5-004xC7-4W; Thu, 10 Feb 2022 21:40:35 +0000 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHB1-004xAb-JO for linux-riscv@lists.infradead.org; Thu, 10 Feb 2022 21:40:32 +0000 Received: by mail-oo1-xc33.google.com with SMTP id u25-20020a4ad0d9000000b002e8d4370689so8008896oor.12 for ; Thu, 10 Feb 2022 13:40:30 -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=GFjBD5pXW1oDYaZhB6JNhzufwg/iO3HkPCeezpJonjE=; b=iksg0xdHxV1KXnXClS6AIq8Ytp1aDbko+dvCH7ZzHG71K23Qmnr1+R0baz0UQxMCs2 YQTWvhzGus502Nd4u11IWiGPHUnIgTfbja0rgGiY7Kn74mZ6HmbGXID4MbaE24nQL4qG danGWG+Lpn6iR2Jc9eq5JDuebElwhYT73dr8r8FB9XinMxsfVaO3PXz71hGqOG7ihwdc 5UygxaTyz5DPQN7mVmw2tyAYRh8Y7UDZtPf/IHUoybfdjnnqxwAlhyxDgVDi0cyjqU/Q jTIeJlVIVuFVs7tIb8dMpkOctU9yNl7saXOCdqPq2OGfMDZ3RmrezmG+996Xw9JtDMN+ VMUw== 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=GFjBD5pXW1oDYaZhB6JNhzufwg/iO3HkPCeezpJonjE=; b=SAXjSXBOgeubp4QG5GOLxL0pbVxmAa1I9VJj8sv7YBkDS5tqvE3tTNK7vH7NpjTVlR Qv/WLKn82v3njIOftNpURO2vQbZLsTZVPGr1Dm9yG+5U1jqxUGDpSbH6+xnKwVsu8av9 e9LT8QjhUHXj05kJXUVOKzdtClneiN/SVN957e+3FMf0/IC1GxD5xh14KKjWLpFCWbe1 scNYNU3KIGdzNySI5QEpvPF/0Hzxm4lRZ8ogzox90ErJdo6lEnMI2ECn7YMA0STPRmYf rrS3OckvxXRArabuplJkNJDZ5/6rKwIos07zMkY8v9Vw7HFpWJWuUtUqYOo4LArGwlcG 0PXw== X-Gm-Message-State: AOAM532L83N4C9W9KDIpu38x6XDAG2eSOXizUGqJeKwcu3qJVh7BJw/w pLV1fE8k2kPYHkrZgUiFgjrDWw== X-Google-Smtp-Source: ABdhPJxIOW/t2XpzltCUJWHCX7cMfGm3IFWRnAKi5lDaNjDq9qMokJgcb7uSVeoQZAYVBUNcPYb07A== X-Received: by 2002:a05:6870:3816:: with SMTP id y22mr1449908oal.210.1644529230378; Thu, 10 Feb 2022 13:40:30 -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 u5sm8700000ooo.46.2022.02.10.13.40.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 13:40:29 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Tsukasa OI , 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 , Rob Herring Subject: [PATCH v2 1/6] RISC-V: Correctly print supported extensions Date: Thu, 10 Feb 2022 13:40:13 -0800 Message-Id: <20220210214018.55739-2-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210214018.55739-1-atishp@rivosinc.com> References: <20220210214018.55739-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220210_134031_662124_870D66A8 X-CRM114-Status: GOOD ( 13.19 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Tsukasa OI This commit replaces BITS_PER_LONG with number of alphabet letters. Current ISA pretty-printing code expects extension 'a' (bit 0) through 'z' (bit 25). Although bit 26 and higher is not currently used (thus never cause an issue in practice), it will be an annoying problem if we start to use those in the future. This commit disables printing high bits for now. Signed-off-by: Tsukasa OI Signed-off-by: Atish Patra --- arch/riscv/kernel/cpufeature.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index d959d207a40d..dd3d57eb4eea 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -13,6 +13,8 @@ #include #include +#define NUM_ALPHA_EXTS ('z' - 'a' + 1) + unsigned long elf_hwcap __read_mostly; /* Host ISA bitmap */ @@ -63,7 +65,7 @@ void __init riscv_fill_hwcap(void) { struct device_node *node; const char *isa; - char print_str[BITS_PER_LONG + 1]; + char print_str[NUM_ALPHA_EXTS + 1]; size_t i, j, isa_len; static unsigned long isa2hwcap[256] = {0}; @@ -133,13 +135,13 @@ void __init riscv_fill_hwcap(void) } memset(print_str, 0, sizeof(print_str)); - for (i = 0, j = 0; i < BITS_PER_LONG; i++) + 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); memset(print_str, 0, sizeof(print_str)); - for (i = 0, j = 0; i < BITS_PER_LONG; i++) + for (i = 0, j = 0; i < NUM_ALPHA_EXTS; i++) if (elf_hwcap & BIT_MASK(i)) print_str[j++] = (char)('a' + i); pr_info("riscv: ELF capabilities %s\n", print_str); From patchwork Thu Feb 10 21:40:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12742446 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B09B7C433EF for ; Thu, 10 Feb 2022 21:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=heT0UZnMghZMago1fcR+5KMHHPbXGVtdTWx6ybBgBdc=; b=oVLvyrOaPNwejw 96HdswOSbzvOWY+wUCOHW2raZ/Je22PYKSrmW7ySqCnC4PN4z9PIUsoHzFkxFTEWngFgRsriINluP +dAkCvqfSXVZoapfzSH66W44dEfjMJQfF51ksfJOGrUeqUBmX3dZO5kRIQEb+w1X8+ZMQvqBdVtH3 0EnbcD/PD7OrrD5NG1M/DZVmr8SsmFtxGKnLic+iEIYNs/3eEjEnZBrTecZjfwtZrD77/vAniIIYC GPBhM0/Hf9YfOM2O9ohKkgKNdTrkkofvsOhHHiyXQiTDQBHb0ul5WOL0eKtmM3LD4PGJXmGqAaPNz KwjXrCh3DHKNxuZrXztA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHB9-004xEd-Eu; Thu, 10 Feb 2022 21:40:39 +0000 Received: from mail-oo1-xc35.google.com ([2607:f8b0:4864:20::c35]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHB3-004xB6-6D for linux-riscv@lists.infradead.org; Thu, 10 Feb 2022 21:40:34 +0000 Received: by mail-oo1-xc35.google.com with SMTP id u47-20020a4a9732000000b00316d0257de0so8035935ooi.7 for ; Thu, 10 Feb 2022 13:40:32 -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=XxLurPe5gtmMACmwYrmQ7RV4VZQpgtW/wJpQ92EZaMA=; b=ZGAexjLB1fsWd1qu3I8dybz0nQgpssACPs0RnY+Wbrn6/mWSSoTmwXtMt9tNeO8Fkc 0I+n/5SG7WgyBJUEanBaXBjICX1pVeCelvfL/q4Xt/QFRo37bcM9/PxgLviQdD4zbMFl 5h58IG8lVAZ1J6bPIwLAp9BJ1/w8D8iX9uPpIWgrmAisAvF8kDTVY/Xx6EKmp+kqXapJ fs2it4qhJDundsIeMW62C6Djp0MgjOappTSv95/++s+Vlh1846suJzz2o+PBfhgkUTN7 iO9VjOWP46FjzScJjuh2v27wQaujMWU43ViE7bryqlB+xX/DBpouqO0D986eCoGCFBrP 0MWg== 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=XxLurPe5gtmMACmwYrmQ7RV4VZQpgtW/wJpQ92EZaMA=; b=cLItPGX/aPBNLBoL3LEdSwmpkZN8M0JimsO1Ry2CIgkbMWwphwJ+9AhjOQPPCyt9WG 1cL2j/jo/6OerD4d41c/R2HFZmJTskK5Lsk1uxFdH80JXH0NNd+uS+aTdklp2GT85hKb AfkUQc42TVt6PNMpSSWfmjNviuBTmHLS+Jc9DdZLUTxXjY088PonHSH+cAaKJ78z0SxB RvVFeYtaS+3XK2S4ePzyynCmdtXQz4uwNHSO/PNcldGV4uFfQGpEvhe6YKCMY/EQcgrz VuROVjq30/4S1Wnuj8ClLfWRrlri44P51ze4E5ZCj5GvMccwlvb9AqSL7IJ1X4GT+0S+ cOeQ== X-Gm-Message-State: AOAM532UPP6WYq/mHn+Qb8v1JGmVDXbWgopw5NbJaR0t+YZd/lpFF5+y Zxo1SkD/20XNahWmvB1Om/D3Wg== X-Google-Smtp-Source: ABdhPJwAVQp1nDJtdS+/A4GMweHMJUn2o2jysgwreocFk+ixOF7CGDbCRGXOrigMVd948zf4+Dd27g== X-Received: by 2002:a05:6870:5a8c:: with SMTP id dt12mr1460469oab.327.1644529232021; Thu, 10 Feb 2022 13:40:32 -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 u5sm8700000ooo.46.2022.02.10.13.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 13:40:31 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Tsukasa OI , 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 , Rob Herring Subject: [PATCH v2 2/6] RISC-V: Minimal parser for "riscv, isa" strings Date: Thu, 10 Feb 2022 13:40:14 -0800 Message-Id: <20220210214018.55739-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210214018.55739-1-atishp@rivosinc.com> References: <20220210214018.55739-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220210_134033_257176_BC2EB6D0 X-CRM114-Status: GOOD ( 17.81 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Tsukasa OI Current hart ISA ("riscv,isa") parser don't correctly parse: 1. Multi-letter extensions 2. Version numbers All ISA extensions ratified recently has multi-letter extensions (except 'H'). The current "riscv,isa" parser that is easily confused by multi-letter extensions and "p" in version numbers can be a huge problem for adding new extensions through the device tree. Leaving it would create incompatible hacks and would make "riscv,isa" value unreliable. This commit implements minimal parser for "riscv,isa" strings. With this, we can safely ignore multi-letter extensions and version numbers. Signed-off-by: Tsukasa OI [Improved commit text and fixed a bug around 's' in base extension] Signed-off-by: Atish Patra --- arch/riscv/kernel/cpufeature.c | 67 ++++++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 11 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index dd3d57eb4eea..e19ae4391a9b 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -66,7 +67,7 @@ void __init riscv_fill_hwcap(void) struct device_node *node; const char *isa; char print_str[NUM_ALPHA_EXTS + 1]; - size_t i, j, isa_len; + int i, j; static unsigned long isa2hwcap[256] = {0}; isa2hwcap['i'] = isa2hwcap['I'] = COMPAT_HWCAP_ISA_I; @@ -92,23 +93,67 @@ void __init riscv_fill_hwcap(void) continue; } - i = 0; - isa_len = strlen(isa); #if IS_ENABLED(CONFIG_32BIT) if (!strncmp(isa, "rv32", 4)) - i += 4; + isa += 4; #elif IS_ENABLED(CONFIG_64BIT) if (!strncmp(isa, "rv64", 4)) - i += 4; + isa += 4; #endif - for (; i < isa_len; ++i) { - this_hwcap |= isa2hwcap[(unsigned char)(isa[i])]; + for (; *isa; ++isa) { + const char *ext = isa++; + bool ext_long, ext_err = false; + + switch (*ext) { + case 's': + case 'x': + case 'z': + /** + * 's' is a special case because: + * It can be present in base extension for supervisor + * Multi-letter extensions can start with 's' as well for + * Supervisor extensions (i.e. sstc, sscofpmf, svinval) + */ + if (*ext == 's' && ext[-1] != '_') + break; + ext_long = true; + /* Multi-letter extension must be delimited */ + for (; *isa && *isa != '_'; ++isa) + if (!islower(*isa) && !isdigit(*isa)) + ext_err = true; + /* ... but must be ignored. */ + break; + default: + ext_long = false; + if (!islower(*ext)) { + ext_err = true; + break; + } + /* Find next extension */ + if (!isdigit(*isa)) + break; + while (isdigit(*++isa)) + ; + if (*isa != 'p') + break; + if (!isdigit(*++isa)) { + --isa; + break; + } + while (isdigit(*++isa)) + ; + break; + } + if (*isa != '_') + --isa; /* - * TODO: X, Y and Z extension parsing for Host ISA - * bitmap will be added in-future. + * TODO: Full version-aware handling including + * multi-letter extensions will be added in-future. */ - if ('a' <= isa[i] && isa[i] < 'x') - this_isa |= (1UL << (isa[i] - 'a')); + if (ext_err || ext_long) + continue; + this_hwcap |= isa2hwcap[(unsigned char)(*ext)]; + this_isa |= (1UL << (*ext - 'a')); } /* From patchwork Thu Feb 10 21:40:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12742447 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8AF74C433EF for ; Thu, 10 Feb 2022 21:40:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xlKCTLx2G1G97WjEiS+s4zNwYdwtJB+41CSdfsSOjTY=; b=EjT8FooTsrD8sC u+GttO42Vu6N3R0hOai4b/s3cwfmrzwojPz4yOBbsXPGmFR9iH7vR+4ZgCbKQTrBa9HlIJUytwAGI 7rCLrbtBrJUIeYoQqLlUkUYm3Fgn7SKy6ns8PcttCYjjL3h13SsFqz+YOm+HCEtaH2vgOuYaw/j2d l1eR61udfYK1xFuHtNZmIR3u2sFFVaBFWWk5cYddU0WMlU0yWlRxYVFZdO058gOz3y6tdbkQ9DA5U OwIpRwr9dvQ3rBg5t4kU9OjIoq3JPi1DxYSwLsYiUb7eujIjOk0Ks3AYN7Y8Zacemq60qsjfTHAog wX4t3xjaflDc66tr/bRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHBB-004xFr-Om; Thu, 10 Feb 2022 21:40:41 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHB4-004xBj-O5 for linux-riscv@lists.infradead.org; Thu, 10 Feb 2022 21:40:36 +0000 Received: by mail-oi1-x233.google.com with SMTP id x193so7554448oix.0 for ; Thu, 10 Feb 2022 13:40:34 -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=Gfak+qx3drveGV1Pvkzt57Jl+W0jEgrAmoVtloDMaBw=; b=b5WIG4HsEF5Iod1jlBRBnYuxQFaXxoMA8iP1rJdZ9dXaGNSGjPXSPmZnGU7z+N98i3 PFUIm+xNgTyD24P1KmltetZbCHaWJt9LqJEf5KV+Rq949EsJphUQp5Q+jf2tZt7Qy7c2 Zt9J61HUTUscpV0smpFM2mhfbNXsZxcRZ828cU4AB7GvTUvUHmVhPml1mkHo4ptzYRRB o2+8U3fQcZMV6Mjj4RR8QjhftLH50cjfmPJgOWDqPVNlM1Ri2IQ6mTlaEx+U0p0RgBOn UlGy3tsfSb1cSMykpj9Vgdw6vDPziX7U52avE88Xpuwl3zSPHr9RwkywA8TqDnBQxfFl PYcQ== 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=Gfak+qx3drveGV1Pvkzt57Jl+W0jEgrAmoVtloDMaBw=; b=t2NfHSzhybftzw09z8WKK4bgnISu2pq+4xA0hRhhIvtzvgZrLuniNyfdyMCL/mJeyM HVct8sOdVjVuFTHc7JxX64OWP17pvqnlyJFYLVpLYm4OMMOj5fXdaFnh+X9DtOOPUKCv QJq0IVCkaJTDF7GPG/KBI3pmPlW2oFFq2zIVWFwge6bv5Uayv8rw5o2TWJxLjjuBeAFP ZLiK3Ph/+Kozn4tKjLR3yz/+Xx2D0SzH1V4F4ISsiduur6UwVJ0Ig419ct60Sx8cCFyd fijAvTwu2Fb2VHtIajwjwmjiLS0dqViESvrDkq9+iqzTgCBMoAN1KB6UCrh0AqeVP7X+ x5tQ== X-Gm-Message-State: AOAM531nzKcCtsIfsQ8UQkAhx4jLZtNJgcuI5/U0LooptOnc9Yrc1j/E Th/cGHRFoTLtja8J46iSTt3C5iWjDKUy3QHZ X-Google-Smtp-Source: ABdhPJykAnYvG8sqBibAI7XjH1k9J0mAOKTMUjlZygKx4hyhEIURQ1Wi20CpxOC5ed/s+MjwLZlz4g== X-Received: by 2002:a05:6808:229f:: with SMTP id bo31mr1819283oib.107.1644529233614; Thu, 10 Feb 2022 13:40:33 -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 u5sm8700000ooo.46.2022.02.10.13.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 13:40:33 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Tsukasa OI , 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 , Rob Herring Subject: [PATCH v2 3/6] RISC-V: Extract multi-letter extension names from "riscv, isa" Date: Thu, 10 Feb 2022 13:40:15 -0800 Message-Id: <20220210214018.55739-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210214018.55739-1-atishp@rivosinc.com> References: <20220210214018.55739-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220210_134034_816610_42630352 X-CRM114-Status: GOOD ( 12.64 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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 --- arch/riscv/kernel/cpufeature.c | 41 +++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index e19ae4391a9b..e9e3b0693d16 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -102,6 +102,7 @@ void __init riscv_fill_hwcap(void) #endif for (; *isa; ++isa) { const char *ext = isa++; + const char *ext_end = isa; bool ext_long, ext_err = false; switch (*ext) { @@ -119,19 +120,39 @@ 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: ext_long = false; - if (!islower(*ext)) { + if (unlikely(!islower(*ext))) { ext_err = true; break; } /* Find next extension */ if (!isdigit(*isa)) break; + /* Skip the minor version */ while (isdigit(*++isa)) ; if (*isa != 'p') @@ -140,20 +161,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')); + } } /* From patchwork Thu Feb 10 21:40:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12742448 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 75812C4332F for ; Thu, 10 Feb 2022 21:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YCNOFzOo3wUpMHiH8SOqPFy8N6ucsAllmdddDByoU1c=; b=NkohlGEJtkQSXB ngfz570gyK8vy/lTquPxXWkplOfhjYrIDAbY9OeeJm19L6hut3ZusbtoIPHbtrrIt5TK46k0MvT0I 01Qq4/vywcuBaz/0NHOpqrvB8HQXb+qOOE7T5GkxML0zmjMBA8V5dBp0baqLE78GUX2yAux635i/t ec1nQrMuM1VNJBGqhNfadm1osPxLLahMlYs6bYUhiLnKN+9c0XR2H6yxDD7fmuHpYzpzPrlW4qaKS jzPkHYt09FSYZOBihhB7yQS/B1Pmg63OtjXve41NcwYZ3cpn5dPgAnwKH1x3JWyiJ0E/6qLqKqf5U pbMNj2QqrUg4sMJECrsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHBE-004xHl-82; Thu, 10 Feb 2022 21:40:44 +0000 Received: from mail-oo1-xc33.google.com ([2607:f8b0:4864:20::c33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHB5-004xCX-OX for linux-riscv@lists.infradead.org; Thu, 10 Feb 2022 21:40:38 +0000 Received: by mail-oo1-xc33.google.com with SMTP id 189-20020a4a03c6000000b003179d7b30d8so8046068ooi.2 for ; Thu, 10 Feb 2022 13:40:35 -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=9HqpIlANdkOQKOXjwBjs8cYmBoShBh+rol5NQg2UHcQ=; b=sEIOgtn1hTncoRYD7rw8soECdhc+qTSuHFirYdgpmhgl11ZRxUmCTJqQVLp3uySO+W cWU9hHTcbrqdsckB4wBTllc/wKv00ME8JP7Kd53Mo4WiUozmQaHHnQ9cj3vRPUTSn/fF IlIOXfazff84lCs44cUF7H1kpTHRjy38zyayW8YKBIJYqZx9DwY2WvZTAi4uumZfvpcH z97M8iueKtbeA9mK57qbseZ9uMRuK3PMSfFtn/ytwtDFyxTVldrjOEscwCdZGImYqZGH s8YuADiDbhjizT4sb6v8MYxBmaDok5yNbwKiPCssHErMqICrXYMohrA7/oWN7P3RDraK g0Og== 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=9HqpIlANdkOQKOXjwBjs8cYmBoShBh+rol5NQg2UHcQ=; b=D2YznpyUzFCj4aU6cYcVt2uYAOPeappxjCUQO3l9/5KGLEHuNckp1AS7sBqcs5bVEE 9bAx+hRNhNBIi08SivVIqaYY9uOZseowPAiLKuVCe7DPRxnxDNmY7TwEVGFqkCAph94V Hw8D49/uZDRkwacOKcn2RvEx68T7IASi/0PTIlZ1SK7GXFj+26zhFboURw4TjdKg5UjQ Wi7muPp4dvRzmiJ6P9HASCZJkIhPSd9mhcst5z6WDio+M050TvIPzCGd9PAJBU4l/Skg ByYuezo/MKQa4sIqkajDrsHG+IXSv8+xKt3wVVbBAUCnpTad2EMb+6AeHP/rEpnsV7Uh bOQA== X-Gm-Message-State: AOAM530j1CnjG7b9Icq+rru9M9kT/gLwYtTy6kqc7EtFp1aFbwtJbxRW ubWs40hBeo6U8FcwEOxoI2oMwA== X-Google-Smtp-Source: ABdhPJwswvuwH8xTFr0UU7nRSK+wVt/HmmuoJ/He9mWLY9YbklssjC7cpvnAPAdYQwCb8VUFbiowSg== X-Received: by 2002:a05:6870:e495:: with SMTP id v21mr1423427oag.39.1644529235166; Thu, 10 Feb 2022 13:40:35 -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 u5sm8700000ooo.46.2022.02.10.13.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 13:40:34 -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 , Rob Herring Subject: [PATCH v2 4/6] RISC-V: Implement multi-letter ISA extension probing framework Date: Thu, 10 Feb 2022 13:40:16 -0800 Message-Id: <20220210214018.55739-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210214018.55739-1-atishp@rivosinc.com> References: <20220210214018.55739-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220210_134035_824606_5E1E1AC2 X-CRM114-Status: GOOD ( 15.00 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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 Tested-by: Heiko Stuebner --- 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 e9e3b0693d16..469b9739faf7 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; if (riscv_of_processor_hartid(node) < 0) continue; @@ -169,12 +169,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)) { \ + this_isa |= (1UL << bit); \ + 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 } /* @@ -187,10 +197,21 @@ void __init riscv_fill_hwcap(void) else elf_hwcap = this_hwcap; - if (riscv_isa[0]) + if (riscv_isa[0]) { +#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 From patchwork Thu Feb 10 21:40:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12742449 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 458EEC433F5 for ; Thu, 10 Feb 2022 21:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TnnQ6vZHe/glcJU5fS0B4b7vt3YxdA76spRYnL+rffI=; b=hJctxrpXEpRH7X SuLQBjEznb3lsHokeF4P1hDCfzuODRUg3ut/kA6KveSyWaGH0YO9XVN4lZ7Mw+wbGPgfPt7w0SNA+ nGdQiE/N428UOwxcOIX00/bWULidD7BtBOFi/Iy5sNLdEiCnO/F4kGuh7bkgmBnonIIUr7XvT27Lz KYgll0nneEJzq3uY9r8IAkUegN806JgNiHAdpmvn6jsRURLBK8O4PUbi7C0/J4W2iMvD2UI4jca6i RJ1b0FNrVzi9TjXIjZyiuhtQ9PjDlBHdbqEgZ9fS40pjC5Ht+fT5zRXjifWzRSzo1+jbMbZAdVmqg GEUeWvcJO1cZ7my2L0dg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHBG-004xJH-G5; Thu, 10 Feb 2022 21:40:46 +0000 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHB7-004xDJ-8l for linux-riscv@lists.infradead.org; Thu, 10 Feb 2022 21:40:38 +0000 Received: by mail-oi1-x233.google.com with SMTP id s185so7492935oie.3 for ; Thu, 10 Feb 2022 13:40: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=3nB7qzXaFNatnaTZQJRAInnjQf9KiqCTDZAFaYuusV0=; b=L+ZGFYNRoNLbHVhM3KhtWzMWcXEDYyJA7aw1jmcFUNm9LwjalIvnug5gAOBoaVsGAi XAfgYWak1dxQzZ5ghazPUUea8fGTUL4XYyIyS3b6NW+CmQgYLVmzlmTGPyvdu36ntJE9 p/WWwPx2fjkcKd0nUagR9y6sxwOG6zjfJTQ/wWjLi9u+NSP/xV0hSdCGSkoc8CSEy4Zh Xfmpchix/fMksPHav7pOiVse8m4TiWBP74rJVn9fBN60F/vQOUJa2ip5dMXv/LouxZAc odHYF6dZ+iuK1KlWP32f8JPsVtkzl9VjkswCDQuIxLTMaPXm3Tnh3rK4m5SBJ5wSZl2Y E93g== 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=3nB7qzXaFNatnaTZQJRAInnjQf9KiqCTDZAFaYuusV0=; b=I9pWjUw3tDbOp59lVEmUNSD7/dniRnL78OUjT0GtfmOthjFcNdZXv2tB2RxNZDAiTv Gci0DEdQr+Flm1+0tX3aLKAAE9dTZVeZvlbP1dpouIst6VubtGlbN5eF41rKrfWfbUSw HkIPvgPXO96/g1+o+y09VdWDw2mRCR1Yi32u2X+zkxHZWUg/psCREJDpC6j8KsVEz7Ks q5MQAbuBxqaV8ZFXYG9PNQ8vpbGdsBzUBRsVcWiT270R7diZqLhoeJtGCJRaDW3EjH1o EbEOabvdNFBNweqYjFKhVOwJgAKcjUk5c74w8DvwPOEGjkecxP8odDAMlV4rNcSyzbFR si8g== X-Gm-Message-State: AOAM531C6iVHbZ9VNte00YezmmjlmzRh/2petZqjCWBeshOENoQrW9P7 gvsI4dYBGebka33hLnTO6HrpQQ== X-Google-Smtp-Source: ABdhPJxnj59RepTjd/uznzgrpDdO30O9r7af3cgqYy9BVCSUocaHEleDWBfL7GJ76jB38zMSSwzmAQ== X-Received: by 2002:a05:6808:11ca:: with SMTP id p10mr1942733oiv.74.1644529236740; Thu, 10 Feb 2022 13:40: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 u5sm8700000ooo.46.2022.02.10.13.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 13:40:36 -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 , Rob Herring Subject: [PATCH v2 5/6] RISC-V: Do no continue isa string parsing without correct XLEN Date: Thu, 10 Feb 2022 13:40:17 -0800 Message-Id: <20220210214018.55739-6-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210214018.55739-1-atishp@rivosinc.com> References: <20220210214018.55739-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220210_134037_336354_2B2E9B7F X-CRM114-Status: GOOD ( 10.53 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The isa string should begin with either rv64 or rv32. Otherwise, it is an incorrect isa string. Currently, the string parsing continues even if it doesnot begin with current XLEN. Fix this by checking if it found "rv64" or "rv32" in the beginning. Signed-off-by: Atish Patra Tested-by: Heiko Stuebner --- arch/riscv/kernel/cpufeature.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 469b9739faf7..cca579bae8a0 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -84,6 +84,7 @@ void __init riscv_fill_hwcap(void) for_each_of_cpu_node(node) { unsigned long this_hwcap = 0; uint64_t this_isa = 0; + char *temp; if (riscv_of_processor_hartid(node) < 0) continue; @@ -93,6 +94,7 @@ void __init riscv_fill_hwcap(void) continue; } + temp = (char *)isa; #if IS_ENABLED(CONFIG_32BIT) if (!strncmp(isa, "rv32", 4)) isa += 4; @@ -100,6 +102,9 @@ void __init riscv_fill_hwcap(void) if (!strncmp(isa, "rv64", 4)) isa += 4; #endif + /* The riscv,isa DT property must start with rv64 or rv32 */ + if (temp == isa) + continue; for (; *isa; ++isa) { const char *ext = isa++; const char *ext_end = isa; From patchwork Thu Feb 10 21:40:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 12742450 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3DEF1C433F5 for ; Thu, 10 Feb 2022 21:40:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9aBdr2XXNDuYqJWcN9Mhesm0TNzK4coVpZioBmBLIaM=; b=QggRjiJ77xxEs8 ZLPiQ4efBMkFIcxBB4bxHa84T3wDuY68OuGoAWUeLZL6AQlE6r4MJLZZhdChS26KAZKZ3qhfUZp9s QJYxeXlsZk0a3Nsux6iONP9Ww6BbLwj2FTddjNczWocI6WpzBQjxe5Cz2fDMaJ6G9wXG18a0SVvv0 IGtKvEg9RxAJOSgG50LbaF09MimjPmvS0vOYhb70msxlqSsp8ZhBLWULtRSXgwrNLrEBT6dxnWObq 8fnzN8bpMmVX5YGZTcc+TVe/5O7ExZJbb1haTcGw3l2WW2xTCVsLzc0l6xGRV0baXAYF5xnlj8IbH 9puQSnBVltjYnqkhH/7w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHBJ-004xLl-1f; Thu, 10 Feb 2022 21:40:49 +0000 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nIHB9-004xDx-Bn for linux-riscv@lists.infradead.org; Thu, 10 Feb 2022 21:40:40 +0000 Received: by mail-oo1-xc36.google.com with SMTP id u47-20020a4a9732000000b00316d0257de0so8036227ooi.7 for ; Thu, 10 Feb 2022 13:40:38 -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=saY5DtvepsvwegCELkFkB7RgpB9RohGc6lIP30RliiM=; b=46zfGr3Kc5ND2ogjveHMMDJajmm20RjiQ5jLchAHKSOeQKPxbVdIY+oOIVYm/iux6G ZW7C8F9MHh0yrmBybRjiWtF0Xu0TFxrjlGVldYLEb13JSmAp10UwNlCF/RQs3NzeLRRw 2fy36iHMRabUOaLns1XyogS6wb2Zks+GqSdmRph/bI6MJPxl0saHoEkNH7YyzZQ4fId2 +pOuGvF2Q4fzB5TYRyebqrzn4PKDTXp8IVhCjORaAesIgT4iGxFQTo0yXwp2hn40ig2y 16NA6FAr6bH+/4dUQKItEPAZiRomvHhNA/crV+uSdzIGkPshdjxQ0yAaA8xLgSiwIjNe ZXOw== 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=saY5DtvepsvwegCELkFkB7RgpB9RohGc6lIP30RliiM=; b=AqIbqsPAoSBFqP707i1Fd8r8Mwn++sggoXKqmQqs2tvVD0KIE2UA7EZJ8+/PYhXmvD pjIu31jtDHQtt3urqqiU0ia0m/ab8y2Iz5le+GCGPpneUv4Lru8cCPrljC1tcc7bLAW5 1n4rKIriy/uscfGTRaVvc8BYDcUYR2cSRHdOuB5Sut63g1xzPD/G6G9ru9TtUIHQSxlj WQ3xLUGulIjyNTLfgFyufAmihwTPgDCPDswA79KDjkX8QHhwXU3qDtUrNo29RpIYYgu2 rOR8+lkQ/NrO47ivtHKgxViFw2T6uhUYePsAgEsp8W1r2TiGfV1bkcpgjXxMOFiAntAM gFUQ== X-Gm-Message-State: AOAM533IBX2+FByTdi74vHBfyp8mSpmoMDkjdY8wv7y+ruo0WJMUI9t0 6yMA8378l4fxddDbIujw4f550g== X-Google-Smtp-Source: ABdhPJwjL2U7/u0jBP7WaACxI4KC0/AXyKMGE0aYyO5DPcLm++C2In2k7oqNhs9hXD+RC9AH2QAtbA== X-Received: by 2002:a05:6870:e3c6:: with SMTP id y6mr1357918oad.200.1644529238281; Thu, 10 Feb 2022 13:40:38 -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 u5sm8700000ooo.46.2022.02.10.13.40.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Feb 2022 13:40:37 -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 , Rob Herring Subject: [PATCH v2 6/6] RISC-V: Improve /proc/cpuinfo output for ISA extensions Date: Thu, 10 Feb 2022 13:40:18 -0800 Message-Id: <20220210214018.55739-7-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210214018.55739-1-atishp@rivosinc.com> References: <20220210214018.55739-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220210_134039_450072_800F8098 X-CRM114-Status: GOOD ( 17.35 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Currently, the /proc/cpuinfo outputs the entire riscv,isa string which is not ideal when we have multiple ISA extensions present in the ISA string. Some of them may not be enabled in kernel as well. Parse only the enabled ISA extension and print them in a separate row. Signed-off-by: Atish Patra Tested-by: Heiko Stuebner --- arch/riscv/include/asm/hwcap.h | 7 ++++++ arch/riscv/kernel/cpu.c | 44 ++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index 170bd80da520..691fc9c8099b 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -54,6 +54,13 @@ enum riscv_isa_ext_id { RISCV_ISA_EXT_ID_MAX = RISCV_ISA_EXT_MAX, }; +struct riscv_isa_ext_data { + /* Name of the extension displayed to userspace via /proc/cpuinfo */ + char uprop[RISCV_ISA_EXT_NAME_LEN_MAX]; + /* The logical ISA extension ID */ + unsigned int isa_ext_id; +}; + unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap); #define riscv_isa_extension_mask(ext) BIT_MASK(RISCV_ISA_EXT_##ext) diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index ad0a7e9f828b..ced7e5be8641 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -63,12 +64,50 @@ int riscv_of_parent_hartid(struct device_node *node) } #ifdef CONFIG_PROC_FS +#define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \ + { \ + .uprop = #UPROP, \ + .isa_ext_id = EXTID, \ + } + +static struct riscv_isa_ext_data isa_ext_arr[] = { + __RISCV_ISA_EXT_DATA("", RISCV_ISA_EXT_MAX), +}; + +static void print_isa_ext(struct seq_file *f) +{ + struct riscv_isa_ext_data *edata; + int i = 0, arr_sz; + + arr_sz = ARRAY_SIZE(isa_ext_arr) - 1; + + /* No extension support available */ + if (arr_sz <= 0) + return; + + seq_puts(f, "isa-ext\t\t: "); + for (i = 0; i <= arr_sz; i++) { + edata = &isa_ext_arr[i]; + if (!__riscv_isa_extension_available(NULL, edata->isa_ext_id)) + continue; + seq_printf(f, "%s ", edata->uprop); + } + seq_puts(f, "\n"); +} static void print_isa(struct seq_file *f, const char *isa) { - /* Print the entire ISA as it is */ + char *ext_start; + int isa_len = strlen(isa); + int base_isa_len = isa_len; + + ext_start = strnchr(isa, isa_len, '_'); + if (ext_start) + base_isa_len = isa_len - strlen(ext_start); + + /* Print only the base ISA as it is */ seq_puts(f, "isa\t\t: "); - seq_write(f, isa, strlen(isa)); + seq_write(f, isa, base_isa_len); seq_puts(f, "\n"); } @@ -115,6 +154,7 @@ static int c_show(struct seq_file *m, void *v) seq_printf(m, "hart\t\t: %lu\n", cpuid_to_hartid_map(cpu_id)); if (!of_property_read_string(node, "riscv,isa", &isa)) print_isa(m, isa); + print_isa_ext(m); print_mmu(m); if (!of_property_read_string(node, "compatible", &compat) && strcmp(compat, "riscv"))