From ernie!bert.kts.org!hm@ppp.net  Mon Jun 29 06:32:09 1998
Received: from mail.ppp.net (mail.ppp.net [194.64.12.35])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id GAA14716
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 29 Jun 1998 06:32:05 -0700 (PDT)
          (envelope-from ernie!bert.kts.org!hm@ppp.net)
Received: from casparc.ppp.net (casparc2.ppp.net [194.64.12.42])
	by mail.ppp.net (8.8.8/8.8.8) with SMTP id PAA19575
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 29 Jun 1998 15:32:01 +0200
Received: from ernie by casparc.ppp.net with uucp
	(Smail3.1.28.1 #1) id m0yqe2L-002ZjZC; Mon, 29 Jun 98 15:32 MET DST
Received: from bert.kts.org(really [194.55.156.2]) by ernie.kts.org
	via sendmail with smtp
	id <m0yqdpu-00002KC@ernie.kts.org>
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 29 Jun 1998 15:19:10 +0200 (CEST)
	(Smail-3.2.0.91 1997-Jan-14 #3 built 1998-Feb-14)
Received: by bert.kts.org
	via sendmail with stdio
	id <m0yqdlI-000020C@bert.kts.org>
	for FreeBSD-gnats-submit@freebsd.org; Mon, 29 Jun 1998 15:14:24 +0200 (CEST)
	(Smail-3.2.0.94 1997-Apr-22 #1 built 1998-Jun-6)
Message-Id: <m0yqdlI-000020C@bert.kts.org>
Date: Mon, 29 Jun 1998 15:14:24 +0200 (CEST)
From: hm@kts.org
Reply-To: hm@kts.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: pcvt: kernel panic when reconnecting keyboard
X-Send-Pr-Version: 3.2

>Number:         7108
>Category:       i386
>Synopsis:       pcvt: kernel panic when reconnecting keyboard after keyboard-less boot
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 29 06:40:01 PDT 1998
>Closed-Date:    Fri Jul 3 07:32:22 PDT 1998
>Last-Modified:  Fri Jul  3 07:35:39 PDT 1998
>Originator:     Hellmuth Michaelis
>Release:        FreeBSD 2.2.6-RELEASE i386
>Organization:
Kitchen Table Systems
>Environment:

	In the kernel config(8) file, replace the line
		device sc0 at isa? port "IO_KBD" tty irq 1 vector scintr
	with
		device vt0 at isa? port "IO_KBD" tty irq 1 vector pcrint
	to enable the pcvt console driver and disable the syscons driver
	and produce a new kernel.

>Description:

	With the conversion of pcvt to the common keyboard code found in
	i386/isa/kbdio.c, the "kbdc" pointer may be left uninitialized
	( = set to NULL ) when the keyboard was not plugged into the
	machine when the kernel boots.

	In case the keyboard is plugged into the machine after it was
	booted without it, the "kbdc" pointer is not initialized causing
	cyclic panics to occur due to calling kbdio.c functions with a
	NULL pointer as an argument.

>How-To-Repeat:

	With the kernel made at item "Environment" , execute 
	"shutdown -h now". 

	When the kernel has halted, unplug the keyboard cable and press 
	the reset switch (or cycle power) to reboot.

	After the machine has come up (with the keyboard unplugged), plug
	the keyboard into the machine.

	The machine will panic (cyclic) until it reboots.

>Fix:

	The following patch to i386/isa/pcvt/pcvt_drv.c will fix the
	above described problem:


*** pcvt_drv.c-226	Wed Sep 10 03:23:31 1997
--- pcvt_drv.c	Mon Jun 29 13:55:21 1998
***************
*** 41,47 ****
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   *
!  * @(#)pcvt_drv.c, 3.20, Last Edit-Date: [Mon Jun 29 15:12:38 1998]
   *
   */
  
--- 41,47 ----
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   *
!  * @(#)pcvt_drv.c, 3.20, Last Edit-Date: [Mon Jun 29 13:55:20 1998]
   *
   */
  
***************
*** 151,156 ****
--- 151,163 ----
  {
  #ifdef _I386_ISA_KBDIO_H_
  	kbdc = kbdc_open(IO_KBD);
+ 
+ 	if(kbdc == NULL)
+ 	{
+ 		reset_keyboard = 0;
+ 		return 1;
+ 	}
+ 		
  	reset_keyboard = 1;		/* it's now safe to do kbd reset */
  #endif /* _I386_ISA_KBDIO_H_ */
  
***************
*** 848,853 ****
--- 855,879 ----
  #else /* !PCVT_KBD_FIFO */
  	u_char	*cp;
  #endif /* PCVT_KBD_FIFO */
+ 
+ 	/*
+ 	 * in case the keyboard was not plugged in while booting, kbdc
+ 	 * was set to NULL at that time. When a keyboard IRQ occurs and
+ 	 * kbdc is NULL, the keyboard was probably reconnected to the
+ 	 * keyboard controller and we have to initialize the keyboard.
+ 	 */
+ 	 
+ 	if(kbdc == NULL)
+ 	{
+ 		kbdc = kbdc_open(IO_KBD);
+ 		if(kbdc == NULL)
+ 		{
+ 			reset_keyboard = 0;
+ 			return;
+ 		}
+ 		reset_keyboard = 1;
+ 		kbd_code_init();
+ 	}
  
  #if PCVT_SCREENSAVER
  	pcvt_scrnsv_reset();


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->suspended 
State-Changed-By: phk 
State-Changed-When: Wed Jul 1 22:43:11 PDT 1998 
State-Changed-Why:  
awaiting committer 
State-Changed-From-To: suspended->closed 
State-Changed-By: jkh 
State-Changed-When: Fri Jul 3 07:32:22 PDT 1998 
State-Changed-Why:  
Done in both branches, thanks. 
>Unformatted:
