From patchwork Sat Apr 20 15:17:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Atish Kumar Patra X-Patchwork-Id: 1925765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=gvfu5uGT; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=hQORsTP5; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=lPOIyQqM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VLrwQ6ydPz1yZP for ; Sat, 20 Apr 2024 09:49: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=TmrKMo2wz0BwctZpySu05yDyrQKtKQpkFVcdQuVoJ2o=; b=gvfu5uGT195r04 CfZ7mPKV7EBqhjGapJ/2itUHgT/3lFvBQD7WpdQkD6IDk9NAOrT8DS/WCXEjG7w1dLesvJTtVFzob 0QG4bKZxHvwJo5R4FBEnDnaCREAve9omh4uaIcWGB+3Dpr3wJPsCCTpd2PY91PqHBzijCinrcWFOy mzR/roXL8uTClLdLnSlYghlmOIwelxXQv1OH72GJxauXoNKQ92SjS7lnewKDGV/nZw1LI103KQIXU MSovurwHG0JZ/Pm68qnpYFM2m1n/Q1EH+xwf1E7efsuxgDqaP1MlQrhoy1TaXVuWoT8usuBF0FrLa +FvpBH2qZr18+sgrKlag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxxzA-00000007K66-3YVz; Fri, 19 Apr 2024 23:49:40 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxxy1-00000007J6H-1SQO for kvm-riscv@bombadil.infradead.org; Fri, 19 Apr 2024 23:48:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=H9soA5cn4wIINjbEEbaSFa4z0U18KoF+cjavdbqPH+4=; b=hQORsTP5cMyzxM6RKW2t2vtjWF iiqduc0KcKw+KcIMvN3r5AImmrbKj1HozgDJjAkry7z0KMQF+QfDGrJifmy6o7mgLbmkT+wgbT5LF ED9vmou/Xi4w9EN/PkUxeMZyJYEVosXfgRexvXp43hH3Dk2VxYVcu6n8prX4OeuI8x5NiZ8cdFQD5 yY3q473rOtTBqrKg3rUjdPLGctMXpPE9E9wY/d2g3OZQ1Yw7MVzRJHZGWpt7T1RJ+Px5ZyKsGaxLc VIPXZXtetCUdL1IMU+Xlgcfcx5C/8Q/mcAOajnzFUkNdg46J+gG287idJbNNcv0QWP4KtHzP4X3VO wyGNLrMQ==; Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by casper.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rxxxw-00000008nJB-1Zjk for kvm-riscv@lists.infradead.org; Fri, 19 Apr 2024 23:48:28 +0000 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5cfd95130c6so1712470a12.1 for ; Fri, 19 Apr 2024 16:48:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713570501; x=1714175301; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H9soA5cn4wIINjbEEbaSFa4z0U18KoF+cjavdbqPH+4=; b=lPOIyQqMitgg/Ia/uJr5L3yI8yUPi4Wq/k/Aeb0IX0W0EtHXIWO/0Wv5kvM2h9PXkI /pGeJ46wXpJ4lvkgeACTnU6XrJsBRAfLX4OyYFnCr7ydFgOv55HtJlIiKxU8/JVhII4h IHBUKepMjiu9nb5c8OU8m299u2VUGFDhKSF+XDYLc0rrL8a/NZGJOL6hCXbWdrtSZY0G U0HhvKj+5BOFVKWZCDmUvFlstwIHJdieCq3azb91EAqHhzd9BG8HUIh2zKxzcdiJjKEe 2UKixFZhVJLmUD8e3ao5eZrGHl9wK5pLCSGVvBp+SSyeJekRQIN3vvdh+H6MAqYmwfR8 afEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713570501; x=1714175301; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H9soA5cn4wIINjbEEbaSFa4z0U18KoF+cjavdbqPH+4=; b=ZErPIqWADJ0Rs9Np+ZA+eCJx5LPs0Oov8VNQ+XqTZKLss6hjqXq1CrBF6D1STeBCa1 +DzUH0X+mNmY4oNgzCr3LAvk7CZv/eyAc1+t5Cjkh84jcWdrHPexQ4IWmpiBxjA/fEqM thKP5zVX4RbmVdtdAi4GPw6uR+NYQnMh7TKMmuL6TUNEFmbW7Og/s2j32y2XbW/qFZ2/ //5gGaOO2ptqu0hOvZGrr72Mgx8+OCotTFKqKT6t9VOTnVt8N9zxBtiXR9/LkcljUB8f H5a2QrHf8XE1TjPk3bL2AS2+BmmtHCK8xeR4mnzRFC9ZyIIT/PgESMPNh00V5vKy6VZj +iyQ== X-Forwarded-Encrypted: i=1; AJvYcCU2SeqTc2tpnHL4j9OYqKC8Txym3V6TMWgP8cRYhw0odo9OrUMFuxRnM/VLzNzD9AnIEMl67udtWvltupS7U0v7oADXPnw8Tg6++bHjPA== X-Gm-Message-State: AOJu0Yy18uWDKg5i4eokkCw4BvWQmSCn1/gmsTG41fqXhCXO5caXmYWU fA5xGnxg3F+rP/rmoJbGgqs1LFBTQgUPx+Vi9K8XeYW4kelAvzTIJiBGdAqM5RU= X-Google-Smtp-Source: AGHT+IExX7jSBzI9snc8ZpgJeYyDpP9nMeKJ6Hd3nM6HLbB59ikb+ctX7/mUd/kE+BrHwRoKJsb1xA== X-Received: by 2002:a17:902:edc4:b0:1e5:1108:af1b with SMTP id q4-20020a170902edc400b001e51108af1bmr3327140plk.22.1713570501082; Fri, 19 Apr 2024 16:48:21 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id w17-20020a170902d11100b001e42f215f33sm3924017plw.85.2024.04.19.16.48.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 16:48:20 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Anup Patel , Ajay Kaher , Albert Ou , Alexandre Ghiti , samuel.holland@sifive.com, Conor Dooley , Juergen Gross , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-riscv@lists.infradead.org, Mark Rutland , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Shuah Khan , virtualization@lists.linux.dev, Will Deacon , x86@kernel.org Subject: [PATCH v8 20/24] KVM: riscv: selftests: Add SBI PMU extension definitions Date: Sat, 20 Apr 2024 08:17:36 -0700 Message-Id: <20240420151741.962500-21-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240420151741.962500-1-atishp@rivosinc.com> References: <20240420151741.962500-1-atishp@rivosinc.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240420_004824_557339_A9CC0900 X-CRM114-Status: UNSURE ( 9.78 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 1.3 (+) X-Spam-Report: SpamAssassin version 4.0.0 on casper.infradead.org summary: Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 3.2 DATE_IN_FUTURE_12_24 Date: is 12 to 24 hours after Received: date -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:52d listed in] [list.dnswl.org] X-BeenThere: kvm-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: "kvm-riscv" Errors-To: kvm-riscv-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The SBI PMU extension definition is required for upcoming SBI PMU selftests. Reviewed-by: Andrew Jones Reviewed-by: Anup Patel Signed-off-by: Atish Patra Reviewed-by: Muhammad Usama Anjum --- .../testing/selftests/kvm/include/riscv/sbi.h | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tools/testing/selftests/kvm/include/riscv/sbi.h b/tools/testing/selftests/kvm/include/riscv/sbi.h index ba04f2dec7b5..6675ca673c77 100644 --- a/tools/testing/selftests/kvm/include/riscv/sbi.h +++ b/tools/testing/selftests/kvm/include/riscv/sbi.h @@ -29,17 +29,83 @@ enum sbi_ext_id { SBI_EXT_BASE = 0x10, SBI_EXT_STA = 0x535441, + SBI_EXT_PMU = 0x504D55, }; enum sbi_ext_base_fid { SBI_EXT_BASE_PROBE_EXT = 3, }; +enum sbi_ext_pmu_fid { + SBI_EXT_PMU_NUM_COUNTERS = 0, + SBI_EXT_PMU_COUNTER_GET_INFO, + SBI_EXT_PMU_COUNTER_CFG_MATCH, + SBI_EXT_PMU_COUNTER_START, + SBI_EXT_PMU_COUNTER_STOP, + SBI_EXT_PMU_COUNTER_FW_READ, + SBI_EXT_PMU_COUNTER_FW_READ_HI, + SBI_EXT_PMU_SNAPSHOT_SET_SHMEM, +}; + +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; + }; +}; struct sbiret { long error; long value; }; +/** 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, +}; + +/* SBI PMU counter types */ +enum sbi_pmu_ctr_type { + SBI_PMU_CTR_TYPE_HW = 0x0, + SBI_PMU_CTR_TYPE_FW, +}; + +/* Flags defined for config matching function */ +#define SBI_PMU_CFG_FLAG_SKIP_MATCH BIT(0) +#define SBI_PMU_CFG_FLAG_CLEAR_VALUE BIT(1) +#define SBI_PMU_CFG_FLAG_AUTO_START BIT(2) +#define SBI_PMU_CFG_FLAG_SET_VUINH BIT(3) +#define SBI_PMU_CFG_FLAG_SET_VSINH BIT(4) +#define SBI_PMU_CFG_FLAG_SET_UINH BIT(5) +#define SBI_PMU_CFG_FLAG_SET_SINH BIT(6) +#define SBI_PMU_CFG_FLAG_SET_MINH BIT(7) + +/* Flags defined for counter start function */ +#define SBI_PMU_START_FLAG_SET_INIT_VALUE BIT(0) +#define SBI_PMU_START_FLAG_INIT_SNAPSHOT BIT(1) + +/* Flags defined for counter stop function */ +#define SBI_PMU_STOP_FLAG_RESET BIT(0) +#define SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT BIT(1) + struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4,