Added bits to complete the sun2 console code. These are

virtually identical copies of files under sys/arch/sparc/dev,
and one day they will be merged under sys/dev/sun.
This commit is contained in:
fredette 2002-03-22 00:22:43 +00:00
parent 1e9998683c
commit ae1f6b9ea8
4 changed files with 1425 additions and 0 deletions

74
sys/arch/sun2/dev/cons.h Normal file
View File

@ -0,0 +1,74 @@
/* $NetBSD: cons.h,v 1.1 2002/03/22 00:22:43 fredette Exp $ */
/*-
* Copyright (c) 2000 Eduardo E. Horvath
* All rights reserved.
*
* 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.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
* PROM console driver.
*
* This is the default fallback console driver if nothing else attaches.
*/
struct pconssoftc {
struct device of_dev;
struct tty *of_tty;
struct callout sc_poll_ch;
int of_flags;
};
/* flags: */
#define OFPOLL 1
#define OFBURSTLEN 128 /* max number of bytes to write in one chunk */
/* These are shared with the consinit OBP console */
void pcons_cnpollc __P((dev_t dev, int on));
struct consdev;
struct zs_chanstate;
extern void *zs_conschan;
extern void nullcnprobe __P((struct consdev *));
extern int zs_getc __P((void *arg));
extern void zs_putc __P((void *arg, int c));
#ifdef KGDB
void zs_kgdb_init __P((void));
void zskgdb __P((struct zs_chanstate *));
void *zs_find_prom __P((int));
#endif
/*
* PROM I/O nodes and arguments are prepared by consinit().
* Drivers can examine these when looking for a console device match.
*/
extern int prom_stdin_node;
extern int prom_stdout_node;
extern char prom_stdin_args[];
extern char prom_stdout_args[];

View File

