/*-
* 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.
*
* 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.
*/
/*
* Console driver based on PROM primitives.
*
* This driver exists to provide a tty device that the indirect
* console driver can point to. It also provides a hook that
* allows another device to serve console input. This will normally
* be a keyboard driver (see sys/dev/sun/kbd.c)
*/
/*
* Get the console struct winsize.
*/
#if defined(RASTERCONSOLE) && NFB > 0
/* If the raster console driver is attached, copy its size */
kd->rows = fbrcons_rows();
kd->cols = fbrcons_cols();
rcons_ttyinit(tp);
#endif
/* else, consult the PROM */
switch (prom_version()) {
char prop[6+1]; /* Enough for six digits */
struct eeprom *ep;
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;
case PROM_OBP_V0:
case PROM_OBP_V2:
case PROM_OBP_V3:
case PROM_OPENFIRM:
if (kd->rows == 0 &&
prom_getoption("screen-#rows", prop, sizeof prop) == 0)
kd->rows = strtoul(prop, NULL, 10);
if (ttypull(tp)) {
tp->t_state |= TS_BUSY;
if ((s1 & PSR_PIL) == 0) {
/* called at level zero - update screen now. */
splx(s2);
kd_putfb(tp);
s2 = spltty();
tp->t_state &= ~TS_BUSY;
} else {
/* called at interrupt level - do it later */
callout_schedule(&tp->t_rstrt_ch, 0);
}
}
out:
splx(s2);
splx(s1);
}
/*
* Timeout function to do delayed writes to the screen.
* Called at splsoftclock when requested by kdstart.
*/
static void
kd_later(void *arg)
{
struct tty *tp = arg;
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(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);
}
}
/*
* Our "interrupt" routine for input. This is called by
* the keyboard driver (dev/sun/kbd.c) at spltty.
*/
static void
kd_cons_input(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;
/*
* Default PROM-based console input stream
* Since the PROM does not notify us when data is available on the
* input channel these functions periodically poll the PROM.
*/
static int kd_rom_iopen(struct cons_channel *);
static int kd_rom_iclose(struct cons_channel *);
static void kd_rom_intr(void *);
static struct cons_channel prom_cons_channel = {
NULL, /* no private data */
kd_rom_iopen,
kd_rom_iclose,
NULL /* will be set by kd driver */
};
static struct callout prom_cons_callout;
static int
kd_rom_iopen(struct cons_channel *cc)
{
static bool callo;
if (!callo) {
callout_init(&prom_cons_callout, 0);
callo = true;
}
/* Poll for ROM input 4 times per second */
callout_reset(&prom_cons_callout, hz / 4, kd_rom_intr, cc);
return (0);
}
static int
kd_rom_iclose(struct cons_channel *cc)
{
callout_stop(&prom_cons_callout);
return (0);
}
/*
* "Interrupt" routine for input through ROM vectors
*/
static void
kd_rom_intr(void *arg)
{
struct cons_channel *cc = arg;
int s, c;
callout_schedule(&prom_cons_callout, hz / 4);
s = spltty();
while ((c = prom_peekchar()) >= 0)
(*cc->cc_upstream)(c);
/*
* 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 table, so that early calls to printf will work.
* this has been moved to cpu_startup()
*/
#if 0
struct consdev *cn_tab = &consdev_prom;
#endif
switch (prom_version()) {
#if 0
case PROM_OLDMON:
case PROM_OBP_V0:
/* The stdio handles identify the device type */
inSource = prom_stdin();
outSink = prom_stdout();
break;
// XXXMRG should these just set prom_stdin_node / prom_stdout_node?
#endif
case PROM_OBP_V2:
case PROM_OBP_V3:
case PROM_OPENFIRM:
/* Save PROM arguments for device matching */
prom_get_device_args("stdin-path", prom_stdin_args,
sizeof(prom_stdin_args));
prom_get_device_args("stdout-path", 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').
*/