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