From patchwork Wed Feb 16 00:29:06 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: 12747758 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 6E34AC433EF for ; Wed, 16 Feb 2022 00:29:35 +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=lD6tZTu7mHG4STAf9AXLdzM7otdiqd1tqQkiiy7t09o=; b=VGe9GFh7wpzs9O MGv8najCF5mmx13NXklL2De7G+pi+loxUCCWxsR46rIxL0RGRasI6figbnX4FIkXK2/e8HHB4HJkA i7b6InEh6Kqfmoz+V5WYhkY9CNl1HIfiB+a2bg/daNsbE6MfuO6KHWgWjbnxxk72zfJxFnkzqnmIZ EhID7KUDMaEqCWSQK5kBemX0dPgUmn8LvTyR+kb6vPFaxcWGgWEKIQhn2mU/e9y1zt1+7F5QfPlzm SirQfQh2H9X9cgLKoXpCWF4j7DdkpZM+WnxCE9/RjbwYHbyN1ulQVRWzoFH4J3hZN6fPfRMM1iweG Trq0LSoxEvounYFtu5TQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CF-0053xQ-3W; Wed, 16 Feb 2022 00:29:27 +0000 Received: from mail-qv1-xf35.google.com ([2607:f8b0:4864:20::f35]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CA-0053ug-BS for linux-riscv@lists.infradead.org; Wed, 16 Feb 2022 00:29:25 +0000 Received: by mail-qv1-xf35.google.com with SMTP id f19so721511qvb.6 for ; Tue, 15 Feb 2022 16:29:21 -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=iS9w0OaNOwq2lVntX7Egw8nvc58/BIqmU/Sn5pstZMs=; b=ScmFXUnXQsBDQOeRRDk2JBohAqloSaHvUZJJVuDjOjk6MgJrr3XFo1W8C/+DWEOpLp CFoD3CAA31Kh5JHz4MeR1/WPbopm9O71On05gdvf3KfQDy903btjnNyyFU0gz0tOB6Z7 xFAFLQyz++xdvte4qay9VSxxaGBH7vl23QevY/KA6IP7MpaF5wB2+AKBVZNamTdUlfaN CIXDvPYRFQEAQU/t6zoMKOHwXQ9qgE2F8qmzjS9ffST7S5fB+ORib58xIj4LD7VVwqZV dk3soLeJWZbsvYAySuo3vUIXxVkk1ku0rTyE6Dy0DE6rWVNDB7awyY9j91+vQH4fLf7R gj7Q== 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=iS9w0OaNOwq2lVntX7Egw8nvc58/BIqmU/Sn5pstZMs=; b=eEtOHQIeW2KNfSvM4kULVGaXbBS/Nont14QgOkErge3D7MsZMfbuEaOu8MtmV5nDpV Wz765M18FKD35LFF3NGqczLAyGkrsso3im109RvMdEkaHKH+HMcb9YVzZ/L8pME+GyTU k8xPZzchvmwEk9J6DAqpeJLto3GN+AXTFClOgJnzuW/VqqRb0btybSaTUBcng51JvT2S BFCiQmFQyIBU2h51S9kY9CJ22L6iPFZoDINRN0JVmLaz7UVAKruJdvob9v70Sx56di4S kRZBUgrdnpwdI47oH0bHYkUy0+JuuxnVsk1kEKDcKeJdmzKD1RPKtC99Vxxm4e+m8Mff zDfg== X-Gm-Message-State: AOAM533W3UV97hKq0eyqDBrFZHTl0XMGu9c052AMr03fv8AKseVuWFW9 yYFiZovjY6fNGictiqso/1EaAgKkpCp7vRCQ X-Google-Smtp-Source: ABdhPJz0gbZP4BqfwiEDTMFUWQv3BXrxUsgsH+d0Rk7lM7XCFsOt8L1wSSB2ejz32cYkvipIBoymcA== X-Received: by 2002:a05:6214:1c87:b0:42d:20cb:e484 with SMTP id ib7-20020a0562141c8700b0042d20cbe484mr288883qvb.10.1644971361084; Tue, 15 Feb 2022 16:29:21 -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 g21sm20882584qtb.70.2022.02.15.16.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 16:29:20 -0800 (PST) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Tsukasa OI , Anup Patel , Heiko Stuebner , 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 v4 1/6] RISC-V: Correctly print supported extensions Date: Tue, 15 Feb 2022 16:29:06 -0800 Message-Id: <20220216002911.1219593-2-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220216002911.1219593-1-atishp@rivosinc.com> References: <20220216002911.1219593-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220215_162922_417527_C50425B2 X-CRM114-Status: GOOD ( 13.57 ) 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. Reviewed-by: Anup Patel Tested-by: Heiko Stuebner 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 Wed Feb 16 00:29:07 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: 12747759 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 14604C433EF for ; Wed, 16 Feb 2022 00:29:37 +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=fw8TVVFZhOS07fabc+sxIWCWqu3LFy2t9NYSVtYxEUY=; b=xxbuONMrlv+SAy mDJ3sLn/k+nvRci6IGb+XGTokBvhcORMnPm5LYuPWcgNpd+5Rm0XXK7FCxyRdlv6xwO0u7HSxc8J+ 42nIakjTvV5NPdrxTDFq3soOAhCZDJSrkI7YUn3/hqlz/gBVoFyPVnKt4GnzEkqgyq+dmhjxH6DCL /H8VZUJpBxTctzYk377rUKUyatVsRyGvdtK9iEfJ7xT6/GAiKtPXdsgQdj8Cph3xgac4HHqN3GoFi MJmltFUYr8JJpvTV2IqtrZ3F+Qe9n/85yPeN0TsfFLspNFY8WRnkNRKc+4x2IwpM0PqeMSzG7WvoJ F3SJfCNU1gA5ZR8GOElQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CH-0053yI-1j; Wed, 16 Feb 2022 00:29:29 +0000 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CC-0053vZ-G0 for linux-riscv@lists.infradead.org; Wed, 16 Feb 2022 00:29:26 +0000 Received: by mail-qk1-x729.google.com with SMTP id o25so371927qkj.7 for ; Tue, 15 Feb 2022 16:29:23 -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=oPhfrRu9lOMUwT/7SSpNUGyvJjdNpXCP/wW++bFxhRc=; b=YPlmDeBF2w6ovQYBYeEzPbox6WtothHnO7nsxF53hmX5zJ0jsbDAZKFrpdr0D1vh0z BbtZFa59zGUcnQ6/cbDnd6PQANTTzmOeB+gsU48SuAocmqBcD4N+sy7LAskYEaXBbwON faFomcz6BuIUnNy12LVRLPmhUmXV2EuhqKhLv5YuTTEKFMqRf/Emz0Vl33gr1+NI30yy WOWkisZcDD98K0wjYQAUeBQPkSOJ2RrMxr4zqfkXb6dusQu7XfRJqSUgx4b6fbppCbtY VEq5tpGWHkbhOf7QjDe3WcQ0aDkKljAApomEwZzmb4UtaF2z/YR0SswW3HCXgIO6LJm8 WaXA== 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=oPhfrRu9lOMUwT/7SSpNUGyvJjdNpXCP/wW++bFxhRc=; b=CgJ4qTk8J1CZ64qn7KXQr72loSeWkdLH5kF3ycNHWzymzbebfjowhqH86CMx5pmF0k 65bxnJeVvDW+5iV9h5ekDy6utu4LNPk6Elh0+hjLIcseESbAGENKMSqWd83sfcQj4vh/ chqWtwRKNcvR9r7UR906Q14fYpRNJ8eCvDpCNE20fu0iRFbDGruuHH1wd6iT8KDL5coM GSuE/7ITKUSqeg5WAIQVQwgFppgIny0IAH6ZZn5X6su5odpX0kAyHd+bbmLBH4cLMEI9 j6AlYqiHymZcmrM9GpBkgkkcYmDxnilGchjtcK1ElQcOaMznc+IpiFm2xGyJaj6Tg7F5 YaIw== X-Gm-Message-State: AOAM533LSVEisBZ+vIg6SDhbXDzROhRVLF5JDaav+se4k+VRWKN+SD/t kY6A4Aldcp2S4tX/UgwNWg7Afg== X-Google-Smtp-Source: ABdhPJwjUXfhUdSHWN5jaqEIsJNOX3lvX7622QszkSBMLvEK3VhO3Psn4rluzieRO/ioHE2DD9qi0Q== X-Received: by 2002:a37:2797:0:b0:605:bbdb:310d with SMTP id n145-20020a372797000000b00605bbdb310dmr208086qkn.638.1644971363199; Tue, 15 Feb 2022 16:29:23 -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 g21sm20882584qtb.70.2022.02.15.16.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 16:29:22 -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 v4 2/6] RISC-V: Minimal parser for "riscv, isa" strings Date: Tue, 15 Feb 2022 16:29:07 -0800 Message-Id: <20220216002911.1219593-3-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220216002911.1219593-1-atishp@rivosinc.com> References: <20220216002911.1219593-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220215_162924_576770_BB406B18 X-CRM114-Status: GOOD ( 18.21 ) 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. [Improved commit text and fixed a bug around 's' in base extension] Signed-off-by: Atish Patra [Fixed workaround for QEMU] Signed-off-by: Tsukasa OI Tested-by: Heiko Stuebner --- 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..65664422b04d 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++; + const char *ext_end = isa; + bool ext_long = false, ext_err = false; + + switch (*ext) { + case 's': + case 'x': + case 'z': + /** + * Workaround for invalid single-letter 's' (QEMU). + * It works until multi-letter extension starting + * with "Su" appears. + */ + if (*ext == 's' && ext[-1] != '_' && ext[1] == 'u') + break; + ext_long = true; + /* Multi-letter extension must be delimited */ + for (; *isa && *isa != '_'; ++isa) + if (!islower(*isa) && !isdigit(*isa)) + ext_err = true; + break; + default: + 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') + break; + if (!isdigit(*++isa)) { + --isa; + break; + } + /* Skip the major version */ + 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 Wed Feb 16 00:29:08 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: 12747760 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 4BC21C433F5 for ; Wed, 16 Feb 2022 00:29:38 +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=antZ2xGd20a41utTSDlsYS1yjbndw6BC8KXqi/tU+Y8=; b=2pBQKSD0fRgOTZ 205ZUVB8N/zeKJWalasYO/mZin7DtB8YJTBPGSt5jlznRf3ldsvmm+SImjobUeTHDzb5E9ZSABnTQ T/YXN4i5SKi38j3ditDdkEOoS0XMn/2/4H84P6So4WQKG+rVChUSUrF0V9hSLEAdOF3+iUVbw6dnf 5gE3yeNnma9NUxgbSMmaugmufV4n2gf1TAdd3zi8kc8JZzcOHkayNlGi4S9EICsFekIF6LWsvqa2v K5XDyPFwA0o37/qHzT/PMHow5elCC9jyRJPKHrCUxSK1JGZN+saKU8OsKjoVwqy+bgeMIfgV8I0xi jZN2bWraYZ+2y33S6hww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CJ-0053zY-J2; Wed, 16 Feb 2022 00:29:31 +0000 Received: from mail-qv1-xf29.google.com ([2607:f8b0:4864:20::f29]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CE-0053wU-Eu for linux-riscv@lists.infradead.org; Wed, 16 Feb 2022 00:29:27 +0000 Received: by mail-qv1-xf29.google.com with SMTP id o5so732971qvm.3 for ; Tue, 15 Feb 2022 16:29:25 -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=y7Lls7PJkZJYc7kZbxcHxB4Pg3B3kBBxHG3i/9qK9T8=; b=iVxQeG9XRXiX+NHnAAPdnfqRFudo+DhuKRYlg3KNjR+r63PyTERvyXTSOhQiHUjPal yadjBGjUpj+SU5JczUAHkrnSTIw7IND+TXvYERHyHEAItPHKufBA2yq2ylTr6eaZQGwq tsHuNeJxApsVwCBvvtWRgYrR9XZqj4fqJeQXkXPKLdWnVEzkad9+676Bf8dy9ySkrc0d rqqAlg48l4rGOKse0SeFEFDc4vt7tJZpMId1OD/FFcwtcgIs504aCf0a0cNhPPV/Oc2v P+2FAewm5fGeh3l0USDUSU2WJ4p0yiBdT1S/ZcPqqimZaI57ZIXFddkPc1ogAIUl1Qu0 rsYQ== 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=y7Lls7PJkZJYc7kZbxcHxB4Pg3B3kBBxHG3i/9qK9T8=; b=qgPDwJY+jNSOULOhbqcLVdXKaxR220ZoXYko6RXu28lz1z6/Pu/rqr1pItt8bl40xX LfEQmXc51PnC9Ov/TVnVVz6YJ9vlkD8fCBKFlI07uJLF/vwDNNpdRVd3jh12xHedJmX1 zEzK5iz77NgzWlyP6sG6Yf5yC31qkPp4QhPnu+xnaPbMldla+JXbx3sPGYOsQgdTx1kh /XqK26Q0dECiqh5X5yKGrSOYbu76Jhd0BsbCCRyAL5nkQ9s/yO/P3ykeoT5PIsXFnlAg RB4tDimMTrjuCnl0Fcw7nVKDMsqlYpsPEU6ZjkkXdh58+fCp0blVCyBRvY5oPpqamFn6 7FeQ== X-Gm-Message-State: AOAM530S974aLADMiGUdQ5l0ppk05oeuyleLB8Vwy4SqaLY6byq++v7t o7kHRhiIyez9FdocZmP7SkKSQuK7JjLLKH5I X-Google-Smtp-Source: ABdhPJxGailfSncIp2wrP5MaMjwC6ViL8hwSFjA+/hbO4qkDXM1lwd4PXEQLXo9gcOR7Hb73XLE29g== X-Received: by 2002:a05:6214:5003:b0:42f:bc42:6ce4 with SMTP id jo3-20020a056214500300b0042fbc426ce4mr344258qvb.63.1644971365295; Tue, 15 Feb 2022 16:29:25 -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 g21sm20882584qtb.70.2022.02.15.16.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 16:29:24 -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 v4 3/6] RISC-V: Extract multi-letter extension names from "riscv, isa" Date: Tue, 15 Feb 2022 16:29:08 -0800 Message-Id: <20220216002911.1219593-4-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220216002911.1219593-1-atishp@rivosinc.com> References: <20220216002911.1219593-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220215_162926_549099_E0E4466F X-CRM114-Status: GOOD ( 12.05 ) 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. 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 65664422b04d..cd9eb34f8d11 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -119,8 +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; + /* 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))) { @@ -146,14 +166,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')); + } } /* From patchwork Wed Feb 16 00:29:09 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: 12747761 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 CABF2C433F5 for ; Wed, 16 Feb 2022 00:29:41 +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=xqcmsnf0FNlOBQcQpPVnYKqcVLQuTIhef2PSSQ7jeVI=; b=LECqXgnYJaEOHx BKQgsxy59Wk/bG+ZaPIIBxDANlJiF0NEH1L9XTg+GIe4OyWVDN6hO44xEfVQ8BbLIUfX7mYTG+fuF eWZvVvvgTJcITPU1rYlgCo8xwvxiBrHkyIyC4WxzWyo+KJRHEGfD8BHoARuvyZCpwBR39gyV/YL4D 0gGusf9+Sf4oG/Lv9wKWMtlrbsgtyr3kQTVJ0ZfpiD55E4YtoygjX5tDKfzWycpm8/ifnLV14HJn+ pTAmScLLAsJ6mmHnhSkmYv7VTCo6wb0EL+dleq3md5VGu9zRhdyUsNkuh2JjPUXBE3eRj9cTwGxQe iPreypXsHFygcqwrto0Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CM-00541h-Lq; Wed, 16 Feb 2022 00:29:34 +0000 Received: from mail-qt1-x830.google.com ([2607:f8b0:4864:20::830]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CG-0053xc-Li for linux-riscv@lists.infradead.org; Wed, 16 Feb 2022 00:29:30 +0000 Received: by mail-qt1-x830.google.com with SMTP id bt3so636717qtb.0 for ; Tue, 15 Feb 2022 16:29: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=+mccZjH8NSKhWBiWsNwtOYrEp5jTHyxoNdNyuVqRQ88=; b=mDyg+hQZjMQDU9Uq7wsWXXtGXQt/Kj3wzuz1/ouJ/1Wf9LjhMW6HW/T5utJ7R+WoUO 8ZXqbkqpEOb7GH1YMqNDIXq+OW1lM5Ma7mLStdU64iy/UHbzDEKDPbQjJ3HcCvwwdlbI bsswUsWe0lxui3GYvtDlMTQKfDytGV898nYDWDOQANRtVJSQ1Kv35c7mkzYzj5MRe47v RRGq65bEr75KzZdsUYEPWi1htw2XehtkmyS9FwVO5wnnBz6H/lkp6qAEkHXXQI54eeQt Z/NDyijOhyhwoQBNpbyY6YKCoQU5JfwFIcTXE+jrErWVabp3/EAv827jBRw0BggzjQ41 FXMw== 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=+mccZjH8NSKhWBiWsNwtOYrEp5jTHyxoNdNyuVqRQ88=; b=s+LoI2hIkgYsOSkhARFqMiEfPH8mqWnH4fPIzXAIQ4Gza3GjFgOBelgtqR+M6v+dYh Meqm8FfvDRVEMBhIYe/gVnmQzeKpulPSnJrhx9T6pMWEeTuKjKZCzaJqZUd7ymOsqLAW alNboiYEfJO3ifd4Ge8tDlpu9JTqBCTZLKtt5Bz74/Z6yHNxD1sh3Wt7v1XFwiTDqg6Q 7P6VWOHmxme93wpwKSh1baVuyjsRF4LnNAFrIZLZbUtPPARkshe/o77G32K/ucaSjE2J JkgcBFq15OGgHrBeVv/WeqyeliXPE+0DZrlnKTRtmW7bQgevGEsCQHmA1HA2tKlko0Km nx5A== X-Gm-Message-State: AOAM530sWRUS+5c8jLL/jiL7Kt+4KZeojF5r08Agr5BQYxHBSQawQ5ey PLd/WTg4uc36pVGZZ9mhZZGgVA== X-Google-Smtp-Source: ABdhPJxX/1iKDISaumVfrJKyBSCp+qB9sw5uGTWszMRMIRfujWc3uyE9wjTNu2++q4autCmibTBZPQ== X-Received: by 2002:a05:622a:4d2:b0:2d7:1d2e:6dd0 with SMTP id q18-20020a05622a04d200b002d71d2e6dd0mr372899qtx.615.1644971367357; Tue, 15 Feb 2022 16:29: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 g21sm20882584qtb.70.2022.02.15.16.29.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 16:29:26 -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 , heiko@sntech.de, Rob Herring Subject: [PATCH v4 4/6] RISC-V: Implement multi-letter ISA extension probing framework Date: Tue, 15 Feb 2022 16:29:09 -0800 Message-Id: <20220216002911.1219593-5-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220216002911.1219593-1-atishp@rivosinc.com> References: <20220216002911.1219593-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220215_162928_735865_4D7F2D20 X-CRM114-Status: GOOD ( 14.85 ) 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 | 24 ++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 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..59c70c104256 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; + DECLARE_BITMAP(this_isa, RISCV_ISA_EXT_MAX); if (riscv_of_processor_hartid(node) < 0) continue; @@ -100,6 +100,7 @@ void __init riscv_fill_hwcap(void) if (!strncmp(isa, "rv64", 4)) isa += 4; #endif + bitmap_zero(this_isa, RISCV_ISA_EXT_MAX); for (; *isa; ++isa) { const char *ext = isa++; const char *ext_end = isa; @@ -167,12 +168,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)) { \ + set_bit(bit, this_isa); \ + 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')); + set_bit(*ext - 'a', this_isa); } +#undef SET_ISA_EXT_MAP } /* @@ -185,10 +196,11 @@ void __init riscv_fill_hwcap(void) else elf_hwcap = this_hwcap; - if (riscv_isa[0]) - riscv_isa[0] &= this_isa; + if (bitmap_weight(riscv_isa, RISCV_ISA_EXT_MAX)) + bitmap_and(riscv_isa, riscv_isa, this_isa, RISCV_ISA_EXT_MAX); else - riscv_isa[0] = this_isa; + bitmap_copy(riscv_isa, this_isa, RISCV_ISA_EXT_MAX); + } /* We don't support systems with F but without D, so mask those out @@ -202,7 +214,7 @@ void __init riscv_fill_hwcap(void) 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); + pr_info("riscv: base ISA extensions %s\n", print_str); memset(print_str, 0, sizeof(print_str)); for (i = 0, j = 0; i < NUM_ALPHA_EXTS; i++) From patchwork Wed Feb 16 00:29:10 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: 12747762 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 26D54C433FE for ; Wed, 16 Feb 2022 00:29: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=4JsSNMXhEXmNjUEmaYOwkMjw0U8ZJ/0Je+2c01P89iY=; b=vz0NLwxeXk6w0B uy4IDQdllssMg5kjsYXIODq+Ya2GWdfvn3KtnNT0GcbWG9M4U5WWGpLRJBOxuzIAbAhKO9LD38OBh bJ+X34lmmCRke5lUYtqFPRw4rB6Mh1Goa4Z9sdVLWde0Ku4hV5h60qmD6PCtzCUGlxGctETZGzabh uAfeHQqA0lL7x/InY3nUTr8VUu91QWw5IWl5XR626fUIVCRzGqeB8GG/vsJFG7f8L4GBppPaGaiW+ VLStesCpcdMsiXU2WjEEsNevXDerUYx61OdapldccHf3eFrAElSXW0dX+3CySN02A4vxf6wZBK+de 2qitbSpLC7EtHJeTNj4w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CQ-00544D-5j; Wed, 16 Feb 2022 00:29:38 +0000 Received: from mail-qk1-x729.google.com ([2607:f8b0:4864:20::729]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CI-0053yj-91 for linux-riscv@lists.infradead.org; Wed, 16 Feb 2022 00:29:31 +0000 Received: by mail-qk1-x729.google.com with SMTP id g24so391602qkl.3 for ; Tue, 15 Feb 2022 16:29: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=XiHWj5DVw0A6uknKnudKc4wLSuqR5J1NlVwPb2L6GW0=; b=n41wMt8sojwGlqC6Z7nUtCycjyWC9vz1LIB3RrVB9l+PleChAXiYN3rYZtcgXv68r5 lwMgO6gQ9r4c9m9dBG2ChZ6+7Uc/pJthcMbEg/wqTpBYisTP3m0Aw7avgPCSMuO67EEt vtvHg5u2ZDi5R2rgf1u7Mym2krHmO8WLxKvRU8hs//5a5q2CKJwPy+LwwJh/dfFONNUX ojJPH2rsitVm4zCAtXU8dtpDC2IPupmM7FTu+DV3w0JCiXshD78B05T9K1CtUmwP6MRL 1P9qhO1k+GBAjy3Vl01uo7JhQu/fYas/p5uKvlA5XcWPzzUMIFWxzR3AuisW3sApDN8x 8L9Q== 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=XiHWj5DVw0A6uknKnudKc4wLSuqR5J1NlVwPb2L6GW0=; b=3IbrlOPS5kbmKFoOBS+jqp3+YNDW71hpKplzZN2iGEqNP8C+hWU3a5OcB/2GzJJowP hF8X1s9NmxUI2N5lYcs0wBPS32cw1g/WA8NmfM99IqdozFY70UdK3KIrV0B3c7mPECUf PsiDF+r3mIyYkUf9WRnVRtlRRuj5XjuINqJLyxXSc1rdPmH6eUQ/jJ+HU1TG7gxm6tOj zjI/DN/1VzPPPOIoEzSaENqa1yThzg5E/D5XvG31rEUqL1mGN2Lbkr4PnN95/Ezwphxt EM/DQAcS4XBlW7afqg0Bz8yNIFtwJkMh8R2jq6Pf4IXxa/8F3Y47HFr6MLUzyIyzBFYC Awzw== X-Gm-Message-State: AOAM532VlU8D28PmUMfEH/gURQHTxzbYaaWDdltLYDOFTNcS2iNAQlIY W2++NwlcJbx5XabffDn3mXwJSA== X-Google-Smtp-Source: ABdhPJy11Z9r73cJwDFvGnyYg0cympD4CllJQkjIKWB04SZc9QKH7SjSeG/2wPtAFwGR5kdzxKZNdA== X-Received: by 2002:a05:620a:1708:b0:47b:ad8e:a33f with SMTP id az8-20020a05620a170800b0047bad8ea33fmr190865qkb.553.1644971369510; Tue, 15 Feb 2022 16:29:29 -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 g21sm20882584qtb.70.2022.02.15.16.29.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 16:29:29 -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 , heiko@sntech.de, Rob Herring Subject: [PATCH v4 5/6] RISC-V: Do no continue isa string parsing without correct XLEN Date: Tue, 15 Feb 2022 16:29:10 -0800 Message-Id: <20220216002911.1219593-6-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220216002911.1219593-1-atishp@rivosinc.com> References: <20220216002911.1219593-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220215_162930_366255_28F30BCB X-CRM114-Status: GOOD ( 10.62 ) 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 59c70c104256..cb9c9e0aab31 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; DECLARE_BITMAP(this_isa, RISCV_ISA_EXT_MAX); + const char *temp; if (riscv_of_processor_hartid(node) < 0) continue; @@ -93,6 +94,7 @@ void __init riscv_fill_hwcap(void) continue; } + temp = 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; bitmap_zero(this_isa, RISCV_ISA_EXT_MAX); for (; *isa; ++isa) { const char *ext = isa++; From patchwork Wed Feb 16 00:29:11 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: 12747763 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 6B75DC433F5 for ; Wed, 16 Feb 2022 00:29:48 +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=1JLrK/aDq5fB5+ y1W9YnstGXItoxUOxd/O4RDfUyg3L7rTar0KgofmNZkKoSjNx4NGZrKnos6MJH86vWo2MpLC2u5Ta DLGUlLByt5rkmMLJGkwRTBaxhccEPIfF1c+hD1ykiXSpVOgf3vGQ9S0ZY1vZFbZKVwDPmmVJm/1WD Je6HKbkXx7BmOwOhPSGWNx6APHJvA0NHOSuPCKKgF2FrU6KxFaw9anIgfh2iQYrcKpb0InXqbj93s O8NWSstdOjcVhI85k8NBoWH/VgEVGPYQUrQV+WIcZ4a4gNMU9W4ZtemrGSu9OA8gSpQYlDLupbY/g 6EwWEUsfcvu7xSeTOowQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CS-005462-LM; Wed, 16 Feb 2022 00:29:40 +0000 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nK8CK-0053zr-Q9 for linux-riscv@lists.infradead.org; Wed, 16 Feb 2022 00:29:34 +0000 Received: by mail-qk1-x731.google.com with SMTP id b22so348027qkk.12 for ; Tue, 15 Feb 2022 16:29: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=saY5DtvepsvwegCELkFkB7RgpB9RohGc6lIP30RliiM=; b=WeZDZR/wgQ3HJBPaI1lbXHd1ymtPQLDkS89Y+hauG1FO7BiVnsUlJENU/aTTHJpzEc froSAw9Ech0bJ+/c1Eraap/5RgylGvP7owPvkrrM6DFIeriyFvDtSEYJItciK+P4Q+a4 ZP5M4HEm1g7/v2Ef94+/nNSZaRNRm8L84VFyZ6sXbTE9YoJyfSqPFlpxEIik7YVM+TbG N8fGGs4RzKaRlfIuJqT0RWYV9frhIGhYUyECWmefGtcKfY7AIBCPxirqDhAOIxi/Bpbz kEwPGV+cemQeaXAUaJayW4Hiez9IXaR63DTPml67Vo00MLrsCxo9jgVcVldPNI7DRUsX 0VBA== 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=rlIKMjEu3G/KdCxgZZxUZt977UN1xU/c+w9DM7duWpIXFg7l7K57ey+LKlkXFGgJNA sldxN5MrFxGKstnS4nxOUPhs9okGsJnztsJ7ImGkuQLsvNi0Y8c6jJ6QOeX3eaAExEWR 15VpaQlXZJPF58/BiwO4UeQLgG3/eREV2IJwPO+OYbCH8g+pmMHocBaYPLngDmN8ZH6W 3L83k2mT542hHSIXmVNsYDWa+sQCigsmc6d+fuFKrtsYwiHa8E8KPb8WAQ2sKRCcjy50 obgXcW0PznaWIb6QZxzNhZsRqrmf2nLKiIbFA3tEo2GCwOAEO+SDNJGQqdxUeyJNx30x 85aQ== X-Gm-Message-State: AOAM533nPJ+ynjeDgmQbMnJNUORcRdAWkmn6JbZ2A4dvKUNXiDWmZaAv fVxqnItmFbOfad67FESnXcYPBg== X-Google-Smtp-Source: ABdhPJxgLsfYpRA+QvmhMNAXVF99c28x84OUD52yELKhbQvJUdEA4sPu3mofe6wteSIvVcp8Ebs2nQ== X-Received: by 2002:a37:d2c7:0:b0:47b:4cd8:5dbc with SMTP id f190-20020a37d2c7000000b0047b4cd85dbcmr187629qkj.567.1644971371452; Tue, 15 Feb 2022 16:29:31 -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 g21sm20882584qtb.70.2022.02.15.16.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 16:29:31 -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 , heiko@sntech.de, Rob Herring Subject: [PATCH v4 6/6] RISC-V: Improve /proc/cpuinfo output for ISA extensions Date: Tue, 15 Feb 2022 16:29:11 -0800 Message-Id: <20220216002911.1219593-7-atishp@rivosinc.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220216002911.1219593-1-atishp@rivosinc.com> References: <20220216002911.1219593-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220215_162932_875371_CF8F7E85 X-CRM114-Status: GOOD ( 17.44 ) 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"))