2008-03-29 22:15:34 +03:00
|
|
|
/* $NetBSD: sunkbd.c,v 1.27 2008/03/29 19:15:36 tsutsui Exp $ */
|
2000-09-22 02:25:08 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratory.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 20:26:28 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2000-09-22 02:25:08 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)kbd.c 8.2 (Berkeley) 10/30/93
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2002-10-03 20:13:24 +04:00
|
|
|
* /dev/kbd lower layer for sun keyboard off a tty (line discipline).
|
|
|
|
* This driver uses kbdsun middle layer to hook up to /dev/kbd.
|
2000-09-22 02:25:08 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keyboard interface line discipline.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2001-11-13 09:54:32 +03:00
|
|
|
#include <sys/cdefs.h>
|
2008-03-29 22:15:34 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sunkbd.c,v 1.27 2008/03/29 19:15:36 tsutsui Exp $");
|
2001-11-13 09:54:32 +03:00
|
|
|
|
2000-09-22 02:25:08 +04:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/signal.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
|
|
|
|
#include <dev/cons.h>
|
|
|
|
#include <machine/vuid_event.h>
|
|
|
|
#include <machine/kbd.h>
|
|
|
|
#include <dev/sun/event_var.h>
|
|
|
|
#include <dev/sun/kbd_xlate.h>
|
|
|
|
#include <dev/sun/kbdvar.h>
|
2002-10-03 20:13:24 +04:00
|
|
|
#include <dev/sun/kbdsunvar.h>
|
2000-09-22 02:25:08 +04:00
|
|
|
#include <dev/sun/kbd_ms_ttyvar.h>
|
|
|
|
|
|
|
|
/****************************************************************
|
|
|
|
* Interface to the lower layer (ttycc)
|
|
|
|
****************************************************************/
|
|
|
|
|
2008-03-29 22:15:34 +03:00
|
|
|
static int sunkbd_match(device_t, cfdata_t, void *);
|
|
|
|
static void sunkbd_attach(device_t, device_t, void *);
|
2002-10-03 20:13:24 +04:00
|
|
|
static void sunkbd_write_data(struct kbd_sun_softc *, int);
|
2008-03-29 22:15:34 +03:00
|
|
|
static int sunkbdiopen(device_t, int mode);
|
2000-09-22 02:25:08 +04:00
|
|
|
|
2002-10-26 23:11:13 +04:00
|
|
|
#if NWSKBD > 0
|
|
|
|
void kbd_wskbd_attach(struct kbd_softc *k, int isconsole);
|
|
|
|
#endif
|
|
|
|
|
2000-09-22 02:25:08 +04:00
|
|
|
int sunkbdinput(int, struct tty *);
|
|
|
|
int sunkbdstart(struct tty *);
|
|
|
|
|
2001-12-11 20:27:25 +03:00
|
|
|
/* Default keyboard baud rate */
|
|
|
|
int sunkbd_bps = KBD_DEFAULT_BPS;
|
2000-09-22 02:25:08 +04:00
|
|
|
|
2008-03-29 22:15:34 +03:00
|
|
|
CFATTACH_DECL_NEW(kbd_tty, sizeof(struct kbd_sun_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
sunkbd_match, sunkbd_attach, NULL, NULL);
|
2000-09-22 02:25:08 +04:00
|
|
|
|
2005-11-27 08:35:52 +03:00
|
|
|
struct linesw sunkbd_disc = {
|
|
|
|
.l_name = "sunkbd",
|
|
|
|
.l_open = ttylopen,
|
|
|
|
.l_close = ttylclose,
|
|
|
|
.l_read = ttyerrio,
|
|
|
|
.l_write = ttyerrio,
|
|
|
|
.l_ioctl = ttynullioctl,
|
|
|
|
.l_rint = sunkbdinput,
|
|
|
|
.l_start = sunkbdstart,
|
|
|
|
.l_modem = nullmodem,
|
|
|
|
.l_poll = ttpoll
|
|
|
|
};
|
2000-11-02 02:57:14 +03:00
|
|
|
|
2002-10-26 23:11:13 +04:00
|
|
|
|
2000-09-22 02:25:08 +04:00
|
|
|
/*
|
|
|
|
* sunkbd_match: how is this tty channel configured?
|
|
|
|
*/
|
2000-10-11 03:33:52 +04:00
|
|
|
int
|
2008-03-29 22:15:34 +03:00
|
|
|
sunkbd_match(device_t parent, cfdata_t cf, void *aux)
|
2000-09-22 02:25:08 +04:00
|
|
|
{
|
|
|
|
struct kbd_ms_tty_attach_args *args = aux;
|
|
|
|
|
|
|
|
if (strcmp(args->kmta_name, "keyboard") == 0)
|
2008-03-29 22:15:34 +03:00
|
|
|
return 1;
|
2000-09-22 02:25:08 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-11 03:33:52 +04:00
|
|
|
void
|
2008-03-29 22:15:34 +03:00
|
|
|
sunkbd_attach(device_t parent, device_t self, void *aux)
|
2000-09-22 02:25:08 +04:00
|
|
|
{
|
2006-03-30 20:09:28 +04:00
|
|
|
struct kbd_sun_softc *k = device_private(self);
|
2000-09-22 02:25:08 +04:00
|
|
|
struct kbd_ms_tty_attach_args *args = aux;
|
|
|
|
struct tty *tp = args->kmta_tp;
|
|
|
|
struct cons_channel *cc;
|
|
|
|
|
2008-03-29 22:15:34 +03:00
|
|
|
k->k_kbd.k_dev = self;
|
|
|
|
|
2000-09-22 02:25:08 +04:00
|
|
|
/* Set up the proper line discipline. */
|
2005-11-27 08:35:52 +03:00
|
|
|
if (ttyldisc_attach(&sunkbd_disc) != 0)
|
2000-11-02 02:57:14 +03:00
|
|
|
panic("sunkbd_attach: sunkbd_disc");
|
2005-11-27 08:35:52 +03:00
|
|
|
ttyldisc_release(tp->t_linesw);
|
|
|
|
tp->t_linesw = ttyldisc_lookup(sunkbd_disc.l_name);
|
|
|
|
KASSERT(tp->t_linesw == &sunkbd_disc);
|
2000-09-22 02:25:08 +04:00
|
|
|
tp->t_oflag &= ~OPOST;
|
|
|
|
tp->t_dev = args->kmta_dev;
|
|
|
|
|
|
|
|
/* link the structures together. */
|
|
|
|
k->k_priv = tp;
|
2008-03-29 22:15:34 +03:00
|
|
|
tp->t_sc = k;
|
2000-09-22 02:25:08 +04:00
|
|
|
|
2002-10-21 19:36:35 +04:00
|
|
|
/* provide our middle layer with a link to the lower layer (i.e. us) */
|
2000-09-22 02:25:08 +04:00
|
|
|
k->k_deviopen = sunkbdiopen;
|
|
|
|
k->k_deviclose = NULL;
|
|
|
|
k->k_write_data = sunkbd_write_data;
|
|
|
|
|
2002-10-21 19:36:35 +04:00
|
|
|
/* provide upper layer with a link to our middle layer */
|
|
|
|
k->k_kbd.k_ops = &kbd_ops_sun;
|
|
|
|
|
|
|
|
/* alloc console input channel */
|
|
|
|
if ((cc = kbd_cc_alloc(&k->k_kbd)) == NULL)
|
2000-09-22 02:25:08 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (args->kmta_consdev) {
|
2000-11-09 02:41:42 +03:00
|
|
|
char magic[4];
|
2000-09-22 02:25:08 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hookup ourselves as the console input channel
|
|
|
|
*/
|
2001-12-11 20:27:25 +03:00
|
|
|
args->kmta_baud = sunkbd_bps;
|
2000-09-22 02:25:08 +04:00
|
|
|
args->kmta_cflag = CLOCAL|CS8;
|
|
|
|
cons_attach_input(cc, args->kmta_consdev);
|
|
|
|
|
|
|
|
/* Tell our parent what the console should be. */
|
|
|
|
args->kmta_consdev = cn_tab;
|
2002-10-03 20:13:24 +04:00
|
|
|
k->k_kbd.k_isconsole = 1;
|
2008-03-29 22:15:34 +03:00
|
|
|
aprint_normal(" (console input)");
|
2000-11-09 02:41:42 +03:00
|
|
|
|
|
|
|
/* Set magic to "L1-A" */
|
|
|
|
magic[0] = KBD_L1;
|
|
|
|
magic[1] = KBD_A;
|
|
|
|
magic[2] = 0;
|
|
|
|
cn_set_magic(magic);
|
2000-09-22 02:25:08 +04:00
|
|
|
} else {
|
|
|
|
extern void kd_attach_input(struct cons_channel *);
|
|
|
|
|
|
|
|
kd_attach_input(cc);
|
|
|
|
}
|
|
|
|
|
2002-10-26 23:11:13 +04:00
|
|
|
|
2008-03-29 22:15:34 +03:00
|
|
|
aprint_normal("\n");
|
2000-09-22 02:25:08 +04:00
|
|
|
|
2002-10-26 23:11:13 +04:00
|
|
|
#if NWSKBD > 0
|
|
|
|
kbd_wskbd_attach(&k->k_kbd, args->kmta_consdev != NULL);
|
|
|
|
#endif
|
|
|
|
|
2000-09-22 02:25:08 +04:00
|
|
|
/* Do this before any calls to kbd_rint(). */
|
2002-10-03 20:13:24 +04:00
|
|
|
kbd_xlate_init(&k->k_kbd.k_state);
|
2000-09-22 02:25:08 +04:00
|
|
|
|
|
|
|
/* Magic sequence. */
|
|
|
|
k->k_magic1 = KBD_L1;
|
|
|
|
k->k_magic2 = KBD_A;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal open routine. This really should be inside com.c
|
|
|
|
* But I'm putting it here until we have a generic internal open
|
|
|
|
* mechanism.
|
|
|
|
*/
|
|
|
|
int
|
2008-03-29 22:15:34 +03:00
|
|
|
sunkbdiopen(device_t dev, int flags)
|
2000-09-22 02:25:08 +04:00
|
|
|
{
|
2008-03-29 22:15:34 +03:00
|
|
|
struct kbd_sun_softc *k = device_private(dev);
|
|
|
|
struct tty *tp = k->k_priv;
|
2005-12-11 15:16:03 +03:00
|
|
|
struct lwp *l = curlwp ? curlwp : &lwp0;
|
2000-09-22 02:25:08 +04:00
|
|
|
struct termios t;
|
2000-10-11 03:33:52 +04:00
|
|
|
int error;
|
2000-09-22 02:25:08 +04:00
|
|
|
|
|
|
|
/* Open the lower device */
|
2007-07-10 00:51:58 +04:00
|
|
|
if ((error = cdev_open(tp->t_dev, O_NONBLOCK|flags,
|
2005-12-11 15:16:03 +03:00
|
|
|
0/* ignored? */, l)) != 0)
|
2000-10-11 03:33:52 +04:00
|
|
|
return (error);
|
2000-09-22 02:25:08 +04:00
|
|
|
|
|
|
|
/* Now configure it for the console. */
|
|
|
|
tp->t_ospeed = 0;
|
2001-12-11 20:27:25 +03:00
|
|
|
t.c_ispeed = sunkbd_bps;
|
|
|
|
t.c_ospeed = sunkbd_bps;
|
2000-09-22 02:25:08 +04:00
|
|
|
t.c_cflag = CLOCAL|CS8;
|
|
|
|
(*tp->t_param)(tp, &t);
|
|
|
|
|
2000-10-11 03:33:52 +04:00
|
|
|
return (0);
|
2000-09-22 02:25:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TTY interface to handle input.
|
|
|
|
*/
|
|
|
|
int
|
2008-03-29 22:15:34 +03:00
|
|
|
sunkbdinput(int c, struct tty *tp)
|
2000-09-22 02:25:08 +04:00
|
|
|
{
|
2008-03-29 22:15:34 +03:00
|
|
|
struct kbd_sun_softc *k = tp->t_sc;
|
2000-09-22 02:25:08 +04:00
|
|
|
u_char *cc;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
cc = tp->t_cc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle exceptional conditions (break, parity, framing).
|
|
|
|
*/
|
|
|
|
if ((error = ((c & TTY_ERRORMASK))) != 0) {
|
|
|
|
/*
|
|
|
|
* After garbage, flush pending input, and
|
|
|
|
* send a reset to resync key translation.
|
|
|
|
*/
|
|
|
|
log(LOG_ERR, "%s: input error (0x%x)\n",
|
2008-03-29 22:15:34 +03:00
|
|
|
device_xname(k->k_kbd.k_dev), c);
|
2000-09-22 02:25:08 +04:00
|
|
|
c &= TTY_CHARMASK;
|
|
|
|
if (!k->k_txflags & K_TXBUSY) {
|
|
|
|
ttyflush(tp, FREAD | FWRITE);
|
|
|
|
goto send_reset;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for input buffer overflow
|
|
|
|
*/
|
|
|
|
if (tp->t_rawq.c_cc + tp->t_canq.c_cc >= TTYHOG) {
|
|
|
|
log(LOG_ERR, "%s: input overrun\n",
|
2008-03-29 22:15:34 +03:00
|
|
|
device_xname(k->k_kbd.k_dev));
|
2000-09-22 02:25:08 +04:00
|
|
|
goto send_reset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pass this up to the "middle" layer. */
|
2005-02-21 01:17:28 +03:00
|
|
|
return(kbd_sun_input(k, c));
|
2000-09-22 02:25:08 +04:00
|
|
|
|
|
|
|
send_reset:
|
|
|
|
/* Send a reset to resync translation. */
|
2002-10-03 20:13:24 +04:00
|
|
|
kbd_sun_output(k, KBD_CMD_RESET);
|
2000-09-22 02:25:08 +04:00
|
|
|
return (ttstart(tp));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-03-29 22:15:34 +03:00
|
|
|
sunkbdstart(struct tty *tp)
|
2000-09-22 02:25:08 +04:00
|
|
|
{
|
2008-03-29 22:15:34 +03:00
|
|
|
struct kbd_sun_softc *k = tp->t_sc;
|
2000-09-22 02:25:08 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Transmit done. Try to send more, or
|
|
|
|
* clear busy and wakeup drain waiters.
|
|
|
|
*/
|
|
|
|
k->k_txflags &= ~K_TXBUSY;
|
2002-10-03 20:13:24 +04:00
|
|
|
kbd_sun_start_tx(k);
|
2000-09-22 02:25:08 +04:00
|
|
|
ttstart(tp);
|
2000-10-11 03:33:52 +04:00
|
|
|
return (0);
|
2000-09-22 02:25:08 +04:00
|
|
|
}
|
|
|
|
/*
|
2002-10-03 20:13:24 +04:00
|
|
|
* used by kbd_sun_start_tx();
|
2000-09-22 02:25:08 +04:00
|
|
|
*/
|
|
|
|
void
|
2008-03-29 22:15:34 +03:00
|
|
|
sunkbd_write_data(struct kbd_sun_softc *k, int c)
|
2000-09-22 02:25:08 +04:00
|
|
|
{
|
2008-03-29 22:15:34 +03:00
|
|
|
struct tty *tp = k->k_priv;
|
2000-10-11 03:33:52 +04:00
|
|
|
|
2007-11-10 21:00:11 +03:00
|
|
|
mutex_spin_enter(&tty_lock);
|
2000-09-22 02:25:08 +04:00
|
|
|
ttyoutput(c, tp);
|
|
|
|
ttstart(tp);
|
2007-11-10 21:00:11 +03:00
|
|
|
mutex_spin_exit(&tty_lock);
|
2000-09-22 02:25:08 +04:00
|
|
|
}
|