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