Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2557277lqz; Wed, 3 Apr 2024 01:15:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU08pKXjIYO5EHNLODW3TzvIgS2Sfqrf6bsn/PdxnQau4eIXsmlo8nRgCHDaysSBECKgYktRZWJAeRt8END19p3itUzrxpieD+45iHp+A== X-Google-Smtp-Source: AGHT+IEuG/cLWjR5m0IKlA1sKP5goGVo3tOxGOv8yNKkoXnSmpnJOQP/yBYRLfNNGiNL9JDre6AT X-Received: by 2002:a05:6a20:b041:b0:1a3:c7e4:313c with SMTP id dx1-20020a056a20b04100b001a3c7e4313cmr13009117pzb.19.1712132139069; Wed, 03 Apr 2024 01:15:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712132139; cv=pass; d=google.com; s=arc-20160816; b=FpSYrbAW7IQToGHyg4xeoo3hCv10o3GfwRfwuBdeCwaEvEdYMLD6is9bQzRpmk8xdu dJr1pKysq2JH+XCKlKJfRpb1cb8RuxNdpSDqY1GSuMktRpkBV+IBsd8/Na5G5IEOIWyb cf/vlPl1hm24wuP8isM//JU7CcOmNmOwd3xOSP+YF4meoUsIgctkCqllqmwy2fffYovc WgxytvxxVdcnejLRklVRt6DhPRNtxXsL8AYTj4S58SMdzXpk426STZUyHRiiEpO6Dp5+ lzk6E0srneGnJoZd4DY2uDZ3M+G4VJHAHmFDDUoP8sRThVwJ+ZA2PGxyd274A/xbTcR5 Hh7Q== 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=GkhEh3Kwi0UVSPm+lxEXp9oZg2L7eBy2zYGiPlgLtso=; fh=EfSfkMqm8bhmjlBnspCOsQn4LXga6kog0QaqhijtOO4=; b=zmmQzKpkDPDJl0ey7UgydZEUbZglVEVkVm5mEdxX3w8+qJdd/Vcw2qu/6YCpLqBw8a gdIMpmKg6xcVAnmC/TwjfUncs9kO0WR7Tp9fKCS69tfttFV6TqjufkigyTXgsSr/FVeN +hXwyGVTCKb5XF5eUsI646DHDaZUtwIhE3VwV+XXLS+AXw9f/S954yj+E3Vx2QwS5FJc wOtdSiEVtGEycnxehdZjfFKHbNzlz2Zj0EUHNUt1E1Zmt2VVe5xY05SbBNp0t7D4UUkd pmTRkSfgduOzN6FHTekGfCO1l/BLHSHK3c9vc/cXLhCMAaBx1eBSoTia4KQMCJs0J23J XDOw==; 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=dyw6GbFn; 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-129259-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129259-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f2-20020a17090aa78200b0029bd4cd336asi14952435pjq.163.2024.04.03.01.15.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:15:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129259-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=dyw6GbFn; 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-129259-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129259-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EA55028A4AB for ; Wed, 3 Apr 2024 08:11:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4ACDB130AC4; Wed, 3 Apr 2024 08:05:57 +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="dyw6GbFn" Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 10EA712FB2B for ; Wed, 3 Apr 2024 08:05:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712131556; cv=none; b=Ox++xTgpaOjZMxiEOu2n4pEab+i9zlwzsNleuf37yhZqeNhoZopk6sFMwqV4hRkT2o//C4ujBOAaT6AF+smA5qASW7o0vM5zgNmZU5QGUEeKbs51jsO2dgFJWvXm8ATaR21bZlaeJORsHJjFoipFmRyoyboELEcfgZi9vbq2z2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712131556; c=relaxed/simple; bh=780bxI6naAUr6IQqUhjJBAL1yGnj9U7hJOgqG70RfWQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=twQFdebJct+C//rxsv2tvgYCwwbAjxM85kZDfWgdxNS4uxQWaW2Y0ToPeKKQILhE2Otdw9shQGCV0sP/OitHKCAGG377hGXtORzQjuOS/bfSxpiVKPL7lza6uRfa0bq2fouOs/Ah2lZkS2KHMTdsby86h2OiDV4klr3xUEYSUlw= 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=dyw6GbFn; arc=none smtp.client-ip=209.85.214.180 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-pl1-f180.google.com with SMTP id d9443c01a7336-1e0f0398553so54198435ad.3 for ; Wed, 03 Apr 2024 01:05:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712131554; x=1712736354; 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=GkhEh3Kwi0UVSPm+lxEXp9oZg2L7eBy2zYGiPlgLtso=; b=dyw6GbFnCpaATK6fytex7MkAcS1lptmbvXUaUMbUoe9vEhDn+bu5LG2/1i9Jz3OP3J dlQaD+FPXCPjyYwvsKUt6bptozlscgtbcJLlB5Br8nkEcfdZG+W1TREVkASQ/7a6Z2ZP fvmUKrli8p/MJn1Qi/gaxhG3BK7eVs9dMjhGw9Ui+LUFrLpJdX6tDXWia0Xa6fO3yCWp cPZoejXsu9nsk60juTbWuM1RmOR+kglX2E6zDkFjSSh5Op0gqdc+OB2emkhL+OjEgwyC lcTJU4lXypUABPT7Buw/+1FSUFziNKYeFvgXXeXwa+suL2d5cj9aRDzf6peU4oq5y5h5 jnxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712131554; x=1712736354; 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=GkhEh3Kwi0UVSPm+lxEXp9oZg2L7eBy2zYGiPlgLtso=; b=hFg9HopEOzMrkRooPJJK2JyeuuFAfDk+G4Ku0mB3oksMG4Vnu8Iz504FjKqyOQ1RTV z+yu1PZ/QBjt0r7FJG/HX2FIhFA195DwZu4gVBlEo4g8H+m0wuQktysNqdvUaozXHdDJ OlpJjXRP/gmLzoEY0p17Y0EcMJZhemxhwbsSFWxLl1ARBPnlETFSqqH1eLdNh/evm/Bh w2I0gqSiHj0+g5iGhVCCSlLrz1ES2WCZ3Fta2s41ZKzjn5857niWE8bG7bnBCufCP9a6 WDV1aESqdvEnFjScNfFQWCghC6yapiUWyShKB73WMVeTieUZ/unwZFzrT/UXNgJUj09f jIww== X-Gm-Message-State: AOJu0YxreHIpN4IAkkHRhMIo4YDQA8lxtVTN3GIFs8ySqsfox1owRdor Hy1NmqGzGpJPlENpeOLj0JgzUa8y5kbZm4j+2qpXGKvI+x+o5WVove1SWfRg2VyZKr97PZ9Xuxk 5 X-Received: by 2002:a17:903:292:b0:1e2:6240:72e7 with SMTP id j18-20020a170903029200b001e2624072e7mr5867168plr.53.1712131554171; Wed, 03 Apr 2024 01:05:54 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id c12-20020a170902d48c00b001e0b5d49fc7sm12557229plg.161.2024.04.03.01.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 01:05:52 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Ajay Kaher , Alexandre Ghiti , Alexey Makhalov , Andrew Jones , 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, VMware PV-Drivers Reviewers , Will Deacon , x86@kernel.org Subject: [PATCH v5 19/22] KVM: riscv: selftests: Add SBI PMU extension definitions Date: Wed, 3 Apr 2024 01:04:48 -0700 Message-Id: <20240403080452.1007601-20-atishp@rivosinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240403080452.1007601-1-atishp@rivosinc.com> References: <20240403080452.1007601-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: 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