From 8cf7a45e373025e4cbd2f25cb83fe987f5bf1667 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Sun, 9 Mar 2003 01:43:47 +0000 Subject: When a sparc machine is running with serial console, the zskbd probe would try to use short cuts, and would not correctly initialize its channel if a keyboard is connected to it, which might have been done on purpose. It would then become impossible to run X11 on this machine afterwards. Fix this by being more cautious during the probe, at the extent of a couple of seconds if no keyboard is present. Tested by various, ok deraadt@ --- sys/arch/sparc/dev/z8530kbd.c | 54 ++++++++++++++++++++------------------ sys/arch/sparc64/dev/z8530kbd.c | 58 +++++++++++++++++++++-------------------- 2 files changed, 59 insertions(+), 53 deletions(-) diff --git a/sys/arch/sparc/dev/z8530kbd.c b/sys/arch/sparc/dev/z8530kbd.c index 4131cfb1ed5..1e5e723c611 100644 --- a/sys/arch/sparc/dev/z8530kbd.c +++ b/sys/arch/sparc/dev/z8530kbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: z8530kbd.c,v 1.2 2002/11/29 01:00:46 miod Exp $ */ +/* $OpenBSD: z8530kbd.c,v 1.3 2003/03/09 01:43:44 miod Exp $ */ /* $NetBSD: z8530tty.c,v 1.77 2001/05/30 15:24:24 lukem Exp $ */ /*- @@ -235,7 +235,7 @@ static void zskbd_txint(struct zs_chanstate *); static void zskbd_softint(struct zs_chanstate *); static void zskbd_diag(void *); -void zskbd_init(struct zskbd_softc *); +int zskbd_init(struct zskbd_softc *); void zskbd_putc(struct zskbd_softc *, u_int8_t); void zskbd_raw(struct zskbd_softc *, u_int8_t); void zskbd_reset(struct zskbd_softc *); @@ -375,37 +375,39 @@ zskbd_attach(parent, self, aux) /* Wait a while for previous console output to complete */ DELAY(10000); - - /* - * Turn on receiver and status interrupts. - * We defer the actual write of the register to zsparam(), - * but we must make sure status interrupts are turned on by - * the time zsparam() reads the initial rr0 state. - */ - zskbd_init(zst); - SET(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_SIE); - zs_write_reg(cs, 1, cs->cs_creg[1]); - - s = splzs(); - - /* Make sure DTR is on now. */ - zs_modem(zst, 1); - - splx(s); } else if (!ISSET(zst->zst_hwflags, ZS_HWFLAG_NORESET)) { /* Not the console; may need reset. */ int reset; reset = (channel == 0) ? ZSWR9_A_RESET : ZSWR9_B_RESET; - s = splzs(); - zs_write_reg(cs, 9, reset); + splx(s); + } + /* + * Probe for a keyboard. + * If one is found, turn on receiver and status interrupts. + * We defer the actual write of the register to zsparam(), + * but we must make sure status interrupts are turned on by + * the time zsparam() reads the initial rr0 state. + */ + if (zskbd_init(zst)) { + SET(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_SIE); + zs_write_reg(cs, 1, cs->cs_creg[1]); + + /* Make sure DTR is on now. */ + s = splzs(); + zs_modem(zst, 1); + splx(s); + } else { /* Will raise DTR in open. */ + s = splzs(); zs_modem(zst, 0); - splx(s); + + printf("%s: no keyboard\n", self->dv_xname); + return; } /* @@ -454,7 +456,7 @@ zskbd_attach(parent, self, aux) zst->zst_wskbddev = config_found(self, &a, wskbddevprint); } -void +int zskbd_init(zst) struct zskbd_softc *zst; { @@ -465,11 +467,11 @@ zskbd_init(zst) /* setup for 1200n81 */ if (zs_set_speed(cs, 1200)) { /* set 1200bps */ printf(": failed to set baudrate\n"); - return; + return 0; } if (zs_set_modes(cs, CS8 | CLOCAL)) { printf(": failed to set modes\n"); - return; + return 0; } s = splzs(); @@ -601,6 +603,8 @@ zskbd_init(zst) if (tries == 0) printf(": reset timeout\n"); splx(s); + + return tries; } void diff --git a/sys/arch/sparc64/dev/z8530kbd.c b/sys/arch/sparc64/dev/z8530kbd.c index 2b2a67d8255..001d1f53ccf 100644 --- a/sys/arch/sparc64/dev/z8530kbd.c +++ b/sys/arch/sparc64/dev/z8530kbd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: z8530kbd.c,v 1.13 2002/11/29 01:00:49 miod Exp $ */ +/* $OpenBSD: z8530kbd.c,v 1.14 2003/03/09 01:43:46 miod Exp $ */ /* $NetBSD: z8530tty.c,v 1.77 2001/05/30 15:24:24 lukem Exp $ */ /*- @@ -230,7 +230,7 @@ static void zskbd_txint(struct zs_chanstate *); static void zskbd_softint(struct zs_chanstate *); static void zskbd_diag(void *); -void zskbd_init(struct zskbd_softc *); +int zskbd_init(struct zskbd_softc *); void zskbd_putc(struct zskbd_softc *, u_int8_t); void zskbd_raw(struct zskbd_softc *, u_int8_t); @@ -369,40 +369,40 @@ zskbd_attach(parent, self, aux) /* Wait a while for previous console output to complete */ DELAY(10000); - - /* - * Turn on receiver and status interrupts. - * We defer the actual write of the register to zsparam(), - * but we must make sure status interrupts are turned on by - * the time zsparam() reads the initial rr0 state. - */ - zskbd_init(zst); - SET(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_SIE); - zs_write_reg(cs, 1, cs->cs_creg[1]); - - s = splzs(); - - /* Make sure DTR is on now. */ - zs_modem(zst, 1); - - splx(s); } else if (!ISSET(zst->zst_hwflags, ZS_HWFLAG_NORESET)) { /* Not the console; may need reset. */ int reset; reset = (channel == 0) ? ZSWR9_A_RESET : ZSWR9_B_RESET; - s = splzs(); - zs_write_reg(cs, 9, reset); + splx(s); + } + + /* + * Probe for a keyboard. + * If one is found, turn on receiver and status interrupts. + * We defer the actual write of the register to zsparam(), + * but we must make sure status interrupts are turned on by + * the time zsparam() reads the initial rr0 state. + */ + if (zskbd_init(zst)) { + SET(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_SIE); + zs_write_reg(cs, 1, cs->cs_creg[1]); + /* Make sure DTR is on now. */ + s = splzs(); + zs_modem(zst, 1); + splx(s); + } else { /* Will raise DTR in open. */ + s = splzs(); zs_modem(zst, 0); - splx(s); - printf("\n"); - } else - printf("\n"); + + printf("%s: no keyboard\n", self->dv_xname); + return; + } a.console = console; if (ISTYPE5(zst->zst_layout)) { @@ -431,7 +431,7 @@ zskbd_attach(parent, self, aux) zst->zst_wskbddev = config_found(self, &a, wskbddevprint); } -void +int zskbd_init(zst) struct zskbd_softc *zst; { @@ -442,11 +442,11 @@ zskbd_init(zst) /* setup for 1200n81 */ if (zs_set_speed(cs, 1200)) { /* set 1200bps */ printf(": failed to set baudrate\n"); - return; + return 0; } if (zs_set_modes(cs, CS8 | CLOCAL)) { printf(": failed to set modes\n"); - return; + return 0; } s = splzs(); @@ -575,6 +575,8 @@ zskbd_init(zst) else printf(": layout %d\n", zst->zst_layout); splx(s); + + return tries; } void -- cgit v1.2.3