Subject: PMS driver and ISA
To: None <port-i386@NetBSD.ORG>
From: Jason Thorpe <thorpej@nas.nasa.gov>
List: port-i386
Date: 02/08/1996 14:40:15
Folks ...

For various reasons, I'm doing some work on the ISA autoconfiguration 
code (don't get your hopes up, please).  It's basically an idea that I 
discussed with Charles, Christos, JT, et al at USENIX.

The idea is to create an ISA iospace/iomem resource map so that once a 
device is probed and attached, other devices won't be subsequently probed 
at an overlapping iospace/iomem location.  This is to partially solve 
problems with the adaptec/buslogic cards and the ed cards that get 
trashed by the mcd (or whichever) probe.  Basically, the probe will fail 
before it becomes destructive because a resource allocation will fail.

The second stage of this will be a small, non-obtrusive change to 
config_search(), which is the MI autoconfig routine that returns 
"matching information" to pass onto the probe routines.  Basically, the 
change is to add a field to the cfdriver structure, cd_priority, which 
will tell config_search() how important it is that this device be probed 
before somethine else.  For almost all drivers, this will require no 
changes.  However, the ISA "ed" driver, for example, will get a "1" (or 
higher) value in this field, telling config_search() to return it's 
cfdata before something else.  Thus, the ed card will match/attach before 
the mcd driver can probe and put it's prom in a strange state.

Anyhow, having said that, Charles pointed out to me that the pms driver 
throws a wrench into that scenario since it shares iospace with the 
keyboard controller (actually, it's a child device of the keyboard 
controller).  To solve this problem, the keyboard controller code should 
really be decoupled from pccons and pcvt and made into its own driver.  
However, looking at both pccons and pcvt, I didn't see a way to do that 
easily at the moment.  (Yes, I know Chris did it with the alpha, but he 
has a whole different set of console issues to worry about.)

So, what I did is sort of kludge around this problem until such time that 
the keyboard controller goo is separated out from the other parts of the 
console drivers.  Basically, I made the pms a child of either pc or vt.  
Unfortunately, I can't really test if this works (though, it should).  
The diffs below compile.  If someone with a pms mouse could apply these 
diffs to their -current tree and tell me if it works, I'd really 
appreciate it.

Ciao.

--------------------------------------------------------------------------
Jason R. Thorpe                                       thorpej@nas.nasa.gov
NASA Ames Research Center                               Home: 408.866.1912
NAS: M/S 258-6                                          Work: 415.604.0935
Moffett Field, CA 94035                                Pager: 415.428.6939

-----cut here-----
Index: conf/GENERIC
===================================================================
RCS file: /mastersrc/netbsd/src/sys/arch/i386/conf/GENERIC,v
retrieving revision 1.3
diff -c -r1.3 GENERIC
*** GENERIC	1996/01/14 01:18:46	1.3
--- GENERIC	1996/02/08 19:53:37
***************
*** 105,111 ****
  lms1	at isa? port 0x238 irq 5
  mms0	at isa? port 0x23c irq 5	# Microsoft InPort mouse
  mms1	at isa? port 0x238 irq 5
! #pms0	at isa? port 0x60 irq 12	# PS/2 auxiliary port mouse
  
  aha0	at isa? port 0x330 irq ? drq ?	# Adaptec 154[02] SCSI controllers
  aha1	at isa? port 0x334 irq ? drq ?	# Adaptec 154[02] SCSI controllers
--- 105,112 ----
  lms1	at isa? port 0x238 irq 5
  mms0	at isa? port 0x23c irq 5	# Microsoft InPort mouse
  mms1	at isa? port 0x238 irq 5
! pms0	at pc? irq 12			# PS/2 auxiliary port mouse
! #pms0	at vt? irq 12
  
  aha0	at isa? port 0x330 irq ? drq ?	# Adaptec 154[02] SCSI controllers
  aha1	at isa? port 0x334 irq ? drq ?	# Adaptec 154[02] SCSI controllers
Index: conf/files.i386
===================================================================
RCS file: /mastersrc/netbsd/src/sys/arch/i386/conf/files.i386,v
retrieving revision 1.1.1.2
diff -c -r1.1.1.2 files.i386
*** files.i386	1996/01/09 18:25:00	1.1.1.2
--- files.i386	1996/02/08 19:25:40
***************
*** 70,81 ****
  device	npx at isa
  file	arch/i386/isa/npx.c		npx needs-flag
  
  # PC console support a la "pccons"
! device	pc at isa: tty
  file	arch/i386/isa/pccons.c		pc needs-flag
  
  # PC console support a la "pcvt"
! device	vt at isa: tty
  file	arch/i386/isa/pcvt/pcvt_drv.c	vt needs-flag
  file	arch/i386/isa/pcvt/pcvt_ext.c	vt needs-flag
  file	arch/i386/isa/pcvt/pcvt_kbd.c	vt needs-flag
--- 70,87 ----
  device	npx at isa
  file	arch/i386/isa/npx.c		npx needs-flag
  
+ # XXX Note the console devices include ISA-like locators
+ # because the PS/2 mouse attaches to them as a child.
+ # This incredible kludge can go away when the keyboard
+ # controller code is decoupled from the console output
+ # routines.
+ 
  # PC console support a la "pccons"
! device	pc at isa { irq = -1 }: tty
  file	arch/i386/isa/pccons.c		pc needs-flag
  
  # PC console support a la "pcvt"
! device	vt at isa { irq = -1 }: tty
  file	arch/i386/isa/pcvt/pcvt_drv.c	vt needs-flag
  file	arch/i386/isa/pcvt/pcvt_ext.c	vt needs-flag
  file	arch/i386/isa/pcvt/pcvt_kbd.c	vt needs-flag
***************
*** 88,94 ****
  file	arch/i386/isa/lms.c		lms needs-flag
  device	mms at isa
  file	arch/i386/isa/mms.c		mms needs-flag
! device	pms at isa
  file	arch/i386/isa/pms.c		pms needs-flag
  
  # Floppy disk controller
--- 94,100 ----
  file	arch/i386/isa/lms.c		lms needs-flag
  device	mms at isa
  file	arch/i386/isa/mms.c		mms needs-flag
! device	pms at pc, vt	# XXX hack
  file	arch/i386/isa/pms.c		pms needs-flag
  
  # Floppy disk controller
Index: isa/pccons.c
===================================================================
RCS file: /mastersrc/netbsd/src/sys/arch/i386/isa/pccons.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 pccons.c
*** pccons.c	1995/12/27 23:55:05	1.1.1.1
--- pccons.c	1996/02/08 19:51:57
***************
*** 116,121 ****
--- 116,122 ----
  
  int pcprobe __P((struct device *, void *, void *));
  void pcattach __P((struct device *, struct device *, void *));
+ void pcscan __P((struct device *, void *));
  int pcintr __P((void *));
  
  struct cfdriver pccd = {
***************
*** 472,477 ****
--- 473,499 ----
  
  	sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, pcintr,
  	    sc);
+ 
+ 	/*
+ 	 * Look for children of the keyboard controller.
+ 	 * XXX hack.  Really should decouple keyboard controller from
+ 	 * console code.
+ 	 */
+ 	config_scan(pcscan, self);
+ }
+ 
+ void
+ pcscan(parent, match)
+ 	struct device *parent;
+ 	void *match;
+ {
+ 	struct cfdata *cf = match;
+ 
+ 	if (cf->cf_fstate == FSTATE_STAR)
+ 		panic("clone devices not supported on keyboard controller");
+ 
+ 	if ((*cf->cf_driver->cd_match)(parent, cf, NULL) > 0)
+ 		config_attach(parent, cf, NULL, NULL);
  }
  
  int
