10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51253Slq150181 * Common Development and Distribution License (the "License").
61253Slq150181 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211253Slq150181
220Sstevel@tonic-gate /*
23*5974Sjm22469 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * isa-specific console configuration routines
310Sstevel@tonic-gate */
320Sstevel@tonic-gate
330Sstevel@tonic-gate #include <sys/types.h>
340Sstevel@tonic-gate #include <sys/param.h>
350Sstevel@tonic-gate #include <sys/cmn_err.h>
360Sstevel@tonic-gate #include <sys/systm.h>
370Sstevel@tonic-gate #include <sys/conf.h>
380Sstevel@tonic-gate #include <sys/debug.h>
390Sstevel@tonic-gate #include <sys/ddi.h>
400Sstevel@tonic-gate #include <sys/sunddi.h>
410Sstevel@tonic-gate #include <sys/esunddi.h>
420Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
430Sstevel@tonic-gate #include <sys/promif.h>
440Sstevel@tonic-gate #include <sys/modctl.h>
450Sstevel@tonic-gate #include <sys/termios.h>
460Sstevel@tonic-gate
470Sstevel@tonic-gate extern char *get_alias(char *alias, char *buf);
480Sstevel@tonic-gate
490Sstevel@tonic-gate extern int polled_debug;
500Sstevel@tonic-gate
510Sstevel@tonic-gate int
plat_use_polled_debug()520Sstevel@tonic-gate plat_use_polled_debug()
530Sstevel@tonic-gate {
540Sstevel@tonic-gate return (polled_debug);
550Sstevel@tonic-gate }
560Sstevel@tonic-gate
570Sstevel@tonic-gate int
plat_support_serial_kbd_and_ms()580Sstevel@tonic-gate plat_support_serial_kbd_and_ms()
590Sstevel@tonic-gate {
600Sstevel@tonic-gate return (1);
610Sstevel@tonic-gate }
620Sstevel@tonic-gate
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate * Return generic path to keyboard device from the alias.
650Sstevel@tonic-gate */
660Sstevel@tonic-gate char *
plat_kbdpath(void)670Sstevel@tonic-gate plat_kbdpath(void)
680Sstevel@tonic-gate {
690Sstevel@tonic-gate static char *kbdpath = NULL;
700Sstevel@tonic-gate static char buf[MAXPATHLEN];
710Sstevel@tonic-gate char *path;
720Sstevel@tonic-gate
730Sstevel@tonic-gate if (kbdpath != NULL)
740Sstevel@tonic-gate return (kbdpath);
750Sstevel@tonic-gate
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate * look for the keyboard property in /aliases
780Sstevel@tonic-gate * The keyboard alias is required on 1275 systems
790Sstevel@tonic-gate */
800Sstevel@tonic-gate path = get_alias("keyboard", buf);
810Sstevel@tonic-gate if (path != NULL) {
820Sstevel@tonic-gate kbdpath = path;
830Sstevel@tonic-gate return (path);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate
860Sstevel@tonic-gate return (NULL);
870Sstevel@tonic-gate }
880Sstevel@tonic-gate
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate * Return generic path to display device from the alias.
910Sstevel@tonic-gate */
920Sstevel@tonic-gate char *
plat_fbpath(void)930Sstevel@tonic-gate plat_fbpath(void)
940Sstevel@tonic-gate {
950Sstevel@tonic-gate static char *fbpath = NULL;
960Sstevel@tonic-gate static char buf[MAXPATHLEN];
970Sstevel@tonic-gate char *path;
980Sstevel@tonic-gate
990Sstevel@tonic-gate if (fbpath != NULL)
1000Sstevel@tonic-gate return (fbpath);
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate /* look for the screen property in /aliases */
1030Sstevel@tonic-gate path = get_alias("screen", buf);
1040Sstevel@tonic-gate if (path != NULL) {
1050Sstevel@tonic-gate fbpath = path;
1060Sstevel@tonic-gate return (path);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate return (NULL);
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate char *
plat_mousepath(void)1130Sstevel@tonic-gate plat_mousepath(void)
1140Sstevel@tonic-gate {
1150Sstevel@tonic-gate static char *mousepath = NULL;
1160Sstevel@tonic-gate static char buf[MAXPATHLEN];
1170Sstevel@tonic-gate char *path, *p, *q;
1180Sstevel@tonic-gate major_t zs_major, kb_major;
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate if (mousepath != NULL)
1210Sstevel@tonic-gate return (mousepath);
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate /* look for the mouse property in /aliases */
1240Sstevel@tonic-gate path = get_alias("mouse", buf);
1250Sstevel@tonic-gate if (path != NULL) {
1260Sstevel@tonic-gate mousepath = path;
1270Sstevel@tonic-gate return (path);
1280Sstevel@tonic-gate }
1290Sstevel@tonic-gate
1300Sstevel@tonic-gate if (!plat_support_serial_kbd_and_ms())
1310Sstevel@tonic-gate return (NULL);
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate if ((zs_major = mod_name_to_major("zs")) == -1)
1340Sstevel@tonic-gate return (NULL);
1350Sstevel@tonic-gate
1360Sstevel@tonic-gate if ((path = plat_kbdpath()) == NULL)
1370Sstevel@tonic-gate return (NULL);
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate if ((kb_major = path_to_major(path)) == (major_t)-1)
1400Sstevel@tonic-gate return (NULL);
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate if (zs_major != kb_major)
1430Sstevel@tonic-gate return (NULL);
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate /*
1460Sstevel@tonic-gate * If we didn't find the mouse property and we're on an OBP
1470Sstevel@tonic-gate * system with a 'zs' port keyboard/mouse duart then the mouse
1480Sstevel@tonic-gate * is the 'b' channel of the keyboard duart. Change :a to :b
1490Sstevel@tonic-gate * or append :b to the last component of the path.
1500Sstevel@tonic-gate * (It's still canonical without :a)
1510Sstevel@tonic-gate */
1520Sstevel@tonic-gate (void) strcpy(buf, path);
1530Sstevel@tonic-gate p = (strrchr(buf, '/')); /* p points to last comp. */
1540Sstevel@tonic-gate if (p != NULL) {
1550Sstevel@tonic-gate q = strchr(p, ':');
1560Sstevel@tonic-gate if (q != 0)
1570Sstevel@tonic-gate *q = (char)0; /* Replace or append options */
1580Sstevel@tonic-gate (void) strcat(p, ":b");
1590Sstevel@tonic-gate mousepath = buf;
1600Sstevel@tonic-gate return (mousepath);
1610Sstevel@tonic-gate }
1620Sstevel@tonic-gate return (NULL);
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate char *
plat_stdinpath(void)1660Sstevel@tonic-gate plat_stdinpath(void)
1670Sstevel@tonic-gate {
1680Sstevel@tonic-gate return (prom_stdinpath());
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate char *
plat_stdoutpath(void)1720Sstevel@tonic-gate plat_stdoutpath(void)
1730Sstevel@tonic-gate {
1740Sstevel@tonic-gate static char *outpath;
1750Sstevel@tonic-gate static char buf[MAXPATHLEN];
1760Sstevel@tonic-gate char *p;
1770Sstevel@tonic-gate
1780Sstevel@tonic-gate if (outpath != NULL)
1790Sstevel@tonic-gate return (outpath);
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate p = prom_stdoutpath();
1820Sstevel@tonic-gate if (p == NULL)
1830Sstevel@tonic-gate return (NULL);
1840Sstevel@tonic-gate
1850Sstevel@tonic-gate /*
1860Sstevel@tonic-gate * If the output device is a framebuffer, we don't
1870Sstevel@tonic-gate * care about monitor resolution options strings.
1880Sstevel@tonic-gate * In fact, we can't handle them at all, so strip them.
1890Sstevel@tonic-gate */
1900Sstevel@tonic-gate if (prom_stdout_is_framebuffer()) {
1910Sstevel@tonic-gate prom_strip_options(p, buf);
1920Sstevel@tonic-gate p = buf;
1930Sstevel@tonic-gate }
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate outpath = p;
1960Sstevel@tonic-gate return (outpath);
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate int
plat_stdin_is_keyboard(void)2000Sstevel@tonic-gate plat_stdin_is_keyboard(void)
2010Sstevel@tonic-gate {
2020Sstevel@tonic-gate return (prom_stdin_is_keyboard());
2030Sstevel@tonic-gate }
2040Sstevel@tonic-gate
2050Sstevel@tonic-gate int
plat_stdout_is_framebuffer(void)2060Sstevel@tonic-gate plat_stdout_is_framebuffer(void)
2070Sstevel@tonic-gate {
2080Sstevel@tonic-gate return (prom_stdout_is_framebuffer());
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate void
kadb_uses_kernel()2120Sstevel@tonic-gate kadb_uses_kernel()
2130Sstevel@tonic-gate {
2140Sstevel@tonic-gate /* only used on intel */
2150Sstevel@tonic-gate }
2161253Slq150181
2171253Slq150181 void
plat_tem_get_inverses(int * inverse,int * inverse_screen)2183994Slq150181 plat_tem_get_inverses(int *inverse, int *inverse_screen)
2193994Slq150181 {
2203994Slq150181 prom_get_tem_inverses(inverse, inverse_screen);
2213994Slq150181 }
2223994Slq150181
2233994Slq150181 void
plat_tem_get_prom_font_size(int * charheight,int * windowtop)2241253Slq150181 plat_tem_get_prom_font_size(int *charheight, int *windowtop)
2251253Slq150181 {
2261253Slq150181 prom_get_term_font_size(charheight, windowtop);
2271253Slq150181 }
2281253Slq150181
2291253Slq150181 void
plat_tem_get_prom_size(size_t * height,size_t * width)2301253Slq150181 plat_tem_get_prom_size(size_t *height, size_t *width)
2311253Slq150181 {
2321253Slq150181 prom_get_tem_size(height, width);
2331253Slq150181 }
2341253Slq150181
2351253Slq150181 void
plat_tem_hide_prom_cursor(void)2361253Slq150181 plat_tem_hide_prom_cursor(void)
2371253Slq150181 {
2381253Slq150181 prom_hide_cursor();
2391253Slq150181 }
2401253Slq150181
2411253Slq150181 void
plat_tem_get_prom_pos(uint32_t * row,uint32_t * col)2421253Slq150181 plat_tem_get_prom_pos(uint32_t *row, uint32_t *col)
2431253Slq150181 {
2441253Slq150181 prom_get_tem_pos(row, col);
2451253Slq150181 }
246*5974Sjm22469
247*5974Sjm22469 /*
248*5974Sjm22469 * Find the path of the virtual console (if available on the
249*5974Sjm22469 * current architecture).
250*5974Sjm22469 *
251*5974Sjm22469 * Returns: -1 if not found, else actual path length.
252*5974Sjm22469 */
253*5974Sjm22469 int
plat_virtual_console_path(char ** bufp)254*5974Sjm22469 plat_virtual_console_path(char **bufp)
255*5974Sjm22469 {
256*5974Sjm22469 pnode_t pnode;
257*5974Sjm22469 int buflen;
258*5974Sjm22469 static char buf[OBP_MAXPATHLEN];
259*5974Sjm22469
260*5974Sjm22469 pnode = prom_finddevice("/virtual-devices/console");
261*5974Sjm22469
262*5974Sjm22469 if (pnode == OBP_BADNODE)
263*5974Sjm22469 return (-1);
264*5974Sjm22469
265*5974Sjm22469 if ((buflen = prom_phandle_to_path(pnode, buf, sizeof (buf))) < 0)
266*5974Sjm22469 return (-1);
267*5974Sjm22469
268*5974Sjm22469 *bufp = buf;
269*5974Sjm22469
270*5974Sjm22469 return (buflen);
271*5974Sjm22469 }
272