[PATCH v2 07/12] x86/jailhouse: Set up timekeeping
From: Jan Kiszka
Date: Mon Nov 27 2017 - 03:13:28 EST
From: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
Get the precalibrated frequencies for the TSC and the APIC timer from
the Jailhouse platform info and set the kernel values accordingly.
Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
arch/x86/kernel/jailhouse.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/arch/x86/kernel/jailhouse.c b/arch/x86/kernel/jailhouse.c
index 267547162a2c..effec7d2b480 100644
--- a/arch/x86/kernel/jailhouse.c
+++ b/arch/x86/kernel/jailhouse.c
@@ -18,6 +18,7 @@
#include <asm/setup.h>
static __initdata struct jailhouse_setup_data setup_data;
+static unsigned int precalibrated_tsc_khz;
static uint32_t jailhouse_cpuid_base(void)
{
@@ -33,6 +34,16 @@ static uint32_t __init jailhouse_detect(void)
return jailhouse_cpuid_base();
}
+static void __init jailhouse_timer_init(void)
+{
+ lapic_timer_frequency = setup_data.apic_khz * (1000 / HZ);
+}
+
+static unsigned long jailhouse_get_tsc(void)
+{
+ return precalibrated_tsc_khz;
+}
+
static void __init jailhouse_get_smp_config(unsigned int early)
{
unsigned int cpu;
@@ -68,8 +79,12 @@ static void __init jailhouse_init_platform(void)
struct setup_data header;
void *mapping;
+ x86_init.timers.timer_init = jailhouse_timer_init;
x86_init.mpparse.get_smp_config = jailhouse_get_smp_config;
+ x86_platform.calibrate_cpu = jailhouse_get_tsc;
+ x86_platform.calibrate_tsc = jailhouse_get_tsc;
+
while (pa_data) {
mapping = early_memremap(pa_data, sizeof(header));
memcpy(&header, mapping, sizeof(header));
@@ -97,6 +112,8 @@ static void __init jailhouse_init_platform(void)
pmtmr_ioport = setup_data.pm_timer_address;
pr_debug("Jailhouse: PM-Timer IO Port: %#x\n", pmtmr_ioport);
+
+ precalibrated_tsc_khz = setup_data.tsc_khz;
}
bool jailhouse_paravirt(void)
--
2.12.3