Commit 3222daf9 authored by Thomas Gleixner's avatar Thomas Gleixner

x86/hpet: Separate counter check out of clocksource register code

The init code checks whether the HPET counter works late in the init
function when the clocksource is registered. That should happen right with
the other sanity checks.

Split it into a separate validation function and move it to the other
sanity checks.
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Reviewed-by: default avatarIngo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Cc: Ashok Raj <ashok.raj@intel.com>
Cc: Andi Kleen <andi.kleen@intel.com>
Cc: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Ravi Shankar <ravi.v.shankar@intel.com>
Link: https://lkml.kernel.org/r/20190623132435.058540608@linutronix.de
parent 6bdec41a
...@@ -809,38 +809,6 @@ static struct clocksource clocksource_hpet = { ...@@ -809,38 +809,6 @@ static struct clocksource clocksource_hpet = {
.resume = hpet_resume_counter, .resume = hpet_resume_counter,
}; };
static int __init hpet_clocksource_register(void)
{
u64 start, now;
u64 t1;
/* Start the counter */
hpet_restart_counter();
/* Verify whether hpet counter works */
t1 = hpet_readl(HPET_COUNTER);
start = rdtsc();
/*
* We don't know the TSC frequency yet, but waiting for
* 200000 TSC cycles is safe:
* 4 GHz == 50us
* 1 GHz == 200us
*/
do {
rep_nop();
now = rdtsc();
} while ((now - start) < 200000UL);
if (t1 == hpet_readl(HPET_COUNTER)) {
pr_warn("Counter not counting. HPET disabled\n");
return -ENODEV;
}
clocksource_register_hz(&clocksource_hpet, (u32)hpet_freq);
return 0;
}
/* /*
* AMD SB700 based systems with spread spectrum enabled use a SMM based * AMD SB700 based systems with spread spectrum enabled use a SMM based
* HPET emulation to provide proper frequency setting. * HPET emulation to provide proper frequency setting.
...@@ -869,6 +837,32 @@ static bool __init hpet_cfg_working(void) ...@@ -869,6 +837,32 @@ static bool __init hpet_cfg_working(void)
return false; return false;
} }
static bool __init hpet_counting(void)
{
u64 start, now, t1;
hpet_restart_counter();
t1 = hpet_readl(HPET_COUNTER);
start = rdtsc();
/*
* We don't know the TSC frequency yet, but waiting for
* 200000 TSC cycles is safe:
* 4 GHz == 50us
* 1 GHz == 200us
*/
do {
rep_nop();
now = rdtsc();
} while ((now - start) < 200000UL);
if (t1 == hpet_readl(HPET_COUNTER)) {
pr_warn("Counter not counting. HPET disabled\n");
return false;
}
return true;
}
/** /**
* hpet_enable - Try to setup the HPET timer. Returns 1 on success. * hpet_enable - Try to setup the HPET timer. Returns 1 on success.
...@@ -890,6 +884,10 @@ int __init hpet_enable(void) ...@@ -890,6 +884,10 @@ int __init hpet_enable(void)
if (!hpet_cfg_working()) if (!hpet_cfg_working())
goto out_nohpet; goto out_nohpet;
/* Validate that the counter is counting */
if (!hpet_counting())
goto out_nohpet;
/* /*
* Read the period and check for a sane value: * Read the period and check for a sane value:
*/ */
...@@ -948,8 +946,7 @@ int __init hpet_enable(void) ...@@ -948,8 +946,7 @@ int __init hpet_enable(void)
} }
hpet_print_config(); hpet_print_config();
if (hpet_clocksource_register()) clocksource_register_hz(&clocksource_hpet, (u32)hpet_freq);
goto out_nohpet;
if (id & HPET_ID_LEGSUP) { if (id & HPET_ID_LEGSUP) {
hpet_legacy_clockevent_register(); hpet_legacy_clockevent_register();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment