From patchwork Tue Nov 16 15:48:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Sm/Do28gTcOhcmlvIERvbWluZ29z?= X-Patchwork-Id: 12622763 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 341D1C433EF for ; Tue, 16 Nov 2021 15:48:48 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CE37F6128A for ; Tue, 16 Nov 2021 15:48:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CE37F6128A Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=tecnico.ulisboa.pt Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=olr/0rH1Cvq4ocOpSX96nNk5gt3CUr7ATkmklQYKsKs=; b=hYz2bZu7p8NrUX 373pG4iwpkhOtzucvYCXxiU6zjckfnjBEY/IRsy8KUs/NeFXMQjU9lA+m9/wTpzgCCa8bOE/uRgPt P8aG2WCGlZri7MLg3IdvaPm7hoLGY5jtT2/K+woK2NUfnhrCMnuMDgYldGJ84by1/i6ukxO/EaL6v p7korZUn1vgrx9VMfF0Erc/I4w8GPHRopGUGBrXCV5RIRoT/T2kKRUBogczXlR/JUI+VU+YlPgOLI m+0Hgecvcll9dWsTA2Yk70xAnIIcMzipMHrak8iQRG3FjuV0/G/PSCHE1zbT9Nipbm3S/maM+aPlI ipSuWEb+CwVVBjHB9nBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mn0hN-002BjF-Ae; Tue, 16 Nov 2021 15:48:41 +0000 Received: from smtp1.tecnico.ulisboa.pt ([193.136.128.21]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mn0hI-002Ben-2h for linux-riscv@lists.infradead.org; Tue, 16 Nov 2021 15:48:38 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTP id 05B776005C2B; Tue, 16 Nov 2021 15:48:18 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.11.0 (20160426) (Debian) at tecnico.ulisboa.pt Received: from smtp1.tecnico.ulisboa.pt ([127.0.0.1]) by localhost (smtp1.tecnico.ulisboa.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id 7suzIrNTA-lf; Tue, 16 Nov 2021 15:48:14 +0000 (WET) Received: from mail2.tecnico.ulisboa.pt (mail2.ist.utl.pt [IPv6:2001:690:2100:1::4750:b5b4]) by smtp1.tecnico.ulisboa.pt (Postfix) with ESMTPS id 873936005C2C; Tue, 16 Nov 2021 15:48:14 +0000 (WET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tecnico.ulisboa.pt; s=mail; t=1637077694; bh=EsbqsfDwR3GCr6eujE8yzM6eJnlvI/PG3VO6iR63Ji8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EFSRGDrk0Lji+eHSFF6QjNgniPFr1qyHOC2TC4bSZ+Pv4PfSL9DFeoWRnc7fxXrtV ZoLgfHbyNx2/Iymj19NLbgs31gu4UgJ2I4JczCeASMbtW9e3N+OmhkY6a/cv6jwSyE 8+tasQSJ8uiky5a5SThGqu+0uKZeTDloQ4U8AKq8= Received: from joaomariovmubuntu.Home (unknown [IPv6:2001:8a0:fa2d:4500:215:5dff:fe40:101]) (Authenticated sender: ist181713) by mail2.tecnico.ulisboa.pt (Postfix) with ESMTPSA id 59F7B56007D; Tue, 16 Nov 2021 15:48:14 +0000 (WET) From: =?utf-8?b?Sm/Do28gTcOhcmlvIERvbWluZ29z?= To: palmer@dabbelt.com, paul.walmsley@sifive.com, aou@eecs.berkeley.edu Cc: atish.patra@wdc.com, anup.patel@wdc.com, linux-riscv@lists.infradead.org, nikita.shubin@maquefel.me, joao.mario@tecnico.ulisboa.pt Subject: [PATCH v2 1/4] RISC-V: Create unique identification for SoC PMU Date: Tue, 16 Nov 2021 15:48:09 +0000 Message-Id: <20211116154812.17008-2-joao.mario@tecnico.ulisboa.pt> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211116154812.17008-1-joao.mario@tecnico.ulisboa.pt> References: <20211109102555.16381-1-joao.mario@tecnico.ulisboa.pt> <20211116154812.17008-1-joao.mario@tecnico.ulisboa.pt> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211116_074836_461724_1F00B84F X-CRM114-Status: GOOD ( 14.33 ) 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 SBI PMU platform driver did not provide any identification for perf events matching. This patch introduces a new sysfs file inside the platform device (soc:pmu/id) for pmu identification. The identification is a 64-bit value generated as: [63-32]: mvendorid; [31]: marchid[MSB]; [30-16]: marchid[15-0]; [15-0]: mimpid[15MSBs]; The CSRs are detailed in the RISC-V privileged spec [1]. The marchid is split in MSB + 15LSBs, due to the MSB being used for open-source architecture identification. [1] https://github.com/riscv/riscv-isa-manual Signed-off-by: João Mário Domingos --- arch/riscv/kernel/sbi.c | 3 +++ drivers/perf/riscv_pmu_sbi.c | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index 7402a417f38e..4e4f5671b864 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -551,16 +551,19 @@ long sbi_get_mvendorid(void) { return __sbi_base_ecall(SBI_EXT_BASE_GET_MVENDORID); } +EXPORT_SYMBOL(sbi_get_mvendorid); long sbi_get_marchid(void) { return __sbi_base_ecall(SBI_EXT_BASE_GET_MARCHID); } +EXPORT_SYMBOL(sbi_get_marchid); long sbi_get_mimpid(void) { return __sbi_base_ecall(SBI_EXT_BASE_GET_MIMPID); } +EXPORT_SYMBOL(sbi_get_mimpid); static void sbi_send_cpumask_ipi(const struct cpumask *target) { diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 7a68dfa89f6f..a69251ec7a3e 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -642,6 +642,46 @@ static int pmu_sbi_setup_irqs(struct riscv_pmu *pmu, struct platform_device *pde return 0; } +static uint64_t pmu_sbi_get_pmu_id(void) +{ + union sbi_pmu_id { + uint64_t value; + struct { + uint16_t imp:16; + uint16_t arch:16; + uint32_t vendor:32; + }; + } pmuid; + + pmuid.value = 0; + pmuid.vendor = (uint32_t) sbi_get_mvendorid(); + pmuid.arch = (sbi_get_marchid() >> (63 - 15) & (1 << 15)) | (sbi_get_marchid() & 0x7FFF); + pmuid.imp = (sbi_get_mimpid() >> 16); + + return pmuid.value; +} + +static ssize_t pmu_sbi_id_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + int len; + + len = sprintf(buf, "0x%llx\n", pmu_sbi_get_pmu_id()); + if (len <= 0) + dev_err(dev, "mydrv: Invalid sprintf len: %dn", len); + + return len; +} + +static DEVICE_ATTR(id, S_IRUGO | S_IWUSR, pmu_sbi_id_show, 0); + +static struct attribute *pmu_sbi_attrs[] = { + &dev_attr_id.attr, + NULL +}; + +ATTRIBUTE_GROUPS(pmu_sbi); + static int pmu_sbi_device_probe(struct platform_device *pdev) { struct riscv_pmu *pmu = NULL; @@ -680,6 +720,13 @@ static int pmu_sbi_device_probe(struct platform_device *pdev) pmu->ctr_clear_idx = pmu_sbi_ctr_clear_idx; pmu->ctr_read = pmu_sbi_ctr_read; + ret = sysfs_create_group(&pdev->dev.kobj, &pmu_sbi_group); + if (ret) { + dev_err(&pdev->dev, "sysfs creation failed\n"); + return ret; + } + pdev->dev.groups = pmu_sbi_groups; + ret = cpuhp_state_add_instance(CPUHP_AP_PERF_RISCV_STARTING, &pmu->node); if (ret) return ret;