Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6045307rwr; Mon, 24 Apr 2023 12:50:47 -0700 (PDT) X-Google-Smtp-Source: AKy350YK9LsjAWizmNCooz99MghX+hzrL16zov/FBmKfcWL2bEEi2ecy4qmieiWwmZapRhS19mO4 X-Received: by 2002:a05:6a00:2e06:b0:63a:33d5:9224 with SMTP id fc6-20020a056a002e0600b0063a33d59224mr20309198pfb.18.1682365847708; Mon, 24 Apr 2023 12:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682365847; cv=none; d=google.com; s=arc-20160816; b=Pe0paMHxGvE5NAk6Pipn7deAlhq077Ugze5IjE7K7irmgJJXfQqtUSuB7rG9a/wdtf 8saIY5kLvfeH6HdgMowTXL3CMhp9ry2eHFB2PqrHHnWAbTaZI3LwumjdGzvmVFjeN5GA va+xC6QNci441H+EJ1j5VbUnwG6zLwLogSqCAE5xGj9IOu3IWFiWX5MIHTxpwJEoYgQ8 zWTuj5LItPBEtn53SZuuA/fFMEtT0rIw3CjcZn9v8Tg1LIE3bs6ECBgohFyB48oBhikr JLyPhNbgtHQsfbHcef+TStq+96DBnWiAMRNuC6NDfZkZFkScZ9i3K+L9XvRPIAAdEsQd YFVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=WpVef7wKAZOD2zMRtPqWRoYyEBvCWl80BGBUi3JUXB8=; b=eimz+8kuFHNHx3Mwv126mea8tw/Nb8XzNCCQFOAOkGd6v8BFbUV2pAcNAJuNy+Gua7 J9rVLYfPAu24COCxM7MUoce9QA7qisYFzAjLQ6xairFHn/qIqqo31NDLz2QwAPY4iDwx 431FcXq8VQTi/BqP0tFMQ1aL169FttoVZsWpRZUpb2hFaPYqQtUlAUyj7Njv86UzHOrm 4U7sd38mketYbFKZsVuqVz6O91ZkLFPIWl9FXKKfFPbmUxsrAz/RHXEVafaV7+OBRVUu 55AZ1KWfx4pMD4Aci4q2WbLJkWuoVUtTJbs5gFYj3hAY6uQvQfG/RaIWURFWoJfl+y1a RbTA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z25-20020aa79599000000b006389d389c01si11594599pfj.78.2023.04.24.12.50.36; Mon, 24 Apr 2023 12:50:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=sntech.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232981AbjDXTuU (ORCPT + 99 others); Mon, 24 Apr 2023 15:50:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231945AbjDXTtl (ORCPT ); Mon, 24 Apr 2023 15:49:41 -0400 Received: from gloria.sntech.de (gloria.sntech.de [185.11.138.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E80B472A0 for ; Mon, 24 Apr 2023 12:49:39 -0700 (PDT) Received: from ip4d1634d3.dynamic.kabel-deutschland.de ([77.22.52.211] helo=phil.lan) by gloria.sntech.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1pr2Bi-0006Mz-8I; Mon, 24 Apr 2023 21:49:26 +0200 From: Heiko Stuebner To: palmer@dabbelt.com, linux-riscv@lists.infradead.org, paul.walmsley@sifive.com Cc: heiko@sntech.de, kito.cheng@sifive.com, jrtc27@jrtc27.com, conor.dooley@microchip.com, matthias.bgg@gmail.com, heinrich.schuchardt@canonical.com, greentime.hu@sifive.com, nick.knight@sifive.com, christoph.muellner@vrull.eu, philipp.tomsich@vrull.eu, richard.henderson@linaro.org, arnd@arndb.de, linux-kernel@vger.kernel.org, Heiko Stuebner Subject: [PATCH 1/4] RISC-V: create ISA string separately - not as part of cpuinfo Date: Mon, 24 Apr 2023 21:49:08 +0200 Message-Id: <20230424194911.264850-2-heiko.stuebner@vrull.eu> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230424194911.264850-1-heiko.stuebner@vrull.eu> References: <20230424194911.264850-1-heiko.stuebner@vrull.eu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_PASS, T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Heiko Stuebner The isa string is a very central part of the RISC-V architecture, so will be needed in other places as well. So in a first step decouple the generation of the runtime isa-string from /proc/cpuinfo - its current only user. The resulting string should not differ from the previously generated one. Signed-off-by: Heiko Stuebner --- arch/riscv/kernel/cpu.c | 70 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index 3df38052dcbd..ebc478f0a16c 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -193,10 +193,33 @@ 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) +static int strlen_isa_ext(void) { struct riscv_isa_ext_data *edata; - int i = 0, arr_sz; + int ext_len = 0, i, arr_sz; + + arr_sz = ARRAY_SIZE(isa_ext_arr) - 1; + + /* No extension support available */ + if (arr_sz <= 0) + return 0; + + for (i = 0; i <= arr_sz; i++) { + edata = &isa_ext_arr[i]; + if (!__riscv_isa_extension_available(NULL, edata->isa_ext_id)) + continue; + + /* string length + underscore */ + ext_len += strlen(edata->uprop) + 1; + } + + return ext_len; +} + +static void strcat_isa_ext(char *isa_str) +{ + struct riscv_isa_ext_data *edata; + int i, arr_sz; arr_sz = ARRAY_SIZE(isa_ext_arr) - 1; @@ -208,7 +231,8 @@ static void print_isa_ext(struct seq_file *f) edata = &isa_ext_arr[i]; if (!__riscv_isa_extension_available(NULL, edata->isa_ext_id)) continue; - seq_printf(f, "_%s", edata->uprop); + strcat(isa_str, "_"); + strcat(isa_str, edata->uprop); } } @@ -220,19 +244,49 @@ static void print_isa_ext(struct seq_file *f) */ static const char base_riscv_exts[13] = "imafdqcbkjpvh"; -static void print_isa(struct seq_file *f, const char *isa) +static char *riscv_create_isa_string(const char *isa) { + int maxlen = 4; + char *isa_str; int i; - seq_puts(f, "isa\t\t: "); + /* calculate the needed string length */ + for (i = 0; i < sizeof(base_riscv_exts); i++) + if (__riscv_isa_extension_available(NULL, base_riscv_exts[i] - 'a')) + maxlen++; + maxlen += strlen_isa_ext(); + + isa_str = kzalloc(maxlen, GFP_KERNEL); + if (!isa_str) + return ERR_PTR(-ENOMEM); + /* Print the rv[64/32] part */ - seq_write(f, isa, 4); + strncat(isa_str, isa, 4); + for (i = 0; i < sizeof(base_riscv_exts); i++) { if (__riscv_isa_extension_available(NULL, base_riscv_exts[i] - 'a')) /* Print only enabled the base ISA extensions */ - seq_write(f, &base_riscv_exts[i], 1); + strncat(isa_str, &base_riscv_exts[i], 1); + } + + strcat_isa_ext(isa_str); + + return isa_str; +} + +static void print_isa(struct seq_file *f, const char *isa) +{ + char *isa_str; + + seq_puts(f, "isa\t\t: "); + + isa_str = riscv_create_isa_string(isa); + if (!IS_ERR(isa_str)) { + seq_write(f, isa_str, strlen(isa_str)); + kfree(isa_str); + } else { + seq_puts(f, "unknown"); } - print_isa_ext(f); seq_puts(f, "\n"); } -- 2.39.0