Subject: nextkbd.c cngetc patches
To: None <deberg@mit.edu>
From: Darrin B. Jewell <jewell@mit.edu>
List: port-next68k
Date: 03/25/1999 08:17:37
Matt,

  I looked at the NeXT keyboard polling problem this morning
briefly.  Have you tried polling by looping on
"INTR_OCCURRED(NEXT_I_KYBD_MOUSE)" ? This is similar to what
the bootloader does to poll the ethernet and scsi devices.

Below are patches where i've implemented such an idea.  They
have not been tested because my machine is busy building
a snapshot and I haven't had the time to set up a second one
for development yet.  What do you think?

Darrin


Index: nextkbd.c
===================================================================
RCS file: /cvsroot/src/sys/arch/next68k/dev/nextkbd.c,v
retrieving revision 1.2
diff -u -r1.2 nextkbd.c
--- nextkbd.c	1999/03/24 23:15:52	1.2
+++ nextkbd.c	1999/03/25 13:10:42
@@ -105,7 +105,7 @@
 	KB_US,
 };
 
-static int nextkbd_poll_data __P((bus_space_tag_t, bus_space_handle_t));
+static int nextkbd_poll_data __P((struct nextkbd_internal *));
 static int nextkbd_decode __P((struct nextkbd_internal *, int, u_int *, int *));
 
 static struct nextkbd_internal nextkbd_consdata;
@@ -230,9 +230,7 @@
 	void *arg;
 {
 	register struct nextkbd_softc *sc = arg;
-	struct mon_regs stat;
-	unsigned char device;
-	int type, key;
+	int type, key, val;
 
 	if (!INTR_OCCURRED(NEXT_I_KYBD_MOUSE)) return 0;
 
@@ -251,23 +249,10 @@
 #define KD_VALID				0x8000 /* only set for scancode keys ? */
 #define KD_MODS					0x4f00
 
-	bus_space_read_region_4(sc->id->iot, sc->id->ioh, 0, &stat, 3);
-	if (stat.mon_csr & CSR_INT) {
-                if (stat.mon_csr & CSR_DATA) {
-                        stat.mon_csr &= ~CSR_INT;
-			sc->id->num_ints++;
-			bus_space_write_4(sc->id->iot, sc->id->ioh, 0, stat.mon_csr);
-			device = stat.mon_data >> 28;
-			if (device != 1) return(1); /* XXX: mouse */
-			if (nextkbd_decode(sc->id, stat.mon_data & 0xffff, &type, &key)) {
-				wskbd_input(sc->sc_wskbddev, type, key);
-			}
-		} else {
-                        printf("nextkbd: int but no data\n");
-                        return(1);
-                }
+	val = nextkbd_poll_data(sc->id);
+	if ((val != -1) && nextkbd_decode(sc->id, val, &type, &key)) {
+		wskbd_input(sc->sc_wskbddev, type, key);
 	}
-
 	return(1);
 }
 
@@ -305,10 +290,12 @@
 
 	/* printf("cngetc: data at %08x (%08x)\n", t, v); */
 	for (;;) {
-		val = nextkbd_poll_data(t->iot, t->ioh);
-		/* printf("%08x\n", val); */
-		if ((val != -1) && nextkbd_decode(t, val, type, data))
-			return;
+		if (INTR_OCCURRED(NEXT_I_KYBD_MOUSE)) {
+			val = nextkbd_poll_data(t);
+			/* printf("%08x\n", val); */
+			if ((val != -1) && nextkbd_decode(t, val, type, data))
+				return;
+		}
 	}
 }
 
@@ -330,27 +317,21 @@
 }
 
 static int
-nextkbd_poll_data(iot, ioh)
-	bus_space_tag_t iot;
-	bus_space_handle_t ioh;
+nextkbd_poll_data(struct nextkbd_internal *id)
 {
-	int i;
+	unsigned char device;
 	struct mon_regs stat;
 				
-	/* printf("cnstart\n"); */
-	for (i=100000; i; i--) {
-		bus_space_read_region_4(iot, ioh, 0, &stat, 3);
-                stat.mon_csr &= ~CSR_INT;
-                if ( (stat.mon_csr & CSR_DATA) ) {
-			if ( (stat.mon_data >> 28) == 1) {
-                          /* printf("cnkey %08x %08x\n", stat.mon_csr, stat.mon_data); */
-				bus_space_write_4(iot, ioh, 0, stat.mon_csr);
-				return (stat.mon_data & 0xffff);
-			}
-		}
+	bus_space_read_region_4(id->iot, id->ioh, 0, &stat, 3);
+	if ((stat.mon_csr & CSR_INT) && (stat.mon_csr & CSR_DATA)) {
+		stat.mon_csr &= ~CSR_INT;
+		id->num_ints++;
+		bus_space_write_4(id->iot, id->ioh, 0, stat.mon_csr);
+		device = stat.mon_data >> 28;
+		if (device != 1) return(-1); /* XXX: mouse */
+		return(stat.mon_data & 0xffff);
 	}
-	/* printf("cnend %08x %08x\n", stat.mon_csr, stat.mon_data); */
-	return (-1);
+	return(-1);
 }
 
 static int