Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * 8253/PIT functions
0004  *
0005  */
0006 #include <linux/clockchips.h>
0007 #include <linux/init.h>
0008 #include <linux/timex.h>
0009 #include <linux/i8253.h>
0010 
0011 #include <asm/apic.h>
0012 #include <asm/hpet.h>
0013 #include <asm/time.h>
0014 #include <asm/smp.h>
0015 
0016 /*
0017  * HPET replaces the PIT, when enabled. So we need to know, which of
0018  * the two timers is used
0019  */
0020 struct clock_event_device *global_clock_event;
0021 
0022 /*
0023  * Modern chipsets can disable the PIT clock which makes it unusable. It
0024  * would be possible to enable the clock but the registers are chipset
0025  * specific and not discoverable. Avoid the whack a mole game.
0026  *
0027  * These platforms have discoverable TSC/CPU frequencies but this also
0028  * requires to know the local APIC timer frequency as it normally is
0029  * calibrated against the PIT interrupt.
0030  */
0031 static bool __init use_pit(void)
0032 {
0033     if (!IS_ENABLED(CONFIG_X86_TSC) || !boot_cpu_has(X86_FEATURE_TSC))
0034         return true;
0035 
0036     /* This also returns true when APIC is disabled */
0037     return apic_needs_pit();
0038 }
0039 
0040 bool __init pit_timer_init(void)
0041 {
0042     if (!use_pit())
0043         return false;
0044 
0045     clockevent_i8253_init(true);
0046     global_clock_event = &i8253_clockevent;
0047     return true;
0048 }
0049 
0050 #ifndef CONFIG_X86_64
0051 static int __init init_pit_clocksource(void)
0052 {
0053      /*
0054       * Several reasons not to register PIT as a clocksource:
0055       *
0056       * - On SMP PIT does not scale due to i8253_lock
0057       * - when HPET is enabled
0058       * - when local APIC timer is active (PIT is switched off)
0059       */
0060     if (num_possible_cpus() > 1 || is_hpet_enabled() ||
0061         !clockevent_state_periodic(&i8253_clockevent))
0062         return 0;
0063 
0064     return clocksource_i8253_init();
0065 }
0066 arch_initcall(init_pit_clocksource);
0067 #endif /* !CONFIG_X86_64 */