Skip to content

Commit 90beae5

Browse files
atishp04palmer-dabbelt
authored andcommitted
RISC-V: Add RISC-V SBI PMU extension definitions
This patch adds all the definitions defined by the SBI PMU extension. Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Atish Patra <atish.patra@wdc.com> Signed-off-by: Atish Patra <atishp@rivosinc.com> Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 9b3e150 commit 90beae5

1 file changed

Lines changed: 95 additions & 0 deletions

File tree

  • arch/riscv/include/asm

arch/riscv/include/asm/sbi.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum sbi_ext_id {
2929
SBI_EXT_RFENCE = 0x52464E43,
3030
SBI_EXT_HSM = 0x48534D,
3131
SBI_EXT_SRST = 0x53525354,
32+
SBI_EXT_PMU = 0x504D55,
3233

3334
/* Experimentals extensions must lie within this range */
3435
SBI_EXT_EXPERIMENTAL_START = 0x08000000,
@@ -95,6 +96,98 @@ enum sbi_srst_reset_reason {
9596
SBI_SRST_RESET_REASON_SYS_FAILURE,
9697
};
9798

99+
enum sbi_ext_pmu_fid {
100+
SBI_EXT_PMU_NUM_COUNTERS = 0,
101+
SBI_EXT_PMU_COUNTER_GET_INFO,
102+
SBI_EXT_PMU_COUNTER_CFG_MATCH,
103+
SBI_EXT_PMU_COUNTER_START,
104+
SBI_EXT_PMU_COUNTER_STOP,
105+
SBI_EXT_PMU_COUNTER_FW_READ,
106+
};
107+
108+
#define RISCV_PMU_RAW_EVENT_MASK GENMASK_ULL(55, 0)
109+
#define RISCV_PMU_RAW_EVENT_IDX 0x20000
110+
111+
/** General pmu event codes specified in SBI PMU extension */
112+
enum sbi_pmu_hw_generic_events_t {
113+
SBI_PMU_HW_NO_EVENT = 0,
114+
SBI_PMU_HW_CPU_CYCLES = 1,
115+
SBI_PMU_HW_INSTRUCTIONS = 2,
116+
SBI_PMU_HW_CACHE_REFERENCES = 3,
117+
SBI_PMU_HW_CACHE_MISSES = 4,
118+
SBI_PMU_HW_BRANCH_INSTRUCTIONS = 5,
119+
SBI_PMU_HW_BRANCH_MISSES = 6,
120+
SBI_PMU_HW_BUS_CYCLES = 7,
121+
SBI_PMU_HW_STALLED_CYCLES_FRONTEND = 8,
122+
SBI_PMU_HW_STALLED_CYCLES_BACKEND = 9,
123+
SBI_PMU_HW_REF_CPU_CYCLES = 10,
124+
125+
SBI_PMU_HW_GENERAL_MAX,
126+
};
127+
128+
/**
129+
* Special "firmware" events provided by the firmware, even if the hardware
130+
* does not support performance events. These events are encoded as a raw
131+
* event type in Linux kernel perf framework.
132+
*/
133+
enum sbi_pmu_fw_generic_events_t {
134+
SBI_PMU_FW_MISALIGNED_LOAD = 0,
135+
SBI_PMU_FW_MISALIGNED_STORE = 1,
136+
SBI_PMU_FW_ACCESS_LOAD = 2,
137+
SBI_PMU_FW_ACCESS_STORE = 3,
138+
SBI_PMU_FW_ILLEGAL_INSN = 4,
139+
SBI_PMU_FW_SET_TIMER = 5,
140+
SBI_PMU_FW_IPI_SENT = 6,
141+
SBI_PMU_FW_IPI_RECVD = 7,
142+
SBI_PMU_FW_FENCE_I_SENT = 8,
143+
SBI_PMU_FW_FENCE_I_RECVD = 9,
144+
SBI_PMU_FW_SFENCE_VMA_SENT = 10,
145+
SBI_PMU_FW_SFENCE_VMA_RCVD = 11,
146+
SBI_PMU_FW_SFENCE_VMA_ASID_SENT = 12,
147+
SBI_PMU_FW_SFENCE_VMA_ASID_RCVD = 13,
148+
149+
SBI_PMU_FW_HFENCE_GVMA_SENT = 14,
150+
SBI_PMU_FW_HFENCE_GVMA_RCVD = 15,
151+
SBI_PMU_FW_HFENCE_GVMA_VMID_SENT = 16,
152+
SBI_PMU_FW_HFENCE_GVMA_VMID_RCVD = 17,
153+
154+
SBI_PMU_FW_HFENCE_VVMA_SENT = 18,
155+
SBI_PMU_FW_HFENCE_VVMA_RCVD = 19,
156+
SBI_PMU_FW_HFENCE_VVMA_ASID_SENT = 20,
157+
SBI_PMU_FW_HFENCE_VVMA_ASID_RCVD = 21,
158+
SBI_PMU_FW_MAX,
159+
};
160+
161+
/* SBI PMU event types */
162+
enum sbi_pmu_event_type {
163+
SBI_PMU_EVENT_TYPE_HW = 0x0,
164+
SBI_PMU_EVENT_TYPE_CACHE = 0x1,
165+
SBI_PMU_EVENT_TYPE_RAW = 0x2,
166+
SBI_PMU_EVENT_TYPE_FW = 0xf,
167+
};
168+
169+
/* SBI PMU event types */
170+
enum sbi_pmu_ctr_type {
171+
SBI_PMU_CTR_TYPE_HW = 0x0,
172+
SBI_PMU_CTR_TYPE_FW,
173+
};
174+
175+
/* Flags defined for config matching function */
176+
#define SBI_PMU_CFG_FLAG_SKIP_MATCH (1 << 0)
177+
#define SBI_PMU_CFG_FLAG_CLEAR_VALUE (1 << 1)
178+
#define SBI_PMU_CFG_FLAG_AUTO_START (1 << 2)
179+
#define SBI_PMU_CFG_FLAG_SET_VUINH (1 << 3)
180+
#define SBI_PMU_CFG_FLAG_SET_VSNH (1 << 4)
181+
#define SBI_PMU_CFG_FLAG_SET_UINH (1 << 5)
182+
#define SBI_PMU_CFG_FLAG_SET_SINH (1 << 6)
183+
#define SBI_PMU_CFG_FLAG_SET_MINH (1 << 7)
184+
185+
/* Flags defined for counter start function */
186+
#define SBI_PMU_START_FLAG_SET_INIT_VALUE (1 << 0)
187+
188+
/* Flags defined for counter stop function */
189+
#define SBI_PMU_STOP_FLAG_RESET (1 << 0)
190+
98191
#define SBI_SPEC_VERSION_DEFAULT 0x1
99192
#define SBI_SPEC_VERSION_MAJOR_SHIFT 24
100193
#define SBI_SPEC_VERSION_MAJOR_MASK 0x7f
@@ -108,6 +201,8 @@ enum sbi_srst_reset_reason {
108201
#define SBI_ERR_DENIED -4
109202
#define SBI_ERR_INVALID_ADDRESS -5
110203
#define SBI_ERR_ALREADY_AVAILABLE -6
204+
#define SBI_ERR_ALREADY_STARTED -7
205+
#define SBI_ERR_ALREADY_STOPPED -8
111206

112207
extern unsigned long sbi_spec_version;
113208
struct sbiret {

0 commit comments

Comments
 (0)