@ -0,0 +1,304 @@
/* $NetBSD: consinit.c,v 1.1 2002/03/22 00:22:43 fredette Exp $ */
/*-
* Copyright (c) 2001 Matthew Fredette
* Copyright (c) 1999 Eduardo E. Horvath
* All rights reserved.
*
* 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.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
#include "opt_ddb.h"
#include "opt_kgdb.h"
#include "pcons.h"
#include "kbd.h"
#include "zs.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/tty.h>
#include <sys/time.h>
#include <sys/syslog.h>
#include <sys/kgdb.h>
#include <machine/autoconf.h>
#include <machine/promlib.h>
#include <machine/conf.h>
#include <machine/cpu.h>
#include <machine/eeprom.h>
#include <machine/psl.h>
#include <machine/z8530var.h>
#include <dev/cons.h>
#include <sun2/dev/cons.h>
static void prom_cnprobe __P((struct consdev *));
static void prom_cninit __P((struct consdev *));
int prom_cngetc __P((dev_t));
static void prom_cnputc __P((dev_t, int));
static void prom_cnpollc __P((dev_t, int));
static void prom_cnputc __P((dev_t, int));
#ifdef PROM_OBP_V2
/*
* The following several variables are related to
* the configuration process, and are used in initializing
* the machine.
*/
int prom_stdin_node; /* node ID of ROM's console input device */
int prom_stdout_node; /* node ID of ROM's console output device */
char prom_stdin_args[16];
char prom_stdout_args[16];
#endif /* PROM_OBP_V2 */
/*
* The console is set to this one initially,
* which lets us use the PROM until consinit()
* is called to select a real console.
*/
struct consdev consdev_prom = {
prom_cnprobe,
prom_cninit,
prom_cngetc,
prom_cnputc,
prom_cnpollc,
NULL,
};
/*
* The console table pointer is statically initialized
* to point to the PROM (output only) table, so that
* early calls to printf will work.
*/
struct consdev *cn_tab = &consdev_prom;
void
prom_cnprobe(cd)
struct consdev *cd;
{
#if NPCONS > 0
int maj;
for (maj = 0; maj < nchrdev; maj++)
if (cdevsw[maj].d_open == pconsopen)
break;
cd->cn_dev = makedev(maj, 0);
cd->cn_pri = CN_INTERNAL;
#endif
}
int
prom_cngetc(dev)
dev_t dev;
{
int ch;
#ifdef DDB
static int nplus = 0;
#endif
ch = prom_getchar();
#ifdef DDB
if (ch == '+') {
if (nplus++ > 3) Debugger();
} else nplus = 0;
#endif
return ch;
}
static void
prom_cninit(cn)
struct consdev *cn;
{
}
/*
* PROM console output putchar.
*/
static void
prom_cnputc(dev, c)
dev_t dev;
int c;
{
int s;
s = splhigh();
prom_putchar(c);
splx(s);
}
void
prom_cnpollc(dev, on)
dev_t dev;
int on;
{
if (on) {
/* Entering debugger. */
#if NFB > 0
fb_unblank();
#endif
} else {
/* Resuming kernel. */
}
#if NPCONS > 0
pcons_cnpollc(dev, on);
#endif
}
/*****************************************************************/
#ifdef DEBUG
#define DBPRINT(x) prom_printf x
#else
#define DBPRINT(x)
#endif
#ifdef notyet /* PROM_OBP_V2 */
void
prom_get_device_args(prop, dev, dev_sz, args, args_sz)
const char *prop;
char *dev;
unsigned int dev_sz;
char *args;
unsigned int args_sz;
{
char *cp, buffer[128];
getpropstringA(prom_findroot(), (char *)prop, buffer, sizeof buffer);
/*
* Extract device-specific arguments from a PROM device path (if any)
*/
cp = buffer + strlen(buffer);
while (cp >= buffer) {
if (*cp == ':') {
strncpy(args, cp+1, args_sz);
*cp = '\0';
strncpy(dev, buffer, dev_sz);
break;
}
cp--;
}
}
#endif /* PROM_OBP_V2 */
/*
* This function replaces sys/dev/cninit.c
* Determine which device is the console using
* the PROM "input source" and "output sink".
*/
void
consinit()
{
#ifdef notyet /* PROM_OBP_V2 */
char buffer[128];
#endif /* PROM_OBP_V2 */
char *consname = "unknown";
DBPRINT(("consinit()\r\n"));
if (cn_tab != &consdev_prom) return;
switch(prom_version()) {
#ifdef PROM_OLDMON
case PROM_OLDMON:
case PROM_OBP_V0:
switch(prom_stdin()) {
case PROMDEV_KBD:
consname = "keyboard/display";
break;
case PROMDEV_TTYA:
consname = "ttya";
break;
case PROMDEV_TTYB:
consname = "ttyb";
break;
}
break;
#endif /* PROM_OLDMON */
#ifdef notyet /* PROM_OBP_V2 */
case PROM_OBP_V2:
case PROM_OBP_V3:
case PROM_OPENFIRM:
/* Save PROM arguments for device matching */
prom_get_device_args("stdin-path",
buffer,
sizeof(buffer),
prom_stdin_args,
sizeof(prom_stdin_args));
prom_get_device_args("stdout-path",
buffer,
sizeof(buffer),
prom_stdout_args,
sizeof(prom_stdout_args));
/*
* Translate the STDIO package instance (`ihandle') -- that
* the PROM has already opened for us -- to a device tree
* node (i.e. a `phandle').
*/
DBPRINT(("stdin instance = %x\r\n", prom_stdin()));
if ((prom_stdin_node = prom_instance_to_package(prom_stdin())) == 0) {
printf("WARNING: no PROM stdin\n");
}
DBPRINT(("stdin package = %x\r\n", prom_stdin_node));
DBPRINT(("stdout instance = %x\r\n", prom_stdout()));
if ((prom_stdout_node = prom_instance_to_package(prom_stdout())) == 0) {
printf("WARNING: no PROM stdout\n");
}
DBPRINT(("stdout package = %x\r\n", prom_stdout_node));
DBPRINT(("buffer @ %p\r\n", buffer));
if (prom_stdin_node && prom_node_has_property(prom_stdin_node, "keyboard") {
#if NKBD == 0
printf("cninit: kdb/display not configured\n");
#endif
consname = "keyboard/display";
} else if (prom_stdout_node)
consname = buffer;
#endif /* PROM_OBP_V2 */
}
printf("console is %s\n", consname);
/* Initialize PROM console */
(*cn_tab->cn_probe)(cn_tab);
(*cn_tab->cn_init)(cn_tab);
#ifdef KGDB
/* Set up KGDB */
#if NZS > 0
if (cdevsw[major(kgdb_dev)].d_open == zsopen)
zs_kgdb_init();
#endif /* NZS > 0 */
#endif /* KGDB */
}

698
sys/arch/sun2/dev/kd.c Normal file
View File

@ -0,0 +1,698 @@
/* $NetBSD: kd.c,v 1.1 2002/03/22 00:22:44 fredette Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Gordon W. Ross.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
*/
/*
* Keyboard/Display device.
*
* This driver exists simply to provide a tty device that
* the indirect console driver can point to.
* The kbd driver sends its input here.
* Output goes to the screen via PROM printf.
*/
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/systm.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/file.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <machine/promlib.h>
#include <machine/eeprom.h>
#include <machine/psl.h>
#include <machine/cpu.h>
#include <machine/kbd.h>
#include <machine/autoconf.h>
#include <machine/conf.h>
#ifdef RASTERCONSOLE
#include <dev/sun/fbio.h>
#include <machine/fbvar.h>
#endif
#include <dev/cons.h>
#include <dev/sun/event_var.h>
#include <dev/sun/kbd_xlate.h>
#include <dev/sun/kbdvar.h>
#include <sun2/dev/cons.h>
struct tty *fbconstty = 0; /* tty structure for frame buffer console */
#define KDMAJOR 1
#define PUT_WSIZE 64
struct kd_softc {
struct device kd_dev; /* required first: base device */
struct tty *kd_tty;
int rows, cols;
/* Console input hook */
struct cons_channel *kd_in;
};
/*
* There is no point in pretending there might be
* more than one keyboard/display device.
*/
static struct kd_softc kd_softc;
static int kd_is_console;
static int kdparam(struct tty *, struct termios *);
static void kdstart(struct tty *);
static void kd_init __P((struct kd_softc *));
static void kd_cons_input __P((int));
static int kdcngetc __P((dev_t));
int cons_ocount; /* output byte count */
/*
* This is called by kbd_attach()
* XXX - Make this a proper child of kbd?
*/
void
kd_init(kd)
struct kd_softc *kd;
{
struct tty *tp;
#ifdef PROM_OLDMON
struct eeprom *ep;
#endif
#ifdef notyet /* PROM_OBP_V2 */
int i;
char *prop;
#endif
kd = &kd_softc; /* XXX */
tp = ttymalloc();
tp->t_oproc = kdstart;
tp->t_param = kdparam;
tp->t_dev = makedev(KDMAJOR, 0);
tty_attach(tp);
kd->kd_tty = tp;
/*
* get the console struct winsize.
*/
if (kd_is_console) {
fbconstty = tp;
#ifdef RASTERCONSOLE
kd->rows = fbrcons_rows();
kd->cols = fbrcons_cols();
rcons_ttyinit(tp);
#endif
}
/* else, consult the PROM */
switch (prom_version()) {
#ifdef PROM_OLDMON
case PROM_OLDMON:
if ((ep = (struct eeprom *)eeprom_va) == NULL)
break;
if (kd->rows == 0)
kd->rows = (u_short)ep->eeTtyRows;
if (kd->cols == 0)
kd->cols = (u_short)ep->eeTtyCols;
break;
#endif /* PROM_OLDMON */
#ifdef notyet /* PROM_OBP_V2 */
case PROM_OBP_V0:
case PROM_OBP_V2:
case PROM_OBP_V3:
case PROM_OPENFIRM:
if (kd->rows == 0 &&
(prop = PROM_getpropstring(optionsnode, "screen-#rows"))) {
i = 0;
while (*prop != '\0')
i = i * 10 + *prop++ - '0';
kd->rows = (unsigned short)i;
}
if (kd->cols == 0 &&
(prop = PROM_getpropstring(optionsnode, "screen-#columns"))) {
i = 0;
while (*prop != '\0')
i = i * 10 + *prop++ - '0';
kd->cols = (unsigned short)i;
}
break;
#endif /* PROM_OBP_V2 */
}
return;
}
struct tty *
kdtty(dev)
dev_t dev;
{
struct kd_softc *kd;
kd = &kd_softc; /* XXX */
return (kd->kd_tty);
}
int
kdopen(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
struct kd_softc *kd;
int error, s, unit;
struct tty *tp;
static int firstopen = 1;
unit = minor(dev);
if (unit != 0)
return ENXIO;
kd = &kd_softc; /* XXX */
if (firstopen) {
kd_init(kd);
firstopen = 0;
}
tp = kd->kd_tty;
/* It's simpler to do this up here. */
if (((tp->t_state & (TS_ISOPEN | TS_XCLUDE))
== (TS_ISOPEN | TS_XCLUDE))
&& (p->p_ucred->cr_uid != 0) )
{
return (EBUSY);
}
s = spltty();
if ((tp->t_state & TS_ISOPEN) == 0) {
/* First open. */
/* Notify the input device that serves us */
struct cons_channel *cc = kd->kd_in;
if (cc != NULL &&
(error = (*cc->cc_iopen)(cc)) != 0) {
splx(s);
return (error);
}
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
(void) kdparam(tp, &tp->t_termios);
ttsetwater(tp);
tp->t_winsize.ws_row = kd->rows;
tp->t_winsize.ws_col = kd->cols;
/* Flush pending input? Clear translator? */
/* This (pseudo)device always has SOFTCAR */
tp->t_state |= TS_CARR_ON;
}
splx(s);
return ((*tp->t_linesw->l_open)(dev, tp));
}
int
kdclose(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
struct kd_softc *kd;
struct tty *tp;
struct cons_channel *cc;
kd = &kd_softc; /* XXX */
tp = kd->kd_tty;
/* XXX This is for cons.c. */
if ((tp->t_state & TS_ISOPEN) == 0)
return 0;
(*tp->t_linesw->l_close)(tp, flag);
ttyclose(tp);
if ((cc = kd->kd_in) != NULL)
(void)(*cc->cc_iclose)(cc->cc_dev);
return (0);
}
int
kdread(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
struct kd_softc *kd;
struct tty *tp;
kd = &kd_softc; /* XXX */
tp = kd->kd_tty;
return ((*tp->t_linesw->l_read)(tp, uio, flag));
}
int
kdwrite(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
struct kd_softc *kd;
struct tty *tp;
kd = &kd_softc; /* XXX */
tp = kd->kd_tty;
return ((*tp->t_linesw->l_write)(tp, uio, flag));
}
int
kdpoll(dev, events, p)
dev_t dev;
int events;
struct proc *p;
{
struct kd_softc *kd;
struct tty *tp;
kd = &kd_softc; /* XXX */
tp = kd->kd_tty;
return ((*tp->t_linesw->l_poll)(tp, events, p));
}
int
kdioctl(dev, cmd, data, flag, p)
dev_t dev;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct kd_softc *kd;
struct tty *tp;
int error;
kd = &kd_softc; /* XXX */
tp = kd->kd_tty;
error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p);
if (error != EPASSTHROUGH)
return error;
error = ttioctl(tp, cmd, data, flag, p);
if (error != EPASSTHROUGH)
return error;
/* Handle any ioctl commands specific to kbd/display. */
/* XXX - Send KB* ioctls to kbd module? */
/* XXX - Send FB* ioctls to fb module? */
return EPASSTHROUGH;
}
void
kdstop(tp, flag)
struct tty *tp;
int flag;
{
}
static int
kdparam(tp, t)
struct tty *tp;
struct termios *t;
{
/* XXX - These are ignored... */
tp->t_ispeed = t->c_ispeed;
tp->t_ospeed = t->c_ospeed;
tp->t_cflag = t->c_cflag;
return 0;
}
static void kd_later(void*);
static void kd_putfb(struct tty *);
static void
kdstart(tp)
struct tty *tp;
{
struct clist *cl;
register int s;
s = spltty();
if (tp->t_state & (TS_BUSY|TS_TTSTOP|TS_TIMEOUT))
goto out;
cl = &tp->t_outq;
if (cl->c_cc) {
if (kd_is_console) {
tp->t_state |= TS_BUSY;
if (is_spl0(s)) {
/* called at level zero - update screen now. */
(void) spllowersoftclock();
kd_putfb(tp);
(void) spltty();
tp->t_state &= ~TS_BUSY;
} else {
/* called at interrupt level - do it later */
callout_reset(&tp->t_rstrt_ch, 0,
kd_later, tp);
}
} else {
/*
* This driver uses the PROM for writing the screen,
* and that only works if this is the console device.
* If this is not the console, just flush the output.
* Sorry. (In that case, use xdm instead of getty.)
*/
ndflush(cl, cl->c_cc);
}
}
if (cl->c_cc <= tp->t_lowat) {
if (tp->t_state & TS_ASLEEP) {
tp->t_state &= ~TS_ASLEEP;
wakeup((caddr_t)cl);
}
selwakeup(&tp->t_wsel);
}
out:
splx(s);
}
/*
* Timeout function to do delayed writes to the screen.
* Called at splsoftclock when requested by kdstart.
*/
static void
kd_later(tpaddr)
void *tpaddr;
{
struct tty *tp = tpaddr;
register int s;
kd_putfb(tp);
s = spltty();
tp->t_state &= ~TS_BUSY;
(*tp->t_linesw->l_start)(tp);
splx(s);
}
/*
* Put text on the screen using the PROM monitor.
* This can take a while, so to avoid missing
* interrupts, this is called at splsoftclock.
*/
static void
kd_putfb(tp)
struct tty *tp;
{
char buf[PUT_WSIZE];
struct clist *cl = &tp->t_outq;
char *p, *end;
int len;
while ((len = q_to_b(cl, buf, PUT_WSIZE-1)) > 0) {
/* PROM will barf if high bits are set. */
p = buf;
end = buf + len;
while (p < end)
*p++ &= 0x7f;
/* Now let the PROM print it. */
prom_putstr(buf, len);
}
}
/*
* Default PROM-based console input stream
*/
static int kd_rom_iopen __P((struct cons_channel *));
static int kd_rom_iclose __P((struct cons_channel *));
static struct cons_channel prom_cons_channel;
int
kd_rom_iopen(cc)
struct cons_channel *cc;
{
return (0);
}
int
kd_rom_iclose(cc)
struct cons_channel *cc;
{
return (0);
}
/*
* Our "interrupt" routine for input. This is called by
* the keyboard driver (dev/sun/kbd.c) at spltty.
*/
void
kd_cons_input(c)
int c;
{
struct kd_softc *kd = &kd_softc;
struct tty *tp;
/* XXX: Make sure the device is open. */
tp = kd->kd_tty;
if (tp == NULL)
return;
if ((tp->t_state & TS_ISOPEN) == 0)
return;
(*tp->t_linesw->l_rint)(c, tp);
}
/****************************************************************
* kd console support
****************************************************************/
/* The debugger gets its own key translation state. */
static struct kbd_state *kdcn_state;
static void kdcnprobe __P((struct consdev *));
static void kdcninit __P((struct consdev *));
static void kdcnputc __P((dev_t, int));
static void kdcnpollc __P((dev_t, int));
/* The keyboard driver uses cn_hw to access the real console driver */
extern struct consdev consdev_prom;
struct consdev consdev_kd = {
kdcnprobe,
kdcninit,
kdcngetc,
kdcnputc,
kdcnpollc,
NULL,
};
struct consdev *cn_hw = &consdev_kd;
void
cons_attach_input(cc, cn)
struct cons_channel *cc;
struct consdev *cn;
{
struct kd_softc *kd = &kd_softc;
struct kbd_softc *kds = cc->cc_dev;
struct kbd_state *ks;
/* Share the keyboard state */
kdcn_state = ks = &kds->k_state;
kd->kd_in = cc;
cc->cc_upstream = kd_cons_input;
/* Attach lower level. */
cn_hw->cn_dev = cn->cn_dev;
cn_hw->cn_pollc = cn->cn_pollc;
cn_hw->cn_getc = cn->cn_getc;
/* Attach us as console. */
cn_tab->cn_dev = makedev(KDMAJOR, 0);
cn_tab->cn_probe = kdcnprobe;
cn_tab->cn_init = kdcninit;
cn_tab->cn_getc = kdcngetc;
cn_tab->cn_pollc = kdcnpollc;
cn_tab->cn_pri = CN_INTERNAL;
/* Set up initial PROM input channel for /dev/console */
prom_cons_channel.cc_dev = NULL;
prom_cons_channel.cc_iopen = kd_rom_iopen;
prom_cons_channel.cc_iclose = kd_rom_iclose;
/* Indicate that it is OK to use the PROM fbwrite */
kd_is_console = 1;
}
void kd_attach_input(struct cons_channel *);
void
kd_attach_input(cc)
struct cons_channel *cc;
{
struct kd_softc *kd = &kd_softc;
kd->kd_in = cc;
cc->cc_upstream = kd_cons_input;
}
/* We never call this. */
static void
kdcnprobe(cn)
struct consdev *cn;
{
}
static void
kdcninit(cn)
struct consdev *cn;
{
#if 0
struct kbd_state *ks = kdcn_state;
cn->cn_dev = makedev(KDMAJOR, 0);
cn->cn_pri = CN_INTERNAL;
/* This prepares kbd_translate() */
ks->kbd_id = KBD_MIN_TYPE;
kbd_xlate_init(ks);
/* Set up initial PROM input channel for /dev/console */
prom_cons_channel.cc_dev = NULL;
prom_cons_channel.cc_iopen = kd_rom_iopen;
prom_cons_channel.cc_iclose = kd_rom_iclose;
cons_attach_input(&prom_cons_channel);
/* Indicate that it is OK to use the PROM fbwrite */
kd_is_console = 1;
#endif
}
static int
kdcngetc(dev)
dev_t dev;
{
struct kbd_state *ks = kdcn_state;
int code, class, data, keysym;
extern int prom_cngetc __P((dev_t));
if (cn_hw->cn_getc == prom_cngetc) return (*cn_hw->cn_getc)(dev);
for (;;) {
code = (*cn_hw->cn_getc)(dev);
keysym = kbd_code_to_keysym(ks, code);
class = KEYSYM_CLASS(keysym);
switch (class) {
case KEYSYM_ASCII:
goto out;
case KEYSYM_CLRMOD:
case KEYSYM_SETMOD:
data = (keysym & 0x1F);
/* Only allow ctrl or shift. */
if (data > KBMOD_SHIFT_R)
break;
data = 1 << data;
if (class == KEYSYM_SETMOD)
ks->kbd_modbits |= data;
else
ks->kbd_modbits &= ~data;
break;
case KEYSYM_ALL_UP:
/* No toggle keys here. */
ks->kbd_modbits = 0;
break;
default: /* ignore all other keysyms */
break;
}
}
out:
return (keysym);
}
static void
kdcnputc(dev, c)
dev_t dev;
int c;
{
int s;
s = splhigh();
prom_putchar(c);
splx(s);
}
static void
kdcnpollc(dev, on)
dev_t dev;
int on;
{
struct kbd_state *ks = kdcn_state;
if (on) {
/* Entering debugger. */
#if NFB > 0
fb_unblank();
#endif
/* Clear shift keys too. */
ks->kbd_modbits = 0;
} else {
/* Resuming kernel. */
}
(*cn_hw->cn_pollc)(dev, on);
}

