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