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