Implement the initial configuration of the timer to be used by the
hardlockup detector. Return a data structure with a description of the
timer; this information is subsequently used by the hardlockup detector.

Only provide the timer if it supports Front Side Bus interrupt delivery.
This condition greatly simplifies the implementation of the detector.
Specifically, it helps to avoid the complexities of routing the interrupt
via the IO-APIC (e.g., potential race conditions that arise from re-
programming the IO-APIC in NMI context).

Cc: "H. Peter Anvin" <h...@zytor.com>
Cc: Ashok Raj <ashok....@intel.com>
Cc: Andi Kleen <andi.kl...@intel.com>
Cc: Tony Luck <tony.l...@intel.com>
Cc: Clemens Ladisch <clem...@ladisch.de>
Cc: Arnd Bergmann <a...@arndb.de>
Cc: Philippe Ombredanne <pombreda...@nexb.com>
Cc: Kate Stewart <kstew...@linuxfoundation.org>
Cc: "Rafael J. Wysocki" <rafael.j.wyso...@intel.com>
Cc: Stephane Eranian <eran...@google.com>
Cc: Suravee Suthikulpanit <suravee.suthikulpa...@amd.com>
Cc: "Ravi V. Shankar" <ravi.v.shan...@intel.com>
Cc: x...@kernel.org
Signed-off-by: Ricardo Neri <ricardo.neri-calde...@linux.intel.com>
---
 arch/x86/include/asm/hpet.h | 13 +++++++++++++
 arch/x86/kernel/hpet.c      | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+)

diff --git a/arch/x86/include/asm/hpet.h b/arch/x86/include/asm/hpet.h
index 6f099e2781ce..20abdaa5372d 100644
--- a/arch/x86/include/asm/hpet.h
+++ b/arch/x86/include/asm/hpet.h
@@ -109,6 +109,19 @@ extern void hpet_set_comparator(int num, unsigned int cmp, 
unsigned int period);
 
 #endif /* CONFIG_HPET_EMULATE_RTC */
 
+#ifdef CONFIG_X86_HARDLOCKUP_DETECTOR_HPET
+struct hpet_hld_data {
+       bool            has_periodic;
+       u32             num;
+       u64             ticks_per_second;
+};
+
+extern struct hpet_hld_data *hpet_hardlockup_detector_assign_timer(void);
+#else
+static inline struct hpet_hld_data *hpet_hardlockup_detector_assign_timer(void)
+{ return NULL; }
+#endif /* CONFIG_X86_HARDLOCKUP_DETECTOR_HPET */
+
 #else /* CONFIG_HPET_TIMER */
 
 static inline int hpet_enable(void) { return 0; }
diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
index ff0250831786..5f9209949fc7 100644
--- a/arch/x86/kernel/hpet.c
+++ b/arch/x86/kernel/hpet.c
@@ -171,6 +171,41 @@ do {                                                       
        \
                _hpet_print_config(__func__, __LINE__); \
 } while (0)
 
+#ifdef CONFIG_X86_HARDLOCKUP_DETECTOR_HPET
+struct hpet_hld_data *hpet_hardlockup_detector_assign_timer(void)
+{
+       struct hpet_hld_data *hdata;
+       u64 temp;
+       u32 cfg;
+
+       cfg = hpet_readl(HPET_Tn_CFG(HPET_WD_TIMER_NR));
+
+       if (!(cfg & HPET_TN_FSB_CAP))
+               return NULL;
+
+       hdata = kzalloc(sizeof(*hdata), GFP_KERNEL);
+       if (!hdata)
+               return NULL;
+
+       if (cfg & HPET_TN_PERIODIC_CAP)
+               hdata->has_periodic = true;
+
+       hdata->num = HPET_WD_TIMER_NR;
+
+       cfg = hpet_readl(HPET_PERIOD);
+
+       /*
+        * hpet_get_ticks_per_sec() expects the contents of the general
+        * capabilities register. The period is in the 32 most significant
+        * bits.
+        */
+       temp = (u64)cfg << HPET_COUNTER_CLK_PERIOD_SHIFT;
+       hdata->ticks_per_second = hpet_get_ticks_per_sec(temp);
+
+       return hdata;
+}
+#endif /* CONFIG_X86_HARDLOCKUP_DETECTOR_HPET */
+
 /*
  * When the hpet driver (/dev/hpet) is enabled, we need to reserve
  * timer 0 and timer 1 in case of RTC emulation. Timer 2 is reserved in case
-- 
2.17.1

Reply via email to