xref: /netbsd-src/sys/arch/sparc64/dev/consinit.c (revision c46608621040cd74bdbf5061122f9c68800c9971)
1*c4660862Snakayama /*	$NetBSD: consinit.c,v 1.28 2015/03/02 14:17:06 nakayama Exp $	*/
2193cc317Seeh 
3193cc317Seeh /*-
4193cc317Seeh  * Copyright (c) 1999 Eduardo E. Horvath
5193cc317Seeh  * All rights reserved.
6193cc317Seeh  *
7193cc317Seeh  * Redistribution and use in source and binary forms, with or without
8193cc317Seeh  * modification, are permitted provided that the following conditions
9193cc317Seeh  * are met:
10193cc317Seeh  * 1. Redistributions of source code must retain the above copyright
11193cc317Seeh  *    notice, this list of conditions and the following disclaimer.
12193cc317Seeh  * 2. Redistributions in binary form must reproduce the above copyright
13193cc317Seeh  *    notice, this list of conditions and the following disclaimer in the
14193cc317Seeh  *    documentation and/or other materials provided with the distribution.
15193cc317Seeh  * 3. The name of the author may not be used to endorse or promote products
16193cc317Seeh  *    derived from this software without specific prior written permission.
17193cc317Seeh  *
18193cc317Seeh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19193cc317Seeh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20193cc317Seeh  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21193cc317Seeh  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22193cc317Seeh  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23193cc317Seeh  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24193cc317Seeh  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25193cc317Seeh  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26193cc317Seeh  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27193cc317Seeh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28193cc317Seeh  * SUCH DAMAGE.
29193cc317Seeh  */
30193cc317Seeh 
31ed517291Slukem #include <sys/cdefs.h>
32*c4660862Snakayama __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.28 2015/03/02 14:17:06 nakayama Exp $");
33ed517291Slukem 
34193cc317Seeh #include "opt_ddb.h"
35424619caSeeh #include "pcons.h"
36b4946a55Sjdc #include "ukbd.h"
37193cc317Seeh 
38193cc317Seeh #include <sys/param.h>
39193cc317Seeh #include <sys/systm.h>
40193cc317Seeh #include <sys/conf.h>
41193cc317Seeh #include <sys/device.h>
42193cc317Seeh #include <sys/file.h>
43193cc317Seeh #include <sys/ioctl.h>
44193cc317Seeh #include <sys/kernel.h>
45193cc317Seeh #include <sys/proc.h>
46193cc317Seeh #include <sys/tty.h>
47193cc317Seeh #include <sys/time.h>
48193cc317Seeh #include <sys/syslog.h>
49193cc317Seeh 
50193cc317Seeh #include <machine/autoconf.h>
51193cc317Seeh #include <machine/openfirm.h>
52193cc317Seeh #include <machine/bsd_openprom.h>
53193cc317Seeh #include <machine/cpu.h>
54193cc317Seeh #include <machine/eeprom.h>
55193cc317Seeh #include <machine/psl.h>
56193cc317Seeh #include <machine/z8530var.h>
5782d7f3e3Smrg #include <machine/sparc64.h>
58193cc317Seeh 
59193cc317Seeh #include <dev/cons.h>
60193cc317Seeh 
61193cc317Seeh #include <sparc64/dev/cons.h>
62193cc317Seeh 
63b4946a55Sjdc #include <dev/usb/ukbdvar.h>
64b4946a55Sjdc 
651a509d61Scdi static void prom_cnprobe(struct consdev *);
661a509d61Scdi static void prom_cninit(struct consdev *);
671a509d61Scdi int  prom_cngetc(dev_t);
681a509d61Scdi static void prom_cnputc(dev_t, int);
691a509d61Scdi static void prom_cnpollc(dev_t, int);
70193cc317Seeh 
71193cc317Seeh /*
72193cc317Seeh  * The console is set to this one initially,
73193cc317Seeh  * which lets us use the PROM until consinit()
74193cc317Seeh  * is called to select a real console.
75193cc317Seeh  */
76193cc317Seeh struct consdev consdev_prom = {
774183890eSmartin 	.cn_probe = prom_cnprobe,
784183890eSmartin 	.cn_init = prom_cninit,
794183890eSmartin 	.cn_getc = prom_cngetc,
804183890eSmartin 	.cn_putc = prom_cnputc,
814183890eSmartin 	.cn_pollc = prom_cnpollc,
82193cc317Seeh };
83193cc317Seeh 
84193cc317Seeh void
prom_cnprobe(struct consdev * cd)851a509d61Scdi prom_cnprobe(struct consdev *cd)
86193cc317Seeh {
87424619caSeeh #if NPCONS > 0
88424619caSeeh 	int maj;
8977a6b82bSgehenna 	extern const struct cdevsw pcons_cdevsw;
90424619caSeeh 
9177a6b82bSgehenna 	maj = cdevsw_lookup_major(&pcons_cdevsw);
92424619caSeeh 	cd->cn_dev = makedev(maj, 0);
93424619caSeeh 	cd->cn_pri = CN_INTERNAL;
94424619caSeeh #endif
95424619caSeeh }
96424619caSeeh 
97424619caSeeh int
prom_cngetc(dev_t dev)981a509d61Scdi prom_cngetc(dev_t dev)
99424619caSeeh {
100424619caSeeh 	unsigned char ch = '\0';
101424619caSeeh 	int l;
102f10d7699Seeh #ifdef DDB
103f10d7699Seeh 	static int nplus = 0;
104f10d7699Seeh #endif
105424619caSeeh 
10605a2b230Spk 	while ((l = prom_read(prom_stdin(), &ch, 1)) != 1)
107424619caSeeh 		/* void */;
108f10d7699Seeh #ifdef DDB
109f10d7699Seeh 	if (ch == '+') {
110f10d7699Seeh 		if (nplus++ > 3) Debugger();
111f10d7699Seeh 	} else nplus = 0;
112f10d7699Seeh #endif
113424619caSeeh 	if (ch == '\r')
114424619caSeeh 		ch = '\n';
115424619caSeeh 	return ch;
116193cc317Seeh }
117193cc317Seeh 
118193cc317Seeh static void
prom_cninit(struct consdev * cn)1191a509d61Scdi prom_cninit(struct consdev *cn)
120193cc317Seeh {
121193cc317Seeh }
122193cc317Seeh 
123193cc317Seeh /*
124193cc317Seeh  * PROM console output putchar.
125193cc317Seeh  */
126193cc317Seeh static void
prom_cnputc(dev_t dev,int c)1271a509d61Scdi prom_cnputc(dev_t dev, int c)
128193cc317Seeh {
129193cc317Seeh 	int s;
130193cc317Seeh 	char c0 = (c & 0x7f);
131193cc317Seeh 
132193cc317Seeh 	s = splhigh();
13305a2b230Spk 	prom_write(prom_stdout(), &c0, 1);
134193cc317Seeh 	splx(s);
135193cc317Seeh }
136193cc317Seeh 
137424619caSeeh void
prom_cnpollc(dev_t dev,int on)1381a509d61Scdi prom_cnpollc(dev_t dev, int on)
139424619caSeeh {
140424619caSeeh 	if (on) {
141424619caSeeh                 /* Entering debugger. */
142424619caSeeh #if NFB > 0
143424619caSeeh                 fb_unblank();
144424619caSeeh #endif
145424619caSeeh 	} else {
146424619caSeeh                 /* Resuming kernel. */
147424619caSeeh 	}
148424619caSeeh #if NPCONS > 0
149424619caSeeh 	pcons_cnpollc(dev, on);
150424619caSeeh #endif
151424619caSeeh }
152424619caSeeh 
153193cc317Seeh /*****************************************************************/
154193cc317Seeh 
155193cc317Seeh #ifdef	DEBUG
156a5a80824Seeh #define	DBPRINT(x)	prom_printf x
157193cc317Seeh #else
158193cc317Seeh #define	DBPRINT(x)
159193cc317Seeh #endif
160193cc317Seeh 
1616c02638eSpk int prom_stdin_node;
1626c02638eSpk int prom_stdout_node;
1636c02638eSpk 
164193cc317Seeh /*
165193cc317Seeh  * This function replaces sys/dev/cninit.c
166193cc317Seeh  * Determine which device is the console using
167193cc317Seeh  * the PROM "input source" and "output sink".
168193cc317Seeh  */
169193cc317Seeh void
consinit(void)170df7f595eScegger consinit(void)
171193cc317Seeh {
172193cc317Seeh 	char buffer[128];
1731a18f24fSchristos 	const char *consname = "unknown";
174193cc317Seeh 
175*c4660862Snakayama 	DBPRINT(("consinit()\n"));
1766c02638eSpk 
1776c02638eSpk 	if (cn_tab != &consdev_prom)
1786c02638eSpk 		return;
1796c02638eSpk 
18005a2b230Spk 	if ((prom_stdin_node = prom_instance_to_package(prom_stdin())) == 0) {
181193cc317Seeh 		printf("WARNING: no PROM stdin\n");
182193cc317Seeh 	}
183*c4660862Snakayama 	DBPRINT(("stdin node = %x\n", prom_stdin_node));
1846c02638eSpk 
18505a2b230Spk 	if ((prom_stdout_node = prom_instance_to_package(prom_stdout())) == 0)
186193cc317Seeh 		printf("WARNING: no PROM stdout\n");
187*c4660862Snakayama 	DBPRINT(("stdout package = %x\n", prom_stdout_node));
1886c02638eSpk 
189*c4660862Snakayama 	DBPRINT(("buffer @ %p\n", buffer));
190193cc317Seeh 
1916c02638eSpk 	if (prom_stdin_node != 0 &&
19205a2b230Spk 	    (prom_getproplen(prom_stdin_node, "keyboard") >= 0)) {
193b4946a55Sjdc #if NUKBD > 0
194b4946a55Sjdc 		if ((OF_instance_to_path(prom_stdin(), buffer, sizeof(buffer)) >= 0) &&
195b4946a55Sjdc 		    (strstr(buffer, "/usb@") != NULL)) {
196b4946a55Sjdc 			/*
197b4946a55Sjdc 		 	* If we have a USB keyboard, it will show up as (e.g.)
198b4946a55Sjdc 		 	*   /pci@1f,0/usb@c,3/keyboard@1	(Blade 100)
199b4946a55Sjdc 		 	*/
200b4946a55Sjdc 			consname = "usb-keyboard/display";
201b4946a55Sjdc 			ukbd_cnattach();
202b4946a55Sjdc 		} else
203193cc317Seeh #endif
204b4946a55Sjdc 			consname = "sun-keyboard/display";
205b4946a55Sjdc 	} else if (prom_stdin_node != 0 &&
20605a2b230Spk 		   (OF_instance_to_path(prom_stdin(), buffer, sizeof(buffer)) >= 0)) {
207193cc317Seeh 		consname = buffer;
208193cc317Seeh 	}
209464d49ceSmartin 	DBPRINT(("console is %s\n", consname));
21077cc2c9eSmartin #ifndef DEBUG
21177cc2c9eSmartin 	(void)consname;
21277cc2c9eSmartin #endif
213193cc317Seeh 
214424619caSeeh 	/* Initialize PROM console */
215424619caSeeh 	(*cn_tab->cn_probe)(cn_tab);
216424619caSeeh 	(*cn_tab->cn_init)(cn_tab);
217193cc317Seeh }
218