Skip to contentSkip to conversation

Eat keys on panic

PATCH In review Andi Kleen 3 participants 4 messages May 31, 2003

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 Eat keys on panic

[forgot to cc linux-kernel with the other mail]

I have a weird KVM that refuses to switch consoles when the keyboard controller doesn't process key presses. Actually it switches, but only after a long delay which usually drives me crazy.

This patch changes the panic loop to eat keys from the keyboard controller on i386 boxes. With that I can switch consoles after a panic.

The ioport should be available on all PC like boxes, the reset code also depends on it being at a fixed place.

ioport.c is not the best place in the world to place the function, but I didn't find a better one. It cannot be inlined to avoid include hell.

-Andi

Index: linux/arch/i386/kernel/ioport.c
===================================================================
RCS file: /home/cvs/linux-2.5/arch/i386/kernel/ioport.c,v retrieving revision 1.17

arch/i386/kernel/ioport.c +7 -0
diff -u -u -r1.17 ioport.c
@@ -15,6 +15,7 @@
 #include <linux/stddef.h>
 #include <linux/slab.h>
 #include <linux/thread_info.h>
+#include <asm/io.h>
 
 /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
 static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value)
@@ -128,4 +129,10 @@
 	/* Make sure we return the long way (not sysenter) */
 	set_thread_flag(TIF_IRET);
 	return 0;
+}
+
+void eat_key(void)
+{
+        if (inb(0x60) & 1) 
+                inb(0x64);
 }

Index: linux/include/asm-i386/system.h
===================================================================
RCS file: /home/cvs/linux-2.5/include/asm-i386/system.h,v retrieving revision 1.37

include/asm-i386/system.h +3 -0
diff -u -u -r1.37 system.h
@@ -476,4 +476,7 @@
 #define BROKEN_PNP_BIOS		0x0004
 #define BROKEN_CPUFREQ		0x0008
 
+#define HAVE_EAT_KEY
+void eat_key(void);
+
 #endif

Index: linux/kernel/panic.c
===================================================================
RCS file: /home/cvs/linux-2.5/kernel/panic.c,v
retrieving revision 1.20

kernel/panic.c +5 -2
diff -u -u -r1.20 panic.c
@@ -96,8 +96,11 @@
         disabled_wait(caller);
 #endif
 	local_irq_enable();
-	for (;;)
-		;
+	for (;;) { 
+#ifdef HAVE_EAT_KEY
+		eat_key();
+#endif
+	} 
 }
 
 /**
#1 lore raw

arch/i386/kernel/ioport.c line 138

Quoted 5 lines · Andi Kleen
arch/i386/kernel/ioport.c +4 -0
+void eat_key(void)
+{
+        if (inb(0x60) & 1) 
+                inb(0x64);
 }

This will crash at least one of my machines. The keyboard controller has mandatory access delays of up to 1mS. Respect them or some stuff dies horribly.

author
#2 lore raw
Quoted 11 lines · Alan Cox

Review

Quoted 5 lines · Andi Kleen
(quoted diff) +4 -0
+void eat_key(void)
+{
+        if (inb(0x60) & 1) 
+                inb(0x64);
 }

This will crash at least one of my machines. The keyboard controller has mandatory access delays of up to 1mS. Respect them or some stuff dies horribly.

1ms? Is it clocked in Khz or something?

Here is a new version that is hopefully Alan's-broken-chipset proof. I also added the request comment.

-Andi

P.S.: This is different from the panic blink code. The two can easily coexist though.

Index: linux/arch/i386/kernel/ioport.c
===================================================================
RCS file: /home/cvs/linux-2.5/arch/i386/kernel/ioport.c,v retrieving revision 1.17

arch/i386/kernel/ioport.c +12 -0
diff -u -u -r1.17 ioport.c
@@ -15,6 +15,8 @@
 #include <linux/stddef.h>
 #include <linux/slab.h>
 #include <linux/thread_info.h>
+#include <asm/io.h>
+#include <linux/delay.h>
 
 /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
 static void set_bitmap(unsigned long *bitmap, short base, short extent, int new_value)
@@ -128,4 +130,14 @@
 	/* Make sure we return the long way (not sysenter) */
 	set_thread_flag(TIF_IRET);
 	return 0;
+}
+
+/* Some KVMs don't switch consoles unless the keyboard is served. */
+void eat_key(void)
+{
+	if (inb(0x60) & 1) {
+		mdelay(1);
+		inb(0x64);
+	}
+	mdelay(1);
 }

Index: linux/include/asm-i386/system.h
===================================================================
RCS file: /home/cvs/linux-2.5/include/asm-i386/system.h,v retrieving revision 1.37

include/asm-i386/system.h +3 -0
diff -u -u -r1.37 system.h
@@ -476,4 +476,7 @@
 #define BROKEN_PNP_BIOS		0x0004
 #define BROKEN_CPUFREQ		0x0008
 
+#define HAVE_EAT_KEY
+void eat_key(void);
+
 #endif

Index: linux/kernel/panic.c
===================================================================
RCS file: /home/cvs/linux-2.5/kernel/panic.c,v
retrieving revision 1.20

kernel/panic.c +5 -2
diff -u -u -r1.20 panic.c
@@ -96,8 +96,11 @@
         disabled_wait(caller);
 #endif
 	local_irq_enable();
-	for (;;)
-		;
+	for (;;) { 
+#ifdef HAVE_EAT_KEY
+		eat_key();
+#endif
+	} 
 }
 
 /**
Quoted 2 lines
#3 lore raw

arch/i386/kernel/ioport.c line 19

Quoted 10 lines · Andi Kleen

...

arch/i386/kernel/ioport.c +2 -0
@@ -15,6 +15,8 @@
 #include <linux/stddef.h>
 #include <linux/slab.h>
 #include <linux/thread_info.h>
+#include <asm/io.h>
+#include <linux/delay.h>
...

Could you move the #include <linux/delay.h> above the #include <asm/io.h> ?

TIA
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed