17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5fea9cb91Slq150181 * Common Development and Distribution License (the "License"). 6fea9cb91Slq150181 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21fea9cb91Slq150181 227c478bd9Sstevel@tonic-gate /* 23*1b83305cSjm22469 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * isa-specific console configuration routines 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/param.h> 357c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 367c478bd9Sstevel@tonic-gate #include <sys/systm.h> 377c478bd9Sstevel@tonic-gate #include <sys/conf.h> 387c478bd9Sstevel@tonic-gate #include <sys/debug.h> 397c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 407c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 417c478bd9Sstevel@tonic-gate #include <sys/esunddi.h> 427c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 437c478bd9Sstevel@tonic-gate #include <sys/promif.h> 447c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 457c478bd9Sstevel@tonic-gate #include <sys/termios.h> 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate extern char *get_alias(char *alias, char *buf); 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate extern int polled_debug; 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate int 527c478bd9Sstevel@tonic-gate plat_use_polled_debug() 537c478bd9Sstevel@tonic-gate { 547c478bd9Sstevel@tonic-gate return (polled_debug); 557c478bd9Sstevel@tonic-gate } 567c478bd9Sstevel@tonic-gate 577c478bd9Sstevel@tonic-gate int 587c478bd9Sstevel@tonic-gate plat_support_serial_kbd_and_ms() 597c478bd9Sstevel@tonic-gate { 607c478bd9Sstevel@tonic-gate return (1); 617c478bd9Sstevel@tonic-gate } 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * Return generic path to keyboard device from the alias. 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate char * 677c478bd9Sstevel@tonic-gate plat_kbdpath(void) 687c478bd9Sstevel@tonic-gate { 697c478bd9Sstevel@tonic-gate static char *kbdpath = NULL; 707c478bd9Sstevel@tonic-gate static char buf[MAXPATHLEN]; 717c478bd9Sstevel@tonic-gate char *path; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate if (kbdpath != NULL) 747c478bd9Sstevel@tonic-gate return (kbdpath); 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* 777c478bd9Sstevel@tonic-gate * look for the keyboard property in /aliases 787c478bd9Sstevel@tonic-gate * The keyboard alias is required on 1275 systems 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate path = get_alias("keyboard", buf); 817c478bd9Sstevel@tonic-gate if (path != NULL) { 827c478bd9Sstevel@tonic-gate kbdpath = path; 837c478bd9Sstevel@tonic-gate return (path); 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate return (NULL); 877c478bd9Sstevel@tonic-gate } 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* 907c478bd9Sstevel@tonic-gate * Return generic path to display device from the alias. 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate char * 937c478bd9Sstevel@tonic-gate plat_fbpath(void) 947c478bd9Sstevel@tonic-gate { 957c478bd9Sstevel@tonic-gate static char *fbpath = NULL; 967c478bd9Sstevel@tonic-gate static char buf[MAXPATHLEN]; 977c478bd9Sstevel@tonic-gate char *path; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate if (fbpath != NULL) 1007c478bd9Sstevel@tonic-gate return (fbpath); 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate /* look for the screen property in /aliases */ 1037c478bd9Sstevel@tonic-gate path = get_alias("screen", buf); 1047c478bd9Sstevel@tonic-gate if (path != NULL) { 1057c478bd9Sstevel@tonic-gate fbpath = path; 1067c478bd9Sstevel@tonic-gate return (path); 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate return (NULL); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate char * 1137c478bd9Sstevel@tonic-gate plat_mousepath(void) 1147c478bd9Sstevel@tonic-gate { 1157c478bd9Sstevel@tonic-gate static char *mousepath = NULL; 1167c478bd9Sstevel@tonic-gate static char buf[MAXPATHLEN]; 1177c478bd9Sstevel@tonic-gate char *path, *p, *q; 1187c478bd9Sstevel@tonic-gate major_t zs_major, kb_major; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate if (mousepath != NULL) 1217c478bd9Sstevel@tonic-gate return (mousepath); 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* look for the mouse property in /aliases */ 1247c478bd9Sstevel@tonic-gate path = get_alias("mouse", buf); 1257c478bd9Sstevel@tonic-gate if (path != NULL) { 1267c478bd9Sstevel@tonic-gate mousepath = path; 1277c478bd9Sstevel@tonic-gate return (path); 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate if (!plat_support_serial_kbd_and_ms()) 1317c478bd9Sstevel@tonic-gate return (NULL); 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate if ((zs_major = mod_name_to_major("zs")) == -1) 1347c478bd9Sstevel@tonic-gate return (NULL); 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate if ((path = plat_kbdpath()) == NULL) 1377c478bd9Sstevel@tonic-gate return (NULL); 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate if ((kb_major = path_to_major(path)) == (major_t)-1) 1407c478bd9Sstevel@tonic-gate return (NULL); 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate if (zs_major != kb_major) 1437c478bd9Sstevel@tonic-gate return (NULL); 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * If we didn't find the mouse property and we're on an OBP 1477c478bd9Sstevel@tonic-gate * system with a 'zs' port keyboard/mouse duart then the mouse 1487c478bd9Sstevel@tonic-gate * is the 'b' channel of the keyboard duart. Change :a to :b 1497c478bd9Sstevel@tonic-gate * or append :b to the last component of the path. 1507c478bd9Sstevel@tonic-gate * (It's still canonical without :a) 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate (void) strcpy(buf, path); 1537c478bd9Sstevel@tonic-gate p = (strrchr(buf, '/')); /* p points to last comp. */ 1547c478bd9Sstevel@tonic-gate if (p != NULL) { 1557c478bd9Sstevel@tonic-gate q = strchr(p, ':'); 1567c478bd9Sstevel@tonic-gate if (q != 0) 1577c478bd9Sstevel@tonic-gate *q = (char)0; /* Replace or append options */ 1587c478bd9Sstevel@tonic-gate (void) strcat(p, ":b"); 1597c478bd9Sstevel@tonic-gate mousepath = buf; 1607c478bd9Sstevel@tonic-gate return (mousepath); 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate return (NULL); 1637c478bd9Sstevel@tonic-gate } 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate char * 1667c478bd9Sstevel@tonic-gate plat_stdinpath(void) 1677c478bd9Sstevel@tonic-gate { 1687c478bd9Sstevel@tonic-gate return (prom_stdinpath()); 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate char * 1727c478bd9Sstevel@tonic-gate plat_stdoutpath(void) 1737c478bd9Sstevel@tonic-gate { 1747c478bd9Sstevel@tonic-gate static char *outpath; 1757c478bd9Sstevel@tonic-gate static char buf[MAXPATHLEN]; 1767c478bd9Sstevel@tonic-gate char *p; 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate if (outpath != NULL) 1797c478bd9Sstevel@tonic-gate return (outpath); 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate p = prom_stdoutpath(); 1827c478bd9Sstevel@tonic-gate if (p == NULL) 1837c478bd9Sstevel@tonic-gate return (NULL); 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* 1867c478bd9Sstevel@tonic-gate * If the output device is a framebuffer, we don't 1877c478bd9Sstevel@tonic-gate * care about monitor resolution options strings. 1887c478bd9Sstevel@tonic-gate * In fact, we can't handle them at all, so strip them. 1897c478bd9Sstevel@tonic-gate */ 1907c478bd9Sstevel@tonic-gate if (prom_stdout_is_framebuffer()) { 1917c478bd9Sstevel@tonic-gate prom_strip_options(p, buf); 1927c478bd9Sstevel@tonic-gate p = buf; 1937c478bd9Sstevel@tonic-gate } 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate outpath = p; 1967c478bd9Sstevel@tonic-gate return (outpath); 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate int 2007c478bd9Sstevel@tonic-gate plat_stdin_is_keyboard(void) 2017c478bd9Sstevel@tonic-gate { 2027c478bd9Sstevel@tonic-gate return (prom_stdin_is_keyboard()); 2037c478bd9Sstevel@tonic-gate } 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate int 2067c478bd9Sstevel@tonic-gate plat_stdout_is_framebuffer(void) 2077c478bd9Sstevel@tonic-gate { 2087c478bd9Sstevel@tonic-gate return (prom_stdout_is_framebuffer()); 2097c478bd9Sstevel@tonic-gate } 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate void 2127c478bd9Sstevel@tonic-gate kadb_uses_kernel() 2137c478bd9Sstevel@tonic-gate { 2147c478bd9Sstevel@tonic-gate /* only used on intel */ 2157c478bd9Sstevel@tonic-gate } 216fea9cb91Slq150181 217fea9cb91Slq150181 void 218c9503a49Slq150181 plat_tem_get_inverses(int *inverse, int *inverse_screen) 219c9503a49Slq150181 { 220c9503a49Slq150181 prom_get_tem_inverses(inverse, inverse_screen); 221c9503a49Slq150181 } 222c9503a49Slq150181 223c9503a49Slq150181 void 224fea9cb91Slq150181 plat_tem_get_prom_font_size(int *charheight, int *windowtop) 225fea9cb91Slq150181 { 226fea9cb91Slq150181 prom_get_term_font_size(charheight, windowtop); 227fea9cb91Slq150181 } 228fea9cb91Slq150181 229fea9cb91Slq150181 void 230fea9cb91Slq150181 plat_tem_get_prom_size(size_t *height, size_t *width) 231fea9cb91Slq150181 { 232fea9cb91Slq150181 prom_get_tem_size(height, width); 233fea9cb91Slq150181 } 234fea9cb91Slq150181 235fea9cb91Slq150181 void 236fea9cb91Slq150181 plat_tem_hide_prom_cursor(void) 237fea9cb91Slq150181 { 238fea9cb91Slq150181 prom_hide_cursor(); 239fea9cb91Slq150181 } 240fea9cb91Slq150181 241fea9cb91Slq150181 void 242fea9cb91Slq150181 plat_tem_get_prom_pos(uint32_t *row, uint32_t *col) 243fea9cb91Slq150181 { 244fea9cb91Slq150181 prom_get_tem_pos(row, col); 245fea9cb91Slq150181 } 246*1b83305cSjm22469 247*1b83305cSjm22469 /* 248*1b83305cSjm22469 * Find the path of the virtual console (if available on the 249*1b83305cSjm22469 * current architecture). 250*1b83305cSjm22469 * 251*1b83305cSjm22469 * Returns: -1 if not found, else actual path length. 252*1b83305cSjm22469 */ 253*1b83305cSjm22469 int 254*1b83305cSjm22469 plat_virtual_console_path(char **bufp) 255*1b83305cSjm22469 { 256*1b83305cSjm22469 pnode_t pnode; 257*1b83305cSjm22469 int buflen; 258*1b83305cSjm22469 static char buf[OBP_MAXPATHLEN]; 259*1b83305cSjm22469 260*1b83305cSjm22469 pnode = prom_finddevice("/virtual-devices/console"); 261*1b83305cSjm22469 262*1b83305cSjm22469 if (pnode == OBP_BADNODE) 263*1b83305cSjm22469 return (-1); 264*1b83305cSjm22469 265*1b83305cSjm22469 if ((buflen = prom_phandle_to_path(pnode, buf, sizeof (buf))) < 0) 266*1b83305cSjm22469 return (-1); 267*1b83305cSjm22469 268*1b83305cSjm22469 *bufp = buf; 269*1b83305cSjm22469 270*1b83305cSjm22469 return (buflen); 271*1b83305cSjm22469 } 272