From 98218e92ae6a3dee34421dcb354e5540cb0cdc05 Mon Sep 17 00:00:00 2001
From: Andrew Morton <akpm@osdl.org>
Date: Tue, 8 Jun 2004 18:18:31 -0700
Subject: [PATCH] [PATCH] cyclone: PIT sanity checking

From: john stultz <johnstul@us.ibm.com>

In testing for SLES9, we ran across a bug caused by userspace apps poking
the PIT which caused bad values to be read by the kernel.  This would then
trigger the lost tick detection code with insane values and would then
break the SCSI subsystem.

This patch includes the PIT sanity check from the TSC timesource into the
cyclone timesource code, which catches the bad case described above and
resolves the issue.

Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
---
 arch/i386/kernel/timers/timer_cyclone.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/i386/kernel/timers/timer_cyclone.c b/arch/i386/kernel/timers/timer_cyclone.c
index 9f80757d15fa..34f1f3d1cd21 100644
--- a/arch/i386/kernel/timers/timer_cyclone.c
+++ b/arch/i386/kernel/timers/timer_cyclone.c
@@ -17,6 +17,7 @@
 #include <asm/io.h>
 #include <asm/pgtable.h>
 #include <asm/fixmap.h>
+#include "io_ports.h"
 
 extern spinlock_t i8253_lock;
 
@@ -62,6 +63,17 @@ static void mark_offset_cyclone(void)
 
 	count = inb_p(0x40);    /* read the latched count */
 	count |= inb(0x40) << 8;
+
+	/*
+	 * VIA686a test code... reset the latch if count > max + 1
+	 * from timer_pit.c - cjb
+	 */
+	if (count > LATCH) {
+		outb_p(0x34, PIT_MODE);
+		outb_p(LATCH & 0xff, PIT_CH0);
+		outb(LATCH >> 8, PIT_CH0);
+		count = LATCH - 1;
+	}
 	spin_unlock(&i8253_lock);
 
 	/* lost tick compensation */
-- 
2.30.9