From patchwork Thu Mar 27 19:35:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Atish Patra X-Patchwork-Id: 14031398 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CADC7C36013 for ; Thu, 27 Mar 2025 19:47:20 +0000 (UTC) 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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yoNJY57PnjaajVGO0wPXJ5f6IDI9UVjViQPB6RN2TeA=; b=ZIeINmo9+nocXt Fyd6fWe4br0Dtr+o/7QUHdRwUkH8u76wBooVwCQQE0YJGrcCFE8bSHrSVdvnp1gmiS8jkexj1+MeF /Eq21cCzkk/++oqD6nlsWCTL7uFk8mbTGNuwMzYFk7Et2Pslw6m+Br3OQ/ta/Hsh1TGHqiVnBy4dm 6vDF9mE3XFpMdSrDLjgP9vbd5oJDWWTKWlN1AuM7KXHs2F4DYjEGU+n5GinXY/dH+imlZgIFkAxCF q/57Y/Piknw6lELfGQ+JAG4kpc05duCMtgOjwtG4+ij3ZhslKSZ2mjN47M7h+Vy9TgmhiXmqv2HMQ GSmYx59nRDRjBWxHa7xA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.1 #2 (Red Hat Linux)) id 1txtC7-0000000Bsaw-0IPf; Thu, 27 Mar 2025 19:47:15 +0000 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.98.1 #2 (Red Hat Linux)) id 1txt1d-0000000Bpar-1t58 for linux-riscv@lists.infradead.org; Thu, 27 Mar 2025 19:36:27 +0000 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-22423adf751so28526615ad.2 for ; Thu, 27 Mar 2025 12:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1743104185; x=1743708985; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yUgUK85uZXa6Y/dNTr7Q9E0wfwXHdLdLqKfyUg5SYXI=; b=I8fn1h7ozu47fV+59BO/m8nosNg0y8F5UEl2l0sRcjp7fzcMSXgzlko+N6H5TPmITo PGE43+OQZXqlbseGQ5piKxIz79z9Zwot/onzOCqCSuDVqwGnJKOlbrD1QgoZy3mGJWyp BY6Dx0X3oHTgNojntbKvQ2uqxQ7Dtrw51i3zaS3twX7fyFrfI+Qpm3YCTjr6r4A+iJFW vfxlijZxlvBuZwwc7iBJI2RuiP+b74b+JH7lObYjdqFxxiYqoO3JH/MwrFaALGIwE5Nw 7wk+sIFr13uy6vQ9rXSTT9Ms1A07S4ImrbXFqAeSDnrUQpfLaJN877+OOefNeQpa286X J/6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743104185; x=1743708985; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yUgUK85uZXa6Y/dNTr7Q9E0wfwXHdLdLqKfyUg5SYXI=; b=bJ/qTvvqT1Ri7+f4/ENeksWmCBidAKpeBvXAGwfPwLvoQpigpw4EmBO+0F0iTd8bFc fUFcbYN9bqBqH4sBWJLnlTo9xwzguUfx1iQRLkGWsqxmOCdzIE5WwvbBvccl9beqhamR Nry1zejWs1pDsBqR8UgFEzLyLPI3SEts0yF3L1z9NDZnRsv46/9K9LQBIkGG+MqUjmRa tQrm9HxEJ4KcpjNKltLx1eef1NOJReTm6U1D3a6B6CgmfCg6kGlkrODOV56UOC3FKoP1 mtKryFYcuDmhnS7PGwskccS/prlJOGlaUIdDXufq6gjKa0KPy0xOxLhMnpbevxpW2Qos wNDg== X-Gm-Message-State: AOJu0Yy7uwKOMGlii77Pjx9wDAYYSBT/olQ/M3wxk8dGyQ71xL7vIsjT l07HzbAcXAvBgLmnJ8Bq9J5c6TAomVWQHs3jQK8DkDgeRcso44ARM9vXDsUCKts= X-Gm-Gg: ASbGncuP2wASkRBEFphPAxcuTfJCOJ1EWnmYGle0dmTyJliOZ+3BceGKeOGYAFncLS3 M2SN7VhNAFGG76ysHdIseIoRaxdwONzNRr+zeRaBneQhc+y0JS9+VKKgpHALAGCPPXDUHll0BuO gM9C0Z2DOadFRRfFpwBOzqJ57cxHuCC4SocQ7c4dl4axIQX/v8dZRQwxpbHzn1hvSeZSwngl7GV PC2dmeekwuSqca+Ky/derI7g+xCsplhoc/StxO/lP8xjVxbkMyAl9qD48jHK1p9Pa4Dslj2zumX aV2LjoMhhvpV+H9lhNWE2Gcc55CRGCi/gu69JPrUkB/qgJ1B5JIldGpKfA== X-Google-Smtp-Source: AGHT+IHsQmzPAsgx/ng9OITR58/G/eBONWXQGgyTGskdwaITzdO2LxTvI25NheeogcoyYSwC74/u/Q== X-Received: by 2002:a17:90b:2f4d:b0:2fe:8a84:e033 with SMTP id 98e67ed59e1d1-303a7b5a137mr7359505a91.2.1743104184705; Thu, 27 Mar 2025 12:36:24 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3039f6b638csm2624220a91.44.2025.03.27.12.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Mar 2025 12:36:24 -0700 (PDT) From: Atish Patra Date: Thu, 27 Mar 2025 12:35:49 -0700 Subject: [PATCH v5 08/21] RISC-V: Add Sscfg extension CSR definition MIME-Version: 1.0 Message-Id: <20250327-counter_delegation-v5-8-1ee538468d1b@rivosinc.com> References: <20250327-counter_delegation-v5-0-1ee538468d1b@rivosinc.com> In-Reply-To: <20250327-counter_delegation-v5-0-1ee538468d1b@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Anup Patel , Atish Patra , Will Deacon , Mark Rutland , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , weilin.wang@intel.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Conor Dooley , devicetree@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, Atish Patra , Kaiwen Xue , =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Mailer: b4 0.15-dev-42535 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250327_123625_494588_CAFF8179 X-CRM114-Status: UNSURE ( 8.97 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org From: Kaiwen Xue This adds the scountinhibit CSR definition and S-mode accessible hpmevent bits defined by smcdeleg/ssccfg. scountinhibit allows S-mode to start/stop counters directly from S-mode without invoking SBI calls to M-mode. It is also used to figure out the counters delegated to S-mode by the M-mode as well. Signed-off-by: Kaiwen Xue Reviewed-by: Clément Léger --- arch/riscv/include/asm/csr.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index bce56a83c384..3d2d4f886c77 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -230,6 +230,31 @@ #define SMSTATEEN0_HSENVCFG (_ULL(1) << SMSTATEEN0_HSENVCFG_SHIFT) #define SMSTATEEN0_SSTATEEN0_SHIFT 63 #define SMSTATEEN0_SSTATEEN0 (_ULL(1) << SMSTATEEN0_SSTATEEN0_SHIFT) +/* HPMEVENT bits. These are accessible in S-mode via Smcdeleg/Ssccfg */ +#ifdef CONFIG_64BIT +#define HPMEVENT_OF (BIT_ULL(63)) +#define HPMEVENT_MINH (BIT_ULL(62)) +#define HPMEVENT_SINH (BIT_ULL(61)) +#define HPMEVENT_UINH (BIT_ULL(60)) +#define HPMEVENT_VSINH (BIT_ULL(59)) +#define HPMEVENT_VUINH (BIT_ULL(58)) +#else +#define HPMEVENTH_OF (BIT_ULL(31)) +#define HPMEVENTH_MINH (BIT_ULL(30)) +#define HPMEVENTH_SINH (BIT_ULL(29)) +#define HPMEVENTH_UINH (BIT_ULL(28)) +#define HPMEVENTH_VSINH (BIT_ULL(27)) +#define HPMEVENTH_VUINH (BIT_ULL(26)) + +#define HPMEVENT_OF (HPMEVENTH_OF << 32) +#define HPMEVENT_MINH (HPMEVENTH_MINH << 32) +#define HPMEVENT_SINH (HPMEVENTH_SINH << 32) +#define HPMEVENT_UINH (HPMEVENTH_UINH << 32) +#define HPMEVENT_VSINH (HPMEVENTH_VSINH << 32) +#define HPMEVENT_VUINH (HPMEVENTH_VUINH << 32) +#endif + +#define SISELECT_SSCCFG_BASE 0x40 /* mseccfg bits */ #define MSECCFG_PMM ENVCFG_PMM @@ -311,6 +336,7 @@ #define CSR_SCOUNTEREN 0x106 #define CSR_SENVCFG 0x10a #define CSR_SSTATEEN0 0x10c +#define CSR_SCOUNTINHIBIT 0x120 #define CSR_SSCRATCH 0x140 #define CSR_SEPC 0x141 #define CSR_SCAUSE 0x142