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 /*
231b83305cSjm22469 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
247c478bd9Sstevel@tonic-gate * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
27*1bc1e552SPeter Tribble /*
28*1bc1e552SPeter Tribble * Copyright 2019 Peter Tribble.
29*1bc1e552SPeter Tribble */
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate * isa-specific console configuration routines
337c478bd9Sstevel@tonic-gate */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include <sys/types.h>
367c478bd9Sstevel@tonic-gate #include <sys/param.h>
377c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
387c478bd9Sstevel@tonic-gate #include <sys/systm.h>
397c478bd9Sstevel@tonic-gate #include <sys/conf.h>
407c478bd9Sstevel@tonic-gate #include <sys/debug.h>
417c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
427c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
437c478bd9Sstevel@tonic-gate #include <sys/esunddi.h>
447c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
457c478bd9Sstevel@tonic-gate #include <sys/promif.h>
467c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
477c478bd9Sstevel@tonic-gate #include <sys/termios.h>
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate extern char *get_alias(char *alias, char *buf);
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate extern int polled_debug;
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate int
plat_use_polled_debug()547c478bd9Sstevel@tonic-gate plat_use_polled_debug()
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate return (polled_debug);
577c478bd9Sstevel@tonic-gate }
587c478bd9Sstevel@tonic-gate
597c478bd9Sstevel@tonic-gate int
plat_support_serial_kbd_and_ms()607c478bd9Sstevel@tonic-gate plat_support_serial_kbd_and_ms()
617c478bd9Sstevel@tonic-gate {
627c478bd9Sstevel@tonic-gate return (1);
637c478bd9Sstevel@tonic-gate }
647c478bd9Sstevel@tonic-gate
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate * Return generic path to keyboard device from the alias.
677c478bd9Sstevel@tonic-gate */
687c478bd9Sstevel@tonic-gate char *
plat_kbdpath(void)697c478bd9Sstevel@tonic-gate plat_kbdpath(void)
707c478bd9Sstevel@tonic-gate {
717c478bd9Sstevel@tonic-gate static char *kbdpath = NULL;
727c478bd9Sstevel@tonic-gate static char buf[MAXPATHLEN];
737c478bd9Sstevel@tonic-gate char *path;
747c478bd9Sstevel@tonic-gate
757c478bd9Sstevel@tonic-gate if (kbdpath != NULL)
767c478bd9Sstevel@tonic-gate return (kbdpath);
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate * look for the keyboard property in /aliases
807c478bd9Sstevel@tonic-gate * The keyboard alias is required on 1275 systems
817c478bd9Sstevel@tonic-gate */
827c478bd9Sstevel@tonic-gate path = get_alias("keyboard", buf);
837c478bd9Sstevel@tonic-gate if (path != NULL) {
847c478bd9Sstevel@tonic-gate kbdpath = path;
857c478bd9Sstevel@tonic-gate return (path);
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate return (NULL);
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate * Return generic path to display device from the alias.
937c478bd9Sstevel@tonic-gate */
947c478bd9Sstevel@tonic-gate char *
plat_fbpath(void)957c478bd9Sstevel@tonic-gate plat_fbpath(void)
967c478bd9Sstevel@tonic-gate {
977c478bd9Sstevel@tonic-gate static char *fbpath = NULL;
987c478bd9Sstevel@tonic-gate static char buf[MAXPATHLEN];
997c478bd9Sstevel@tonic-gate char *path;
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate if (fbpath != NULL)
1027c478bd9Sstevel@tonic-gate return (fbpath);
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate /* look for the screen property in /aliases */
1057c478bd9Sstevel@tonic-gate path = get_alias("screen", buf);
1067c478bd9Sstevel@tonic-gate if (path != NULL) {
1077c478bd9Sstevel@tonic-gate fbpath = path;
1087c478bd9Sstevel@tonic-gate return (path);
1097c478bd9Sstevel@tonic-gate }
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate return (NULL);
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate char *
plat_mousepath(void)1157c478bd9Sstevel@tonic-gate plat_mousepath(void)
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate static char *mousepath = NULL;
1187c478bd9Sstevel@tonic-gate static char buf[MAXPATHLEN];
1197c478bd9Sstevel@tonic-gate char *path, *p, *q;
1207c478bd9Sstevel@tonic-gate major_t zs_major, kb_major;
1217c478bd9Sstevel@tonic-gate
1227c478bd9Sstevel@tonic-gate if (mousepath != NULL)
1237c478bd9Sstevel@tonic-gate return (mousepath);
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate /* look for the mouse property in /aliases */
1267c478bd9Sstevel@tonic-gate path = get_alias("mouse", buf);
1277c478bd9Sstevel@tonic-gate if (path != NULL) {
1287c478bd9Sstevel@tonic-gate mousepath = path;
1297c478bd9Sstevel@tonic-gate return (path);
1307c478bd9Sstevel@tonic-gate }
1317c478bd9Sstevel@tonic-gate
1327c478bd9Sstevel@tonic-gate if (!plat_support_serial_kbd_and_ms())
1337c478bd9Sstevel@tonic-gate return (NULL);
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate if ((zs_major = mod_name_to_major("zs")) == -1)
1367c478bd9Sstevel@tonic-gate return (NULL);
1377c478bd9Sstevel@tonic-gate
1387c478bd9Sstevel@tonic-gate if ((path = plat_kbdpath()) == NULL)
1397c478bd9Sstevel@tonic-gate return (NULL);
1407c478bd9Sstevel@tonic-gate
1417c478bd9Sstevel@tonic-gate if ((kb_major = path_to_major(path)) == (major_t)-1)
1427c478bd9Sstevel@tonic-gate return (NULL);
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate if (zs_major != kb_major)
1457c478bd9Sstevel@tonic-gate return (NULL);
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate /*
1487c478bd9Sstevel@tonic-gate * If we didn't find the mouse property and we're on an OBP
1497c478bd9Sstevel@tonic-gate * system with a 'zs' port keyboard/mouse duart then the mouse
1507c478bd9Sstevel@tonic-gate * is the 'b' channel of the keyboard duart. Change :a to :b
1517c478bd9Sstevel@tonic-gate * or append :b to the last component of the path.
1527c478bd9Sstevel@tonic-gate * (It's still canonical without :a)
1537c478bd9Sstevel@tonic-gate */
1547c478bd9Sstevel@tonic-gate (void) strcpy(buf, path);
1557c478bd9Sstevel@tonic-gate p = (strrchr(buf, '/')); /* p points to last comp. */
1567c478bd9Sstevel@tonic-gate if (p != NULL) {
1577c478bd9Sstevel@tonic-gate q = strchr(p, ':');
1587c478bd9Sstevel@tonic-gate if (q != 0)
1597c478bd9Sstevel@tonic-gate *q = (char)0; /* Replace or append options */
1607c478bd9Sstevel@tonic-gate (void) strcat(p, ":b");
1617c478bd9Sstevel@tonic-gate mousepath = buf;
1627c478bd9Sstevel@tonic-gate return (mousepath);
1637c478bd9Sstevel@tonic-gate }
1647c478bd9Sstevel@tonic-gate return (NULL);
1657c478bd9Sstevel@tonic-gate }
1667c478bd9Sstevel@tonic-gate
1677c478bd9Sstevel@tonic-gate char *
plat_stdinpath(void)1687c478bd9Sstevel@tonic-gate plat_stdinpath(void)
1697c478bd9Sstevel@tonic-gate {
1707c478bd9Sstevel@tonic-gate return (prom_stdinpath());
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate
1737c478bd9Sstevel@tonic-gate char *
plat_stdoutpath(void)1747c478bd9Sstevel@tonic-gate plat_stdoutpath(void)
1757c478bd9Sstevel@tonic-gate {
1767c478bd9Sstevel@tonic-gate static char *outpath;
1777c478bd9Sstevel@tonic-gate static char buf[MAXPATHLEN];
1787c478bd9Sstevel@tonic-gate char *p;
1797c478bd9Sstevel@tonic-gate
1807c478bd9Sstevel@tonic-gate if (outpath != NULL)
1817c478bd9Sstevel@tonic-gate return (outpath);
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate p = prom_stdoutpath();
1847c478bd9Sstevel@tonic-gate if (p == NULL)
1857c478bd9Sstevel@tonic-gate return (NULL);
1867c478bd9Sstevel@tonic-gate
1877c478bd9Sstevel@tonic-gate /*
1887c478bd9Sstevel@tonic-gate * If the output device is a framebuffer, we don't
1897c478bd9Sstevel@tonic-gate * care about monitor resolution options strings.
1907c478bd9Sstevel@tonic-gate * In fact, we can't handle them at all, so strip them.
1917c478bd9Sstevel@tonic-gate */
1927c478bd9Sstevel@tonic-gate if (prom_stdout_is_framebuffer()) {
1937c478bd9Sstevel@tonic-gate prom_strip_options(p, buf);
1947c478bd9Sstevel@tonic-gate p = buf;
1957c478bd9Sstevel@tonic-gate }
1967c478bd9Sstevel@tonic-gate
1977c478bd9Sstevel@tonic-gate outpath = p;
1987c478bd9Sstevel@tonic-gate return (outpath);
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate
201*1bc1e552SPeter Tribble /*
202*1bc1e552SPeter Tribble * stub definition for consconfig_dacf
203*1bc1e552SPeter Tribble */
204*1bc1e552SPeter Tribble char *
plat_diagpath(void)205*1bc1e552SPeter Tribble plat_diagpath(void)
206*1bc1e552SPeter Tribble {
207*1bc1e552SPeter Tribble return (NULL);
208*1bc1e552SPeter Tribble }
209*1bc1e552SPeter Tribble
2107c478bd9Sstevel@tonic-gate int
plat_stdin_is_keyboard(void)2117c478bd9Sstevel@tonic-gate plat_stdin_is_keyboard(void)
2127c478bd9Sstevel@tonic-gate {
2137c478bd9Sstevel@tonic-gate return (prom_stdin_is_keyboard());
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate int
plat_stdout_is_framebuffer(void)2177c478bd9Sstevel@tonic-gate plat_stdout_is_framebuffer(void)
2187c478bd9Sstevel@tonic-gate {
2197c478bd9Sstevel@tonic-gate return (prom_stdout_is_framebuffer());
2207c478bd9Sstevel@tonic-gate }
2217c478bd9Sstevel@tonic-gate
2227c478bd9Sstevel@tonic-gate void
kadb_uses_kernel()2237c478bd9Sstevel@tonic-gate kadb_uses_kernel()
2247c478bd9Sstevel@tonic-gate {
2257c478bd9Sstevel@tonic-gate /* only used on intel */
2267c478bd9Sstevel@tonic-gate }
227fea9cb91Slq150181
228fea9cb91Slq150181 void
plat_tem_get_inverses(int * inverse,int * inverse_screen)229c9503a49Slq150181 plat_tem_get_inverses(int *inverse, int *inverse_screen)
230c9503a49Slq150181 {
231c9503a49Slq150181 prom_get_tem_inverses(inverse, inverse_screen);
232c9503a49Slq150181 }
233c9503a49Slq150181
234c9503a49Slq150181 void
plat_tem_get_prom_font_size(int * charheight,int * windowtop)235fea9cb91Slq150181 plat_tem_get_prom_font_size(int *charheight, int *windowtop)
236fea9cb91Slq150181 {
237fea9cb91Slq150181 prom_get_term_font_size(charheight, windowtop);
238fea9cb91Slq150181 }
239fea9cb91Slq150181
240fea9cb91Slq150181 void
plat_tem_get_prom_size(size_t * height,size_t * width)241fea9cb91Slq150181 plat_tem_get_prom_size(size_t *height, size_t *width)
242fea9cb91Slq150181 {
243fea9cb91Slq150181 prom_get_tem_size(height, width);
244fea9cb91Slq150181 }
245fea9cb91Slq150181
246fea9cb91Slq150181 void
plat_tem_hide_prom_cursor(void)247fea9cb91Slq150181 plat_tem_hide_prom_cursor(void)
248fea9cb91Slq150181 {
249fea9cb91Slq150181 prom_hide_cursor();
250fea9cb91Slq150181 }
251fea9cb91Slq150181
252fea9cb91Slq150181 void
plat_tem_get_prom_pos(uint32_t * row,uint32_t * col)253fea9cb91Slq150181 plat_tem_get_prom_pos(uint32_t *row, uint32_t *col)
254fea9cb91Slq150181 {
255fea9cb91Slq150181 prom_get_tem_pos(row, col);
256fea9cb91Slq150181 }
2571b83305cSjm22469
2581b83305cSjm22469 /*
2591b83305cSjm22469 * Find the path of the virtual console (if available on the
2601b83305cSjm22469 * current architecture).
2611b83305cSjm22469 *
2621b83305cSjm22469 * Returns: -1 if not found, else actual path length.
2631b83305cSjm22469 */
2641b83305cSjm22469 int
plat_virtual_console_path(char ** bufp)2651b83305cSjm22469 plat_virtual_console_path(char **bufp)
2661b83305cSjm22469 {
2671b83305cSjm22469 pnode_t pnode;
2681b83305cSjm22469 int buflen;
2691b83305cSjm22469 static char buf[OBP_MAXPATHLEN];
2701b83305cSjm22469
2711b83305cSjm22469 pnode = prom_finddevice("/virtual-devices/console");
2721b83305cSjm22469
2731b83305cSjm22469 if (pnode == OBP_BADNODE)
2741b83305cSjm22469 return (-1);
2751b83305cSjm22469
2761b83305cSjm22469 if ((buflen = prom_phandle_to_path(pnode, buf, sizeof (buf))) < 0)
2771b83305cSjm22469 return (-1);
2781b83305cSjm22469
2791b83305cSjm22469 *bufp = buf;
2801b83305cSjm22469
2811b83305cSjm22469 return (buflen);
2821b83305cSjm22469 }
283