Skip to content

Commit 3203b94

Browse files
atishp04avpatel
authored andcommitted
KVM: riscv: selftests: Add SBI PMU extension definitions
The SBI PMU extension definition is required for upcoming SBI PMU selftests. Reviewed-by: Andrew Jones <[email protected]> Reviewed-by: Anup Patel <[email protected]> Signed-off-by: Atish Patra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Anup Patel <[email protected]>
1 parent 3a21b37 commit 3203b94

File tree

1 file changed

+66
-0
lines changed
  • tools/testing/selftests/kvm/include/riscv

1 file changed

+66
-0
lines changed

tools/testing/selftests/kvm/include/riscv/sbi.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,83 @@
2929
enum sbi_ext_id {
3030
SBI_EXT_BASE = 0x10,
3131
SBI_EXT_STA = 0x535441,
32+
SBI_EXT_PMU = 0x504D55,
3233
};
3334

3435
enum sbi_ext_base_fid {
3536
SBI_EXT_BASE_PROBE_EXT = 3,
3637
};
38+
enum sbi_ext_pmu_fid {
39+
SBI_EXT_PMU_NUM_COUNTERS = 0,
40+
SBI_EXT_PMU_COUNTER_GET_INFO,
41+
SBI_EXT_PMU_COUNTER_CFG_MATCH,
42+
SBI_EXT_PMU_COUNTER_START,
43+
SBI_EXT_PMU_COUNTER_STOP,
44+
SBI_EXT_PMU_COUNTER_FW_READ,
45+
SBI_EXT_PMU_COUNTER_FW_READ_HI,
46+
SBI_EXT_PMU_SNAPSHOT_SET_SHMEM,
47+
};
48+
49+
union sbi_pmu_ctr_info {
50+
unsigned long value;
51+
struct {
52+
unsigned long csr:12;
53+
unsigned long width:6;
54+
#if __riscv_xlen == 32
55+
unsigned long reserved:13;
56+
#else
57+
unsigned long reserved:45;
58+
#endif
59+
unsigned long type:1;
60+
};
61+
};
3762

3863
struct sbiret {
3964
long error;
4065
long value;
4166
};
4267

68+
/** General pmu event codes specified in SBI PMU extension */
69+
enum sbi_pmu_hw_generic_events_t {
70+
SBI_PMU_HW_NO_EVENT = 0,
71+
SBI_PMU_HW_CPU_CYCLES = 1,
72+
SBI_PMU_HW_INSTRUCTIONS = 2,
73+
SBI_PMU_HW_CACHE_REFERENCES = 3,
74+
SBI_PMU_HW_CACHE_MISSES = 4,
75+
SBI_PMU_HW_BRANCH_INSTRUCTIONS = 5,
76+
SBI_PMU_HW_BRANCH_MISSES = 6,
77+
SBI_PMU_HW_BUS_CYCLES = 7,
78+
SBI_PMU_HW_STALLED_CYCLES_FRONTEND = 8,
79+
SBI_PMU_HW_STALLED_CYCLES_BACKEND = 9,
80+
SBI_PMU_HW_REF_CPU_CYCLES = 10,
81+
82+
SBI_PMU_HW_GENERAL_MAX,
83+
};
84+
85+
/* SBI PMU counter types */
86+
enum sbi_pmu_ctr_type {
87+
SBI_PMU_CTR_TYPE_HW = 0x0,
88+
SBI_PMU_CTR_TYPE_FW,
89+
};
90+
91+
/* Flags defined for config matching function */
92+
#define SBI_PMU_CFG_FLAG_SKIP_MATCH BIT(0)
93+
#define SBI_PMU_CFG_FLAG_CLEAR_VALUE BIT(1)
94+
#define SBI_PMU_CFG_FLAG_AUTO_START BIT(2)
95+
#define SBI_PMU_CFG_FLAG_SET_VUINH BIT(3)
96+
#define SBI_PMU_CFG_FLAG_SET_VSINH BIT(4)
97+
#define SBI_PMU_CFG_FLAG_SET_UINH BIT(5)
98+
#define SBI_PMU_CFG_FLAG_SET_SINH BIT(6)
99+
#define SBI_PMU_CFG_FLAG_SET_MINH BIT(7)
100+
101+
/* Flags defined for counter start function */
102+
#define SBI_PMU_START_FLAG_SET_INIT_VALUE BIT(0)
103+
#define SBI_PMU_START_FLAG_INIT_SNAPSHOT BIT(1)
104+
105+
/* Flags defined for counter stop function */
106+
#define SBI_PMU_STOP_FLAG_RESET BIT(0)
107+
#define SBI_PMU_STOP_FLAG_TAKE_SNAPSHOT BIT(1)
108+
43109
struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0,
44110
unsigned long arg1, unsigned long arg2,
45111
unsigned long arg3, unsigned long arg4,

0 commit comments

Comments
 (0)