2022-01-23 20:15:53 -05:00
|
|
|
#include "opensbi/extensions/legacy.h"
|
|
|
|
|
|
|
|
namespace drivers {
|
|
|
|
namespace opensbi::legacy {
|
2022-01-23 20:27:14 -05:00
|
|
|
|
2022-01-23 20:15:53 -05:00
|
|
|
namespace {
|
|
|
|
enum class ExtensionId {
|
|
|
|
SET_TIMER,
|
|
|
|
CONSOLE_PUTCHAR,
|
|
|
|
CONSOLE_GETCHAR,
|
|
|
|
CLEAR_IPI,
|
|
|
|
SEND_IPI,
|
|
|
|
REMOTE_FENCE_I,
|
|
|
|
REMOTE_SFENCE_VMA,
|
|
|
|
REMOTE_SFENCE_VMA_ASID,
|
|
|
|
SHUTDOWN
|
|
|
|
};
|
2022-01-23 22:52:02 -05:00
|
|
|
|
|
|
|
enum class Functionid {
|
|
|
|
UNUSED
|
|
|
|
};
|
2022-01-23 20:15:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SbiRet set_timer(std::uint64_t stime_value) {
|
|
|
|
#if __riscv_xlen == 64
|
|
|
|
return ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::SET_TIMER),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED),
|
2022-01-23 20:15:53 -05:00
|
|
|
stime_value);
|
|
|
|
#else
|
|
|
|
return ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::SET_TIMER),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED),
|
2022-01-23 20:15:53 -05:00
|
|
|
static_cast<uint32_t>(stime_value),
|
|
|
|
static_cast<uint32_t>(stime_value >> 32));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
SbiRet console_putchar(int ch) {
|
|
|
|
return ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::CONSOLE_PUTCHAR),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED),
|
2022-01-23 20:15:53 -05:00
|
|
|
ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
SbiRet console_getchar() {
|
|
|
|
return ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::CONSOLE_GETCHAR),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED));
|
2022-01-23 20:15:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SbiRet clear_ipmi() {
|
|
|
|
return ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::CLEAR_IPI),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED));
|
2022-01-23 20:15:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
SbiRet send_ipmi(hart_mask_t hart_mask) {
|
|
|
|
return ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::SEND_IPI),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED),
|
2022-01-23 20:15:53 -05:00
|
|
|
reinterpret_cast<sbiword_t>(hart_mask));
|
|
|
|
}
|
|
|
|
|
|
|
|
SbiRet remote_fence_i(hart_mask_t hart_mask) {
|
|
|
|
return ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::REMOTE_FENCE_I),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED),
|
2022-01-23 20:15:53 -05:00
|
|
|
reinterpret_cast<sbiword_t>(hart_mask));
|
|
|
|
}
|
|
|
|
|
|
|
|
SbiRet remote_sfence_vma(
|
|
|
|
hart_mask_t hart_mask,
|
|
|
|
sbiword_t start,
|
|
|
|
sbiword_t size) {
|
|
|
|
return ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::REMOTE_SFENCE_VMA),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED),
|
2022-01-23 20:15:53 -05:00
|
|
|
reinterpret_cast<sbiword_t>(hart_mask),
|
|
|
|
start,
|
|
|
|
size);
|
|
|
|
}
|
|
|
|
|
|
|
|
SbiRet remote_sfence_vma_asid(
|
|
|
|
hart_mask_t hart_mask,
|
|
|
|
sbiword_t start,
|
|
|
|
sbiword_t size,
|
|
|
|
sbiword_t asid) {
|
|
|
|
return ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::REMOTE_SFENCE_VMA_ASID),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED),
|
2022-01-23 20:15:53 -05:00
|
|
|
reinterpret_cast<sbiword_t>(hart_mask),
|
|
|
|
start,
|
|
|
|
size,
|
|
|
|
asid);
|
|
|
|
}
|
|
|
|
|
|
|
|
void shutdown() {
|
|
|
|
ecall(
|
|
|
|
static_cast<sbiword_t>(ExtensionId::SHUTDOWN),
|
2022-01-23 22:52:02 -05:00
|
|
|
static_cast<sbiword_t>(Functionid::UNUSED));
|
2022-01-23 20:15:53 -05:00
|
|
|
|
|
|
|
// This should never be reached, explode if it is
|
|
|
|
__builtin_trap();
|
|
|
|
while(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End namespace opensbi::legacy
|
|
|
|
} // End namespace drivers
|
|
|
|
|