349
sys/arch/sun2/dev/pcons.c Normal file
View File

@ -0,0 +1,349 @@
/* $NetBSD: pcons.c,v 1.1 2002/03/22 00:22:44 fredette Exp $ */
/*-
* Copyright (c) 2000 Eduardo E. Horvath
* All rights reserved.
*
* 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.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
/*
* Default console driver. Uses the PROM or whatever
* driver(s) are appropriate.
*/
#include "opt_ddb.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/tty.h>
#include <sys/time.h>
#include <sys/syslog.h>
#include <machine/autoconf.h>
#include <machine/promlib.h>
#include <machine/conf.h>
#include <machine/cpu.h>
#include <machine/psl.h>
#include <dev/cons.h>
#include <sun2/dev/cons.h>
static int pconsmatch __P((struct device *, struct cfdata *, void *));
static void pconsattach __P((struct device *, struct device *, void *));
struct cfattach pcons_ca = {
sizeof(struct pconssoftc), pconsmatch, pconsattach
};
extern struct cfdriver pcons_cd;
static struct cnm_state pcons_cnm_state;
static int pconsprobe __P((void));
extern struct consdev *cn_tab;
static int
pconsmatch(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
{
struct mainbus_attach_args *ma = aux;
extern int prom_cngetc __P((dev_t));
/* Only attach if no other console has attached. */
return ((ma->ma_name != NULL) &&
(strcmp("pcons", ma->ma_name) == 0) &&
(cn_tab->cn_getc == prom_cngetc));
}
static void
pconsattach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct pconssoftc *sc = (struct pconssoftc *) self;
printf("\n");
if (!pconsprobe())
return;
cn_init_magic(&pcons_cnm_state);
cn_set_magic("+++++");
callout_init(&sc->sc_poll_ch);
}
static void pconsstart __P((struct tty *));
static int pconsparam __P((struct tty *, struct termios *));
static void pcons_poll __P((void *));
int
pconsopen(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
struct pconssoftc *sc;
int unit = minor(dev);
struct tty *tp;
if (unit >= pcons_cd.cd_ndevs)
return ENXIO;
sc = pcons_cd.cd_devs[unit];
if (!sc)
return ENXIO;
if (!(tp = sc->of_tty))
sc->of_tty = tp = ttymalloc();
tp->t_oproc = pconsstart;
tp->t_param = pconsparam;
tp->t_dev = dev;
cn_tab->cn_dev = dev;
if (!(tp->t_state & TS_ISOPEN)) {
ttychars(tp);
tp->t_iflag = TTYDEF_IFLAG;
tp->t_oflag = TTYDEF_OFLAG;
tp->t_cflag = TTYDEF_CFLAG;
tp->t_lflag = TTYDEF_LFLAG;
tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
pconsparam(tp, &tp->t_termios);
ttsetwater(tp);
} else if ((tp->t_state&TS_XCLUDE) && suser(p->p_ucred, &p->p_acflag))
return EBUSY;
tp->t_state |= TS_CARR_ON;
if (!(sc->of_flags & OFPOLL)) {
sc->of_flags |= OFPOLL;
callout_reset(&sc->sc_poll_ch, 1, pcons_poll, sc);
}
return (*tp->t_linesw->l_open)(dev, tp);
}
int
pconsclose(dev, flag, mode, p)
dev_t dev;
int flag, mode;
struct proc *p;
{
struct pconssoftc *sc = pcons_cd.cd_devs[minor(dev)];
struct tty *tp = sc->of_tty;
callout_stop(&sc->sc_poll_ch);
sc->of_flags &= ~OFPOLL;
(*tp->t_linesw->l_close)(tp, flag);
ttyclose(tp);
return 0;
}
int
pconsread(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
struct pconssoftc *sc = pcons_cd.cd_devs[minor(dev)];
struct tty *tp = sc->of_tty;
return (*tp->t_linesw->l_read)(tp, uio, flag);
}
int
pconswrite(dev, uio, flag)
dev_t dev;
struct uio *uio;
int flag;
{
struct pconssoftc *sc = pcons_cd.cd_devs[minor(dev)];
struct tty *tp = sc->of_tty;
return (*tp->t_linesw->l_write)(tp, uio, flag);
}
int
pconspoll(dev, events, p)
dev_t dev;
int events;
struct proc *p;
{
struct pconssoftc *sc = pcons_cd.cd_devs[minor(dev)];
struct tty *tp = sc->of_tty;
return ((*tp->t_linesw->l_poll)(tp, events, p));
}
int
pconsioctl(dev, cmd, data, flag, p)
dev_t dev;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct pconssoftc *sc = pcons_cd.cd_devs[minor(dev)];
struct tty *tp = sc->of_tty;
int error;
if ((error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, p)) >= 0)
return error;
if ((error = ttioctl(tp, cmd, data, flag, p)) >= 0)
return error;
return ENOTTY;
}
struct tty *
pconstty(dev)
dev_t dev;
{
struct pconssoftc *sc = pcons_cd.cd_devs[minor(dev)];
return sc->of_tty;
}
void
pconsstop(tp, flag)
struct tty *tp;
int flag;
{
}
static void
pconsstart(tp)
struct tty *tp;
{
struct clist *cl;
int s, len;
u_char buf[OFBURSTLEN];
s = spltty();
if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
splx(s);
return;
}
tp->t_state |= TS_BUSY;
splx(s);
cl = &tp->t_outq;
len = q_to_b(cl, buf, OFBURSTLEN);
prom_putstr(buf, len);
s = spltty();
tp->t_state &= ~TS_BUSY;
if (cl->c_cc) {
tp->t_state |= TS_TIMEOUT;
callout_reset(&tp->t_rstrt_ch, 1, ttrstrt, (void *)tp);
}
if (cl->c_cc <= tp->t_lowat) {
if (tp->t_state & TS_ASLEEP) {
tp->t_state &= ~TS_ASLEEP;
wakeup(cl);
}
selwakeup(&tp->t_wsel);
}
splx(s);
}
static int
pconsparam(tp, t)
struct tty *tp;
struct termios *t;
{
tp->t_ispeed = t->c_ispeed;
tp->t_ospeed = t->c_ospeed;
tp->t_cflag = t->c_cflag;
return 0;
}
static void
pcons_poll(aux)
void *aux;
{
struct pconssoftc *sc = aux;
struct tty *tp = sc->of_tty;
int c;
char ch;
while ((c = prom_peekchar()) >= 0) {
ch = c;
cn_check_magic(tp->t_dev, ch, pcons_cnm_state);
if (tp && (tp->t_state & TS_ISOPEN))
(*tp->t_linesw->l_rint)(ch, tp);
}
callout_reset(&sc->sc_poll_ch, 1, pcons_poll, sc);
}
int
pconsprobe()
{
switch (prom_version()) {
#ifdef PROM_OLDMON
case PROM_OLDMON:
case PROM_OBP_V0:
return (1);
#endif /* PROM_OLDMON */
#ifdef PROM_OBP_V2
case PROM_OBP_V2:
case PROM_OBP_V3:
case PROM_OPENFIRM:
return (prom_stdin() && prom_stdout());
#endif /* PROM_OBP_V2 */
default: break;
}
return (0);
}
void
pcons_cnpollc(dev, on)
dev_t dev;
int on;
{
struct pconssoftc *sc = NULL;
if (pcons_cd.cd_devs)
sc = pcons_cd.cd_devs[minor(dev)];
if (on) {
if (!sc) return;
if (sc->of_flags & OFPOLL)
callout_stop(&sc->sc_poll_ch);
sc->of_flags &= ~OFPOLL;
} else {
/* Resuming kernel. */
if (sc && !(sc->of_flags & OFPOLL)) {
sc->of_flags |= OFPOLL;
callout_reset(&sc->sc_poll_ch, 1, pcons_poll, sc);
}
}
}
void pcons_dopoll __P((void));
void
pcons_dopoll() {
pcons_poll((void*)pcons_cd.cd_devs[0]);
}