xref: /illumos-gate/usr/src/uts/i86pc/io/consplat.c (revision 967072a15e834441c4b221b17b3859169a2c9af2)
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 2007 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 	"vgatext",
56 	"i915",
57 	"atiatom",
58 	"nvidia",
59 };
60 
61 int
62 plat_use_polled_debug() {
63 	return (0);
64 }
65 
66 int
67 plat_support_serial_kbd_and_ms() {
68 	return (0);
69 }
70 
71 #define	A_CNT(arr)	(sizeof (arr) / sizeof (arr[0]))
72 
73 #define	CONS_INVALID	-1
74 #define	CONS_SCREEN	0
75 #define	CONS_TTYA	1
76 #define	CONS_TTYB	2
77 #define	CONS_USBSER	3
78 #define	CONS_HYPERVISOR	4
79 
80 static int
81 console_type()
82 {
83 	static int boot_console = CONS_INVALID;
84 
85 	char *cons;
86 	dev_info_t *root;
87 
88 	if (boot_console != CONS_INVALID)
89 		return (boot_console);
90 
91 #if defined(__xpv)
92 	if (!DOMAIN_IS_INITDOMAIN(xen_info) || bcons_hypervisor_redirect()) {
93 		boot_console = CONS_HYPERVISOR;
94 		return (boot_console);
95 	}
96 #endif /* __xpv */
97 
98 	/*
99 	 * console is defined by "console" property, with
100 	 * fallback on the old "input-device" property.
101 	 */
102 	boot_console = CONS_SCREEN;	/* default is screen/kb */
103 	root = ddi_root_node();
104 	if ((ddi_prop_lookup_string(DDI_DEV_T_ANY, root,
105 	    DDI_PROP_DONTPASS, "console", &cons) == DDI_SUCCESS) ||
106 	    (ddi_prop_lookup_string(DDI_DEV_T_ANY, root,
107 	    DDI_PROP_DONTPASS, "input-device", &cons) == DDI_SUCCESS)) {
108 		if (strcmp(cons, "ttya") == 0) {
109 			boot_console = CONS_TTYA;
110 		} else if (strcmp(cons, "ttyb") == 0) {
111 			boot_console = CONS_TTYB;
112 		} else if (strcmp(cons, "usb-serial") == 0) {
113 			(void) i_ddi_attach_hw_nodes("ehci");
114 			(void) i_ddi_attach_hw_nodes("uhci");
115 			(void) i_ddi_attach_hw_nodes("ohci");
116 			/*
117 			 * USB device enumerate asynchronously.
118 			 * Wait 2 seconds for USB serial devices to attach.
119 			 */
120 			delay(drv_usectohz(2000000));
121 			boot_console = CONS_USBSER;
122 #if defined(__xpv)
123 		} else if (strcmp(cons, "hypervisor") == 0) {
124 			boot_console = CONS_HYPERVISOR;
125 #endif /* __xpv */
126 		}
127 		ddi_prop_free(cons);
128 	}
129 	return (boot_console);
130 }
131 
132 int
133 plat_stdin_is_keyboard(void)
134 {
135 	return (console_type() == CONS_SCREEN);
136 }
137 
138 int
139 plat_stdout_is_framebuffer(void)
140 {
141 	return (console_type() == CONS_SCREEN);
142 }
143 
144 /*
145  * Return generic path to keyboard device from the alias.
146  */
147 char *
148 plat_kbdpath(void)
149 {
150 	/*
151 	 * Hardcode to isa keyboard path
152 	 * XXX make it settable via bootprop?
153 	 */
154 	return ("/isa/i8042@1,60/keyboard@0");
155 }
156 
157 /*
158  * Return generic path to display device from the alias.
159  */
160 char *
161 plat_fbpath(void)
162 {
163 	static char *fbpath = NULL;
164 	static char fbpath_buf[MAXPATHLEN];
165 	major_t major;
166 	dev_info_t *dip, *dip_pseudo = NULL;
167 	int i;
168 
169 	/* lookup the dip for the pseudo device */
170 	(void) resolve_pathname("/pseudo", &dip_pseudo, NULL, NULL);
171 
172 	for (i = 0; i < A_CNT(gfxdrv_name); i++) {
173 		/*
174 		 * look for first instance of each driver
175 		 */
176 		if ((major = ddi_name_to_major(gfxdrv_name[i])) == (major_t)-1)
177 			continue;
178 
179 		if ((dip = devnamesp[major].dn_head) == NULL)
180 			continue;
181 
182 		/*
183 		 * We're looking for a real hardware device here so skip
184 		 * any pseudo devices.  When could a framebuffer hardware
185 		 * driver also have a pseudo node?  Well, some framebuffer
186 		 * hardware drivers (nvidia) also create pseudo nodes for
187 		 * administration purposes, and these nodes will exist
188 		 * regardless of if the actual associated hardware
189 		 * is present or not.
190 		 */
191 		if (ddi_get_parent(dip) == dip_pseudo)
192 			continue;
193 
194 		if (i_ddi_attach_node_hierarchy(dip) == DDI_SUCCESS) {
195 			(void) ddi_pathname(dip, fbpath_buf);
196 			fbpath = fbpath_buf;
197 		}
198 
199 		if (fbpath)
200 			break;
201 	}
202 
203 	if (dip_pseudo != NULL)
204 		ddi_release_devi(dip_pseudo);
205 
206 	/* No screen found */
207 	return (fbpath);
208 }
209 
210 char *
211 plat_mousepath(void)
212 {
213 	/*
214 	 * Hardcode to isa mouse path
215 	 * XXX make it settable via bootprop?
216 	 */
217 	return ("/isa/i8042@1,60/mouse@1");
218 }
219 
220 /* return path of first usb serial device */
221 static char *
222 plat_usbser_path(void)
223 {
224 	extern dev_info_t *usbser_first_device(void);
225 
226 	dev_info_t *us_dip;
227 	static char *us_path = NULL;
228 
229 	if (us_path)
230 		return (us_path);
231 
232 	us_dip = usbser_first_device();
233 	if (us_dip == NULL)
234 		return (NULL);
235 
236 	us_path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
237 	(void) ddi_pathname(us_dip, us_path);
238 	ndi_rele_devi(us_dip);	/* held from usbser_first_device */
239 	return (us_path);
240 }
241 
242 /*
243  * Lacking support for com2 and com3, if that matters.
244  * Another possible enhancement could be to use properties
245  * for the port mapping rather than simply hard-code them.
246  */
247 char *
248 plat_stdinpath(void)
249 {
250 	switch (console_type()) {
251 #if defined(__xpv)
252 	case CONS_HYPERVISOR:
253 		return ("/xpvd/xencons@0");
254 #endif /* __xpv */
255 	case CONS_TTYA:
256 		return ("/isa/asy@1,3f8:a");
257 	case CONS_TTYB:
258 		return ("/isa/asy@1,2f8:b");
259 	case CONS_USBSER:
260 		return (plat_usbser_path());
261 	case CONS_SCREEN:
262 	default:
263 		break;
264 	};
265 	return (plat_kbdpath());
266 }
267 
268 char *
269 plat_stdoutpath(void)
270 {
271 	switch (console_type()) {
272 #if defined(__xpv)
273 	case CONS_HYPERVISOR:
274 		return ("/xpvd/xencons@0");
275 #endif /* __xpv */
276 	case CONS_TTYA:
277 		return ("/isa/asy@1,3f8:a");
278 	case CONS_TTYB:
279 		return ("/isa/asy@1,2f8:b");
280 	case CONS_USBSER:
281 		return (plat_usbser_path());
282 	case CONS_SCREEN:
283 	default:
284 		break;
285 	};
286 	return (plat_fbpath());
287 }
288 
289 /*
290  * If VIS_PIXEL mode will be implemented on x86, these following
291  * functions should be re-considered. Now these functions are
292  * unused on x86.
293  */
294 void
295 plat_tem_get_inverses(int *inverse, int *inverse_screen)
296 {
297 	*inverse = 0;
298 	*inverse_screen = 0;
299 }
300 
301 void
302 plat_tem_get_prom_font_size(int *charheight, int *windowtop)
303 {
304 	*charheight = 0;
305 	*windowtop = 0;
306 }
307 
308 /*ARGSUSED*/
309 void
310 plat_tem_get_prom_size(size_t *height, size_t *width)
311 {
312 	panic("unimplemented at line %d of %s", __LINE__, __FILE__);
313 }
314 
315 void
316 plat_tem_hide_prom_cursor(void)
317 {
318 	panic("unimplemented at line %d of %s", __LINE__, __FILE__);
319 }
320 
321 /*ARGSUSED*/
322 void
323 plat_tem_get_prom_pos(uint32_t *row, uint32_t *col)
324 {
325 	panic("unimplemented at line %d of %s", __LINE__, __FILE__);
326 }
327