Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp167866lqb; Tue, 16 Apr 2024 11:51:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXvK77ZXagZn3fHfX62LRnFTsyOwpF32Vb0VWgzRRoWoD7kb+6HKkVImemmspj1DnB+Awbkeqedjm7xv7htfHOnY/AEFoNAsvrDn/i0A== X-Google-Smtp-Source: AGHT+IEZWbIj1XMgfZ1FtT24CGORXM1668V8mi70aYrFF4AYUfkdJSBbCFo9/TQzYfU2KaLt1t+K X-Received: by 2002:a50:ab18:0:b0:56d:faa2:789b with SMTP id s24-20020a50ab18000000b0056dfaa2789bmr8721405edc.40.1713293517708; Tue, 16 Apr 2024 11:51:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713293517; cv=pass; d=google.com; s=arc-20160816; b=BrhGHmuth/MgTLjI31J/3hUT7bmCotUd08CUMvEA5BXVWMbEc+hQdRGKzQznd0+ahX p2OsdkDv33AlWrh0zJiW0tHMplkA9YosuNwYWEDpTcHac3WlO98RsJ+OBvhuN9VceT3j LrRUyxMUK549StO6u71koGMf8Ggqz2emiHPdQ4S4yfCBdX+gxSxUOT2KgMLVBmw4r9si cpbZpALE6JT52/0cTPqDvt6FNWsSV7NlVnLiYtOhNWH1Ra5zttFaJK5UbbzfuXzJLqMe Idh/6o1L+V0eoVDnmH5JH56Asjhli7ZhiRooBRlGGa4GjLqDiPF3DQG7U6yGDAyVo/mb KAKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=H9soA5cn4wIINjbEEbaSFa4z0U18KoF+cjavdbqPH+4=; fh=miPuCJ12mtzzszcREievCfVnZyZXF4zzROB3NKono6Q=; b=AvScPVWizHPXN2r+RXZikHjUR6nEeT++EGqmac+Io1HjWbah2OvVEX/73OjvsvHrSi OLE3jEZETQ8tl9Dv6nVdP8oHF1grxYJ4Taw5oDxet89ZF3W+J7z7xjnzwOtQOZisxbq4 1vYi5dJ7Zhw0LcswF+D9Ob1KUGAGtDqZmeyOuuMCsY0kskDQfAthoC0YZgdsBQqHwqNU cZYBm1mD/0ecRM+4usZdzYg7CmtEiY2hlmBcvnagLjWBxEmRoyUXspP0kFVnbHYIiVnW XuPvh8i6IcBTx7sn4kZBOGlBcpPebaExQ/Vs8sHztlUxIxS8/9Af3Kxolx+u9HHuKPEn 14Pg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="0/Ej4FOW"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-147419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147419-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b14-20020a056402350e00b0056e47321882si6027374edd.196.2024.04.16.11.51.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:51:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-147419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="0/Ej4FOW"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-147419-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-147419-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5991B1F20593 for ; Tue, 16 Apr 2024 18:51:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B159142919; Tue, 16 Apr 2024 18:45:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="0/Ej4FOW" Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D0E3140E2B for ; Tue, 16 Apr 2024 18:45:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293112; cv=none; b=T/luUj3aEPfMvlpbwueOAL8Pg6l6g/gBimBy1KLb1cqIUha8CMUkoxk4jG43hKzUvzfuxz00I6cufL1kdAYtdJskMkUIDYiRZRTXvQfbkVNebRLZWsti/Zv1In3NvjU+SkFSy0wlHKktLsMHmblOd9igPrzvETpCwJgeR71pkd0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713293112; c=relaxed/simple; bh=XaYtSkDqV2Gk6SkR/vZ7T7PA/8MDDP7ooY8/f+ym4MI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Onwu7NvR6ts6RUYdPpL6hx8dgEqhRijyW+Emj08WmD2DGr+DRH5CTvaDEU2wwHlzL8bAyqC7yPkzzwYk2hkSyl8I2Gtsub+ruE+erYG+GBtbKg5VLRbPREtYbFWQADbra0r3HCZsC3mIY8QpCAl+74cslovgZk13e2MzsJ7TgUA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=0/Ej4FOW; arc=none smtp.client-ip=209.85.216.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2a4bdef3d8eso3573783a91.1 for ; Tue, 16 Apr 2024 11:45:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713293110; x=1713897910; darn=vger.kernel.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=0/Ej4FOWhyarDlN60tU97y4o0Wf/7Mtnm5qIVr+X4bGkvAqrtqrEdjexaSYrhMPVST NNtqK3voiXQZhsNsxX1Ej8U8is93drZzCJObsSXm7ljDEq6r5rIDwsxSeRRLU5UlMBS3 JF+ZHlADp3La4UVFzsLgvYqFSLDHDLy/+DKE6n9TP5KT2/N/e+0Au8NSoJKBHH65WkeS 3ke9hDI5WXKsUUHZ4I3CWO9vhoh+OiMj7LUEFgrApNFuliI6pykR6A3UeVZBHP2ndkYc fMqQXzBToIQij3HFebkbP/p8ufcKi/nIomB6i0JFEs984Fh7QuvVpl8RJlUiCwz9Dd+A IdDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713293110; x=1713897910; 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=nFSIaw/dUamkoruFn6ZmGp9lqNypdYwk8KChz6yQghu2wnuGTjhshx0RsUBlEPqyWT 0Nf3LweYrTcYIQmjUz4x+TyyjXV6+jQNukDL01O3FWB1T3/0yDPiLxWL6Qq6gZfpS/PV zDuB/t6kBexTcO7xnBS7dF7GWc33gWSEzO5GQV0udNKHZFNZe7yOK4W7S8qF2l6CQQus A3dxdvUCw52JMuKE5lyPPCgPqxKorl40pIW6tlD/jbM70FEk6wloaVMxIZBXars0kt9e FAEUcQzG5I4DoltFmJ+6hH6clp83py9CwZWZZzLwMliZR9QQXj9erR9xpX1GJeU/YfeH N9Jg== X-Gm-Message-State: AOJu0YwtlEWTb4iEu8hekJkzFQuwGVNe3KRDPlJFovChJ+bGOjPH1kyk Io6CszLx+pF1gXFOOw8pYcLlhhl9MDuLDZcY2voyi8vhvcbJUP/beyRV3tx7WB+bFwEvF4ze3qE X X-Received: by 2002:a17:90b:180a:b0:2a2:55de:93eb with SMTP id lw10-20020a17090b180a00b002a255de93ebmr11036026pjb.33.1713293109672; Tue, 16 Apr 2024 11:45:09 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id o19-20020a17090aac1300b002a269828bb8sm8883645pjq.40.2024.04.16.11.45.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 11:45:09 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Andrew Jones , Anup Patel , Ajay Kaher , Albert Ou , Alexandre Ghiti , 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 v7 20/24] KVM: riscv: selftests: Add SBI PMU extension definitions Date: Tue, 16 Apr 2024 11:44:17 -0700 Message-Id: <20240416184421.3693802-21-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240416184421.3693802-1-atishp@rivosinc.com> References: <20240416184421.3693802-1-atishp@rivosinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- .../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, -- 2.34.1