Index: isa/pms.c
===================================================================
RCS file: /mastersrc/netbsd/src/sys/arch/i386/isa/pms.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 pms.c
*** pms.c	1995/12/27 23:55:06	1.1.1.1
--- pms.c	1996/02/08 19:51:29
***************
*** 155,170 ****
  	outb(PMS_DATA, value);
  }
  
  int
  pmsprobe(parent, match, aux)
  	struct device *parent;
  	void *match, *aux;
  {
! 	struct isa_attach_args *ia = aux;
  	u_char x;
! 
! 	if (ia->ia_iobase != 0x60)
! 		return 0;
  
  	pms_dev_cmd(PMS_RESET);
  	pms_aux_cmd(PMS_AUX_TEST);
--- 155,200 ----
  	outb(PMS_DATA, value);
  }
  
+ #include "pc.h"
+ #if NPC > 0
+ extern struct cfdriver pccd;
+ #endif
+ #include "vt.h"
+ #if NVT > 0
+ extern struct cfdriver vtcd;
+ #endif
+ 
  int
  pmsprobe(parent, match, aux)
  	struct device *parent;
  	void *match, *aux;
  {
! 	struct cfdata *cf = match;
  	u_char x;
! #if NPC > 0
! 	struct cfdriver *pccons = &pccd;
! #else
! 	struct cfdriver *pccons = NULL;
! #endif
! #if NVT > 0
! 	struct cfdriver *pcvt = &pcvt;
! #else
! 	struct cfdriver *pcvt = NULL;
! #endif
! 
! 	/*
! 	 * We only attach to the keyboard controller via
! 	 * the console drivers. (We really wish we could be the
! 	 * child of a real keyboard controller driver.)
! 	 */
! 	if ((parent == NULL) ||
! 	   ((parent->dv_cfdata->cf_driver != pccons) &&
! 	    (parent->dv_cfdata->cf_driver != pcvt)))
! 		return (0);
! 
! 	/* Can't wildcard IRQ. */
! 	if (cf->cf_loc[0] == -1)
! 		return (0);
  
  	pms_dev_cmd(PMS_RESET);
  	pms_aux_cmd(PMS_AUX_TEST);
***************
*** 174,181 ****
  	if (x & 0x04)
  		return 0;
  
- 	ia->ia_iosize = PMS_NPORTS;
- 	ia->ia_msize = 0;
  	return 1;
  }
  
