diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2005-01-11 00:11:06 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2005-01-11 00:11:06 +0000 |
commit | cd81217034d23fa8aa970c8780709caf30d4b151 (patch) | |
tree | 8ca9db080209650ca64b8460df1d3b4f2c37aead /sys | |
parent | 44101ba4b541339e5661d2ae9b8cffddc7defa82 (diff) |
Reliability fixes:
- Let the loop initialize completely before attempting to probe its devices.
Fixes the "no answer from device 1" problem.
- Handle ``loop unplugged'' events and force detach of all children in this
case.
Diffstat (limited to 'sys')
-rw-r--r-- | sys/dev/hil/hil.c | 99 | ||||
-rw-r--r-- | sys/dev/hil/hilreg.h | 4 | ||||
-rw-r--r-- | sys/dev/hil/hilvar.h | 9 |
3 files changed, 100 insertions, 12 deletions
diff --git a/sys/dev/hil/hil.c b/sys/dev/hil/hil.c index 77763bad297..e794795c6be 100644 --- a/sys/dev/hil/hil.c +++ b/sys/dev/hil/hil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hil.c,v 1.15 2005/01/09 23:49:35 miod Exp $ */ +/* $OpenBSD: hil.c,v 1.16 2005/01/11 00:11:05 miod Exp $ */ /* * Copyright (c) 2003, 2004, Miodrag Vallat. * All rights reserved. @@ -93,6 +93,7 @@ struct cfdriver hil_cd = { }; 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); int hil_process_poll(struct hil_softc *, u_int8_t, u_int8_t); @@ -194,6 +195,8 @@ hil_attach_deferred(void *v) int tries; u_int8_t db; + sc->sc_status = HIL_STATUS_BUSY; + /* * Initialize the loop: reconfigure, don't report errors, * put keyboard in cooked mode, and enable autopolling. @@ -238,10 +241,19 @@ hil_attach_deferred(void *v) } /* - * At this point, the loop should have reconfigured. - * The reconfiguration interrupt has already called hilconfig(). + * Enable loop interrupts. */ send_hil_cmd(sc, HIL_INTON, NULL, 0, NULL); + + /* + * Reconfigure if necessary + */ + sc->sc_status = HIL_STATUS_READY; + if (sc->sc_pending == HIL_PENDING_RECONFIG) { + sc->sc_pending = 0; + hilconfig(sc); + } else + sc->sc_pending = 0; } /* @@ -275,8 +287,20 @@ hil_process_int(struct hil_softc *sc, u_int8_t stat, u_int8_t c) case HIL_STATUS: if (c & HIL_ERROR) { sc->sc_cmddone = 1; - if (c == HIL_RECONFIG) - hilconfig(sc); + switch (c) { + case HIL_RECONFIG: + if (sc->sc_status == HIL_STATUS_BUSY) + sc->sc_pending = HIL_PENDING_RECONFIG; + else + hilconfig(sc); + break; + case HIL_UNPLUGGED: + if (sc->sc_status == HIL_STATUS_BUSY) + sc->sc_pending = HIL_PENDING_UNPLUGGED; + else + hilempty(sc); + break; + } break; } if (c & HIL_COMMAND) { @@ -332,13 +356,14 @@ hil_process_poll(struct hil_softc *sc, u_int8_t stat, u_int8_t c) case HIL_STATUS: if (c & HIL_ERROR) { sc->sc_cmddone = 1; - if (c == HIL_RECONFIG) { + switch (c) { + case HIL_RECONFIG: /* * Remember that a configuration event * occurred; it will be processed upon * leaving polled mode... */ - sc->sc_cpending = 1; + sc->sc_pending = HIL_PENDING_RECONFIG; /* * However, the keyboard will come back as * cooked, and we rely on it being in raw @@ -348,6 +373,15 @@ hil_process_poll(struct hil_softc *sc, u_int8_t stat, u_int8_t c) db = 0; send_hil_cmd(sc, HIL_WRITEKBDSADR, &db, 1, NULL); + break; + case HIL_UNPLUGGED: + /* + * Remember that an unplugged event + * occured; it will be processed upon + * leaving polled mode... + */ + sc->sc_pending = HIL_PENDING_UNPLUGGED; + break; } break; } @@ -504,6 +538,47 @@ hilconfig(struct hil_softc *sc) } /* + * Called after the loop has been unplugged. We simply force detach of + * all our children. + */ +void +hilempty(struct hil_softc *sc) +{ + u_int8_t db; + int id, s; + + s = splhil(); + + /* + * Check that the loop is really empty. + */ + db = 0; + send_hil_cmd(sc, HIL_READLPSTAT, NULL, 0, &db); + sc->sc_maxdev = db & LPS_DEVMASK; + + if (sc->sc_maxdev != 0) { + printf("%s: unplugged loop finds %d devices???\n", + sc->sc_dev.dv_xname, sc->sc_maxdev); + hilconfig(sc); + return; + } + + /* + * Now detach all hil devices. + */ + for (id = sc->sc_maxdev + 1; id < NHILD; id++) { + if (sc->sc_devices[id] != NULL) + config_detach((struct device *)sc->sc_devices[id], + DETACH_FORCE); + sc->sc_devices[id] = NULL; + } + + sc->sc_cmdbp = sc->sc_cmdbuf; + + splx(s); +} + +/* * Low level routines which actually talk to the 8042 chip. */ @@ -725,9 +800,15 @@ hil_set_poll(struct hil_softc *sc, int on) if (on) { pollon(sc); } else { - if (sc->sc_cpending) { - sc->sc_cpending = 0; + 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; } send_hil_cmd(sc, HIL_INTON, NULL, 0, NULL); } diff --git a/sys/dev/hil/hilreg.h b/sys/dev/hil/hilreg.h index 50fbe3c8b5c..3ff370da0b1 100644 --- a/sys/dev/hil/hilreg.h +++ b/sys/dev/hil/hilreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hilreg.h,v 1.4 2003/06/02 23:28:01 millert Exp $ */ +/* $OpenBSD: hilreg.h,v 1.5 2005/01/11 00:11:05 miod Exp $ */ /* $NetBSD: hilreg.h,v 1.6 1997/02/02 09:39:21 thorpej Exp $ */ /* @@ -48,7 +48,9 @@ #define HIL_POLLDATA 0x10 /* HIL poll data follows */ #define HIL_COMMAND 0x08 /* Start of original command */ #define HIL_ERROR 0x80 /* HIL error */ + #define HIL_RECONFIG 0x80 /* HIL has reconfigured */ +#define HIL_UNPLUGGED 0x84 /* HIL cable unplugged */ #define HIL_SSHIFT 4 /* Bits to shift status over */ #define HIL_SMASK 0x0f /* Service request status mask */ diff --git a/sys/dev/hil/hilvar.h b/sys/dev/hil/hilvar.h index 7467899d700..9253bed0ba4 100644 --- a/sys/dev/hil/hilvar.h +++ b/sys/dev/hil/hilvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hilvar.h,v 1.7 2005/01/09 23:49:36 miod Exp $ */ +/* $OpenBSD: hilvar.h,v 1.8 2005/01/11 00:11:05 miod Exp $ */ /* * Copyright (c) 2003, Miodrag Vallat. * All rights reserved. @@ -83,7 +83,12 @@ struct hil_softc { u_int8_t *sc_pollbp; /* pointer into sc_pollbuf */ u_int8_t *sc_cmdbp; /* pointer into sc_cmdbuf */ - int sc_cpending; /* reconfiguration in progress */ + int sc_status; /* initialization status */ +#define HIL_STATUS_BUSY 0x00 +#define HIL_STATUS_READY 0x01 + int sc_pending; /* reconfiguration events in progress */ +#define HIL_PENDING_RECONFIG 0x01 +#define HIL_PENDING_UNPLUGGED 0x02 u_int sc_maxdev; /* number of devices on loop */ struct hildev_softc *sc_devices[NHILD]; /* interrupt dispatcher */ }; |