include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / arch / x86 / kernel / hpet.c
index dedc2bd..d10a7e7 100644 (file)
@@ -4,6 +4,7 @@
 #include <linux/sysdev.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
+#include <linux/slab.h>
 #include <linux/hpet.h>
 #include <linux/init.h>
 #include <linux/cpu.h>
@@ -33,6 +34,9 @@
  * HPET address is set in acpi/boot.c, when an ACPI entry exists
  */
 unsigned long                          hpet_address;
+u8                                     hpet_blockid; /* OS timer block num */
+u8                                     hpet_msi_disable;
+
 #ifdef CONFIG_PCI_MSI
 static unsigned long                   hpet_num_timers;
 #endif
@@ -47,12 +51,12 @@ struct hpet_dev {
        char                            name[10];
 };
 
-unsigned long hpet_readl(unsigned long a)
+inline unsigned int hpet_readl(unsigned int a)
 {
        return readl(hpet_virt_address + a);
 }
 
-static inline void hpet_writel(unsigned long d, unsigned long a)
+static inline void hpet_writel(unsigned int d, unsigned int a)
 {
        writel(d, hpet_virt_address + a);
 }
@@ -167,7 +171,7 @@ do {                                                                \
 
 static void hpet_reserve_msi_timers(struct hpet_data *hd);
 
-static void hpet_reserve_platform_timers(unsigned long id)
+static void hpet_reserve_platform_timers(unsigned int id)
 {
        struct hpet __iomem *hpet = hpet_virt_address;
        struct hpet_timer __iomem *timer = &hpet->hpet_timers[2];
@@ -205,7 +209,7 @@ static void hpet_reserve_platform_timers(unsigned long id)
 
 }
 #else
-static void hpet_reserve_platform_timers(unsigned long id) { }
+static void hpet_reserve_platform_timers(unsigned int id) { }
 #endif
 
 /*
@@ -246,7 +250,7 @@ static void hpet_reset_counter(void)
 
 static void hpet_start_counter(void)
 {
-       unsigned long cfg = hpet_readl(HPET_CFG);
+       unsigned int cfg = hpet_readl(HPET_CFG);
        cfg |= HPET_CFG_ENABLE;
        hpet_writel(cfg, HPET_CFG);
 }
@@ -263,7 +267,7 @@ static void hpet_resume_device(void)
        force_hpet_resume();
 }
 
-static void hpet_resume_counter(void)
+static void hpet_resume_counter(struct clocksource *cs)
 {
        hpet_resume_device();
        hpet_restart_counter();
@@ -271,7 +275,7 @@ static void hpet_resume_counter(void)
 
 static void hpet_enable_legacy_int(void)
 {
-       unsigned long cfg = hpet_readl(HPET_CFG);
+       unsigned int cfg = hpet_readl(HPET_CFG);
 
        cfg |= HPET_CFG_LEGACY;
        hpet_writel(cfg, HPET_CFG);
@@ -314,7 +318,7 @@ static int hpet_setup_msi_irq(unsigned int irq);
 static void hpet_set_mode(enum clock_event_mode mode,
                          struct clock_event_device *evt, int timer)
 {
-       unsigned long cfg, cmp, now;
+       unsigned int cfg, cmp, now;
        uint64_t delta;
 
        switch (mode) {
@@ -323,7 +327,7 @@ static void hpet_set_mode(enum clock_event_mode mode,
                delta = ((uint64_t)(NSEC_PER_SEC/HZ)) * evt->mult;
                delta >>= evt->shift;
                now = hpet_readl(HPET_COUNTER);
-               cmp = now + (unsigned long) delta;
+               cmp = now + (unsigned int) delta;
                cfg = hpet_readl(HPET_Tn_CFG(timer));
                /* Make sure we use edge triggered interrupts */
                cfg &= ~HPET_TN_LEVEL;
@@ -339,7 +343,7 @@ static void hpet_set_mode(enum clock_event_mode mode,
                 * (See AMD-8111 HyperTransport I/O Hub Data Sheet,
                 * Publication # 24674)
                 */
-               hpet_writel((unsigned long) delta, HPET_Tn_CMP(timer));
+               hpet_writel((unsigned int) delta, HPET_Tn_CMP(timer));
                hpet_start_counter();
                hpet_print_config();
                break;
@@ -383,13 +387,24 @@ static int hpet_next_event(unsigned long delta,
        hpet_writel(cnt, HPET_Tn_CMP(timer));
 
        /*
-        * We need to read back the CMP register to make sure that
-        * what we wrote hit the chip before we compare it to the
-        * counter.
+        * We need to read back the CMP register on certain HPET
+        * implementations (ATI chipsets) which seem to delay the
+        * transfer of the compare register into the internal compare
+        * logic. With small deltas this might actually be too late as
+        * the counter could already be higher than the compare value
+        * at that point and we would wait for the next hpet interrupt
+        * forever. We found out that reading the CMP register back
+        * forces the transfer so we can rely on the comparison with
+        * the counter register below. If the read back from the
+        * compare register does not match the value we programmed
+        * then we might have a real hardware problem. We can not do
+        * much about it here, but at least alert the user/admin with
+        * a prominent warning.
         */
-       WARN_ON_ONCE((u32)hpet_readl(HPET_Tn_CMP(timer)) != cnt);
+       WARN_ONCE(hpet_readl(HPET_Tn_CMP(timer)) != cnt,
+                 KERN_WARNING "hpet: compare register read back failed.\n");
 
-       return (s32)((u32)hpet_readl(HPET_COUNTER) - cnt) >= 0 ? -ETIME : 0;
+       return (s32)(hpet_readl(HPET_COUNTER) - cnt) >= 0 ? -ETIME : 0;
 }
 
 static void hpet_legacy_set_mode(enum clock_event_mode mode,
@@ -415,7 +430,7 @@ static struct hpet_dev      *hpet_devs;
 void hpet_msi_unmask(unsigned int irq)
 {
        struct hpet_dev *hdev = get_irq_data(irq);
-       unsigned long cfg;
+       unsigned int cfg;
 
        /* unmask it */
        cfg = hpet_readl(HPET_Tn_CFG(hdev->num));
@@ -425,7 +440,7 @@ void hpet_msi_unmask(unsigned int irq)
 
 void hpet_msi_mask(unsigned int irq)
 {
-       unsigned long cfg;
+       unsigned int cfg;
        struct hpet_dev *hdev = get_irq_data(irq);
 
        /* mask it */
@@ -467,7 +482,7 @@ static int hpet_msi_next_event(unsigned long delta,
 
 static int hpet_setup_msi_irq(unsigned int irq)
 {
-       if (arch_setup_hpet_msi(irq)) {
+       if (arch_setup_hpet_msi(irq, hpet_blockid)) {
                destroy_irq(irq);
                return -EINVAL;
        }
@@ -584,6 +599,11 @@ static void hpet_msi_capability_lookup(unsigned int start_timer)
        unsigned int num_timers_used = 0;
        int i;
 
+       if (hpet_msi_disable)
+               return;
+
+       if (boot_cpu_has(X86_FEATURE_ARAT))
+               return;
        id = hpet_readl(HPET_ID);
 
        num_timers = ((id & HPET_ID_NUMBER) >> HPET_ID_NUMBER_SHIFT);
@@ -598,7 +618,7 @@ static void hpet_msi_capability_lookup(unsigned int start_timer)
 
        for (i = start_timer; i < num_timers - RESERVE_TIMERS; i++) {
                struct hpet_dev *hdev = &hpet_devs[num_timers_used];
-               unsigned long cfg = hpet_readl(HPET_Tn_CFG(i));
+               unsigned int cfg = hpet_readl(HPET_Tn_CFG(i));
 
                /* Only consider HPET timer with MSI support */
                if (!(cfg & HPET_TN_FSB_CAP))
@@ -813,7 +833,7 @@ static int hpet_clocksource_register(void)
  */
 int __init hpet_enable(void)
 {
-       unsigned long id;
+       unsigned int id;
        int i;
 
        if (!is_hpet_capable())
@@ -872,10 +892,8 @@ int __init hpet_enable(void)
 
        if (id & HPET_ID_LEGSUP) {
                hpet_legacy_clockevent_register();
-               hpet_msi_capability_lookup(2);
                return 1;
        }
-       hpet_msi_capability_lookup(0);
        return 0;
 
 out_nohpet:
@@ -908,9 +926,20 @@ static __init int hpet_late_init(void)
        if (!hpet_virt_address)
                return -ENODEV;
 
+       if (hpet_readl(HPET_ID) & HPET_ID_LEGSUP)
+               hpet_msi_capability_lookup(2);
+       else
+               hpet_msi_capability_lookup(0);
+
        hpet_reserve_platform_timers(hpet_readl(HPET_ID));
        hpet_print_config();
 
+       if (hpet_msi_disable)
+               return 0;
+
+       if (boot_cpu_has(X86_FEATURE_ARAT))
+               return 0;
+
        for_each_online_cpu(cpu) {
                hpet_cpuhp_notify(NULL, CPU_ONLINE, (void *)(long)cpu);
        }
@@ -925,7 +954,7 @@ fs_initcall(hpet_late_init);
 void hpet_disable(void)
 {
        if (is_hpet_capable()) {
-               unsigned long cfg = hpet_readl(HPET_CFG);
+               unsigned int cfg = hpet_readl(HPET_CFG);
 
                if (hpet_legacy_int_enabled) {
                        cfg &= ~HPET_CFG_LEGACY;
@@ -965,8 +994,8 @@ static int hpet_prev_update_sec;
 static struct rtc_time hpet_alarm_time;
 static unsigned long hpet_pie_count;
 static u32 hpet_t1_cmp;
-static unsigned long hpet_default_delta;
-static unsigned long hpet_pie_delta;
+static u32 hpet_default_delta;
+static u32 hpet_pie_delta;
 static unsigned long hpet_pie_limit;
 
 static rtc_irq_handler irq_handler;
@@ -1017,7 +1046,8 @@ EXPORT_SYMBOL_GPL(hpet_unregister_irq_handler);
  */
 int hpet_rtc_timer_init(void)
 {
-       unsigned long cfg, cnt, delta, flags;
+       unsigned int cfg, cnt, delta;
+       unsigned long flags;
 
        if (!is_hpet_enabled())
                return 0;
@@ -1027,7 +1057,7 @@ int hpet_rtc_timer_init(void)
 
                clc = (uint64_t) hpet_clockevent.mult * NSEC_PER_SEC;
                clc >>= hpet_clockevent.shift + DEFAULT_RTC_SHIFT;
-               hpet_default_delta = (unsigned long) clc;
+               hpet_default_delta = clc;
        }
 
        if (!(hpet_rtc_flags & RTC_PIE) || hpet_pie_limit)
@@ -1113,7 +1143,7 @@ int hpet_set_periodic_freq(unsigned long freq)
                clc = (uint64_t) hpet_clockevent.mult * NSEC_PER_SEC;
                do_div(clc, freq);
                clc >>= hpet_clockevent.shift;
-               hpet_pie_delta = (unsigned long) clc;
+               hpet_pie_delta = clc;
        }
        return 1;
 }
@@ -1127,7 +1157,7 @@ EXPORT_SYMBOL_GPL(hpet_rtc_dropped_irq);
 
 static void hpet_rtc_timer_reinit(void)
 {
-       unsigned long cfg, delta;
+       unsigned int cfg, delta;
        int lost_ints = -1;
 
        if (unlikely(!hpet_rtc_flags)) {