xref: /titanic_41/usr/src/uts/i86pc/io/consplat.c (revision 8275a87e46b79352e8c1a918b91373159c477438)
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 
48 /* The names of currently supported graphics drivers on x86 */
49 static char *
50 gfxdrv_name[] = {
51 	"vgatext",
52 	"i915",
53 	"nvidia"
54 };
55 
56 int
57 plat_use_polled_debug() {
58 	return (0);
59 }
60 
61 int
62 plat_support_serial_kbd_and_ms() {
63 	return (0);
64 }
65 
66 #define	CONS_INVALID	-1
67 #define	CONS_SCREEN	0
68 #define	CONS_TTYA	1
69 #define	CONS_TTYB	2
70 #define	CONS_USBSER	3
71 
72 static int
73 console_type()
74 {
75 	static int boot_console = CONS_INVALID;
76 
77 	char *cons;
78 	dev_info_t *root;
79 
80 	if (boot_console != CONS_INVALID)
81 		return (boot_console);
82 
83 	/*
84 	 * console is defined by "console" property, with
85 	 * fallback on the old "input-device" property.
86 	 */
87 	boot_console = CONS_SCREEN;	/* default is screen/kb */
88 	root = ddi_root_node();
89 	if ((ddi_prop_lookup_string(DDI_DEV_T_ANY, root,
90 	    DDI_PROP_DONTPASS, "console", &cons) == DDI_SUCCESS) ||
91 	    (ddi_prop_lookup_string(DDI_DEV_T_ANY, root,
92 	    DDI_PROP_DONTPASS, "input-device", &cons) == DDI_SUCCESS)) {
93 		if (strcmp(cons, "ttya") == 0)
94 			boot_console = CONS_TTYA;
95 		else if (strcmp(cons, "ttyb") == 0)
96 			boot_console = CONS_TTYB;
97 		else if (strcmp(cons, "usb-serial") == 0) {
98 			(void) i_ddi_attach_hw_nodes("ehci");
99 			(void) i_ddi_attach_hw_nodes("uhci");
100 			(void) i_ddi_attach_hw_nodes("ohci");
101 			/*
102 			 * USB device enumerate asynchronously.
103 			 * Wait 2 seconds for USB serial devices to attach.
104 			 */
105 			delay(drv_usectohz(2000000));
106 			boot_console = CONS_USBSER;
107 		}
108 		ddi_prop_free(cons);
109 	}
110 	return (boot_console);
111 }
112 
113 int
114 plat_stdin_is_keyboard(void)
115 {
116 	return (console_type() == CONS_SCREEN);
117 }
118 
119 int
120 plat_stdout_is_framebuffer(void)
121 {
122 	return (console_type() == CONS_SCREEN);
123 }
124 
125 /*
126  * Return generic path to keyboard device from the alias.
127  */
128 char *
129 plat_kbdpath(void)
130 {
131 	/*
132 	 * Hardcode to isa keyboard path
133 	 * XXX make it settable via bootprop?
134 	 */
135 	return ("/isa/i8042@1,60/keyboard@0");
136 }
137 
138 /*
139  * Return generic path to display device from the alias.
140  */
141 char *
142 plat_fbpath(void)
143 {
144 	static char *fbpath = NULL;
145 	static char fbpath_buf[MAXPATHLEN];
146 	major_t major;
147 	dev_info_t *dip;
148 	int i;
149 
150 	for (i = 0; i < (sizeof (gfxdrv_name) / sizeof (char *)); i++) {
151 		/*
152 		 * look for first instance of each driver
153 		 */
154 		major = ddi_name_to_major(gfxdrv_name[i]);
155 		if (major != (major_t)-1) {
156 			dip = devnamesp[major].dn_head;
157 			if (dip &&
158 			    i_ddi_attach_node_hierarchy(dip) == DDI_SUCCESS) {
159 				(void) ddi_pathname(dip, fbpath_buf);
160 				fbpath = fbpath_buf;
161 			}
162 		}
163 
164 		if (fbpath)
165 			return (fbpath);
166 	}
167 
168 	/* No screen found */
169 	return (NULL);
170 }
171 
172 char *
173 plat_mousepath(void)
174 {
175 	/*
176 	 * Hardcode to isa mouse path
177 	 * XXX make it settable via bootprop?
178 	 */
179 	return ("/isa/i8042@1,60/mouse@1");
180 }
181 
182 /* return path of first usb serial device */
183 static char *
184 plat_usbser_path(void)
185 {
186 	extern dev_info_t *usbser_first_device(void);
187 
188 	dev_info_t *us_dip;
189 	static char *us_path = NULL;
190 
191 	if (us_path)
192 		return (us_path);
193 
194 	us_dip = usbser_first_device();
195 	if (us_dip == NULL)
196 		return (NULL);
197 
198 	us_path = kmem_alloc(MAXPATHLEN, KM_SLEEP);
199 	(void) ddi_pathname(us_dip, us_path);
200 	ndi_rele_devi(us_dip);	/* held from usbser_first_device */
201 	return (us_path);
202 }
203 
204 /*
205  * Lacking support for com2 and com3, if that matters.
206  * Another possible enhancement could be to use properties
207  * for the port mapping rather than simply hard-code them.
208  */
209 char *
210 plat_stdinpath(void)
211 {
212 	switch (console_type()) {
213 	case CONS_TTYA:
214 		return ("/isa/asy@1,3f8:a");
215 	case CONS_TTYB:
216 		return ("/isa/asy@1,2f8:b");
217 	case CONS_USBSER:
218 		return (plat_usbser_path());
219 	case CONS_SCREEN:
220 	default:
221 		break;
222 	};
223 	return (plat_kbdpath());
224 }
225 
226 char *
227 plat_stdoutpath(void)
228 {
229 	switch (console_type()) {
230 	case CONS_TTYA:
231 		return ("/isa/asy@1,3f8:a");
232 	case CONS_TTYB:
233 		return ("/isa/asy@1,2f8:b");
234 	case CONS_USBSER:
235 		return (plat_usbser_path());
236 	case CONS_SCREEN:
237 	default:
238 		break;
239 	};
240 	return (plat_fbpath());
241 }
242 
243 /*
244  * If VIS_PIXEL mode will be implemented on x86, these following
245  * functions should be re-considered. Now these functions are
246  * unused on x86.
247  */
248 void
249 plat_tem_get_inverses(int *inverse, int *inverse_screen)
250 {
251 	*inverse = 0;
252 	*inverse_screen = 0;
253 }
254 
255 void
256 plat_tem_get_prom_font_size(int *charheight, int *windowtop)
257 {
258 	*charheight = 0;
259 	*windowtop = 0;
260 }
261 
262 void
263 plat_tem_get_prom_size(size_t *height, size_t *width)
264 {
265 	*height = 25;
266 	*width = 80;
267 }
268 
269 void
270 plat_tem_hide_prom_cursor(void)
271 {
272 }
273 
274 void
275 plat_tem_get_prom_pos(uint32_t *row, uint32_t *col)
276 {
277 	*row = 0;
278 	*col = 0;
279 }
280