2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2001-06-16 07:17:56 +00:00
|
|
|
* Copyright (C) 2001 Benno Rice.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Benno Rice ``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 TOOLS GMBH 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.
|
|
|
|
*/
|
|
|
|
|
2003-04-03 21:36:33 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
2001-06-16 07:17:56 +00:00
|
|
|
|
2003-02-07 16:20:09 +00:00
|
|
|
#include "opt_comconsole.h"
|
2004-06-24 02:57:11 +00:00
|
|
|
#include "opt_ofw.h"
|
2003-02-07 16:20:09 +00:00
|
|
|
|
2001-06-16 07:17:56 +00:00
|
|
|
#include <sys/param.h>
|
2004-07-10 21:07:44 +00:00
|
|
|
#include <sys/kdb.h>
|
2001-06-16 07:17:56 +00:00
|
|
|
#include <sys/kernel.h>
|
2006-11-06 17:43:10 +00:00
|
|
|
#include <sys/priv.h>
|
2001-06-16 07:17:56 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/cons.h>
|
|
|
|
#include <sys/consio.h>
|
|
|
|
#include <sys/tty.h>
|
|
|
|
|
|
|
|
#include <dev/ofw/openfirm.h>
|
|
|
|
|
2003-02-07 16:20:09 +00:00
|
|
|
#include <ddb/ddb.h>
|
|
|
|
|
2004-06-24 02:57:11 +00:00
|
|
|
#ifndef OFWCONS_POLL_HZ
|
|
|
|
#define OFWCONS_POLL_HZ 4 /* 50-100 works best on Ultra2 */
|
|
|
|
#endif
|
|
|
|
#define OFBURSTLEN 128 /* max number of bytes to write in one chunk */
|
2001-06-16 07:17:56 +00:00
|
|
|
|
|
|
|
static d_open_t ofw_dev_open;
|
|
|
|
static d_close_t ofw_dev_close;
|
|
|
|
|
|
|
|
static struct cdevsw ofw_cdevsw = {
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_version = D_VERSION,
|
2003-03-03 12:15:54 +00:00
|
|
|
.d_open = ofw_dev_open,
|
|
|
|
.d_close = ofw_dev_close,
|
|
|
|
.d_name = "ofw",
|
2004-02-21 21:10:55 +00:00
|
|
|
.d_flags = D_TTY | D_NEEDGIANT,
|
2001-06-16 07:17:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct tty *ofw_tp = NULL;
|
|
|
|
static int polltime;
|
|
|
|
static struct callout_handle ofw_timeouthandle
|
|
|
|
= CALLOUT_HANDLE_INITIALIZER(&ofw_timeouthandle);
|
|
|
|
|
2004-07-10 21:07:44 +00:00
|
|
|
#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
|
2003-02-07 16:20:09 +00:00
|
|
|
static int alt_break_state;
|
|
|
|
#endif
|
|
|
|
|
2001-06-16 07:17:56 +00:00
|
|
|
static void ofw_tty_start(struct tty *);
|
|
|
|
static int ofw_tty_param(struct tty *, struct termios *);
|
|
|
|
static void ofw_tty_stop(struct tty *, int);
|
|
|
|
static void ofw_timeout(void *);
|
|
|
|
|
2006-05-26 18:25:34 +00:00
|
|
|
static cn_probe_t ofw_cnprobe;
|
|
|
|
static cn_init_t ofw_cninit;
|
|
|
|
static cn_term_t ofw_cnterm;
|
|
|
|
static cn_getc_t ofw_cngetc;
|
|
|
|
static cn_putc_t ofw_cnputc;
|
2001-06-16 07:17:56 +00:00
|
|
|
|
2006-05-30 07:56:57 +00:00
|
|
|
CONSOLE_DRIVER(ofw);
|
2001-06-16 07:17:56 +00:00
|
|
|
|
2002-01-09 04:03:55 +00:00
|
|
|
static void
|
|
|
|
cn_drvinit(void *unused)
|
|
|
|
{
|
2002-11-18 06:19:12 +00:00
|
|
|
phandle_t options;
|
|
|
|
char output[32];
|
2004-06-16 09:47:26 +00:00
|
|
|
struct cdev *dev;
|
2002-11-18 06:19:12 +00:00
|
|
|
|
2003-09-28 06:51:47 +00:00
|
|
|
if (ofw_consdev.cn_pri != CN_DEAD &&
|
|
|
|
ofw_consdev.cn_name[0] != '\0') {
|
2002-11-18 06:19:12 +00:00
|
|
|
if ((options = OF_finddevice("/options")) == -1 ||
|
|
|
|
OF_getprop(options, "output-device", output,
|
|
|
|
sizeof(output)) == -1)
|
|
|
|
return;
|
2004-10-12 21:23:33 +00:00
|
|
|
/*
|
|
|
|
* XXX: This is a hack and it may result in two /dev/ttya
|
|
|
|
* XXX: devices on platforms where the sab driver works.
|
|
|
|
*/
|
2003-09-26 19:35:50 +00:00
|
|
|
dev = make_dev(&ofw_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "%s",
|
2003-01-27 04:42:17 +00:00
|
|
|
output);
|
2003-09-26 19:35:50 +00:00
|
|
|
make_dev_alias(dev, "ofwcons");
|
2002-11-18 06:19:12 +00:00
|
|
|
}
|
2002-01-09 04:03:55 +00:00
|
|
|
}
|
|
|
|
|
2008-03-16 10:58:09 +00:00
|
|
|
SYSINIT(cndev, SI_SUB_CONFIGURE, SI_ORDER_MIDDLE, cn_drvinit, NULL);
|
2002-01-09 04:03:55 +00:00
|
|
|
|
2001-06-16 07:17:56 +00:00
|
|
|
static int stdin;
|
|
|
|
static int stdout;
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
ofw_dev_open(struct cdev *dev, int flag, int mode, struct thread *td)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
int unit;
|
|
|
|
int error, setuptimeout;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
setuptimeout = 0;
|
|
|
|
unit = minor(dev);
|
|
|
|
|
2004-10-12 21:23:33 +00:00
|
|
|
/*
|
|
|
|
* XXX: BAD, should happen at attach time
|
|
|
|
*/
|
|
|
|
if (dev->si_tty == NULL) {
|
|
|
|
ofw_tp = ttyalloc();
|
|
|
|
dev->si_tty = ofw_tp;
|
|
|
|
ofw_tp->t_dev = dev;
|
|
|
|
}
|
|
|
|
tp = dev->si_tty;
|
2001-06-16 07:17:56 +00:00
|
|
|
|
|
|
|
tp->t_oproc = ofw_tty_start;
|
|
|
|
tp->t_param = ofw_tty_param;
|
|
|
|
tp->t_stop = ofw_tty_stop;
|
|
|
|
tp->t_dev = dev;
|
|
|
|
|
|
|
|
if ((tp->t_state & TS_ISOPEN) == 0) {
|
|
|
|
tp->t_state |= TS_CARR_ON;
|
2004-10-18 21:51:27 +00:00
|
|
|
ttyconsolemode(tp, 0);
|
2001-06-16 07:17:56 +00:00
|
|
|
|
|
|
|
setuptimeout = 1;
|
2006-11-06 13:42:10 +00:00
|
|
|
} else if ((tp->t_state & TS_XCLUDE) &&
|
|
|
|
priv_check(td, PRIV_TTY_EXCLUSIVE)) {
|
2001-06-16 07:17:56 +00:00
|
|
|
return (EBUSY);
|
|
|
|
}
|
|
|
|
|
2004-06-04 16:02:56 +00:00
|
|
|
error = ttyld_open(tp, dev);
|
2001-06-16 07:17:56 +00:00
|
|
|
|
|
|
|
if (error == 0 && setuptimeout) {
|
2004-06-24 02:57:11 +00:00
|
|
|
polltime = hz / OFWCONS_POLL_HZ;
|
2001-06-16 07:17:56 +00:00
|
|
|
if (polltime < 1) {
|
|
|
|
polltime = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofw_timeouthandle = timeout(ofw_timeout, tp, polltime);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-06-16 09:47:26 +00:00
|
|
|
ofw_dev_close(struct cdev *dev, int flag, int mode, struct thread *td)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
int unit;
|
|
|
|
struct tty *tp;
|
|
|
|
|
|
|
|
unit = minor(dev);
|
2004-10-12 21:23:33 +00:00
|
|
|
tp = dev->si_tty;
|
2001-06-16 07:17:56 +00:00
|
|
|
|
|
|
|
if (unit != 0) {
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
2004-06-24 02:57:11 +00:00
|
|
|
/* XXX Should be replaced with callout_stop(9) */
|
|
|
|
untimeout(ofw_timeout, tp, ofw_timeouthandle);
|
2004-06-04 16:02:56 +00:00
|
|
|
ttyld_close(tp, flag);
|
2004-07-15 20:47:41 +00:00
|
|
|
tty_close(tp);
|
2001-06-16 07:17:56 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
ofw_tty_param(struct tty *tp, struct termios *t)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ofw_tty_start(struct tty *tp)
|
|
|
|
{
|
2004-06-24 02:57:11 +00:00
|
|
|
struct clist *cl;
|
|
|
|
int len;
|
|
|
|
u_char buf[OFBURSTLEN];
|
|
|
|
|
2001-06-16 07:17:56 +00:00
|
|
|
|
2004-06-24 02:57:11 +00:00
|
|
|
if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
|
2001-06-16 07:17:56 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
tp->t_state |= TS_BUSY;
|
2004-06-24 02:57:11 +00:00
|
|
|
cl = &tp->t_outq;
|
|
|
|
len = q_to_b(cl, buf, OFBURSTLEN);
|
|
|
|
OF_write(stdout, buf, len);
|
2001-06-16 07:17:56 +00:00
|
|
|
tp->t_state &= ~TS_BUSY;
|
|
|
|
|
|
|
|
ttwwakeup(tp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ofw_tty_stop(struct tty *tp, int flag)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (tp->t_state & TS_BUSY) {
|
|
|
|
if ((tp->t_state & TS_TTSTOP) == 0) {
|
|
|
|
tp->t_state |= TS_FLUSH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ofw_timeout(void *v)
|
|
|
|
{
|
|
|
|
struct tty *tp;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
tp = (struct tty *)v;
|
|
|
|
|
2006-05-30 07:56:57 +00:00
|
|
|
while ((c = ofw_cngetc(NULL)) != -1) {
|
2001-06-16 07:17:56 +00:00
|
|
|
if (tp->t_state & TS_ISOPEN) {
|
2004-06-04 16:02:56 +00:00
|
|
|
ttyld_rint(tp, c);
|
2001-06-16 07:17:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ofw_timeouthandle = timeout(ofw_timeout, tp, polltime);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-30 07:56:57 +00:00
|
|
|
ofw_cnprobe(struct consdev *cp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
int chosen;
|
|
|
|
|
|
|
|
if ((chosen = OF_finddevice("/chosen")) == -1) {
|
|
|
|
cp->cn_pri = CN_DEAD;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin)) == -1) {
|
|
|
|
cp->cn_pri = CN_DEAD;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (OF_getprop(chosen, "stdout", &stdout, sizeof(stdout)) == -1) {
|
|
|
|
cp->cn_pri = CN_DEAD;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-09-28 05:38:37 +00:00
|
|
|
cp->cn_pri = CN_LOW;
|
2001-06-16 07:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-26 18:25:34 +00:00
|
|
|
ofw_cninit(struct consdev *cp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
|
2003-09-26 10:55:07 +00:00
|
|
|
/* XXX: This is the alias, but that should be good enough */
|
|
|
|
sprintf(cp->cn_name, "ofwcons");
|
2002-11-18 06:19:12 +00:00
|
|
|
cp->cn_tp = ofw_tp;
|
2001-06-16 07:17:56 +00:00
|
|
|
}
|
|
|
|
|
2006-05-26 18:25:34 +00:00
|
|
|
static void
|
2006-05-30 07:56:57 +00:00
|
|
|
ofw_cnterm(struct consdev *cp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-05-26 18:25:34 +00:00
|
|
|
ofw_cngetc(struct consdev *cp)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
unsigned char ch;
|
|
|
|
|
2002-01-01 21:45:30 +00:00
|
|
|
if (OF_read(stdin, &ch, 1) > 0) {
|
2004-07-10 21:07:44 +00:00
|
|
|
#if defined(KDB) && defined(ALT_BREAK_TO_DEBUGGER)
|
2008-05-04 23:29:38 +00:00
|
|
|
int kdb_brk;
|
|
|
|
|
|
|
|
if ((kdb_brk = kdb_alt_break(ch, &alt_break_state)) != 0) {
|
|
|
|
switch (kdb_brk) {
|
|
|
|
case KDB_REQ_DEBUGGER:
|
|
|
|
kdb_enter(KDB_WHY_BREAK,
|
|
|
|
"Break sequence on console");
|
|
|
|
break;
|
|
|
|
case KDB_REQ_PANIC:
|
|
|
|
kdb_panic("Panic sequence on console");
|
|
|
|
break;
|
|
|
|
case KDB_REQ_REBOOT:
|
|
|
|
kdb_reboot();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2003-02-07 16:20:09 +00:00
|
|
|
#endif
|
2001-06-16 07:17:56 +00:00
|
|
|
return (ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-05-26 18:25:34 +00:00
|
|
|
ofw_cnputc(struct consdev *cp, int c)
|
2001-06-16 07:17:56 +00:00
|
|
|
{
|
|
|
|
char cbuf;
|
|
|
|
|
|
|
|
if (c == '\n') {
|
|
|
|
cbuf = '\r';
|
|
|
|
OF_write(stdout, &cbuf, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
cbuf = c;
|
|
|
|
OF_write(stdout, &cbuf, 1);
|
|
|
|
}
|