1 0 stevel /* 2 0 stevel * CDDL HEADER START 3 0 stevel * 4 0 stevel * The contents of this file are subject to the terms of the 5 1253 lq150181 * Common Development and Distribution License (the "License"). 6 1253 lq150181 * You may not use this file except in compliance with the License. 7 0 stevel * 8 0 stevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 0 stevel * or http://www.opensolaris.org/os/licensing. 10 0 stevel * See the License for the specific language governing permissions 11 0 stevel * and limitations under the License. 12 0 stevel * 13 0 stevel * When distributing Covered Code, include this CDDL HEADER in each 14 0 stevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 0 stevel * If applicable, add the following below this CDDL HEADER, with the 16 0 stevel * fields enclosed by brackets "[]" replaced with your own identifying 17 0 stevel * information: Portions Copyright [yyyy] [name of copyright owner] 18 0 stevel * 19 0 stevel * CDDL HEADER END 20 0 stevel */ 21 1253 lq150181 22 0 stevel /* 23 8960 Jan * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24 0 stevel * Use is subject to license terms. 25 0 stevel */ 26 0 stevel 27 0 stevel /* 28 0 stevel * This module performs two functions. First, it kicks off the driver loading 29 0 stevel * of the console devices during boot in dynamic_console_config(). 30 0 stevel * The loading of the drivers for the console devices triggers the 31 0 stevel * additional device autoconfiguration to link the drivers into the keyboard 32 0 stevel * and mouse console streams. 33 0 stevel * 34 0 stevel * The second function of this module is to provide the dacf functions 35 0 stevel * to be called after a driver has attached and before it detaches. For 36 0 stevel * example, a driver associated with the keyboard will have kb_config called 37 0 stevel * after the driver attaches and kb_unconfig before it detaches. Similar 38 0 stevel * configuration actions are performed on behalf of minor nodes representing 39 0 stevel * mice. The configuration functions for the attach case take a module 40 0 stevel * name as a parameter. The module is pushed on top of the driver during 41 0 stevel * the configuration. 42 0 stevel * 43 0 stevel * Although the dacf framework is used to configure all keyboards and mice, 44 0 stevel * its primary function is to allow keyboard and mouse hotplugging. 45 0 stevel * 46 0 stevel * This module supports multiple keyboards and mice at the same time. 47 0 stevel * 48 0 stevel * From the kernel perspective, there are roughly three different possible 49 0 stevel * console configurations. Across these three configurations, the following 50 0 stevel * elements are constant: 51 0 stevel * wsconsvp = IWSCN_PATH 52 0 stevel * rwsconsvp = WC_PATH 53 0 stevel * consms -> msdev 54 0 stevel * 55 0 stevel * The "->" syntax indicates that the streams device on the right is 56 0 stevel * linked under the streams device on the left. 57 0 stevel * 58 0 stevel * The following lists how the system is configured for different setups: 59 0 stevel * 60 0 stevel * stdin is a local keyboard. use stdin and stdout as the console. 61 0 stevel * sp->cons_input_type = CONSOLE_LOCAL 62 0 stevel * rconsvp = IWSCN_PATH 63 0 stevel * wc -> conskbd -> kbddev 64 0 stevel * 65 0 stevel * stdin is not a keyboard and stdin is the same as stdout. 66 0 stevel * assume we running on a tip line and use stdin/stdout as the console. 67 0 stevel * sp->cons_input_type = CONSOLE_TIP 68 0 stevel * rconsvp = (stdindev/stdoutdev) 69 0 stevel * wc -> conskbd -> kbddev 70 0 stevel * 71 0 stevel * stdin is not a keyboard device and it's not the same as stdout. 72 0 stevel * assume we have a serial keyboard hooked up and use it along with 73 0 stevel * stdout as the console. 74 0 stevel * sp->cons_input_type = CONSOLE_SERIAL_KEYBOARD 75 0 stevel * rconsvp = IWSCN_PATH 76 0 stevel * wc -> stdindev 77 0 stevel * conskbd -> kbddev 78 0 stevel * 79 0 stevel * CAVEAT: 80 0 stevel * The above is all true except for one possible Intel configuration. 81 0 stevel * If stdin is set to a local keyboard but stdout is set to something 82 0 stevel * other than the local display (a tip port for example) stdout will 83 0 stevel * still go to the local display. This is an artifact of the console 84 0 stevel * implementation on intel. 85 0 stevel */ 86 0 stevel 87 0 stevel #include <sys/types.h> 88 0 stevel #include <sys/param.h> 89 0 stevel #include <sys/cmn_err.h> 90 0 stevel #include <sys/user.h> 91 0 stevel #include <sys/vfs.h> 92 0 stevel #include <sys/vnode.h> 93 0 stevel #include <sys/pathname.h> 94 0 stevel #include <sys/systm.h> 95 0 stevel #include <sys/file.h> 96 0 stevel #include <sys/stropts.h> 97 0 stevel #include <sys/stream.h> 98 0 stevel #include <sys/strsubr.h> 99 0 stevel 100 0 stevel #include <sys/consdev.h> 101 1253 lq150181 #include <sys/console.h> 102 1253 lq150181 #include <sys/wscons.h> 103 0 stevel #include <sys/kbio.h> 104 0 stevel #include <sys/debug.h> 105 0 stevel #include <sys/reboot.h> 106 0 stevel #include <sys/termios.h> 107 0 stevel 108 0 stevel #include <sys/ddi.h> 109 0 stevel #include <sys/sunddi.h> 110 0 stevel #include <sys/sunldi.h> 111 0 stevel #include <sys/sunndi.h> 112 0 stevel #include <sys/ndi_impldefs.h> 113 0 stevel #include <sys/modctl.h> 114 0 stevel #include <sys/ddi_impldefs.h> 115 0 stevel #include <sys/ddi_implfuncs.h> 116 0 stevel #include <sys/promif.h> 117 0 stevel #include <sys/fs/snode.h> 118 0 stevel 119 0 stevel #include <sys/errno.h> 120 0 stevel #include <sys/devops.h> 121 0 stevel #include <sys/note.h> 122 0 stevel 123 1253 lq150181 #include <sys/tem_impl.h> 124 0 stevel #include <sys/polled_io.h> 125 0 stevel #include <sys/kmem.h> 126 0 stevel #include <sys/dacf.h> 127 0 stevel #include <sys/consconfig_dacf.h> 128 7335 Lipeng #include <sys/consplat.h> 129 2191 szhou #include <sys/log.h> 130 2191 szhou #include <sys/disp.h> 131 0 stevel 132 0 stevel /* 133 0 stevel * External global variables 134 0 stevel */ 135 0 stevel extern vnode_t *rconsvp; 136 0 stevel extern dev_t rwsconsdev; 137 0 stevel 138 0 stevel /* 139 0 stevel * External functions 140 0 stevel */ 141 0 stevel extern uintptr_t space_fetch(char *key); 142 0 stevel extern int space_store(char *key, uintptr_t ptr); 143 0 stevel 144 0 stevel /* 145 0 stevel * Tasks 146 0 stevel */ 147 0 stevel static int kb_config(dacf_infohdl_t, dacf_arghdl_t, int); 148 0 stevel static int kb_unconfig(dacf_infohdl_t, dacf_arghdl_t, int); 149 0 stevel static int ms_config(dacf_infohdl_t, dacf_arghdl_t, int); 150 0 stevel static int ms_unconfig(dacf_infohdl_t, dacf_arghdl_t, int); 151 0 stevel 152 0 stevel /* 153 0 stevel * Internal functions 154 0 stevel */ 155 0 stevel static int consconfig_setmodes(dev_t dev, struct termios *termiosp); 156 0 stevel static void consconfig_check_phys_kbd(cons_state_t *); 157 0 stevel static void consconfig_rem_dev(cons_state_t *, dev_t); 158 0 stevel static void consconfig_add_dev(cons_state_t *, cons_prop_t *); 159 0 stevel static cons_prop_t *consconfig_find_dev(cons_state_t *, dev_t); 160 0 stevel static void consconfig_free_prop(cons_prop_t *prop); 161 8960 Jan static void flush_deferred_console_buf(void); 162 0 stevel 163 0 stevel 164 0 stevel /* 165 0 stevel * On supported configurations, the firmware defines the keyboard and mouse 166 0 stevel * paths. However, during USB development, it is useful to be able to use 167 0 stevel * the USB keyboard and mouse on machines without full USB firmware support. 168 0 stevel * These variables may be set in /etc/system according to a machine's 169 0 stevel * USB configuration. This module will override the firmware's values 170 0 stevel * with these. 171 0 stevel * 172 0 stevel * NOTE: 173 0 stevel * The master copies of these variables in the misc/consconfig module. 174 0 stevel * The reason for this is historic. In versions of solaris up to and 175 0 stevel * including solaris 9 the conscole configuration code was split into a 176 0 stevel * seperate sparc and intel version. These variables were defined 177 0 stevel * in misc/consconfig on sparc and dacf/consconfig_dacf on intel. 178 0 stevel * 179 0 stevel * Unfortunatly the sparc variables were well documented. 180 0 stevel * So to aviod breaking either sparc or intel we'll declare the variables 181 0 stevel * in both modules. This will allow any /etc/system entries that 182 0 stevel * users may have to continue working. 183 0 stevel * 184 0 stevel * The variables in misc/consconfig will take precedence over the variables 185 0 stevel * found in this file. Since we eventually want to remove the variables 186 0 stevel * local to this this file, if the user set them we'll emmit an error 187 0 stevel * message telling them they need to set the variables in misc/consconfig 188 0 stevel * instead. 189 0 stevel */ 190 0 stevel static char *usb_kb_path = NULL; 191 0 stevel static char *usb_ms_path = NULL; 192 0 stevel 193 0 stevel /* 194 0 stevel * Access functions in the misc/consconfig module used to retrieve the 195 0 stevel * values of it local usb_kb_path and usb_ms_path variables 196 0 stevel */ 197 0 stevel extern char *consconfig_get_usb_kb_path(); 198 0 stevel extern char *consconfig_get_usb_ms_path(); 199 0 stevel 200 0 stevel /* 201 0 stevel * Local variables used to store the value of the usb_kb_path and 202 0 stevel * usb_ms_path variables found in misc/consconfig 203 0 stevel */ 204 0 stevel static char *consconfig_usb_kb_path = NULL; 205 0 stevel static char *consconfig_usb_ms_path = NULL; 206 0 stevel 207 0 stevel /* 208 0 stevel * Internal variables 209 0 stevel */ 210 0 stevel static dev_t stdoutdev; 211 3446 mrj static cons_state_t *consconfig_sp; 212 0 stevel 213 0 stevel /* 214 0 stevel * consconfig_errlevel: debug verbosity; smaller numbers are more 215 0 stevel * verbose. 216 0 stevel */ 217 3446 mrj int consconfig_errlevel = DPRINT_L3; 218 0 stevel 219 0 stevel /* 220 0 stevel * Baud rate table 221 0 stevel */ 222 0 stevel static struct speed { 223 0 stevel char *name; 224 0 stevel int code; 225 9354 Tim } speedtab[] = { 226 0 stevel {"0", B0}, {"50", B50}, {"75", B75}, 227 0 stevel {"110", B110}, {"134", B134}, {"150", B150}, 228 0 stevel {"200", B200}, {"300", B300}, {"600", B600}, 229 0 stevel {"1200", B1200}, {"1800", B1800}, {"2400", B2400}, 230 0 stevel {"4800", B4800}, {"9600", B9600}, {"19200", B19200}, 231 0 stevel {"38400", B38400}, {"57600", B57600}, {"76800", B76800}, 232 0 stevel {"115200", B115200}, {"153600", B153600}, {"230400", B230400}, 233 9354 Tim {"307200", B307200}, {"460800", B460800}, {"921600", B921600}, 234 9354 Tim {"", 0} 235 0 stevel }; 236 9354 Tim 237 9354 Tim static const int MAX_SPEEDS = sizeof (speedtab) / sizeof (speedtab[0]); 238 0 stevel 239 0 stevel static dacf_op_t kbconfig_op[] = { 240 0 stevel { DACF_OPID_POSTATTACH, kb_config }, 241 0 stevel { DACF_OPID_PREDETACH, kb_unconfig }, 242 0 stevel { DACF_OPID_END, NULL }, 243 0 stevel }; 244 0 stevel 245 0 stevel static dacf_op_t msconfig_op[] = { 246 0 stevel { DACF_OPID_POSTATTACH, ms_config }, 247 0 stevel { DACF_OPID_PREDETACH, ms_unconfig }, 248 0 stevel { DACF_OPID_END, NULL }, 249 0 stevel }; 250 0 stevel 251 0 stevel static dacf_opset_t opsets[] = { 252 0 stevel { "kb_config", kbconfig_op }, 253 0 stevel { "ms_config", msconfig_op }, 254 0 stevel { NULL, NULL } 255 0 stevel }; 256 0 stevel 257 0 stevel struct dacfsw dacfsw = { 258 0 stevel DACF_MODREV_1, 259 0 stevel opsets, 260 0 stevel }; 261 0 stevel 262 7767 John static struct modldacf modldacf = { 263 0 stevel &mod_dacfops, /* Type of module */ 264 7335 Lipeng "Consconfig DACF", 265 0 stevel &dacfsw 266 0 stevel }; 267 0 stevel 268 7767 John static struct modlinkage modlinkage = { 269 0 stevel MODREV_1, (void *)&modldacf, NULL 270 0 stevel }; 271 0 stevel 272 0 stevel int 273 0 stevel _init(void) { 274 0 stevel return (mod_install(&modlinkage)); 275 0 stevel } 276 0 stevel 277 0 stevel int 278 0 stevel _fini(void) 279 0 stevel { 280 0 stevel /* 281 0 stevel * This modules state is held in the kernel by space.c 282 0 stevel * allowing this module to be unloaded. 283 0 stevel */ 284 0 stevel return (mod_remove(&modlinkage)); 285 0 stevel } 286 0 stevel 287 0 stevel int 288 0 stevel _info(struct modinfo *modinfop) 289 0 stevel { 290 0 stevel return (mod_info(&modlinkage, modinfop)); 291 0 stevel } 292 0 stevel 293 0 stevel /*PRINTFLIKE2*/ 294 0 stevel static void consconfig_dprintf(int, const char *, ...) 295 0 stevel __KPRINTFLIKE(2); 296 0 stevel 297 0 stevel static void 298 0 stevel consconfig_dprintf(int l, const char *fmt, ...) 299 0 stevel { 300 0 stevel va_list ap; 301 0 stevel 302 0 stevel #ifndef DEBUG 303 0 stevel if (!l) { 304 0 stevel return; 305 0 stevel } 306 1253 lq150181 #endif /* DEBUG */ 307 0 stevel if (l < consconfig_errlevel) { 308 0 stevel return; 309 0 stevel } 310 0 stevel 311 0 stevel va_start(ap, fmt); 312 0 stevel (void) vprintf(fmt, ap); 313 0 stevel va_end(ap); 314 0 stevel } 315 0 stevel 316 0 stevel /* 317 6128 edp * Return a property value for the specified alias in /aliases. 318 0 stevel */ 319 0 stevel char * 320 0 stevel get_alias(char *alias, char *buf) 321 0 stevel { 322 789 ahrens pnode_t node; 323 6128 edp int len; 324 0 stevel 325 6128 edp /* The /aliases node only exists in OBP >= 2.4. */ 326 0 stevel if ((node = prom_alias_node()) == OBP_BADNODE) 327 0 stevel return (NULL); 328 0 stevel 329 6128 edp if ((len = prom_getproplen(node, (caddr_t)alias)) <= 0) 330 0 stevel return (NULL); 331 0 stevel 332 0 stevel (void) prom_getprop(node, (caddr_t)alias, (caddr_t)buf); 333 6128 edp 334 6128 edp /* 335 6128 edp * The IEEE 1275 standard specifies that /aliases string property 336 6128 edp * values should be null-terminated. Unfortunatly the reality 337 6128 edp * is that most aren't and the OBP can't easily be modified to 338 6128 edp * add null termination to these strings. So we'll add the 339 6128 edp * null termination here. If the string already contains a 340 6128 edp * null termination character then that's ok too because we'll 341 6128 edp * just be adding a second one. 342 6128 edp */ 343 6128 edp buf[len] = '\0'; 344 6128 edp 345 0 stevel prom_pathname(buf); 346 0 stevel return (buf); 347 0 stevel } 348 0 stevel 349 0 stevel /* 350 0 stevel * i_consconfig_createvp: 351 0 stevel * This routine is a convenience routine that is passed a path and returns 352 0 stevel * a vnode. 353 0 stevel */ 354 0 stevel static vnode_t * 355 0 stevel i_consconfig_createvp(char *path) 356 0 stevel { 357 0 stevel int error; 358 0 stevel vnode_t *vp; 359 0 stevel char *buf = NULL, *fullpath; 360 0 stevel 361 0 stevel DPRINTF(DPRINT_L0, "i_consconfig_createvp: %s\n", path); 362 0 stevel fullpath = kmem_alloc(MAXPATHLEN, KM_SLEEP); 363 0 stevel 364 0 stevel if (strchr(path, ':') == NULL) { 365 0 stevel /* convert an OBP path to a /devices path */ 366 0 stevel buf = kmem_alloc(MAXPATHLEN, KM_SLEEP); 367 0 stevel if (i_ddi_prompath_to_devfspath(path, buf) != DDI_SUCCESS) { 368 0 stevel kmem_free(buf, MAXPATHLEN); 369 0 stevel kmem_free(fullpath, MAXPATHLEN); 370 0 stevel return (NULL); 371 0 stevel } 372 0 stevel (void) snprintf(fullpath, MAXPATHLEN, "/devices%s", buf); 373 0 stevel kmem_free(buf, MAXPATHLEN); 374 0 stevel } else { 375 0 stevel /* convert a devfs path to a /devices path */ 376 0 stevel (void) snprintf(fullpath, MAXPATHLEN, "/devices%s", path); 377 0 stevel } 378 0 stevel 379 0 stevel DPRINTF(DPRINT_L0, "lookupname(%s)\n", fullpath); 380 0 stevel error = lookupname(fullpath, UIO_SYSSPACE, FOLLOW, NULLVPP, &vp); 381 0 stevel kmem_free(fullpath, MAXPATHLEN); 382 0 stevel if (error) 383 0 stevel return (NULL); 384 0 stevel 385 0 stevel DPRINTF(DPRINT_L0, "create vnode = 0x%p - dev 0x%lx\n", vp, vp->v_rdev); 386 0 stevel ASSERT(vn_matchops(vp, spec_getvnodeops())); 387 0 stevel 388 0 stevel return (vp); 389 0 stevel } 390 0 stevel 391 0 stevel /* 392 0 stevel * consconfig_print_paths: 393 0 stevel * Function to print out the various paths 394 0 stevel */ 395 0 stevel static void 396 0 stevel consconfig_print_paths(void) 397 0 stevel { 398 0 stevel char *path; 399 0 stevel 400 0 stevel if (usb_kb_path != NULL) 401 0 stevel cmn_err(CE_WARN, 402 0 stevel "consconfig_dacf:usb_kb_path has been deprecated, " 403 0 stevel "use consconfig:usb_kb_path instead"); 404 0 stevel 405 0 stevel if (usb_ms_path != NULL) 406 0 stevel cmn_err(CE_WARN, 407 0 stevel "consconfig_dacf:usb_ms_path has been deprecated, " 408 0 stevel "use consconfig:usb_ms_path instead"); 409 0 stevel 410 0 stevel if (consconfig_errlevel > DPRINT_L0) 411 0 stevel return; 412 0 stevel 413 0 stevel path = NULL; 414 0 stevel if (consconfig_usb_kb_path != NULL) 415 0 stevel path = consconfig_usb_kb_path; 416 0 stevel else if (usb_kb_path != NULL) 417 0 stevel path = usb_kb_path; 418 0 stevel if (path != NULL) 419 0 stevel DPRINTF(DPRINT_L0, "usb keyboard path = %s\n", path); 420 0 stevel 421 0 stevel path = plat_kbdpath(); 422 0 stevel if (path != NULL) 423 0 stevel DPRINTF(DPRINT_L0, "keyboard path = %s\n", path); 424 0 stevel 425 0 stevel path = NULL; 426 0 stevel if (consconfig_usb_ms_path != NULL) 427 0 stevel path = consconfig_usb_ms_path; 428 0 stevel else if (usb_ms_path != NULL) 429 0 stevel path = usb_ms_path; 430 0 stevel if (path != NULL) 431 0 stevel DPRINTF(DPRINT_L0, "usb mouse path = %s\n", path); 432 0 stevel 433 0 stevel path = plat_mousepath(); 434 0 stevel if (path != NULL) 435 0 stevel DPRINTF(DPRINT_L0, "mouse path = %s\n", path); 436 0 stevel 437 0 stevel path = plat_stdinpath(); 438 0 stevel if (path != NULL) 439 0 stevel DPRINTF(DPRINT_L0, "stdin path = %s\n", path); 440 0 stevel 441 0 stevel path = plat_stdoutpath(); 442 0 stevel if (path != NULL) 443 0 stevel DPRINTF(DPRINT_L0, "stdout path = %s\n", path); 444 0 stevel 445 0 stevel path = plat_fbpath(); 446 0 stevel if (path != NULL) 447 0 stevel DPRINTF(DPRINT_L0, "fb path = %s\n", path); 448 0 stevel } 449 0 stevel 450 0 stevel /* 451 0 stevel * consconfig_kbd_abort_enable: 452 0 stevel * Send the CONSSETABORTENABLE ioctl to the lower layers. This ioctl 453 0 stevel * will only be sent to the device if it is the console device. 454 0 stevel * This ioctl tells the device to pay attention to abort sequences. 455 0 stevel * In the case of kbtrans, this would tell the driver to pay attention 456 0 stevel * to the two key abort sequences like STOP-A. In the case of the 457 0 stevel * serial keyboard, it would be an abort sequence like a break. 458 0 stevel */ 459 0 stevel static int 460 0 stevel consconfig_kbd_abort_enable(ldi_handle_t lh) 461 0 stevel { 462 0 stevel int err, rval; 463 0 stevel 464 0 stevel DPRINTF(DPRINT_L0, "consconfig_kbd_abort_enable\n"); 465 0 stevel 466 0 stevel err = ldi_ioctl(lh, CONSSETABORTENABLE, (uintptr_t)B_TRUE, 467 0 stevel FKIOCTL, kcred, &rval); 468 0 stevel return (err); 469 0 stevel } 470 0 stevel 471 0 stevel /* 472 0 stevel * consconfig_kbd_abort_disable: 473 0 stevel * Send CONSSETABORTENABLE ioctl to lower layers. This ioctl 474 0 stevel * will only be sent to the device if it is the console device. 475 0 stevel * This ioctl tells the physical device to ignore abort sequences, 476 0 stevel * and send the sequences up to virtual keyboard(conskbd) so that 477 0 stevel * STOP and A (or F1 and A) can be combined. 478 0 stevel */ 479 0 stevel static int 480 0 stevel consconfig_kbd_abort_disable(ldi_handle_t lh) 481 0 stevel { 482 0 stevel int err, rval; 483 0 stevel 484 0 stevel DPRINTF(DPRINT_L0, "consconfig_kbd_abort_disable\n"); 485 0 stevel 486 0 stevel err = ldi_ioctl(lh, CONSSETABORTENABLE, (uintptr_t)B_FALSE, 487 0 stevel FKIOCTL, kcred, &rval); 488 0 stevel return (err); 489 0 stevel } 490 0 stevel 491 5974 jm22469 #ifdef _HAVE_TEM_FIRMWARE 492 5974 jm22469 static int 493 5974 jm22469 consconfig_tem_supported(cons_state_t *sp) 494 5974 jm22469 { 495 5974 jm22469 dev_t dev; 496 5974 jm22469 dev_info_t *dip; 497 5974 jm22469 int *int_array; 498 5974 jm22469 uint_t nint; 499 5974 jm22469 int rv = 0; 500 5974 jm22469 501 7688 Aaron if (sp->cons_fb_path == NULL) 502 7688 Aaron return (0); 503 7688 Aaron 504 5974 jm22469 if ((dev = ddi_pathname_to_dev_t(sp->cons_fb_path)) == NODEV) 505 5974 jm22469 return (0); /* warning printed later by common code */ 506 5974 jm22469 507 5974 jm22469 /* 508 5974 jm22469 * Here we hold the driver and check "tem-support" property. 509 5974 jm22469 * We're doing this with e_ddi_hold_devi_by_dev and 510 5974 jm22469 * ddi_prop_lookup_int_array without opening the driver since 511 5974 jm22469 * some video cards that don't support the kernel terminal 512 5974 jm22469 * emulator could hang or crash if opened too early during 513 5974 jm22469 * boot. 514 5974 jm22469 */ 515 5974 jm22469 if ((dip = e_ddi_hold_devi_by_dev(dev, 0)) == NULL) { 516 5974 jm22469 cmn_err(CE_WARN, "consconfig: cannot hold fb dev %s", 517 5974 jm22469 sp->cons_fb_path); 518 5974 jm22469 return (0); 519 5974 jm22469 } 520 5974 jm22469 521 5974 jm22469 /* 522 5974 jm22469 * Check that the tem-support property exists AND that 523 5974 jm22469 * it is equal to 1. 524 5974 jm22469 */ 525 5974 jm22469 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 526 5974 jm22469 DDI_PROP_DONTPASS, "tem-support", &int_array, &nint) == 527 5974 jm22469 DDI_SUCCESS) { 528 5974 jm22469 if (nint > 0) 529 5974 jm22469 rv = int_array[0] == 1; 530 5974 jm22469 ddi_prop_free(int_array); 531 5974 jm22469 } 532 5974 jm22469 533 5974 jm22469 ddi_release_devi(dip); 534 5974 jm22469 535 5974 jm22469 return (rv); 536 5974 jm22469 } 537 5974 jm22469 #endif /* _HAVE_TEM_FIRMWARE */ 538 5974 jm22469 539 0 stevel /* 540 0 stevel * consconfig_get_polledio: 541 0 stevel * Query the console with the CONSPOLLEDIO ioctl. 542 0 stevel * The polled I/O routines are used by debuggers to perform I/O while 543 0 stevel * interrupts and normal kernel services are disabled. 544 0 stevel */ 545 0 stevel static cons_polledio_t * 546 0 stevel consconfig_get_polledio(ldi_handle_t lh) 547 0 stevel { 548 0 stevel int err, rval; 549 0 stevel struct strioctl strioc; 550 0 stevel cons_polledio_t *polled_io; 551 0 stevel 552 0 stevel /* 553 0 stevel * Setup the ioctl to be sent down to the lower driver. 554 0 stevel */ 555 0 stevel strioc.ic_cmd = CONSOPENPOLLEDIO; 556 0 stevel strioc.ic_timout = INFTIM; 557 0 stevel strioc.ic_len = sizeof (polled_io); 558 0 stevel strioc.ic_dp = (char *)&polled_io; 559 0 stevel 560 0 stevel /* 561 0 stevel * Send the ioctl to the driver. The ioctl will wait for 562 0 stevel * the response to come back from wc. wc has already issued 563 0 stevel * the CONSOPENPOLLEDIO to the lower layer driver. 564 0 stevel */ 565 0 stevel err = ldi_ioctl(lh, I_STR, (intptr_t)&strioc, FKIOCTL, kcred, &rval); 566 0 stevel 567 0 stevel if (err != 0) { 568 0 stevel /* 569 0 stevel * If the lower driver does not support polled I/O, then 570 0 stevel * return NULL. This will be the case if the driver does 571 0 stevel * not handle polled I/O, or OBP is going to handle polled 572 0 stevel * I/O for the device. 573 0 stevel */ 574 0 stevel 575 0 stevel return (NULL); 576 0 stevel } 577 0 stevel 578 0 stevel /* 579 0 stevel * Return the polled I/O structure. 580 0 stevel */ 581 0 stevel return (polled_io); 582 0 stevel } 583 0 stevel 584 0 stevel /* 585 0 stevel * consconfig_setup_polledio: 586 0 stevel * This routine does the setup work for polled I/O. First we get 587 0 stevel * the polled_io structure from the lower layers 588 0 stevel * and then we register the polled I/O 589 0 stevel * callbacks with the debugger that will be using them. 590 0 stevel */ 591 0 stevel static void 592 0 stevel consconfig_setup_polledio(cons_state_t *sp, dev_t dev) 593 0 stevel { 594 0 stevel cons_polledio_t *polled_io; 595 0 stevel ldi_handle_t lh; 596 0 stevel 597 0 stevel DPRINTF(DPRINT_L0, "consconfig_setup_polledio: start\n"); 598 0 stevel 599 0 stevel 600 0 stevel if (ldi_open_by_dev(&dev, OTYP_CHR, 601 0 stevel FREAD|FWRITE|FNOCTTY, kcred, &lh, sp->cons_li) != 0) 602 0 stevel return; 603 0 stevel 604 0 stevel 605 0 stevel /* 606 0 stevel * Get the polled io routines so that we can use this 607 0 stevel * device with the debuggers. 608 0 stevel */ 609 0 stevel polled_io = consconfig_get_polledio(lh); 610 0 stevel 611 0 stevel /* 612 0 stevel * If the get polledio failed, then we do not want to throw 613 0 stevel * the polled I/O switch. 614 0 stevel */ 615 0 stevel if (polled_io == NULL) { 616 0 stevel DPRINTF(DPRINT_L0, 617 0 stevel "consconfig_setup_polledio: get_polledio failed\n"); 618 0 stevel (void) ldi_close(lh, FREAD|FWRITE, kcred); 619 0 stevel return; 620 0 stevel } 621 0 stevel 622 0 stevel /* Initialize the polled input */ 623 0 stevel polled_io_init(); 624 0 stevel 625 0 stevel /* Register the callbacks */ 626 0 stevel DPRINTF(DPRINT_L0, 627 0 stevel "consconfig_setup_polledio: registering callbacks\n"); 628 0 stevel (void) polled_io_register_callbacks(polled_io, 0); 629 0 stevel 630 0 stevel (void) ldi_close(lh, FREAD|FWRITE, kcred); 631 0 stevel 632 0 stevel DPRINTF(DPRINT_L0, "consconfig_setup_polledio: end\n"); 633 0 stevel } 634 0 stevel 635 0 stevel static cons_state_t * 636 0 stevel consconfig_state_init(void) 637 0 stevel { 638 0 stevel cons_state_t *sp; 639 0 stevel int rval; 640 0 stevel 641 0 stevel /* Initialize console information */ 642 0 stevel sp = kmem_zalloc(sizeof (cons_state_t), KM_SLEEP); 643 0 stevel sp->cons_keyboard_problem = B_FALSE; 644 0 stevel 645 0 stevel mutex_init(&sp->cons_lock, NULL, MUTEX_DRIVER, NULL); 646 0 stevel 647 0 stevel /* check if consconfig:usb_kb_path is set in /etc/system */ 648 0 stevel consconfig_usb_kb_path = consconfig_get_usb_kb_path(); 649 0 stevel 650 0 stevel /* check if consconfig:usb_ms_path is set in /etc/system */ 651 0 stevel consconfig_usb_ms_path = consconfig_get_usb_ms_path(); 652 0 stevel 653 0 stevel consconfig_print_paths(); 654 0 stevel 655 0 stevel /* init external globals */ 656 0 stevel stdoutdev = NODEV; 657 0 stevel 658 0 stevel /* 659 0 stevel * Find keyboard, mouse, stdin and stdout devices, if they 660 0 stevel * exist on this platform. 661 0 stevel */ 662 0 stevel 663 0 stevel if (consconfig_usb_kb_path != NULL) { 664 0 stevel sp->cons_keyboard_path = consconfig_usb_kb_path; 665 0 stevel } else if (usb_kb_path != NULL) { 666 0 stevel sp->cons_keyboard_path = usb_kb_path; 667 0 stevel } else { 668 0 stevel sp->cons_keyboard_path = plat_kbdpath(); 669 0 stevel } 670 0 stevel 671 0 stevel if (consconfig_usb_ms_path != NULL) { 672 0 stevel sp->cons_mouse_path = consconfig_usb_ms_path; 673 0 stevel } else if (usb_ms_path != NULL) { 674 0 stevel sp->cons_mouse_path = usb_ms_path; 675 0 stevel } else { 676 0 stevel sp->cons_mouse_path = plat_mousepath(); 677 0 stevel } 678 0 stevel 679 0 stevel /* Identify the stdout driver */ 680 0 stevel sp->cons_stdout_path = plat_stdoutpath(); 681 5974 jm22469 sp->cons_stdout_is_fb = plat_stdout_is_framebuffer(); 682 0 stevel 683 5974 jm22469 sp->cons_stdin_is_kbd = plat_stdin_is_keyboard(); 684 5974 jm22469 685 5974 jm22469 if (sp->cons_stdin_is_kbd && 686 539 ry162471 (usb_kb_path != NULL || consconfig_usb_kb_path != NULL)) { 687 0 stevel sp->cons_stdin_path = sp->cons_keyboard_path; 688 0 stevel } else { 689 0 stevel /* 690 0 stevel * The standard in device may or may not be the same as 691 0 stevel * the keyboard. Even if the keyboard is not the 692 0 stevel * standard input, the keyboard console stream will 693 0 stevel * still be built if the keyboard alias provided by the 694 0 stevel * firmware exists and is valid. 695 0 stevel */ 696 0 stevel sp->cons_stdin_path = plat_stdinpath(); 697 5974 jm22469 } 698 5974 jm22469 699 5974 jm22469 if (sp->cons_stdout_is_fb) { 700 5974 jm22469 sp->cons_fb_path = sp->cons_stdout_path; 701 5974 jm22469 702 5974 jm22469 #ifdef _HAVE_TEM_FIRMWARE 703 5974 jm22469 sp->cons_tem_supported = consconfig_tem_supported(sp); 704 5974 jm22469 705 5974 jm22469 /* 706 5974 jm22469 * Systems which offer a virtual console must use that 707 5974 jm22469 * as a fallback whenever the fb doesn't support tem. 708 5974 jm22469 * Such systems cannot render characters to the screen 709 5974 jm22469 * using OBP. 710 5974 jm22469 */ 711 5974 jm22469 if (!sp->cons_tem_supported) { 712 5974 jm22469 char *path; 713 5974 jm22469 714 5974 jm22469 if (plat_virtual_console_path(&path) >= 0) { 715 5974 jm22469 sp->cons_stdin_is_kbd = 0; 716 5974 jm22469 sp->cons_stdout_is_fb = 0; 717 5974 jm22469 sp->cons_stdin_path = path; 718 5974 jm22469 sp->cons_stdout_path = path; 719 5974 jm22469 sp->cons_fb_path = plat_fbpath(); 720 5974 jm22469 721 5974 jm22469 cmn_err(CE_WARN, 722 5974 jm22469 "%s doesn't support terminal emulation " 723 5974 jm22469 "mode; switching to virtual console.", 724 5974 jm22469 sp->cons_fb_path); 725 5974 jm22469 } 726 5974 jm22469 } 727 5974 jm22469 #endif /* _HAVE_TEM_FIRMWARE */ 728 5974 jm22469 } else { 729 5974 jm22469 sp->cons_fb_path = plat_fbpath(); 730 7688 Aaron #ifdef _HAVE_TEM_FIRMWARE 731 7688 Aaron sp->cons_tem_supported = consconfig_tem_supported(sp); 732 7688 Aaron #endif /* _HAVE_TEM_FIRMWARE */ 733 0 stevel } 734 0 stevel 735 0 stevel sp->cons_li = ldi_ident_from_anon(); 736 0 stevel 737 0 stevel /* Save the pointer for retrieval by the dacf functions */ 738 0 stevel rval = space_store("consconfig", (uintptr_t)sp); 739 0 stevel ASSERT(rval == 0); 740 0 stevel 741 0 stevel return (sp); 742 0 stevel } 743 0 stevel 744 0 stevel static int 745 0 stevel consconfig_relink_wc(cons_state_t *sp, ldi_handle_t new_lh, int *muxid) 746 0 stevel { 747 0 stevel int err, rval; 748 0 stevel ldi_handle_t wc_lh; 749 0 stevel dev_t wc_dev; 750 0 stevel 751 0 stevel ASSERT(muxid != NULL); 752 0 stevel 753 0 stevel /* 754 0 stevel * NOTE: we could be in a dacf callback context right now. normally 755 0 stevel * it's not legal to call any ldi_open_*() function from this context 756 0 stevel * because we're currently holding device tree locks and if the 757 0 stevel * ldi_open_*() call could try to acquire other device tree locks 758 0 stevel * (to attach the device we're trying to open.) if this happens then 759 0 stevel * we could deadlock. To avoid this situation, during initialization 760 0 stevel * we made sure to grab a hold on the dip of the device we plan to 761 0 stevel * open so that it can never be detached. Then we use 762 0 stevel * ldi_open_by_dev() to actually open the device since it will see 763 0 stevel * that the device is already attached and held and instead of 764 0 stevel * acquire any locks it will only increase the reference count 765 0 stevel * on the device. 766 0 stevel */ 767 0 stevel wc_dev = sp->cons_wc_vp->v_rdev; 768 0 stevel err = ldi_open_by_dev(&wc_dev, OTYP_CHR, FREAD|FWRITE|FNOCTTY, 769 0 stevel kcred, &wc_lh, sp->cons_li); 770 0 stevel ASSERT(wc_dev == sp->cons_wc_vp->v_rdev); 771 0 stevel if (err) { 772 0 stevel cmn_err(CE_WARN, "consconfig_relink_wc: " 773 0 stevel "unable to open wc device"); 774 0 stevel return (err); 775 0 stevel } 776 0 stevel 777 0 stevel if (new_lh != NULL) { 778 0 stevel DPRINTF(DPRINT_L0, "linking stream under wc\n"); 779 0 stevel 780 0 stevel err = ldi_ioctl(wc_lh, I_PLINK, (uintptr_t)new_lh, 781 0 stevel FKIOCTL, kcred, muxid); 782 0 stevel if (err != 0) { 783 0 stevel cmn_err(CE_WARN, "consconfig_relink_wc: " 784 0 stevel "wc link failed, error %d", err); 785 0 stevel } 786 0 stevel } else { 787 0 stevel DPRINTF(DPRINT_L0, "unlinking stream from under wc\n"); 788 0 stevel 789 0 stevel err = ldi_ioctl(wc_lh, I_PUNLINK, *muxid, 790 0 stevel FKIOCTL, kcred, &rval); 791 0 stevel if (err != 0) { 792 0 stevel cmn_err(CE_WARN, "consconfig_relink_wc: " 793 0 stevel "wc unlink failed, error %d", err); 794 0 stevel } else { 795 0 stevel *muxid = -1; 796 0 stevel } 797 0 stevel } 798 0 stevel 799 0 stevel (void) ldi_close(wc_lh, FREAD|FWRITE, kcred); 800 0 stevel return (err); 801 0 stevel } 802 0 stevel 803 0 stevel static void 804 0 stevel cons_build_upper_layer(cons_state_t *sp) 805 0 stevel { 806 1253 lq150181 ldi_handle_t wc_lh; 807 1253 lq150181 struct strioctl strioc; 808 1253 lq150181 int rval; 809 5974 jm22469 dev_t dev; 810 1253 lq150181 dev_t wc_dev; 811 1253 lq150181 812 0 stevel /* 813 0 stevel * Build the wc->conskbd portion of the keyboard console stream. 814 0 stevel * Even if no keyboard is attached to the system, the upper 815 0 stevel * layer of the stream will be built. If the user attaches 816 0 stevel * a keyboard after the system is booted, the keyboard driver 817 0 stevel * and module will be linked under conskbd. 818 0 stevel * 819 0 stevel * Errors are generally ignored here because conskbd and wc 820 0 stevel * are pseudo drivers and should be present on the system. 821 0 stevel */ 822 0 stevel 823 0 stevel /* open the console keyboard device. will never be closed */ 824 3446 mrj if (ldi_open_by_name(CONSKBD_PATH, FREAD|FWRITE|FNOCTTY, 825 3446 mrj kcred, &sp->conskbd_lh, sp->cons_li) != 0) { 826 3446 mrj panic("consconfig: unable to open conskbd device"); 827 3446 mrj /*NOTREACHED*/ 828 3446 mrj } 829 0 stevel 830 0 stevel DPRINTF(DPRINT_L0, "conskbd_lh = %p\n", sp->conskbd_lh); 831 0 stevel 832 0 stevel /* open the console mouse device. will never be closed */ 833 3446 mrj if (ldi_open_by_name(CONSMS_PATH, FREAD|FWRITE|FNOCTTY, 834 3446 mrj kcred, &sp->consms_lh, sp->cons_li) != 0) { 835 3446 mrj panic("consconfig: unable to open consms device"); 836 3446 mrj /*NOTREACHED*/ 837 3446 mrj } 838 0 stevel 839 0 stevel DPRINTF(DPRINT_L0, "consms_lh = %p\n", sp->consms_lh); 840 0 stevel 841 0 stevel /* 842 0 stevel * Get a vnode for the wc device and then grab a hold on the 843 0 stevel * device dip so it can never detach. We need to do this now 844 0 stevel * because later we'll have to open the wc device in a context 845 0 stevel * were it isn't safe to acquire any device tree locks (ie, during 846 0 stevel * a dacf callback.) 847 0 stevel */ 848 0 stevel sp->cons_wc_vp = i_consconfig_createvp(WC_PATH); 849 0 stevel if (sp->cons_wc_vp == NULL) 850 0 stevel panic("consconfig: unable to find wc device"); 851 0 stevel 852 0 stevel if (e_ddi_hold_devi_by_dev(sp->cons_wc_vp->v_rdev, 0) == NULL) 853 0 stevel panic("consconfig: unable to hold wc device"); 854 0 stevel 855 0 stevel /* 856 0 stevel * Build the wc->conskbd portion of the keyboard console stream. 857 0 stevel * Even if no keyboard is attached to the system, the upper 858 0 stevel * layer of the stream will be built. If the user attaches 859 0 stevel * a keyboard after the system is booted, the keyboard driver 860 0 stevel * and module will be linked under conskbd. 861 0 stevel * 862 0 stevel * The act of linking conskbd under wc will cause wc to 863 0 stevel * query the lower layers about their polled I/O routines 864 0 stevel * using CONSOPENPOLLEDIO. This will fail on this link because 865 0 stevel * there is not a physical keyboard linked under conskbd. 866 0 stevel * 867 0 stevel * Since conskbd and wc are pseudo drivers, errors are 868 0 stevel * generally ignored when linking and unlinking them. 869 0 stevel */ 870 0 stevel (void) consconfig_relink_wc(sp, sp->conskbd_lh, &sp->conskbd_muxid); 871 0 stevel 872 0 stevel /* 873 0 stevel * Get a vnode for the redirection device. (It has the 874 0 stevel * connection to the workstation console device wired into it, 875 0 stevel * so that it's not necessary to establish the connection 876 0 stevel * here. If the redirection device is ever generalized to 877 0 stevel * handle multiple client devices, it won't be able to 878 0 stevel * establish the connection itself, and we'll have to do it 879 0 stevel * here.) 880 0 stevel */ 881 0 stevel wsconsvp = i_consconfig_createvp(IWSCN_PATH); 882 3446 mrj if (wsconsvp == NULL) { 883 3446 mrj panic("consconfig: unable to find iwscn device"); 884 3446 mrj /*NOTREACHED*/ 885 3446 mrj } 886 0 stevel 887 1253 lq150181 if (cons_tem_disable) 888 1253 lq150181 return; 889 1253 lq150181 890 0 stevel if (sp->cons_fb_path == NULL) { 891 3446 mrj #if defined(__x86) 892 5974 jm22469 if (sp->cons_stdout_is_fb) 893 3446 mrj cmn_err(CE_WARN, "consconfig: no screen found"); 894 3446 mrj #endif 895 0 stevel return; 896 1253 lq150181 } 897 0 stevel 898 1253 lq150181 /* make sure the frame buffer device exists */ 899 1253 lq150181 dev = ddi_pathname_to_dev_t(sp->cons_fb_path); 900 1253 lq150181 if (dev == NODEV) { 901 1253 lq150181 cmn_err(CE_WARN, "consconfig: " 902 1253 lq150181 "cannot find driver for screen device %s", 903 1253 lq150181 sp->cons_fb_path); 904 1253 lq150181 return; 905 1253 lq150181 } 906 0 stevel 907 1253 lq150181 #ifdef _HAVE_TEM_FIRMWARE 908 1253 lq150181 /* 909 5974 jm22469 * If the underlying fb device doesn't support terminal emulation, 910 5974 jm22469 * we don't want to open the wc device (below) because it depends 911 5974 jm22469 * on features which aren't available (polled mode io). 912 1253 lq150181 */ 913 5974 jm22469 if (!sp->cons_tem_supported) 914 1253 lq150181 return; 915 1253 lq150181 #endif /* _HAVE_TEM_FIRMWARE */ 916 0 stevel 917 1253 lq150181 /* tell wc to open the frame buffer device */ 918 1253 lq150181 wc_dev = sp->cons_wc_vp->v_rdev; 919 1253 lq150181 if (ldi_open_by_dev(&wc_dev, OTYP_CHR, FREAD|FWRITE|FNOCTTY, kcred, 920 1253 lq150181 &wc_lh, sp->cons_li)) { 921 1253 lq150181 cmn_err(CE_PANIC, "cons_build_upper_layer: " 922 1253 lq150181 "unable to open wc device"); 923 1253 lq150181 return; 924 1253 lq150181 } 925 1253 lq150181 ASSERT(wc_dev == sp->cons_wc_vp->v_rdev); 926 0 stevel 927 1253 lq150181 strioc.ic_cmd = WC_OPEN_FB; 928 1253 lq150181 strioc.ic_timout = INFTIM; 929 1253 lq150181 strioc.ic_len = strlen(sp->cons_fb_path) + 1; 930 1253 lq150181 strioc.ic_dp = sp->cons_fb_path; 931 1253 lq150181 932 1253 lq150181 if (ldi_ioctl(wc_lh, I_STR, (intptr_t)&strioc, 933 1253 lq150181 FKIOCTL, kcred, &rval) == 0) 934 1253 lq150181 consmode = CONS_KFB; 935 1253 lq150181 else 936 1253 lq150181 cmn_err(CE_WARN, 937 1253 lq150181 "consconfig: terminal emulator failed to initialize"); 938 1253 lq150181 (void) ldi_close(wc_lh, FREAD|FWRITE, kcred); 939 0 stevel } 940 0 stevel 941 0 stevel static void 942 0 stevel consconfig_load_drivers(cons_state_t *sp) 943 0 stevel { 944 0 stevel /* 945 0 stevel * Calling ddi_pathname_to_dev_t causes the drivers to be loaded. 946 0 stevel * The attaching of the drivers will cause the creation of the 947 0 stevel * keyboard and mouse minor nodes, which will in turn trigger the 948 0 stevel * dacf framework to call the keyboard and mouse configuration 949 0 stevel * tasks. See PSARC/1998/212 for more details about the dacf 950 0 stevel * framework. 951 0 stevel * 952 0 stevel * on sparc, when the console is ttya, zs0 is stdin/stdout, and zs1 953 0 stevel * is kb/mouse. zs0 must be attached before zs1. The zs driver 954 0 stevel * is written this way and the hardware may depend on this, too. 955 0 stevel * It would be better to enforce this by attaching zs in sibling 956 0 stevel * order with a driver property, such as ddi-attachall. 957 0 stevel */ 958 0 stevel if (sp->cons_stdin_path != NULL) 959 0 stevel stdindev = ddi_pathname_to_dev_t(sp->cons_stdin_path); 960 0 stevel if (stdindev == NODEV) { 961 0 stevel DPRINTF(DPRINT_L0, 962 0 stevel "!fail to attach stdin: %s\n", sp->cons_stdin_path); 963 0 stevel } 964 0 stevel if (sp->cons_stdout_path != NULL) 965 0 stevel stdoutdev = ddi_pathname_to_dev_t(sp->cons_stdout_path); 966 0 stevel if (sp->cons_keyboard_path != NULL) 967 0 stevel kbddev = ddi_pathname_to_dev_t(sp->cons_keyboard_path); 968 0 stevel if (sp->cons_mouse_path != NULL) 969 0 stevel mousedev = ddi_pathname_to_dev_t(sp->cons_mouse_path); 970 3446 mrj 971 3446 mrj /* 972 3446 mrj * On x86, make sure the fb driver is loaded even if we don't use it 973 3446 mrj * for the console. This will ensure that we create a /dev/fb link 974 3446 mrj * which is required to start Xorg. 975 3446 mrj */ 976 3446 mrj #if defined(__x86) 977 3446 mrj if (sp->cons_fb_path != NULL) 978 3446 mrj fbdev = ddi_pathname_to_dev_t(sp->cons_fb_path); 979 3446 mrj #endif 980 3446 mrj 981 0 stevel DPRINTF(DPRINT_L0, "stdindev %lx, stdoutdev %lx, kbddev %lx, " 982 0 stevel "mousedev %lx\n", stdindev, stdoutdev, kbddev, mousedev); 983 0 stevel } 984 0 stevel 985 10064 James #if !defined(__x86) 986 10064 James void 987 10064 James consconfig_virtual_console_vp(cons_state_t *sp) 988 10064 James { 989 10064 James char *virtual_cons_path; 990 10064 James 991 10064 James if (plat_virtual_console_path(&virtual_cons_path) < 0) 992 10064 James return; 993 10064 James 994 10064 James DPRINTF(DPRINT_L0, "consconfig_virtual_console_vp: " 995 10064 James "virtual console device path %s\n", virtual_cons_path); 996 10064 James 997 10064 James ASSERT(sp->cons_stdout_path != NULL); 998 10064 James if (strcmp(virtual_cons_path, sp->cons_stdout_path) == 0) { 999 10064 James /* virtual console already in use */ 1000 10064 James return; 1001 10064 James } 1002 10064 James 1003 10064 James vsconsvp = i_consconfig_createvp(virtual_cons_path); 1004 10064 James if (vsconsvp == NULL) { 1005 10064 James cmn_err(CE_WARN, "consconfig_virtual_console_vp: " 1006 10064 James "unable to find serial virtual console device %s", 1007 10064 James virtual_cons_path); 1008 10064 James return; 1009 10064 James } 1010 10064 James 1011 10064 James (void) e_ddi_hold_devi_by_dev(vsconsvp->v_rdev, 0); 1012 10064 James } 1013 10064 James #endif 1014 10064 James 1015 0 stevel static void 1016 0 stevel consconfig_init_framebuffer(cons_state_t *sp) 1017 0 stevel { 1018 5974 jm22469 if (!sp->cons_stdout_is_fb) 1019 0 stevel return; 1020 0 stevel 1021 0 stevel DPRINTF(DPRINT_L0, "stdout is framebuffer\n"); 1022 0 stevel ASSERT(strcmp(sp->cons_fb_path, sp->cons_stdout_path) == 0); 1023 0 stevel 1024 0 stevel /* 1025 0 stevel * Console output is a framebuffer. 1026 0 stevel * Find the framebuffer driver if we can, and make 1027 0 stevel * ourselves a shadow vnode to track it with. 1028 0 stevel */ 1029 0 stevel fbdev = stdoutdev; 1030 0 stevel if (fbdev == NODEV) { 1031 0 stevel DPRINTF(DPRINT_L3, 1032 0 stevel "Can't find driver for console framebuffer\n"); 1033 0 stevel } else { 1034 0 stevel /* stdoutdev is valid, of fbvp should exist */ 1035 0 stevel fbvp = i_consconfig_createvp(sp->cons_stdout_path); 1036 0 stevel if (fbvp == NULL) { 1037 10064 James panic("consconfig_init_framebuffer: " 1038 0 stevel "unable to find frame buffer device"); 1039 0 stevel /*NOTREACHED*/ 1040 0 stevel } 1041 0 stevel ASSERT(fbvp->v_rdev == fbdev); 1042 0 stevel 1043 0 stevel /* console device is never released */ 1044 0 stevel fbdip = e_ddi_hold_devi_by_dev(fbdev, 0); 1045 0 stevel } 1046 0 stevel pm_cfb_setup(sp->cons_stdout_path); 1047 0 stevel } 1048 0 stevel 1049 0 stevel /* 1050 0 stevel * consconfig_prepare_dev: 1051 0 stevel * Flush the stream, push "pushmod" onto the stream. 1052 0 stevel * for keyboard, issue the KIOCTRANSABLE ioctl, and 1053 0 stevel * possible enable abort. 1054 0 stevel */ 1055 0 stevel static void 1056 0 stevel consconfig_prepare_dev( 1057 0 stevel ldi_handle_t new_lh, 1058 0 stevel const char *pushmod, 1059 0 stevel int kbdtranslatable, 1060 0 stevel int input_type, 1061 0 stevel int dev_type) 1062 0 stevel { 1063 0 stevel int err, rval; 1064 0 stevel 1065 0 stevel /* send a flush down the stream to the keyboard driver */ 1066 0 stevel (void) ldi_ioctl(new_lh, I_FLUSH, (intptr_t)FLUSHRW, 1067 0 stevel FKIOCTL, kcred, &rval); 1068 0 stevel 1069 0 stevel if (pushmod) { 1070 0 stevel err = ldi_ioctl(new_lh, I_PUSH, (intptr_t)pushmod, 1071 0 stevel FKIOCTL, kcred, &rval); 1072 0 stevel if (err) { 1073 0 stevel cmn_err(CE_WARN, "consconfig_prepare_dev: " 1074 0 stevel "can't push streams module \"%s\", error %d", 1075 0 stevel pushmod, err); 1076 0 stevel } 1077 0 stevel } 1078 0 stevel 1079 0 stevel if (dev_type == CONS_MS) 1080 0 stevel return; 1081 0 stevel 1082 0 stevel ASSERT(dev_type == CONS_KBD); 1083 0 stevel 1084 0 stevel err = ldi_ioctl(new_lh, KIOCTRANSABLE, 1085 0 stevel (intptr_t)&kbdtranslatable, FKIOCTL, kcred, &rval); 1086 0 stevel if (err) { 1087 0 stevel cmn_err(CE_WARN, "consconfig_prepare_dev: " 1088 0 stevel "KIOCTRANSABLE failed, error: %d", err); 1089 0 stevel } 1090 0 stevel 1091 0 stevel /* 1092 0 stevel * During boot, dynamic_console_config() will call the 1093 0 stevel * function to enable abort on the console. If the 1094 0 stevel * keyboard is hotplugged after boot, check to see if 1095 0 stevel * the keyboard is the console input. If it is 1096 0 stevel * enable abort on it. 1097 0 stevel */ 1098 0 stevel if (input_type == CONSOLE_LOCAL) 1099 0 stevel (void) consconfig_kbd_abort_enable(new_lh); 1100 0 stevel } 1101 0 stevel 1102 0 stevel /* 1103 0 stevel * consconfig_relink_conskbd: 1104 0 stevel * If new_lh is not NULL it should represent a driver with a 1105 0 stevel * keyboard module pushed on top of it. The driver is then linked 1106 0 stevel * underneath conskbd. the resulting stream will be 1107 0 stevel * wc->conskbd->"new_lh driver". 1108 0 stevel * 1109 0 stevel * If new_lh is NULL, then an unlink operation is done on conskbd 1110 0 stevel * that attempts to unlink the stream specified by *muxid. 1111 0 stevel * the resulting stream will be wc->conskbd. 1112 0 stevel */ 1113 0 stevel static int 1114 0 stevel consconfig_relink_conskbd(cons_state_t *sp, ldi_handle_t new_lh, int *muxid) 1115 0 stevel { 1116 0 stevel int err, rval; 1117 0 stevel int conskbd_relink = 0; 1118 0 stevel 1119 0 stevel ASSERT(muxid != NULL); 1120 0 stevel 1121 0 stevel DPRINTF(DPRINT_L0, "consconfig_relink_conskbd: " 1122 0 stevel "conskbd_lh = %p, new_lh = %p, muxid = %x\n", 1123 0 stevel sp->conskbd_lh, new_lh, *muxid); 1124 0 stevel 1125 0 stevel /* 1126 0 stevel * If conskbd is linked under wc then temporarily unlink it 1127 0 stevel * from under wc so that the new_lh stream may be linked under 1128 0 stevel * conskbd. This has to be done because streams are built bottom 1129 0 stevel * up and linking a stream under conskbd isn't allowed when 1130 0 stevel * conskbd is linked under wc. 1131 0 stevel */ 1132 0 stevel if (sp->conskbd_muxid != -1) { 1133 0 stevel DPRINTF(DPRINT_L0, "unlinking conskbd from under wc\n"); 1134 0 stevel conskbd_relink = 1; 1135 0 stevel err = consconfig_relink_wc(sp, NULL, &sp->conskbd_muxid); 1136 0 stevel if (err) { 1137 0 stevel cmn_err(CE_WARN, "consconfig_relink_conskbd: " 1138 0 stevel "wc unlink failed, error %d", err); 1139 0 stevel return (err); 1140 0 stevel } 1141 0 stevel } 1142 0 stevel 1143 0 stevel if (new_lh != NULL) { 1144 0 stevel DPRINTF(DPRINT_L0, "linking keyboard under conskbd\n"); 1145 0 stevel 1146 0 stevel /* Link the stream represented by new_lh under conskbd */ 1147 0 stevel err = ldi_ioctl(sp->conskbd_lh, I_PLINK, (uintptr_t)new_lh, 1148 6128 edp FKIOCTL, kcred, muxid); 1149 0 stevel if (err != 0) { 1150 0 stevel cmn_err(CE_WARN, "consconfig_relink_conskbd: " 1151 0 stevel "conskbd link failed, error %d", err); 1152 0 stevel goto relink_failed; 1153 0 stevel } 1154 0 stevel } else { 1155 0 stevel DPRINTF(DPRINT_L0, "unlinking keyboard from under conskbd\n"); 1156 0 stevel 1157 0 stevel /* 1158 0 stevel * This will cause the keyboard driver to be closed, 1159 0 stevel * all modules to be popped, and the keyboard vnode released. 1160 0 stevel */ 1161 0 stevel err = ldi_ioctl(sp->conskbd_lh, I_PUNLINK, *muxid, 1162 6128 edp FKIOCTL, kcred, &rval); 1163 0 stevel if (err != 0) { 1164 0 stevel cmn_err(CE_WARN, "consconfig_relink_conskbd: " 1165 0 stevel "conskbd unlink failed, error %d", err); 1166 0 stevel goto relink_failed; 1167 0 stevel } else { 1168 0 stevel *muxid = -1; 1169 0 stevel } 1170 0 stevel 1171 0 stevel consconfig_check_phys_kbd(sp); 1172 0 stevel } 1173 0 stevel 1174 0 stevel if (!conskbd_relink) 1175 0 stevel return (err); 1176 0 stevel 1177 0 stevel /* 1178 0 stevel * Link consbkd back under wc. 1179 0 stevel * 1180 0 stevel * The act of linking conskbd back under wc will cause wc 1181 0 stevel * to query the lower lower layers about their polled I/O 1182 0 stevel * routines. This time the request will succeed because there 1183 0 stevel * is a physical keyboard linked under conskbd. 1184 0 stevel */ 1185 0 stevel DPRINTF(DPRINT_L0, "re-linking conskbd under wc\n"); 1186 0 stevel err = consconfig_relink_wc(sp, sp->conskbd_lh, &sp->conskbd_muxid); 1187 0 stevel if (err) { 1188 0 stevel cmn_err(CE_WARN, "consconfig_relink_conskbd: " 1189 0 stevel "wc link failed, error %d", err); 1190 0 stevel } 1191 0 stevel return (err); 1192 0 stevel 1193 0 stevel relink_failed: 1194 0 stevel if (!conskbd_relink) 1195 0 stevel return (err); 1196 0 stevel 1197 0 stevel /* something went wrong, try to reconnect conskbd back under wc */ 1198 0 stevel DPRINTF(DPRINT_L0, "re-linking conskbd under wc\n"); 1199 0 stevel (void) consconfig_relink_wc(sp, sp->conskbd_lh, &sp->conskbd_muxid); 1200 0 stevel return (err); 1201 0 stevel } 1202 0 stevel 1203 0 stevel /* 1204 0 stevel * consconfig_relink_consms: 1205 0 stevel * If new_lh is not NULL it should represent a driver with a 1206 0 stevel * mouse module pushed on top of it. The driver is then linked 1207 0 stevel * underneath consms. the resulting stream will be 1208 0 stevel * consms->"new_lh driver". 1209 0 stevel * 1210 0 stevel * If new_lh is NULL, then an unlink operation is done on consms 1211 0 stevel * that attempts to unlink the stream specified by *muxid. 1212 0 stevel */ 1213 0 stevel static int 1214 0 stevel consconfig_relink_consms(cons_state_t *sp, ldi_handle_t new_lh, int *muxid) 1215 0 stevel { 1216 0 stevel int err, rval; 1217 0 stevel 1218 0 stevel DPRINTF(DPRINT_L0, "consconfig_relink_consms: " 1219 0 stevel "consms_lh = %p, new_lh = %p, muxid = %x\n", 1220 0 stevel (void *)sp->consms_lh, (void *)new_lh, *muxid); 1221 0 stevel 1222 0 stevel if (new_lh != NULL) { 1223 0 stevel DPRINTF(DPRINT_L0, "linking mouse under consms\n"); 1224 0 stevel 1225 0 stevel /* Link ms/usbms stream underneath consms multiplexor. */ 1226 0 stevel err = ldi_ioctl(sp->consms_lh, I_PLINK, (uintptr_t)new_lh, 1227 0 stevel FKIOCTL, kcred, muxid); 1228 0 stevel if (err != 0) { 1229 0 stevel cmn_err(CE_WARN, "consconfig_relink_consms: " 1230 0 stevel "mouse link failed, error %d", err); 1231 0 stevel } 1232 0 stevel } else { 1233 0 stevel DPRINTF(DPRINT_L0, "unlinking mouse from under consms\n"); 1234 0 stevel 1235 0 stevel /* Tear down the mouse stream */ 1236 0 stevel err = ldi_ioctl(sp->consms_lh, I_PUNLINK, *muxid, 1237 0 stevel FKIOCTL, kcred, &rval); 1238 0 stevel if (err != 0) { 1239 0 stevel cmn_err(CE_WARN, "consconfig_relink_consms: " 1240 0 stevel "mouse unlink failed, error %d", err); 1241 0 stevel } else { 1242 0 stevel *muxid = -1; 1243 0 stevel } 1244 0 stevel } 1245 0 stevel return (err); 1246 0 stevel } 1247 0 stevel 1248 0 stevel static int 1249 5974 jm22469 cons_get_input_type(cons_state_t *sp) 1250 0 stevel { 1251 0 stevel int type; 1252 5974 jm22469 1253 0 stevel /* 1254 0 stevel * Now that we know what all the devices are, we can figure out 1255 0 stevel * what kind of console we have. 1256 0 stevel */ 1257 5974 jm22469 if (sp->cons_stdin_is_kbd) { 1258 0 stevel /* Stdin is from the system keyboard */ 1259 0 stevel type = CONSOLE_LOCAL; 1260 0 stevel } else if ((stdindev != NODEV) && (stdindev == stdoutdev)) { 1261 0 stevel /* 1262 0 stevel * A reliable indicator that we are doing a remote console 1263 0 stevel * is that stdin and stdout are the same. 1264 0 stevel * This is probably a tip line. 1265 0 stevel */ 1266 0 stevel type = CONSOLE_TIP; 1267 0 stevel } else { 1268 0 stevel type = CONSOLE_SERIAL_KEYBOARD; 1269 0 stevel } 1270 0 stevel 1271 0 stevel return (type); 1272 0 stevel } 1273 0 stevel 1274 0 stevel static void 1275 0 stevel consconfig_init_input(cons_state_t *sp) 1276 0 stevel { 1277 0 stevel ldi_handle_t new_lh; 1278 0 stevel dev_t cons_final_dev; 1279 0 stevel int err; 1280 0 stevel 1281 0 stevel cons_final_dev = NODEV; 1282 0 stevel 1283 0 stevel switch (sp->cons_input_type) { 1284 0 stevel case CONSOLE_LOCAL: 1285 0 stevel DPRINTF(DPRINT_L0, "stdin is keyboard\n"); 1286 0 stevel 1287 0 stevel /* 1288 0 stevel * The machine is allowed to boot without a keyboard. 1289 0 stevel * If a user attaches a keyboard later, the keyboard 1290 0 stevel * will be hooked into the console stream with the dacf 1291 0 stevel * functions. 1292 0 stevel * 1293 0 stevel * The only drivers that look at kbbdev are the 1294 0 stevel * serial drivers, which looks at kbdev to see if 1295 0 stevel * they should allow abort on a break. In the absence 1296 0 stevel * of keyboard, the serial drivers won't be attached 1297 0 stevel * for any keyboard instance. 1298 0 stevel */ 1299 0 stevel if (kbddev == NODEV) { 1300 0 stevel /* 1301 0 stevel * If there is a problem with the keyboard 1302 0 stevel * during the driver loading, then the polled 1303 0 stevel * input won't get setup properly if polled 1304 0 stevel * input is needed. This means that if the 1305 0 stevel * keyboard is hotplugged, the keyboard would 1306 0 stevel * work normally, but going down to the 1307 0 stevel * debugger would not work if polled input is 1308 0 stevel * required. This field is set here. The next 1309 0 stevel * time a keyboard is plugged in, the field is 1310 0 stevel * checked in order to give the next keyboard a 1311 0 stevel * chance at being registered for console 1312 0 stevel * input. 1313 0 stevel * 1314 0 stevel * Although this code will rarely be needed, 1315 0 stevel * USB keyboards can be flaky, so this code 1316 0 stevel * will be useful on the occasion that the 1317 0 stevel * keyboard doesn't enumerate when the drivers 1318 0 stevel * are loaded. 1319 0 stevel */ 1320 0 stevel DPRINTF(DPRINT_L2, "Error with console keyboard\n"); 1321 0 stevel sp->cons_keyboard_problem = B_TRUE; 1322 0 stevel } 1323 0 stevel stdindev = kbddev; 1324 0 stevel cons_final_dev = sp->cons_wc_vp->v_rdev; 1325 0 stevel break; 1326 0 stevel 1327 0 stevel case CONSOLE_TIP: 1328 0 stevel DPRINTF(DPRINT_L0, "console input is tty (%s)\n", 1329 0 stevel sp->cons_stdin_path); 1330 0 stevel 1331 0 stevel /* 1332 0 stevel * Console device drivers must be able to output 1333 0 stevel * after being closed. 1334 0 stevel */ 1335 0 stevel rconsvp = i_consconfig_createvp(sp->cons_stdin_path); 1336 3446 mrj if (rconsvp == NULL) { 1337 3446 mrj panic("consconfig_init_input: " 1338 0 stevel "unable to find stdin device (%s)", 1339 0 stevel sp->cons_stdin_path); 1340 3446 mrj /*NOTREACHED*/ 1341 3446 mrj } 1342 0 stevel rconsdev = rconsvp->v_rdev; 1343 0 stevel 1344 0 stevel ASSERT(rconsdev == stdindev); 1345 0 stevel 1346 0 stevel cons_final_dev = rconsdev; 1347 0 stevel break; 1348 0 stevel 1349 0 stevel case CONSOLE_SERIAL_KEYBOARD: 1350 0 stevel DPRINTF(DPRINT_L0, "stdin is serial keyboard\n"); 1351 0 stevel 1352 0 stevel /* 1353 0 stevel * Non-keyboard input device, but not rconsdev. 1354 0 stevel * This is known as the "serial keyboard" case - the 1355 0 stevel * most likely use is someone has a keyboard attached 1356 0 stevel * to a serial port (tip) and still has output on a 1357 0 stevel * framebuffer. 1358 0 stevel * 1359 0 stevel * In this case, the serial driver must be linked 1360 0 stevel * directly beneath wc. Since conskbd was linked 1361 0 stevel * underneath wc above, first we unlink conskbd. 1362 0 stevel */ 1363 0 stevel (void) consconfig_relink_wc(sp, NULL, &sp->conskbd_muxid); 1364 0 stevel sp->conskbd_muxid = -1; 1365 0 stevel 1366 0 stevel /* 1367 0 stevel * Open the serial keyboard, configure it, 1368 0 stevel * and link it underneath wc. 1369 0 stevel */ 1370 0 stevel err = ldi_open_by_name(sp->cons_stdin_path, 1371 0 stevel FREAD|FWRITE|FNOCTTY, kcred, &new_lh, sp->cons_li); 1372 0 stevel if (err == 0) { 1373 0 stevel struct termios termios; 1374 0 stevel int rval; 1375 0 stevel int stdin_muxid; 1376 0 stevel 1377 0 stevel consconfig_prepare_dev(new_lh, 1378 0 stevel "kb", TR_CANNOT, sp->cons_input_type, CONS_KBD); 1379 0 stevel 1380 0 stevel /* Re-set baud rate */ 1381 0 stevel (void) ldi_ioctl(new_lh, TCGETS, (intptr_t)&termios, 1382 6128 edp FKIOCTL, kcred, &rval); 1383 0 stevel 1384 0 stevel /* Set baud rate */ 1385 0 stevel if (consconfig_setmodes(stdindev, &termios) == 0) { 1386 0 stevel err = ldi_ioctl(new_lh, 1387 0 stevel TCSETSF, (intptr_t)&termios, 1388 0 stevel FKIOCTL, kcred, &rval); 1389 0 stevel if (err) { 1390 0 stevel cmn_err(CE_WARN, 1391 0 stevel "consconfig_init_input: " 1392 0 stevel "TCSETSF failed, error %d", err); 1393 0 stevel } 1394 0 stevel } 1395 0 stevel 1396 0 stevel /* 1397 0 stevel * Now link the serial keyboard direcly under wc 1398 0 stevel * we don't save the returned muxid because we 1399 0 stevel * don't support changing/hotplugging the console 1400 0 stevel * keyboard when it is a serial keyboard. 1401 0 stevel */ 1402 0 stevel (void) consconfig_relink_wc(sp, new_lh, &stdin_muxid); 1403 0 stevel 1404 0 stevel (void) ldi_close(new_lh, FREAD|FWRITE, kcred); 1405 0 stevel } 1406 0 stevel 1407 0 stevel cons_final_dev = sp->cons_wc_vp->v_rdev; 1408 0 stevel break; 1409 0 stevel 1410 0 stevel default: 1411 0 stevel panic("consconfig_init_input: " 1412 0 stevel "unsupported console input/output combination"); 1413 0 stevel /*NOTREACHED*/ 1414 0 stevel } 1415 0 stevel 1416 0 stevel /* 1417 0 stevel * Use the redirection device/workstation console pair as the "real" 1418 0 stevel * console if the latter hasn't already been set. 1419 0 stevel * The workstation console driver needs to see rwsconsvp, but 1420 0 stevel * all other access should be through the redirecting driver. 1421 0 stevel */ 1422 0 stevel if (rconsvp == NULL) { 1423 0 stevel consconfig_dprintf(DPRINT_L0, "setup redirection driver\n"); 1424 0 stevel rconsvp = wsconsvp; 1425 0 stevel rconsdev = wsconsvp->v_rdev; 1426 0 stevel } 1427 0 stevel 1428 0 stevel ASSERT(cons_final_dev != NODEV); 1429 0 stevel 1430 0 stevel err = ldi_open_by_dev(&cons_final_dev, OTYP_CHR, FREAD|FWRITE|FNOCTTY, 1431 0 stevel kcred, &new_lh, sp->cons_li); 1432 0 stevel if (err) { 1433 0 stevel panic("consconfig_init_input: " 1434 0 stevel "unable to open console device"); 1435 0 stevel /*NOTREACHED*/ 1436 0 stevel } 1437 0 stevel 1438 0 stevel /* Enable abort on the console */ 1439 0 stevel (void) consconfig_kbd_abort_enable(new_lh); 1440 0 stevel 1441 0 stevel /* Now we must close it to make console logins happy */ 1442 0 stevel (void) ldi_close(new_lh, FREAD|FWRITE, kcred); 1443 0 stevel 1444 0 stevel /* Set up polled input if it is supported by the console device */ 1445 0 stevel if (plat_use_polled_debug()) { 1446 0 stevel /* 1447 0 stevel * In the debug case, register the keyboard polled entry 1448 0 stevel * points, but don't throw the switch in the debugger. This 1449 0 stevel * allows the polled entry points to be checked by hand 1450 0 stevel */ 1451 0 stevel consconfig_setup_polledio(sp, sp->cons_wc_vp->v_rdev); 1452 0 stevel } else { 1453 0 stevel consconfig_setup_polledio(sp, cons_final_dev); 1454 0 stevel } 1455 0 stevel 1456 0 stevel kadb_uses_kernel(); 1457 0 stevel } 1458 0 stevel 1459 0 stevel /* 1460 0 stevel * This function kicks off the console configuration. 1461 0 stevel * Configure keyboard and mouse. Main entry here. 1462 0 stevel */ 1463 0 stevel void 1464 0 stevel dynamic_console_config(void) 1465 0 stevel { 1466 0 stevel /* initialize space.c globals */ 1467 0 stevel stdindev = NODEV; 1468 0 stevel mousedev = NODEV; 1469 0 stevel kbddev = NODEV; 1470 0 stevel fbdev = NODEV; 1471 0 stevel fbvp = NULL; 1472 0 stevel fbdip = NULL; 1473 0 stevel wsconsvp = NULL; 1474 0 stevel rwsconsvp = NULL; 1475 0 stevel rwsconsdev = NODEV; 1476 0 stevel rconsvp = NULL; 1477 0 stevel rconsdev = NODEV; 1478 0 stevel 1479 0 stevel /* Initialize cons_state_t structure and console device paths */ 1480 3446 mrj consconfig_sp = consconfig_state_init(); 1481 3446 mrj ASSERT(consconfig_sp); 1482 0 stevel 1483 0 stevel /* Build upper layer of console stream */ 1484 3446 mrj cons_build_upper_layer(consconfig_sp); 1485 0 stevel 1486 0 stevel /* 1487 0 stevel * Load keyboard/mouse drivers. The dacf routines will 1488 0 stevel * plumb the devices into the console stream 1489 0 stevel * 1490 0 stevel * At the conclusion of the ddi_pathname_to_dev_t calls, the keyboard 1491 0 stevel * and mouse drivers are linked into their respective console 1492 0 stevel * streams if the pathnames are valid. 1493 0 stevel */ 1494 3446 mrj consconfig_load_drivers(consconfig_sp); 1495 5974 jm22469 consconfig_sp->cons_input_type = cons_get_input_type(consconfig_sp); 1496 0 stevel 1497 0 stevel /* 1498 0 stevel * This is legacy special case code for the "cool" virtual console 1499 0 stevel * for the Starfire project. Starfire has a dummy "ssp-serial" 1500 0 stevel * node in the OBP device tree and cvc is a pseudo driver. 1501 0 stevel */ 1502 3446 mrj if (consconfig_sp->cons_stdout_path != NULL && stdindev == NODEV && 1503 3446 mrj strstr(consconfig_sp->cons_stdout_path, "ssp-serial")) { 1504 0 stevel /* 1505 0 stevel * Setup the virtual console driver for Starfire 1506 0 stevel * Note that console I/O will still go through prom for now 1507 0 stevel * (notice we don't open the driver here). The cvc driver 1508 0 stevel * will be activated when /dev/console is opened by init. 1509 0 stevel * During that time, a cvcd daemon will be started that 1510 0 stevel * will open the cvcredirection driver to facilitate 1511 0 stevel * the redirection of console I/O from cvc to cvcd. 1512 0 stevel */ 1513 0 stevel rconsvp = i_consconfig_createvp(CVC_PATH); 1514 0 stevel if (rconsvp == NULL) 1515 10783 Vincent goto done; 1516 0 stevel rconsdev = rconsvp->v_rdev; 1517 10783 Vincent goto done; 1518 0 stevel } 1519 0 stevel 1520 3446 mrj rwsconsvp = consconfig_sp->cons_wc_vp; 1521 3446 mrj rwsconsdev = consconfig_sp->cons_wc_vp->v_rdev; 1522 0 stevel 1523 0 stevel 1524 0 stevel /* initialize framebuffer, console input, and redirection device */ 1525 3446 mrj consconfig_init_framebuffer(consconfig_sp); 1526 3446 mrj consconfig_init_input(consconfig_sp); 1527 0 stevel 1528 10064 James #if !defined(__x86) 1529 10064 James /* initialize virtual console vp for logging if needed */ 1530 10064 James consconfig_virtual_console_vp(consconfig_sp); 1531 10064 James #endif 1532 10064 James 1533 0 stevel DPRINTF(DPRINT_L0, 1534 6128 edp "mousedev %lx, kbddev %lx, fbdev %lx, rconsdev %lx\n", 1535 6128 edp mousedev, kbddev, fbdev, rconsdev); 1536 2191 szhou 1537 8960 Jan flush_deferred_console_buf(); 1538 10783 Vincent done: 1539 10783 Vincent consconfig_sp->cons_initialized = B_TRUE; 1540 0 stevel } 1541 0 stevel 1542 0 stevel 1543 0 stevel /* 1544 0 stevel * Start of DACF interfaces 1545 0 stevel */ 1546 0 stevel 1547 0 stevel /* 1548 0 stevel * Do the real job for keyboard/mouse auto-configuration. 1549 0 stevel */ 1550 0 stevel static int 1551 0 stevel do_config(cons_state_t *sp, cons_prop_t *prop) 1552 0 stevel { 1553 0 stevel ldi_handle_t lh; 1554 0 stevel dev_t dev; 1555 0 stevel int error; 1556 0 stevel 1557 0 stevel ASSERT((prop->cp_type == CONS_KBD) || (prop->cp_type == CONS_MS)); 1558 0 stevel 1559 0 stevel dev = prop->cp_dev; 1560 0 stevel error = ldi_open_by_dev(&dev, OTYP_CHR, 1561 0 stevel FREAD|FWRITE|FNOCTTY, kcred, &lh, sp->cons_li); 1562 0 stevel if (error) { 1563 0 stevel return (DACF_FAILURE); 1564 0 stevel } 1565 0 stevel ASSERT(dev == prop->cp_dev); /* clone not supported */ 1566 0 stevel 1567 0 stevel /* 1568 0 stevel * Prepare the new keyboard/mouse driver 1569 0 stevel * to be linked under conskbd/consms. 1570 0 stevel */ 1571 0 stevel consconfig_prepare_dev(lh, prop->cp_pushmod, TR_CAN, 1572 0 stevel sp->cons_input_type, prop->cp_type); 1573 0 stevel 1574 0 stevel if (prop->cp_type == CONS_KBD) { 1575 0 stevel /* 1576 0 stevel * Tell the physical keyboard driver to send 1577 0 stevel * the abort sequences up to the virtual keyboard 1578 0 stevel * driver so that STOP and A (or F1 and A) 1579 0 stevel * can be applied to different keyboards. 1580 0 stevel */ 1581 0 stevel (void) consconfig_kbd_abort_disable(lh); 1582 0 stevel 1583 0 stevel /* Link the stream underneath conskbd */ 1584 0 stevel error = consconfig_relink_conskbd(sp, lh, &prop->cp_muxid); 1585 0 stevel } else { 1586 0 stevel /* Link the stream underneath consms */ 1587 0 stevel error = consconfig_relink_consms(sp, lh, &prop->cp_muxid); 1588 0 stevel } 1589 0 stevel 1590 0 stevel /* 1591 0 stevel * At this point, the stream is: 1592 0 stevel * for keyboard: wc->conskbd->["pushmod"->"kbd_vp driver"] 1593 0 stevel * for mouse: consms->["module_name"->]"mouse_avp driver" 1594 0 stevel */ 1595 0 stevel 1596 0 stevel /* Close the driver stream, it will stay linked under conskbd */ 1597 0 stevel (void) ldi_close(lh, FREAD|FWRITE, kcred); 1598 0 stevel 1599 0 stevel if (error) { 1600 0 stevel return (DACF_FAILURE); 1601 0 stevel } 1602 0 stevel 1603 0 stevel return (DACF_SUCCESS); 1604 0 stevel } 1605 0 stevel 1606 0 stevel static int 1607 0 stevel do_unconfig(cons_state_t *sp, cons_prop_t *prop) 1608 0 stevel { 1609 0 stevel ASSERT((prop->cp_type == CONS_KBD) || (prop->cp_type == CONS_MS)); 1610 0 stevel 1611 0 stevel if (prop->cp_type == CONS_KBD) 1612 0 stevel return (consconfig_relink_conskbd(sp, NULL, &prop->cp_muxid)); 1613 0 stevel else 1614 0 stevel return (consconfig_relink_consms(sp, NULL, &prop->cp_muxid)); 1615 0 stevel } 1616 0 stevel 1617 0 stevel static int 1618 0 stevel kb_ms_config(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int type) 1619 0 stevel { 1620 0 stevel major_t major; 1621 0 stevel minor_t minor; 1622 0 stevel dev_t dev; 1623 0 stevel dev_info_t *dip; 1624 0 stevel cons_state_t *sp; 1625 0 stevel cons_prop_t *prop; 1626 0 stevel const char *pushmod; 1627 0 stevel 1628 0 stevel /* 1629 0 stevel * Retrieve the state information 1630 0 stevel * Some platforms may use the old-style "consconfig" to configure 1631 0 stevel * console stream modules but may also support devices that happen 1632 0 stevel * to match a rule in /etc/dacf.conf. This will cause a problem 1633 0 stevel * since the console state structure will not be initialized. 1634 0 stevel * In that case, these entry points should silently fail and 1635 0 stevel * permit console to be plumbed later in boot. 1636 0 stevel */ 1637 0 stevel if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL) 1638 0 stevel return (DACF_FAILURE); 1639 0 stevel 1640 0 stevel dip = dacf_devinfo_node(minor_hdl); 1641 0 stevel major = ddi_driver_major(dip); 1642 7009 cth ASSERT(major != DDI_MAJOR_T_NONE); 1643 0 stevel minor = dacf_minor_number(minor_hdl); 1644 0 stevel dev = makedevice(major, minor); 1645 0 stevel ASSERT(dev != NODEV); 1646 0 stevel 1647 0 stevel DPRINTF(DPRINT_L0, "driver name = \"%s\", dev = 0x%lx, major = 0x%x\n", 1648 0 stevel (char *)dacf_driver_name(minor_hdl), dev, major); 1649 0 stevel 1650 0 stevel /* Access to the global variables is synchronized */ 1651 0 stevel mutex_enter(&sp->cons_lock); 1652 0 stevel 1653 0 stevel /* 1654 0 stevel * Check if the keyboard/mouse has already configured. 1655 0 stevel */ 1656 0 stevel if (consconfig_find_dev(sp, dev) != NULL) { 1657 0 stevel mutex_exit(&sp->cons_lock); 1658 0 stevel return (DACF_SUCCESS); 1659 0 stevel } 1660 0 stevel 1661 0 stevel prop = kmem_zalloc(sizeof (cons_prop_t), KM_SLEEP); 1662 0 stevel 1663 0 stevel /* Config the new keyboard/mouse device */ 1664 0 stevel prop->cp_dev = dev; 1665 0 stevel 1666 0 stevel pushmod = dacf_get_arg(arg_hdl, "pushmod"); 1667 0 stevel prop->cp_pushmod = i_ddi_strdup((char *)pushmod, KM_SLEEP); 1668 0 stevel 1669 0 stevel prop->cp_type = type; 1670 0 stevel if (do_config(sp, prop) != DACF_SUCCESS) { 1671 0 stevel /* 1672 0 stevel * The keyboard/mouse node failed to open. 1673 0 stevel * Set the major and minor numbers to 0 so 1674 0 stevel * kb_unconfig/ms_unconfig won't unconfigure 1675 0 stevel * this node if it is detached. 1676 0 stevel */ 1677 0 stevel mutex_exit(&sp->cons_lock); 1678 0 stevel consconfig_free_prop(prop); 1679 0 stevel return (DACF_FAILURE); 1680 0 stevel } 1681 0 stevel 1682 0 stevel consconfig_add_dev(sp, prop); 1683 0 stevel 1684 0 stevel /* 1685 0 stevel * See if there was a problem with the console keyboard during boot. 1686 0 stevel * If so, try to register polled input for this keyboard. 1687 0 stevel */ 1688 0 stevel if ((type == CONS_KBD) && (sp->cons_keyboard_problem)) { 1689 0 stevel consconfig_setup_polledio(sp, sp->cons_wc_vp->v_rdev); 1690 0 stevel sp->cons_keyboard_problem = B_FALSE; 1691 0 stevel } 1692 0 stevel 1693 0 stevel /* Prevent autodetach due to memory pressure */ 1694 0 stevel (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, DDI_NO_AUTODETACH, 1); 1695 0 stevel 1696 0 stevel mutex_exit(&sp->cons_lock); 1697 0 stevel 1698 0 stevel return (DACF_SUCCESS); 1699 0 stevel } 1700 0 stevel 1701 0 stevel static int 1702 0 stevel kb_ms_unconfig(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl) 1703 0 stevel { 1704 0 stevel _NOTE(ARGUNUSED(arg_hdl)) 1705 0 stevel 1706 0 stevel major_t major; 1707 0 stevel minor_t minor; 1708 0 stevel dev_t dev; 1709 0 stevel dev_info_t *dip; 1710 0 stevel cons_state_t *sp; 1711 0 stevel cons_prop_t *prop; 1712 0 stevel 1713 0 stevel /* 1714 0 stevel * Retrieve the state information 1715 0 stevel * So if there isn't a state available, then this entry point just 1716 0 stevel * returns. See note in kb_config(). 1717 0 stevel */ 1718 0 stevel if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL) 1719 0 stevel return (DACF_SUCCESS); 1720 0 stevel 1721 0 stevel dip = dacf_devinfo_node(minor_hdl); 1722 0 stevel major = ddi_driver_major(dip); 1723 7009 cth ASSERT(major != DDI_MAJOR_T_NONE); 1724 0 stevel minor = dacf_minor_number(minor_hdl); 1725 0 stevel dev = makedevice(major, minor); 1726 0 stevel ASSERT(dev != NODEV); 1727 0 stevel 1728 0 stevel /* 1729 0 stevel * Check if the keyboard/mouse that is being detached 1730 0 stevel * is the console keyboard/mouse or not. 1731 0 stevel */ 1732 0 stevel mutex_enter(&sp->cons_lock); 1733 0 stevel if ((prop = consconfig_find_dev(sp, dev)) == NULL) { 1734 0 stevel mutex_exit(&sp->cons_lock); 1735 0 stevel return (DACF_SUCCESS); 1736 0 stevel } 1737 0 stevel 1738 0 stevel /* 1739 0 stevel * This dev may be opened physically and then hotplugged out. 1740 0 stevel */ 1741 0 stevel if (prop->cp_muxid != -1) { 1742 0 stevel (void) do_unconfig(sp, prop); 1743 0 stevel consconfig_rem_dev(sp, dev); 1744 0 stevel } 1745 0 stevel 1746 0 stevel mutex_exit(&sp->cons_lock); 1747 0 stevel 1748 0 stevel return (DACF_SUCCESS); 1749 0 stevel } 1750 0 stevel 1751 0 stevel /* 1752 0 stevel * This is the post-attach / pre-detach action function for the keyboard 1753 0 stevel * and mouse. This function is associated with a node type in /etc/dacf.conf. 1754 0 stevel */ 1755 0 stevel static int 1756 0 stevel kb_config(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags) 1757 0 stevel { 1758 0 stevel _NOTE(ARGUNUSED(flags)) 1759 0 stevel 1760 0 stevel return (kb_ms_config(minor_hdl, arg_hdl, CONS_KBD)); 1761 0 stevel } 1762 0 stevel 1763 0 stevel static int 1764 0 stevel ms_config(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags) 1765 0 stevel { 1766 0 stevel _NOTE(ARGUNUSED(flags)) 1767 0 stevel 1768 0 stevel return (kb_ms_config(minor_hdl, arg_hdl, CONS_MS)); 1769 0 stevel } 1770 0 stevel 1771 0 stevel static int 1772 0 stevel kb_unconfig(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags) 1773 0 stevel { 1774 0 stevel _NOTE(ARGUNUSED(flags)) 1775 0 stevel 1776 0 stevel return (kb_ms_unconfig(minor_hdl, arg_hdl)); 1777 0 stevel } 1778 0 stevel 1779 0 stevel static int 1780 0 stevel ms_unconfig(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags) 1781 0 stevel { 1782 0 stevel _NOTE(ARGUNUSED(flags)) 1783 0 stevel 1784 0 stevel return (kb_ms_unconfig(minor_hdl, arg_hdl)); 1785 0 stevel } 1786 0 stevel 1787 0 stevel /* 1788 0 stevel * consconfig_link and consconfig_unlink are provided to support 1789 0 stevel * direct access to physical keyboard/mouse underlying conskbd/ 1790 0 stevel * consms. 1791 0 stevel * When the keyboard/mouse is opened physically via its device 1792 0 stevel * file, it will be unlinked from the virtual one, and when it 1793 0 stevel * is closed physically, it will be linked back under the virtual 1794 0 stevel * one. 1795 0 stevel */ 1796 0 stevel void 1797 0 stevel consconfig_link(major_t major, minor_t minor) 1798 0 stevel { 1799 0 stevel char buf[MAXPATHLEN]; 1800 0 stevel dev_t dev; 1801 0 stevel cons_state_t *sp; 1802 0 stevel cons_prop_t *prop; 1803 0 stevel 1804 0 stevel if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL) 1805 0 stevel return; 1806 0 stevel 1807 0 stevel dev = makedevice(major, minor); 1808 0 stevel ASSERT(dev != NODEV); 1809 0 stevel 1810 0 stevel mutex_enter(&sp->cons_lock); 1811 0 stevel if ((prop = consconfig_find_dev(sp, dev)) == NULL) { 1812 0 stevel mutex_exit(&sp->cons_lock); 1813 0 stevel return; 1814 0 stevel } 1815 0 stevel 1816 0 stevel if (do_config(sp, prop) != DACF_SUCCESS) { 1817 0 stevel (void) ddi_dev_pathname(dev, 0, buf); 1818 0 stevel if (prop->cp_type == CONS_KBD) 1819 0 stevel cmn_err(CE_WARN, "Failed to relink the keyboard " 1820 0 stevel "(%s) underneath virtual keyboard", buf); 1821 0 stevel else 1822 0 stevel cmn_err(CE_WARN, "Failed to relink the mouse " 1823 0 stevel "(%s) underneath virtual mouse", buf); 1824 0 stevel consconfig_rem_dev(sp, dev); 1825 0 stevel } 1826 0 stevel 1827 0 stevel mutex_exit(&sp->cons_lock); 1828 0 stevel } 1829 0 stevel 1830 0 stevel 1831 0 stevel int 1832 0 stevel consconfig_unlink(major_t major, minor_t minor) 1833 0 stevel { 1834 0 stevel dev_t dev; 1835 0 stevel cons_state_t *sp; 1836 0 stevel cons_prop_t *prop; 1837 0 stevel int error; 1838 0 stevel 1839 0 stevel if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL) 1840 0 stevel return (DACF_SUCCESS); 1841 0 stevel 1842 0 stevel dev = makedevice(major, minor); 1843 0 stevel ASSERT(dev != NODEV); 1844 0 stevel 1845 0 stevel mutex_enter(&sp->cons_lock); 1846 0 stevel if ((prop = consconfig_find_dev(sp, dev)) == NULL) { 1847 0 stevel mutex_exit(&sp->cons_lock); 1848 0 stevel return (DACF_FAILURE); 1849 0 stevel } 1850 0 stevel 1851 0 stevel error = do_unconfig(sp, prop); 1852 0 stevel 1853 0 stevel /* 1854 0 stevel * Keep this dev on the list, for this dev is still online. 1855 0 stevel */ 1856 0 stevel mutex_exit(&sp->cons_lock); 1857 0 stevel 1858 0 stevel return (error); 1859 0 stevel } 1860 0 stevel 1861 0 stevel /* 1862 0 stevel * Routine to set baud rate, bits-per-char, parity and stop bits 1863 0 stevel * on the console line when necessary. 1864 0 stevel */ 1865 0 stevel static int 1866 0 stevel consconfig_setmodes(dev_t dev, struct termios *termiosp) 1867 0 stevel { 1868 0 stevel char buf[MAXPATHLEN]; 1869 0 stevel int len = MAXPATHLEN; 1870 0 stevel char name[16]; 1871 6128 edp int ppos, i; 1872 0 stevel char *path; 1873 0 stevel dev_t tdev; 1874 0 stevel 1875 0 stevel /* 1876 0 stevel * First, search for a devalias which matches this dev_t. 1877 0 stevel * Try all of ttya through ttyz until no such alias 1878 0 stevel */ 1879 0 stevel (void) strcpy(name, "ttya"); 1880 0 stevel for (i = 0; i < ('z'-'a'); i++) { 1881 0 stevel name[3] = 'a' + i; /* increment device name */ 1882 0 stevel path = get_alias(name, buf); 1883 0 stevel if (path == NULL) 1884 0 stevel return (1); 1885 0 stevel 1886 0 stevel tdev = ddi_pathname_to_dev_t(path); 1887 0 stevel if (tdev == dev) 1888 0 stevel break; /* Exit loop if found */ 1889 0 stevel } 1890 0 stevel 1891 0 stevel if (i >= ('z'-'a')) 1892 0 stevel return (1); /* If we didn't find it, return */ 1893 0 stevel 1894 0 stevel /* 1895 0 stevel * Now that we know which "tty" this corresponds to, retrieve 1896 0 stevel * the "ttya-mode" options property, which tells us how to configure 1897 0 stevel * the line. 1898 0 stevel */ 1899 0 stevel (void) strcpy(name, "ttya-mode"); /* name of option we want */ 1900 0 stevel name[3] = 'a' + i; /* Adjust to correct line */ 1901 0 stevel 1902 0 stevel if (ddi_getlongprop_buf(DDI_DEV_T_ANY, ddi_root_node(), 0, name, 1903 0 stevel buf, &len) != DDI_PROP_SUCCESS) 1904 0 stevel return (1); /* if no such option, just return */ 1905 6128 edp 1906 6128 edp /* 1907 6128 edp * The IEEE 1275 standard specifies that /aliases string property 1908 9674 George * values should be null-terminated. Unfortunately the reality 1909 6128 edp * is that most aren't and the OBP can't easily be modified to 1910 6128 edp * add null termination to these strings. So we'll add the 1911 6128 edp * null termination here. If the string already contains a 1912 6128 edp * null termination character then that's ok too because we'll 1913 6128 edp * just be adding a second one. 1914 6128 edp */ 1915 6128 edp buf[len] = '\0'; 1916 0 stevel 1917 0 stevel /* Clear out options we will be setting */ 1918 0 stevel termiosp->c_cflag &= 1919 0 stevel ~(CSIZE | CBAUD | CBAUDEXT | PARODD | PARENB | CSTOPB); 1920 9674 George 1921 9674 George /* Clear options which potentially conflict with new settings */ 1922 9674 George termiosp->c_cflag &= ~(CIBAUD | CIBAUDEXT); 1923 0 stevel 1924 0 stevel /* 1925 0 stevel * Now, parse the string. Wish I could use sscanf(). 1926 0 stevel * Format 9600,8,n,1,- 1927 0 stevel * baud rate, bits-per-char, parity, stop-bits, ignored 1928 0 stevel */ 1929 0 stevel for (ppos = 0; ppos < (MAXPATHLEN-8); ppos++) { /* Find first comma */ 1930 0 stevel if ((buf[ppos] == 0) || (buf[ppos] == ',')) 1931 0 stevel break; 1932 0 stevel } 1933 0 stevel 1934 0 stevel if (buf[ppos] != ',') { 1935 0 stevel cmn_err(CE_WARN, "consconfig_setmodes: " 1936 0 stevel "invalid mode string %s", buf); 1937 0 stevel return (1); 1938 0 stevel } 1939 0 stevel 1940 0 stevel for (i = 0; i < MAX_SPEEDS; i++) { 1941 0 stevel if (strncmp(buf, speedtab[i].name, ppos) == 0) 1942 6128 edp break; 1943 0 stevel } 1944 0 stevel 1945 0 stevel if (i >= MAX_SPEEDS) { 1946 0 stevel cmn_err(CE_WARN, 1947 6128 edp "consconfig_setmodes: unrecognized speed in %s", buf); 1948 0 stevel return (1); 1949 0 stevel } 1950 0 stevel 1951 0 stevel /* Found the baud rate, set it */ 1952 0 stevel termiosp->c_cflag |= speedtab[i].code & CBAUD; 1953 0 stevel if (speedtab[i].code > 16) /* cfsetospeed! */ 1954 0 stevel termiosp->c_cflag |= CBAUDEXT; 1955 0 stevel 1956 0 stevel /* Set bits per character */ 1957 0 stevel switch (buf[ppos+1]) { 1958 0 stevel case '8': 1959 0 stevel termiosp->c_cflag |= CS8; 1960 0 stevel break; 1961 0 stevel case '7': 1962 0 stevel termiosp->c_cflag |= CS7; 1963 0 stevel break; 1964 0 stevel default: 1965 0 stevel cmn_err(CE_WARN, 1966 0 stevel "consconfig_setmodes: illegal bits-per-char %s", buf); 1967 0 stevel return (1); 1968 0 stevel } 1969 0 stevel 1970 0 stevel /* Set parity */ 1971 0 stevel switch (buf[ppos+3]) { 1972 0 stevel case 'o': 1973 0 stevel termiosp->c_cflag |= PARENB | PARODD; 1974 0 stevel break; 1975 0 stevel case 'e': 1976 0 stevel termiosp->c_cflag |= PARENB; /* enabled, not odd */ 1977 0 stevel break; 1978 0 stevel case 'n': 1979 0 stevel break; /* not enabled. */ 1980 0 stevel default: 1981 0 stevel cmn_err(CE_WARN, "consconfig_setmodes: illegal parity %s", buf); 1982 0 stevel return (1); 1983 0 stevel } 1984 0 stevel 1985 0 stevel /* Set stop bits */ 1986 0 stevel switch (buf[ppos+5]) { 1987 0 stevel case '1': 1988 0 stevel break; /* No extra stop bit */ 1989 0 stevel case '2': 1990 0 stevel termiosp->c_cflag |= CSTOPB; /* 1 extra stop bit */ 1991 0 stevel break; 1992 0 stevel default: 1993 0 stevel cmn_err(CE_WARN, "consconfig_setmodes: " 1994 0 stevel "illegal stop bits %s", buf); 1995 0 stevel return (1); 1996 0 stevel } 1997 0 stevel 1998 0 stevel return (0); 1999 0 stevel } 2000 0 stevel 2001 0 stevel /* 2002 0 stevel * Check to see if underlying keyboard devices are still online, 2003 0 stevel * if any one is offline now, unlink it. 2004 0 stevel */ 2005 0 stevel static void 2006 0 stevel consconfig_check_phys_kbd(cons_state_t *sp) 2007 0 stevel { 2008 0 stevel ldi_handle_t kb_lh; 2009 0 stevel cons_prop_t *prop; 2010 0 stevel int error; 2011 0 stevel int rval; 2012 0 stevel 2013 0 stevel for (prop = sp->cons_km_prop; prop; prop = prop->cp_next) { 2014 0 stevel if ((prop->cp_type != CONS_KBD) || (prop->cp_muxid == -1)) 2015 0 stevel continue; 2016 0 stevel 2017 0 stevel error = ldi_open_by_dev(&prop->cp_dev, OTYP_CHR, 2018 0 stevel FREAD|FWRITE|FNOCTTY, kcred, &kb_lh, sp->cons_li); 2019 0 stevel 2020 0 stevel if (error) { 2021 0 stevel (void) ldi_ioctl(sp->conskbd_lh, I_PUNLINK, 2022 0 stevel prop->cp_muxid, FKIOCTL, kcred, &rval); 2023 0 stevel prop->cp_dev = NODEV; 2024 0 stevel } else { 2025 0 stevel (void) ldi_close(kb_lh, FREAD|FWRITE, kcred); 2026 0 stevel } 2027 0 stevel } 2028 0 stevel 2029 0 stevel /* 2030 0 stevel * Remove all disconnected keyboards, 2031 0 stevel * whose dev is turned into NODEV above. 2032 0 stevel */ 2033 0 stevel consconfig_rem_dev(sp, NODEV); 2034 0 stevel } 2035 0 stevel 2036 0 stevel /* 2037 0 stevel * Remove devices according to dev, which may be NODEV 2038 0 stevel */ 2039 0 stevel static void 2040 0 stevel consconfig_rem_dev(cons_state_t *sp, dev_t dev) 2041 0 stevel { 2042 0 stevel cons_prop_t *prop; 2043 0 stevel cons_prop_t *prev_prop; 2044 0 stevel cons_prop_t *tmp_prop; 2045 0 stevel cons_prop_t *head_prop; 2046 0 stevel 2047 0 stevel head_prop = NULL; 2048 0 stevel prev_prop = NULL; 2049 0 stevel for (prop = sp->cons_km_prop; prop != NULL; ) { 2050 0 stevel if (prop->cp_dev == dev) { 2051 0 stevel tmp_prop = prop->cp_next; 2052 0 stevel consconfig_free_prop(prop); 2053 0 stevel prop = tmp_prop; 2054 0 stevel if (prev_prop) 2055 0 stevel prev_prop->cp_next = prop; 2056 0 stevel } else { 2057 0 stevel if (head_prop == NULL) 2058 0 stevel head_prop = prop; 2059 0 stevel prev_prop = prop; 2060 0 stevel prop = prop->cp_next; 2061 0 stevel } 2062 0 stevel } 2063 0 stevel sp->cons_km_prop = head_prop; 2064 0 stevel } 2065 0 stevel 2066 0 stevel /* 2067 0 stevel * Add a dev according to prop 2068 0 stevel */ 2069 0 stevel static void 2070 0 stevel consconfig_add_dev(cons_state_t *sp, cons_prop_t *prop) 2071 0 stevel { 2072 0 stevel prop->cp_next = sp->cons_km_prop; 2073 0 stevel sp->cons_km_prop = prop; 2074 0 stevel } 2075 0 stevel 2076 0 stevel /* 2077 0 stevel * Find a device from our list according to dev 2078 0 stevel */ 2079 0 stevel static cons_prop_t * 2080 0 stevel consconfig_find_dev(cons_state_t *sp, dev_t dev) 2081 0 stevel { 2082 0 stevel cons_prop_t *prop; 2083 0 stevel 2084 0 stevel for (prop = sp->cons_km_prop; prop; prop = prop->cp_next) { 2085 0 stevel if (prop->cp_dev == dev) 2086 0 stevel break; 2087 0 stevel } 2088 0 stevel 2089 0 stevel return (prop); 2090 0 stevel } 2091 0 stevel 2092 0 stevel /* 2093 0 stevel * Free a cons prop associated with a keyboard or mouse 2094 0 stevel */ 2095 0 stevel static void 2096 0 stevel consconfig_free_prop(cons_prop_t *prop) 2097 0 stevel { 2098 0 stevel if (prop->cp_pushmod) 2099 0 stevel kmem_free(prop->cp_pushmod, strlen(prop->cp_pushmod) + 1); 2100 0 stevel kmem_free(prop, sizeof (cons_prop_t)); 2101 0 stevel } 2102 2191 szhou 2103 2191 szhou /* 2104 8960 Jan * The early boot code can't print to a usb serial device or the 2105 8960 Jan * graphical boot screen. 2106 8960 Jan * 2107 8960 Jan * The early boot messages are saved in a buffer at the address indicated 2108 8960 Jan * by "deferred-console-buf" This function flushes the message to the 2109 8960 Jan * current console now that it is set up. 2110 2191 szhou */ 2111 2191 szhou static void 2112 8960 Jan flush_deferred_console_buf(void) 2113 2191 szhou { 2114 2191 szhou int rval; 2115 2191 szhou vnode_t *vp; 2116 8960 Jan uint_t defcons_buf; 2117 8960 Jan char *kc, *bc, *defcons_kern_buf; 2118 2191 szhou 2119 8960 Jan /* defcons_buf is in low memory, so an int works here */ 2120 8960 Jan defcons_buf = ddi_prop_get_int(DDI_DEV_T_ANY, ddi_root_node(), 2121 8960 Jan DDI_PROP_DONTPASS, "deferred-console-buf", 0); 2122 2191 szhou 2123 8960 Jan if (defcons_buf == 0) 2124 2191 szhou return; 2125 2191 szhou 2126 2191 szhou /* 2127 2191 szhou * After consconfig() and before userland opens /dev/sysmsg, 2128 2191 szhou * console I/O is goes to polled I/O entry points. 2129 2191 szhou * 2130 2191 szhou * If usb-serial doesn't implement polled I/O, we need 2131 2191 szhou * to open /dev/console now to get kernel console I/O to work. 2132 2191 szhou * We also push ttcompat and ldterm explicitly to get the 2133 2191 szhou * correct output format (autopush isn't set up yet). We 2134 2191 szhou * ignore push errors because they are non-fatal. 2135 2191 szhou * Note that opening /dev/console causes rconsvp to be 2136 2191 szhou * opened as well. 2137 2191 szhou */ 2138 2191 szhou if (cons_polledio == NULL) { 2139 2191 szhou if (vn_open("/dev/console", UIO_SYSSPACE, FWRITE | FNOCTTY, 2140 2191 szhou 0, &vp, 0, 0) != 0) 2141 2191 szhou return; 2142 2191 szhou 2143 2191 szhou if (rconsvp) { 2144 2191 szhou (void) strioctl(rconsvp, __I_PUSH_NOCTTY, 2145 2191 szhou (intptr_t)"ldterm", FKIOCTL, K_TO_K, kcred, &rval); 2146 2191 szhou (void) strioctl(rconsvp, __I_PUSH_NOCTTY, 2147 2191 szhou (intptr_t)"ttcompat", FKIOCTL, K_TO_K, 2148 2191 szhou kcred, &rval); 2149 2191 szhou } 2150 2191 szhou } 2151 2191 szhou 2152 2191 szhou /* 2153 2191 szhou * Copy message to a kernel buffer. Various kernel routines 2154 2191 szhou * expect buffer to be above kernelbase 2155 2191 szhou */ 2156 9354 Tim kc = defcons_kern_buf = kmem_zalloc(MMU_PAGESIZE, KM_SLEEP); 2157 8960 Jan bc = (char *)(uintptr_t)defcons_buf; 2158 2191 szhou while (*kc++ = *bc++) 2159 2191 szhou ; 2160 8960 Jan console_printf("%s", defcons_kern_buf); 2161 2191 szhou 2162 8960 Jan kmem_free(defcons_kern_buf, MMU_PAGESIZE); 2163 2191 szhou } 2164 7688 Aaron 2165 7688 Aaron boolean_t 2166 7688 Aaron consconfig_console_is_tipline(void) 2167 7688 Aaron { 2168 7688 Aaron cons_state_t *sp; 2169 7688 Aaron 2170 7688 Aaron if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL) 2171 7688 Aaron return (B_FALSE); 2172 7688 Aaron 2173 7688 Aaron if (sp->cons_input_type == CONSOLE_TIP) 2174 7688 Aaron return (B_TRUE); 2175 7688 Aaron 2176 7688 Aaron return (B_FALSE); 2177 7688 Aaron } 2178 10783 Vincent 2179 10783 Vincent boolean_t 2180 10783 Vincent consconfig_dacf_initialized(void) 2181 10783 Vincent { 2182 10783 Vincent cons_state_t *sp; 2183 10783 Vincent 2184 10783 Vincent if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL) 2185 10783 Vincent return (B_FALSE); 2186 10783 Vincent 2187 10783 Vincent return (sp->cons_initialized); 2188 10783 Vincent } 2189