From patchwork Wed Feb 16 05:04:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 12747956 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 6C6A3C433EF for ; Wed, 16 Feb 2022 05:04:59 +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=jpWqBRutIGHQmF+G/pFhBmKjX+u/cPx/rzqOu4305Js=; b=fzb7d8aqcJsES1 nlKeWzBPVBGM4vG9YopXxeNCuoMn0WhnbYqTVKKVuxntFK1GgPhjE5mj3I2yIadKT8rBSBF9rK/f4 OT5S8OgItQH4AE+YlPW8LnowGan58vzpC8wdP7J+n7g6yuy7IslmxLL477r3o5miSE++jKumwEt0D y5IWMteDI/S+3QK1WnQ53L9uiCMNLOLEJ1vbHj/HDfOAOXAsohXZ5MkVBDcLBIozNRkxhmDCWit67 Cj1DbSaVpp9TyPycnSwgRRPAmuo3iGcg8HX6vgragpUBc+e4WN4IHOfYr6zPYDaPj+ud2LbuAolMx inHNp3MirK0a+x35J8Eg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKCUi-005YIJ-ER; Wed, 16 Feb 2022 05:04:48 +0000 Received: from mail-sender.a4lg.com ([153.120.152.154] helo=mail-sender-0.a4lg.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKCUf-005YFC-1d for linux-riscv@lists.infradead.org; Wed, 16 Feb 2022 05:04:46 +0000 From: Tsukasa OI Authentication-Results: mail-sender-0.a4lg.com; dkim=permerror (bad message/signature format) To: Tsukasa OI , linux-riscv@lists.infradead.org Cc: Atish Patra Subject: [PATCH 1/2] RISC-V: Better 'S' workaround Date: Wed, 16 Feb 2022 14:04:26 +0900 Message-Id: <3742d1f8962538661bfe5f9f74128d6375d45884.1644987761.git.research_trasio@irq.a4lg.com> In-Reply-To: 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_210445_262320_EB91E58B X-CRM114-Status: UNSURE ( 7.34 ) X-CRM114-Notice: Please train this message. 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 This commit moves 'S' workaround and skips 'S' and 'U' "extensions" (invalid as single-letter extensions) from riscv_isa (base ISA extensions). This commit is intended to be squashed into Atish's isa_framework_v4 PATCH 3/6. Signed-off-by: Tsukasa OI --- arch/riscv/kernel/cpufeature.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index c3ef55203117..b00ce81627a4 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -113,15 +113,19 @@ void __init riscv_fill_hwcap(void) 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') + if (ext[-1] != '_' && ext[1] == 'u') { + ++isa; + ext_err = true; break; + } + fallthrough; + case 'x': + case 'z': ext_long = true; /* Multi-letter extension must be delimited */ for (; *isa && *isa != '_'; ++isa) From patchwork Wed Feb 16 05:04:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 12747955 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 52B16C433F5 for ; Wed, 16 Feb 2022 05:04:59 +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=+yxOBV+qbZD9cuuojstcxkUWTqYimZnHfilOHKyHDX0=; b=X7GYIZrIg2iKyh A7aprNKsTnLoWNIwi9+IJxU26lR0itVOwVqcmYHHpSfr5VQ1yPCOODvxN1EjFY++1VifLxUMLiyaM ORbTsPQx2SQutVZ9YVAbY7oLMAGxh7zr36rUDTT78IbArh2C3LI3mVdlI7RqJs8cOMI1VKZruzoZF kcRKch4ofZ/Ab1p8ILF1dClxQoogQZee5+HcKSI6BnEuxS51peirKE/EebH8cQJRrnTlfShZIf3kU Ne7Q0opOi86xfstnISD0X2i+WvbjHE/15Tc7DnEiuromulFIgnIiELybjDgRxHQ6vd57miMtQb2c9 JgR1Bwo8bDZ31Z9XIRuA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKCUl-005YJC-Th; Wed, 16 Feb 2022 05:04:51 +0000 Received: from mail-sender.a4lg.com ([153.120.152.154] helo=mail-sender-0.a4lg.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nKCUg-005YFa-FW for linux-riscv@lists.infradead.org; Wed, 16 Feb 2022 05:04:48 +0000 From: Tsukasa OI Authentication-Results: mail-sender-0.a4lg.com; dkim=permerror (bad message/signature format) To: Tsukasa OI , linux-riscv@lists.infradead.org Cc: Atish Patra Subject: [PATCH 2/2] RISC-V: Extract base ISA from device tree Date: Wed, 16 Feb 2022 14:04:27 +0900 Message-Id: <8d7e1937f9476d14f64a53684b11bedd6f4ff88d.1644987761.git.research_trasio@irq.a4lg.com> In-Reply-To: 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_210446_685267_851E26D3 X-CRM114-Status: GOOD ( 12.39 ) 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 This commit replaces print_isa function to extract base ISA from device tree ("riscv,isa"). It uses a subset of Tsukasa's riscv_fill_hwcap ISA parser. Design choices (1): It constructs base ISA string from the original string (does not cut the original string like Atish's). This is to strip version numbers (too minor to represent as major ISA) but this behavior may be debatable. Design choices (2): It skips when single-letter 'S' or 'U' is encountered. It improves familiarity with regular ISA string. This commit is intended to be squashed into Atish's isa_framework_v4 PATCH 6/6. Signed-off-by: Tsukasa OI --- arch/riscv/kernel/cpu.c | 83 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 9 deletions(-) diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index 6f9660c0a973..3f9607a66d95 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -101,17 +101,82 @@ static void print_isa_ext(struct seq_file *f) static void print_isa(struct seq_file *f, const char *isa) { - 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); + unsigned char parse_break = 0; + char base_isa[RISCV_ISA_EXT_BASE + 5]; + char *base_isa_end = base_isa; + const char *isa_end = isa; +#if IS_ENABLED(CONFIG_32BIT) + if (!strncmp(isa, "rv32", 4)) + isa_end += 4; +#elif IS_ENABLED(CONFIG_64BIT) + if (!strncmp(isa, "rv64", 4)) + isa_end += 4; +#endif + if (isa != isa_end) { + strncpy(base_isa, isa, isa_end - isa); + base_isa_end += isa_end - isa; + for (; *isa_end; ++isa_end) { + switch (*isa_end++) { + case 'x': + case 'z': + parse_break = 1; + break; + case 's': + if (*isa_end != 'u') { + parse_break = 1; + break; + } + /** + * Workaround for invalid single-letter 's' + * (QEMU). Should break for valid ISA string. + */ + fallthrough; + default: + if (unlikely(!islower(isa_end[-1]) + || base_isa_end == base_isa + sizeof(base_isa))) { + parse_break = 2; + break; + } + switch (isa_end[-1]) { + case 's': + case 'u': + break; + default: + *base_isa_end++ = isa_end[-1]; + } + /* Skip version number */ + if (!isdigit(*isa_end)) + break; + while (isdigit(*++isa_end)) + ; + if (*isa_end != 'p') + break; + if (!isdigit(*++isa_end)) { + --isa_end; + break; + } + while (isdigit(*++isa_end)) + ; + break; + } + if (*isa_end != '_') + --isa_end; + if (parse_break) + break; + } + } - /* Print only the base ISA as it is */ + /** + * Print only the base ISA + * (original ISA string as is if an error is encountered) + */ seq_puts(f, "isa\t\t: "); - seq_write(f, isa, base_isa_len); + if (parse_break < 2) { + seq_write(f, base_isa, base_isa_end - base_isa); + } else { + isa_end += strlen(isa_end); + seq_write(f, isa, isa_end - isa); + } seq_puts(f, "\n"); }