summaryrefslogtreecommitdiff
path: root/sys/dev/hil
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2005-05-08 04:39:41 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2005-05-08 04:39:41 +0000
commitbfee6ea4078b7804a9d191cc74f080ddf73184f6 (patch)
tree9e35ad06d84d38a6be505e9cff1a113e84ec088d /sys/dev/hil
parent98799b6e6cf6eb9857863f97d5f3d8998a291529 (diff)
Simplify loop reconfiguration code.
Diffstat (limited to 'sys/dev/hil')
-rw-r--r--sys/dev/hil/hil.c69
1 files changed, 27 insertions, 42 deletions
diff --git a/sys/dev/hil/hil.c b/sys/dev/hil/hil.c
index e8122414211..ea7bb676f6b 100644
--- a/sys/dev/hil/hil.c
+++ b/sys/dev/hil/hil.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: hil.c,v 1.17 2005/01/15 19:48:15 miod Exp $ */
+/* $OpenBSD: hil.c,v 1.18 2005/05/08 04:39:40 miod Exp $ */
/*
* Copyright (c) 2003, 2004, Miodrag Vallat.
* All rights reserved.
@@ -96,6 +96,7 @@ void hilconfig(struct hil_softc *);
void hilempty(struct hil_softc *);
int hilsubmatch(struct device *, void *, void *);
void hil_process_int(struct hil_softc *, u_int8_t, u_int8_t);
+void hil_process_pending(struct hil_softc *);
int hil_process_poll(struct hil_softc *, u_int8_t, u_int8_t);
int send_device_cmd(struct hil_softc *sc, u_int device, u_int cmd);
void polloff(struct hil_softc *);
@@ -277,6 +278,8 @@ hil_intr(void *v)
DELAY(1);
hil_process_int(sc, stat, c);
+ hil_process_pending(sc);
+
return (1);
}
@@ -291,16 +294,10 @@ hil_process_int(struct hil_softc *sc, u_int8_t stat, u_int8_t c)
sc->sc_cmddone = 1;
switch (c) {
case HIL_RECONFIG:
- if (sc->sc_status == HIL_STATUS_BUSY)
- sc->sc_pending = HIL_PENDING_RECONFIG;
- else
- hilconfig(sc);
+ sc->sc_pending = HIL_PENDING_RECONFIG;
break;
case HIL_UNPLUGGED:
- if (sc->sc_status == HIL_STATUS_BUSY)
- sc->sc_pending = HIL_PENDING_UNPLUGGED;
- else
- hilempty(sc);
+ sc->sc_pending = HIL_PENDING_UNPLUGGED;
break;
}
break;
@@ -342,7 +339,6 @@ hil_process_int(struct hil_softc *sc, u_int8_t stat, u_int8_t c)
}
break;
}
-
}
/*
@@ -424,6 +420,21 @@ hil_process_poll(struct hil_softc *sc, u_int8_t stat, u_int8_t c)
return 0;
}
+void
+hil_process_pending(struct hil_softc *sc)
+{
+ switch (sc->sc_pending) {
+ case HIL_PENDING_RECONFIG:
+ sc->sc_pending = 0;
+ hilconfig(sc);
+ break;
+ case HIL_PENDING_UNPLUGGED:
+ sc->sc_pending = 0;
+ hilempty(sc);
+ break;
+ }
+}
+
/*
* Called after the loop has reconfigured. Here we need to:
* - determine how many devices are on the loop
@@ -445,6 +456,7 @@ hilconfig(struct hil_softc *sc)
{
struct hil_attach_args ha;
u_int8_t db;
+ u_int oldmax;
int id, s;
s = splhil();
@@ -454,6 +466,7 @@ hilconfig(struct hil_softc *sc)
*/
db = 0;
send_hil_cmd(sc, HIL_READLPSTAT, NULL, 0, &db);
+ oldmax = sc->sc_maxdev;
sc->sc_maxdev = db & LPS_DEVMASK;
#ifdef HILDEBUG
printf("%s: %d device(s)\n", sc->sc_dev.dv_xname, sc->sc_maxdev);
@@ -466,9 +479,9 @@ hilconfig(struct hil_softc *sc)
send_hil_cmd(sc, HIL_WRITEKBDSADR, &db, 1, NULL);
/*
- * Now attach hil devices as they are found.
+ * If the loop grew, attach new devices.
*/
- for (id = 1; id <= sc->sc_maxdev; id++) {
+ for (id = oldmax + 1; id <= sc->sc_maxdev; id++) {
int len;
const struct hildevice *hd;
@@ -487,25 +500,6 @@ hilconfig(struct hil_softc *sc)
continue;
}
- /*
- * If we already have a device configured at this position,
- * then either it is still the same, or there has been some
- * removal or insertion in the chain that made it change
- * its position on the loop.
- *
- * Rather than trying to play smart and find where the
- * device has gone, detach it, it will get reattached at
- * its new address...
- */
- if (sc->sc_devices[id] != NULL) {
- if (len == sc->sc_devices[id]->sc_infolen &&
- bcmp(sc->sc_cmdbuf, sc->sc_devices[id]->sc_info,
- len) == 0)
- continue;
-
- config_detach((struct device *)sc->sc_devices[id], 0);
- }
-
/* Identify and attach device */
for (hd = hildevs; hd->minid >= 0; hd++)
if (sc->sc_cmdbuf[0] >= hd->minid &&
@@ -525,7 +519,7 @@ hilconfig(struct hil_softc *sc)
}
/*
- * Detach remaining devices, if they have been removed
+ * Detach remaining devices, if the loop has shrunk.
*/
for (id = sc->sc_maxdev + 1; id < NHILD; id++) {
if (sc->sc_devices[id] != NULL)
@@ -802,16 +796,7 @@ hil_set_poll(struct hil_softc *sc, int on)
if (on) {
pollon(sc);
} else {
- switch (sc->sc_pending) {
- case HIL_PENDING_RECONFIG:
- sc->sc_pending = 0;
- hilconfig(sc);
- break;
- case HIL_PENDING_UNPLUGGED:
- sc->sc_pending = 0;
- hilempty(sc);
- break;
- }
+ hil_process_pending(sc);
send_hil_cmd(sc, HIL_INTON, NULL, 0, NULL);
}
}