Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp42005imn; Tue, 26 Jul 2022 21:48:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tltEhjV0YmRDa/RkKoOO+TK4ROcR3fG761PvjBT1Ub1BW0Fx8At5GsCF9PpzgpqsSRS1/C X-Received: by 2002:a63:b08:0:b0:41a:a7b9:d8d6 with SMTP id 8-20020a630b08000000b0041aa7b9d8d6mr17519742pgl.306.1658897314540; Tue, 26 Jul 2022 21:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658897314; cv=none; d=google.com; s=arc-20160816; b=0v4lLx9bVFTBy7lI/73PZyp0UPAUobD4uDN69HmxSf5BbYjCTZfBRI+4tOnJ218/dL eoMN/UODutDGAomCuL9aVo3JxpAznweEjUyz74OaAu8WssZmZqfj6IrAuWx0gvfWQgWx HdZxSLKejFHsOZ2l5bPYDk/ls4VnOzC8dBFVZKi2QSCFRGZVkT+VhT9HkmfoeSl/3+c/ bdNo8nWeEcj0OVYktAX9FHGFfpHCSM+Za7tkuTSjgQaPh5Uzfgdc18zIidy+1pd7n78X Wlij67Hf9TC6Csz8oGPbOsB3fgwFXsEZFNkWXViujfq4chln9oF6JF+7V2iFYIGb+vdr glHA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=72mc9rV+Or/UCSUqmbngTq+GJzkxqJLuquOjL+k6DMk=; b=jOf2YTIM28o+Ncd2PiIgdTNs1p6QIEQup358XkqfMaAzz7W8TCVzRx3ddQIeyVIT3w 1EU1XhEkIMPkTX782c6sDHT8ACpnVtcwlNmAivXReAUPrEHEilHF8S+GrpiWv7wT9+Up D9G/+PqKbg9T2E4A/XHP/95BkAAZj395ViFVjQnFzShM/+nhn8WR8nh1p8CIy052WjYz ZwNgH+0sLKPuXZDTnkfnEYOXMR/SviV+htsqnRzQrbjhae+7GlAEkEu3AMs7Alvj9ZE/ yGi+760pKxON0hOmVNqfJCrWJjNu+RbPgpyBgFnsKQ4hqjrMInXCEnRtiuQHQKbkR78Y KAFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=RUBWXp33; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l70-20020a638849000000b0041a94732957si17006724pgd.443.2022.07.26.21.48.15; Tue, 26 Jul 2022 21:48:34 -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; dkim=pass header.i=@ventanamicro.com header.s=google header.b=RUBWXp33; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240407AbiG0Ej3 (ORCPT + 99 others); Wed, 27 Jul 2022 00:39:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39396 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240396AbiG0EjZ (ORCPT ); Wed, 27 Jul 2022 00:39:25 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E53A73DF1B for ; Tue, 26 Jul 2022 21:39:23 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id ku18so15314269pjb.2 for ; Tue, 26 Jul 2022 21:39:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=72mc9rV+Or/UCSUqmbngTq+GJzkxqJLuquOjL+k6DMk=; b=RUBWXp3346mGXGsT/osQGMIKkSCA7yBvKUWTxP6L7ZIoPDHhZWW3FU0T2eh8E66tQu 639S1w9a6BlXBIGp2jX6yp5WT2gYUDqvnvYRa4cuHGwRQ3xENfJv/A+KPLMCA3EUsGhI hgzz0vAqmQoeaVWvPbRpm/8xi0fiS2xSf1wsACbKru8KFtUNsK0c+O+stYy2n8GxyAim qrRUEbZGWGVSDoicrAUaKPzTHfVF23eXYxcO/PIFW5gbXJPU5+tynMvpsPUogKKg9d1P nG3fUHb7Ln1NJ3aU99x6VeKAkO2mWvEMaPOxwSYv7hAZvbO88LjX9WrifLX3tfQWSyE+ ihNg== 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:mime-version :content-transfer-encoding; bh=72mc9rV+Or/UCSUqmbngTq+GJzkxqJLuquOjL+k6DMk=; b=zO2MDSmx0R5gm8Si4ZRg7T5LPUN60Ir4Q6NwYYScx8hFxoF7yjSA3Wol+wcJaKvgVv QOFCSO5G2to+DI4m5G5oWQum1QiPuZWbSubMPa/FWoXsA1WUDmzEohZYagmdjbZ5S9jK mLUQIUMRtdW0WHgeT6JzhkF6khPLI1fkla9rQBYM6r9vHqaqoWB+MdFK+zLp9RTvu45M 8KewkzE4lQ1ez8y+1EynjQws/UZIrN0+gM117z95WPKCzzG8dtGTMN6UKYHK/DKbOLJj Kh2lOtz3+nslNy3uit3Tv6NTMwXOL2B2VfvBDInNnezeYTwqXSIcSOfYdxwuGB8P/QbC Kv7Q== X-Gm-Message-State: AJIora9Q/RP38wQO1BtmH18jQ4AAKA4Xq8jUNmaQtGTit0kHG9iUPII6 /67BhVKFn+GU3BNxlOdJt1qilw== X-Received: by 2002:a17:902:7143:b0:16d:986c:f2f9 with SMTP id u3-20020a170902714300b0016d986cf2f9mr7136604plm.42.1658896763327; Tue, 26 Jul 2022 21:39:23 -0700 (PDT) Received: from anup-ubuntu64-vm.. ([171.76.87.63]) by smtp.gmail.com with ESMTPSA id p2-20020a17090a284200b001f216407204sm500698pjf.36.2022.07.26.21.39.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Jul 2022 21:39:22 -0700 (PDT) From: Anup Patel To: Palmer Dabbelt , Paul Walmsley Cc: Arnd Bergmann , Atish Patra , Nikita Shubin , Heinrich Schuchardt , Anup Patel , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel , Nikita Shubin Subject: [PATCH v2] RISC-V: Add mvendorid, marchid, and mimpid to /proc/cpuinfo output Date: Wed, 27 Jul 2022 10:08:29 +0530 Message-Id: <20220727043829.151794-1-apatel@ventanamicro.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 Identifying the underlying RISC-V implementation can be important for some of the user space applications. For example, the perf tool uses arch specific CPU implementation id (i.e. CPUID) to select a JSON file describing custom perf events on a CPU. Currently, there is no way to identify RISC-V implementation so we add mvendorid, marchid, and mimpid to /proc/cpuinfo output. Signed-off-by: Anup Patel Reviewed-by: Heinrich Schuchardt Tested-by: Nikita Shubin --- Changes since v1: - Use IS_ENABLED() to check CONFIG defines - Added RB and TB tags in commit description --- arch/riscv/kernel/cpu.c | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index fba9e9f46a8c..04bcc91c91ea 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -3,10 +3,13 @@ * Copyright (C) 2012 Regents of the University of California */ +#include #include #include #include +#include #include +#include #include #include @@ -64,6 +67,50 @@ int riscv_of_parent_hartid(struct device_node *node) } #ifdef CONFIG_PROC_FS + +struct riscv_cpuinfo { + unsigned long mvendorid; + unsigned long marchid; + unsigned long mimpid; +}; +static DEFINE_PER_CPU(struct riscv_cpuinfo, riscv_cpuinfo); + +static int riscv_cpuinfo_starting(unsigned int cpu) +{ + struct riscv_cpuinfo *ci = this_cpu_ptr(&riscv_cpuinfo); + +#if IS_ENABLED(CONFIG_RISCV_SBI) + ci->mvendorid = sbi_spec_is_0_1() ? 0 : sbi_get_mvendorid(); + ci->marchid = sbi_spec_is_0_1() ? 0 : sbi_get_marchid(); + ci->mimpid = sbi_spec_is_0_1() ? 0 : sbi_get_mimpid(); +#elif IS_ENABLED(CONFIG_RISCV_M_MODE) + ci->mvendorid = csr_read(CSR_MVENDORID); + ci->marchid = csr_read(CSR_MARCHID); + ci->mimpid = csr_read(CSR_MIMPID); +#else + ci->mvendorid = 0; + ci->marchid = 0; + ci->mimpid = 0; +#endif + + return 0; +} + +static int __init riscv_cpuinfo_init(void) +{ + int ret; + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "riscv/cpuinfo:starting", + riscv_cpuinfo_starting, NULL); + if (ret < 0) { + pr_err("cpuinfo: failed to register hotplug callbacks.\n"); + return ret; + } + + return 0; +} +device_initcall(riscv_cpuinfo_init); + #define __RISCV_ISA_EXT_DATA(UPROP, EXTID) \ { \ .uprop = #UPROP, \ @@ -178,6 +225,7 @@ static int c_show(struct seq_file *m, void *v) { unsigned long cpu_id = (unsigned long)v - 1; struct device_node *node = of_get_cpu_node(cpu_id, NULL); + struct riscv_cpuinfo *ci = per_cpu_ptr(&riscv_cpuinfo, cpu_id); const char *compat, *isa; seq_printf(m, "processor\t: %lu\n", cpu_id); @@ -188,6 +236,9 @@ static int c_show(struct seq_file *m, void *v) if (!of_property_read_string(node, "compatible", &compat) && strcmp(compat, "riscv")) seq_printf(m, "uarch\t\t: %s\n", compat); + seq_printf(m, "mvendorid\t: 0x%lx\n", ci->mvendorid); + seq_printf(m, "marchid\t\t: 0x%lx\n", ci->marchid); + seq_printf(m, "mimpid\t\t: 0x%lx\n", ci->mimpid); seq_puts(m, "\n"); of_node_put(node); -- 2.34.1