QTechOS/kernel/drivers/opensbi/extensions/pmu.cpp

85 lines
2.4 KiB
C++

#include "opensbi/extensions/pmu.h"
namespace drivers {
namespace opensbi::pmu {
namespace {
enum class ExtensionId {
PMU = 0x504D55
};
enum class FunctionId {
NUM_COUNTERS,
COUNTER_GET_INFO,
COUNTER_CONFIG_MATCHING,
COUNTER_START,
COUNTER_STOP,
COUNTER_FW_READ
};
}
SbiRet num_counters() {
return ecall(
static_cast<sbiword_t>(ExtensionId::PMU),
static_cast<sbiword_t>(FunctionId::NUM_COUNTERS));
}
SbiRet counter_get_info(unsigned long counter_idx) {
return ecall(
static_cast<sbiword_t>(ExtensionId::PMU),
static_cast<sbiword_t>(FunctionId::COUNTER_GET_INFO),
counter_idx);
}
SbiRet counter_config_matching(
unsigned long counter_idx_base,
unsigned long counter_idx_mask,
unsigned long config_flags,
unsigned long event_idx,
uint64_t event_data) {
return ecall(
static_cast<sbiword_t>(ExtensionId::PMU),
static_cast<sbiword_t>(FunctionId::COUNTER_CONFIG_MATCHING),
counter_idx_base,
counter_idx_mask,
config_flags,
event_idx,
event_data);
}
SbiRet counter_start(
unsigned long counter_idx_base,
unsigned long counter_idx_mask,
unsigned long start_flags,
uint64_t initial_value) {
return ecall(
static_cast<sbiword_t>(ExtensionId::PMU),
static_cast<sbiword_t>(FunctionId::COUNTER_START),
counter_idx_base,
counter_idx_mask,
start_flags,
initial_value);
}
SbiRet counter_stop(
unsigned long counter_idx_base,
unsigned long counter_idx_mask,
unsigned long stop_flags) {
return ecall(
static_cast<sbiword_t>(ExtensionId::PMU),
static_cast<sbiword_t>(FunctionId::COUNTER_STOP),
counter_idx_base,
counter_idx_mask,
stop_flags);
}
SbiRet counter_fw_read(unsigned long counter_idx) {
return ecall(
static_cast<sbiword_t>(ExtensionId::PMU),
static_cast<sbiword_t>(FunctionId::COUNTER_FW_READ),
counter_idx);
}
} // End namespace opensbi::pmu
} // End namespace drivers