From patchwork Thu May 27 00:30:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484366 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=evfnjYHN; 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=Ie/rfeFs; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7z8094rz9s24 for ; Thu, 27 May 2021 10:31:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nvwXiQ9QwVg0nibZtN2MrMoaIgiYeH8iD/3z2ik87uU=; b=evfnjYHNbfPGCp c7L/qu3CwoDyTlzBNb3z8BNclxdifWGXRCEwS02nNZQgqtkwIFndhHBTw8snNI7jr6I+jHscqzcs4 x9V/lcOHfmklinD5CMdIVfECDQxNj82ZBosD1+TrKJYVDaCX6gg7z69Fts8rn+uEd1Nj/W9KcKnnU x+wDCchW4Oqhy5kokow9aCPu45m8zYhv4lmqJRovkKlMgkCLTixJUUitwmZrSuWmkkeQ3D3kwLl11 09Dr8fY/XWtlcunNGgrL6suqqiMlrPH5YHyF/00rEMO+JwllJxuIJi9kQq2QYIXKrJdLeszlZiYA/ X+OV6HwSDx5ZsLOzDbqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vY-001ALP-Ut; Thu, 27 May 2021 00:31:08 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vT-001AJC-LE for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:08 +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=1622075481; x=1653611481; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZvWoSsciAV2fx0wXl3hlZRB1JjNGBbHAq198zpY9uh8=; b=Ie/rfeFszmrQkBx30+JLAJ9f7fmrKQRTQ/aMaUCGdRFSow9SzT3M80wx V+NhuRgA8Luhm49ZId/CGEu+XfhQ2YT10RRAxdgcDWHpxSVvGbXrue8ca 2tILZhC0YTCxTDXkt0igI0y7PAZNZHK8d5RVCL4iBxX1+jMGXaZ2bGC5T 3zPKmZYmoJSqbHPSELrxO1V1yNpvAkCZjJHZ/4y7nmG6N8aacuwAxlqgy cb8mzsgY+JVqOFYr37JNeRbZVlHDXNjZftqGQQTut30szFGJ2F59HRTQB P5heYzPzqElXpztc1GuYlGtIjsuYmEgUPf8SFRnr/q4e50aCkqD8wVzII w==; IronPort-SDR: bwhYAuBDJol6nXg/RWQRFYUpiuPl6Il5y7bnyo4eXhLXMUI8jjLAR+Sj+2F2WJPXQZmXr1HuLC hTmClfAJbg2kTAXlFYjCrVmPOXJyjlf6KVteOCJ1QhsKVqpOX0/gkKhKU6KbEUCH96LLS5Pt5W QXn4V8jKYZuFDuz+kR+vYqamJBiw9BfzYuObnGDthlQy7FwLYpNfPU/SkBknl0u4TYxtqn1fzj JrHyVClMgOtpGIwBWjW7hr7azqFtUyqLAqXqdlDpycd9k/QcrSfpUii6Q1cEneM2EU1cxdcCnD WIQ= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477694" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:20 +0800 IronPort-SDR: mhiUUeqT859C2ihQbmKCVac8CEoe7XSiUYZKi67aeLNLkELg5mqr3Vp3/gqK3NxlqWWalicDP0 SzGa/tyq9CbbliSYOhg3cA6af5pPrLgIsvPGT9CXdgJVJrAkh3vFzqAWvq1QQAxS9/CQcmJPQ1 F6aiZ8C4qWXhznJYgF9dIislQ3bD1sBtQ7dlkXFv9/nJi4nMghfFbFoE8WcZU/EuRynBuykBw6 ncCoVv8HaJgWhW9o4BLmF02YkPWVZv30DPFVST+GKrxfo/OP31X0rdoiKI9W6Khv8HRVr++0K5 SbUNXKsZT02LbBQqyjIdg2kI Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:28 -0700 IronPort-SDR: cUtCNqdoBFmcy4DKl3kiNsTSiNGCOcDaqwumwHaUqsq65IomjR3kXyrglmQe+bSnhN/8ulAW3M s44PmeMKEl0nuw4jZ2WbYQtPLWc9Gp9zKcUXcoXzEbgVZMNKSeGCg5LyEka+mdW8m6ZX3371/j 3Ue5+BPrggHpRVoA2GNAM+0hYlCGJzutfQQT478tcw6PZiuIBYzLQqZv0/ayNCuNSw7sz2xYTN iL7a/JsnY7HbkugENrTBG6U2hz/M29fk/SVtX8yWXXr1rJDaVIZYUUYDzsgFjsb2+QUVIySWCw qmk= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:01 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 01/15] docs: Add device tree bindings for SBI PMU extension Date: Wed, 26 May 2021 17:30:30 -0700 Message-Id: <20210527003044.889681-2-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173103_780417_92DFDD76 X-CRM114-Status: GOOD ( 19.55 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 Reviewed-by: Anup Patel --- 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 Thu May 27 00:30:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484364 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=EZqIp4/O; 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=Dk7AYA38; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7z80LBrz9sTD for ; Thu, 27 May 2021 10:31:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B56MWesKRy6iKwZXCmoWrYF+85mzzP0PdzXZit4AQRg=; b=EZqIp4/OS43CST pZWCtC3GPinvpgCx053mWHgD1hYBFTL0DTR/uej5ecxYMKwrc3cmAuUExqubjcXaqDvwPVucru+1X Oj4WLmvltFWOlrn0h7R/hUdjhoDjpUtfzJr74jfo5jZtM9Q1VbAD6h5roQfglqXFtFJQ7yWhgkllH AglIcHKyyO1ZY4Un7jYeTuCrOUp9La04NFkT1TIhk8TGGe5NbMjrRoFJUp+x40ZvhAIXJZY1dmQ3q rPFxlm2VaceT7pE4b3P/xBvfXgDIxCocas7JSc0Tb9LCyrSC6EOdQEIKfSVJhruOSa9Qp8CCZSuzX Z88Fz81f0thqUPx4exXQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3va-001AML-CR; Thu, 27 May 2021 00:31:10 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vW-001AK8-7o for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:08 +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=1622075485; x=1653611485; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=E40qBaUsagnRkyPKED8OeYtM2cAUAEB5NZah3HuhPDU=; b=Dk7AYA3864aqcBGN0nEy62zJZop5NYiLJDxfeOmtRWxnB90/Ihi3bn4e B26UyerPAtiQf76LQ1G+/Zs7doRNfLGxp5kH7E8VuiFNUOunRZUSbB+QG NcyntkAHkTe1iB8r9lbCrMnwtJtEwDVr8RWs75L0TmHw6wm1SvivC4shS FrpebBF+AyXYt7pNQ3zNrsoRZkuIuOMX43TDVEcTkGHNZ2YUZW3bWRUTo 6GflTyJOIjlRmWJRx94GvAF36rGywxzKHRgqEVd1tRd9i1q59L3d0Oipa B3zZZidH6L7zdhP9cGO6TWyc9kTysVqCdyJk5Ad+ubrZraIr2sP5y6JEP g==; IronPort-SDR: JxpfVSxyNEWPSdbTnuoIi/zsFS/6JtloHzsEu2Sx4uBnolO7jiwPf4KOTr2gPHUg6nv6QkzNDR KktehGZ/XwhhCy8acKbvx8L6pOUCYJPipgTIKC+DuImc7GDpQf4mH5RFaYjXAYNHnjxspHwKkm UK/XAb5oGocg9ZF2sY/1nQM9qib35JCdYoZN6QLW89TJ3OG5DL4sig0FDWzSKYTegJxLt9+MKc 7sHq4YelJjpgrds6yxRsN6vs8P6ws78Jbq1tkPN6eZrE/4vcQOwsu8K0XuwphGYPblY4jzwfSN M5c= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477706" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:24 +0800 IronPort-SDR: 4L2+O8E6poCGwtZc/vtZvKK20lFBAEmoe9P6dtUbWPeT+0xm6U+CR47boh+EEXxWgayyD5OrjO hQICICwjEsZzJ05mHMIpYbeMLWCnN2Bi8M1ZCXtyoNLYOkXlFxtN4vV9cPLvrNqZQdVIx0yeNU AP4eVsuhmHhpm5vj1Qom8O7t+5GjuT4J94m3LMgm+m/zjghnU52I8Ns4tg6Sg8IptqPQUvIiDN 53/I5+2oJ3rq77aNglprgO0EOubNgceyBxMTdFl0McfC++R9Jq7j6ytSxD01tdUMgrxtWqqYMB 7iIJMNAVYz0Ri+akpD6F5843 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:31 -0700 IronPort-SDR: J03xmhnXJ0hzd3fwwlc9kbukeqCr592C2cE1x3ju3k10R5pOBKVJhokHBjlz0lABTJY2Ocdz2V gNfFGi1oby4/RSgYdLLOAJYf2PU83AykNsR+ONO7DWytU5DYdw6lhwiOHsK3nFqXuE/CIJEint 2UWkKIFTNDW9WtmX3ge3IdLfdRRcMwvekb4DPTRBigKBa1gPPP3Qm7m0TmpDijoau1Yb40FvzU ASnf/T+zRRSOOMD2VM2mH0gQtpQU4GTpgk0y3aT9/LEvrhahMYTCSkJxUpI2EZOVoLLoC/vYdm NTU= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:03 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , Anup Patel Subject: [PATCH v2 02/15] lib: sbi: Detect mcountinihibit support at runtime Date: Wed, 26 May 2021 17:30:31 -0700 Message-Id: <20210527003044.889681-3-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173106_360401_F4428973 X-CRM114-Status: GOOD ( 11.62 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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. Reviewed-by: Anup Patel Signed-off-by: Atish Patra Reviewed-by: Xiang W --- include/sbi/sbi_hart.h | 4 +++- lib/sbi/sbi_hart.c | 11 +++++++++++ 2 files changed, 14 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 de59b1431b5b..8fae20891bde 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; @@ -421,6 +424,14 @@ __mhpm_skip: hfeatures->features |= SBI_HART_HAS_MCOUNTEREN; } + /* Detect if hart supports MCOUNTINHIBIT feature */ + 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 */ csr_read_allowed(CSR_TIME, (unsigned long)&trap); if (!trap.cause) From patchwork Thu May 27 00:30:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484367 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=uI4WSAxY; 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=c1MYSl8e; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7z80Hrtz9sPf for ; Thu, 27 May 2021 10:31:16 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8QipcpMWw5bt0RLXtvx2gwjWelqTZzOkET5VPEcJx0o=; b=uI4WSAxYzC/sr9 MvGVnfZOHVav66Hie4rMeX+ZJc0Pe8KnRvAwxYQbiXjkjbUio9HmWif+NP4IEq6fE4FonrK2i/sNH Gfs5swfFs2Lcze7MK7l/a3yZZu4aIj8UVs7Ezf4Lm5E1YFM0XXgsxwl6m7tHiOU/zMTYwHzYdmzh9 oiqjyARbCCIzQmGzmSXVLBScmVadGJoD+NyQFmPYsyvQI8kdw7KUy8jp/QGHYpt/LyvrI5bP3hQkS /4Dvt1oUVY+sWg/9KKZoy9+ghTVbhh2bavnjoBWK25hrPwJ7T+Imns1kIEG72Ph976wHX+dnIZo9d a4faaJuPI3eT7IL+QSgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vb-001ANJ-Ow; Thu, 27 May 2021 00:31:11 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vY-001AK8-Sv for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:10 +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=1622075489; x=1653611489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3A6rukzSZDsdn0beciRftCJOojiJV/vpms2iVPNqWDc=; b=c1MYSl8e6Jnih6plc+NENrXD5RiPWf524mFLTLg+FYQsHshznnpQiEpY LsHXH2bzQOV19FPUzhpMlEBDlK192NlpkSiLOP+P5iEbmPUbeQccRNxyP w3ICwPj2jLyWQ7zWf3CwLBDAossswkKogDlaiV4ORY8CEanqsAI9IMoGf 0pTd246M6fpCjxn7QOgF7Zj8wHsCRrWWRYXJPOAAB4TjlWJAyo3p8mNJu JqarfVTIy/p4yxxIreQeI26y5CoWUDWUSkZsvi21J+mVaqLGT9yhPfcQm 1zrd+NO1HxCFquDsF7/moMi9e6G7Qr5LDfhyi8noUnMB4i6Ka4UVrcgZe g==; IronPort-SDR: tTdX9xLMIOaFm0HUQ3tlaDZim8uqHCmXQVvxQGbd9D5jy4b7mF6gzaNKNDidobWU7p/Vkw3zOo grmQxTD0eb1Y7AI+705SR/2mIm7CY2irIPm4+15H7S7ajMlrMyXJJDQI99EHT1UUMu6wbAIBWm ijLyt3G7DQQveRvAX5idESqtMtEET+o7GDzRzVrQnSUqZ6InSonHNCSBquQSI8WY/iFx51wJkQ YbgZSyLkLAxgFywWC4Z3AmXdmGmwypPR9hqgjTxDT3/FRHebiPxqaHdMn/ecgvliHQr6lLT9wf EkM= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477721" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:28 +0800 IronPort-SDR: dO5tE8Vr2sLJ6OjOOwhYbdFB4AFkMr7i6RLY5rIBlVKzY1K/Q8f9De9rd76SIt0gQPysT2W0cq g9qQP7OAt5Tcc6yW3mym+QfK1yepL5M7HQ1Vb95GLvp5XM0LeZ6NR5jN7sj7E3lVBo+zD//pvd EOR1k5UZvWDUy7OG8lHWyl4uffCMiETTO4CIUNIMcN8pFnufiYJOpi5sspjFSWXGXo7qEpkZSn g5OtyFZpBnuMu9vbVy3qhfAIystOLVoYGYSd9NqDcWnNfN1Fa8UBtnE1D8OHk9agUI1LyeVRjb RYVBrgGkfuZyLWKiRhojC+La Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:34 -0700 IronPort-SDR: VvU8bcsz2O+0LwMW2wb6DdyfS973KCYFVAllLhuK4H4Qsfizi96zmrQBUOc30NjYXSW8Xu58A+ +iY4FssQhOVn/gOkOBpJh3RKhkflfqFD0hfZ3y8+N2FZ42EKQ5aqx3yt6EW9EdTqxQrkhVvK05 eeeA50teD1saM/iKVsKzYZpMefmonYyuJIv3GwcFjCc2aT0NROzfj0J4SzSlXmJQWtNQHx3wC1 huZx8a6Oycfup+4hu8brFxtP0hex0JUHjSQaNVJevtpI7CW7wwW/aQ3q2RDYz1vANUJFA+l18K Qdg= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:06 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , Xiang W , Anup Patel Subject: [PATCH v2 03/15] lib: sbi: Remove stray '\' character Date: Wed, 26 May 2021 17:30:32 -0700 Message-Id: <20210527003044.889681-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173109_020865_8C603EC7 X-CRM114-Status: GOOD ( 10.36 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: Reviewed-by: Xiang W Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- lib/sbi/sbi_hart.c | 2 +- 1 file changed, 1 insertion(+), 1 dele [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 Reviewed-by: Xiang W Reviewed-by: Anup Patel 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 8fae20891bde..e5e5781ff412 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 Thu May 27 00:30:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484368 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=UUKqBWOt; 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=EfdCgfjF; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zB5mkZz9sW8 for ; Thu, 27 May 2021 10:31:18 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=DY2/9m9zhuYEKUPkfx8x11jfNNpMQH5tp7HReifW6cY=; b=UUKqBWOtVgz6XJ TRmVLJ5tone6l5dOTrM5G5pXKrozpW9ZHQyY3eWcrOdzUIKPY62EgpUzEEcaYk8wB5sv6qolk3YTE TMngevE6X1n1uU3Xxu8KIhXKu13fXdqiBc6rvQjMuMMYEopLGN6CNtOZkXkovi7au4+yAAiC4OeYX dQxsy1pxZU0heiEZwEwyimrRSw92wkq967WLFeMseppUY4A8wa4x2iOhVhIU2lDR0tmlTBaxGAPAD 2tgKrlBikJZ4VtGuTzm+2+Ue6wUmhE9kwMeFjJqw6gqSLwtaFwuFz9cGJBQgwK+7OJ1PpS1E7kG2e kYBaaRV1HqjHTNITbFYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3ve-001AOz-CA; Thu, 27 May 2021 00:31:14 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vb-001AMq-BT for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:12 +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=1622075493; x=1653611493; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eY8wrl3uyShsVj/VxPw5AwpYHdbJ7IdS8rr/7eGbzis=; b=EfdCgfjFQjVgXiCEYf0RahRyeQ7d/VBFO2V/YzHcodhjIa6J+Ko4Hwy7 dFN6gkiceOw/FS1lR78caiAoFaF95l6hNdBoaTjfM6ATy04sJy8QHYywe IzvTQ5YPVju5lNoWyk/mIBiU6qL5vFRk+d6JYbhe5mOAH85n6+3mWEGo4 mZINu3QW8IzELJDNNlIXJsU+4sQ9tCMlUCNS381ADG3fgTkxXNLR6Qs7b eW/mub5WPBi0zcwEgy85xSVxkoCEas+/TS/7Nodxi+KCN3Qm+OJqOCkYC ogkrPL4yf1ojF2LaCqvN6FbFH2UDvbHWZ85n+yd3BYNdO9QqPsNlU0LtX g==; IronPort-SDR: L3XjgtGdvMo7RuKJY4XOfWvXUpHeqsPMohvm5wy41fu10JiLyLHygNK/LboHqbPTiiym3xPP3H Zp8ilCbBPj8xs6HjXuzlor8WX5853WwCXaDwPZ8lvklkkNP3L+2UKWTubFLRPuyi9WpPa/ytBz ktE59euQ79l/qspHuVTu0NXppgdNLIejUHb1mWIkQuVqSyRk5NrQmrxv+L20eBkvQomBifwAv2 hKyYtJdSCIBwwOgSSk6wU27iJGgv0sjytYAMxh3/q8zB12+UKT7P3m4Jn4Ml/Ka49+8+fX+rzo XmM= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477733" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:32 +0800 IronPort-SDR: SISD995Jweqb8uoZRgDQUKT51u+yw00Z/L4vO/OnQJb7N/not9RnkfNH61Kph9KVTrt4LqsDaY ix7lnvzk2BYvcejsnXL8F0JhJcS7cREWbwA8Aj+iWyhbwCZe1LcuL5hMh2pMfMYtDJ8IzqZzNo H35MHNHE4TviFs7o7+hVgWHcnq+/4u3GfFHN3aa6uRoYZ10gfBES/rl/9cwyUg8gOdl8Av5a2v i9DLfeCQ7X4oW6JZUnO+zBH7lNlRbpj/fcI9I5/Hi8wcJG4gzg7WLzGrAe1oaAawcFNPsNAzzI 1eltTGo2+8iH60TsPtFkXcra Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:36 -0700 IronPort-SDR: ZUlbZoOx5jbZUCyR6iqCNmZ+dvq4yV6WVPXDZ+rpufboG0dmaxZ5yT/GFw6aQbQNkqfG71fmzN TquKDT1gsd/y7ctqyXQxfnnOFK56lS7KBZ4DzXrSNUnDRz7onmmB4N2K8b2m7jpylOuRrUnYfp M2NDddIsL9JLJVVKGFbEBFJAlB1IWBT+d8Be33qAZKCZSbYH6vs6BZLwDuLD0w5/X4VtvSnNBr +yE4ONWb6zvdz8zCE4Bdreq7J+xAZK3Txf7KWJQ3nHLZ1uMH2tBovWIWiogVhmfngNG5niHstQ Rz8= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:08 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 04/15] lib: sbi: Detect number of bits implemented in mhpmcounter Date: Wed, 26 May 2021 17:30:33 -0700 Message-Id: <20210527003044.889681-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173111_483522_0C1E7FDA X-CRM114-Status: GOOD ( 15.46 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 Reviewed-by: Xiang W Reviewed-by: Anup Patel --- 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..0c18ef9325b2 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_mhpm_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 e5e5781ff412..0d5b7b8d3509 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 mhpm_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_mhpm_bits(struct sbi_scratch *scratch) +{ + struct hart_features *hfeatures = + sbi_scratch_offset_ptr(scratch, hart_features_offset); + + return hfeatures->mhpm_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) + return 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) + return num_bits; + } + 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->mhpm_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 Thu May 27 00:30:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484369 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=4Wbco9CH; 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=W3TbZKys; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zF3NVyz9s24 for ; Thu, 27 May 2021 10:31:21 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Cr/8wNSFOlHDHzLbgNPj2hEQV2FDohg4WOlHsIyTPsQ=; b=4Wbco9CHPJT8uL zbY+BeM9x6sI2fFEdNLcih/jbZrnmrPJdg9gjUqm/XyBtwx++HgAq1ZQvAO6KNFQyF55KYG11xcPp gdMAFwqHcyt7jifurWNRNj3Rzm8F1uXLGoXNLZMGCmY4eDPxtB96DLeua7Joy1q6QF60yvYDOBgPy saBPgL14LvE5SD3qcs21r+w6RaVuWI5IoaGuef6C4u5JtxHpPw52JKYmFCDxLIvXYRb2VAgbkR5gc Ete44Fu0BHcgu34usN3EB8C421UmIn2NG8A5laPSUIe271poykxQqn2/tk1ils1WIi0hjFCtzjAIQ IH+A9YLsM34fJTNju+lw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vg-001AQZ-O6; Thu, 27 May 2021 00:31:16 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vd-001AMq-IY for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:14 +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=1622075496; x=1653611496; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EZcf6/hUB6YSIhXwxyyXylHfz4/7cr75jtet9TAHHuc=; b=W3TbZKyst0lIlrkbXBGr/PzzaCPwBK3P8Ti6+BKfcrVd7LsbdOMxQR3W QxHxsvgPZ2Xw5iGV5+TjjBmzbLqD27hY2dZScJdR1Av+pq4jV8oWbdtTo egC+hGIeR20EQ/O4+SmKijRcWzDV2rBHs3OPXN7Dz5MOXdTb7yXtc/E4p qtJoyfXIIvhTNHJ6DklvYEKxPPYqVsBdOmQF0XxYOm780fTWSCA2reKOf 598Lpb2D5X3u7G2T9j2i82210851M5JK9Cf6sUqRNjnO/MNXycpRehRDB lzy0/XRCsozJzN4pDnN7B46hbGGB2mP11libGn/ytBKPLxJi6tDOFe+7H w==; IronPort-SDR: FT+DgsFw6u7/zfjKkaSmMc0Cocd7mbjq3yK9sFMaRGtwU33zK1NSLTOjGXf0/KYZDxmMnkw+x2 Wg5QlOyWjleshf09UHWX1Yb8+BST2bZoIbT3jVmzYfum8IPnhOSfvoARkPJTAdy6PD8pINB/YD 3nX7RwalWx3fIEtOCFb5AVOsKliOOaV7IgYb/Bp89YHh1WiZUMnb1p3rKc2hiqjyqRHkrvIQd7 byrUj3cMfcCkkXIKj/NBPhEzeKLccmI476J4ZtTLwSipJcTc3hZLPX+t4V6XSqjdJ0qD49CiNN 0h4= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477744" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:36 +0800 IronPort-SDR: ySUYLDkKkiLvtGFwepgsd06Su92DfdN+Xgw7E+wJ/qsTxfKev85b/mopykIZUPBYDbnG7AhcCN bM7mM/IN7WhcEM52fQ/cm/M53YpBPEZcHskDo6KRFngsGmP+aQA8z+83Mlo7ccpKZkEuLcpsIB DcJgB3ayIvu38rWmR3HFY/fFlCDq3oDjbM27DXmw2zdUDEwVlEfsjFAfgYcEFI3Tf7wHnbVNK6 DkwmkLgm3Yuyad6i1LRR8fP87UVDMq0Ebk6X5sJgzTBMm4Wxb2coj+L1XMVaToa5vlV0R9zOyG 66yt7eCkvwxiL/c9X9E3GpE4 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:38 -0700 IronPort-SDR: YnjSy8VzQg47DXenjf4bRJ6ETUu/qA4dUZ0nQyAwzwyeSkce/SVbXdx0KpGdKeF6mpHjX9PhRT 4t+0YO6YozyPi4RNaTRUDanvRt0Id1soQOYgEK0nebut0i1WCEYakWEPwy3fkhTzi1ZjgIXsRY XiDGudP44UWWr23bD5kGENbX6ncJGJmmJruuknUQV9x8aAFZcUx06EQVUtymiPPjGy525E5arc qtgGSqFgwVfAdeQz0C0VVbH9i2SEELcFo00dJZGDhwq9QUwlPBX7LyTZkn5KY5AU+8AtFlFI8b nMg= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:11 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , Anup Patel Subject: [PATCH v2 05/15] lib: sbi: Disable m/scounteren & enable mcountinhibit Date: Wed, 26 May 2021 17:30:34 -0700 Message-Id: <20210527003044.889681-6-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173113_727355_CED3B13A X-CRM114-Status: GOOD ( 12.17 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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. Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- 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 0d5b7b8d3509..9f1ee20fa978 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 Thu May 27 00:30:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484370 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=YCeylPGe; 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=cCL12oQk; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zH0TJbz9s24 for ; Thu, 27 May 2021 10:31:23 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ep/v7TFDYmG7r7yJmYrFKp3p8ifJdZWqQDvKHdvb9Dk=; b=YCeylPGe3dQBeq YZyuTLG7PFKk041F2GOF0E1TEGYgYSTXh2jj7ixOfQqu16TRgsKafNrJ74lwBjscLE41bO+HR1SZx ilxOrHRLmPAvsPZkJUCYdTd4SJjNTkczPtdZ00It8kOelJ17Gl+qTOAo5704LR8OMqbloLNw6pGis yrtvb2AcKl4LkoneOkUQA6fn64LijZNAZ82JB6v2GpLVeiKMhf2j0B0xfdmkmh00HsQFQOJCRLV3Y YRi2t2FzvoCqjfZCrE/bXsv3IOI6l7Iy9ZmOmStoD5xZbgsBpUISKUr4aoT+B7q6S/bCAF0YcTHQN SkqOmR3HP7bQmBs4P2Pg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vi-001ASD-EL; Thu, 27 May 2021 00:31:18 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vg-001AMq-AR for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:17 +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=1622075477; x=1653611477; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2Uy8LOJBKl39QWbNVvdF99m9s4V2r/iqvfma8ORR2NI=; b=cCL12oQkqtKTGPXLxWCl9TQtRYclRD/vajryfWJJ1TksludsHmsMCPxR +QDXd6vvz3Cf/KVEjXouQZtPVBpGqdmcjDkB/jPQK/Hggr4Nri4HhMfIz saqzA5IPnNVQxVZ2iBSPTnOEnOA7sJQCHNrJtY/0/Dky8i28ZhwoxQGo7 ed1z/aJFNrXACJRctgcVSOmyx7MO4h3E/xhh8Q3IQIQMZRTVc847vPS+m mtXiuWSNuaODgH45Qf20Zto+X0179gAuedPyBIFT7ZFd/i2hp460ya+GF wbdYuh0uLA3GfxvTyb7AtqUbDAfWI77ZtE5zH8r1IgDH3In1YVmA3yqXj A==; IronPort-SDR: X7KfAyGT8lKr5W6X+Oz9YUR5qbadps4FXAlofsAK0iVnTVrR2/iTyYXueSyCN6SCsbsvArYSU1 OmPYAXbynHedhilnEp0mB0NHQ+q1568un8lIoPiXcOyY1akV9m92Fq/Vi4fDtTjEDoz7A6XAyI NVvDS4jfDm69F2C/1CUbrq3UK1SjfwcqNNqkg4qTrD+wP1T5BAf1VJTIYm3TfFPgOZxOFqlxTZ R1Lp+uLlCaqvIN2gIeZETSe4kZO3UcADZ3koHH3/ONZx5gn4d0FBrMztcd+2jYW9zNQaVDPkWz DgU= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477758" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:17 +0800 IronPort-SDR: ynjKTj8+CI48gWBzqlyjo7UGyvRO9xZDmUICTlwGERisYlNwoRqUqbdmQEkTOEQzC7IgEREknN O61u8OA2G7kOp9zwy9TnD2jKTj4rUCJvs3ngMC7huQekIqJct9vMwbxSuyrNn7z5K6oVZKeGaS gbuImGyf/fWhLpM4guACt6SaHUY0uR9uTaRnqV/7ztx1IMFmMrsFsoVO5kPt/t4bRfQNMiw2VO S/GdkNn7XPXmVybLj2+VneWYtPPnuR4wGZjMQQEvOAsBMFXHCc/BMFtECos1CAuI96wk8qewpJ uowhUfNHfcvKdPK1j7cwPHub Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:41 -0700 IronPort-SDR: AZH+z6amznTH+EBGjbVavAfZI8NHa5K47Qt8b/0BWHqBBMjMI9Uut1J9y5iftct4AyeInsb9WK ePJHi8tssobe4uqe/XWCr2gVwzaZgtpcZ1ZyX0bvkGgK4SBasRyOpxdkIdL5jlBbdUW6gImRwy alV0H9IQ5WkhVXGv1HHICTvHl5W9hPXoO7012+QR3VMVQnwexQQ1pcj1uOmbNaehRcKcSx+0Hh qGOYpuvubIwYqpsyUzWnGEDCcWbGbTAsH9yDXxMsm5J062f9KU6L0gQtCWaRLMIi0UsTuJNvQI oeQ= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:13 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , Anup Patel , Xiang W Subject: [PATCH v2 06/15] include: Add a list empty check function Date: Wed, 26 May 2021 17:30:35 -0700 Message-Id: <20210527003044.889681-7-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173116_439845_021D3E21 X-CRM114-Status: UNSURE ( 9.74 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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. Reviewed-by: Anup Patel Reviewed-by: Xiang W Signed-off-by: Atish Patra --- include/sbi/sbi_list.h | 11 +++++++++++ 1 file changed, 11 inser [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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. Reviewed-by: Anup Patel Reviewed-by: Xiang W 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 __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 Thu May 27 00:30:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484371 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=oUeoH0/w; 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=A+luq2H8; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zL57BDz9s24 for ; Thu, 27 May 2021 10:31:26 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dYHyL0kOJFOvHRy+y6GEgRhojn5m5qk8XUO5GUh2xKs=; b=oUeoH0/wIZ+q7d o2Ok9TAYzEPgqo2mmelarHrhhYTMOdI02ISown5EvS/E1gbNg5Ey8rrdM7zn4PjGtaPOAh5l2RXcm DokA9K0mUXSJ1T2s8cKHhf+7LtO7p/tDi50WJUW3fJc/1cRCLh0msENCzEnyPJ3kHK76TVul+hDC+ Af7JeJKXSMUrgWPNdZrLu5BR085xB0o6WJSeIRzsc5k9NSFj4ZRz5FuNx6ab2kJ+GOXWqp9tN58i8 BdxxlDZwyqdT8bHA1B4ywnpZb+rHTQlxo5rRAuvWQfJV0rXz88aXNVJRpjJlUVAIuEnqTDNQfEV85 jlLc2u4+N+4S7vXLNL4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vm-001AWt-9D; Thu, 27 May 2021 00:31:22 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vi-001AMq-Ov for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:21 +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=1622075480; x=1653611480; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7MXNlK96ewVuZgP3GvUT4wsPFyoNom4iaX6qUykaMS0=; b=A+luq2H8UXOiksiSytNuFMfLUJk2LdGDdHNTjzOn1haJrZAorKMyF500 2y0kTt1Dma2CpN46wj+Js/5YZDNdu9qC4Asi+KGuZOAj+pSvTSRXuodr4 GqtJWu3L3yH2HMQWoISc89xPJLYgjDy494IOTzOp+wkOmNsDGLPiRGn0+ 5YczVDg4I6kX+yTSpzg2OTerwgXzcFB843rveMhvlrtaPs6afdAb9WDrK WEdW9eyA1qiF5vyQEtZaWoBaSmwN/+e8Qn4RWd/NKrsqzxfNmqYYsny+F vV+KWSL76/2Xf7AEC3tjc1ppJy/w8W4nas8UxVIlE9D/S6iKVwPjE3lcI w==; IronPort-SDR: QzHNlwDcBE6CVniAHb68N164bwbsU9tdwt/S3l4xTIddsbEjmHy+YcPjvvRiSwrhweAiq2/A+J aCZSBCaMNsf2E8dLiubZd0K1myFmkkGMAENR+OnpwnrhF+jTrkVdtml/9vRU3QAASZvEi/JGjm zXLjPp7u/Ma8VAb8L2Use8ZzgjN8SlVqcOnERVV2hud/fddrkQNYY6JqpAUmum2766RDH/Cpil wC6iZCetkmeEf1x9BNGudoEhsc02c6tAt4T/Fc7WGfWyy5IgkgXGsMfwRpPFrYaR5oZ9UPxA7m GB0= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477769" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:20 +0800 IronPort-SDR: ptz43YwvUstKNflQsdSx9L49Ky5+dRtc86CBzQZy1/yeKsxiv7bazxlMt1aTp+nk6WVsnGluIw tMTNHmx97WMaNCnT3wZMlu4efQnHmi+x2w9NX/Bmqhn9ZUj76kGqOIIsXNedMbcWS1zj9FFh89 KNjk4WnUJwV66iJQwghMcibaW+V3b+61tc9+8a1n5xc/kBbJ7NNgCS2hiuUpaf9TS6zj5Ke/xp /V1K6vDLfiLbPW4WpGM0YLty/fO/KaWLDaGjSa0RUxkU9mR9b7WlBMKeKrz832A0LtL36upud8 EBEw/yWy/mIjCKnmFx0na/WO Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:44 -0700 IronPort-SDR: La7gQdokiW4RhDNEMVh1zzDtelaDG4ffqiCtu2CX7qSynspqCwWiYjC4sEpd6Ilp3DFgBpALOD Q/DirmQuas6gdG2BRLG62QvTKlk3FJdnbL3UP3vd7HT2ENioeJlUl3a9NCxH7dekgI5zjL9YmI sL9EFiT1GgoOgx7cKTBw1FnduVvruCuuMy5fw9sZBBz7ti0hSwjvymQRtPJArAMbNbL2BiTmOd FT9D6lFM/6sgZk5YO6tU6OxnP8FFdwP9RsbGs9Z99x5uDv/cfWIQ48fU8gZq6bT2TWBqxnrVH5 gnU= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:16 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , Anup Patel Subject: [PATCH v2 07/15] lib: sbi: Remove redundant boot time print statement Date: Wed, 26 May 2021 17:30:36 -0700 Message-Id: <20210527003044.889681-8-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173118_901494_6077923D X-CRM114-Status: UNSURE ( 7.99 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: Reviewed-by: Anup Patel 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 3f44a2b87152..65af5705f484 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -137,8 +137,6 @@ static void sbi_boot_print_hart(struc [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 Reviewed-by: Anup Patel Signed-off-by: Atish Patra Reviewed-by: Xiang W --- 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 3f44a2b87152..65af5705f484 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -137,8 +137,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 Thu May 27 00:30:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484372 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=rqUSoFu+; 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=OU1B9OUi; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zN1BLcz9s5R for ; Thu, 27 May 2021 10:31:28 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UAsT5igE1phaAyq+e3HVxpoQDfb/KXHrK4IHKlN/1XM=; b=rqUSoFu+2xhQSC MbGRhKBBaO5LgjFE1CixYIoowJvlG2TxLOYS0/jW76b0/AN5UTu6IUAoFgZrk3wEa+ngwPl5VN75O fQ+LGNzPYgl51SNICnLZvIvkKCx3BB1KaRwIBTVGIw83L6/lFxvid7M952qFA+vC0z/2eOMkoybKz vVtKV44hUaNuzyAa3Duzv0+xeUKgR+XWMa0UA32Pp0Boj1C23+0EDrPnSebToXTqngby+Mb6NdMqm aS3/6Sb/SJgNNDBm3+M3xQS4JLVqGfoel4wgGnLQ2+Z+iNpLIln63E1fLSjwiQTXD7OKTAEbd9Zih vCO6buVAefrUyUs4ZpGw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vn-001AYE-Pz; Thu, 27 May 2021 00:31:23 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vl-001AMq-CP for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:22 +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=1622075483; x=1653611483; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XQvRNhsK/E5/8s8NwJrUbIxyNt7aOjD7pUCTsyx57A4=; b=OU1B9OUiQenUd+DmMXxXE2yIvJE4TK+azJhL1WYU6yMG3TxugMHl6bQo 3gxBmxc2+SQWh7X3D7VRcy2BNyAeK/yLGXG6jbN30RMzTmFIMMQK+Zj0p hPoflBoBcIC2G2FG0kXIoZUlDc67bLyPx6RxVV1Wm0yNE3i9tSm5hxnNp /0lWOWHAVeWW+TBly1+K/MWLgE3063GZ9bLWV+bjPq9gaBQqZS6j+rK16 ed278tu3ARozg6Wg8VsK0cMXztbdnppzQJp3SuJXD6usjoEMXXWSt9GkX V+xyhQ7slqBXqlt++vaZhWk8mPQvz4IlalZsE7YP/hFLVGcBzRiDxIHZp Q==; IronPort-SDR: kWuLo/kLwhS8SVKfdASGNm1ouPOz1x/yY2htfjtAMT0c49xpipWcMgfmyKWvAFrDcj9nv7mVn+ s86ouQROyGYpCRvYm9sqnNym2IX+2Ake8gEXNoCTzZ0sW/3ROsafXZv1z3i3uYtSfKX4+nTpat TgYNh3cCP5xuz+M0BvVCDWrWsQUscfFhFRInSwqAObF2cf2XCgrQFph6hcNxDyJfYgUit0KIWD Bo3pRUZW/EWHIznBb7WJvFPB00/fyqZRm+50SaIK2CNRTk1lYcm8uFyZL/wt8CX7DN6tNla3cM eH0= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477785" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:24 +0800 IronPort-SDR: 0Ds/oxg9JyjL5Tlbk1Jl3DClnsx9HunFbPCX/R0j/qZGUDUA6CnPvRcVVMoeB5OPMjoV20Lemz yJQyLEFh2J06Gg3piow2M3nfOfclVYmjm1djbaVbiTOiONPuzuFKn0sGgg6WJazDUw7rULTX+S FNIhIlDO9OgUxxMK3nVCqSeqvtzgpd26MB8apXQCbflhrjswr0DbqEsa0WrM9RNjBIQgPhrmk3 yb2MCAAUkXb/24HLpFEzVd/SG6vsmeFXaLdCTVn2oW7AmBR3Oog5FY7BW2cUS6zu0+5B92HqkB 8pdsWQjR/9bd8jGrtSLahyLj Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:46 -0700 IronPort-SDR: KzQWa8cgNOrq1/PlIVpO28OL5e0AcIvlqpMBGTiZ5nZR45dmG6zMdvr+6IRQvGXsim9/PmSnTL nFBtrrbNF+J30SCXmYtawdAVXxtusVTqJGUtlZjjPh0x9F4ZFg+XsMz/yxEpmQKq1ez89JCg6w acGNxgJUU8Ge4w7KA+23p45zpEaaxe4gSFQOq6TJqPfHr0QsBOLnz2VplCOtxCEWNulqbpzDZx rrpMHYA4Cb1HF9ero/6W8RC0S9BIkmMsh0WQAsFYZxspUNYyTCj1A3GgFJYMmj/JQXHvFqFsde wI4= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:19 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 08/15] lib: sbi: Use csr_read/write_num to read/update PMU counters Date: Wed, 26 May 2021 17:30:37 -0700 Message-Id: <20210527003044.889681-9-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173121_516605_A6B075F8 X-CRM114-Status: UNSURE ( 8.24 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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: Xiang W 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 Thu May 27 00:30:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484373 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=a/g6klS0; 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=S7sGsPIq; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zR4CSsz9s24 for ; Thu, 27 May 2021 10:31:31 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CMCh6z84t6VEEDoEIOHMbo3Tsm0ZMezEFLD8elQUp1A=; b=a/g6klS05/i5uN zqmdTEHYqPWGOppPrI2xe6ekPBkYjfW2KDbg6vOAw7TXTp5MALwMMM/ArEWJHS3aJKKQ7yztDSqnc k6z8LrFg2AFHZih1dn53zr2phEWK4egniDhldlhn2Pi9LUBM6JEfa8oMHSmCWIABzaUq13mFfAMky PyHNRFGtcUR1FvWGtlKuA9IEvi4+ZGtdzty5NyvTkYj61BqkUJtTGfQzfqCAJbk+9xtGUlTYNIqXk +L8K5F7UuCmDRxtdpAUxiwrl93VsTx4fLELADwrFfnFSz9JM0kQmCTo/wd4tIAj0IRjniKmOa0uCM ADi52CC36EaeRspZugeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vq-001AaY-Ki; Thu, 27 May 2021 00:31:26 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vn-001AYD-VN for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:25 +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=1622075487; x=1653611487; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ECsGahwjVpWWW2ENAEmFlTs6FzLlukA/kVcO4ktoz6k=; b=S7sGsPIq1nPZsGw366IYI51vitmPtTegEHFBXiU28Mfu1Bvzn6XX7xPu Jh6lzaKPgCt6+7BeOo1sZnG+eedF0ffxfBsQSke+HV6zSFCJ6eCjyEJ0O VCXDDEvlHrmxdTqaf/rQPu+Toa3J8LV6v5iIpfdHUQC1mTXDeIF10gWgE ki0ksRgCvlxkxgEGHn1EvZ6QfGM64NKt5cpxqBGZidlONjMgCW35KvmWs jsaDwqDM1V5Ee4C/E6+eN0TpCFs2wwcCwTvk+x1X095tgkoM71JxZHhUf c1HB416T46u4l4didHAAjj+VWWarChk3zo3yPjne36Z/UKP/MJqooknnM g==; IronPort-SDR: Mbk/VAn2fwKFdO9CBglUY9GRsk0CMA+44+sLvL9WdC3/3Vm2CgTLvcDqT8M4k99dWeczgcP+Ni YX2to6EdVyBg6NIz76I3HmFVugRGKwLNhbCe6iQ+/h4VLz61V5z+TX0hF4KZz64x3TvcTzNXIx XuZm0aRswSiFvkjXK7Ckqa1wb6fx3JpUbA0EY9q/RNdb7RYRc9Vdp+8PJAPUWD4YbzWI4Con9K sN8xfBgd+4a39cZ6Y5atPQilbu4L2qXqhR0Z3ngEMAjQKlSSrf9XfHvZY04Ou5Mh0LCXWTgFI3 k8c= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477800" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:26 +0800 IronPort-SDR: wcA77nu//UsKtsxmpn+7uHNkxbrA10rouJZ1GrOflWTifeuTNB6LH245Sx42wCVYILyH5c4duD g5t2H1z0V0u6eN9ZUDxIgYnI7QimNyV7s+VbOkH20LKbK0e/oK+PgmFh7gHjJzMYCKpA34qp6/ hHJGD+QltyQL6OhEl86D+psRSVOonw+TqCul1ehctXZ7Yqid1UwcjUmp7bBlsnCFCpq7mINyxw e/ViXHMto2GHkDa7tQkWNlgjDm6F9t3sVMq93iLsuI8Bv7Za3dg4bt8YJA7lF8lpz1PkYVbqXJ BovsbR/7WEfwUgEYt5k3pNLz Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:49 -0700 IronPort-SDR: HcjfbWgyOWFZxs9sVM+d6Sbrg5RxeakFWvR7Ey6cKxvdi7oevJHywn+3dQLVCNxl4rio+59BEQ dLeyxTp6XERgwjrU03KbHKYA6EccggMlsJ2/ClabrwEFyqslcWLD4r9wKejstEU75vX8alvbMU ujAMhwYX7akJiiAo8D8CRf+jjDw7z4Y8kyZe5N+/CZoArJPnLHppxO/gtIgFTbi+BuL03fFEvx Q7pk0JpaHMkLy0MfV5bWmo1g38XGyrG45yPckeUE1zMdA/ydPy70xXXeDPQ/ExGvShq3mVpEHO B4k= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:21 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 09/15] lib: sbi: Add PMU specific platform hooks Date: Wed, 26 May 2021 17:30:38 -0700 Message-Id: <20210527003044.889681-10-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173124_097959_20B0143B X-CRM114-Status: GOOD ( 13.36 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 Reviewed-by: Anup Patel --- include/sbi/sbi_platform.h | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/sbi/sbi_platform.h b/include/sbi/sbi_platform.h index f8074d28db65..8e6caea6965b 100644 --- a/include/sbi/sbi_platform.h +++ b/include/sbi/sbi_platform.h @@ -89,6 +89,12 @@ struct sbi_platform_operations { /** Initialize (or populate) domains for the platform */ int (*domains_init)(void); + /** Initialize hw performance counters */ + int (*pmu_init)(void); + + /** Get platform specific mhpmevent value */ + uint64_t (*pmu_xlate_to_mhpmevent)(uint32_t event_idx, uint64_t data); + /** Initialize the platform console */ int (*console_init)(void); @@ -391,6 +397,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_pmu_xlate_to_mhpmevent(const struct sbi_platform *plat, + uint32_t event_idx, uint64_t data) +{ + if (plat && sbi_platform_ops(plat)->pmu_xlate_to_mhpmevent) + return sbi_platform_ops(plat)->pmu_xlate_to_mhpmevent(event_idx, + data); + return 0; +} + /** * Initialize the platform console * From patchwork Thu May 27 00:30:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484374 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=zLrJehPI; 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=LVddXw4c; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zX4X90z9s5R for ; Thu, 27 May 2021 10:31:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OnOKMl/l+r1BlMPcxMtdPf95PxfEvIgeNg/j0Mt28kY=; b=zLrJehPIPnGc20 biPDrQCJbJgJMDVupsh5ZrEGw6puUcJs5XWF/1xPs0+TLpB4Dy4C2I7URKTjQAxcQApfdM/vsxRcl +VUg/BR+JCdXJHrLQGvm43mlmAWT67w3MwUWLanlVrli8bPEQY8t8+nTYzgsyZh9sA6ejsLlN+sY4 jTlpG06rI1HN+Sy4VecaIbIa5VAjKDb/XDLDfz7HHndCcLANZzxB53g8b1Nn6KgxvD3gnJ1rKDj1q 49TW9qRbzpxDa6HqMkpF2LjcsewsnFdDys3k6+nWh5skrsjGaGdE0OEr2m1xQudVx8oYT1rS++y44 pieaFOLfQ5S/ENVadhAw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vv-001AgV-Qu; Thu, 27 May 2021 00:31:31 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vq-001AYD-FH for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:30 +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=1622075488; x=1653611488; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SmLUNJTzI/8O4rbOcKZf1GXNEajtjSjqNSBdjKIVL2k=; b=LVddXw4cetgLQsL7vjL5DPk457ADOWDxK4j6cpPD+rTuAl/OuyiqUyQr v5taNDLNefdqq+BgonBn4l6dTzKw4HDU4fsf6dy1Bnutkmp/JRRujIE9N rvl1R+YH2cKiUpCqKRwlW8VIFjCIX3ZFyIXuUCmC6A9+XuinISPJ2/lPu gDpdEPfdvCSP5/AGjYnh2gabfYcSs6hB/WKPczAIc28xS6RX+eH2KJF9N CmAA77EoDHVORAgigOiXghcfzR5Iw9gsNWQsILhrnJ2f0GTMGd/Uvdzhf Z8kkaaV7KFOW9ZohAWWyb5hPrbvQQrHj3IgxWOWSQm50DCIsF7sDqrd1g A==; IronPort-SDR: s8L4C8TMjf/ypxSsaPzYsKT59z+/Zr0uIPDSW6Be/FmW1WAnp8yVdhEaX1iFwONUH8/RmAtHxY Y9riLwHj5kMhe19e3qQn7fAjWTlSG1zDiT6EILZW4iidMz/03MPj0q0yWPUY2mwTFsVKewA9Q8 44nKP3KjnrB+E+yBrEOJ+t/+j4/Ly5LduY0V+EeDDsmEPzTcmPEYJXqho090k1uZwQFWKyY9d4 rtgs6wRFOoA5kloOiroex0ahevHX/1utSPwGjcneWPtUlQkTQVjKIOI8y0pQbmUG9HXZSTOehI sQs= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477812" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:28 +0800 IronPort-SDR: 3lXDbS1YFxRSFAeiw0T7hxzra9wkLSmVme/bw3rK9GWgPkgQM+My8vZ88+FcEdpu4MkEMsPy2j f6Fpj4D1Ita8QWVtJXTRIIp7UFpW7uEWx2luHP6spbmVgZQxlmkfrfvRbIfeGsW0gTQJMyS+V5 WRVnSqUFwxrNL321xSdesh9Wym1yGh+C/g+nLBfgZd3AqgVBwkW5QMp2F9gm2DMSkYf5PSnTX3 MNAVRMiBqjgqxoxT0W4GcCFLjVwjuoeQWk1DVLHnh0JU15RIrUrZ9PGFdocKOySyD3e3Qi34uj +G2sTWNWtOSrdnBdH0NpXSLM Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:51 -0700 IronPort-SDR: 0ZYAjVtqalUD5HAdk40PTrRyQdbLjNSfH3WM1fxDErKxda1+oOEcFFseLZMVskL1X3BmJvtRoR SbFXWdHZXri9Jdt36zpMDWdO7JC3CTiWBle7y2IyUWhOwe1O0CfTE7ew2s+LGSZEO+EMMbd6rH 36Z3kPRxY1kPK15+yOg79Mp8wi3N6iy38qZkfacAWrlYvFenzH0ugscVfTxow9ne56dYkRlM9N Mi2CexSCCcOWmvnG6i1PwnGfMXmKi9Jd1VHmwQlx0fclXLqNsyx9bzkDFSG7fbACyGwZOjwdCv Jj0= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:23 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 10/15] lib: sbi: Add PMU support Date: Wed, 26 May 2021 17:30:39 -0700 Message-Id: <20210527003044.889681-11-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173126_730677_A355E393 X-CRM114-Status: GOOD ( 27.32 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 Reviewed-by: Xiang W Reviewed-by: Anup Patel --- include/sbi/sbi_ecall_interface.h | 138 ++++++- include/sbi/sbi_error.h | 2 + include/sbi/sbi_pmu.h | 73 ++++ lib/sbi/objects.mk | 1 + lib/sbi/sbi_init.c | 9 + lib/sbi/sbi_pmu.c | 600 ++++++++++++++++++++++++++++++ 6 files changed, 822 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..8fc723bc212c 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,139 @@ #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_START 0x3 +#define SBI_EXT_PMU_COUNTER_STOP 0x4 +#define SBI_EXT_PMU_COUNTER_FW_READ 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 = 1, + SBI_PMU_HW_INSTRUCTIONS = 2, + SBI_PMU_HW_CACHE_REFERENCES = 3, + SBI_PMU_HW_CACHE_MISSES = 4, + SBI_PMU_HW_BRANCH_INSTRUCTIONS = 5, + SBI_PMU_HW_BRANCH_MISSES = 6, + SBI_PMU_HW_BUS_CYCLES = 7, + SBI_PMU_HW_STALLED_CYCLES_FRONTEND = 8, + SBI_PMU_HW_STALLED_CYCLES_BACKEND = 9, + SBI_PMU_HW_REF_CPU_CYCLES = 10, + + SBI_PMU_HW_GENERAL_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_SKIP_MATCH (1 << 0) +#define SBI_PMU_CFG_FLAG_CLEAR_VALUE (1 << 1) +#define SBI_PMU_CFG_FLAG_AUTO_START (1 << 2) +#define SBI_PMU_CFG_FLAG_SET_MINH (1 << 3) +#define SBI_PMU_CFG_FLAG_SET_SINH (1 << 4) +#define SBI_PMU_CFG_FLAG_SET_UINH (1 << 5) +#define SBI_PMU_CFG_FLAG_SET_VSINH (1 << 6) +#define SBI_PMU_CFG_FLAG_SET_VUINH (1 << 7) + +/* Flags defined for counter start function */ +#define SBI_PMU_START_FLAG_SET_INIT_VALUE (1 << 0) + +/* Flags defined for counter stop function */ +#define SBI_PMU_STOP_FLAG_RESET (1 << 0) + +/* 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 +241,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..b3010cc5c1ce --- /dev/null +++ b/include/sbi/sbi_pmu.h @@ -0,0 +1,73 @@ +/* + * 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_ctr_read(uint32_t cidx, unsigned long *cval); + +int sbi_pmu_ctr_stop(unsigned long cidx_base, unsigned long cidx_mask, + unsigned long flag); + +int sbi_pmu_ctr_start(unsigned long cidx_base, unsigned long cidx_mask, + unsigned long flags, uint64_t ival); + +int sbi_pmu_ctr_get_info(uint32_t cidx, unsigned long *ctr_info); + +unsigned long sbi_pmu_num_ctr(void); + +int sbi_pmu_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask, + unsigned long flags, unsigned long event_idx, + uint64_t event_data); + +int sbi_pmu_ctr_incr_fw(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_init.c b/lib/sbi/sbi_init.c index 65af5705f484..143b98f93c02 100644 --- a/lib/sbi/sbi_init.c +++ b/lib/sbi/sbi_init.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -252,6 +253,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); @@ -353,6 +356,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(); @@ -393,6 +398,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(); @@ -516,6 +523,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..ed519dfcc860 --- /dev/null +++ b/lib/sbi/sbi_pmu.c @@ -0,0 +1,600 @@ +/* + * 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 + +/** 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_ctr_validate(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 pmu_ctr_read_fw(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 pmu_ctr_read_hw(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_ctr_read(uint32_t cidx, unsigned long *cval) +{ + int event_idx_type; + uint32_t event_code; + uint64_t cval64; + + event_idx_type = pmu_ctr_validate(cidx, &event_code); + if (event_idx_type < 0) + return SBI_EINVAL; + else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) + pmu_ctr_read_fw(cidx, cval, event_code); + else + pmu_ctr_read_hw(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 void pmu_ctr_write_hw(uint32_t cidx, uint64_t ival) +{ +#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 +} + +static int pmu_ctr_start_hw(uint32_t cidx, uint64_t ival, bool ival_update) +{ + 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); + + if (ival_update) + pmu_ctr_write_hw(cidx, ival); + + csr_write(CSR_MCOUNTEREN, mctr_en); + csr_write(CSR_MCOUNTINHIBIT, mctr_inhbt); + + return 0; +} + +static int pmu_ctr_start_fw(uint32_t cidx, uint32_t fw_evt_code, + uint64_t ival, bool ival_update) +{ + u32 hartid = current_hartid(); + struct sbi_pmu_fw_event *fevent; + + fevent = &fw_event_map[hartid][fw_evt_code]; + if (ival_update) + fevent->curr_count = ival; + fevent->bStarted = TRUE; + + return 0; +} + +int sbi_pmu_ctr_start(unsigned long cbase, unsigned long cmask, + unsigned long flags, uint64_t ival) +{ + int event_idx_type; + uint32_t event_code; + unsigned long ctr_mask = cmask << cbase; + int ret = SBI_EINVAL; + bool bUpdate = FALSE; + + if (cbase >= total_ctrs) + return ret; + + if (flags & SBI_PMU_START_FLAG_SET_INIT_VALUE) + bUpdate = TRUE; + + for_each_set_bit_from(cbase, &ctr_mask, total_ctrs) { + event_idx_type = pmu_ctr_validate(cbase, &event_code); + if (event_idx_type < 0) + return SBI_EINVAL; + else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) + ret = pmu_ctr_start_fw(cbase, event_code, ival, bUpdate); + else + ret = pmu_ctr_start_hw(cbase, ival, bUpdate); + } + + return ret; +} + +static int pmu_ctr_stop_hw(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_ctr_stop_fw(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_ctr_stop(unsigned long cbase, unsigned long cmask, + unsigned long flag) +{ + u32 hartid = current_hartid(); + int ret = SBI_EINVAL; + int event_idx_type; + uint32_t event_code; + unsigned long ctr_mask = cmask << cbase; + + if (cbase >= total_ctrs) + return SBI_EINVAL; + + for_each_set_bit_from(cbase, &ctr_mask, total_ctrs) { + event_idx_type = pmu_ctr_validate(cbase, &event_code); + if (event_idx_type < 0) + return SBI_EINVAL; + + else if (event_idx_type == SBI_PMU_EVENT_TYPE_FW) + ret = pmu_ctr_stop_fw(cbase, event_code); + else + ret = pmu_ctr_stop_hw(cbase); + + if (!ret && (flag & SBI_PMU_STOP_FLAG_RESET)) + active_events[hartid][cbase] = 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_pmu_xlate_to_mhpmevent(plat, eindex, data); + + if (!mhpmevent_val || ctr_idx < 3 || ctr_idx >= SBI_PMU_HW_CTR_MAX) + return SBI_EFAIL; + + /* TODO: The upper 8 bits of mhpmevent is reserved by sscofpmf extension. + * Update those bits based on the flags received from supervisor. + * The OVF bit also should be cleared here in case it was not cleared + * during event stop. + */ + csr_write_num(CSR_MCOUNTINHIBIT + ctr_idx, mhpmevent_val); + + return 0; +} + +static int pmu_ctr_find_hw(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_ctr_find_fw(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_ctr_cfg_match(unsigned long cidx_base, unsigned long cidx_mask, + unsigned long flags, unsigned long event_idx, + uint64_t event_data) +{ + int ctr_idx = SBI_ENOTSUPP; + u32 hartid = current_hartid(); + int event_type = get_cidx_type(event_idx); + struct sbi_pmu_fw_event *fevent; + uint32_t fw_evt_code; + unsigned long tmp = cidx_mask << cidx_base; + + /* Do a basic sanity check of counter base & mask */ + if (cidx_base >= total_ctrs || __fls(tmp) >= total_ctrs || + event_type >= SBI_PMU_EVENT_TYPE_MAX) + return SBI_EINVAL; + + if (flags & SBI_PMU_CFG_FLAG_SKIP_MATCH) { + /* The caller wants to skip the match because it already knows the + * counter idx for the given event. Verify that the counter idx + * is still valid. + */ + if (active_events[hartid][cidx_base] == SBI_PMU_EVENT_IDX_INVALID) + return SBI_EINVAL; + ctr_idx = cidx_base; + goto skip_match; + } + + if (event_type == SBI_PMU_EVENT_TYPE_FW) { + /* Any firmware counter can be used track any firmware event */ + ctr_idx = pmu_ctr_find_fw(cidx_base, cidx_mask, hartid); + } else { + ctr_idx = pmu_ctr_find_hw(cidx_base, cidx_mask, event_idx, event_data); + } + + if (ctr_idx < 0) + return SBI_ENOTSUPP; + + active_events[hartid][ctr_idx] = event_idx; +skip_match: + if (event_type == SBI_PMU_EVENT_TYPE_HW) { + if (flags & SBI_PMU_CFG_FLAG_CLEAR_VALUE) + pmu_ctr_write_hw(ctr_idx, 0); + if (flags & SBI_PMU_CFG_FLAG_AUTO_START) + pmu_ctr_start_hw(ctr_idx, 0, false); + } else if (event_type == SBI_PMU_EVENT_TYPE_FW) { + fw_evt_code = get_cidx_code(event_idx); + fevent = &fw_event_map[hartid][fw_evt_code]; + if (flags & SBI_PMU_CFG_FLAG_CLEAR_VALUE) + fevent->curr_count = 0; + if (flags & SBI_PMU_CFG_FLAG_AUTO_START) + fevent->bStarted = TRUE; + } + + return ctr_idx; +} + +inline int sbi_pmu_ctr_incr_fw(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_ctr_get_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_mhpm_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(); + + csr_write(CSR_MCOUNTINHIBIT, -1); + csr_write(CSR_MCOUNTEREN, 2); + 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 Thu May 27 00:30:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484375 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=Zy9VbwZD; 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=X+2xicGX; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zZ2Yygz9s24 for ; Thu, 27 May 2021 10:31:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LEGA08Nwu5tAH6l3oidL6Tty/5IXyEuqvjstQQLqza8=; b=Zy9VbwZDAnQVo0 3j46T2oF/EutoNV6nHZagYvHuxW+pS1nEKwEAR+NJ7gQlrOQKVIAw8iELVEOQoFxdxOL65bCp2M8k rswSFUsJWFmefyaO7hQWTjeAIvb3fiaKj9T320pKpF8gcyVa/Rgj7mxI/KiulUwz/TlgeL6FRQCGC 2Rgmz+oVh6yF2uyI8vDiXc9pyfyAD9SjrzCGt0BvI/mKsQPZbvHAQk15Nm++KAQNg2IPy0AJBCiLc A1PUTebQKMEokKrZbyCgwZhR6B5KS8c8qSQh7VGpkKLFWgaM+I9w8d/V6MJj2SkE6Lu3y08roYbkA RUdIsDzhUZ+wu/Wg8jlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vx-001Ain-P2; Thu, 27 May 2021 00:31:33 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vt-001Ad4-6l for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:31 +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=1622075492; x=1653611492; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xhCR0ISdrvCcLtKgf+cB/Z0H37I+OZx3llRS10q8ew8=; b=X+2xicGXWO1IL0LaP0T8iX65+7EjaCjDovuCJsCRYQe7ZsveTqCnUEE7 D+ssGk1qddGTOAc+txew0XgyJrbmrKpMlA/2p1WCe4Ey5yQSYji95IEBD w3pV/haJKzskMJGzV9ipJsTVWusAi6U7xMmVVYmArBCLYMHkwTujrXEgF 8jZjuoh5FRFrwCk699+zi7NhL54fdkkDj2lQA+u2s4DIwHSi9g8zgZt6q +wr7l+q6tahgu4k6sWLSQCMSC2SEt7wMfO0GqCbDRPp4wtiJ2xHqAnszo ZX//pz2lAPBA01CTsp1ArNZzoDW9jnwdhyW5KiEYT3pmtLAyto2fT6TTN g==; IronPort-SDR: 3Du72851mT+9c51b3YU1CcLuuXWrLKaxzxcIBW+FinZeejxs58MgKptjVbhLap9OsDZw0QdFqE spklJUOUDmcHkdlMtCl4ggYT49NuNlg20V+5o3ClXX8FAf/LzCcu6RmTutbI7Xr9VeB1ih1dQR 5WcRVrsLRCXs21tfqDGDDiAYNIupoizXBLCSlCYYUYoiyzlNbPgJ02ynBecHbh0OdkwwpE74zP loutWmBk3DZfOQwt56azwlCfLb6cBDLYKz6IDLc6+YsFKypzWZhN8u9V6aY3XVdQHkHrACq3ZW HH4= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477829" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:32 +0800 IronPort-SDR: Wt/0gdm6sSyD7k4pKQHVkr5CMtbgqeoT9yuYuGXN1KtVZsuVxxX+dk36ljKA4xubN/Xe/6BQvq P7iRD7Nn1KvzlIJBtpmfkb4Q/ZBfxc5eS40Otp3Wa8v/0VYY6PXGlYhPiyQYZTzaMJvlfApM4r j3OvbexLUUhQpyoO7lgoVTXS0OAUs717zxXRbtV7r/m+Hj9q9a2XW4SG5Zm0tu6JXmRFPc3GNz 122Iwein9DZ5JNpKOih5XOYDDE56DSt0WP+GW6LQwpejsHJMgt89eAkrZXJi+xtnY3NiLdrey3 k4FnuPh+YyK08KbiJ+ww2h+s Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:54 -0700 IronPort-SDR: GsGIjcK7h2StwJ0C7pKDhVy/8d7q45UtUTlSZ+k992bFvnwb8YC1PpOF844kLbSb5RZnRkTGtY 9WRk0WQKP+M1s7AHt1ucDal58M30PWw88uEk9uw5l2xrqKq+U0SDcpYO8TWc5TiObFVnbldU19 /GKrvgHnQALXAyCx53i2JXXc1R0QvrAy/8ykvKDBSkUEpJosA9/GcSleQGaRyyRDlEScVbQdiS Hjcbnr6qHv8pyNzaKNCg+/PSQmGYMsDuTIAMS445QEj684GzLRKI621hpk7hcwLlXW7nS1XM23 Urk= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:26 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 11/15] utils: fdt: Add fdt helper functions to parse PMU DT nodes Date: Wed, 26 May 2021 17:30:40 -0700 Message-Id: <20210527003044.889681-12-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173129_443887_8DAB4819 X-CRM114-Status: GOOD ( 23.34 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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 | 111 ++++++++++++++++++++++++++++++++ l [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 | 111 ++++++++++++++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + 4 files changed, 160 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 14655000b815..ac01ba3dfac1 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) @@ -263,6 +264,7 @@ void fdt_fixups(void *fdt) fdt_plic_fixup(fdt); 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..910bf30ee761 --- /dev/null +++ b/lib/utils/fdt/fdt_pmu.c @@ -0,0 +1,111 @@ +// 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 + +#define FDT_PMU_HW_EVENT_MAX (SBI_PMU_HW_EVENT_MAX * 2) + +struct fdt_pmu_hw_event_select { + uint32_t eidx; + uint64_t select; +}; + +static struct fdt_pmu_hw_event_select fdt_pmu_evt_select[FDT_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 fdt_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 fdt_pmu_hw_event_select *event; + uint64_t raw_selector; + 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++) { + raw_selector = fdt32_to_cpu(event_val[3 * i]); + raw_selector = (raw_selector << 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(raw_selector, 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 Thu May 27 00:30:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484376 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=IfQegPTv; 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=Hq5aioTp; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zZ6dG2z9s5R for ; Thu, 27 May 2021 10:31:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EQrrBo8dd1nUbigYBA41Tooo7umKq5Ujp6pzHQICJF4=; b=IfQegPTvwlSLbS 5vEp7MDDMSkW+GgT1HgCEbO74Im12R3h32UKSj+T/yx3ycgc4tny5SzIVlKpmslmX2p/3oh0iMwq6 YyWL8iPqUSsyOqPubKlkY5roxWM3i7YlzfwLl1bzDWcm/hBMExJFEn9dbz7WJIL7wLHVH92Pl3+3J Ho9HKDWNxSuxTnGkNlKsPTn+tpK4SdZqg0Y4SRH98D27usm1v30mbPduMLzOKZxuCUbmuKjqrtc4V xidN/92D7qlO7bkdSVZSv+8jx/uAOJCRRRyDsemzn5EBTIJRxMA+iXAWjX9qzsY3fM4/wrbT6M1Kv fOSitGFCldqAxD4g06+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vy-001AjS-Lg; Thu, 27 May 2021 00:31:34 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vv-001AYD-BE for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31: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=1622075495; x=1653611495; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v8Jw1QzcRn472NaFgToLcloUxkZ+VDRKBDs7QAUWAbw=; b=Hq5aioTpY7XlyN4KV53hlGHPgRlJwaRZ3MrqEHIfxF6phhA59Zjywx9I ZqocdoTMuTSl8Dj1qlt/KEmz8EZ1xeuqcZNGEfODLXZwqHZr1c7l4/UmZ /A4o/TKXlQ5uuFMf3qWmNaG2sx0dtWFSrGuGzneE46o+f01UJkvCb5O9K BAiOOClpMNjXEEKle7O87oKEzz1VN+5BkcCjRCdKm2P70SWz18oIDPaEF 246HPHcSi3Sfd4ug6r75mgunqRcRw5eLFUG3n1lSDt1Y1isReZVdgJ5Kw qo6ef6ZomfLLc7Ftsk3edIr6cSKtCd88CWH8Re8451Zhi9kbpDgeJIwsq A==; IronPort-SDR: ALqjwwSisuvEozEDMxTC6MfD1xFcn3uVwohns1DkNiGCHSbjiMNg9LdOFAY0HHwE6R85RWrP1Z Urp0bdqyfD75y/cGy1ZAFMDoOAUOhPjV2dgkOTD5WYHemblha9vaEsTaOB7c/rLoCtRQS+Ba8E Yq35D4t7SGcJXkO/oLfr2loXx2Hf+IkrcNjCSEOnRL9tmZKX8zHhIAWdVUIM7rv+OvKTvEcFaj CEJelt1lbafigWT+HEh1OBBt5HzVwI4ZR/4weg/ZNMm7Hz/KW75zg7BtCslFsEmpd81/oI4GNA Sf0= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477841" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:35 +0800 IronPort-SDR: pkzYgskeApbnbvkWS2SlrqJb1oqUny331XuUws/+5PMLatThwGbY7DJqC2O6o0o7Cer8uUqNrH KArMqZm8bct/udCgkKNVQbsIkJEA7ffXg9zIRYvG54Hmtvr8xT6VLscY0wT7X2bxCM+QQlfYhV rr8gzHR/S1/hG1MXK3kxuaYaClwcCTGporv8UMugbQRqV1AiU3HEDmNtbjU7fbmNLP64CB9I5r P/3qfzDs/EbGLXJBCk15xgvaUu1PKuIYPYODHOAgmrq467V1wVCV1z66qLSjfBIaT2tou8m7xA IwlChslg2OrS+YJd6Hryazdg Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:56 -0700 IronPort-SDR: iZ+TBrWtdtS04JXpJ9+b6EAYf33tTLz1qQyEFjTm7FUerEaBersDacN/9zT4VD4BrJ6AJJGHhT gpxLK470So4U8gpFSxwNkJIydymI+0OKche49RyfsvHjvVKoFBinMUaV8ze5EAVJOK34xTY7x8 /KX8y2HMy8IOob8w8Cv6x9eesfF7d5eeINKfd32boLKDluhWWTLxVSutJbw9ItXHMETQlqM7TV SKJQjjkyggbzPQtir5fthTTaYlv4ul0bGGhAs33sqZeMcQwH+qaNAP2rdEoRnXhLU+B8AZCrMK WQc= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:29 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 12/15] lib: sbi: Implement SBI PMU extension Date: Wed, 26 May 2021 17:30:41 -0700 Message-Id: <20210527003044.889681-13-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173131_545910_0304E159 X-CRM114-Status: GOOD ( 19.00 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 | 9 +++++ lib/sbi/sbi_ecall_pmu.c | 78 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 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..a87bb7ad1c8d 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,12 @@ 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..938bf31b907e --- /dev/null +++ b/lib/sbi/sbi_ecall_pmu.c @@ -0,0 +1,78 @@ +/* + * 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 temp; + + 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_ctr_get_info(regs->a0, out_val); + break; + case SBI_EXT_PMU_COUNTER_CFG_MATCH: +#if __riscv_xlen == 32 + temp = ((uint64_t)regs->a5 << 32) | regs->a4; +#else + temp = regs->a4; +#endif + ret = sbi_pmu_ctr_cfg_match(regs->a0, regs->a1, regs->a2, + regs->a3, temp); + if (ret >= 0) { + *out_val = ret; + ret = 0; + } + + break; + case SBI_EXT_PMU_COUNTER_FW_READ: + ret = sbi_pmu_ctr_read(regs->a0, out_val); + break; + case SBI_EXT_PMU_COUNTER_START: + +#if __riscv_xlen == 32 + temp = ((uint64_t)regs->a4 << 32) | regs->a3; +#else + temp = regs->a3; +#endif + ret = sbi_pmu_ctr_start(regs->a0, regs->a1, regs->a2, temp); + break; + case SBI_EXT_PMU_COUNTER_STOP: + ret = sbi_pmu_ctr_stop(regs->a0, regs->a1, regs->a2); + 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 Thu May 27 00:30:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484377 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=Xq2oy2TY; 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=XNvz0p6R; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zf2n5bz9s24 for ; Thu, 27 May 2021 10:31:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=J/i7ivvFhV3acUk9KstA4PDf4GWnQJHwgpQ4C19/hQs=; b=Xq2oy2TYLz3WjR QGbV03ffR59GYymtpMoqb5hRGABnrxueB5pK/nuScE4h0p6l9EZWqaRtkCAYUcM2XQjdMKI8iqvoG WBATMLjNu4uKRUyVW+gB7COBF3rtFQ0aH8wq+ombaVdKQzDtx//qW3Z7FUs8yC9NpUc9G7zCLV0TD oJ46myeToNWJrxdo3+4ZDLbbUwcCGUCi/6JJH/Hll+ZLNZ6oMRrW5qKhcttgCShqQw0EV+91sbvko TiQtg+aXZRDNgfk1l1uotuqXRlTFwFLgTX7Z8BRWMpiau65+bTbL3gRDYt0qUZKJXyPY/vZdjq7dk 0OkTkeGZP4IY1zP/wozA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3w1-001Anp-Lv; Thu, 27 May 2021 00:31:37 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3vy-001Aiy-4j for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31: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=1622075500; x=1653611500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ixFfjKoj5fQs+FiQW1iSw0wdC5YfR8RVS7LkSlohsYk=; b=XNvz0p6R0fyOCoBrZwbE2TyvV8STxj3+8RLLGqUxk0MzdYuP8XxtXrVj WJ2CWNInaLPI456iA7l2kJ0eAlWeZ/XpO9RN+GlUPCOXIDM5vmfk/kl1z +CtNOjqXyXiL+UFtqEl4iHq2KYjGUDvXJDSiYEZDqCRGl5gQizbVD42HY I+HvBQLUXWJrNTMd0jfnoksL2tnYl60DCMHtoKROfQiUBaS+NNmSFZUew qpbF0mjTvmqOw0FEg2liB7TXN/r1Nc5FDtfJdKLm7WjTUlyQeM5lXROU8 1Jn3NJxpKTk8N6LdmZYV0xU4/Tn7uxek9+WOn++QWW3C4VhaDhSzDe2Th g==; IronPort-SDR: XUnDK2NE4c8ftiGKoE+Sjn4GYN57gZWPCnJ80yOeVPTXuSapH46ZC0nLHy16rgkEc711BKP13/ iXAZXJ8PNFVniOfC0yK0so/TBv741cBladOti5dXEHDIpk2V16k9BVGYWY/oxq1Uxh6gXZYbdI hUnXsWzYkPVfrF94o7GTq6JDgMskfE7UXOMdiknKb5MPWkl3PHOMMrlZK5/+TLDDQTD7XITwoY euiRLwgWY+7e3aPog0UOCScvztu/O9YuwRt1uVfgHIIoaz0aWbuhO8MbZTFsCscSxcZj0t7DO0 u/g= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477852" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:39 +0800 IronPort-SDR: qhK/feBYMExFp7JIIthIjkaaTKBU+5dXnwhvEf5EBQYXLepFJEmT6VGM1TQKfQClde/esR4+oG V9ijrAzKDoPmTo5Utl4gt0/HQwAxqfQq/T5w81bj5xe0pI4vADPx64ZMzaKp4UlQrPmybyAey6 o74NRKrkgaWzySgaqi38O7wD1W2p8Vg9hJ0vJGkrtCo6DKF6/0na4BTx4AdvVCJutglKm8F/Iw 1hUqbo0DHTubmdGJOCy8lQ5OWx6uU8q0utJ0e9b4DdTGXHc8mi+o0Ystf2FgrmjGxPMAFAJ7ik qRyC0SNU9+siv7HcWxzvqJtb Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:10:59 -0700 IronPort-SDR: kZsikMwQ5AbSjZUUXa58wByDShf+A4QCVQa4+wreZowTsES1cDxnnzJPixxo4eB0Ad5Gq8eDnf CWEtgdGMkNKEb6Okf35u2rgiuMf5pyuHpuyv+mIJbkdAzeyNux0pbfu+V7+OHzk1GQYr55Ik68 KCXLc56szYMEJ1QmP1x7BKvhh2B1QI5HvQPGKs5cB8hSox8ORfWCYFfRQ/6g81H4UlzMYWK0vy INY2UC6714wCvg/xLTB7Fswyt7ILn7fUnyHXF/YIPzxo7jBd7+pcJJq8+Rv+T7aUZgc41+uhFV DQU= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:31 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 13/15] lib: sbi: Implement firmware counters Date: Wed, 26 May 2021 17:30:42 -0700 Message-Id: <20210527003044.889681-14-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173134_353330_D5ABE372 X-CRM114-Status: GOOD ( 17.66 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 Reviewed-by: Anup Patel --- lib/sbi/sbi_ecall_replace.c | 1 + lib/sbi/sbi_illegal_insn.c | 2 ++ lib/sbi/sbi_ipi.c | 6 ++++++ lib/sbi/sbi_misaligned_ldst.c | 5 +++++ lib/sbi/sbi_timer.c | 2 ++ lib/sbi/sbi_tlb.c | 38 +++++++++++++++++++++++++++++++++++ lib/sbi/sbi_trap.c | 5 +++++ 7 files changed, 59 insertions(+) diff --git a/lib/sbi/sbi_ecall_replace.c b/lib/sbi/sbi_ecall_replace.c index a7935d97300d..fb1235d66fa9 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 diff --git a/lib/sbi/sbi_illegal_insn.c b/lib/sbi/sbi_illegal_insn.c index 9af3d24d797e..bfe7d6195898 100644 --- a/lib/sbi/sbi_illegal_insn.c +++ b/lib/sbi/sbi_illegal_insn.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -129,6 +130,7 @@ int sbi_illegal_insn_handler(ulong insn, struct sbi_trap_regs *regs) * instruction trap. */ + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ILLEGAL_INSN); if (unlikely((insn & 3) != 3)) { insn = sbi_get_insn(regs->mepc, &uptrap); if (uptrap.cause) { diff --git a/lib/sbi/sbi_ipi.c b/lib/sbi/sbi_ipi.c index bfaf4e9766e1..563db2cf9e55 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; @@ -64,6 +67,8 @@ static int sbi_ipi_send(struct sbi_scratch *scratch, u32 remote_hartid, if (ipi_dev && ipi_dev->ipi_send) ipi_dev->ipi_send(remote_hartid); + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_SENT); + if (ipi_ops->sync) ipi_ops->sync(scratch); @@ -183,6 +188,7 @@ void sbi_ipi_process(void) sbi_scratch_offset_ptr(scratch, ipi_data_off); u32 hartid = current_hartid(); + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_IPI_RECVD); if (ipi_dev && ipi_dev->ipi_clear) ipi_dev->ipi_clear(hartid); diff --git a/lib/sbi/sbi_misaligned_ldst.c b/lib/sbi/sbi_misaligned_ldst.c index 5057cb5ecd58..c879ce72f61a 100644 --- a/lib/sbi/sbi_misaligned_ldst.c +++ b/lib/sbi/sbi_misaligned_ldst.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -29,6 +30,8 @@ int sbi_misaligned_load_handler(ulong addr, ulong tval2, ulong tinst, struct sbi_trap_info uptrap; int i, fp = 0, shift = 0, len = 0; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_LOAD); + if (tinst & 0x1) { /* * Bit[0] == 1 implies trapped instruction value is @@ -149,6 +152,8 @@ int sbi_misaligned_store_handler(ulong addr, ulong tval2, ulong tinst, struct sbi_trap_info uptrap; int i, len = 0; + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_MISALIGNED_STORE); + if (tinst & 0x1) { /* * Bit[0] == 1 implies trapped instruction value is diff --git a/lib/sbi/sbi_timer.c b/lib/sbi/sbi_timer.c index 63e8ea98eadc..c7f1c80b8939 100644 --- a/lib/sbi/sbi_timer.c +++ b/lib/sbi/sbi_timer.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -88,6 +89,7 @@ void sbi_timer_set_delta_upper(ulong delta_upper) void sbi_timer_event_start(u64 next_event) { + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SET_TIMER); if (timer_dev && timer_dev->timer_event_start) timer_dev->timer_event_start(next_event); csr_clear(CSR_MIP, MIP_STIP); diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 73f59e8681e2..6e9e4f0b1916 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_ctr_incr_fw(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_ctr_incr_fw(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_ctr_incr_fw(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_ctr_incr_fw(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_ctr_incr_fw(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_ctr_incr_fw(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_ctr_incr_fw(SBI_PMU_FW_FENCE_I_RECVD); + __asm__ __volatile("fence.i"); } +static void 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_ctr_incr_fw(SBI_PMU_FW_FENCE_I_SENT); + else if (data->local_fn == sbi_tlb_local_sfence_vma) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_SENT); + else if (data->local_fn == sbi_tlb_local_sfence_vma_asid) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_ASID_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_gvma) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_GVMA_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_gvma_vmid) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_GVMA_VMID_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_vvma) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_SENT); + else if (data->local_fn == sbi_tlb_local_hfence_vvma_asid) + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_ASID_SENT); +} + static void sbi_tlb_entry_process(struct sbi_tlb_info *tinfo) { u32 rhartid; @@ -368,6 +404,8 @@ int sbi_tlb_request(ulong hmask, ulong hbase, struct sbi_tlb_info *tinfo) if (!tinfo->local_fn) return SBI_EINVAL; + tlb_pmu_incr_fw_ctr(tinfo); + return sbi_ipi_send_many(hmask, hbase, tlb_event, tinfo); } diff --git a/lib/sbi/sbi_trap.c b/lib/sbi/sbi_trap.c index 1ba649074b75..dda68d4375af 100644 --- a/lib/sbi/sbi_trap.c +++ b/lib/sbi/sbi_trap.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -257,6 +258,10 @@ struct sbi_trap_regs *sbi_trap_handler(struct sbi_trap_regs *regs) rc = sbi_ecall_handler(regs); msg = "ecall handler failed"; break; + case CAUSE_LOAD_ACCESS: + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_LOAD); + case CAUSE_STORE_ACCESS: + sbi_pmu_ctr_incr_fw(SBI_PMU_FW_ACCESS_STORE); default: /* If the trap came from S or U mode, redirect it there */ trap.epc = regs->mepc; From patchwork Thu May 27 00:30:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484378 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=LMrPVC/U; 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=bW6IRNxW; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zh3rdjz9s24 for ; Thu, 27 May 2021 10:31:44 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dx9cHFTdz4NkwsdBXXk1JVncd/3KLUcO4SnHVjhRNA4=; b=LMrPVC/UOAfEDh AhtatBDYpKE4xp8pY9lBzhefzI1a5dQhvfUKobIcCMEBuVBSNFTK0n78onc3D4Rlu5rzd/uvGrbs6 4tj40JG7Rpabngt1YQmRjv/pXhtAcH1dtZ8uE3REe5T7qBeHGPS3oZc8IkDHvF8blnX3N/PQAKg6B tFxuKkD2FF0FHVxeg8400G4sWRqaZoh0/8NVYN3kpwxgP8c9T3b7b/ez02LXOWZfp0Ql3NXWFOOht 93KR96t6gfZRxvZ+Gzm+yJhI+P5LAwgNqRR7s8r+t4LloWsejz78a1IXarHA1fmEvDZ/RN5HckApx AKGLjCEjnQVrKbXvBXaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3w3-001AqS-Rv; Thu, 27 May 2021 00:31:39 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3w0-001Aiy-9w for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31:37 +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=1622075503; x=1653611503; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cPRcUbXDQn3wn8/vLK9k+4qAiRdkCMEmaPnG25N4Cx4=; b=bW6IRNxWCtk55jqla3DQ2GVoLvB+0ddi9Cum7B8IgDvqN6zMmaNoUj2S LP0jjMhS9iNTbYHitNkWtFlUWa0WaR3J5A4UE1ufFhzMq2ewHUPW5RyhP TELK1q790hI2PLrA8NbBfQx9abj2FhrMuRo/4+2eG7bJ15teMIfT2C5eJ kTNhwREJJ1D9q8InzLi1/3PWOM362gxmLwLhIDGiF9uMQxT8KXhPHiOS9 KhQXwetJmU8PssQ6A9fkW35IdcofJQka0cTJWkSHxeFQxFU5tNJR3XUoU nA/oXHnsv7V/XRAxM+kjdiu3Wl4uL6RQgsJN45wG5JLhfydwCvt4h90Ix Q==; IronPort-SDR: eRGV2okWKWBbSGL3DK4t984CTK9972+SNf7NlUh1biZXkSrqndmgyRlJtMiA9AHkDH6RqgfAkx xU+B+mPnOlclKooYvQxGXYuOJTqvW/GvsFoyUeDo205SWZ1FRBianOOzN4ZPOJJ3r1htNo4cU2 ZGYQXLEn0qy3clfk4GV80BZIhye7at53tvuoK/xpFDfVMdte4tuEZFMdfnmUfEbpSifzkTw+hE dUQK+K6X3UsJ3FdbBrnD/W1gJ5npwKd9LCc6EwXY+ybXIzqk6JeboEdC0W0oa0Xx53vDa68VHg DBY= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477865" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:43 +0800 IronPort-SDR: 7jFLfdA2HnF5rqvrsMZdPEOD/aVr3CCz4pJra+2W1afIK7jwUoMFCzaJa6fDitqGfIenRSACzl t0qYnPCsDRL9STt1nVHInsSqBTLNVTE6KTbjSC2wwuhPwPuJvw/chcBXxGNATybM8pue2q4iBY wY1FQ/F3dkFiRKRZKw3asxr7f5ncaYSRyF9L5RTxfNxA+qMMRzxSVAPNlBa/fQfAKCIQ1Nsz/9 vADfNuGFTQMaPpHCyU15KC99xhN+ukFE/0STAyU9w/EJRzWZ64WDS2iUvj7icLQrwLzNC7R4V+ KqJy1xdOmkjKexFFOuhHj0T8 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:11:01 -0700 IronPort-SDR: OsurFgZx6TUCCgqGp+jPQ0GrtV8z/zbOE1b3kpZNjYMWzoYIDdSeJKa/A1YQ9LApWiaACekgmI AS+5pCb2O9MQWNsJTEfnbIaYf6kbJVTrnO+Kfnb/GtAKEhMfUUQmyNKR5HgkrUGA8CUVyaK+ZK tGTps53GllF7bXpVYs2E8dJihRamlI+iS2CM7rmqH12Nm3t8uAuwFQQ2ypntE3zvecHcrsP151 7M3fcgjRPBEGWliz8jyWFXPeVb4NlyNtIP6DZMfAueXgWSYWwEYt9sdTXL014kZ2ih1aoc7FMN N3c= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:34 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 14/15] lib:sbi:tlb: Improve function naming Date: Wed, 26 May 2021 17:30:43 -0700 Message-Id: <20210527003044.889681-15-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173136_470617_94145DAF X-CRM114-Status: GOOD ( 14.68 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: Follow the standard conventon for static function names: All global functions should be start with sbi__ All static functions should be start with _ Signed-off-by: Atish Patra --- lib/sbi/sbi_tlb.c | 40 ++++++++++++++++++++ 1 file changed, 20 insertions(+), 20 deletions(-) Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 Follow the standard conventon for static function names: All global functions should be start with sbi__ All static functions should be start with _ Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- lib/sbi/sbi_tlb.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/sbi/sbi_tlb.c b/lib/sbi/sbi_tlb.c index 6e9e4f0b1916..bddf2654005e 100644 --- a/lib/sbi/sbi_tlb.c +++ b/lib/sbi/sbi_tlb.c @@ -28,7 +28,7 @@ static unsigned long tlb_fifo_off; static unsigned long tlb_fifo_mem_off; static unsigned long tlb_range_flush_limit; -static void sbi_tlb_flush_all(void) +static void tlb_flush_all(void) { __asm__ __volatile("sfence.vma"); } @@ -85,7 +85,7 @@ void sbi_tlb_local_sfence_vma(struct sbi_tlb_info *tinfo) sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_RCVD); if ((start == 0 && size == 0) || (size == SBI_TLB_FLUSH_ALL)) { - sbi_tlb_flush_all(); + tlb_flush_all(); return; } @@ -162,7 +162,7 @@ void sbi_tlb_local_sfence_vma_asid(struct sbi_tlb_info *tinfo) sbi_pmu_ctr_incr_fw(SBI_PMU_FW_SFENCE_VMA_ASID_RCVD); if (start == 0 && size == 0) { - sbi_tlb_flush_all(); + tlb_flush_all(); return; } @@ -211,7 +211,7 @@ static void tlb_pmu_incr_fw_ctr(struct sbi_tlb_info *data) sbi_pmu_ctr_incr_fw(SBI_PMU_FW_HFENCE_VVMA_ASID_SENT); } -static void sbi_tlb_entry_process(struct sbi_tlb_info *tinfo) +static void tlb_entry_process(struct sbi_tlb_info *tinfo) { u32 rhartid; struct sbi_scratch *rscratch = NULL; @@ -229,7 +229,7 @@ static void sbi_tlb_entry_process(struct sbi_tlb_info *tinfo) } } -static void sbi_tlb_process_count(struct sbi_scratch *scratch, int count) +static void tlb_process_count(struct sbi_scratch *scratch, int count) { struct sbi_tlb_info tinfo; u32 deq_count = 0; @@ -237,7 +237,7 @@ static void sbi_tlb_process_count(struct sbi_scratch *scratch, int count) sbi_scratch_offset_ptr(scratch, tlb_fifo_off); while (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) { - sbi_tlb_entry_process(&tinfo); + tlb_entry_process(&tinfo); deq_count++; if (deq_count > count) break; @@ -245,17 +245,17 @@ static void sbi_tlb_process_count(struct sbi_scratch *scratch, int count) } } -static void sbi_tlb_process(struct sbi_scratch *scratch) +static void tlb_process(struct sbi_scratch *scratch) { struct sbi_tlb_info tinfo; struct sbi_fifo *tlb_fifo = sbi_scratch_offset_ptr(scratch, tlb_fifo_off); while (!sbi_fifo_dequeue(tlb_fifo, &tinfo)) - sbi_tlb_entry_process(&tinfo); + tlb_entry_process(&tinfo); } -static void sbi_tlb_sync(struct sbi_scratch *scratch) +static void tlb_sync(struct sbi_scratch *scratch) { unsigned long *tlb_sync = sbi_scratch_offset_ptr(scratch, tlb_sync_off); @@ -265,13 +265,13 @@ static void sbi_tlb_sync(struct sbi_scratch *scratch) * While we are waiting for remote hart to set the sync, * consume fifo requests to avoid deadlock. */ - sbi_tlb_process_count(scratch, 1); + tlb_process_count(scratch, 1); } return; } -static inline int __sbi_tlb_range_check(struct sbi_tlb_info *curr, +static inline int tlb_range_check(struct sbi_tlb_info *curr, struct sbi_tlb_info *next) { unsigned long curr_end; @@ -314,7 +314,7 @@ static inline int __sbi_tlb_range_check(struct sbi_tlb_info *curr, * before continuing the while loop. This method is preferred over wfi/ipi because * of MMIO cost involved in later method. */ -static int sbi_tlb_update_cb(void *in, void *data) +static int tlb_update_cb(void *in, void *data) { struct sbi_tlb_info *curr; struct sbi_tlb_info *next; @@ -329,16 +329,16 @@ static int sbi_tlb_update_cb(void *in, void *data) if (next->local_fn == sbi_tlb_local_sfence_vma_asid && curr->local_fn == sbi_tlb_local_sfence_vma_asid) { if (next->asid == curr->asid) - ret = __sbi_tlb_range_check(curr, next); + ret = tlb_range_check(curr, next); } else if (next->local_fn == sbi_tlb_local_sfence_vma && curr->local_fn == sbi_tlb_local_sfence_vma) { - ret = __sbi_tlb_range_check(curr, next); + ret = tlb_range_check(curr, next); } return ret; } -static int sbi_tlb_update(struct sbi_scratch *scratch, +static int tlb_update(struct sbi_scratch *scratch, struct sbi_scratch *remote_scratch, u32 remote_hartid, void *data) { @@ -368,7 +368,7 @@ static int sbi_tlb_update(struct sbi_scratch *scratch, tlb_fifo_r = sbi_scratch_offset_ptr(remote_scratch, tlb_fifo_off); - ret = sbi_fifo_inplace_update(tlb_fifo_r, data, sbi_tlb_update_cb); + ret = sbi_fifo_inplace_update(tlb_fifo_r, data, tlb_update_cb); if (ret != SBI_FIFO_UNCHANGED) { return 1; } @@ -382,7 +382,7 @@ static int sbi_tlb_update(struct sbi_scratch *scratch, * TODO: Introduce a wait/wakeup event mechanism to handle * this properly. */ - sbi_tlb_process_count(scratch, 1); + tlb_process_count(scratch, 1); sbi_dprintf("hart%d: hart%d tlb fifo full\n", curr_hartid, remote_hartid); } @@ -392,9 +392,9 @@ static int sbi_tlb_update(struct sbi_scratch *scratch, static struct sbi_ipi_event_ops tlb_ops = { .name = "IPI_TLB", - .update = sbi_tlb_update, - .sync = sbi_tlb_sync, - .process = sbi_tlb_process, + .update = tlb_update, + .sync = tlb_sync, + .process = tlb_process, }; static u32 tlb_event = SBI_IPI_EVENT_MAX; From patchwork Thu May 27 00:30:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1484379 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=2607:7c80:54:e::133; helo=bombadil.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=bombadil.20210309 header.b=TbEPSETQ; 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=RX1+2OJG; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fr7zj6jpdz9s24 for ; Thu, 27 May 2021 10:31:45 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=B+e/w1K6MRSMGC/OCr0VrEysrInKHQACQmWntrBFEjk=; b=TbEPSETQMEek6o iDuDnPsIw9IiokVHPWH5IrQPAFSo+eZGGaV3lRB4trQ/ttjF3Kmsd0EIhuE0dMsN0mYPQfSCHNKVd lYry9sWRxNDYYWgvh4QyWEnYluTKbJod0accLAeJRs9n5WL8+OdbTzLk5BDKis355PVi1BlrmFUrr FMKjD86gFkb+EezSz2NmZTrRMIRd7yl1OlDjH4KlEyGx8hs3d8HewAyz02WQ3KiyX5JaTHNHyzwsA +daBwuo7jQKP7I90Q5KkA+heejgwsOG3lms2E9b3qDTdAPZMDwyTHtndT3waJukiXpabukQ7LxGBW BujIbcOB7aH9G0Fz88wg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3w5-001Ass-Gv; Thu, 27 May 2021 00:31:41 +0000 Received: from esa2.hgst.iphmx.com ([68.232.143.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lm3w2-001ApG-Uf for opensbi@lists.infradead.org; Thu, 27 May 2021 00:31: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=1622075507; x=1653611507; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eNvf6Ac3joZUX/+W898JFI7okpNlchb78g6e2N/yGvM=; b=RX1+2OJGYboojY6gX5mZ24hMblouwtB+XAOhWpmnUEEzw10odZh0M31q DkTFXcNRt5x2pAkQlIl22gl6cfPrbYn2XB0ByFnZaql9Gw8HTYvIGYdIe XN/+X8BlSn4N0E7whWqYwwYnx1gRrl20fyD8gNwc88oB7F75yjWwkmNzd V8m+8YlUz+0pp12ClWTfx8Ym72h8b2u81ufDedJyBZQfys7EAx4RMl1eR dxruJ6/wBjSDbdBUrbQ3ACRq/3b8syEQTrGR+r/SK91eOtJIyU7+Yeerq 8L/L6fDTo1ZHbYP4z85t4FVyDA+bDLv0sMpjTn6YTkzApBPROm0tM+AZZ Q==; IronPort-SDR: ihzobpvG/shYdI2gNdkzj7jOy89OTKKjqQDjnSeWmxDZQTxGgaLXNRf0M4JOyN1E9Nk30Jb5Ec O88pPlljrImq5kWEMzVzwBrR2OwqjNghNjPTZyGWnSc/WzUrQi7EYtMMJaLp/YlbyG098G0xOF 4Ds2f+uht73ND7D0dIifKxez1+4P7LutCOZaovOx7WoIrmHAuDIzTv/sIGPCBYivxzezXaQ7/o IMap/jQKCKzZ5eaM1w7ZQN9+Qkf/SI8U1E4T3xyZtKDLWn02WbVvCcTx/kBQr+x4GrOsPj+b7z B0A= X-IronPort-AV: E=Sophos;i="5.82,333,1613404800"; d="scan'208";a="273477875" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2021 08:31:46 +0800 IronPort-SDR: /8ApNgwWPksPF7lamu6K9MBrj3+tSMF8hptvld265+E0JDjMh9y+gKaFEtnm2L4aKjGr+r1D4E xsctk8gscr4kzOCdgodTWRi9sj4BmuT00r5nrsJxKR//Aqp+8rFtxq8HTonteGI8DcMOmZnpbr qxpAZ9FURI8H4OLRPoa44GdlYQX80IKI177r8vPURKoEMOi1TFuqfqN+tbYdDgTSdyjf2zG8WI 9Yqbxm7/nQhPB+nXbPTcAiKu1JJR19zKUw2JdBaHj+hTqi5xg3dKPOjvv8RnrLN93jS/J9pUQw NNqEMxI/XUdd5mb8WwuVSjJl Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 May 2021 17:11:03 -0700 IronPort-SDR: XLMLcyE7UN4fURsTlBLdma7S1G02iCfudTMTn5QKSdpcESWm1/Yf2KUp989xr6wf0l7M5Yyz1d Kt0PpsDKs3oxnUuBK8GUsCBGrLHYiHJgbpoC2AlQs819Ak5IqB3uDjbyE4dkkQGIRjTZ/hB604 G0pwVnVGLOm6hUiJqT6rVOQSnvlDaCP4sU6zt+13C0H+8pVffOjC92UjFXqxmRlvZsxxYRxH6r V67RnznixaUagMzSjmGgQ6l5ApFwHlvaq4enR2OW2nea/LSqd4IXEdEzCtPfWrF3pm0oXSNfK+ gn0= WDCIronportException: Internal Received: from unknown (HELO jedi-01.wdc.com) ([10.225.163.91]) by uls-op-cesaip02.wdc.com with ESMTP; 26 May 2021 17:31:36 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , anup.patel@wdc.com Subject: [PATCH v2 15/15] platform: generic: Add PMU support Date: Wed, 26 May 2021 17:30:44 -0700 Message-Id: <20210527003044.889681-16-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210527003044.889681-1-atish.patra@wdc.com> References: <20210527003044.889681-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-20210526_173139_099738_3ABC2173 X-CRM114-Status: GOOD ( 13.85 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.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: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [68.232.143.124 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from 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 | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/platform/generic/platform.c b/platform/generic/platform.c index da0c1af8f92e..44a9c73fba0c 100644 --- a/platform/generic/platform.c +++ b/platform/generic/platform.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -184,6 +185,33 @@ static u64 generic_tlbr_flush_limit(void) return SBI_PLATFORM_TLB_RANGE_FLUSH_LIMIT_DEFAULT; } +static int generic_pmu_init(void) +{ + return fdt_pmu_setup(sbi_scratch_thishart_arg1_ptr()); +} + +static uint64_t generic_pmu_xlate_to_mhpmevent(uint32_t event_idx, + uint64_t data) +{ + uint64_t evt_val = 0; + + /* data is valid only for raw events and is equal to event selector */ + if (event_idx == SBI_PMU_EVENT_RAW_IDX) + evt_val = data; + else { + /** + * Generic platform follows the SBI specification recommendation + * i.e. zero extended event_idx is used as mhpmevent value for + * hardware general/cache events if platform does't define one. + */ + evt_val = fdt_pmu_get_select_value(event_idx); + if (!evt_val) + evt_val = (uint64_t)event_idx; + } + + return evt_val; +} + const struct sbi_platform_operations platform_ops = { .early_init = generic_early_init, .final_init = generic_final_init, @@ -195,6 +223,8 @@ const struct sbi_platform_operations platform_ops = { .irqchip_exit = fdt_irqchip_exit, .ipi_init = fdt_ipi_init, .ipi_exit = fdt_ipi_exit, + .pmu_init = generic_pmu_init, + .pmu_xlate_to_mhpmevent = generic_pmu_xlate_to_mhpmevent, .get_tlbr_flush_limit = generic_tlbr_flush_limit, .timer_init = fdt_timer_init, .timer_exit = fdt_timer_exit,