From owner-freebsd-hackers Sun Dec 31 12:22:20 1995 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id MAA19102 for hackers-outgoing; Sun, 31 Dec 1995 12:22:20 -0800 (PST) Received: from mail.barrnet.net (mail.barrnet.net [131.119.246.7]) by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id MAA19097 for ; Sun, 31 Dec 1995 12:22:17 -0800 (PST) Received: from hq.icb.chel.su (icb-rich-gw.icb.chel.su [193.125.10.34]) by mail.barrnet.net (8.7.1/MAIL-RELAY-LEN) with SMTP id AAA04876 for ; Tue, 26 Dec 1995 00:46:11 -0800 (PST) Received: from localhost (babkin@localhost) by hq.icb.chel.su (8.6.5/8.6.5) id NAA25821; Tue, 26 Dec 1995 13:36:59 +0500 From: "Serge A. Babkin" Message-Id: <199512260836.NAA25821@hq.icb.chel.su> Subject: Re: Digiboard patch To: bde@zeta.org.au (Bruce Evans) Date: Tue, 26 Dec 1995 13:36:59 +0500 (GMT+0500) Cc: hackers@freebsd.org In-Reply-To: <199512221447.BAA14659@godzilla.zeta.org.au> from "Bruce Evans" at Dec 23, 95 01:47:02 am X-Mailer: ELM [version 2.4 PL23] Content-Type: text Sender: owner-hackers@freebsd.org Precedence: bulk > This was slightly better before. The comment no longer matches the code. > But to be correct, the state should be left at DC_UNCONFIGURED when the > device is first registered, then set to DC_BUSY when a subdevice is > attached (since you're not bothering to keep track of opens). > > Note that setting DC_* in kdc_dgb[0].kdc_state clobbers the template. > In general you have to worry about all the fields in the template being > changed as device 0 is attached, used and detached, so the template > shouldn't be in kdc_xxx[0]. This bug has been copied into about 100 > drivers :-(. This patch must fix these problems. Commit it please (if you think that it is worth). Thank you! ----------------------------------- cut here --------------------------- *** dgb.c 1995/12/22 11:09:12 --- dgb.c 1995/12/26 08:26:21 *************** *** 427,433 **** return 4; /* we need I/O space of 4 ports */ } ! static struct kern_devconf kdc_dgb[NDGB] = { { 0, 0, 0, /* filled in by dev_attach */ "dgb", 0, { MDDT_ISA, 0, "tty" }, isa_generic_externalize, 0, 0, ISA_EXTERNALLEN, --- 427,434 ---- return 4; /* we need I/O space of 4 ports */ } ! static struct kern_devconf kdc_dgb[NDGB]; ! static struct kern_devconf kdc_dgb_init = { 0, 0, 0, /* filled in by dev_attach */ "dgb", 0, { MDDT_ISA, 0, "tty" }, isa_generic_externalize, 0, 0, ISA_EXTERNALLEN, *************** *** 436,442 **** DC_UNCONFIGURED, "DigiBoard multiport card", DC_CLS_SERIAL, ! } }; static void dgbregisterdev(id) --- 437,443 ---- DC_UNCONFIGURED, "DigiBoard multiport card", DC_CLS_SERIAL, ! }; static void dgbregisterdev(id) *************** *** 445,457 **** int unit; unit = id->id_unit; ! if (unit != 0) ! kdc_dgb[unit] = kdc_dgb[0]; kdc_dgb[unit].kdc_unit = unit; kdc_dgb[unit].kdc_isa = id; ! /* now we assume that multiport is always 'open' for simplicity */ ! kdc_dgb[unit].kdc_state = DC_UNKNOWN; dev_attach(&kdc_dgb[unit]); } --- 446,457 ---- int unit; unit = id->id_unit; ! kdc_dgb[unit] = kdc_dgb_init; kdc_dgb[unit].kdc_unit = unit; kdc_dgb[unit].kdc_isa = id; ! /* no ports are open yet */ ! kdc_dgb[unit].kdc_state = DC_IDLE; dev_attach(&kdc_dgb[unit]); } *************** *** 1037,1042 **** --- 1037,1048 ---- port->active_out = TRUE; port->used=1; + + /* If any port is open (i.e. the open() call is completed for it) + * the device is busy + */ + + kdc_dgb[unit].kdc_state = DC_BUSY; out: splx(s); *************** *** 1063,1068 **** --- 1069,1075 ---- struct dgb_softc *sc; struct dgb_p *port; int s; + int i; mynor=minor(dev); unit=MINOR_TO_UNIT(mynor); *************** *** 1086,1091 **** --- 1093,1107 ---- ttyclose(tp); port->closing=0; wakeup(&port->closing); port->used=0; + + /* mark the card idle when all ports are closed */ + + for(i=0; inumports; i++) + if(sc->ports[i].used) + break; + + if(i>= sc->numports) + kdc_dgb[unit].kdc_state = DC_IDLE; splx(s);