diff -urN linux-2.4.15-pre4/arch/i386/kernel/time.c linux/arch/i386/kernel/time.c --- linux-2.4.15-pre4/arch/i386/kernel/time.c Mon Nov 12 22:31:52 2001 +++ linux/arch/i386/kernel/time.c Mon Nov 12 22:52:25 2001 @@ -112,6 +112,50 @@ return delay_at_last_interrupt + edx; } +/* + * VIA hardware bug workaround with check if it is really needed and + * a printk that could tell us what's exactly happening on machines which + * trigger the check, but are not VIA-based. + * + * Must be called with the i8253_spinlock held. + */ + +static void via_reset_and_whine(int *count) +{ + static unsigned long last_whine = 0; + unsigned long new_whine; + int count2; + + new_whine = last_whine; + + outb_p(0x00, 0x43); /* Re-read the timer */ + count2 = inb_p(0x40); + count2 |= inb(0x40) << 8; + + if (time_after(jiffies, last_whine)) { + printk(KERN_WARNING "timer.c: VIA bug check triggered. " + "Value read %d [%#x], re-read %d [%#x]\n", + *count, *count, count2, count2); + new_whine = jiffies + HZ; + } + + *count = count2; + + if (count2 > LATCH) { /* Still bad */ + if (time_after(jiffies, last_whine)) { + printk(KERN_WARNING "timer.c VIA bug really present. " + "Resetting PIT timer.\n"); + new_whine = jiffies + HZ; + } + outb_p(0x34, 0x43); + outb_p(LATCH & 0xff, 0x40); + outb(LATCH >> 8, 0x40); + *count = LATCH - 1; + } + + last_whine = new_whine; +} + #define TICK_SIZE tick spinlock_t i8253_lock = SPIN_LOCK_UNLOCKED; @@ -180,12 +224,8 @@ count |= inb_p(0x40) << 8; /* VIA686a test code... reset the latch if count > max + 1 */ - if (count > LATCH) { - outb_p(0x34, 0x43); - outb_p(LATCH & 0xff, 0x40); - outb(LATCH >> 8, 0x40); - count = LATCH - 1; - } + if (count > LATCH) + via_reset_and_whine(&count); spin_unlock(&i8253_lock); @@ -501,6 +541,10 @@ count = inb_p(0x40); /* read the latched count */ count |= inb(0x40) << 8; + + if (count > LATCH) + via_reset_and_whine(&count); + spin_unlock(&i8253_lock); count = ((LATCH-1) - count) * TICK_SIZE;