OpenSBI: Added PMU(Performance Monitoring Unit) extension
This commit is contained in:
parent
e149b8d503
commit
b78b3f5763
3 changed files with 120 additions and 1 deletions
85
kernel/drivers/opensbi/extensions/pmu.cpp
Normal file
85
kernel/drivers/opensbi/extensions/pmu.cpp
Normal file
|
@ -0,0 +1,85 @@
|
|||
#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
|
||||
|
33
kernel/drivers/opensbi/include/opensbi/extensions/pmu.h
Normal file
33
kernel/drivers/opensbi/include/opensbi/extensions/pmu.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include "opensbi/opensbi.h"
|
||||
|
||||
namespace drivers {
|
||||
namespace opensbi::pmu {
|
||||
|
||||
SbiRet num_counters();
|
||||
|
||||
SbiRet counter_get_info(unsigned long 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);
|
||||
|
||||
SbiRet counter_start(
|
||||
unsigned long counter_idx_base,
|
||||
unsigned long counter_idx_mask,
|
||||
unsigned long start_flags,
|
||||
uint64_t initial_value);
|
||||
|
||||
SbiRet counter_stop(
|
||||
unsigned long counter_idx_base,
|
||||
unsigned long counter_idx_mask,
|
||||
unsigned long stop_flags);
|
||||
|
||||
SbiRet counter_fw_read(unsigned long counter_idx);
|
||||
|
||||
} // End namespace opensbi::pmu
|
||||
} // End namespace drivers
|
|
@ -7,7 +7,8 @@ kernel_sources += [
|
|||
'extensions/ipi.cpp',
|
||||
'extensions/rfence.cpp',
|
||||
'extensions/hsm.cpp',
|
||||
'extensions/srst.cpp'
|
||||
'extensions/srst.cpp',
|
||||
'extensions/pmu.cpp'
|
||||
),
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in a new issue