--- 204,209 ----
***************
*** 185,199 ****
  	void *aux;
  {
  	struct pms_softc *sc = (void *)self;
! 	struct isa_attach_args *ia = aux;
  
! 	printf("\n");
  
  	/* Other initialization was done by pmsprobe. */
  	sc->sc_state = 0;
  
! 	sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, pmsintr,
! 	    sc);
  }
  
  int
--- 213,226 ----
  	void *aux;
  {
  	struct pms_softc *sc = (void *)self;
! 	int irq = self->dv_cfdata->cf_loc[0];
  
! 	printf(" irq %d\n", irq);
  
  	/* Other initialization was done by pmsprobe. */
  	sc->sc_state = 0;
  
! 	sc->sc_ih = isa_intr_establish(irq, IST_EDGE, IPL_TTY, pmsintr, sc);
  }
  
  int
Index: isa/pcvt/pcvt_drv.c
===================================================================
RCS file: /mastersrc/netbsd/src/sys/arch/i386/isa/pcvt/pcvt_drv.c,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 pcvt_drv.c
*** pcvt_drv.c	1995/12/27 23:55:08	1.1.1.1
--- pcvt_drv.c	1996/02/08 19:46:36
***************
*** 107,112 ****
--- 107,117 ----
  #define VT_DESCR_LEN 40
  #endif /* PCVT_FREEBSD > 205 */
  
+ #if PCVT_NETBSD > 101
+ void
+ pcscan(struct device *parent, void *match);
+ #endif /* PCVT_NETBSD > 101 */
+ 
  #if PCVT_NETBSD > 100	/* NetBSD-current Feb 20 1995 */
  int
  pcprobe(struct device *parent, void *match, void *aux)
***************
*** 337,342 ****
--- 342,354 ----
  #if PCVT_NETBSD > 101
  	sc->sc_ih = isa_intr_establish(ia->ia_irq, IST_EDGE, IPL_TTY, pcintr,
  	    (void *)0);
+ 
+ 	/*
+ 	 * Look for children of the keyboard controller.
+ 	 * XXX hack.  Really should decouple keyboard controller from
+ 	 * console code.
+ 	 */
+ 	config_scan(pcscan, self);
  #else /* PCVT_NETBSD > 100 */
  	vthand.ih_fun = pcrint;
  	vthand.ih_arg = 0;
***************
*** 351,356 ****
--- 363,382 ----
  #endif /* PCVT_NETBSD > 9 */
  
  }
+ 
+ #if PCVT_NETBSD > 101
+ void
+ pcscan(struct device *parent, void *match)
+ {
+ 	struct cfdata *cf = match;
+ 
+ 	if (cf->cf_state == FSTATE_STAR)
+ 		panic("clone devices not supported on keyboard controller");
+ 	
+ 	if ((*cf->cf_driver->cd_match)(parent, cf, NULL) > 0)
+ 		config_attach(parent, cf, NULL, NULL);
+ }
+ #endif /* PCVT_NETBSD > 101 */
  
  /* had a look at the friedl driver */