Files
2026-05-27 19:34:54 +02:00

32 lines
1.0 KiB
C

// SPDX-License-Identifier: MPL-2.0
#ifndef SH_LIB_TSC_H
#define SH_LIB_TSC_H
#include "std/type.h"
#include "std/status.h"
#include "cpu/asm.h"
#include "devs/devs.h"
typedef sh_uint64 sh_tsc_TSC_VALUE;
// Reas TSC register.
static inline sh_tsc_TSC_VALUE sh_tsc_read_tsc() {
return sh_asm_rdtsc();
}
// Init kernel start tsc. Intended for single use only.
SH_STATUS sh_tsc_init_tsc();
// Return kernel start tsc.
sh_tsc_TSC_VALUE sh_tsc_get_kernel_init_tsc();
// Return kernel current tsc.
sh_tsc_TSC_VALUE sh_tsc_get_kernel_current_tsc();
// Estimate CPU frequency using TSC and PIT
sh_uint64 sh_tsc_estimate_cpu_freq();
// Load CPU frequency
void sh_tsc_load_cpu_freq(sh_uint64 cpu_freq);
// Detect if CPUID provide hypervisor bit
sh_bool sh_tsc_has_hypervisor();
// Detect if CPUID provide TSC constant bit
sh_bool sh_tsc_is_tsc_constant();
// Return CPUID CPU frequence if available
SH_STATUS sh_tsc_get_cpu_freq_cpuid(sh_uint64 *freq);
// Parse a TSC DevS query
SH_STATUS sh_tsc_devs_query(char *sub_path,sh_devs_RESULT *result);
#endif