From patchwork Mon Oct 25 19:44:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 1545955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=aNhxdVxn; 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=EQbpNnsB; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4HdQR10H8gz9shn for ; Tue, 26 Oct 2021 06:45:16 +1100 (AEDT) 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=AXyegA0pYwqZ+xNvP3wQT7vbcUGTC214Ov/WnFahw0g=; b=aNhxdVxnTgyTi3 Z/o34ohVYD7MP87G04ztkaQe8XbH7ft7DXMj6cWGBYwC1IvsOlsrbB+Pdh0USigC9YGISRuUHrJCp drfDAOMpAglPBRzQsWrixhr6MnnYMqPXo89BHOt6rrylimCN7c2HXdmpLfJXrM5fQ17r15bkr/Q50 fu4EjURapBBbVw1msl+yTQzwh6lwEYY0fCC1I9B3d94tgpLVHPupXRt5tXCiOmh1U4hbu9VlLcWE2 GXLTsMjW77GPqj3GgyCLPjm2RrsX+1+FBfTwKDo56XP/w+5snDIaqwhGvNitcUk2nExCwA9i5tmff PX7T0iPiHBQwkw9G4sGQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mf5uA-00HTL8-Oj; Mon, 25 Oct 2021 19:45: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 1mf5u5-00HTGr-CR for opensbi@lists.infradead.org; Mon, 25 Oct 2021 19:45:06 +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=1635191105; x=1666727105; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zxo32I5e9NukvtdY34wqZDC+nsdPCYuGcK9g8OeQGRE=; b=EQbpNnsBRC2tXi9saw4YPGP2wGlwzRRIpeYAhLYcisN2a/p78r1meCTF mz0LQTU57CYZcwy883I1lijfH+nIl4fOxDE1ryqwDdNHfdoOowOCE/FTG 7UCFTj2yWooi9eAdpLpdZHX4mfMntn75eC/wELZ/QNB93EE9KnxKUPFUi jH3ooI84Sx9GlAPs8ZhU2upTf3nf0YF+LJuUTCQQ1fIbhFAyiXGYY2v8n TYtqLiLtEROxktiYnX7raYJgd7xciTd8Kt83Vt6AVucnDsV9ph21f+sz8 DZkwnLJ+zYafOWSYXiIUoVMebwTOoTU9k6rRJwCpIV5laM/FZjgKOc2ju A==; X-IronPort-AV: E=Sophos;i="5.87,181,1631548800"; d="scan'208";a="287682477" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 26 Oct 2021 03:45:02 +0800 IronPort-SDR: AA/U5eah3XmDQYeioBcEFC5rfnz9PXZprMCpS1F4JRxS4/9O5In6TnzIStqYjsdMCOU6d6QgTm gM4f+0uBhspVAslp010ZeegYVOUAeQpStTba82HaRbbP/1pr0wXORJQBY64KlbOdAvkkpPnEQj JyudEMe8/GKwrAMpMZv2xWda/d7ylbeJBBwONhB6a4rRSRHRmI/ziDxJG4CeiW1+oF63hVjQ1H 4+jpiWDFofB+T7lFwRbxxSQfySFL5edfy1gfPee7BxQNvFbwUoqr6zLuJTIZk36VNWKW5BxxWO zFMdL1K/fskSq3dE6uuFeK1f 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; 25 Oct 2021 12:20:33 -0700 IronPort-SDR: HgPCeO15jA7SQWuaAzhJvgqZzSRcBIMKYOJ4xvpf6DEZtM3+zkNJgIJlAp1SnSa0gZH9nzNiF6 ja+l+sb8Ha+ArX7wICdPfoV1UqgNWYxQFJUrVf0W9cthZ+vHPwyGbsMSKVyGx3t2f1sF5hoHIi m3sE2bevDDHC1C2yQBiTUqkkTPj9TslIXoxAKFsdisKeKml6GTd9kVWCxp3QvinnvnFhwxLsm8 eyS652nQ90wpSGai4JlzMpsafTqP8enY47OQZrtwrtz7VLgQCgklJ009Z4cW01374o74ah/6Ak 9DI= WDCIronportException: Internal Received: from unknown (HELO hulk.wdc.com) ([10.225.167.27]) by uls-op-cesaip02.wdc.com with ESMTP; 25 Oct 2021 12:45:02 -0700 From: Atish Patra To: opensbi@lists.infradead.org Cc: Atish Patra , Anup Patel Subject: [PATCH v2 03/10] lib: sbi: Detect SSCOF extension at run time Date: Mon, 25 Oct 2021 12:44:48 -0700 Message-Id: <20211025194455.232828-4-atish.patra@wdc.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211025194455.232828-1-atish.patra@wdc.com> References: <20211025194455.232828-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-20211025_124505_504230_28F9D35D X-CRM114-Status: GOOD ( 13.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: SSCOF ISA extension introduces PMU counter overflow and filtering support. It introduces a read only `scountovf` csr that can be used to detect if a hart supports this extension at runtime. However, t [...] 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_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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 SSCOF ISA extension introduces PMU counter overflow and filtering support. It introduces a read only `scountovf` csr that can be used to detect if a hart supports this extension at runtime. However, this feature is only useful if the hart already supports mcounteren and mcountinhibit. Add a dynamic detection mechanism and boot time print message if sscof is present. Reviewed-by: Anup Patel Signed-off-by: Atish Patra --- include/sbi/sbi_hart.h | 4 +++- lib/sbi/sbi_hart.c | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/sbi/sbi_hart.h b/include/sbi/sbi_hart.h index 0c18ef9325b2..580a7989a4de 100644 --- a/include/sbi/sbi_hart.h +++ b/include/sbi/sbi_hart.h @@ -20,8 +20,10 @@ enum sbi_hart_features { SBI_HART_HAS_MCOUNTEREN = (1 << 1), /** Hart has counter inhibit CSR */ SBI_HART_HAS_MCOUNTINHIBIT = (1 << 2), + /** Hart has sscofpmf extension */ + SBI_HART_HAS_SSCOF = (1 << 3), /** HART has timer csr implementation in hardware */ - SBI_HART_HAS_TIME = (1 << 3), + SBI_HART_HAS_TIME = (1 << 4), /** 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 6254452e11bb..44b8dfd1b551 100644 --- a/lib/sbi/sbi_hart.c +++ b/lib/sbi/sbi_hart.c @@ -288,6 +288,9 @@ static inline char *sbi_hart_feature_id2string(unsigned long feature) case SBI_HART_HAS_MCOUNTINHIBIT: fstr = "mcountinhibit"; break; + case SBI_HART_HAS_SSCOF: + fstr = "sscof"; + break; case SBI_HART_HAS_TIME: fstr = "time"; break; @@ -497,6 +500,15 @@ __mhpm_skip: hfeatures->features |= SBI_HART_HAS_MCOUNTINHIBIT; } + /* Counter overflow/filtering is not useful without mcounter/inhibit */ + if (hfeatures->features & SBI_HART_HAS_MCOUNTINHIBIT && + hfeatures->features & SBI_HART_HAS_MCOUNTEREN) { + /* Detect if hart supports sscofpmf */ + csr_read_allowed(CSR_SCOUNTOVF, (unsigned long)&trap); + if (!trap.cause) + hfeatures->features |= SBI_HART_HAS_SSCOF; + } + /* Detect if hart supports time CSR */ csr_read_allowed(CSR_TIME, (unsigned long)&trap); if (!trap.cause)