Annotation of sys/arch/sparc64/dev/consinit.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: consinit.c,v 1.10 2005/04/26 15:16:20 miod Exp $ */
! 2: /* $NetBSD: consinit.c,v 1.9 2000/10/20 05:32:35 mrg Exp $ */
! 3:
! 4: /*-
! 5: * Copyright (c) 1999 Eduardo E. Horvath
! 6: * All rights reserved.
! 7: *
! 8: * Redistribution and use in source and binary forms, with or without
! 9: * modification, are permitted provided that the following conditions
! 10: * are met:
! 11: * 1. Redistributions of source code must retain the above copyright
! 12: * notice, this list of conditions and the following disclaimer.
! 13: * 2. Redistributions in binary form must reproduce the above copyright
! 14: * notice, this list of conditions and the following disclaimer in the
! 15: * documentation and/or other materials provided with the distribution.
! 16: * 3. The name of the author may not be used to endorse or promote products
! 17: * derived from this software without specific prior written permission.
! 18: *
! 19: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 20: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 21: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 22: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 23: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
! 24: * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
! 25: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
! 26: * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
! 27: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 29: * SUCH DAMAGE.
! 30: */
! 31:
! 32: #include "pcons.h"
! 33: #include "ukbd.h"
! 34:
! 35: #include <sys/param.h>
! 36: #include <sys/systm.h>
! 37: #include <sys/conf.h>
! 38: #include <sys/device.h>
! 39: #include <sys/file.h>
! 40: #include <sys/ioctl.h>
! 41: #include <sys/kernel.h>
! 42: #include <sys/proc.h>
! 43: #include <sys/tty.h>
! 44: #include <sys/time.h>
! 45: #include <sys/syslog.h>
! 46:
! 47: #include <machine/autoconf.h>
! 48: #include <machine/openfirm.h>
! 49: #include <machine/bsd_openprom.h>
! 50: #include <machine/conf.h>
! 51: #include <machine/cpu.h>
! 52: #include <machine/eeprom.h>
! 53: #include <machine/psl.h>
! 54: #include <machine/z8530var.h>
! 55: #include <machine/sparc64.h>
! 56:
! 57: #include <dev/cons.h>
! 58:
! 59: #include <sparc64/dev/cons.h>
! 60:
! 61: #include <dev/usb/ukbdvar.h>
! 62:
! 63: cons_decl(prom_);
! 64:
! 65: int stdin = NULL, stdout = NULL;
! 66:
! 67: /*
! 68: * The console is set to this one initially,
! 69: * which lets us use the PROM until consinit()
! 70: * is called to select a real console.
! 71: */
! 72: struct consdev consdev_prom = {
! 73: prom_cnprobe,
! 74: prom_cninit,
! 75: prom_cngetc,
! 76: prom_cnputc,
! 77: prom_cnpollc,
! 78: NULL
! 79: };
! 80:
! 81: /*
! 82: * The console table pointer is statically initialized
! 83: * to point to the PROM (output only) table, so that
! 84: * early calls to printf will work.
! 85: */
! 86: struct consdev *cn_tab = &consdev_prom;
! 87:
! 88: void
! 89: prom_cnprobe(struct consdev *cd)
! 90: {
! 91: #if NPCONS > 0
! 92: int maj;
! 93:
! 94: for (maj = 0; maj < nchrdev; maj++)
! 95: if (cdevsw[maj].d_open == pconsopen)
! 96: break;
! 97: cd->cn_dev = makedev(maj, 0);
! 98: cd->cn_pri = CN_INTERNAL;
! 99: #endif
! 100: }
! 101:
! 102: int
! 103: prom_cngetc(dev_t dev)
! 104: {
! 105: unsigned char ch = '\0';
! 106: int l;
! 107: #ifdef DDB
! 108: static int nplus = 0;
! 109: #endif
! 110:
! 111: while ((l = OF_read(stdin, &ch, 1)) != 1)
! 112: /* void */;
! 113: #ifdef DDB
! 114: if (ch == '+') {
! 115: if (nplus++ > 3)
! 116: Debugger();
! 117: } else
! 118: nplus = 0;
! 119: #endif
! 120: if (ch == '\r')
! 121: ch = '\n';
! 122: if (ch == '\b')
! 123: ch = '\177';
! 124: return ch;
! 125: }
! 126:
! 127: void
! 128: prom_cninit(struct consdev *cn)
! 129: {
! 130: if (!stdin) stdin = OF_stdin();
! 131: if (!stdout) stdout = OF_stdout();
! 132: }
! 133:
! 134: /*
! 135: * PROM console output putchar.
! 136: */
! 137: void
! 138: prom_cnputc(dev_t dev, int c)
! 139: {
! 140: int s;
! 141: char c0 = (c & 0x7f);
! 142:
! 143: #if 0
! 144: if (!stdout) stdout = OF_stdout();
! 145: #endif
! 146: s = splhigh();
! 147: OF_write(stdout, &c0, 1);
! 148: splx(s);
! 149: }
! 150:
! 151: void
! 152: prom_cnpollc(dev_t dev, int on)
! 153: {
! 154: if (on) {
! 155: /* Entering debugger. */
! 156: fb_unblank();
! 157: } else {
! 158: /* Resuming kernel. */
! 159: }
! 160: #if NPCONS > 0
! 161: pcons_cnpollc(dev, on);
! 162: #endif
! 163: }
! 164:
! 165: /*****************************************************************/
! 166:
! 167: #ifdef DEBUG
! 168: #define DBPRINT(x) prom_printf x
! 169: #else
! 170: #define DBPRINT(x)
! 171: #endif
! 172:
! 173: /*
! 174: * This function replaces sys/dev/cninit.c
! 175: * Determine which device is the console using
! 176: * the PROM "input source" and "output sink".
! 177: */
! 178: void
! 179: consinit()
! 180: {
! 181: register int chosen;
! 182: char buffer[128];
! 183: extern int stdinnode, fbnode;
! 184: char *consname = "unknown";
! 185:
! 186: DBPRINT(("consinit()\r\n"));
! 187: if (cn_tab != &consdev_prom) return;
! 188:
! 189: DBPRINT(("setting up stdin\r\n"));
! 190: chosen = OF_finddevice("/chosen");
! 191: OF_getprop(chosen, "stdin", &stdin, sizeof(stdin));
! 192: DBPRINT(("stdin instance = %x\r\n", stdin));
! 193:
! 194: if ((stdinnode = OF_instance_to_package(stdin)) == 0) {
! 195: printf("WARNING: no PROM stdin\n");
! 196: }
! 197: #if NUKBD > 0
! 198: else {
! 199: if (OF_getprop(stdinnode, "compatible", buffer,
! 200: sizeof(buffer)) != -1 && strncmp("usb", buffer, 3) == 0)
! 201: ukbd_cnattach();
! 202: }
! 203: #endif
! 204:
! 205: DBPRINT(("setting up stdout\r\n"));
! 206: OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
! 207:
! 208: DBPRINT(("stdout instance = %x\r\n", stdout));
! 209:
! 210: if ((fbnode = OF_instance_to_package(stdout)) == 0)
! 211: printf("WARNING: no PROM stdout\n");
! 212:
! 213: DBPRINT(("stdout package = %x\r\n", fbnode));
! 214:
! 215: if (stdinnode && (OF_getproplen(stdinnode,"keyboard") >= 0)) {
! 216: consname = "keyboard/display";
! 217: } else if (fbnode &&
! 218: (OF_instance_to_path(stdin, buffer, sizeof(buffer)) >= 0)) {
! 219: consname = buffer;
! 220: }
! 221: printf("console is %s\n", consname);
! 222:
! 223: /* Initialize PROM console */
! 224: (*cn_tab->cn_probe)(cn_tab);
! 225: (*cn_tab->cn_init)(cn_tab);
! 226: }
CVSweb