From patchwork Fri Mar 19 22:12:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456048 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=poZECQm6; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=jElErmsP; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J7n483kz9sVS for ; Sat, 20 Mar 2021 09:13:41 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=nvwXiQ9QwVg0nibZtN2MrMoaIgiYeH8iD/3z2ik87uU=; b=poZECQm6iSJOtdqCpT+cRHqzU F4og7+MepTBVotzVyBJbMYGX/AEyQoOBNgF+6t7i4dmK25sPTd9AuBcd/6noq/DIcQ+kHQJbFpNjR zsYe9RKzj5NVFmQQRqmCGwS0359zfR69WkhVERjKzrVVbel8ZhtLOazYT1lSfbfdWMpzUHqanyqDU kL7OxvYzvzIKfMRmTltde7qCa+Et5+QamrUkfUaLyDF6cnf3bBBpjmIBRzpsB51LnQ/kn2nm0J2uI j1EOLj5igsFcXuIYoADITl1/CeA/OlMGiBcC8H6umwLuRZ9VZnyikaRlUT21NquDvLx+uDW9o4UoX Qun8ZL3Bg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNA-008FMB-4l; Fri, 19 Mar 2021 22:13:36 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNN4-008FJO-Ri for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192011; x=1647728011; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZvWoSsciAV2fx0wXl3hlZRB1JjNGBbHAq198zpY9uh8=; b=jElErmsPR84n8OqKdO8DZBfpe4JpenrbRac4CudnJkoVBJF5EqTo2HBs whLMNviWVYtSpKTBvnAtn+X7ByVIHZ8NRPOF8hPpBuqXUDJFlE54d+oj6 E1pyI3UlkqDBR33zKOzwJwAlu9UNFr89oonzfasieZMc518WlZ4Dv99EB sTOkvAwZXJswaqhWBFwPosMJx4ayoSP/YTYTsMygvNHd8qWVFwnNRuNLa Ctk29C8TxgkNys7PeeGzSDQPmp3A2pPrAtO52R+msc2JxRI4HqT0h9k+Z U7iO6wjJm73p68BWXMk2kUKhrQZYuE+Qghd3bBrCpTjpl7/7sYG1Ui/jm Q==; IronPort-SDR: CBleSRzYtCpZgYlA0efSbyVWIVKmXBw9FQPIyttPV+JVq2zGT7T4CZCi9k2UuU4ZD7P2WT0DT2 9fOKcvj6T7/mMXNpXYB8Lnoeyz+hTFa7TNp2gr3kEEL+vDKOedRKRXWOGYJXPNdxdVPNM9pOi+ 3GR/8XElMVFTtpdFtWIe2wN3EmQ5s+D1sDnub3j4A4ZqihzXWYOpSpbBM1YEAtG0Rl/0+RJ1BL dvX18A2K7JmYkOHe0GFQxIuoWlhjjG/C+CDMkgc8e3CroTih/XkjNvXbKbsuAMs2rTlhHXKqOP XHY= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713900" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:18 +0800 IronPort-SDR: XBEkyK/op4e3yaSpCPFZ9QExkOQM7SkYc007mWPBRkN/Cda/NbouL5EmnJdmzxThBXuKv2hpeO 3jqW5oEfBCIu3FALg3TYHwTppj3tYOYERtEzjiAqilnydcYgeQKAVCo7dYUkTe0yw0gIoynHIq 3d3xZYIOEcX+PT+E8r8i+yd3YfjufHT/p9S0MwYpZIm7wZHfZ3AnAaPdmhAh9gd3IzpT88bweZ pQdxWWZHq7nVeZpbpf/vLkSXLa8g3tSyf1xZLWEwHsXt8u02gzbrJxyGNqP9yj/hGmVCgSa0Pq QgC4abB3tTLTS/5wEDRwPvC4 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:49 -0700 IronPort-SDR: 5HoZimTPv/uzDdmBK5jhf4u8iH8C+v8//HP0GxTZnELk5wmZqtR91MdOK1PCZQsGvUFm1lSMS/ pIGHQ28lWaCibXfqYmVtbqM7YS80W+whHkYmKujeCaRBlMRyeqY5huK3sXOBwjNla4Sw5mlYUa FVf0vF+l2zakFNTleOAu1xfiPQpVIzlJwvx3dBdGwaHIcMlyCXHsQi8SW6Ax7gPktJrLwFO0Zf 9CrZHh2b6jhreE2AD/cAVuKAywJIeX3A0jkadQRP7C7UwT8F6+OcMb+gPov5mG0WTBYeClY8ke wP8= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:17 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 01/14] docs: Add device tree bindings for SBI PMU extension Date: Fri, 19 Mar 2021 15:12:52 -0700 Message-Id: <20210319221305.2138412-2-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221331_350208_68C89DC1 X-CRM114-Status: GOOD ( 20.09 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: SBI PMU extension requires a firmware to be aware of the event to counter/mhpmevent mappings supported by the hardware. One approach is to encode that information in the device tree. Define a device tree binding that allows a hardware to describe all the PMU mappings required in concise format. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org SBI PMU extension requires a firmware to be aware of the event to counter/mhpmevent mappings supported by the hardware. One approach is to encode that information in the device tree. Define a device tree binding that allows a hardware to describe all the PMU mappings required in concise format. Signed-off-by: Atish Patra --- docs/pmu_support.md | 83 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 docs/pmu_support.md diff --git a/docs/pmu_support.md b/docs/pmu_support.md new file mode 100644 index 000000000000..8535a1dccbeb --- /dev/null +++ b/docs/pmu_support.md @@ -0,0 +1,83 @@ +OpenSBI SBI PMU extension support +================================== +SBI PMU extension supports allow supervisor software to configure/start/stop +any performance counter at anytime. Thus, an user can leverage full +capability of performance analysis tools such as perf if SBI PMU extension is +enabled. The OpenSBI implementation makes the following assumptions about the +hardware platform. + + * MCOUNTINHIBIT CSR must be implemented in the hardware. Otherwise, SBI PMU +extension will not be enabled. + + * The platform must provide information about PMU event to counter mapping +via device tree or platform specific hooks. Otherwise, SBI PMU extension will +not be enabled. + + * The platforms should provide information about the PMU event selector values +that should be encoded in the expected value of MHPMEVENTx while configuring +MHPMCOUNTERx for that specific event. This can be done via a device tree or +platform specific hooks. The exact value to be written to he MHPMEVENTx is +completely platform specific. Generic platform writes a default value to +the MHPMEVENTx CSR where is formatted as described below. +``` + xyz[0:19] : event_idx + xyz[20:XLEN] : event_data[0:(XLEN-20)] + +``` + +SBI PMU Device Tree Bindings +---------------------------- + +Platforms may choose to describe PMU event selector and event to counter mapping +values via device tree. The following sections describes the PMU DT node +bindings in details. + +* **compatible** (Mandatory) - The compatible string of SBI PMU device tree node. +This DT property must have the value **riscv,pmu**. + +* **opensbi,event-to-mhpmevent**(Optional) - It represents an ONE-to-ONE mapping +between a PMU event and the event selector value that platform expects to be +written to the MHPMEVENTx CSR for that event. The mapping is encoded in a +table format where each row represents an event. The first column represent the +event idx where the 2nd & 3rd column represent the event selector value that +should be encoded in the expected value to be written in MHPMEVENTx. +This property shouldn't encode any raw hardware event. + +* **opensbi,event-to-counters**(Optional) - It represents a MANY-to-MANY +mapping between a range of events and all the MHPMCOUNTERx in a bitmap format +that can be used to monitor these range of events. The information is encoded in +a table format where each row represent a certain range of events and +corresponding counters. The first column represents starting of the pmu event id +and 2nd column represents the end of the pmu event id. The third column +represent a bitmap of all the MHPMCOUNTERx. This property is mandatory if +event-to-mhpmevent is present. Otherwise, it can be omitted. This property +shouldn't encode any raw event. + +* **opensbi,raw-event-to-counters**(Optional) - It represents an ONE-to-MANY +mapping between a raw event and all the MHPMCOUNTERx in a bitmap format that can +be used to monitor that raw event. The information is encoded in a table format +where each raw represent a specific raw event. The first column stores the +expected event selector value that should be encoded in the expected value to be +written in MHPMEVENTx. The second column stores a bitmap of all the MHPMCOUNTERx +that can be used for monitoring the specified event. + +*Note:* A platform may choose to provide the mapping between event & counters +via platform hooks rather than the device tree. + +### Example + +``` +pmu { + compatible = "riscv,pmu"; + interrupts = <0x100>; + interrupt-parent = <&plic> + opensbi,event-to-mhpmevent = <0x0000B 0x0000 0x0001>, + opensbi,event-to-counters = <0x00001 0x00001 0x00000001>, + <0x00002 0x00002 0x00000004>, + <0x00003 0x0000A 0x00000ff8>, + <0x10000 0x10033 0x000ff000>, + opensbi,raw-event-to-counters = <0x0000 0x0002 0x00000f8>, + <0x0000 0x0003 0x00000ff0>, +}; + +``` From patchwork Fri Mar 19 22:12:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456049 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=QfbcNiT4; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=GQ/aDLW1; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J7v0g56z9sSC for ; Sat, 20 Mar 2021 09:13:47 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=iXp2KdBg09+rtnKfPaCs5CtF6UMXyBx7Rl4ADKxEcbQ=; b=QfbcNiT4lyRiMxM0yx4cZaTia W+J/QXiW4b+sA6cgY1naWTiF4emsK1Ol44QLPT9boexQky9hchcg92RLwzm1z2uABFtfWn2LZpJGk kYO26hpzgs7Zse/Fp8gICdIKrxyO8CWd764blNAP5INfzcl+MV2irSHMK6gLVoZlR1myM+9HjEUOq aFYtMJaNpIjSDaIKJpEjOTBr8rclXMBMDJ7pLsE0MUmbyIkH4XqSwQD8q1M/EG1FGAYZhj6fqAMI5 CvRmEyDO2sYaV310yJ77+D0DQjMc9UsEh8qAVlx92kZ0w8ByyisbhTDmSIBB0QgGPwsoadDahCmnw 1CueMv8gA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNE-008FN9-Vq; Fri, 19 Mar 2021 22:13:41 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNN5-008FKT-SI for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192012; x=1647728012; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=88mkeT0cUiZeDamsw6IhN4Eg7XH6kdMXTQMs2cPRMEY=; b=GQ/aDLW1ild88qKVCg80G27m+vhUztt6xYuGFS94Nja20PopiGUdpGJg lwBJG+LTnGX8YLKAwrRpwiwqVJVPXcQ2VwJZ5XmUgqu6Ixp19RBS7M1Ss d2cap6SZLYu16P977M+df9yYtXs4AmUWZAI+0Gkw2UwNeLd7MJkyMKAjx UcFl1UZGQblGOWRpXtSUjVK+u/tWwcz+kTsIyXrg2s8LXlXa3brn1bcMl wMAE8TPncixH8lc9RZN5YK7huRGWD94ejgSocjQ2A9ux8dWBiJEJr8WA+ jvjuyLoy46mPj/id0Pzr8DXgd9JFG9VVIluH7rivAreBJz3QezqnPks/w Q==; IronPort-SDR: jnv96TajT/eN/5EmgW1+MIdHKDk+TJT2zCd985XrcisPfB9tQaPXMDhmaIx7O2u127rQdJTZEm DQfjqjCOAlyiY1ZkxHbBC49uh1OeXp8E7jiTlQobL/4WlAfs9/FuTVI6+vfZQEoH+4rLJr77jj dhDjjF+hhJdVTLZleKQdXGRXxFzKFnpy+JBYwMFLem+5thIziAAk5OI83+ek4WrZSKfQRXx+aD 2iB9+kIVe9eBUNwx2l/NuZFRsN1OeBZDgfBhLnj4uFkbsPR7Qm4OXNmPIpAkaWXJ8EIRf4T39G dn0= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713901" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:18 +0800 IronPort-SDR: ibOoMHxeML6mQHRD3xa2ZF6r6jtQMZs9HsOCnSz82Y8E2gfrb3xQGfqaHikjTdJXUDkvUAS8eK RNmWpgFcI2xFe41BFEf/0ast338qhLZtRDZxckiVhvphfPRliTP65/vcMJKB1aeW2OQtAg5kT+ Qvq9SYIs3DiQ2KJHJNy+QQR8pOmGGZF83QS9fhD0SmDIsExQ23SSAfwGT2itgcEdy20nb+iRfn F2cblLARd0+Oo7HHwOj10glL3/JwRKnAwBTQ7K+L5E19u9cKwlF2Sr04NJVcPNYiG+QDJTK7Uq RInrEYTm6+b1Bbl+UVxeaOY3 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:50 -0700 IronPort-SDR: 7g777qW/cTIl2Esqsp2QB1ZUFiodUxBfRE+doJwub6mOgvb3cfuC8ET9V8IbFlVdoYTJ57Aevd ryabS9ygb/b6sAHOVEcIKAxKa4P0xCN/S0GBuXxzywuJ/SexebNYZIT6T3pFf2Cd2ZuaVZ7FKh YzBkq5ea8gTNRS7JHnv0DDz1+Jot1BGcvdnv9Sp4iyaYUz4Ikku1yefAwIQeR4wNvCifpNeMhZ EzZlqxabVTxKe5IrhLprLoOh/3U94ULvzOxZmorOb331ohL97oFuHBmb4a03iSNve3p26T7o7l uq8= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:18 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 02/14] lib: sbi: Detect mcountinihibit support at runtime Date: Fri, 19 Mar 2021 15:12:53 -0700 Message-Id: <20210319221305.2138412-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221332_315324_3F7D711E X-CRM114-Status: GOOD ( 12.24 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: RISC-V ISA specification v1.11 defined mcountinhibit CSR that allows software to stop any counter from incrementing. The SBI PMU extension depends on this CSR support in hardware. Define mcountinhibit as a hart specific feature and detect it at runtime. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org RISC-V ISA specification v1.11 defined mcountinhibit CSR that allows software to stop any counter from incrementing. The SBI PMU extension depends on this CSR support in hardware. Define mcountinhibit as a hart specific feature and detect it at runtime. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- include/sbi/sbi_hart.h | 4 +++- lib/sbi/sbi_hart.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 031c7b08a815..9e317c52008c 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -18,8 +18,10 @@ enum sbi_hart_features { SBI_HART_HAS_SCOUNTEREN = (1 << 0), /** Hart has M-mode counter enable */ SBI_HART_HAS_MCOUNTEREN = (1 << 1), + /** Hart has counter inhibit CSR */ + SBI_HART_HAS_MCOUNTINHIBIT = (1 << 2), /** HART has timer csr implementation in hardware */ - SBI_HART_HAS_TIME = (1 << 2), + SBI_HART_HAS_TIME = (1 << 3), /** Last index of Hart features*/ SBI_HART_HAS_LAST_FEATURE = SBI_HART_HAS_TIME, diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index d91b08cf1cec..0b3bb6237182 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -259,6 +259,9 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature) case SBI_HART_HAS_MCOUNTEREN: fstr = "mcounteren"; break; + case SBI_HART_HAS_MCOUNTINHIBIT: + fstr = "mcountinhibit"; + break; case SBI_HART_HAS_TIME: fstr = "time"; break; @@ -423,6 +426,15 @@ __mhpm_skip: hfeatures->features |= SBI_HART_HAS_MCOUNTEREN; } + /* Detect if hart supports MCOUNTINHIBIT feature */ + trap.cause = 0; + val = csr_read_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap); + if (!trap.cause) { + csr_write_allowed(CSR_MCOUNTINHIBIT, (unsigned long)&trap, val); + if (!trap.cause) + hfeatures->features |= SBI_HART_HAS_MCOUNTINHIBIT; + } + /* Detect if hart supports time CSR */ trap.cause = 0; csr_read_allowed(CSR_TIME, (unsigned long)&trap); From patchwork Fri Mar 19 22:12:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456050 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=Tus9j/1u; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=BRIrCKOG; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J7x1XCkz9sVS for ; Sat, 20 Mar 2021 09:13:49 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=YmAhN0Pcq+7X5K+QlbpfkU+MVJNz9f7MPlgm4MsjNtQ=; b=Tus9j/1u197gIDGd575BEH/2A FQvOmRU16ukR0/r1DLZpz/MpHh1I9VTveYuZr/hcRdnZl8rZxCoBNZfhn79XWYLoQiMJ95qYUcwah dvpqrGnbAaeIFRAWCVrc+n3LBs6/fYnmzTBbsivWzB0jyH7Ve1w5yTvaWt/kz8CWGREaGdXeDf6xz +ETjJRDKpVo3eL8urltx2nxhJScyG/8LqJAvTEhbBfTUM1m5Ux0KR8lY7m4uahA3WRRWK37piR/LO H+xdjB4t/+sEBAIO6ZHnrlSjY7RdJ7ufMpdEhv/joGf1I7unToKWeQ5SHfRkfXIpjq3zyehmxXqhz Fn3SA8ziw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNG-008FOA-Tm; Fri, 19 Mar 2021 22:13:43 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNN8-008FJO-7G for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192015; x=1647728015; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NaQck0m8jIHi2qlslesrxYQgzgjCxH03CfDN91j2jYE=; b=BRIrCKOGLgTcaTMVYj+Zf1klpjfSs7ChBZQ//7PlUIWjKR5vkhCLWvKB iTqPUtTA1lE2dcyH0SbM9dFx9e2xPGrjHpX1pXZ8CxVV6zIg8VVCiXl8t a1609q43bBRcw8wEX+kOaR68oyhwKBaOemHYrb+bF6Dg1mOJObbiokCb2 imFiXGm/HKT0uIuAeo5oaQBAlUN357ZOJi1kPnmEv0YghDDR9cUJN2E02 Dex+PUif8TZWlVFxJMdfjjl9/A1HTYhmfZJryCv7BhjaHCAw6MdR9u8Ri 6iVf3JT4Fwv50+pvL2OWMJ8Q1qZcG1ahnBNRmls5Wgh5HMRlaHUOWCY3Y A==; IronPort-SDR: nIF56HwPXaLHic52LC7vN8ULWtWsROMnoWYaTd+VpITbFvatrFMLJFdjF2t66WCm5Qa4Yx7uwD OTQg+I0aFcE4LMFUMBApzqA9+68zRblG/XSsHCSc2qM8PwQplaQ13wpxfEIx0flbT3lLYm4F8L /KLdtrhDOvq9cDYpybPzCVp6BDEtZgtaPRXZTNfKv82qDQ01TUHfomsBCWWyf5F2qUwS6SFGzc sWzkY8NHvFEoGQTz0hglOW99g54D7P8UY7I0FDQ6IKUYSlF/sFRRsCS9lWzMI/RwAuGwQbRT1s Bz0= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713902" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:19 +0800 IronPort-SDR: bFKthvrqdsIiHWih8b7YOzemZwLx7/M1yz4U2Ck+g669IEWtDL9A0ozjXhglVLlmgcf/Slf8mK kDS4S6RtOupt7q7Fby6J2uw7hjkon5o22J+4BPW49v57lD2qcGamR1ZyH8XD/KQh8U5/sCwef3 yPRH6i8SQ6ewSsnRbWsncYyoW19Py2nUdKrJAtbpjJ2sbnTFhNpiZtyuL3zDDQ8G/zbGBAeHsl wOjtOc/VTy6YhBAvYB1mnWxO+jG4bAASlCyHCFU5pLR5RzPTLTg9s0UuN9AfSHlLFqZwM9Ukmh GKqzBvV/UpYDLRXMt/QT5lgq Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:50 -0700 IronPort-SDR: bWDCvrWZVILQKYspJN8ubr3rjtvEOr2vpotIc9DOM97RmgEOsEu1KAM828fno2UlGGhwWz9nAI pm9LRmk0jbhLzOn1t7ZSCkjwOojdNpVUapiUVF8jsmAXltRRDYwEYVuw/ob83S4hmf3XM/U7/R Z639ugqCl4FEd6uDKjWE1W4wQV8QBLAL0HSJdW1Or1ngYlwwlUqJx72iwoCNrQl0LBWJ0u0XLG XFlXrbVGZ4oZoi3IANYC0QtMSnwUG9sJKXurML+CT6cfHUE1j/XcuLW2ekAh+KVcqwYAcMsQSv +Fc= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:18 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 03/14] lib: sbi: Remove stray '\' character Date: Fri, 19 Mar 2021 15:12:54 -0700 Message-Id: <20210319221305.2138412-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221334_699038_4F4DF1EE X-CRM114-Status: GOOD ( 10.82 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Signed-off-by: Atish Patra --- lib/sbi/sbi_hart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 0b3bb6237182..ee11b2133d05 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -320, 7 +320, 7 @@ static unsigned long hart_pmp_get_all [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Atish Patra Reviewed-by: Anup Patel Reviewed-by: Xiang W --- lib/sbi/sbi_hart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 0b3bb6237182..ee11b2133d05 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -320,7 +320,7 @@ static unsigned long hart_pmp_get_allowed_addr(void) unsigned long val = 0; struct sbi_trap_info trap = {0}; - csr_write_allowed(CSR_PMPADDR0, (ulong)&trap, PMP_ADDR_MASK); \ + csr_write_allowed(CSR_PMPADDR0, (ulong)&trap, PMP_ADDR_MASK); if (!trap.cause) { val = csr_read_allowed(CSR_PMPADDR0, (ulong)&trap); if (trap.cause) From patchwork Fri Mar 19 22:12:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456051 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=c7T+6H5S; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=kN1Hcskz; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J830wkdz9sSC for ; Sat, 20 Mar 2021 09:13:55 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=5MPIWckApJ0D0YLmw5qtKBKsYpqn2iAfWPhDFoeMb4g=; b=c7T+6H5S8151hRS3sgo/7vvl1 +OpfRyzyr+GvQEX/mGlj3ufBGsZHcjQ7QSCWXG8oDplwfqKlIcur6OULHb44hiiXWi6fbCTm5qPlr esSkVkZXvJ1Rrkuhinf6GEv8o9zguGB4cOHUT7zqQkO2dnYPy82WvHKekWuTmY2Dt9yvQPa89MUcO cu4xtlekCTnP+BCJs5W8cDR8Wk3rNdeDjhtNAXzfPYsoQ/RZKHqR7r2iYG+po0266loVpg7OT4tEa 7UDFAcnxMaTd0WLkNzM1WU7DjYoIwNpp9NJ0BjAvkjw3qfpzElmy/+esn9hRFmcywu9rEuNKgm19C w9wQn5MEQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNP-008FRC-7g; Fri, 19 Mar 2021 22:13:51 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNN8-008FKT-Mp for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192015; x=1647728015; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0SVu7Jv9j059b3wv3/WlmT0/8snPgMvlyKhK5nsBzeY=; b=kN1Hcskz1Tc2PL6Kf44euPjoG3DVxqO339RuWajwgkayRFnYM4RLbol8 BNohZQf8GF7vPJNEaLZFRl7mNgAtBIWNbzQNzBBkCRdFTNgrmh8SNVOQU GJyN+AEqw8zwgeQv2L5pi2pTRrk1pfCbQs/3Q39THmyqtNye5yLqbInny VaUJhP57/D9FeY53TGIUT/hMNnyqgrbVmuaqR6T+1ZO4nlai/Szp5cYlY pMLs0464f4cBHQnoq1b84WLBU+FhsQXlDsw/q5OUewlYnRzvRalC645U2 oeugXxxBFKZhnNpKocj7xnQ5RhRJuOM0YXFRBQ7yQwm8zD+uzX3SaLJxK g==; IronPort-SDR: oc91F8icoGK9kxjmdTjPHq/OlBAyeuPUUWQ4NsnbhkmYl5U+3ii9dQjii8of+NbvCmkI4OkupR lR9+AIrNaHbgxPr9QX5KbTdqwuh1Rk32eyXdCXXPLwpi4jE2axOk3oTI9YoDBVpqx+yPmhO0q9 DIqklId4I26NwlUH+VrdAY0m33LWoPqPuYHom78A3zq7pQEE19xAPqLCjWhbXQaPRhdYERs4SC znE7absNOzi6DbWW27E2nbVZx+0uzGCeiBCe85gzQK32G4SoYao64Z1YqMyFepO69SU2KBOLPi +go= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713903" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:19 +0800 IronPort-SDR: kdPZ4gxlcJT+5Dr1dB7niiLeSBLUMJjT0VThprkmSrDpbnzbL/5domFvswj7/claQgJzTTYNxM LDSfhvGUjOQiZEWDxJl6bUr9iz/tfqx2YbEPHW6M2nUED2JTbmu8HXje+3hfIsshZev3y2sw6/ KtYziQWFICzf7kCprBeQ6B8kIejn9jxz74rP+RARVn6JAxevzsLKyuaCeIIXWc6Qn2JlOscz0E IwcCdIDyPYvDGOgrWcVsbkHVzXiz9dQi6hdL8LL5XP4yPdiCgEt7Q1qyFNwk+QGSlAiXdT2E3K TNV7rwOJnUP3hP6sHowkyUBk Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:50 -0700 IronPort-SDR: qI9IT0b1oPwFHDH8Q7REKFcAQV8mAZ4S+GBqwZ1Fd0lHnSgYPaT+/8vIf30QcHeS9J5NKG/Uys h22dkMn3mXL321zTcFxbLl9uaPXwXqzfR/kzdY4Ij95IHsDqWdWniemxhS2eWpPbu9auj3ISSx zv5XNUd7ghHyLXNlgd8bTFH6MlB5COcp/Njwfxj1RC3L4pU+zON8Xrg0qyGXLV5NbB1VjXUl+u kRN5cZqGrnNidO3Ur5TFYPnuDsIj75/NuFcqihoNB8uQVfkRUAHU0xqNiyTHwzLl8zhOiCOhrx tBo= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:18 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 04/14] lib: sbi: Detect number of bits implemented in mhpmcounter Date: Fri, 19 Mar 2021 15:12:55 -0700 Message-Id: <20210319221305.2138412-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221335_265283_B2EDACF4 X-CRM114-Status: GOOD ( 15.72 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: RISC-V privilege specification allows the implementation to have less than 64 bits. Add a function to detect the number of implemented bits in mhpmcounter dynamically at runtime. Signed-off-by: Atish Patra --- include/sbi/sbi_hart.h | 1 + lib/sbi/sbi_hart.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org RISC-V privilege specification allows the implementation to have less than 64 bits. Add a function to detect the number of implemented bits in mhpmcounter dynamically at runtime. Signed-off-by: Atish Patra --- include/sbi/sbi_hart.h | 1 + lib/sbi/sbi_hart.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 9e317c52008c..5f23595ccb27 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -44,6 +44,7 @@ void sbi_hart_delegation_dump(struct sbi_scratch *scratch, unsigned int sbi_hart_pmp_count(struct sbi_scratch *scratch); unsigned long sbi_hart_pmp_granularity(struct sbi_scratch *scratch); unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch); +unsigned int sbi_hart_pmu_event_bits(struct sbi_scratch *scratch); int sbi_hart_pmp_configure(struct sbi_scratch *scratch); bool sbi_hart_has_feature(struct sbi_scratch *scratch, unsigned long feature); void sbi_hart_get_features_str(struct sbi_scratch *scratch, diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index ee11b2133d05..006ec830d86c 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -33,6 +33,7 @@ struct hart_features { unsigned int pmp_addr_bits; unsigned long pmp_gran; unsigned int mhpm_count; + unsigned int pmu_bits; }; static unsigned long hart_features_offset; @@ -177,6 +178,14 @@ unsigned int sbi_hart_pmp_addrbits(struct sbi_scratch *scratch) return hfeatures->pmp_addr_bits; } +unsigned int sbi_hart_pmu_event_bits(struct sbi_scratch *scratch) +{ + struct hart_features *hfeatures = + sbi_scratch_offset_ptr(scratch, hart_features_offset); + + return hfeatures->pmu_bits; +} + int sbi_hart_pmp_configure(struct sbi_scratch *scratch) { struct sbi_domain_memregion *reg; @@ -330,6 +339,37 @@ static unsigned long hart_pmp_get_allowed_addr(void) return val; } +static int hart_pmu_get_allowed_bits(void) +{ + unsigned long val = ~(0UL); + struct sbi_trap_info trap = {0}; + int num_bits = 0; + + /** + * It is assumed that platforms will implement same number of bits for + * all the performance counters including mcycle/minstret. + */ + csr_write_allowed(CSR_MHPMCOUNTER3, (ulong)&trap, val); + if (!trap.cause) { + val = csr_read_allowed(CSR_MHPMCOUNTER3, (ulong)&trap); + if (trap.cause) + num_bits = 0; + } + num_bits = __fls(val) + 1; +#if __riscv_xlen == 32 + csr_write_allowed(CSR_MHPMCOUNTER3H, (ulong)&trap, val); + if (!trap.cause) { + val = csr_read_allowed(CSR_MHPMCOUNTER3H, (ulong)&trap); + if (trap.cause) + num_bits = 0; + } + num_bits = __fls(val) + 1; + +#endif + + return num_bits; +} + static void hart_detect_features(struct sbi_scratch *scratch) { struct sbi_trap_info trap = {0}; @@ -394,10 +434,19 @@ static void hart_detect_features(struct sbi_scratch *scratch) __pmp_skip: /* Detect number of MHPM counters */ + trap.cause = 0; __check_csr(CSR_MHPMCOUNTER3, 0, 1UL, mhpm_count, __mhpm_skip); + hfeatures->pmu_bits = hart_pmu_get_allowed_bits(); + __check_csr_4(CSR_MHPMCOUNTER4, 0, 1UL, mhpm_count, __mhpm_skip); __check_csr_8(CSR_MHPMCOUNTER8, 0, 1UL, mhpm_count, __mhpm_skip); __check_csr_16(CSR_MHPMCOUNTER16, 0, 1UL, mhpm_count, __mhpm_skip); + + /** + * No need to check for MHPMCOUNTERH for RV32 as they are expected to be + * implemented if MHPMCOUNTER is implemented. + */ + __mhpm_skip: #undef __check_csr_64 From patchwork Fri Mar 19 22:12:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456052 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=Uqhui+xF; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=Sm6sf8PJ; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J894x26z9sSC for ; Sat, 20 Mar 2021 09:14:01 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=WXcIKMJSDfmRsmXn8NlnZSJspRl/1KR6+q62XSFBIQw=; b=Uqhui+xF7umhLhiUXVGLt20Fa NsOd8NO0WrsmnvN+2y0jnFnBUGnhqtF3Ex+482QaZiN++pznPOQX9lEz0i9gd1+vrK6Ses132vkYw CjBodtlXuNmmAIN1nCY9gIqYglBx0X3eTpOHR8VGyNWMS81phAbEqN64devlV165xawR8w/IZPeg5 V/LJDAJa7hB70lLsf79JSQ7lVk2G+NLdkBNMrp06F9vwc8NuFxHAeWFndMtnPU9yr0/mhqwodOeP1 j2R1o3uOuIkbQQEMMe2XNXQ8CeewODia4EXYx1HP0fXb30I6bGqmM1rcZT2IzyncBNRpuC+AAexFe SryTy4Ycw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNR-008FSe-LI; Fri, 19 Mar 2021 22:13:55 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNN9-008FLJ-72 for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192016; x=1647728016; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ujDSgN4feqy2/uB5rGwVFIip+ELTCzX9KSl3F3tPUDI=; b=Sm6sf8PJLNJLAZKMOFhrqrLCmLLJ1bNOFGH1axGw3zKLNzTzEN5h3Di/ GsIqKTOQRVo1LywhHndnq7EFqWCFLXedb1GylpwIIzZbD9+a2QMKdwx/1 8yUogorFfwxyjvhFe94bi+Bsyj03Ck86Zq1AgKhWLLtbNCmBfmBXjVwWg BsqiOc48u6PKmAHTLhzcakv+gPWv5aCJrOPmmQOezzeTeYA4aUwv9cAX/ 2Xlt+pbiZThEmF1nOYRSaBKQsUjp71xIXGVuyd+GstOtawIWBC45I5pHR ODfhJNPjQqebserEq5x9a6rqrnXvTKgvxHYpCXH8/7lsG16nq7bl8eqvz A==; IronPort-SDR: rlAc0I2lMWPbxrkf7u//MqUgfKnufj3Xxv+IvYBcO1JYWvXUKpSsA/vgo0OElHZNkF/01sdJ2j RjcT0D+BAfzu1d2bZxcMw4qcsxzJLUbPshdiLoyGW7eXQVsvN3oeWS+HzVMW9A89VcYz7MM3jt hH8mtm2fpXfRuE/CwaoPahE5YAe/QQVfGhyBvmJ96bZ6fwuF4ZYo1CmR8NT468Or5SB1i+VejJ ibstWV48QMVD8p87N9hAcOaFp9zarYkzp0vPgKEuoN84X/Md0FWY4Mv5y8zSZ3f8t6M/Dy/D5m utU= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713904" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:19 +0800 IronPort-SDR: KZO7iSuCj0P0DAUuoMu1ENkHvsllkN6wgs5zw5vKaKmkIPzU1cP5S5QiUlqrcvF2J+5KUBcQxR CjVLLe/bAyoSLSPEXn6ZOSOWlUuEXFPQ+jb/QLxmmHCtHth9VlktpvZ4iR9PEpXe2kZjcYVFZn aekFzwGyKwlqDEqs0M8+xjsdp5UiRXofaFlIDYF66bEocagYuPIpDqvIzCzEwixZn+hB3DMArH EH27AnrQsOG7HYafFdl3B33wIhJU9xc/5I4ANaZoAsuXO1tvF84hUFpi0vkPds7WM14e7NcLp7 RWI8d8D5axTc4zgjgrTcFMKZ Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:50 -0700 IronPort-SDR: HtoUFIAUSa6CJYMpd2R04o/DIQSCNVKTpgAMvXu/yod2VBFyZfU7YSOXNlElLP1R8XqXLuN6aV Sfre7jB2wZL415DP0ak8V33hpfp54pKkRKckcUzPT2AcdYs7QxVyxfutpOrikP0FZfmEi0XY9C 7grtBwyUV9UV0FvrqevZqOCPU33Zyc3ZbzZ8OfGksD0OwitaswyQuf7s9Uu4Nh90VAu/6be1Ww C4LyzFsSEUQ1Ve6BuaUQi9LnxW8fkdEFJhIRPHPUc+AEaFEJzSgTabBcIEF/7KnCtabb1w97jM nWM= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:18 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 05/14] lib: sbi: Disable m/scounteren & enable mcountinhibit Date: Fri, 19 Mar 2021 15:12:56 -0700 Message-Id: <20210319221305.2138412-6-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221335_795131_7AB1299B X-CRM114-Status: GOOD ( 12.62 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Currently, all bits in mcountern are enabled unconditionally at boot time. With SBI PMU extension, this should enabled only during performance monitoring for a particular event except the TM bit. Howe [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently, all bits in mcountern are enabled unconditionally at boot time. With SBI PMU extension, this should enabled only during performance monitoring for a particular event except the TM bit. However, this is done only if mcountinhibit is implemented because the supervisor mode can not start/stop any event without mcountinhibit. Similarly, supervisor should take care enabling scounteren which allows U-mode to access pmu counters. Disable all bits in scounteren in M-mode. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- lib/sbi/sbi_hart.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index 006ec830d86c..b87d1dbedc0b 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -51,12 +51,26 @@ static void mstatus_init(struct sbi_scratch *scratch) csr_write(CSR_MSTATUS, mstatus_val); - /* Enable user/supervisor use of perf counters */ + /* Disable user mode usage of perf counters */ if (misa_extension('S') && sbi_hart_has_feature(scratch, SBI_HART_HAS_SCOUNTEREN)) - csr_write(CSR_SCOUNTEREN, -1); - if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN)) - csr_write(CSR_MCOUNTEREN, -1); + csr_write(CSR_SCOUNTEREN, 0); + + if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTEREN)) { + if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) + /** + * Just enable TM bit now. All other counters will be + * enabled at runtime after S-mode request + */ + csr_write(CSR_MCOUNTEREN, 2); + else + /* Supervisor mode usage are enabled by default */ + csr_write(CSR_MCOUNTEREN, -1); + } + + /* Counters will start running at runtime after S-mode request */ + if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) + csr_write(CSR_MCOUNTINHIBIT, -1); /* Disable all interrupts */ csr_write(CSR_MIE, 0); From patchwork Fri Mar 19 22:12:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=ftDyoFOZ; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=fAGm7rVT; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J8C4VH5z9sSC for ; Sat, 20 Mar 2021 09:14:03 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=bFy/gp2m/aewgwS0X5yqc0fWFitgU7ptQperB6dBd6w=; b=ftDyoFOZ4luxRz0snflOjM5jJ kn7o4uFILkzNMeSg5E5OW4LJZIL6XwgIeVyb42IP01Q7Idv8jpyGlG1/3WtJE/Y3+6PB0+uYTUDpJ csF99hY2Otr8Q1O3phMvnWkfmvSjRW3ROD5E7xnahVueZFYH6nivNYKUT9blwtIm7KG1IIHJ/sAaa LMC8BWI1vpPePkAikKy9e4K4WsvOVtWjPuOPZ6IMJZJwaSCfgUI1dFmKMgyoYCeNjqMHIzUyacEmb aIBbaBOaPMCh1oABWXSqyJ2W/uXuDSYYLj8RdN92jYOa/AdsyjvrRIPPGBXAqW6W9ONTQ3yNKChas KdBoRy0hg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNY-008FU9-1z; Fri, 19 Mar 2021 22:14:00 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNA-008FJO-Sy for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192018; x=1647728018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mf5iWPVP/UAohNrh/WDMWln38BQDIH32Yj7FmfbD600=; b=fAGm7rVTSQXCzICq1vBIv4kSJWR6mgU3+Z5D+B+OQvJgHy1222smkXaQ I0nMhtQglnQ/aXjkm4tPdjrNzf2v5PuYWKlDyv1ckRs8azOl8n+4TLNbv oT7/HpEtUIu9pI6Hzv6XeBtIjzO2i9kSbfXlXAUGCZ1E7SC0hjyYS8Xzy fPymCxzuk7YX4P++OWwxgkbWxm6lf16HvM+QLBIKU8Ff9C1gmA7HUHDp1 WMDLO5GiGJyukMECEO5YiGyHw3WYFY8L+vpqF61de5YgFo01gSTvu9dwb MEyo1SwAn2/V6+Qxg440rFVWfRzEv00qYa0vVEcZFMZxxh8HriEOucS2f w==; IronPort-SDR: STVo/YVjq71bV+dCWUaF9X4/RLiiU6XCTzYeOW4bMqgLPLx1a/ysLudeSJTmK8GZE4iShAP0o8 NoS3T87b1op8PaeOd0pMDmL+V/5FY6iWOgtBXYhV1ftto/4z++TNC6RdJ+sVCNqVoxUANOhULG FW0D1sF6ZzbjSVA0xS9RSXieDmuxGTwA/irekzCq10YBAgE/aXAY0+G9wKN/bqyE4NzODER7w6 QEO842alOD4G/TyApm2XSaW/ThLGaIWhVqxhW3z/ZlpvKkA37EYA6afK842x632HwlJwGNy49U Bu4= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713905" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:19 +0800 IronPort-SDR: slKdatcSm451osxXlynF+aSam42b5r7iKaIUO3LPvmRUJL4Wvi9rSo4xxZohPh94OCbVeMhJbj fYZNBIEf6Dn/Iwv/TTxuhDvD2LppZ+hrJYUCMr1GENCXFPMtpEZflY9mozXdozWjT2p6iz8QLN Z3sfMuR+DV+3hyTDHGce8rKwAVRJx3X6PaGLtj+nDkhkj6Kw8SePFjfw49rg6FhDmFU+pP5Q4w VPt5xgeTVXjfFE6qab+sU01VPaRKexfi/ela0DvpgRVZpJtkdsaSUrAd47iIOHDPwdJy4Wy8U4 kWGuYY7G7KsQMd1YBdj4+/IW Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:50 -0700 IronPort-SDR: eKp+pCyAj5bqKhPexdukRKsq/6LnxM7lv+w7NH12x8DuWBB9s8qM7aZ/rXih5KROvhLpO/G43L HT6PdHIbT+a5m6OGAXE/4KskPqQMWfE1TOJpwc8GivpGF6RrPAu+dpr3qvgqSzq4MBoSQ+4U03 q6wGeCiHslrX29v3uhuUXqVrhQBfA16tGAb949sKaovjLyCCGfwPgPFyMt5V4TW93S2f87p0D7 qVwFdk8BRB6sTafakrPfoTFkbZkm/kHyZLPeyP5pHnQqlPJfQLY0bNItHrCZvNYON+u/oKyYS7 KmA= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:19 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 06/14] include: Add a list empty check function Date: Fri, 19 Mar 2021 15:12:57 -0700 Message-Id: <20210319221305.2138412-7-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221339_299416_B045F75F X-CRM114-Status: GOOD ( 10.39 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Implement a list helper function that checks for empty lists. Signed-off-by: Atish Patra --- include/sbi/sbi_list.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/sbi/sbi_list.h b/include/sbi/sbi_list.h index 1174ad274c54..b1178dfc9b8e 100644 --- a/include/sbi/sbi_list.h +++ b/include/sbi/sbi_list.h @@ -43,6 +43,17 @@ static inline void __s [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Implement a list helper function that checks for empty lists. Signed-off-by: Atish Patra Reviewed-by: Anup Patel Reviewed-by: Xiang W --- include/sbi/sbi_list.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/include/sbi/sbi_list.h b/include/sbi/sbi_list.h index 1174ad274c54..b1178dfc9b8e 100644 --- a/include/sbi/sbi_list.h +++ b/include/sbi/sbi_list.h @@ -43,6 +43,17 @@ static inline void __sbi_list_add(struct sbi_dlist *new, next->prev = new; } +/** + * Checks if the list is empty or not. + * @param head List head + * + * Retruns TRUE if list is empty, FALSE otherwise. + */ +static inline bool sbi_list_empty(struct sbi_dlist *head) +{ + return head->next == head; +} + /** * Adds the new node after the given head. * @param new New node that needs to be added to list. From patchwork Fri Mar 19 22:12:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=gFcGSh7z; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=SARvbl8e; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J8J3dslz9sSC for ; Sat, 20 Mar 2021 09:14:08 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=oHaNm6Wrxnlf8hxtsN6U9u+sLGMRBr07XJn84uMfOBk=; b=gFcGSh7zBhGL6N3IAz8f8jwOc 1QWIqoY6dWsLG9rGW62hLxGKxEN91v3Y9UlehfMrgVA5lFhpmZ1PAakytHToSMZc8ql4sIvvnNqyz K3yz1KrBgSkJXrq57i/kyvX8rY2OQS9gNp0JKRGSlXrfcqrJ5jK4EvAeuuxj/h/nETF5gWkxnty2q /QDD8o0Zh9tJqUtWQodFdxw50uvN/Y1RqyU+AKQGbVoHD1qkXHI0iOJ2Kud3yeu5lFdbUbslpf2cy QvTU13JDzS8jIwC1eYbfEPCsPjXRu+DMFeZwGegYc4NlMkvd0xfgGSkXWQhFH46MuiKAANlzqlMjJ hVW7pEslg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNb-008FVc-Cg; Fri, 19 Mar 2021 22:14:03 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNND-008FKT-QJ for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192020; x=1647728020; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hJ4srI2ufbHGx+ydmvQHgBsKB9SOczhaO3dolPzfQ2Q=; b=SARvbl8e5e48QB/4/efSXQ4X39ijo9syJ4mXRmnHItl8Kr0dn8mWveDO oFVkpwpAGtnL9PHADnPP2tap4fB1i/x80GWOIXL+Rp/zVd/Vw+U2qbF+G DaKAeT522HqvkRILE4Fywg6R0tjL82l1kLQ9Sp/eZ9B0zbGFxEjdgmlif BVR+K+m3lPBczDyq7OF01RBogtIWyN2VYkp0YSNl9758X91qb6jsU9d9O k1CRSD5LVy+/mosS2nlUf4oxH6dl93yzz7v8rO0DRGbp5odU53Zksy7zu TWa83zFGNDTlp9SLaKSIct/naZvxODtV35uEi5B3TCWuL5SeHs21gIkD+ Q==; IronPort-SDR: 6ILoasCKm/26dwlA/Bt8jIAKZH8oIuBO/XL2tPcfw2jlWxuyZuxPBun4MHDxW9pVuOqv54XkaM dx+SeQmTBGFHJ45GR2x9XZU4MGvDUAR+e9Uz9B+l0rAVEv6fLlWgm/kNuHcOki1yvPqGP2PnVx +xQjBNIxEoo+RIYHwEavKmKQfh8lqp6a1/Kd+n2vLWwWdvQR535y26maKwh5pDSbptbt/skepq Po7+d3rC7ZxQbxLlITUTyOnztNpxM35BJeA0PUBlEjP8dk6J/o92PRaUnzRs+sa/uffRk0r9M7 rvY= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713907" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:19 +0800 IronPort-SDR: aIyRPyNXxtN1td342I5QE5PDhuJNPGyOlyAygSTNmtGEpkXCBDXOFDOjbg4lI2IJq6PTM98N57 PBF5P6vPwR/r/Y0FJMOMwRwrWTxiTH51U2HxWbMeaaZ9MReeQvrVVqeEvZS68sMvY9krNAM4QV S4g72Yw4x9i4QXeIPLnWTCR2CTPd5rGtHgLy/Zer63JV3AH2mPqlSszcLhT4yAGduDHBShA7ki lT02D0aYgVAsJfAWYx+Osugys35h+yuJkWWvg6SRideVkJaWS9V4A7Nk0Ud3zftn75mUHPkryn aUATwpMZTl/DGM0MotM/nGtI Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:51 -0700 IronPort-SDR: iwnPjB8sPtHmx1H4gWR5bdAugJahxacnTRw7Po27PVoQjHWfWfCpBdt87EZA/sJeYH+nzDCy1I Ri4/oKNJZ5JxZtXyoWR5rTaLmkx/7nXpmfp+V+TkzrlWEm4xUuxE6VlkjCspz6B7XK0s43XZq2 ILWjuJzmfHRyH+sq9ivFkvVzgCGCTKfh5rq7tBHHJubZtcHZK5pSbBoKVO55mPwD5WlFjwUp4N iC+ReAuWYtTJ/6RwWfOlti8pSzzCKWp3J26uCu0yTMztIobZR+iuOacwm54Vxoc/+dTKMN0zoQ AD8= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:19 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 07/14] lib: sbi: Remove redundant boot time print statement Date: Fri, 19 Mar 2021 15:12:58 -0700 Message-Id: <20210319221305.2138412-8-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221340_266446_A363DB2D X-CRM114-Status: UNSURE ( 8.44 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Signed-off-by: Atish Patra --- lib/sbi/sbi_init.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 4de2dfa7c99d..acc2a81a1b53 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -117,8 +117,6 @@ static void sbi_boot_print_hart(struc [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- lib/sbi/sbi_init.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index 4de2dfa7c99d..acc2a81a1b53 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -117,8 +117,6 @@ static void sbi_boot_print_hart(struct sbi_scratch *scratch, u32 hartid) sbi_hart_pmp_addrbits(scratch)); sbi_printf("Boot HART MHPM Count : %d\n", sbi_hart_mhpm_count(scratch)); - sbi_printf("Boot HART MHPM Count : %d\n", - sbi_hart_mhpm_count(scratch)); sbi_hart_delegation_dump(scratch, "Boot HART ", " "); } From patchwork Fri Mar 19 22:12:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456055 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=MYLPd8p9; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=nRCd1xw3; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J8M1kDMz9sSC for ; Sat, 20 Mar 2021 09:14:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=UAsT5igE1phaAyq+e3HVxpoQDfb/KXHrK4IHKlN/1XM=; b=MYLPd8p9zwFGswzu32pVbursP tOGl2UrQTfVB/orDi2PZlmh9VbbRf+Nz6Ye5y4fY9MpBt4Bbwy+r3FbpHWErM0RVABbO24PO/ZuoT 0S2fUiGgErIOz9TC+N/Rd7JX7bPv9tGKG8d6Zaft2mHQT6MGcxYZlZSJGnFsQECxVMGZThW9DnIMI mqiVPkmRkax+g4RUVTaFlL9nW/Oqv4/K6ag1zEepQXBNOJssziHlxCBEGqxSs/BAlWp4WyJqez7mv 5KIxDD9pwQrFa22NNRls7LjEawJ7Jl05RfDy1Y1aajzpCvLRB4APJsgYmpFmsALlsRp4uy61C270+ jxukmk7fg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNe-008FWj-Cr; Fri, 19 Mar 2021 22:14:06 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNE-008FLJ-CD for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192021; x=1647728021; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XQvRNhsK/E5/8s8NwJrUbIxyNt7aOjD7pUCTsyx57A4=; b=nRCd1xw3p05VC1LpSWIRWE6Te0I9LvN/AbxZ5L0+WAnmzG1eDdK9sTF5 Xj5AMbpUY1C1xgdOZwq1zn8EUo5z5tTyLr8cBqib8zc/AmTIaBx0EtRFG lYRmYU9S+jxPAJ7O2ILLDIVU61D7sTZuCdC0fVvCOKkS76TGKHmUUnMkx fQBnMJDiE36YB5aSHqRtyNUhKfRsQpwYHfGvrGAkf8IGmhtQCkPgNR3ba X4j9SgysERU39eOBKvWvZfwv3JrcTdrxE20SJBIFdQm048S1r/tEb8S4b uzttgpJU4m33Y7LmpknNZ4ZnU4AmobY4rYjykhm1rH70bxq8AlfcJF9MD Q==; IronPort-SDR: maQYq12JPobH5c3IToJKbEbwAvmw97EuTUst6A5wtUeQG2/gXZ8BkD0Ht7r4l0HRcQ1VREw05u LsoWG0zGtC7sAZAG3sJFcDLI/fs4xuLLyMUaZzPHpnRsJpLhPpDV8bGSW2UhU0lrPzPLh7PPWc ddpkFWvudM5lEGQaKJOlcywwhesEDgBENjHNGYSCoEFlZ7wsWnvn2TcsHVx3gcBDFAYZaDLs45 JkIal+hRMGL6DFRVPUeUfCxs8Wu+jdXpShpifjTtkFOXqqKBZA48E8fqNj2EU1V4aSGrPteH6P fGk= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713908" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:20 +0800 IronPort-SDR: 1nrZH5KxvzECZOIYqRoIwGIiFGQMI+pkV3s/9CeTmYW3WDfOcbmg1JbJ7eux8NByP0CmUAYQW1 aoUSUDa4DaExo/rJWLKeuAWGtBhqafs3J9lgAVikuBHSge58IwnBlZu4lrvgYeMxnBUt2fw1gw IJRoraDLnMgw3UFtACN0PWh9w/hHcU6+kX7zNPEbBXoRcpcanSSwuGw9b1AERwRPRN7DHAXjOp GFqfGxtJdgLjwdszAxrfKgj1bAn8+VwJmDZXLcQG+nF06KRr73F+mLR7j+2c9z0z9nlW75sWzi YGulvQHtfObAb4gJ6K1C8qTp Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:51 -0700 IronPort-SDR: c09fbEOEu4ODmKFEj7J7ITLz6Sp6HYgET0tvsXlHi8+9W7GlbB2Fbks93eUrMRiG1l9bydxPLq plzhIfXTakdqs0ke4gyn/U3UVKF4o8vyAXvqcQH/zHnIyUfZEGQ3Dw/SQ8fVFxMvwvOFji5qT2 2GENaBqchiqUzLo31TMFLaU2IHxJBcpH5jSZDANLdQfjyBG1hmdwWGFmoEl/rV14X74z/t956y wmbGs4BVq7LYA5Oat8eqNOVN4vLaZOo/ZuuDquVETn1XkJD1WD4qOxRKwXms4QYnFEOb17qPh0 UGk= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:19 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 08/14] lib: sbi: Use csr_read/write_num to read/update PMU counters Date: Fri, 19 Mar 2021 15:12:59 -0700 Message-Id: <20210319221305.2138412-9-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221340_932023_53BA2A31 X-CRM114-Status: UNSURE ( 8.79 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Currently, csr_read/write_num functions are used to read/write PMP related CSRs where CSR value is decided at runtime. Expand this function to include PMU related CSRs as well. Signed-off-by: Atish Patra --- lib/sbi/riscv_asm.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Currently, csr_read/write_num functions are used to read/write PMP related CSRs where CSR value is decided at runtime. Expand this function to include PMU related CSRs as well. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- lib/sbi/riscv_asm.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c index 8c54c11147e7..4c24a5132195 100644 --- a/lib/sbi/riscv_asm.c +++ b/lib/sbi/riscv_asm.c @@ -118,6 +118,21 @@ unsigned long csr_read_num(int csr_num) switch (csr_num) { switchcase_csr_read_16(CSR_PMPCFG0, ret) switchcase_csr_read_64(CSR_PMPADDR0, ret) + switchcase_csr_read(CSR_MCYCLE, ret) + switchcase_csr_read(CSR_MINSTRET, ret) + switchcase_csr_read(CSR_MHPMCOUNTER3, ret) + switchcase_csr_read_4(CSR_MHPMCOUNTER4, ret) + switchcase_csr_read_8(CSR_MHPMCOUNTER8, ret) + switchcase_csr_read_16(CSR_MHPMCOUNTER16, ret) +#if __riscv_xlen == 32 + switchcase_csr_read(CSR_MCYCLEH, ret) + switchcase_csr_read(CSR_MINSTRETH, ret) + switchcase_csr_read(CSR_MHPMCOUNTER3H, ret) + switchcase_csr_read_4(CSR_MHPMCOUNTER4H, ret) + switchcase_csr_read_8(CSR_MHPMCOUNTER8H, ret) + switchcase_csr_read_16(CSR_MHPMCOUNTER16H, ret) +#endif + default: break; }; @@ -161,6 +176,26 @@ void csr_write_num(int csr_num, unsigned long val) switch (csr_num) { switchcase_csr_write_16(CSR_PMPCFG0, val) switchcase_csr_write_64(CSR_PMPADDR0, val) + switchcase_csr_write(CSR_MCYCLE, val) + switchcase_csr_write(CSR_MINSTRET, val) + switchcase_csr_write(CSR_MHPMCOUNTER3, val) + switchcase_csr_write_4(CSR_MHPMCOUNTER4, val) + switchcase_csr_write_8(CSR_MHPMCOUNTER8, val) + switchcase_csr_write_16(CSR_MHPMCOUNTER16, val) +#if __riscv_xlen == 32 + switchcase_csr_write(CSR_MCYCLEH, val) + switchcase_csr_write(CSR_MINSTRETH, val) + switchcase_csr_write(CSR_MHPMCOUNTER3H, val) + switchcase_csr_write_4(CSR_MHPMCOUNTER4H, val) + switchcase_csr_write_8(CSR_MHPMCOUNTER8H, val) + switchcase_csr_write_16(CSR_MHPMCOUNTER16H, val) +#endif + switchcase_csr_write(CSR_MCOUNTINHIBIT, val) + switchcase_csr_write(CSR_MHPMEVENT3, val) + switchcase_csr_write_4(CSR_MHPMEVENT4, val) + switchcase_csr_write_8(CSR_MHPMEVENT8, val) + switchcase_csr_write_16(CSR_MHPMEVENT16, val) + default: break; }; From patchwork Fri Mar 19 22:13:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456056 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=Eg/o5jyD; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=OEBqyvLZ; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J8M2BYQz9sVS for ; Sat, 20 Mar 2021 09:14:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=uzpppQxFDRSzBGY6K7qZ1CqnTN0PalA6YCYjt5NNkTw=; b=Eg/o5jyD9GW4WllLiymcIlKA4 E9CnFdmTiiSWhADNGHyAQ+D4+cj+9zeRXmKlYCrjEteITX68a56/XewIocKErm98Cy8MqB7WHKobd Y6NM6KyD29FxhmCDl9KbKaWFwtEP2BQ7S8ptgHovd23efQqK45LCOjZldw8wqpZBA+NcOSPTjxkhb /Kd3Nb2HI+A5aWS3pm7XzIRQFiBNX4vkhEjNrelrkBkGKWwJnlUAcqUntAMst6Os1U1FqHDlTFSCn WjhTcn5J47O6wCFFfZxwKDw+aXE3XCQ4LVTbngzRDzZeeYuJwloriggslQEt3jf/KxQxMy0t1UpDY HhgvCJe3g==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNf-008FXE-EJ; Fri, 19 Mar 2021 22:14:07 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNF-008FJO-N8 for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192022; x=1647728022; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tvKpeHCWAqWHhZBqyIrUEQXUjmkoDDRv/U5VG5QZ27c=; b=OEBqyvLZOkPDzaZPeM0pWGUXcazQvqfZqMRdVgkYPhhNe0Ms99BuIByK Gzc3gbssaGJWFEnvj9MINh2hGP3OlFtGsuI33C0dWKPeSBOB3WexbIO+J DOSV3TD7DWURjb0gJf2AGKgKyy0QK6oqOo8RZuN3mXMLbKhTVevBcA4dS 0M/UJp5PhwXrXjVhGgAxUR5InuPdO4qtjU5qTAZFFOT4o0rBtw4ocDdkW vWJnMwXoJjnH/iRHn9JSsdhyRAr8Z6ao8X4gh1bislsxHuoHLDLLN2pWV 999G8VbGBCWRiIkMrK6sY5lM9n9+sbHL2C7kM1KH8wBe1lq2zgUZAxxDm g==; IronPort-SDR: aLqz1w0J8vuhMxH5W2pfdQjymukvVsfNUiF0jDOgioCTO0HHuO3ZNgTQCUYAUxUNiw0pKzL7nt qhtc/n0IOCzjcTBxfAAeunAW75PJxPlWCZXGmORgj5ggT1D4VXWz03Ma+1CVu6oKOhJAKkMujk AjZZjTn29A72cgGtZCTrBs/46xsCY2qYTgCoAgxQnLdK3A67qnyS3tGh9ICtKI/YxtDN6tf/6T xj0imB55Xjkw5FWd7qXDWQxtFtGukU8wIVksMZc510MKr7+xCJFvoUS5fw/b/74NutzB8vSvIs 9mQ= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713909" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:20 +0800 IronPort-SDR: /tT1a0H3z8Mn+FGcwRPqZlIWL7QRNj7fHK5OPm0TkgoYL+9+XxScmsiN1aTLRif4cGw1r0SrAD B7M7TMSalzvBprdr5hcH78oVX4CGGFixGCVHACvxC4NrsNjLzBKt+cGlIjiua6bf/Mp52UTjfG Jrv1xc7jQIg4fgdS6SWlHcvHR28TorwDVHIn9fC9f4mWTqunjac5TdhTmKu/8qQu+SQjj4INdI ONjH6+L2egpMGq034Qw1aS7OA+dtAXHp8IpTxrMXYiSa59FqDXfR6pKnsYUeayo5jCIe4ECYnT GGPKEVTneFRZTPEH+Ytr1Wsb Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:51 -0700 IronPort-SDR: mWwLhJH8fOlVy0E/jjQmqifh06zZPfaSBdt4HOC/1p7kRSwuIcf33nffqnVz0AKWS6img4r/dV xzlfEETG4rcebM0XQfIpUkHSF8am8cM5ZLGtQC6NNSxaJTVVJoIE98tI2LeGrEvSeNjazCT3kP tkafRalVw+6qS0Pd0ocZndetS5tQ0VkYudfiKsTpCQKeA7nC5JpEOyP5CkT9L9d0zkqKlinQIe XeZ6GHcKCrFojhfcH7nEYzBdAJQZfa6Qog8tlv7v4wkHNHaWXd6etAEX2Ew2+TEqzNkN133Lm4 wBM= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:19 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 09/14] lib: sbi: Add PMU specific platform hooks Date: Fri, 19 Mar 2021 15:13:00 -0700 Message-Id: <20210319221305.2138412-10-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221342_230080_402F0268 X-CRM114-Status: GOOD ( 13.82 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: A platform hook to initialize PMU allows platform vendors to provide their own mechanism to define pmu event-counter mappings in addition to the DT based approach. Another platform hook that allows platform vendors customize the final mhpmevent value configuration. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org A platform hook to initialize PMU allows platform vendors to provide their own mechanism to define pmu event-counter mappings in addition to the DT based approach. Another platform hook that allows platform vendors customize the final mhpmevent value configuration. Signed-off-by: Atish Patra --- include/sbi/sbi_platform.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index dadbc1e94e18..02773f672443 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -97,6 +97,11 @@ struct sbi_platform_operations { /** Initialize (or populate) domains for the platform */ int (*domains_init)(void); + /** Initialize hw performance counters */ + int (*pmu_init)(void); + + uint64_t (*get_mhpmevent_value)(uint32_t event_idx, uint64_t data); + /** Write a character to the platform console output */ void (*console_putc)(char ch); /** Read a character from the platform console input */ @@ -514,6 +519,39 @@ static inline int sbi_platform_domains_init(const struct sbi_platform *plat) return 0; } +/** + * Setup hw PMU events for the platform + * + * @param plat pointer to struct sbi_platform + * + * @return 0 on success and negative error code on failure + */ +static inline int sbi_platform_pmu_init(const struct sbi_platform *plat) +{ + if (plat && sbi_platform_ops(plat)->pmu_init) + return sbi_platform_ops(plat)->pmu_init(); + return 0; +} + +/** + * Get the value to be written in mhpmeventx for event_idx + * + * @param plat pointer to struct sbi_platform + * @param event_idx ID of the PMU event + * @param data Additional configuration data passed from supervisor software + * + * @return expected value by the platform or 0 if platform doesn't know about + * the event + */ +static inline int sbi_platform_get_mhpmevent_value(const struct sbi_platform *plat, + uint32_t event_idx, uint64_t data) +{ + if (plat && sbi_platform_ops(plat)->get_mhpmevent_value) + return sbi_platform_ops(plat)->get_mhpmevent_value(event_idx, + data); + return 0; +} + /** * Write a character to the platform console output * From patchwork Fri Mar 19 22:13:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456057 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=Hj6S5nDh; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=e2+9lcU2; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J8V5krtz9sVS for ; Sat, 20 Mar 2021 09:14:18 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=8YgrU/JfsSFRdAA7TZq/6zJhdoZHRT6tXr4qRtEe4bk=; b=Hj6S5nDhTiEyO8rI7p2r1lITZ 7WMUS4bkFgNa9T793pU4LljmyA21IzdCEvJReYYS2J2Z5S8lkS1m8AKOsO24hzHaBLD33cvLQ/jPn KNqeO1K7dClEKFcGeXaiadlTrbreZko3QThC72yj1eBIyDG2u24LRMsqZbFfs24EqV/AC8E2u69li SZckafMLRXCWZ5cTJvVsq7M1HUxHMdlR9KZ9rFrXY21l7sdJTZAgD0K1p1fjQqRYRWd7cY4y4fWaR w0sAa82F9mY3fO1O751OUINv71EuMw854jLLCrHHhvhaGdBxF1S3HS/07r5tPWa9cAkJVpcE6dSzJ Oix+eD59g==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNi-008FYx-KN; Fri, 19 Mar 2021 22:14:10 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNG-008FKT-96 for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:45 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192023; x=1647728023; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=58fNAsudfBAablJ9ws09lmvrPtEkafw8FD24Ji1s6WQ=; b=e2+9lcU2BEKtqe28D/jLWoog4P/lUetdxUSW86WPnoR6y30YudJKrqpg AOb2fdJJ1wAhzWJ7zeST5RwNCkMj1CysO+dVrUZLTWoYdzMqlo0eZESUg cl5y3K95uxVPEy7VRAhaQq9zaVR6iKWxBM4YlfzH0AqCj0luyhbQh3OhH SZa13yOBGu/F0hUF8fVlTvMD/rqmfPHEiP8NU8gdUfmOV+onQWsu0jT+d 2xZoxp0nAShpfFQF5xLiy8b7qJN3cx6+zi8/1XX1MOXkKU9EPYInN+Hiu l2+J1z2R/ZNH3jf+z4ClygsVKMcXPLErt/a2w/402TLYW62bUnJDoYSiR Q==; IronPort-SDR: /gSgL+oeSHRFjlMa1DjcFNFrsLvomi4f5eZ/wgS+dFB8wuGCPTLPiz32XqENf5/mV//22BCn/y rIxHu26g8gD4mTAnFAK/j2Zh0QnWHIYz83NY7hJFh+Mhnsr6TMOMLTnlih13LJsMD1iiYnAxKz FzvcqaAsrDeCYGejCZ8dmoVv+8iVjXTkhyNDUnEcXhkl6MlDYADVdzeM+g2NYZyYlwsjnhnPvY 3Z3lUn3MN0t2s1Hd0Rf2lMuMY7j/WJIyuzyBWCiEKN0/t7PsH4ZRQhSN7bYTg9O/hivWxq8jZD 1nI= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713910" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:20 +0800 IronPort-SDR: 7Vrhg/7BFiGwU7Qo3a9srgZvj0jV3NgDHx5H6c+o85c3u/p6Df3fMzTcaRd4e6fmg0gjKO/4wt ZBBydK2MrMlVMyhaqIJU8nUsAbLNNvO1k7GP4zaqTkzjFsi3Qr7khp4SsCwfRCZpGEkHlWeqEf 46U+8Fr8lFeTeeVwC9KtBPCt8yjVisaAtLK4S0BXfZRy/sgWPtC0WB8t493WkG9FwLh+nHiOsY dGqmclQUST+sfsK2IHI3I2jAwHlHq4y6p6POSig5DnJHPu70vTEWIDm7bncbXfQcMEFx/hbs9h Fw98shx718csvTiojg9G3rtN Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:51 -0700 IronPort-SDR: ILxa7KtmPukZzrUKfOLE5TEZmcplu7nL0o3RyPpJP6onoEEZNWAOmnjFQIkTYWvWX+y1U5cwjU l1WndRgxjPRrNCLCurIgIfVyTQm+PexnXr5dhXxcFJGNGtUBwA5E+6UJqF+J/TIOygRbflgpt3 gcjPn8uumhNGwDlG/wdIQxn+KFFarm7+xuwSCssEj1+BSotfkgjB/yj/rOErld+vVlAnz9CXmi xWZ4hOzYTPmPcMXZeqa0FLUOrOjx6KasemfK8zL6Ts+kVCHwKvft6m57I9M1tpYqjh7wpMK9BC sQs= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:19 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 10/14] lib: sbi: Add PMU support Date: Fri, 19 Mar 2021 15:13:01 -0700 Message-Id: <20210319221305.2138412-11-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221342_860819_ECB98F3B X-CRM114-Status: GOOD ( 28.54 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: RISC-V SBI v0.3 specification defined a PMU extension to configure/start/stop the hardware/firmware pmu events. Implement PMU support in OpenSBI library. The implementation is agnostic of event to counter mapping & mhpmevent value configuration. That means, it expects platform hooks will be used to set up the m [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org RISC-V SBI v0.3 specification defined a PMU extension to configure/start/stop the hardware/firmware pmu events. Implement PMU support in OpenSBI library. The implementation is agnostic of event to counter mapping & mhpmevent value configuration. That means, it expects platform hooks will be used to set up the mapping and provide the mhpmevent value at runtime. Signed-off-by: Atish Patra --- include/sbi/sbi_ecall_interface.h | 129 +++++++- include/sbi/sbi_error.h | 2 + include/sbi/sbi_pmu.h | 71 ++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_hart.c | 1 + lib/sbi/sbi_init.c | 9 + lib/sbi/sbi_pmu.c | 534 ++++++++++++++++++++++++++++++ 7 files changed, 746 insertions(+), 1 deletion(-) create mode 100644 include/sbi/sbi_pmu.h create mode 100644 lib/sbi/sbi_pmu.c diff --git a/include/sbi/sbi_ecall_interface.h b/include/sbi/sbi_ecall_interface.h index 559a33e7ced0..63b1ca7c75b4 100644 --- a/include/sbi/sbi_ecall_interface.h +++ b/include/sbi/sbi_ecall_interface.h @@ -28,6 +28,7 @@ #define SBI_EXT_RFENCE 0x52464E43 #define SBI_EXT_HSM 0x48534D #define SBI_EXT_SRST 0x53525354 +#define SBI_EXT_PMU 0x504D55 /* SBI function IDs for BASE extension*/ #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 @@ -91,6 +92,130 @@ #define SBI_SRST_RESET_REASON_NONE 0x0 #define SBI_SRST_RESET_REASON_SYSFAIL 0x1 +/* SBI function IDs for PMU extension */ +#define SBI_EXT_PMU_NUM_COUNTERS 0x0 +#define SBI_EXT_PMU_COUNTER_GET_INFO 0x1 +#define SBI_EXT_PMU_COUNTER_CFG_MATCH 0x2 +#define SBI_EXT_PMU_COUNTER_FW_READ 0x3 +#define SBI_EXT_PMU_COUNTER_START 0x4 +#define SBI_EXT_PMU_COUNTER_STOP 0x5 + +/** General pmu event codes specified in SBI PMU extension */ +enum sbi_pmu_hw_generic_events_t { + SBI_PMU_HW_NO_EVENT = 0, + SBI_PMU_HW_CPU_CYCLES, + SBI_PMU_HW_INSTRUCTIONS, + SBI_PMU_HW_CACHE_REFERENCES, + SBI_PMU_HW_CACHE_MISSES, + SBI_PMU_HW_BRANCH_INSTRUCTIONS, + SBI_PMU_HW_BRANCH_MISSES, + SBI_PMU_HW_BUS_CYCLES, + SBI_PMU_HW_STALLED_CYCLES_FRONTEND, + SBI_PMU_HW_STALLED_CYCLES_BACKEND, + SBI_PMU_HW_REF_CPU_CYCLES, + + SBI_PMU_HW_GENERIC_MAX, +}; + +/** + * Generalized hardware cache events: + * + * { L1-D, L1-I, LLC, ITLB, DTLB, BPU, NODE } x + * { read, write, prefetch } x + * { accesses, misses } + */ +enum sbi_pmu_hw_cache_id { + SBI_PMU_HW_CACHE_L1D = 0, + SBI_PMU_HW_CACHE_L1I = 1, + SBI_PMU_HW_CACHE_LL = 2, + SBI_PMU_HW_CACHE_DTLB = 3, + SBI_PMU_HW_CACHE_ITLB = 4, + SBI_PMU_HW_CACHE_BPU = 5, + SBI_PMU_HW_CACHE_NODE = 6, + + SBI_PMU_HW_CACHE_MAX, +}; + +enum sbi_pmu_hw_cache_op_id { + SBI_PMU_HW_CACHE_OP_READ = 0, + SBI_PMU_HW_CACHE_OP_WRITE = 1, + SBI_PMU_HW_CACHE_OP_PREFETCH = 2, + + SBI_PMU_HW_CACHE_OP_MAX, +}; + +enum sbi_pmu_hw_cache_op_result_id { + SBI_PMU_HW_CACHE_RESULT_ACCESS = 0, + SBI_PMU_HW_CACHE_RESULT_MISS = 1, + + SBI_PMU_HW_CACHE_RESULT_MAX, +}; + +/** + * Special "firmware" events provided by the OpenSBI, even if the hardware + * does not support performance events. These events are encoded as a raw + * event type in Linux kernel perf framework. + */ +enum sbi_pmu_fw_event_code_id { + SBI_PMU_FW_MISALIGNED_LOAD = 0, + SBI_PMU_FW_MISALIGNED_STORE = 1, + SBI_PMU_FW_ACCESS_LOAD = 2, + SBI_PMU_FW_ACCESS_STORE = 3, + SBI_PMU_FW_ILLEGAL_INSN = 4, + SBI_PMU_FW_SET_TIMER = 5, + SBI_PMU_FW_IPI_SENT = 6, + SBI_PMU_FW_IPI_RECVD = 7, + SBI_PMU_FW_FENCE_I_SENT = 8, + SBI_PMU_FW_FENCE_I_RECVD = 9, + SBI_PMU_FW_SFENCE_VMA_SENT = 10, + SBI_PMU_FW_SFENCE_VMA_RCVD = 11, + SBI_PMU_FW_SFENCE_VMA_ASID_SENT = 12, + SBI_PMU_FW_SFENCE_VMA_ASID_RCVD = 13, + + SBI_PMU_FW_HFENCE_GVMA_SENT = 14, + SBI_PMU_FW_HFENCE_GVMA_RCVD = 15, + SBI_PMU_FW_HFENCE_GVMA_VMID_SENT = 16, + SBI_PMU_FW_HFENCE_GVMA_VMID_RCVD = 17, + + SBI_PMU_FW_HFENCE_VVMA_SENT = 18, + SBI_PMU_FW_HFENCE_VVMA_RCVD = 19, + SBI_PMU_FW_HFENCE_VVMA_ASID_SENT = 20, + SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD = 21, + SBI_PMU_FW_MAX, +}; + +/** SBI PMU event idx type */ +enum sbi_pmu_event_type_id { + SBI_PMU_EVENT_TYPE_HW = 0x0, + SBI_PMU_EVENT_TYPE_HW_CACHE = 0x1, + SBI_PMU_EVENT_TYPE_HW_RAW = 0x2, + SBI_PMU_EVENT_TYPE_FW = 0xf, + SBI_PMU_EVENT_TYPE_MAX, +}; + +/** SBI PMU counter type */ +enum sbi_pmu_ctr_type { + SBI_PMU_CTR_TYPE_HW = 0, + SBI_PMU_CTR_TYPE_FW, +}; + +/* Helper macros to decode event idx */ +#define SBI_PMU_EVENT_IDX_OFFSET 20 +#define SBI_PMU_EVENT_IDX_MASK 0xFFFFF +#define SBI_PMU_EVENT_IDX_CODE_MASK 0xFFFF +#define SBI_PMU_EVENT_IDX_TYPE_MASK 0xF0000 +#define SBI_PMU_EVENT_RAW_IDX 0x20000 + +#define SBI_PMU_EVENT_IDX_INVALID 0xFFFFFFFF + +/* Flags defined for config matching function */ +#define SBI_PMU_CFG_FLAG_AUTOSTART 0x1 +#define SBI_PMU_CFG_FLAG_SKIPMATCH 0x2 + +/* Flags defined for counter stop function */ +#define SBI_PMU_STOP_FLAG_RESET 0x1 + +/* SBI base specification related macros */ #define SBI_SPEC_VERSION_MAJOR_OFFSET 24 #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f #define SBI_SPEC_VERSION_MINOR_MASK 0xffffff @@ -107,8 +232,10 @@ #define SBI_ERR_DENIED -4 #define SBI_ERR_INVALID_ADDRESS -5 #define SBI_ERR_ALREADY_AVAILABLE -6 +#define SBI_ERR_ALREADY_STARTED -7 +#define SBI_ERR_ALREADY_STOPPED -8 -#define SBI_LAST_ERR SBI_ERR_ALREADY_AVAILABLE +#define SBI_LAST_ERR SBI_ERR_ALREADY_STOPPED /* clang-format on */ diff --git a/include/sbi/sbi_error.h b/include/sbi/sbi_error.h index 3655d122006b..dd65e14b6fcd 100644 --- a/include/sbi/sbi_error.h +++ b/include/sbi/sbi_error.h @@ -21,6 +21,8 @@ #define SBI_EDENIED SBI_ERR_DENIED #define SBI_EINVALID_ADDR SBI_ERR_INVALID_ADDRESS #define SBI_EALREADY SBI_ERR_ALREADY_AVAILABLE +#define SBI_EALREADY_STARTED SBI_ERR_ALREADY_STARTED +#define SBI_EALREADY_STOPPED SBI_ERR_ALREADY_STOPPED #define SBI_ENODEV -1000 #define SBI_ENOSYS -1001 diff --git a/include/sbi/sbi_pmu.h b/include/sbi/sbi_pmu.h new file mode 100644 index 000000000000..b6f25de44c6c --- /dev/null +++ b/include/sbi/sbi_pmu.h @@ -0,0 +1,71 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + */ + +#ifndef __SBI_PMU_H__ +#define __SBI_PMU_H__ + +#include +#include +#include +#include + +/* Event related macros */ +/* Maximum number of hardware events that can mapped by OpenSBI */ +#define SBI_PMU_HW_EVENT_MAX 64 + +/* Maximum number of firmware events that can mapped by OpenSBI */ +#define SBI_PMU_FW_EVENT_MAX 32 + +/* Counter related macros */ +#define SBI_PMU_FW_CTR_MAX 16 +#define SBI_PMU_HW_CTR_MAX 32 +#define SBI_PMU_CTR_MAX (SBI_PMU_HW_CTR_MAX + SBI_PMU_FW_CTR_MAX) + +/** Initialize PMU */ +int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot); + +/** Reset PMU during hart exit */ +void sbi_pmu_exit(struct sbi_scratch *scratch); + +/** + * Add the hardware event to counter mapping information. This should be called + * from the platform code to update the mapping table. + * @param eidx_start Start of the event idx range for supported counters + * @param eidx_end End of the event idx range for supported counters + * @param cmap A bitmap representing counters supporting the event range + * @return 0 on success, error otherwise. + */ +int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap); + +/** + * Add the raw hardware event selector and supported counter information. This + * should be called from the platform code to update the mapping table. + * @param info a pointer to the hardware event info + * @return 0 on success, error otherwise. + */ + +int sbi_pmu_add_raw_event_counter_map(uint64_t select, u32 cmap); + +int sbi_pmu_read_ctr(uint32_t cidx, unsigned long *cval); + +int sbi_pmu_stop_ctr(uint32_t cidx, bool bReset); + +int sbi_pmu_start_ctr(uint32_t cidx, uint64_t ival); + +int sbi_pmu_get_ctr_info(uint32_t cidx, unsigned long *ctr_info); + +unsigned long sbi_pmu_num_ctr(void); + +int sbi_pmu_get_ctr_match(unsigned long cidx_base, unsigned long cidx_mask, + unsigned long event_idx, uint64_t event_info, + unsigned long flags); + +int sbi_pmu_incr_fw_ctr(enum sbi_pmu_fw_event_code_id fw_id); + +#endif diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index 6f2c06f5b501..d9068b707854 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -33,6 +33,7 @@ libsbi-objs-y += sbi_init.o libsbi-objs-y += sbi_ipi.o libsbi-objs-y += sbi_misaligned_ldst.o libsbi-objs-y += sbi_platform.o +libsbi-objs-y += sbi_pmu.o libsbi-objs-y += sbi_scratch.o libsbi-objs-y += sbi_string.o libsbi-objs-y += sbi_system.o diff --git a/lib/sbi/sbi_hart.c b/lib/sbi/sbi_hart.c index b87d1dbedc0b..2d155c6b6bf4 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/lib/sbi/sbi_init.c b/lib/sbi/sbi_init.c index acc2a81a1b53..7362430716e6 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -234,6 +235,8 @@ static void __noreturn init_coldboot(struct sbi_scratch *scratch, u32 hartid) if (rc) sbi_hart_hang(); + sbi_pmu_init(scratch, TRUE); + sbi_boot_print_banner(scratch); rc = sbi_platform_irqchip_init(plat, TRUE); @@ -335,6 +338,8 @@ static void init_warm_startup(struct sbi_scratch *scratch, u32 hartid) if (rc) sbi_hart_hang(); + sbi_pmu_init(scratch, FALSE); + rc = sbi_platform_irqchip_init(plat, FALSE); if (rc) sbi_hart_hang(); @@ -375,6 +380,8 @@ static void init_warm_resume(struct sbi_scratch *scratch) if (rc) sbi_hart_hang(); + sbi_pmu_init(scratch, FALSE); + rc = sbi_hart_pmp_configure(scratch); if (rc) sbi_hart_hang(); @@ -498,6 +505,8 @@ void __noreturn sbi_exit(struct sbi_scratch *scratch) sbi_platform_early_exit(plat); + sbi_pmu_exit(scratch); + sbi_timer_exit(scratch); sbi_ipi_exit(scratch); diff --git a/lib/sbi/sbi_pmu.c b/lib/sbi/sbi_pmu.c new file mode 100644 index 000000000000..904b583fc7d6 --- /dev/null +++ b/lib/sbi/sbi_pmu.c @@ -0,0 +1,534 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/** Information about hardware counters */ +struct sbi_pmu_hw_event { + unsigned long counters; + unsigned long start_idx; + unsigned long end_idx; + /* Event selector value used only for raw events */ + uint64_t select; +}; + +/** Representation of a firmware event */ +struct sbi_pmu_fw_event { + + /* Event associated with the particular counter */ + unsigned long event_idx; + + /* Current value of the counter */ + unsigned long curr_count; + + /* A flag indicating pmu event monitoring is started */ + bool bStarted; +}; + +/* Information about PMU counters as per SBI specification */ +union sbi_pmu_ctr_info { + unsigned long value; + struct { + unsigned long csr:12; + unsigned long width:6; +#if __riscv_xlen == 32 + unsigned long reserved:13; +#else + unsigned long reserved:45; +#endif + unsigned long type:1; + }; +}; + +/* Mapping between event range and possible counters */ +static struct sbi_pmu_hw_event hw_event_map[SBI_PMU_HW_EVENT_MAX] = {0}; + +/* counter to enabled event mapping */ +static uint32_t active_events[SBI_HARTMASK_MAX_BITS][SBI_PMU_HW_CTR_MAX + SBI_PMU_FW_CTR_MAX]; + +/* Contains all the information about firmwares events */ +static struct sbi_pmu_fw_event fw_event_map[SBI_HARTMASK_MAX_BITS][SBI_PMU_FW_EVENT_MAX] = {0}; + +/* Maximum number of hardware events available */ +static uint32_t num_hw_events; +/* Maximum number of hardware counters available */ +static uint32_t num_hw_ctrs; + +/* Maximum number of counters available */ +static uint32_t total_ctrs; + +/* Helper macros to retrieve event idx and code type */ +#define get_cidx_type(x) ((x & SBI_PMU_EVENT_IDX_TYPE_MASK) >> 16) +#define get_cidx_code(x) (x & SBI_PMU_EVENT_IDX_CODE_MASK) + +/** + * Perform a sanity check on event & counter mappings with event range overlap check + * @param evtA Pointer to the existing hw event structure + * @param evtB Pointer to the new hw event structure + * + * Return FALSE if the range doesn't overlap, TRUE otherwise + */ +static bool pmu_event_range_overlap(struct sbi_pmu_hw_event *evtA, + struct sbi_pmu_hw_event *evtB) +{ + /* check if the range of events overlap with a previous entry */ + if (((evtA->end_idx < evtB->start_idx) && (evtA->end_idx < evtB->end_idx)) || + ((evtA->start_idx > evtB->start_idx) && (evtA->start_idx > evtB->end_idx))) + return FALSE; + return TRUE; +} + +static bool pmu_event_select_overlap(struct sbi_pmu_hw_event *evt, + uint64_t select_val) +{ + + if (evt->select == select_val) + return TRUE; + + return FALSE; +} + +static int pmu_validate_ctr(uint32_t cidx, uint32_t *event_idx_code) +{ + uint32_t event_idx_val; + uint32_t event_idx_type; + u32 hartid = current_hartid(); + + event_idx_val = active_events[hartid][cidx]; + + if (cidx >= total_ctrs || (event_idx_val == SBI_PMU_EVENT_IDX_INVALID)) + return SBI_EINVAL; + + event_idx_type = get_cidx_type(event_idx_val); + if (event_idx_type >= SBI_PMU_EVENT_TYPE_MAX) + return SBI_EINVAL; + + *event_idx_code = get_cidx_code(event_idx_val); + + return event_idx_type; +} + +static int sbi_pmu_read_fw_ctr(uint32_t cidx, unsigned long *cval, + uint32_t fw_evt_code) +{ + u32 hartid = current_hartid(); + struct sbi_pmu_fw_event fevent; + + fevent = fw_event_map[hartid][fw_evt_code]; + *cval = fevent.curr_count; + + return 0; +} + +/* Add a hardware counter read for completeness for future purpose */ +static int sbi_pmu_read_hw_ctr(uint32_t cidx, uint64_t *cval) +{ +#if __riscv_xlen == 32 + uint32_t temp, temph = 0; + + temp = csr_read_num(CSR_MCYCLE + cidx); + temph = csr_read_num(CSR_MCYCLEH + cidx); + *cval = ((uint64_t)temph << 32) | temp; +#else + *cval = csr_read_num(CSR_MCYCLE + cidx); +#endif + + return 0; +} + +int sbi_pmu_read_ctr(uint32_t cidx, unsigned long *cval) +{ + int event_idx_type; + uint32_t event_code; + uint64_t cval64; + + event_idx_type = pmu_validate_ctr(cidx, &event_code); + if (event_idx_type < 0) + return SBI_EINVAL; + else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) + sbi_pmu_read_fw_ctr(cidx, cval, event_code); + else + sbi_pmu_read_hw_ctr(cidx, &cval64); + + return 0; +} + +static int pmu_add_hw_event_map(u32 eidx_start, u32 eidx_end, u32 cmap, + uint64_t select) +{ + int i = 0; + bool is_overlap; + struct sbi_pmu_hw_event *event = &hw_event_map[num_hw_events]; + + /* The first two counters are reserved by priv spec */ + if ((eidx_start == SBI_PMU_HW_CPU_CYCLES && cmap != 0x1) || + (eidx_start == SBI_PMU_HW_INSTRUCTIONS && cmap != 0x4) || + (eidx_start > SBI_PMU_HW_INSTRUCTIONS && cmap < 0x08)) + return SBI_EDENIED; + + if (num_hw_events >= SBI_PMU_HW_EVENT_MAX - 1) { + sbi_printf("Can not handle more than %d perf events\n", + SBI_PMU_HW_EVENT_MAX); + return SBI_EFAIL; + } + + event->start_idx = eidx_start; + event->end_idx = eidx_end; + event->counters = cmap; + event->select = select; + + /* Sanity check */ + for (i = 0; i < num_hw_events; i++) { + if (eidx_start == SBI_PMU_EVENT_RAW_IDX) + /* All raw events have same event idx. Just do sanity check on select */ + is_overlap = pmu_event_select_overlap(&hw_event_map[i], select); + else + is_overlap = pmu_event_range_overlap(&hw_event_map[i], event); + if (is_overlap) + return SBI_EINVALID_ADDR; + } + num_hw_events++; + + return 0; +} + +/** + * Logical counter ids are assigned to hardware counters are assigned consecutively. + * E.g. counter0 must count MCYCLE where counter2 must count minstret. Similarly, + * counterX will mhpmcounterX. + */ +int sbi_pmu_add_hw_event_counter_map(u32 eidx_start, u32 eidx_end, u32 cmap) +{ + if ((eidx_start > eidx_end) || eidx_start == SBI_PMU_EVENT_RAW_IDX || + eidx_end == SBI_PMU_EVENT_RAW_IDX) + return SBI_EINVAL; + + return pmu_add_hw_event_map(eidx_start, eidx_end, cmap, 0); +} + +int sbi_pmu_add_raw_event_counter_map(uint64_t select, u32 cmap) +{ + return pmu_add_hw_event_map(SBI_PMU_EVENT_RAW_IDX, + SBI_PMU_EVENT_RAW_IDX, cmap, select); +} + +static int pmu_start_hw_ctr(uint32_t cidx, uint64_t ival) +{ + unsigned long mctr_en = csr_read(CSR_MCOUNTEREN); + unsigned long mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT); + + if (cidx > num_hw_ctrs) + return SBI_EINVAL; + + if (__test_bit(cidx, &mctr_en) && !__test_bit(cidx, &mctr_inhbt)) + return SBI_EALREADY_STARTED; + + __set_bit(cidx, &mctr_en); + __clear_bit(cidx, &mctr_inhbt); + + csr_write(CSR_MCOUNTEREN, mctr_en); + csr_write(CSR_MCOUNTINHIBIT, mctr_inhbt); + +#if __riscv_xlen == 32 + csr_write_num(CSR_MCYCLE + cidx, ival & 0xFFFF); + csr_write_num(CSR_MCYCLEH + cidx, ival >> BITS_PER_LONG); +#else + csr_write_num(CSR_MCYCLE + cidx, ival); +#endif + + return 0; +} + +static int pmu_start_fw_ctr(uint32_t cidx, uint64_t ival, uint32_t fw_evt_code) +{ + u32 hartid = current_hartid(); + struct sbi_pmu_fw_event *fevent; + + fevent = &fw_event_map[hartid][fw_evt_code]; + fevent->curr_count = ival; + fevent->bStarted = TRUE; + + return 0; +} + +int sbi_pmu_start_ctr(uint32_t cidx, uint64_t ival) +{ + int event_idx_type; + uint32_t event_code; + + event_idx_type = pmu_validate_ctr(cidx, &event_code); + if (event_idx_type < 0) + return SBI_EINVAL; + else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) + return pmu_start_fw_ctr(cidx, ival, event_code); + else + return pmu_start_hw_ctr(cidx, ival); +} + +static int pmu_stop_hw_ctr(uint32_t cidx) +{ + unsigned long mctr_en = csr_read(CSR_MCOUNTEREN); + unsigned long mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT); + + if (__test_bit(cidx, &mctr_en) && !__test_bit(cidx, &mctr_inhbt)) { + __set_bit(cidx, &mctr_inhbt); + __clear_bit(cidx, &mctr_en); + csr_write(CSR_MCOUNTEREN, mctr_en); + csr_write(CSR_MCOUNTINHIBIT, mctr_inhbt); + return 0; + } else + return SBI_EALREADY_STOPPED; +} + +static int pmu_stop_fw_ctr(uint32_t cidx, uint32_t fw_evt_code) +{ + u32 hartid = current_hartid(); + + fw_event_map[hartid][fw_evt_code].bStarted = FALSE; + + return 0; +} + +int sbi_pmu_stop_ctr(uint32_t cidx, bool bReset) +{ + u32 hartid = current_hartid(); + int ret, event_idx_type; + uint32_t event_code; + + event_idx_type = pmu_validate_ctr(cidx, &event_code); + if (event_idx_type < 0) + return SBI_EINVAL; + + else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) + ret = pmu_stop_fw_ctr(cidx, event_code); + else + ret = pmu_stop_hw_ctr(cidx); + + if (!ret && bReset) + active_events[hartid][cidx] = SBI_PMU_EVENT_IDX_INVALID; + + return ret; +} + +static int pmu_update_hw_mhpmevent(struct sbi_pmu_hw_event *hw_evt, int ctr_idx, + unsigned long eindex, uint64_t data) +{ + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + const struct sbi_platform *plat = sbi_platform_ptr(scratch); + uint64_t mhpmevent_val; + + /* Get the final mhpmevent value to be written from platform */ + mhpmevent_val = sbi_platform_get_mhpmevent_value(plat, eindex, data); + + if (!mhpmevent_val || ctr_idx < 3 || ctr_idx >= SBI_PMU_HW_CTR_MAX) + return SBI_EFAIL; + + csr_write_num(CSR_MCOUNTINHIBIT + ctr_idx, mhpmevent_val); + + return 0; +} + +static int pmu_find_hw_ctr(unsigned long cbase, unsigned long cmask, + unsigned long event_idx, uint64_t data) +{ + unsigned long ctr_mask; + int i, ret = 0, ctr_idx = SBI_ENOTSUPP; + struct sbi_pmu_hw_event *temp; + unsigned long mctr_en = csr_read(CSR_MCOUNTEREN); + unsigned long mctr_inhbt = csr_read(CSR_MCOUNTINHIBIT); + int evt_idx_code = get_cidx_code(event_idx); + + if (cbase > num_hw_ctrs) + return SBI_EINVAL; + + for (i = 0; i < num_hw_events; i++) { + temp = &hw_event_map[i]; + if ((temp->start_idx > event_idx && event_idx < temp->end_idx) || + (temp->start_idx < event_idx && event_idx > temp->end_idx)) + continue; + + /* For raw events, event data is used as the select value */ + if ((event_idx == SBI_PMU_EVENT_RAW_IDX) && temp->select != data) + continue; + + ctr_mask = temp->counters & (cmask << cbase); + for_each_set_bit_from(cbase, &ctr_mask, SBI_PMU_HW_CTR_MAX) { + if (!__test_bit(cbase, &mctr_en) && + __test_bit(cbase, &mctr_inhbt)) { + ctr_idx = cbase; + break; + } + } + } + + if (ctr_idx == SBI_ENOTSUPP) + return SBI_EFAIL; + + /* No need to update the event selectors for fixed events */ + if (evt_idx_code != SBI_PMU_HW_CPU_CYCLES && + evt_idx_code != SBI_PMU_HW_INSTRUCTIONS) + ret = pmu_update_hw_mhpmevent(temp, ctr_idx, event_idx, data); + + if (!ret) + ret = ctr_idx; + + return ret; +} + + +/** + * Any firmware counter can map to any firmware event. + * Thus, select the first available fw counter after sanity + * check. + */ +static int pmu_find_fw_ctr(unsigned long cbase, unsigned long cmask, u32 hartid) +{ + int i = 0; + int fw_base; + unsigned long ctr_mask = cmask << cbase; + + if (cbase <= num_hw_ctrs) + fw_base = num_hw_ctrs + 1; + else + fw_base = cbase; + + for (i = fw_base; i < total_ctrs; i++) + if ((active_events[hartid][i] == SBI_PMU_EVENT_IDX_INVALID) && + ((1UL << i) & ctr_mask)) + return i; + + return SBI_ENOTSUPP; +} + +int sbi_pmu_get_ctr_match(unsigned long cidx_base, unsigned long cidx_mask, + unsigned long event_idx, uint64_t event_data, + unsigned long flags) +{ + int ctr_idx = SBI_ENOTSUPP; + u32 hartid = current_hartid(); + int event_type = get_cidx_type(event_idx); + + if (cidx_base >= total_ctrs || event_type >= SBI_PMU_EVENT_TYPE_MAX) + return SBI_EINVAL; + + if (event_type == SBI_PMU_EVENT_TYPE_FW) { + /* Any firmware counter can be used track any firmware event */ + ctr_idx = pmu_find_fw_ctr(cidx_base, cidx_mask, hartid); + } else { + ctr_idx = pmu_find_hw_ctr(cidx_base, cidx_mask, event_idx, event_data); + } + + if (ctr_idx < 0) + return SBI_ENOTSUPP; + + active_events[hartid][ctr_idx] = event_idx; + + return ctr_idx; +} + +inline int sbi_pmu_incr_fw_ctr(enum sbi_pmu_fw_event_code_id fw_id) +{ + u32 hartid = current_hartid(); + struct sbi_pmu_fw_event *fevent; + + if (unlikely(fw_id >= SBI_PMU_FW_MAX)) + return SBI_EINVAL; + + fevent = &fw_event_map[hartid][fw_id]; + + /* PMU counters will be only enabled during performance debugging */ + if (unlikely(fevent->bStarted)) + fevent->curr_count++; + + return 0; +} + +unsigned long sbi_pmu_num_ctr(void) +{ + return (num_hw_ctrs + SBI_PMU_FW_CTR_MAX); +} + +int sbi_pmu_get_ctr_info(uint32_t cidx, unsigned long *ctr_info) +{ + union sbi_pmu_ctr_info cinfo = {0}; + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); + + /* Sanity check. Counter1 is not mapped at all */ + if (cidx > total_ctrs || cidx == 1) + return SBI_EINVAL; + + /* We have 31 HW counters with 31 being the last index(MHPMCOUNTER31) */ + if (cidx <= num_hw_ctrs) { + cinfo.type = SBI_PMU_CTR_TYPE_HW; + cinfo.csr = CSR_CYCLE + cidx; + /* mcycle & minstret are always 64 bit */ + if (cidx == 0 || cidx == 2) + cinfo.width = 63; + else + cinfo.width = sbi_hart_pmu_event_bits(scratch); + } else { + /* it's a firmware counter */ + cinfo.type = SBI_PMU_CTR_TYPE_FW; + /* Firmware counters are XLEN bits wide */ + cinfo.width = BITS_PER_LONG - 1; + } + + *ctr_info = cinfo.value; + + return 0; +} + + +static void pmu_reset_event_map(u32 hartid) +{ + int j; + + /* Initialize the counter to event mapping table */ + for (j = 0; j < total_ctrs; j++) + active_events[hartid][j] = SBI_PMU_EVENT_IDX_INVALID; + for (j = 0; j < SBI_PMU_FW_CTR_MAX; j++) + sbi_memset(&fw_event_map[hartid][j], 0, + sizeof(struct sbi_pmu_fw_event)); +} + +void sbi_pmu_exit(struct sbi_scratch *scratch) +{ + u32 hartid = current_hartid(); + + pmu_reset_event_map(hartid); +} + +int sbi_pmu_init(struct sbi_scratch *scratch, bool cold_boot) +{ + const struct sbi_platform *plat; + + if (!sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) + return SBI_ENOTSUPP; + + if (cold_boot) { + plat = sbi_platform_ptr(scratch); + /* Initialize hw pmu events */ + sbi_platform_pmu_init(plat); + + /* mcycle & minstret is available always */ + num_hw_ctrs = sbi_hart_mhpm_count(scratch) + 2; + total_ctrs = num_hw_ctrs + SBI_PMU_FW_CTR_MAX; + } + + pmu_reset_event_map(current_hartid()); + + return 0; +} From patchwork Fri Mar 19 22:13:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456058 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=HwgTo2DD; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=IMF0kZiS; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J8X0nFtz9sSC for ; Sat, 20 Mar 2021 09:14:20 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=WWfAwuFdfBOpYJM5dkg6hU1jrn4hJwCQumud03F6dto=; b=HwgTo2DDPGiKv6XSfZbbYcXxq HGzqghXt1qZ6cyxL6/OV/zMMGT9Cvo8vdXs2bI3AQIg5H1jNJN/in+dzMeMoBYytYixYvqfyvIZcu mhIlfiikg4AnF6K00vYZkyNumTIewBiJm3LND7eXhsClybMPipbBqh8cmibpp4rVIokpnSpnbGAnf g59i8w8AuXuGzqw120DFGYC/RgpS0bTNjTcDkeh5Ie2P3Xqd9MwECWqHzd+vq+i8u9A4K1I6Ua7mf U/XVvH7dn4oNVYTQCY0Cir3LJ3KjbHTKZ1VU+Ec9vCShyyAKxMpZ5BSeh1EfUyMQdm/VA+mAFVTse 1mzVKwmlw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNo-008Faf-Iq; Fri, 19 Mar 2021 22:14:16 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNH-008FLJ-37 for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192024; x=1647728024; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gPBYcaMAoNRjuNuLLQhHPUZskbCJaOVajL8ogMr+lIs=; b=IMF0kZiSW/OsVX2PKlghVoZFZMif8CZmh7sX6dRwfyCdEHnvQZdYRbng 51YXkI5vnRorz6Hv3rhdK/wKVUNa9qZnWUh/cm6rTDKUvv25fT8T1/5X7 repW3jkr+4tUwc/u1OImtzTCc4y0f9UyEO++ocB/1whi+tPDkuU0XVlKj s6sNp6UgaDf/ydJv/aBTR4As+oRvZQzflobqDrQ3pufrD3wv4T4djgw4Y H/53kC05U8jQ5V1la7oDT7RCX+FPabd6zFoFkUYzWIgVBe5EXtVjeJ3Yy wVWq8XrS16l+U8iwmBuOhjTriITVG62/76npaaQ0ef3bnqnHMeUBi3riO g==; IronPort-SDR: CcB1PpFgPIXm+Y2CL4EFyVDdqKU4JlCT+oYhXdMsJIOlozQt7Bjtwdk8sbndFbrjgsOA95/Nim nwNfD8wXpnV3mdF7G2GdddPg2bTHC1jSJMn/hEwL8FH0yNQ82r2e4DwibNG9XYcwSnACf9kUGP 3yNVFks7i2QKibOHAsze7ryIWO1icNSDfRmpb5XVkopUaEEckZGNjAl8wNLrz4wBRDLaneI/S6 nohds4oM1qI6GMG2NdAsKefhUENhFplHGcmFBmHChfOVbWE7vWpyV+vjS94w3HOP5dz6GEFN6f xnk= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713911" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:20 +0800 IronPort-SDR: MtpZuiH0CTWquqe0cd/X0O660kik4d4lfBfVEvfVY2GZRVIZn9X7wz5nXSGs95RQYChxhLAGkI hfd6xbzRA/DiAZFQFG5XEdLcPnXniRZhlU8tzpZNLPzuBVYIrgi3bbeAZ/clUNKb6S5+fRx8RK IHmzOKwdu08sDYFOCrjfrL7PR7jM7Ug4X1Y+oK+5kmUg7PPYpGoEC2MuQ1rReZ/wskk1wNTFsO dKXB9mlepCDfKojUYLUAyDW6PNik2ymO3ZYiphZHQDKt2m/PlULicgcuQpv/13e9zjl7ntlps+ QMzfu0FxLM/q7/1mh+pYLXJl Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:51 -0700 IronPort-SDR: okRc4F1WH/R/j7y3VkNKRgzVoHHEyY43dy6f4XAJYk038MEAZhgkE7Aw3nEhbmAO4Ys2SbAG0w BfQExLj1KzsDLX57yuKbQqbUfo+6QocFaCZgn0AqADJBQunTmADvw70z4ht7Bxr7PVZHI492Dk mAl21Jquwcjw0i1Ibb9CUNYWZYHIE4lKgQ9AI1z5+102TmGoy1TZaNr9dvkEz4jLOiZOYOpccL MGJjnGoOChrpJ16Kgh988wJUvWVFhtQJh/UNCOjZmjjjXDSjgAR8idb+TanEimctYh32TlV0l4 YUg= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:20 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 11/14] utils: fdt: Add fdt helper functions to parse PMU DT nodes Date: Fri, 19 Mar 2021 15:13:02 -0700 Message-Id: <20210319221305.2138412-12-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221344_446982_157FB6EF X-CRM114-Status: GOOD ( 23.89 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The PMU DT node bindings are defined in docs/pmu_support.md Add few fdt helper functions to parse the DT node and update the event-counter mapping tables. Signed-off-by: Atish Patra --- include/sbi_utils/fdt/fdt_pmu.h | 46 +++++++++++++ lib/utils/fdt/fdt_fixup.c | 2 + lib/utils/fdt/fdt_pmu.c | 110 ++++++++++++++++++++++++++++++++ l [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The PMU DT node bindings are defined in docs/pmu_support.md Add few fdt helper functions to parse the DT node and update the event-counter mapping tables. Signed-off-by: Atish Patra --- include/sbi_utils/fdt/fdt_pmu.h | 46 +++++++++++++ lib/utils/fdt/fdt_fixup.c | 2 + lib/utils/fdt/fdt_pmu.c | 110 ++++++++++++++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + 4 files changed, 159 insertions(+) create mode 100644 include/sbi_utils/fdt/fdt_pmu.h create mode 100644 lib/utils/fdt/fdt_pmu.c diff --git a/include/sbi_utils/fdt/fdt_pmu.h b/include/sbi_utils/fdt/fdt_pmu.h new file mode 100644 index 000000000000..2fa01edc0743 --- /dev/null +++ b/include/sbi_utils/fdt/fdt_pmu.h @@ -0,0 +1,46 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * fdt_pmu.c - Flat Device Tree PMU helper routines + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + */ + +#ifndef __FDT_PMU_H__ +#define __FDT_PMU_H__ + +#include + +/** + * Fix up the PMU node in the device tree + * + * This routine: + * 1. Disables opensbi specific properties from the DT + * + * It is recommended that platform support call this function in + * their final_init() platform operation. + * + * @param fdt device tree blob + */ +void fdt_pmu_fixup(void *fdt); + +/** + * Setup PMU data from device tree + * + * @param fdt device tree blob + * + * @return 0 on success and negative error code on failure + */ +int fdt_pmu_setup(void *fdt); + +/** + * Get the mhpmevent select value read from DT for a given event + * @param event_idx Event ID of the given event + * + * @return The select value read from DT or 0 if given index was not found + */ +uint64_t fdt_pmu_get_select_value(uint32_t event_idx); + +#endif diff --git a/lib/utils/fdt/fdt_fixup.c b/lib/utils/fdt/fdt_fixup.c index eea450d80492..ab351e408c86 100644 --- a/lib/utils/fdt/fdt_fixup.c +++ b/lib/utils/fdt/fdt_fixup.c @@ -15,6 +15,7 @@ #include #include #include +#include #include void fdt_cpu_fixup(void *fdt) @@ -260,6 +261,7 @@ void fdt_fixups(void *fdt) fdt_plic_fixup(fdt, "riscv,plic0"); fdt_reserved_memory_fixup(fdt); + fdt_pmu_fixup(fdt); } diff --git a/lib/utils/fdt/fdt_pmu.c b/lib/utils/fdt/fdt_pmu.c new file mode 100644 index 000000000000..5053ab7568d8 --- /dev/null +++ b/lib/utils/fdt/fdt_pmu.c @@ -0,0 +1,110 @@ +// SPDX-License-Identifier: BSD-2-Clause +/* + * fdt_pmu.c - Flat Device Tree PMU helper routines + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + */ + +#include +#include +#include +#include + +struct sbi_pmu_hw_event_select { + uint32_t eidx; + uint64_t select; +}; + +static struct sbi_pmu_hw_event_select fdt_pmu_evt_select[SBI_PMU_HW_EVENT_MAX] = {0}; +static uint32_t hw_event_count; + +uint64_t fdt_pmu_get_select_value(uint32_t event_idx) +{ + int i; + struct sbi_pmu_hw_event_select *event; + + for (i = 0; i < SBI_PMU_HW_EVENT_MAX; i++) { + event = &fdt_pmu_evt_select[i]; + if (event->eidx == event_idx) + return event->select; + } + + return 0; +} + +int fdt_pmu_fixup(void *fdt) +{ + int pmu_offset; + + if (!fdt) + return SBI_EINVAL; + + pmu_offset = fdt_node_offset_by_compatible(fdt, -1, "riscv,pmu"); + if (pmu_offset < 0) + return SBI_EFAIL; + + fdt_delprop(fdt, pmu_offset, "opensbi,event-to-counters"); + fdt_delprop(fdt, pmu_offset, "opensbi,event-to-mhpmevent"); + fdt_delprop(fdt, pmu_offset, "opensbi,raw-event-to-counters"); + + return 0; +} + +int fdt_pmu_setup(void *fdt) +{ + int i, pmu_offset, len, result; + const u32 *event_val; + const u32 *event_ctr_map; + struct sbi_pmu_hw_event_select *event; + u32 event_idx_start, event_idx_end, ctr_map; + + if (!fdt) + return SBI_EINVAL; + + pmu_offset = fdt_node_offset_by_compatible(fdt, -1, "riscv,pmu"); + if (pmu_offset < 0) + return SBI_EFAIL; + + event_ctr_map = fdt_getprop(fdt, pmu_offset, "opensbi,event-to-counters", &len); + if (!event_ctr_map || len < 8) + return SBI_EFAIL; + len = len / (sizeof(u32) * 3); + for (i = 0; i < len; i++) { + event_idx_start = fdt32_to_cpu(event_ctr_map[3 * i]); + event_idx_end = fdt32_to_cpu(event_ctr_map[3 * i + 1]); + ctr_map = fdt32_to_cpu(event_ctr_map[3 * i + 2]); + sbi_pmu_add_hw_event_counter_map(event_idx_start, event_idx_end, ctr_map); + } + + event_val = fdt_getprop(fdt, pmu_offset, "opensbi,event-to-mhpmevent", &len); + if (!event_val || len < 8) + return SBI_EFAIL; + len = len / (sizeof(u32) * 3); + for (i = 0; i < len; i++) { + event = &fdt_pmu_evt_select[hw_event_count]; + event->eidx = fdt32_to_cpu(event_val[3 * i]); + event->select = fdt32_to_cpu(event_val[3 * i + 1]); + event->select = (event->select << 32) | fdt32_to_cpu(event_val[3 * i + 2]); + hw_event_count++; + } + + event_val = fdt_getprop(fdt, pmu_offset, "opensbi,raw-event-to-counters", &len); + if (!event_val || len < 8) + return SBI_EFAIL; + len = len / (sizeof(u32) * 3); + for (i = 0; i < len; i++) { + event = &fdt_pmu_evt_select[hw_event_count]; + event->eidx = SBI_PMU_EVENT_RAW_IDX; + event->select = fdt32_to_cpu(event_val[3 * i]); + event->select = (event->select << 32) | fdt32_to_cpu(event_val[3 * i + 1]); + ctr_map = fdt32_to_cpu(event_val[3 * i + 2]); + result = sbi_pmu_add_raw_event_counter_map(event->select, ctr_map); + if (!result) + hw_event_count++; + } + + return 0; +} diff --git a/lib/utils/fdt/objects.mk b/lib/utils/fdt/objects.mk index d9f1eae19292..03800f96d74d 100644 --- a/lib/utils/fdt/objects.mk +++ b/lib/utils/fdt/objects.mk @@ -5,5 +5,6 @@ # libsbiutils-objs-y += fdt/fdt_domain.o +libsbiutils-objs-y += fdt/fdt_pmu.o libsbiutils-objs-y += fdt/fdt_helper.o libsbiutils-objs-y += fdt/fdt_fixup.o From patchwork Fri Mar 19 22:13:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456059 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=bv5JbcJa; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=FBc/BHPo; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J8b2qWcz9sWK for ; Sat, 20 Mar 2021 09:14:23 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=aBnf1E2tvYfxELQwVeQFy6Cd6weADvWnoz6a5hXAEg8=; b=bv5JbcJapyFO3+5YdeKqVfrTs XENJLTUMqfew/5ftZdVXNQpck7foszNzancX/Td8hw9yXcurgOHZFAFcKD1VP6Rub8KFwyQkHyuH+ C3ktVIMD0TUYAbZtCRKeP2Vq1k//Xp1hSO/cifl+jAKBTPKI+BLvsj+v0cIvkLuPUS156czTnSgnp Db3M6RZ2JklCKgwtj0pF1RjDv3r/XXZ4uSMTpxMfxJI9tADucSETr9+1AaEZQavc5Of7xJEr5moOo 8rXLOqjRnGVdpzAAKrGLxvdtgcQEqRDVQNIEKYZHQ7w+SZAjap6Og1J9LRv9NcD8jDcMkj23rjXp0 xDc25hcww==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNq-008Fbn-Au; Fri, 19 Mar 2021 22:14:18 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNJ-008FJO-1R for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192026; x=1647728026; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vh1IjQ3AE8du6vbyzCNKgTv4VklqgIuCd3g2hvFlWMg=; b=FBc/BHPo51VY/rzK+DDcgOGmy8eifc/s5dOE+u7zPNpS9Cx9xro5rbl8 QjBhSS+7Z20Ta+Jw1Btiwt1I4qiZ3Z1F/9Dfjq7fPc0TSjGDs9PAUfTnl vtSx714wiWLNUkD5/x8SyYHgW93uCg14g8PxMMEAKtmi/m802eIME8w85 CAmLNivXBHabcPp4ELBxmlBsDtR0mSBY7+Mmm1t4OIbNR3HKKgnXUsuMN 3NJvFX7Li35h+/hm/2/mD4A0zgqkJNdiZcvwg2vKFX+uKwUGoE7GLWMdt W2YgHhjsOGLbvRaoEdzmwEGAAjowjiZjuDsoiTGNSJHgZPFcalOT2K4Gj Q==; IronPort-SDR: 99eUc1PaQmn0t/gQrZkAebQ0nJQfb9+fScqSlwceQmJleI9M6rPFVjJsZmdy6cXQCc6ckC3lew Y9o8cJeRIrwVI8o1wgmgLLAJPRrK1+fwGaBd3G9uipbUMZBxo3BILkaRkFR0Mqo5r7w5lYhfnZ m3fyjYdJTbXcWXchrIz/shurwsWAyVx7ZeBqGpP8hCBvgTQxgdmcwah67gbCS49Wd3wnFKJ1pT pYLHhX6EX/bi/dExvtD9kKE882uzQqhPwYOkjVhJFbzFwHf+MC57nMUihr89nGmnGOQ0A0XTBE Rew= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713912" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:20 +0800 IronPort-SDR: bvm59OqVZZ41IB9qw0Iq/l3lZkFeJC2fcKTG0IPp48zPjAwqZz7lHp88B3/esW48gg6hicYLY5 TZqB5qBFLjlAiMHgleBpbMfyYwmM/zLjWybq5/7G1dkaVcaA0wqGwa/ugF9XYPhxKfidYAmzgT AXjlxxkV7sZ0b8dwnTzD1zQWUjcPP3viMl9DPrOj/TUaa79j+nJC0eqUEwZx3ShfWshOAzDyP6 BQRPf+9vd2Sn0X2YwScLnLTThKidgdfBmaNhjOLkXMM9/K8lrPKTvgUMFt8Khs/VHHKL9dJZDk ETmm3uIdzCU1sIJGikP0cF/r Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:52 -0700 IronPort-SDR: 7pz1lyyTHihZNzpPeq2sqJ5l/iGZIqGCBPuF8IRmSo5v3HCjOdfCtQdNODjNtuyzGiWPyVujtO oAb8wsQPIgWRTwdaATFnUmP+xoJnfgzzWYWpih6RRxzhRTNG1AOM/L+wtq3SYamlZJKAZslzYL q6QYa7C+X+F7tX2x33iB7NGKHzLbFdhv1p42O3rLCR9sH1u+L5WLcsofoO5Bxe9a5bhZupuIBo odUQ2heRd+pqs+QJRulzmse2Z3amWhVMwT/AHjuyLyLPeNlOgY2gncViMk8qVWnPuaJlM2G1M6 L3I= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:20 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 12/14] lib: sbi: Implement SBI PMU extension Date: Fri, 19 Mar 2021 15:13:03 -0700 Message-Id: <20210319221305.2138412-13-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221346_733994_95B79C62 X-CRM114-Status: GOOD ( 19.51 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: RISC-V SBI specfication 0.3 defines a PMU extension that allows supervisor mode to start/stop/configure pmu related events. This patch implements all of the functionality defined in the specification. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org RISC-V SBI specfication 0.3 defines a PMU extension that allows supervisor mode to start/stop/configure pmu related events. This patch implements all of the functionality defined in the specification. Signed-off-by: Atish Patra --- include/sbi/sbi_ecall.h | 1 + lib/sbi/objects.mk | 1 + lib/sbi/sbi_ecall.c | 10 ++++++ lib/sbi/sbi_ecall_pmu.c | 73 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 lib/sbi/sbi_ecall_pmu.c diff --git a/include/sbi/sbi_ecall.h b/include/sbi/sbi_ecall.h index 63ef866ba2d4..9500d0430429 100644 --- a/include/sbi/sbi_ecall.h +++ b/include/sbi/sbi_ecall.h @@ -39,6 +39,7 @@ extern struct sbi_ecall_extension ecall_ipi; extern struct sbi_ecall_extension ecall_vendor; extern struct sbi_ecall_extension ecall_hsm; extern struct sbi_ecall_extension ecall_srst; +extern struct sbi_ecall_extension ecall_pmu; u16 sbi_ecall_version_major(void); diff --git a/lib/sbi/objects.mk b/lib/sbi/objects.mk index d9068b707854..7096f245ae0c 100644 --- a/lib/sbi/objects.mk +++ b/lib/sbi/objects.mk @@ -20,6 +20,7 @@ libsbi-objs-y += sbi_ecall.o libsbi-objs-y += sbi_ecall_base.o libsbi-objs-y += sbi_ecall_hsm.o libsbi-objs-y += sbi_ecall_legacy.o +libsbi-objs-y += sbi_ecall_pmu.o libsbi-objs-y += sbi_ecall_replace.o libsbi-objs-y += sbi_ecall_vendor.o libsbi-objs-y += sbi_emulate_csr.o diff --git a/lib/sbi/sbi_ecall.c b/lib/sbi/sbi_ecall.c index e92a53930460..bd51c7f796b8 100644 --- a/lib/sbi/sbi_ecall.c +++ b/lib/sbi/sbi_ecall.c @@ -11,6 +11,8 @@ #include #include #include +#include +#include #include u16 sbi_ecall_version_major(void) @@ -144,6 +146,7 @@ int sbi_ecall_handler(struct sbi_trap_regs *regs) int sbi_ecall_init(void) { int ret; + struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); /* The order of below registrations is performance optimized */ ret = sbi_ecall_register_extension(&ecall_time); @@ -164,6 +167,13 @@ int sbi_ecall_init(void) ret = sbi_ecall_register_extension(&ecall_srst); if (ret) return ret; + + /* SBI PMU extension is useless without mcount inhibit features */ + if (sbi_hart_has_feature(scratch, SBI_HART_HAS_MCOUNTINHIBIT)) { + ret = sbi_ecall_register_extension(&ecall_pmu); + if (ret) + return ret; + } ret = sbi_ecall_register_extension(&ecall_legacy); if (ret) return ret; diff --git a/lib/sbi/sbi_ecall_pmu.c b/lib/sbi/sbi_ecall_pmu.c new file mode 100644 index 000000000000..6a473f733e64 --- /dev/null +++ b/lib/sbi/sbi_ecall_pmu.c @@ -0,0 +1,73 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Western Digital Corporation or its affiliates. + * + * Authors: + * Atish Patra + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static int sbi_ecall_pmu_handler(unsigned long extid, unsigned long funcid, + const struct sbi_trap_regs *regs, + unsigned long *out_val, + struct sbi_trap_info *out_trap) +{ + int ret = 0; + uint64_t ival; + + switch (funcid) { + case SBI_EXT_PMU_NUM_COUNTERS: + ret = sbi_pmu_num_ctr(); + if (ret >= 0) { + *out_val = ret; + ret = 0; + } + break; + case SBI_EXT_PMU_COUNTER_GET_INFO: + ret = sbi_pmu_get_ctr_info(regs->a0, out_val); + break; + case SBI_EXT_PMU_COUNTER_CFG_MATCH: + ret = sbi_pmu_get_ctr_match(regs->a0, regs->a1, regs->a2, + regs->a3, regs->a4); + if (ret >= 0) { + *out_val = ret; + ret = 0; + } + + break; + case SBI_EXT_PMU_COUNTER_FW_READ: + ret = sbi_pmu_read_ctr(regs->a0, out_val); + break; + case SBI_EXT_PMU_COUNTER_START: + +#if __riscv_xlen == 32 + ival = ((uint64_t)regs->a1 << 32) | regs->a2; +#else + ival = regs->a1; +#endif + ret = sbi_pmu_start_ctr(regs->a0, ival); + break; + case SBI_EXT_PMU_COUNTER_STOP: + ret = sbi_pmu_stop_ctr(regs->a0, regs->a1); + break; + default: + ret = SBI_ENOTSUPP; + }; + + return ret; +} + +struct sbi_ecall_extension ecall_pmu = { + .extid_start = SBI_EXT_PMU, + .extid_end = SBI_EXT_PMU, + .handle = sbi_ecall_pmu_handler, +}; From patchwork Fri Mar 19 22:13:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456060 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=YpT48HQS; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=XUSfAcEC; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J8f6Zcgz9sSC for ; Sat, 20 Mar 2021 09:14:26 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=CdOQIUP5SsfjWd/n3qq+GjKEoAZqdIqGLPfE5xOF9v0=; b=YpT48HQSVWSQdS+Fvs9bb9Me2 1dVgegLouT0DVRnJdIfz23zQGC25TD89p/mU6UCAESopHHNy0dEwm3ztyQrP5P3HpIg14O8T4AUXa 5//brt/DULd3Lq8zYqrn17tfBdI1HKRllQYhpXtFZCTOg3PjTLXsQSUQK1DH65NWWZnguVDtoOkL1 eSX/V44Ne+8BpAGFDuj8zQQKju14tnfWBvOSonSfccLUaGOIF/fAwxEifqra3zETs8G+qMVQ6elwX 4vNB/9KvAx15LNRmTh1tM6xBlRTsQ6iomZ37QaG/7TQGe7mye68vejp3mr7sXGN6Pyyk2Wu7xNSHv HB+mwfrrA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNu-008Fdy-BK; Fri, 19 Mar 2021 22:14:22 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNM-008FKT-KS for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192029; x=1647728029; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=01nO1sYWwMXB+f4dIpPDOBw1xwkRPukVJf3DM2y6iyQ=; b=XUSfAcECAW8FiVnILn0XXIIq82WiLvCDrRvccOa394LV2zEsiMQ3+5Hl fyrSo41i/Q1493FDn9I6V349u8uMfiJapdDrfGf+1Rd/RYa8zIuSr5dl6 HkowhDMpOrkqwYmln+biVPvwfZkHuBoKloCxRO0xdfLcbFmc6WoZiOpm8 IHZbd0ddveKiKlpV5m2sRLswjTKrWeJtlHtK7gakOoZ0NugU3+atVok6v TG8+T9vK3WJmjBmDBjNc0Tu6d+MlJfknMKifcCwj0QwNzsuJCLgE078J/ bJ/XXJrIfLLMT1r8OSnCNHNGtOuKJPQVF2RQgHFdJ8qCQ2NwLjn+UCYbE A==; IronPort-SDR: mIr+9YjyuzMFVr4Yui/aj5xc/6PD+BC8nor9s3U4MHCIwyA02PTU/CmfB+8UHuDkuyZS3HA5AC BE0EoDpyh1ppOLxT1oEw7zU1GzkAd5XxT+XBtt9rsUc/Mgxe1D8E4izETeV4Y1x8veTvpUdKeb WY8Eca2xVgmthQpFKHiTPYJLG4q08UZGBFCYTR6RmpDI6uxi6+9+MH02884KKdvvNoYzG72QA0 16lf9GnDdo5MFKtKMuVo455rSG2LlupEe9i8yS9hPsfoTWEWgMgKZHU4+L8aSp3EgiaWHBlVq0 /FQ= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713913" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:21 +0800 IronPort-SDR: KXP27b5JDHvCiYwqjgtmlBJEFQW4ZSp7nsbZH3VJr24JR6L5cOPPVCcIqp69/TuIsNy1w61orT rdrKgkkGSky6yktdRtXXFGXJcZVGfRQbFKCTnsAklYAbPjyaAQQv5pQF/n5V77HaLs19dfw+d9 WoCXjY4wQcdD0TR4nng01zFN5SU2w5ZnD62PIXWFmyTXPU1dEIoTIMAsdZwmdQhpPjODLBFEhk 2L0480I4rMxdnAt7q938t8PNLap7okUhoPwchJ3gZKOU86WVcnRUhvhS/Ir0mL9EK+K8nrwv0r KYRdqWQ2o5o07EhibOpf1nF/ Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:52 -0700 IronPort-SDR: lcRGncrJovXZSTmckdu2DQ1mNtgCmuExy+IsNPZGBlfkeVDtaTiMJR8z1pNwZTIfQMexpNjvav tj26DqlfBzyA6MqnW7uTTva3pr2GzWvFa4j/vj5yGUMS0LCdvvgC0GDXQYPJqBiA7v9JR8gYtB QG++3xrpmx4IpQnN+MkYdw73KC1ODh45Ng6mZMIRtbpFov+CjUl+zyn4n64DmHCzqBwImV8S7u cfAieGwLu3Y4zdxulKzmQuE4MCH7c+8aSTS2v4v8JTbPMP6BxWXeYCbuWVsJVyCgyt8PzulE9L vxY= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:20 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 13/14] lib: sbi: Implement firmware counters Date: Fri, 19 Mar 2021 15:13:04 -0700 Message-Id: <20210319221305.2138412-14-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221350_119809_AE24187E X-CRM114-Status: GOOD ( 16.21 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: RISC-V SBI v0.3 specification defines a set of firmware events that can provide additional information about the current firmware context. All of the firmware event monitoring are enabled now. The fir [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org RISC-V SBI v0.3 specification defines a set of firmware events that can provide additional information about the current firmware context. All of the firmware event monitoring are enabled now. The firmware events must be defined as raw perf event with MSB set as specified in the specification. Signed-off-by: Atish Patra --- include/sbi/sbi_tlb.h | 1 + lib/sbi/sbi_ecall_replace.c | 2 ++ lib/sbi/sbi_ipi.c | 7 +++++++ lib/sbi/sbi_tlb.c | 36 ++++++++++++++++++++++++++++++++++++ lib/sbi/sbi_trap.c | 9 +++++++++ 5 files changed, 55 insertions(+) diff --git a/include/sbi/sbi_tlb.h b/include/sbi/sbi_tlb.h index 48f1962d7dcf..680fcc758072 100644 --- a/include/sbi/sbi_tlb.h +++ b/include/sbi/sbi_tlb.h @@ -33,6 +33,7 @@ struct sbi_tlb_info { struct sbi_hartmask smask; }; +void sbi_tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data); void sbi_tlb_local_hfence_vvma(struct sbi_tlb_info *tinfo); void sbi_tlb_local_hfence_gvma(struct sbi_tlb_info *tinfo); void sbi_tlb_local_sfence_vma(struct sbi_tlb_info *tinfo); diff --git a/lib/sbi/sbi_ecall_replace.c b/lib/sbi/sbi_ecall_replace.c index a7935d97300d..83544bb6e05f 100644 --- a/lib/sbi/sbi_ecall_replace.c +++ b/lib/sbi/sbi_ecall_replace.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ static int sbi_ecall_time_handler(unsigned long extid, unsigned long funcid, int ret = 0; if (funcid == SBI_EXT_TIME_SET_TIMER) { + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_SET_TIMER); #if __riscv_xlen == 32 sbi_timer_event_start((((u64)regs->a1 << 32) | (u64)regs->a0)); #else diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c index b50735e4099a..cd998ac7acfa 100644 --- a/lib/sbi/sbi_ipi.c +++ b/lib/sbi/sbi_ipi.c @@ -19,6 +19,9 @@ #include #include #include +#include +#include +#include struct sbi_ipi_data { unsigned long ipi_type; @@ -61,6 +64,10 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid, */ atomic_raw_set_bit(event, &ipi_data->ipi_type); smp_wmb(); + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_IPI_SENT); + if (sbi_strncmp(ipi_ops->name, "IPI_TLB", 7)) + sbi_tlb_pmu_incr_fw_ctr(data); + sbi_platform_ipi_send(plat, remote_hartid); if (ipi_ops->sync) diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 73f59e8681e2..36b21a74a713 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -21,6 +21,7 @@ #include #include #include +#include static unsigned long tlb_sync_off; static unsigned long tlb_fifo_off; @@ -39,6 +40,8 @@ void sbi_tlb_local_hfence_vvma(struct sbi_tlb_info *tinfo) unsigned long vmid = tinfo->vmid; unsigned long i, hgatp; + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_HFENCE_VVMA_RCVD); + hgatp = csr_swap(CSR_HGATP, (vmid << HGATP_VMID_SHIFT) & HGATP_VMID_MASK); @@ -61,6 +64,8 @@ void sbi_tlb_local_hfence_gvma(struct sbi_tlb_info *tinfo) unsigned long size = tinfo->size; unsigned long i; + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_HFENCE_GVMA_RCVD); + if ((start == 0 && size == 0) || (size == SBI_TLB_FLUSH_ALL)) { __sbi_hfence_gvma_all(); return; @@ -77,6 +82,8 @@ void sbi_tlb_local_sfence_vma(struct sbi_tlb_info *tinfo) unsigned long size = tinfo->size; unsigned long i; + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_SFENCE_VMA_RCVD); + if ((start == 0 && size == 0) || (size == SBI_TLB_FLUSH_ALL)) { sbi_tlb_flush_all(); return; @@ -98,6 +105,8 @@ void sbi_tlb_local_hfence_vvma_asid(struct sbi_tlb_info *tinfo) unsigned long vmid = tinfo->vmid; unsigned long i, hgatp; + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD); + hgatp = csr_swap(CSR_HGATP, (vmid << HGATP_VMID_SHIFT) & HGATP_VMID_MASK); @@ -126,6 +135,8 @@ void sbi_tlb_local_hfence_gvma_vmid(struct sbi_tlb_info *tinfo) unsigned long vmid = tinfo->vmid; unsigned long i; + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_HFENCE_GVMA_VMID_RCVD); + if (start == 0 && size == 0) { __sbi_hfence_gvma_all(); return; @@ -148,6 +159,8 @@ void sbi_tlb_local_sfence_vma_asid(struct sbi_tlb_info *tinfo) unsigned long asid = tinfo->asid; unsigned long i; + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_SFENCE_VMA_ASID_RCVD); + if (start == 0 && size == 0) { sbi_tlb_flush_all(); return; @@ -172,9 +185,32 @@ void sbi_tlb_local_sfence_vma_asid(struct sbi_tlb_info *tinfo) void sbi_tlb_local_fence_i(struct sbi_tlb_info *tinfo) { + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_FENCE_I_RECVD); + __asm__ __volatile("fence.i"); } +void sbi_tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data) +{ + if (unlikely(!data)) + return; + + if (data->local_fn == sbi_tlb_local_fence_i) + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_FENCE_I_SENT); + else if (data->local_fn == sbi_tlb_local_sfence_vma) + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_SFENCE_VMA_SENT); + else if (data->local_fn == sbi_tlb_local_sfence_vma_asid) + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_SFENCE_VMA_ASID_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_gvma) + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_HFENCE_GVMA_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_gvma_vmid) + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_HFENCE_GVMA_VMID_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_vvma) + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_HFENCE_VVMA_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_vvma_asid) + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_HFENCE_VVMA_ASID_SENT); +} + static void sbi_tlb_entry_process(struct sbi_tlb_info *tinfo) { u32 rhartid; diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index b7349d2c914e..3b540ea7f76c 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -230,6 +231,7 @@ void sbi_trap_handler(struct sbi_trap_regs *regs) sbi_timer_process(); break; case IRQ_M_SOFT: + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_IPI_RECVD); sbi_ipi_process(); break; default: @@ -241,14 +243,17 @@ void sbi_trap_handler(struct sbi_trap_regs *regs) switch (mcause) { case CAUSE_ILLEGAL_INSTRUCTION: + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_ILLEGAL_INSN); rc = sbi_illegal_insn_handler(mtval, regs); msg = "illegal instruction handler failed"; break; case CAUSE_MISALIGNED_LOAD: + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_MISALIGNED_LOAD); rc = sbi_misaligned_load_handler(mtval, mtval2, mtinst, regs); msg = "misaligned load handler failed"; break; case CAUSE_MISALIGNED_STORE: + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_MISALIGNED_STORE); rc = sbi_misaligned_store_handler(mtval, mtval2, mtinst, regs); msg = "misaligned store handler failed"; break; @@ -257,6 +262,10 @@ void sbi_trap_handler(struct sbi_trap_regs *regs) rc = sbi_ecall_handler(regs); msg = "ecall handler failed"; break; + case CAUSE_LOAD_ACCESS: + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_ACCESS_LOAD); + case CAUSE_STORE_ACCESS: + sbi_pmu_incr_fw_ctr(SBI_PMU_FW_ACCESS_STORE); default: /* If the trap came from S or U mode, redirect it there */ trap.epc = regs->mepc; From patchwork Fri Mar 19 22:13:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1456061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=ImlgVfzI; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=A3/QnX20; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4F2J8j5PJYz9sSC for ; Sat, 20 Mar 2021 09:14:29 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=9c0vTTXbkpzCOBM1noJqM563Q/gDOH48aLWN/2sHDr8=; b=ImlgVfzIl/hQmX+MnFqE6C8lQ T1Ch+hkuVxV+vKF64J7+ndh6H63TQobFtRKAyyry+5a1HC3L1TGs+FwfzUAjKKbSMAs3mPhLHUxny +PyQG4/3yrSM0M1tW2FHFz2eQlheTneVUBArF8koMjOEpxkMvWH0Tq/r06pe6CN2kogBbM/6u+Mm3 nyWrA8P04yrcGxGK4qK/oZORG9Ga6fHPnMw05wAFiyvq4KFFOyCXMVEOHp39mmAq8lNqRzx4qAGQf 96wecTDbC5F2lJVeppb7fseXrhnZBXJ1LVXOH4yxwbEGDStl0A7FVBtbGz/otP7ATOKBAkBPT+K4p v6/xXs12Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNx-008FfI-PZ; Fri, 19 Mar 2021 22:14:25 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNNNO-008FLJ-D1 for opensbi@lists.infradead.org; Fri, 19 Mar 2021 22:13:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1616192031; x=1647728031; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AOJ0dPyN3wis/cuNLRy6nQce34A1o3HU3tq0Y0NIgns=; b=A3/QnX20beQveoRHOjPi4cS3Aba1uqQxCQ4GV957aoiF6ydvwg11WzMj kBk0wD9B+SgiMf1ZX12aqZ0LidYyTQas67G9pg9nz3/ZX+48Y8bQZrtMB abVZIvvCUG0toDBn1NxWIcIahDrCAady+G7Xf7ztL1qt0H4JsIUjh8wa+ lkOXTQoA9m4a96sIiUce9tQhoH+bzfSkayP2Cq+KYT6+kXY7AR2VAqWZv NY/+Da4kmbP/41FlA3eV16JjbKaUuJYk4a4lGnSo+x3JEgQ9CE3ocwtKR 8OxixKigvVYMD6BRG/wUwGZ89pCVDo9pcyH8hBgjQnnKA1oA9xpQQHcfD A==; IronPort-SDR: vSkJiR1D0VGMYUFX/scJX3Q7PvyqRSsSNeUux8MFsXSFVl/l08R0bIKp42figaPj413Gv5Ow1b H3cXbflx3/+3U4kFST/G/z09inDpbPuTCQ3K1Ltbud8XNgYS5N3Q+wRnRdcCF9ryy5iCdrMyEm qrKWAFwAKvF2osi0/SH5NA5wZ37ed+A96NQMQfpPRHKCux0uWJUkLRUAyN9xAe+u8qUxfB2QLl xs0sojIPbvq79P6LT/sHn87Wez+d69jIgPT3VfJCd5Y9/JkZtqbVzNIxkN4/5BhtylE4UUWCxl QsM= X-IronPort-AV: E=Sophos;i="5.81,263,1610380800"; d="scan'208";a="163713915" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 20 Mar 2021 06:13:21 +0800 IronPort-SDR: ISvRwummMGInxcP1M/POoM65mgKyQ7QvMbPhQ16s9uG+2kYXlw94SQPtGvwQmIeOABiBNW4Y0g XfblFojMTvYGZs47Pdk27yoocxtpxP8c+L1L4mG6iTSfPN0Xb0tN93qXkN6A8SvyClSPgC1f/8 iBABCl7sqqWGOriguWPksVpxszgm1VcW3a44TgqxSLInieR+JDlyLK/Giq0iMzeSdexV94ZOwB YxKKgAVBRaN36Vkj1EfCgGAWonYDRTJCk5N46SNR4yY+tDD7zGIOIv2228IqD7mfEWmxeuZYKR 4lTR6c3HDsiIUcV6PWwwPorF Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Mar 2021 14:53:52 -0700 IronPort-SDR: 3I0+midp1+3qqIq+MMZg7FWUesrxznBNXswNiWjLPV1+Tn686IWhMsN2w/HJatQ8D0/7l7xP/6 FjH3hH08qDo40S8U/H8NlqkcVgEHazmkzvEEzjz/N7/RDxJnGtqHHKZjj8ElMFLB7GM0C/MzHe PHcGSZXHtaxAFBx0Q1FpVvcgT4158GP6Zbn4NYvq4kGzM0x4H5Jko82s8+CleKdSRbQi/WmCCN inkLMOpcV+fMuGdDG2hh2+NmVzKGqYzSR7vqVVwIq6AbWvXvlH5PVbhFS31V6jMb6BpJQVA3jj aPg= WDCIronportException: Internal Received: from ind002560.ad.shared (HELO jedi-01.hgst.com) ([10.86.48.105]) by uls-op-cesaip01.wdc.com with ESMTP; 19 Mar 2021 15:13:20 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [RFC 14/14] platform: generic: Add PMU support Date: Fri, 19 Mar 2021 15:13:05 -0700 Message-Id: <20210319221305.2138412-15-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319221305.2138412-1-atish.patra@wdc.com> References: <20210319221305.2138412-1-atish.patra@wdc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_221351_150257_02A24402 X-CRM114-Status: GOOD ( 14.61 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Add PMU support for generic platform. Generic platform solely relies on the device tree to parse all pmu related information. If any event is not described in device tree, generic platform will not su [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [216.71.154.45 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add PMU support for generic platform. Generic platform solely relies on the device tree to parse all pmu related information. If any event is not described in device tree, generic platform will not support it. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- platform/generic/platform.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/platform/generic/platform.c b/platform/generic/platform.c index 8c1e06f1244c..03f8bca2cb2d 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -204,6 +205,35 @@ static void generic_system_reset(u32 reset_type, u32 reset_reason) fdt_system_reset(reset_type, reset_reason); } +static int generic_pmu_init(void) +{ + return fdt_pmu_setup(sbi_scratch_thishart_arg1_ptr()); +} + +static uint64_t generic_pmu_get_mhpmevent_value(uint32_t event_idx, + uint64_t data) +{ + uint64_t result = 0; + + + /* data is valid only for raw events and is equal to event selector */ + if (event_idx == SBI_PMU_EVENT_RAW_IDX) + result = data; + else + result = fdt_pmu_get_select_value(event_idx); + + /** + * Generic platform follows the SBI specification recommendation to + * compute the mhpmevent value i.e. + * xyz[0:19] : event_idx + * xyz[20:XLEN] : event_data[0:(XLEN-20)] + */ + result = result << SBI_PMU_EVENT_IDX_OFFSET | + (event_idx & SBI_PMU_EVENT_IDX_MASK); + + return result; +} + const struct sbi_platform_operations platform_ops = { .early_init = generic_early_init, .final_init = generic_final_init, @@ -219,6 +249,8 @@ const struct sbi_platform_operations platform_ops = { .ipi_clear = fdt_ipi_clear, .ipi_init = fdt_ipi_init, .ipi_exit = fdt_ipi_exit, + .pmu_init = generic_pmu_init, + .get_mhpmevent_value = generic_pmu_get_mhpmevent_value, .get_tlbr_flush_limit = generic_tlbr_flush_limit, .timer_value = fdt_timer_value, .timer_event_stop = fdt_timer_event_stop,