#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.28 2015/03/02 14:17:06 nakayama Exp $");
#include "opt_ddb.h"
#include "pcons.h"
#include "ukbd.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/openfirm.h>
#include <machine/bsd_openprom.h>
#include <machine/cpu.h>
#include <machine/eeprom.h>
#include <machine/psl.h>
#include <machine/z8530var.h>
#include <machine/sparc64.h>
#include <dev/cons.h>
#include <sparc64/dev/cons.h>
#include <dev/usb/ukbdvar.h>
static void prom_cnprobe(struct consdev *);
static void prom_cninit(struct consdev *);
int prom_cngetc(dev_t);
static void prom_cnputc(dev_t, int);
static void prom_cnpollc(dev_t, int);
struct consdev consdev_prom = {
.cn_probe = prom_cnprobe,
.cn_init = prom_cninit,
.cn_getc = prom_cngetc,
.cn_putc = prom_cnputc,
.cn_pollc = prom_cnpollc,
};
void
prom_cnprobe(struct consdev *cd)
{
#if NPCONS > 0
int maj;
extern const struct cdevsw pcons_cdevsw;
maj = cdevsw_lookup_major(&pcons_cdevsw);
cd->cn_dev = makedev(maj, 0);
cd->cn_pri = CN_INTERNAL;
#endif
}
int
prom_cngetc(dev_t dev)
{
unsigned char ch = '\0';
int l;
#ifdef DDB
static int nplus = 0;
#endif
while ((l = prom_read(prom_stdin(), &ch, 1)) != 1)
;
#ifdef DDB
if (ch == '+') {
if (nplus++ > 3) Debugger();
} else nplus = 0;
#endif
if (ch == '\r')
ch = '\n';
return ch;
}
static void
prom_cninit(struct consdev *cn)
{
}
static void
prom_cnputc(dev_t dev, int c)
{
int s;
char c0 = (c & 0x7f);
s = splhigh();
prom_write(prom_stdout(), &c0, 1);
splx(s);
}
void
prom_cnpollc(dev_t dev, int on)
{
if (on) {
#if NFB > 0
fb_unblank();
#endif
} else {
}
#if NPCONS > 0
pcons_cnpollc(dev, on);
#endif
}
#ifdef DEBUG
#define DBPRINT(x) prom_printf x
#else
#define DBPRINT(x)
#endif
int prom_stdin_node;
int prom_stdout_node;
void
consinit(void)
{
char buffer[128];
const char *consname = "unknown";
DBPRINT(("consinit()\n"));
if (cn_tab != &consdev_prom)
return;
if ((prom_stdin_node = prom_instance_to_package(prom_stdin())) == 0) {
printf("WARNING: no PROM stdin\n");
}
DBPRINT(("stdin node = %x\n", prom_stdin_node));
if ((prom_stdout_node = prom_instance_to_package(prom_stdout())) == 0)
printf("WARNING: no PROM stdout\n");
DBPRINT(("stdout package = %x\n", prom_stdout_node));
DBPRINT(("buffer @ %p\n", buffer));
if (prom_stdin_node != 0 &&
(prom_getproplen(prom_stdin_node, "keyboard") >= 0)) {
#if NUKBD > 0
if ((OF_instance_to_path(prom_stdin(), buffer, sizeof(buffer)) >= 0) &&
(strstr(buffer, "/usb@") != NULL)) {
consname = "usb-keyboard/display";
ukbd_cnattach();
} else
#endif
consname = "sun-keyboard/display";
} else if (prom_stdin_node != 0 &&
(OF_instance_to_path(prom_stdin(), buffer, sizeof(buffer)) >= 0)) {
consname = buffer;
}
DBPRINT(("console is %s\n", consname));
#ifndef DEBUG
(void)consname;
#endif
(*cn_tab->cn_probe)(cn_tab);
(*cn_tab->cn_init)(cn_tab);
}