2003-10-21 12:20:15 +04:00
|
|
|
/* $NetBSD: consinit.c,v 1.14 2003/10/21 08:20:15 petrov Exp $ */
|
1999-05-23 06:46:35 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2003-07-15 06:54:31 +04:00
|
|
|
#include <sys/cdefs.h>
|
2003-10-21 12:20:15 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.14 2003/10/21 08:20:15 petrov Exp $");
|
2003-07-15 06:54:31 +04:00
|
|
|
|
1999-05-23 06:46:35 +04:00
|
|
|
#include "opt_ddb.h"
|
2000-05-19 09:26:16 +04:00
|
|
|
#include "pcons.h"
|
1999-05-23 06:46:35 +04:00
|
|
|
|
|
|
|
#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/openfirm.h>
|
|
|
|
#include <machine/bsd_openprom.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/eeprom.h>
|
|
|
|
#include <machine/psl.h>
|
|
|
|
#include <machine/z8530var.h>
|
2000-10-20 09:32:35 +04:00
|
|
|
#include <machine/sparc64.h>
|
1999-05-23 06:46:35 +04:00
|
|
|
|
|
|
|
#include <dev/cons.h>
|
|
|
|
|
|
|
|
#include <sparc64/dev/cons.h>
|
|
|
|
|
2000-05-19 09:26:16 +04:00
|
|
|
static void prom_cnprobe __P((struct consdev *));
|
1999-05-23 06:46:35 +04:00
|
|
|
static void prom_cninit __P((struct consdev *));
|
2000-05-19 09:26:16 +04:00
|
|
|
int prom_cngetc __P((dev_t));
|
|
|
|
static void prom_cnputc __P((dev_t, int));
|
|
|
|
static void prom_cnpollc __P((dev_t, int));
|
1999-05-23 06:46:35 +04:00
|
|
|
static void prom_cnputc __P((dev_t, int));
|
|
|
|
|
2003-10-21 12:20:15 +04:00
|
|
|
int stdin = 0, stdout = 0;
|
1999-05-23 06:46:35 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 = {
|
2000-05-19 09:26:16 +04:00
|
|
|
prom_cnprobe,
|
1999-05-23 06:46:35 +04:00
|
|
|
prom_cninit,
|
|
|
|
prom_cngetc,
|
|
|
|
prom_cnputc,
|
2000-05-19 09:26:16 +04:00
|
|
|
prom_cnpollc,
|
2000-03-07 00:36:05 +03:00
|
|
|
NULL,
|
1999-05-23 06:46:35 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2000-05-19 09:26:16 +04:00
|
|
|
prom_cnprobe(cd)
|
|
|
|
struct consdev *cd;
|
1999-05-23 06:46:35 +04:00
|
|
|
{
|
2000-05-19 09:26:16 +04:00
|
|
|
#if NPCONS > 0
|
|
|
|
int maj;
|
2002-09-06 17:18:43 +04:00
|
|
|
extern const struct cdevsw pcons_cdevsw;
|
2000-05-19 09:26:16 +04:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
maj = cdevsw_lookup_major(&pcons_cdevsw);
|
2000-05-19 09:26:16 +04:00
|
|
|
cd->cn_dev = makedev(maj, 0);
|
|
|
|
cd->cn_pri = CN_INTERNAL;
|
|
|
|
#endif
|
1999-05-23 06:46:35 +04:00
|
|
|
}
|
|
|
|
|
2000-05-19 09:26:16 +04:00
|
|
|
int
|
1999-05-23 06:46:35 +04:00
|
|
|
prom_cngetc(dev)
|
|
|
|
dev_t dev;
|
|
|
|
{
|
2000-05-19 09:26:16 +04:00
|
|
|
unsigned char ch = '\0';
|
|
|
|
int l;
|
2000-07-11 00:24:23 +04:00
|
|
|
#ifdef DDB
|
|
|
|
static int nplus = 0;
|
|
|
|
#endif
|
2000-05-19 09:26:16 +04:00
|
|
|
|
|
|
|
while ((l = OF_read(stdin, &ch, 1)) != 1)
|
|
|
|
/* void */;
|
2000-07-11 00:24:23 +04:00
|
|
|
#ifdef DDB
|
|
|
|
if (ch == '+') {
|
|
|
|
if (nplus++ > 3) Debugger();
|
|
|
|
} else nplus = 0;
|
|
|
|
#endif
|
2000-05-19 09:26:16 +04:00
|
|
|
if (ch == '\r')
|
|
|
|
ch = '\n';
|
|
|
|
return ch;
|
|
|
|
}
|
2000-04-19 12:15:06 +04:00
|
|
|
|
2000-05-19 09:26:16 +04:00
|
|
|
static void
|
|
|
|
prom_cninit(cn)
|
|
|
|
struct consdev *cn;
|
|
|
|
{
|
|
|
|
if (!stdin) stdin = OF_stdin();
|
|
|
|
if (!stdout) stdout = OF_stdout();
|
1999-05-23 06:46:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PROM console output putchar.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
prom_cnputc(dev, c)
|
|
|
|
dev_t dev;
|
|
|
|
int c;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
char c0 = (c & 0x7f);
|
|
|
|
|
2000-05-19 09:26:16 +04:00
|
|
|
#if 0
|
|
|
|
if (!stdout) stdout = OF_stdout();
|
|
|
|
#endif
|
1999-05-23 06:46:35 +04:00
|
|
|
s = splhigh();
|
|
|
|
OF_write(stdout, &c0, 1);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
2000-05-19 09:26:16 +04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
1999-05-23 06:46:35 +04:00
|
|
|
/*****************************************************************/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2000-09-28 19:23:06 +04:00
|
|
|
#define DBPRINT(x) prom_printf x
|
1999-05-23 06:46:35 +04:00
|
|
|
#else
|
|
|
|
#define DBPRINT(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function replaces sys/dev/cninit.c
|
|
|
|
* Determine which device is the console using
|
|
|
|
* the PROM "input source" and "output sink".
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
consinit()
|
|
|
|
{
|
|
|
|
register int chosen;
|
|
|
|
char buffer[128];
|
|
|
|
extern int stdinnode, fbnode;
|
|
|
|
char *consname = "unknown";
|
|
|
|
|
|
|
|
DBPRINT(("consinit()\r\n"));
|
|
|
|
if (cn_tab != &consdev_prom) return;
|
|
|
|
|
|
|
|
DBPRINT(("setting up stdin\r\n"));
|
|
|
|
chosen = OF_finddevice("/chosen");
|
2001-08-31 21:10:54 +04:00
|
|
|
DBPRINT(("chosen = %x, stdin @ %p\r\n", chosen, &stdin));
|
1999-05-23 06:46:35 +04:00
|
|
|
OF_getprop(chosen, "stdin", &stdin, sizeof(stdin));
|
|
|
|
DBPRINT(("stdin instance = %x\r\n", stdin));
|
|
|
|
|
|
|
|
if ((stdinnode = OF_instance_to_package(stdin)) == 0) {
|
|
|
|
printf("WARNING: no PROM stdin\n");
|
|
|
|
}
|
|
|
|
|
2001-08-31 21:10:54 +04:00
|
|
|
DBPRINT(("stdin node = %x\r\n", stdinnode));
|
1999-05-23 06:46:35 +04:00
|
|
|
DBPRINT(("setting up stdout\r\n"));
|
|
|
|
OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
|
|
|
|
|
|
|
|
DBPRINT(("stdout instance = %x\r\n", stdout));
|
|
|
|
|
|
|
|
if ((fbnode = OF_instance_to_package(stdout)) == 0)
|
|
|
|
printf("WARNING: no PROM stdout\n");
|
|
|
|
|
|
|
|
DBPRINT(("stdout package = %x\r\n", fbnode));
|
2001-08-31 21:10:54 +04:00
|
|
|
DBPRINT(("buffer @ %p\r\n", buffer));
|
1999-05-23 06:46:35 +04:00
|
|
|
|
|
|
|
if (stdinnode && (OF_getproplen(stdinnode,"keyboard") >= 0)) {
|
|
|
|
#if NKBD > 0
|
|
|
|
printf("cninit: kdb/display not configured\n");
|
|
|
|
#endif
|
|
|
|
consname = "keyboard/display";
|
|
|
|
} else if (fbnode &&
|
2001-08-31 21:10:54 +04:00
|
|
|
(OF_instance_to_path(stdin, buffer, sizeof(buffer)) >= 0)) {
|
1999-05-23 06:46:35 +04:00
|
|
|
consname = buffer;
|
|
|
|
}
|
|
|
|
printf("console is %s\n", consname);
|
|
|
|
|
2000-05-19 09:26:16 +04:00
|
|
|
/* Initialize PROM console */
|
|
|
|
(*cn_tab->cn_probe)(cn_tab);
|
|
|
|
(*cn_tab->cn_init)(cn_tab);
|
1999-05-23 06:46:35 +04:00
|
|
|
}
|
|
|
|
|