xref: /illumos-gate/usr/src/uts/sparc/io/consplat.c (revision 1b83305c)
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/esunddi.h>
42 #include <sys/ddi_impldefs.h>
43 #include <sys/promif.h>
44 #include <sys/modctl.h>
45 #include <sys/termios.h>
46 
47 extern char *get_alias(char *alias, char *buf);
48 
49 extern int polled_debug;
50 
51 int
52 plat_use_polled_debug()
53 {
54 	return (polled_debug);
55 }
56 
57 int
58 plat_support_serial_kbd_and_ms()
59 {
60 	return (1);
61 }
62 
63 /*
64  * Return generic path to keyboard device from the alias.
65  */
66 char *
67 plat_kbdpath(void)
68 {
69 	static char *kbdpath = NULL;
70 	static char buf[MAXPATHLEN];
71 	char *path;
72 
73 	if (kbdpath != NULL)
74 		return (kbdpath);
75 
76 	/*
77 	 * look for the keyboard property in /aliases
78 	 * The keyboard alias is required on 1275 systems
79 	 */
80 	path = get_alias("keyboard", buf);
81 	if (path != NULL) {
82 		kbdpath = path;
83 		return (path);
84 	}
85 
86 	return (NULL);
87 }
88 
89 /*
90  * Return generic path to display device from the alias.
91  */
92 char *
93 plat_fbpath(void)
94 {
95 	static char *fbpath = NULL;
96 	static char buf[MAXPATHLEN];
97 	char *path;
98 
99 	if (fbpath != NULL)
100 		return (fbpath);
101 
102 	/* look for the screen property in /aliases */
103 	path = get_alias("screen", buf);
104 	if (path != NULL) {
105 		fbpath = path;
106 		return (path);
107 	}
108 
109 	return (NULL);
110 }
111 
112 char *
113 plat_mousepath(void)
114 {
115 	static char 	*mousepath = NULL;
116 	static char 	buf[MAXPATHLEN];
117 	char 		*path, *p, *q;
118 	major_t		zs_major, kb_major;
119 
120 	if (mousepath != NULL)
121 		return (mousepath);
122 
123 	/* look for the mouse property in /aliases */
124 	path = get_alias("mouse", buf);
125 	if (path != NULL) {
126 		mousepath = path;
127 		return (path);
128 	}
129 
130 	if (!plat_support_serial_kbd_and_ms())
131 		return (NULL);
132 
133 	if ((zs_major = mod_name_to_major("zs")) == -1)
134 		return (NULL);
135 
136 	if ((path = plat_kbdpath()) == NULL)
137 		return (NULL);
138 
139 	if ((kb_major = path_to_major(path)) == (major_t)-1)
140 		return (NULL);
141 
142 	if (zs_major != kb_major)
143 		return (NULL);
144 
145 	/*
146 	 * If we didn't find the mouse property and we're on an OBP
147 	 * system with a 'zs' port keyboard/mouse duart then the mouse
148 	 * is the 'b' channel of the keyboard duart. Change :a to :b
149 	 * or append :b to the last component of the path.
150 	 * (It's still canonical without :a)
151 	 */
152 	(void) strcpy(buf, path);
153 	p = (strrchr(buf, '/'));	/* p points to last comp. */
154 	if (p != NULL) {
155 		q = strchr(p, ':');
156 		if (q != 0)
157 			*q = (char)0;	/* Replace or append options */
158 		(void) strcat(p, ":b");
159 		mousepath = buf;
160 		return (mousepath);
161 	}
162 	return (NULL);
163 }
164 
165 char *
166 plat_stdinpath(void)
167 {
168 	return (prom_stdinpath());
169 }
170 
171 char *
172 plat_stdoutpath(void)
173 {
174 	static char *outpath;
175 	static char buf[MAXPATHLEN];
176 	char *p;
177 
178 	if (outpath != NULL)
179 		return (outpath);
180 
181 	p = prom_stdoutpath();
182 	if (p == NULL)
183 		return (NULL);
184 
185 	/*
186 	 * If the output device is a framebuffer, we don't
187 	 * care about monitor resolution options strings.
188 	 * In fact, we can't handle them at all, so strip them.
189 	 */
190 	if (prom_stdout_is_framebuffer()) {
191 		prom_strip_options(p, buf);
192 		p = buf;
193 	}
194 
195 	outpath = p;
196 	return (outpath);
197 }
198 
199 int
200 plat_stdin_is_keyboard(void)
201 {
202 	return (prom_stdin_is_keyboard());
203 }
204 
205 int
206 plat_stdout_is_framebuffer(void)
207 {
208 	return (prom_stdout_is_framebuffer());
209 }
210 
211 void
212 kadb_uses_kernel()
213 {
214 	/* only used on intel */
215 }
216 
217 void
218 plat_tem_get_inverses(int *inverse, int *inverse_screen)
219 {
220 	prom_get_tem_inverses(inverse, inverse_screen);
221 }
222 
223 void
224 plat_tem_get_prom_font_size(int *charheight, int *windowtop)
225 {
226 	prom_get_term_font_size(charheight, windowtop);
227 }
228 
229 void
230 plat_tem_get_prom_size(size_t *height, size_t *width)
231 {
232 	prom_get_tem_size(height, width);
233 }
234 
235 void
236 plat_tem_hide_prom_cursor(void)
237 {
238 	prom_hide_cursor();
239 }
240 
241 void
242 plat_tem_get_prom_pos(uint32_t *row, uint32_t *col)
243 {
244 	prom_get_tem_pos(row, col);
245 }
246 
247 /*
248  * Find the path of the virtual console (if available on the
249  * current architecture).
250  *
251  * Returns: -1 if not found, else actual path length.
252  */
253 int
254 plat_virtual_console_path(char **bufp)
255 {
256 	pnode_t		pnode;
257 	int		buflen;
258 	static char	buf[OBP_MAXPATHLEN];
259 
260 	pnode = prom_finddevice("/virtual-devices/console");
261 
262 	if (pnode == OBP_BADNODE)
263 		return (-1);
264 
265 	if ((buflen = prom_phandle_to_path(pnode, buf, sizeof (buf))) < 0)
266 		return (-1);
267 
268 	*bufp = buf;
269 
270 	return (buflen);
271 }
272