Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp964126lqt; Fri, 19 Apr 2024 16:54:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwxEUbrqZlPjiQo/87J+fX/EZgGbK3y8qaCJm3SHcetgvjxMG9I61KQUFv9czGcWL0RcAu7mRy4ch7JlSJQ3q9bu4Xaq+5EVb/1Fr9yQ== X-Google-Smtp-Source: AGHT+IGdY39wSwl4cTUnSbN6s5Bie0tKzQHs9xE5BqH25AKtdzYidIvgbOvVR7yx+VRoIy61CXY5 X-Received: by 2002:ac8:5751:0:b0:434:8f38:81d2 with SMTP id 17-20020ac85751000000b004348f3881d2mr4295564qtx.16.1713570847500; Fri, 19 Apr 2024 16:54:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713570847; cv=pass; d=google.com; s=arc-20160816; b=wFscUCJ6VzYThHpIlPpBhkyh2MljsHR63kU0/lK/r7hF7wcbkkkUk3dnmEbg+ZsVio atQ4+OBhHntA70p1StPvj9byw8BJTI3ArVaT4X9xr71A5gHvYMTqcPPcuSOZiVcXop52 ORN7OSYDaNLHm+Muojm0w05ARXGHkwrXkvHF0NgDlyQrbqYI9ayeVpchgiwLelgVp9wt 5bCnhlPkmEzzwB9ZiAuPWBTt5igs6cvafvRGGAn90ZAK9pU6WNbNIqE1ZxEWFhiCULMd Tc8ioyzl9wmygBo/vWSNpS5RvlNOpiatFpxyowIZr1hS70/jCXu8n1W7ELtU3uApRr8y Ig1A== 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=T3o9ytfnOI0rfpWkEpCj/g73RiGldXLT4R9OSoqDo9w=; b=oMQldHkMsvr6rCuaNz6MAUed+28IPBmZQPMxkxLoLNhpqpgO2jybcuX+zHcJtM7Xq4 iNq/ScWLxlWIc/LqTnGZ8DBr3ppSM/O53RIBegaP7pSA62A9J5qEPGWxBcOsO5DrfHSm cwbKyZJv4X1/XZFMqEwMdoNSYQogsM5YvS6yDXVaJD66zHx8yT2V1nHv6CB3kZ/8Coc5 GOJM3dh7Ke2bZ1s5aKgj1hHvCxCN1Cc7Gpv/DTD/JzetUlVsmB1gBN4dpOg7F649H2NO NoxlwTNdPK9NBe/Kr5X5OhjHH+Qx7YxJWm/NbgDI885m8DnnmSrW1Gf4GjDCIpyO9hIY tgsA==; 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=hynTKEUE; 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-152043-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152043-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k5-20020ac85fc5000000b0043466e3b8e2si4796902qta.168.2024.04.19.16.54.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 16:54:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152043-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hynTKEUE; 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-152043-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152043-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 30C771C20C90 for ; Fri, 19 Apr 2024 23:54:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AF507152162; Fri, 19 Apr 2024 23:48:24 +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="hynTKEUE" Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) (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 74EE814EC71 for ; Fri, 19 Apr 2024 23:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570503; cv=none; b=D3tIGPHi7ZhJ5KtiJBFZSwvqv2JrcWH6ImRzjhPnf6Gwe9POO0aKU8izejGUX/CFoPVKajDNDs+dx9180ekWYzIdprckoLN2+NfNMwNvEn3RuLioA7HaLhnkIhodzDtsJikxSN0bYRbFC0FRpp3Fg4q3xdXlA9/tJ0dNxng/aCs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713570503; c=relaxed/simple; bh=XaYtSkDqV2Gk6SkR/vZ7T7PA/8MDDP7ooY8/f+ym4MI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n4TUqu7ybgpJDTjDCYUqxn6rB+D3/dneb7TPIZsfJJcb2bHRo019gCzqjHrN8iTxVLz/D3pkXSeAFIyRI7M+EsZ3B8hwKn0B8tC/C/nnH/BghG5pXVPufQb1nQppyO1yXMJJ+ODHjClM+fK8kjT1NtHQ583YmwVXlky06Z44lLg= 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=hynTKEUE; arc=none smtp.client-ip=209.85.215.181 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-pg1-f181.google.com with SMTP id 41be03b00d2f7-5cfd95130c6so1712474a12.1 for ; Fri, 19 Apr 2024 16:48:22 -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=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=hynTKEUEoIGX/tQReH2E0haucsJSmyTUPQRazvr5cpsIvqsvy2t68CUcSdXJ3WgIzt 4hSrEe12CRAEq8fZoPmxnp9/gqyCWWMRY63kX8YfDSkuHxj+zz0z9OOGt1fDKWPhlUEb EoonxUsbDQ6MJ/hLq/gojzto0YJM2GPiBRgzgFbQmnCyAfV9IxFFSVMgSiHWg69Qb2v+ UL2SZJKlRe7ZK1TGY190wWOQ8hbVWeZI3HmxBBBrjQ02wCNSQi6wUykcouBew7jY8Nyw Ggg46xuH3PPNykhJMG1oly3kvYoMlLY0if+b5yxXGtEQ0i5E6ZgkJhruXiBFbUOHqIKm 0pYQ== 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=hxMzQbxMW5P+uSHfDKaeIU2KeiOBPlaebufABr1i1FXpmcWZRYWXBXjID+qwfNO/pe SWvjO6reXWsdpH03Jt0X9OMRH7gVYLXmsqOv867wdIBDwnQHlFrhUF3QDs6JymZRHd+V Ydii+APQxSLQh9elmMSoC7vmTb6se1ivTaPU/N5/wMZ8cz48yszUg9qg1Si+etCeuIUE 43Ru2GYMkASv5seCuWO9DFOzuPn721B3KfzTeodfHuCNAhd9tS2HuuBlq8sLK5w0M5Rv GdPPBhYcjjkaelVZt2gELkA5P7r/TRyXtI5mnxatTtvK+Mwr0/0q+jh2lIPHD5oDVNXm LdTA== X-Gm-Message-State: AOJu0Yzifo1ZcNpmpepWHG9VDMd0XCVqwtZ/WM6FWki47r3hAH2cqI63 XKqTVLDnVz+beUduB33hlEF3sbgGrpJp7Z8Z3WQC8d98wf/tPwlKF1QmFY4ypU7wHh7bP3Flccu x 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> 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