Received: by 2002:ac0:e34a:0:0:0:0:0 with SMTP id g10csp646385imn; Tue, 26 Jul 2022 05:56:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vsorsGivyO+0JhJnsgotqP2jmRO9t25/eTp3zMZrsbTb4Sz+9esYFKKd9gXO/vFvKzPHbI X-Received: by 2002:a17:90b:ec7:b0:1f2:fa08:44cd with SMTP id gz7-20020a17090b0ec700b001f2fa0844cdmr1917700pjb.183.1658840216540; Tue, 26 Jul 2022 05:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658840216; cv=none; d=google.com; s=arc-20160816; b=SAx/CKE8n6jT3m1G/f6E0omOVMCw1OO5C46pLR3wfIDwdRtzbIonvGJl1hNBJDTVKa W/a4a4G+XrC+l/zsFejRfM8mRd+9zbJM/4+NrZ8jNc5wEMzvb8Q2jzVyThyolT55AX8k QE9HJ9R4OWdsU23hEUoqouNl1KaD8NMB9MN0vvJXfETajeTktjcfuAvrPCA/gexBNVmu 8pVcAX+YuuSCE3FGYuIu4DKV0Vr2EKJpy/2VYEO/PpwJNT8cBsbQPA20jbmR5nrSbtpl wHk14clA7J27w9YD4YdWmK2zFIk4Yofm4lNkwZGbxjJxc5i70H74xBeYSju5wBKKw+zC w2Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8b1XaIe2pvWP5K0yAx5yjeutw2voVbR8sHlsVHCDajs=; b=d8+jm30QtKxziEh5+69BL4yxnnTC3awXYBCvWLr12ExcOsdxNut6nsZ9DozfsLpz26 8JMmmC6pdAUx9eAnUvnkEvHxFM32KSjItBzsLs10XDUZy0kQRJlaNcFEX8E/mtqew8zu CN9I1S4E3vPsu5jhqdWKLoFZb23LcKEEBlOhZ0HNVGwVZzJnfNdqxUjfYp/Tv7EFmdNU igqxMVKlNx4LjVT8hOeqpV5hwm5knh/5WdRhR0Vf6eAGArhQsGiprq8oXl0Kv4Ll82hX 4fHxaw6xooWq0K7Y1KJzeHmZd1/pJ9XdOIS0tBUyBUP7W3fMJJRTZwD+I+HRd7FXNpue ghQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=yMtzTJeq; 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 u1-20020a056a00158100b0052acf3f4090si19027201pfk.55.2022.07.26.05.56.41; Tue, 26 Jul 2022 05:56:56 -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=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=yMtzTJeq; 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 S233364AbiGZL5T (ORCPT + 99 others); Tue, 26 Jul 2022 07:57:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233355AbiGZL5R (ORCPT ); Tue, 26 Jul 2022 07:57:17 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4191F23150 for ; Tue, 26 Jul 2022 04:57:16 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id v67-20020a1cac46000000b003a1888b9d36so11198780wme.0 for ; Tue, 26 Jul 2022 04:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8b1XaIe2pvWP5K0yAx5yjeutw2voVbR8sHlsVHCDajs=; b=yMtzTJeqrokV2Tq5n9n0naG9BirUc2w4TdHlJJhVt8ONXCDvE0yFD/l2QV14iAO9DN lEyu6vMN4AtNxp7R50TNLxHa1uLikl+YgnwA4Yam2fIXfRmCEf/dio1dyqNYUaWLRLzF EfusuE/dxyqTUKBnZco/jPxSBWdRPfTiTj01cPA14iYm0iSePTzYbKrMTlJgifJe9r+D wwniCNDsSQCbWS1yl/VtNEb4Lc1f2HAStTf8nyc+lXwwGqBaOtKj0bRhMcXorpPpSde9 /w4TK23qDBWLZ9HJTOp4iYyyEUyNbJNRuSQOX5Le1KCGD1ZJQtSO1IJifsR7aNHkFVJf 29Lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8b1XaIe2pvWP5K0yAx5yjeutw2voVbR8sHlsVHCDajs=; b=iGtM4hVyeQhbmLU2z4jsKYy7Ams+MVad3IrLJMFmVgAIeTV7gvijCjHo+VfGZ8rqn6 FFtqiSJfGpLNBxhLFZC4VB8NO+pGbRqP77MNPJ9fn0nRzcJ6gkO6785kzYTtmKu4sbld fB9eiz6lA9Lsh+bYpKlcyuk8GsKaGK/I/TuVLpsmdvdIa5dCeqjxYDiS7zwkSnwnWu68 PRyAC1a/yR0/VMaUy6z8sbanSfBUSLfmuq7mHv0himFn/+RCF2+lGg0iP5oZKvoH9EwK A8+GC5PG5fMhiz8bMX/9dh7zg9biRmkjjLhASRwC9LOi6PBpjIqUNfJEpoO97IUhClOa 3Z4A== X-Gm-Message-State: AJIora+R1V6XMTTCeV0zSIOKoOE0NN+J2w4NOvrzCz+VuvbepJ8PuF+j Ey9NJGmTmb6I+T4tUE5oJvly4ZNds1CDDKNi7J/Im36C218= X-Received: by 2002:a05:600c:4fd5:b0:3a3:4664:6d55 with SMTP id o21-20020a05600c4fd500b003a346646d55mr12232878wmq.73.1658836634580; Tue, 26 Jul 2022 04:57:14 -0700 (PDT) MIME-Version: 1.0 References: <20220620115549.1529597-1-apatel@ventanamicro.com> In-Reply-To: <20220620115549.1529597-1-apatel@ventanamicro.com> From: Anup Patel Date: Tue, 26 Jul 2022 17:27:03 +0530 Message-ID: Subject: Re: [PATCH] RISC-V: Add mvendorid, marchid, and mimpid to /proc/cpuinfo output To: Palmer Dabbelt Cc: Paul Walmsley , Arnd Bergmann , Atish Patra , Nikita Shubin , Heinrich Schuchardt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Anup Patel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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 Hi Palmer, On Mon, Jun 20, 2022 at 5:26 PM Anup Patel wrote: > > 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 Can this patch be considered for 5.20 ? Regards, Anup > --- > 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..c037b8691bbb 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 defined(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 defined(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 >