xref: /titanic_51/usr/src/uts/i86pc/io/consplat.c (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
1*ae115bc7Smrj /*
2*ae115bc7Smrj  * CDDL HEADER START
3*ae115bc7Smrj  *
4*ae115bc7Smrj  * The contents of this file are subject to the terms of the
5*ae115bc7Smrj  * Common Development and Distribution License (the "License").
6*ae115bc7Smrj  * You may not use this file except in compliance with the License.
7*ae115bc7Smrj  *
8*ae115bc7Smrj  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*ae115bc7Smrj  * or http://www.opensolaris.org/os/licensing.
10*ae115bc7Smrj  * See the License for the specific language governing permissions
11*ae115bc7Smrj  * and limitations under the License.
12*ae115bc7Smrj  *
13*ae115bc7Smrj  * When distributing Covered Code, include this CDDL HEADER in each
14*ae115bc7Smrj  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*ae115bc7Smrj  * If applicable, add the following below this CDDL HEADER, with the
16*ae115bc7Smrj  * fields enclosed by brackets "[]" replaced with your own identifying
17*ae115bc7Smrj  * information: Portions Copyright [yyyy] [name of copyright owner]
18*ae115bc7Smrj  *
19*ae115bc7Smrj  * CDDL HEADER END
20*ae115bc7Smrj  */
21*ae115bc7Smrj 
22*ae115bc7Smrj /*
23*ae115bc7Smrj  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24*ae115bc7Smrj  * Use is subject to license terms.
25*ae115bc7Smrj  */
26*ae115bc7Smrj 
27*ae115bc7Smrj #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*ae115bc7Smrj 
29*ae115bc7Smrj /*
30*ae115bc7Smrj  * isa-specific console configuration routines
31*ae115bc7Smrj  */
32*ae115bc7Smrj 
33*ae115bc7Smrj #include <sys/types.h>
34*ae115bc7Smrj #include <sys/param.h>
35*ae115bc7Smrj #include <sys/cmn_err.h>
36*ae115bc7Smrj #include <sys/systm.h>
37*ae115bc7Smrj #include <sys/conf.h>
38*ae115bc7Smrj #include <sys/debug.h>
39*ae115bc7Smrj #include <sys/ddi.h>
40*ae115bc7Smrj #include <sys/sunddi.h>
41*ae115bc7Smrj #include <sys/sunndi.h>
42*ae115bc7Smrj #include <sys/esunddi.h>
43*ae115bc7Smrj #include <sys/ddi_impldefs.h>
44*ae115bc7Smrj #include <sys/promif.h>
45*ae115bc7Smrj #include <sys/modctl.h>
46*ae115bc7Smrj #include <sys/termios.h>
47*ae115bc7Smrj 
48*ae115bc7Smrj /* The names of currently supported graphics drivers on x86 */
49*ae115bc7Smrj static char *
50*ae115bc7Smrj gfxdrv_name[] = {
51*ae115bc7Smrj 	"vgatext",
52*ae115bc7Smrj 	"i915",
53*ae115bc7Smrj 	"nvidia"
54*ae115bc7Smrj };
55*ae115bc7Smrj 
56*ae115bc7Smrj int
57*ae115bc7Smrj plat_use_polled_debug() {
58*ae115bc7Smrj 	return (0);
59*ae115bc7Smrj }
60*ae115bc7Smrj 
61*ae115bc7Smrj int
62*ae115bc7Smrj plat_support_serial_kbd_and_ms() {
63*ae115bc7Smrj 	return (0);
64*ae115bc7Smrj }
65*ae115bc7Smrj 
66*ae115bc7Smrj #define	CONS_INVALID	-1
67*ae115bc7Smrj #define	CONS_SCREEN	0
68*ae115bc7Smrj #define	CONS_TTYA	1
69*ae115bc7Smrj #define	CONS_TTYB	2
70*ae115bc7Smrj #define	CONS_USBSER	3
71*ae115bc7Smrj 
72*ae115bc7Smrj static int
73*ae115bc7Smrj console_type()
74*ae115bc7Smrj {
75*ae115bc7Smrj 	static int boot_console = CONS_INVALID;
76*ae115bc7Smrj 
77*ae115bc7Smrj 	char *cons;
78*ae115bc7Smrj 	dev_info_t *root;
79*ae115bc7Smrj 
80*ae115bc7Smrj 	if (boot_console != CONS_INVALID)
81*ae115bc7Smrj 		return (boot_console);
82*ae115bc7Smrj 
83*ae115bc7Smrj 	/*
84*ae115bc7Smrj 	 * console is defined by "console" property, with
85*ae115bc7Smrj 	 * fallback on the old "input-device" property.
86*ae115bc7Smrj 	 */
87*ae115bc7Smrj 	boot_console = CONS_SCREEN;	/* default is screen/kb */
88*ae115bc7Smrj 	root = ddi_root_node();
89*ae115bc7Smrj 	if ((ddi_prop_lookup_string(DDI_DEV_T_ANY, root,
90*ae115bc7Smrj 	    DDI_PROP_DONTPASS, "console", &cons) == DDI_SUCCESS) ||
91*ae115bc7Smrj 	    (ddi_prop_lookup_string(DDI_DEV_T_ANY, root,
92*ae115bc7Smrj 	    DDI_PROP_DONTPASS, "input-device", &cons) == DDI_SUCCESS)) {
93*ae115bc7Smrj 		if (strcmp(cons, "ttya") == 0)
94*ae115bc7Smrj 			boot_console = CONS_TTYA;
95*ae115bc7Smrj 		else if (strcmp(cons, "ttyb") == 0)
96*ae115bc7Smrj 			boot_console = CONS_TTYB;
97*ae115bc7Smrj 		else if (strcmp(cons, "usb-serial") == 0) {
98*ae115bc7Smrj 			(void) i_ddi_attach_hw_nodes("ehci");
99*ae115bc7Smrj 			(void) i_ddi_attach_hw_nodes("uhci");
100*ae115bc7Smrj 			(void) i_ddi_attach_hw_nodes("ohci");
101*ae115bc7Smrj 			/*
102*ae115bc7Smrj 			 * USB device enumerate asynchronously.
103*ae115bc7Smrj 			 * Wait 2 seconds for USB serial devices to attach.
104*ae115bc7Smrj 			 */
105*ae115bc7Smrj 			delay(drv_usectohz(2000000));
106*ae115bc7Smrj 			boot_console = CONS_USBSER;
107*ae115bc7Smrj 		}
108*ae115bc7Smrj 		ddi_prop_free(cons);
109*ae115bc7Smrj 	}
110*ae115bc7Smrj 	return (boot_console);
111*ae115bc7Smrj }
112*ae115bc7Smrj 
113*ae115bc7Smrj int
114*ae115bc7Smrj plat_stdin_is_keyboard(void)
115*ae115bc7Smrj {
116*ae115bc7Smrj 	return (console_type() == CONS_SCREEN);
117*ae115bc7Smrj }
118*ae115bc7Smrj 
119*ae115bc7Smrj int
120*ae115bc7Smrj plat_stdout_is_framebuffer(void)
121*ae115bc7Smrj {
122*ae115bc7Smrj 	return (console_type() == CONS_SCREEN);
123*ae115bc7Smrj }
124*ae115bc7Smrj 
125*ae115bc7Smrj /*
126*ae115bc7Smrj  * Return generic path to keyboard device from the alias.
127*ae115bc7Smrj  */
128*ae115bc7Smrj char *
129*ae115bc7Smrj plat_kbdpath(void)
130*ae115bc7Smrj {
131*ae115bc7Smrj 	/*
132*ae115bc7Smrj 	 * Hardcode to isa keyboard path
133*ae115bc7Smrj 	 * XXX make it settable via bootprop?
134*ae115bc7Smrj 	 */
135*ae115bc7Smrj 	return ("/isa/i8042@1,60/keyboard@0");
136*ae115bc7Smrj }
137*ae115bc7Smrj 
138*ae115bc7Smrj /*
139*ae115bc7Smrj  * Return generic path to display device from the alias.
140*ae115bc7Smrj  */
141*ae115bc7Smrj char *
142*ae115bc7Smrj plat_fbpath(void)
143*ae115bc7Smrj {
144*ae115bc7Smrj 	static char *fbpath = NULL;
145*ae115bc7Smrj 	static char fbpath_buf[MAXPATHLEN];
146*ae115bc7Smrj 	major_t major;
147*ae115bc7Smrj 	dev_info_t *dip;
148*ae115bc7Smrj 	int i;
149*ae115bc7Smrj 
150*ae115bc7Smrj 	for (i = 0; i < (sizeof (gfxdrv_name) / sizeof (char *)); i++) {
151*ae115bc7Smrj 		/*
152*ae115bc7Smrj 		 * look for first instance of each driver
153*ae115bc7Smrj 		 */
154*ae115bc7Smrj 		major = ddi_name_to_major(gfxdrv_name[i]);
155*ae115bc7Smrj 		if (major != (major_t)-1) {
156*ae115bc7Smrj 			dip = devnamesp[major].dn_head;
157*ae115bc7Smrj 			if (dip &&
158*ae115bc7Smrj 			    i_ddi_attach_node_hierarchy(dip) == DDI_SUCCESS) {
159*ae115bc7Smrj 				(void) ddi_pathname(dip, fbpath_buf);
160*ae115bc7Smrj 				fbpath = fbpath_buf;
161*ae115bc7Smrj 			}
162*ae115bc7Smrj 		}
163*ae115bc7Smrj 
164*ae115bc7Smrj 		if (fbpath)
165*ae115bc7Smrj 			return (fbpath);
166*ae115bc7Smrj 	}
167*ae115bc7Smrj 
168*ae115bc7Smrj 	/* No screen found */
169*ae115bc7Smrj 	return (NULL);
170*ae115bc7Smrj }
171*ae115bc7Smrj 
172*ae115bc7Smrj char *
173*ae115bc7Smrj plat_mousepath(void)
174*ae115bc7Smrj {
175*ae115bc7Smrj 	/*
176*ae115bc7Smrj 	 * Hardcode to isa mouse path
177*ae115bc7Smrj 	 * XXX make it settable via bootprop?
178*ae115bc7Smrj 	 */
179*ae115bc7Smrj 	return ("/isa/i8042@1,60/mouse@1");
180*ae115bc7Smrj }
181*ae115bc7Smrj 
182*ae115bc7Smrj /* return path of first usb serial device */
183*ae115bc7Smrj static char *
184*ae115bc7Smrj plat_usbser_path(void)
185*ae115bc7Smrj {
186*ae115bc7Smrj 	extern dev_info_t *usbser_first_device(void);
187*ae115bc7Smrj 
188*ae115bc7Smrj 	dev_info_t *us_dip;
189*ae115bc7Smrj 	static char *us_path = NULL;
190*ae115bc7Smrj 
191*ae115bc7Smrj 	if (us_path)
192*ae115bc7Smrj 		return (us_path);
193*ae115bc7Smrj 
194*ae115bc7Smrj 	us_dip = usbser_first_device();
195*ae115bc7Smrj 	if (us_dip == NULL)
196*ae115bc7Smrj 		return (NULL);
197*ae115bc7Smrj 
198*ae115bc7Smrj 	us_path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
199*ae115bc7Smrj 	(void) ddi_pathname(us_dip, us_path);
200*ae115bc7Smrj 	ndi_rele_devi(us_dip);	/* held from usbser_first_device */
201*ae115bc7Smrj 	return (us_path);
202*ae115bc7Smrj }
203*ae115bc7Smrj 
204*ae115bc7Smrj /*
205*ae115bc7Smrj  * Lacking support for com2 and com3, if that matters.
206*ae115bc7Smrj  * Another possible enhancement could be to use properties
207*ae115bc7Smrj  * for the port mapping rather than simply hard-code them.
208*ae115bc7Smrj  */
209*ae115bc7Smrj char *
210*ae115bc7Smrj plat_stdinpath(void)
211*ae115bc7Smrj {
212*ae115bc7Smrj 	switch (console_type()) {
213*ae115bc7Smrj 	case CONS_TTYA:
214*ae115bc7Smrj 		return ("/isa/asy@1,3f8:a");
215*ae115bc7Smrj 	case CONS_TTYB:
216*ae115bc7Smrj 		return ("/isa/asy@1,2f8:b");
217*ae115bc7Smrj 	case CONS_USBSER:
218*ae115bc7Smrj 		return (plat_usbser_path());
219*ae115bc7Smrj 	case CONS_SCREEN:
220*ae115bc7Smrj 	default:
221*ae115bc7Smrj 		break;
222*ae115bc7Smrj 	};
223*ae115bc7Smrj 	return (plat_kbdpath());
224*ae115bc7Smrj }
225*ae115bc7Smrj 
226*ae115bc7Smrj char *
227*ae115bc7Smrj plat_stdoutpath(void)
228*ae115bc7Smrj {
229*ae115bc7Smrj 	switch (console_type()) {
230*ae115bc7Smrj 	case CONS_TTYA:
231*ae115bc7Smrj 		return ("/isa/asy@1,3f8:a");
232*ae115bc7Smrj 	case CONS_TTYB:
233*ae115bc7Smrj 		return ("/isa/asy@1,2f8:b");
234*ae115bc7Smrj 	case CONS_USBSER:
235*ae115bc7Smrj 		return (plat_usbser_path());
236*ae115bc7Smrj 	case CONS_SCREEN:
237*ae115bc7Smrj 	default:
238*ae115bc7Smrj 		break;
239*ae115bc7Smrj 	};
240*ae115bc7Smrj 	return (plat_fbpath());
241*ae115bc7Smrj }
242*ae115bc7Smrj 
243*ae115bc7Smrj /*
244*ae115bc7Smrj  * If VIS_PIXEL mode will be implemented on x86, these following
245*ae115bc7Smrj  * functions should be re-considered. Now these functions are
246*ae115bc7Smrj  * unused on x86.
247*ae115bc7Smrj  */
248*ae115bc7Smrj void
249*ae115bc7Smrj plat_tem_get_prom_font_size(int *charheight, int *windowtop)
250*ae115bc7Smrj {
251*ae115bc7Smrj 	*charheight = 0;
252*ae115bc7Smrj 	*windowtop = 0;
253*ae115bc7Smrj }
254*ae115bc7Smrj 
255*ae115bc7Smrj void
256*ae115bc7Smrj plat_tem_get_prom_size(size_t *height, size_t *width)
257*ae115bc7Smrj {
258*ae115bc7Smrj 	*height = 25;
259*ae115bc7Smrj 	*width = 80;
260*ae115bc7Smrj }
261*ae115bc7Smrj 
262*ae115bc7Smrj void
263*ae115bc7Smrj plat_tem_hide_prom_cursor(void)
264*ae115bc7Smrj {
265*ae115bc7Smrj }
266*ae115bc7Smrj 
267*ae115bc7Smrj void
268*ae115bc7Smrj plat_tem_get_prom_pos(uint32_t *row, uint32_t *col)
269*ae115bc7Smrj {
270*ae115bc7Smrj 	*row = 0;
271*ae115bc7Smrj 	*col = 0;
272*ae115bc7Smrj }
273