summaryrefslogtreecommitdiff
path: root/sys/dev/sun
diff options
context:
space:
mode:
authorgwr <gwr@NetBSD.org>1996-04-10 21:44:35 +0000
committergwr <gwr@NetBSD.org>1996-04-10 21:44:35 +0000
commit32d12d3be499df36aa968d255ab0a9997bc0731b (patch)
tree6e92cef7a6bb8d8f043b486545990cf8a6c6f105 /sys/dev/sun
parent5eb08a6790bbacb4c9443f004a009ad6e162f644 (diff)
Make the ring size configurable in the tty driver.
Make the pseudo-interrupt functions return void. Call the tty layer at spltty (to be safe).
Diffstat (limited to 'sys/dev/sun')
-rw-r--r--sys/dev/sun/kbd.c252
-rw-r--r--sys/dev/sun/ms.c34
2 files changed, 160 insertions, 126 deletions
diff --git a/sys/dev/sun/kbd.c b/sys/dev/sun/kbd.c
index 3a71ccb7661..4e12d3e590c 100644
--- a/sys/dev/sun/kbd.c
+++ b/sys/dev/sun/kbd.c
@@ -1,4 +1,4 @@
-/* $NetBSD: kbd.c,v 1.6 1996/03/21 22:37:26 gwr Exp $ */
+/* $NetBSD: kbd.c,v 1.7 1996/04/10 21:44:58 gwr Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -378,12 +378,18 @@ kbdselect(dev, rw, p)
return (ev_select(&k->k_events, rw, p));
}
-static int kbd_oldkeymap __P((struct kbd_state *ks,
- u_long cmd, struct okiockey *okio));
+static int kbd_ioccmd(struct kbd_softc *k, int *data);
static int kbd_iockeymap __P((struct kbd_state *ks,
u_long cmd, struct kiockeymap *kio));
+static int kbd_iocsled(struct kbd_softc *k, int *data);
+
+#ifdef KIOCGETKEY
+static int kbd_oldkeymap __P((struct kbd_state *ks,
+ u_long cmd, struct okiockey *okio));
+#endif
+
int
kbdioctl(dev, cmd, data, flag, p)
dev_t dev;
@@ -431,14 +437,7 @@ kbdioctl(dev, cmd, data, flag, p)
break;
case KIOCCMD: /* Send a command to the keyboard */
- /*
- * ``unimplemented commands are ignored'' (blech)
- * so cannot check return value from kbd_docmd
- */
- error = kbd_drain_tx(k);
- if (error == 0) {
- (void) kbd_docmd(k, *(int *)data);
- }
+ error = kbd_ioccmd(k, (int *)data);
break;
case KIOCTYPE: /* Get keyboard type */
@@ -456,8 +455,7 @@ kbdioctl(dev, cmd, data, flag, p)
break;
case KIOCSLED:
- error = kbd_drain_tx(k);
- kbd_set_leds(k, *(int *)data);
+ error = kbd_iocsled(k, (int *)data);
break;
case KIOCGLED:
@@ -489,7 +487,7 @@ kbdioctl(dev, cmd, data, flag, p)
/*
* Get/Set keymap entry
*/
-int
+static int
kbd_iockeymap(ks, cmd, kio)
struct kbd_state *ks;
u_long cmd;
@@ -574,6 +572,76 @@ kbd_oldkeymap(ks, cmd, kio)
}
#endif /* KIOCGETKEY */
+
+/*
+ * keyboard command ioctl
+ * ``unimplemented commands are ignored'' (blech)
+ */
+static int
+kbd_ioccmd(k, data)
+ struct kbd_softc *k;
+ int *data;
+{
+ struct kbd_state *ks = &k->k_state;
+ int cmd, error, s;
+
+ cmd = *data;
+ switch (cmd) {
+
+ case KBD_CMD_BELL:
+ case KBD_CMD_NOBELL:
+ /* Supported by type 2, 3, and 4 keyboards */
+ break;
+
+ case KBD_CMD_CLICK:
+ case KBD_CMD_NOCLICK:
+ /* Unsupported by type 2 keyboards */
+ if (ks->kbd_id <= KB_SUN2)
+ return (0);
+ ks->kbd_click = (cmd == KBD_CMD_CLICK);
+ break;
+
+ default:
+ return (0);
+ }
+
+ s = spltty();
+
+ error = kbd_drain_tx(k);
+ if (error == 0) {
+ kbd_output(k, cmd);
+ kbd_start_tx(k);
+ }
+
+ splx(s);
+
+ return (error);
+}
+
+/*
+ * Set LEDs ioctl.
+ */
+static int
+kbd_iocsled(k, data)
+ struct kbd_softc *k;
+ int *data;
+{
+ struct kbd_state *ks = &k->k_state;
+ int leds, error, s;
+
+ leds = *data;
+
+ s = spltty();
+ error = kbd_drain_tx(k);
+ if (error == 0) {
+ kbd_set_leds(k, leds);
+ }
+ splx(s);
+
+ return (error);
+}
+
+
/****************************************************************
* middle layers:
* - keysym to ASCII sequence
@@ -688,8 +756,7 @@ kbd_input_funckey(k, keysym)
/*
* This is called by kbd_input_raw() or by kb_repeat()
- * to deliver ASCII input. Called at splsoftclock()
- * XXX: Raise to spltty before calling kd_input() ?
+ * to deliver ASCII input. Called at spltty().
*/
void
kbd_input_keysym(k, keysym)
@@ -750,23 +817,25 @@ kbd_input_keysym(k, keysym)
/*
* This is the autorepeat timeout function.
- * (called at splsoftclock)
+ * Called at splsoftclock().
*/
void
kbd_repeat(void *arg)
{
struct kbd_softc *k = (struct kbd_softc *)arg;
+ int s = spltty();
if (k->k_repeating && k->k_repeatsym >= 0) {
kbd_input_keysym(k, k->k_repeatsym);
timeout(kbd_repeat, k, k->k_repeat_step);
}
+ splx(s);
}
/*
* Called by our kbd_softint() routine on input,
* which passes the raw hardware scan codes.
- * Note: this is called at splsoftclock()
+ * Called at spltty()
*/
void
kbd_input_raw(k, c)
@@ -881,7 +950,7 @@ kbd_input_raw(k, c)
* Interface to the lower layer (zscc)
****************************************************************/
-static int
+static void
kbd_rxint(cs)
register struct zs_chanstate *cs;
{
@@ -892,11 +961,12 @@ kbd_rxint(cs)
k = cs->cs_private;
put = k->k_rbput;
- /* Read the input data ASAP. */
- c = zs_read_data(cs);
-
- /* Save the status register too. */
+ /*
+ * First read the status, because reading the received char
+ * destroys the status of this char.
+ */
rr1 = zs_read_reg(cs, 1);
+ c = zs_read_data(cs);
if (rr1 & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE)) {
/* Clear the receive error. */
@@ -937,29 +1007,24 @@ kbd_rxint(cs)
/* Ask for softint() call. */
cs->cs_softreq = 1;
- return(1);
}
-static int
+static void
kbd_txint(cs)
register struct zs_chanstate *cs;
{
register struct kbd_softc *k;
- register int count, rval;
k = cs->cs_private;
-
zs_write_csr(cs, ZSWR0_RESET_TXINT);
-
k->k_intr_flags |= INTR_TX_EMPTY;
/* Ask for softint() call. */
cs->cs_softreq = 1;
- return (1);
}
-static int
+static void
kbd_stint(cs)
register struct zs_chanstate *cs;
{
@@ -968,7 +1033,7 @@ kbd_stint(cs)
k = cs->cs_private;
- rr0 = zs_read_csr(cs);
+ cs->cs_rr0_new = zs_read_csr(cs);
zs_write_csr(cs, ZSWR0_RESET_STATUS);
#if 0
@@ -982,14 +1047,13 @@ kbd_stint(cs)
k->k_intr_flags |= INTR_ST_CHECK;
/* Ask for softint() call. */
cs->cs_softreq = 1;
- return (1);
}
/*
* Get input from the recieve ring and pass it on.
* Note: this is called at splsoftclock()
*/
-static int
+static void
kbd_softint(cs)
struct zs_chanstate *cs;
{
@@ -1005,7 +1069,9 @@ kbd_softint(cs)
s = splzs();
intr_flags = k->k_intr_flags;
k->k_intr_flags = 0;
- splx(s);
+
+ /* Now lower to spltty for the rest. */
+ (void) spltty();
/*
* Copy data from the receive ring to the event layer.
@@ -1059,9 +1125,10 @@ kbd_softint(cs)
*/
log(LOG_ERR, "%s: status interrupt?\n",
k->k_dev.dv_xname);
+ cs->cs_rr0 = cs->cs_rr0_new;
}
- return (1);
+ splx(s);
}
struct zsops zsops_kbd = {
@@ -1078,6 +1145,7 @@ struct zsops zsops_kbd = {
/*
* Initialization to be done at first open.
* This is called from kbdopen or kdopen (in kd.c)
+ * Called with user context.
*/
int
kbd_iopen(unit)
@@ -1146,6 +1214,9 @@ out:
return error;
}
+/*
+ * Called by kbd_input_raw, at spltty()
+ */
void
kbd_was_reset(k)
struct kbd_softc *k;
@@ -1167,14 +1238,20 @@ kbd_was_reset(k)
case KB_SUN3:
/* Type 3 keyboards come up with keyclick on */
- if (!ks->kbd_click)
- (void) kbd_docmd(k, KBD_CMD_NOCLICK);
+ if (!ks->kbd_click) {
+ /* turn off the click */
+ kbd_output(k, KBD_CMD_NOCLICK);
+ kbd_start_tx(k);
+ }
break;
case KB_SUN4:
/* Type 4 keyboards come up with keyclick off */
- if (ks->kbd_click)
- (void) kbd_docmd(k, KBD_CMD_CLICK);
+ if (ks->kbd_click) {
+ /* turn on the click */
+ kbd_output(k, KBD_CMD_CLICK);
+ kbd_start_tx(k);
+ }
break;
}
@@ -1182,6 +1259,9 @@ kbd_was_reset(k)
ks->kbd_leds = 0;
}
+/*
+ * Called by kbd_input_raw, at spltty()
+ */
void
kbd_new_layout(k)
struct kbd_softc *k;
@@ -1200,28 +1280,28 @@ kbd_new_layout(k)
/*
* Wait for output to finish.
- * Called with user context.
+ * Called at spltty(). Has user context.
*/
int
kbd_drain_tx(k)
struct kbd_softc *k;
{
- int error, s;
+ int error;
error = 0;
- s = spltty();
+
while (k->k_txflags & K_TXBUSY) {
k->k_txflags |= K_TXWANT;
error = tsleep((caddr_t)&k->k_txflags,
PZERO | PCATCH, "kbdout", 0);
}
- splx(s);
+
return (error);
}
/*
- * Send out a byte to the keyboard (i.e. reset)
- * Called with user context.
+ * Enqueue some output for the keyboard
+ * Called at spltty().
*/
void
kbd_output(k, c)
@@ -1229,9 +1309,8 @@ kbd_output(k, c)
int c; /* the data */
{
struct zs_chanstate *cs = k->k_cs;
- int put, s;
+ int put;
- s = spltty();
put = k->k_tbput;
k->k_tbuf[put] = (u_char)c;
put = (put + 1) & KBD_TX_RING_MASK;
@@ -1244,10 +1323,12 @@ kbd_output(k, c)
/* OK, really increment. */
k->k_tbput = put;
}
-
- splx(s);
}
+/*
+ * Start the sending data from the output queue
+ * Called at spltty().
+ */
void
kbd_start_tx(k)
struct kbd_softc *k;
@@ -1256,9 +1337,8 @@ kbd_start_tx(k)
int get, s;
u_char c;
- s = spltty();
if (k->k_txflags & K_TXBUSY)
- goto out;
+ return;
/* Is there anything to send? */
get = k->k_tbget;
@@ -1268,7 +1348,7 @@ kbd_start_tx(k)
k->k_txflags &= ~K_TXWANT;
wakeup((caddr_t)&k->k_txflags);
}
- goto out;
+ return;
}
/* Have something to send. */
@@ -1278,41 +1358,41 @@ kbd_start_tx(k)
k->k_txflags |= K_TXBUSY;
/* Need splzs to avoid interruption of the delay. */
- (void) splzs();
+ s = splzs();
zs_write_data(cs, c);
-
-out:
splx(s);
}
-
+/*
+ * Called at spltty by:
+ * kbd_update_leds, kbd_iocsled
+ */
void
kbd_set_leds(k, new_leds)
struct kbd_softc *k;
int new_leds;
{
struct kbd_state *ks = &k->k_state;
- int s;
-
- s = spltty();
/* Don't send unless state changes. */
if (ks->kbd_leds == new_leds)
- goto out;
+ return;
+
ks->kbd_leds = new_leds;
/* Only type 4 and later has LEDs anyway. */
if (ks->kbd_id < 4)
- goto out;
+ return;
kbd_output(k, KBD_CMD_SETLED);
kbd_output(k, new_leds);
kbd_start_tx(k);
-
-out:
- splx(s);
}
+/*
+ * Called at spltty by:
+ * kbd_input_keysym
+ */
void
kbd_update_leds(k)
struct kbd_softc *k;
@@ -1331,47 +1411,3 @@ kbd_update_leds(k)
kbd_set_leds(k, leds);
}
-
-/*
- * Execute a keyboard command; return 0 on success.
- */
-int
-kbd_docmd(k, cmd)
- struct kbd_softc *k;
- int cmd;
-{
- struct kbd_state *ks = &k->k_state;
- int error, s;
-
- switch (cmd) {
-
- case KBD_CMD_BELL:
- case KBD_CMD_NOBELL:
- /* Supported by type 2, 3, and 4 keyboards */
- break;
-
- case KBD_CMD_CLICK:
- /* Unsupported by type 2 keyboards */
- if (ks->kbd_id != KB_SUN2) {
- ks->kbd_click = 1;
- break;
- }
- return (EINVAL);
-
- case KBD_CMD_NOCLICK:
- /* Unsupported by type 2 keyboards */
- if (ks->kbd_id != KB_SUN2) {
- ks->kbd_click = 0;
- break;
- }
- return (EINVAL);
-
- default:
- return (EINVAL); /* ENOTTY? EOPNOTSUPP? */
- }
-
- kbd_output(k, cmd);
- kbd_start_tx(k);
- return (0);
-}
-
diff --git a/sys/dev/sun/ms.c b/sys/dev/sun/ms.c
index 9d7c019286c..a37665b3f29 100644
--- a/sys/dev/sun/ms.c
+++ b/sys/dev/sun/ms.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ms.c,v 1.4 1996/03/17 00:57:16 thorpej Exp $ */
+/* $NetBSD: ms.c,v 1.5 1996/04/10 21:45:01 gwr Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -478,7 +478,7 @@ out:
* Interface to the lower layer (zscc)
****************************************************************/
-static int
+static void
ms_rxint(cs)
register struct zs_chanstate *cs;
{
@@ -489,11 +489,12 @@ ms_rxint(cs)
ms = cs->cs_private;
put = ms->ms_rbput;
- /* Read the input data ASAP. */
- c = zs_read_data(cs);
-
- /* Save the status register too. */
+ /*
+ * First read the status, because reading the received char
+ * destroys the status of this char.
+ */
rr1 = zs_read_reg(cs, 1);
+ c = zs_read_data(cs);
if (rr1 & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE)) {
/* Clear the receive error. */
@@ -516,29 +517,24 @@ ms_rxint(cs)
/* Ask for softint() call. */
cs->cs_softreq = 1;
- return(1);
}
-static int
+static void
ms_txint(cs)
register struct zs_chanstate *cs;
{
register struct ms_softc *ms;
- register int count, rval;
ms = cs->cs_private;
-
zs_write_csr(cs, ZSWR0_RESET_TXINT);
-
ms->ms_intr_flags |= INTR_TX_EMPTY;
/* Ask for softint() call. */
cs->cs_softreq = 1;
- return (1);
}
-static int
+static void
ms_stint(cs)
register struct zs_chanstate *cs;
{
@@ -547,17 +543,16 @@ ms_stint(cs)
ms = cs->cs_private;
- rr0 = zs_read_csr(cs);
+ cs->cs_rr0_new = zs_read_csr(cs);
zs_write_csr(cs, ZSWR0_RESET_STATUS);
ms->ms_intr_flags |= INTR_ST_CHECK;
/* Ask for softint() call. */
cs->cs_softreq = 1;
- return (1);
}
-static int
+static void
ms_softint(cs)
struct zs_chanstate *cs;
{
@@ -573,7 +568,9 @@ ms_softint(cs)
s = splzs();
intr_flags = ms->ms_intr_flags;
ms->ms_intr_flags = 0;
- splx(s);
+
+ /* Now lower to spltty for the rest. */
+ (void) spltty();
/*
* Copy data from the receive ring to the event layer.
@@ -617,9 +614,10 @@ ms_softint(cs)
*/
log(LOG_ERR, "%s: status interrupt?\n",
ms->ms_dev.dv_xname);
+ cs->cs_rr0 = cs->cs_rr0_new;
}
- return (1);
+ splx(s);
}
struct zsops zsops_ms = {