4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * This module performs two functions. First, it kicks off the driver loading
29 * of the console devices during boot in dynamic_console_config().
30 * The loading of the drivers for the console devices triggers the
31 * additional device autoconfiguration to link the drivers into the keyboard
32 * and mouse console streams.
34 * The second function of this module is to provide the dacf functions
35 * to be called after a driver has attached and before it detaches. For
36 * example, a driver associated with the keyboard will have kb_config called
37 * after the driver attaches and kb_unconfig before it detaches. Similar
38 * configuration actions are performed on behalf of minor nodes representing
39 * mice. The configuration functions for the attach case take a module
40 * name as a parameter. The module is pushed on top of the driver during
43 * Although the dacf framework is used to configure all keyboards and mice,
44 * its primary function is to allow keyboard and mouse hotplugging.
46 * This module supports multiple keyboards and mice at the same time.
48 * From the kernel perspective, there are roughly three different possible
49 * console configurations. Across these three configurations, the following
50 * elements are constant:
51 * wsconsvp = IWSCN_PATH
55 * The "->" syntax indicates that the streams device on the right is
56 * linked under the streams device on the left.
58 * The following lists how the system is configured for different setups:
60 * stdin is a local keyboard. use stdin and stdout as the console.
61 * sp->cons_input_type = CONSOLE_LOCAL
62 * rconsvp = IWSCN_PATH
63 * wc -> conskbd -> kbddev
65 * stdin is not a keyboard and stdin is the same as stdout.
66 * assume we running on a tip line and use stdin/stdout as the console.
67 * sp->cons_input_type = CONSOLE_TIP
68 * rconsvp = (stdindev/stdoutdev)
69 * wc -> conskbd -> kbddev
71 * stdin is not a keyboard device and it's not the same as stdout.
72 * assume we have a serial keyboard hooked up and use it along with
73 * stdout as the console.
74 * sp->cons_input_type = CONSOLE_SERIAL_KEYBOARD
75 * rconsvp = IWSCN_PATH
80 * The above is all true except for one possible Intel configuration.
81 * If stdin is set to a local keyboard but stdout is set to something
82 * other than the local display (a tip port for example) stdout will
83 * still go to the local display. This is an artifact of the console
84 * implementation on intel.
87 #include <sys/types.h>
88 #include <sys/param.h>
89 #include <sys/cmn_err.h>
92 #include <sys/vnode.h>
93 #include <sys/pathname.h>
94 #include <sys/systm.h>
96 #include <sys/stropts.h>
97 #include <sys/stream.h>
98 #include <sys/strsubr.h>
100 #include <sys/consdev.h>
101 #include <sys/console.h>
102 #include <sys/wscons.h>
103 #include <sys/kbio.h>
104 #include <sys/debug.h>
105 #include <sys/reboot.h>
106 #include <sys/termios.h>
109 #include <sys/sunddi.h>
110 #include <sys/sunldi.h>
111 #include <sys/sunndi.h>
112 #include <sys/ndi_impldefs.h>
113 #include <sys/modctl.h>
114 #include <sys/ddi_impldefs.h>
115 #include <sys/ddi_implfuncs.h>
116 #include <sys/promif.h>
117 #include <sys/fs/snode.h>
119 #include <sys/errno.h>
120 #include <sys/devops.h>
121 #include <sys/note.h>
123 #include <sys/tem_impl.h>
124 #include <sys/polled_io.h>
125 #include <sys/kmem.h>
126 #include <sys/dacf.h>
127 #include <sys/consconfig_dacf.h>
128 #include <sys/consplat.h>
130 #include <sys/disp.h>
133 * External global variables
135 extern vnode_t
*rconsvp
;
136 extern dev_t rwsconsdev
;
141 extern uintptr_t space_fetch(char *key
);
142 extern int space_store(char *key
, uintptr_t ptr
);
147 static int kb_config(dacf_infohdl_t
, dacf_arghdl_t
, int);
148 static int kb_unconfig(dacf_infohdl_t
, dacf_arghdl_t
, int);
149 static int ms_config(dacf_infohdl_t
, dacf_arghdl_t
, int);
150 static int ms_unconfig(dacf_infohdl_t
, dacf_arghdl_t
, int);
155 static int consconfig_setmodes(dev_t dev
, struct termios
*termiosp
);
156 static void consconfig_check_phys_kbd(cons_state_t
*);
157 static void consconfig_rem_dev(cons_state_t
*, dev_t
);
158 static void consconfig_add_dev(cons_state_t
*, cons_prop_t
*);
159 static cons_prop_t
*consconfig_find_dev(cons_state_t
*, dev_t
);
160 static void consconfig_free_prop(cons_prop_t
*prop
);
161 static void flush_deferred_console_buf(void);
165 * On supported configurations, the firmware defines the keyboard and mouse
166 * paths. However, during USB development, it is useful to be able to use
167 * the USB keyboard and mouse on machines without full USB firmware support.
168 * These variables may be set in /etc/system according to a machine's
169 * USB configuration. This module will override the firmware's values
173 * The master copies of these variables in the misc/consconfig module.
174 * The reason for this is historic. In versions of solaris up to and
175 * including solaris 9 the conscole configuration code was split into a
176 * seperate sparc and intel version. These variables were defined
177 * in misc/consconfig on sparc and dacf/consconfig_dacf on intel.
179 * Unfortunatly the sparc variables were well documented.
180 * So to aviod breaking either sparc or intel we'll declare the variables
181 * in both modules. This will allow any /etc/system entries that
182 * users may have to continue working.
184 * The variables in misc/consconfig will take precedence over the variables
185 * found in this file. Since we eventually want to remove the variables
186 * local to this this file, if the user set them we'll emmit an error
187 * message telling them they need to set the variables in misc/consconfig
190 static char *usb_kb_path
= NULL
;
191 static char *usb_ms_path
= NULL
;
194 * Access functions in the misc/consconfig module used to retrieve the
195 * values of it local usb_kb_path and usb_ms_path variables
197 extern char *consconfig_get_usb_kb_path();
198 extern char *consconfig_get_usb_ms_path();
201 * Local variables used to store the value of the usb_kb_path and
202 * usb_ms_path variables found in misc/consconfig
204 static char *consconfig_usb_kb_path
= NULL
;
205 static char *consconfig_usb_ms_path
= NULL
;
210 static dev_t stdoutdev
;
211 static cons_state_t
*consconfig_sp
;
214 * consconfig_errlevel: debug verbosity; smaller numbers are more
217 int consconfig_errlevel
= DPRINT_L3
;
222 static struct speed
{
226 {"0", B0
}, {"50", B50
}, {"75", B75
},
227 {"110", B110
}, {"134", B134
}, {"150", B150
},
228 {"200", B200
}, {"300", B300
}, {"600", B600
},
229 {"1200", B1200
}, {"1800", B1800
}, {"2400", B2400
},
230 {"4800", B4800
}, {"9600", B9600
}, {"19200", B19200
},
231 {"38400", B38400
}, {"57600", B57600
}, {"76800", B76800
},
232 {"115200", B115200
}, {"153600", B153600
}, {"230400", B230400
},
233 {"307200", B307200
}, {"460800", B460800
}, {"921600", B921600
},
237 static const int MAX_SPEEDS
= sizeof (speedtab
) / sizeof (speedtab
[0]);
239 static dacf_op_t kbconfig_op
[] = {
240 { DACF_OPID_POSTATTACH
, kb_config
},
241 { DACF_OPID_PREDETACH
, kb_unconfig
},
242 { DACF_OPID_END
, NULL
},
245 static dacf_op_t msconfig_op
[] = {
246 { DACF_OPID_POSTATTACH
, ms_config
},
247 { DACF_OPID_PREDETACH
, ms_unconfig
},
248 { DACF_OPID_END
, NULL
},
251 static dacf_opset_t opsets
[] = {
252 { "kb_config", kbconfig_op
},
253 { "ms_config", msconfig_op
},
257 struct dacfsw dacfsw
= {
262 static struct modldacf modldacf
= {
263 &mod_dacfops
, /* Type of module */
268 static struct modlinkage modlinkage
= {
269 MODREV_1
, (void *)&modldacf
, NULL
275 return (mod_install(&modlinkage
));
282 * This modules state is held in the kernel by space.c
283 * allowing this module to be unloaded.
285 return (mod_remove(&modlinkage
));
289 _info(struct modinfo
*modinfop
)
291 return (mod_info(&modlinkage
, modinfop
));
295 static void consconfig_dprintf(int, const char *, ...)
299 consconfig_dprintf(int l
, const char *fmt
, ...)
308 if (l
< consconfig_errlevel
) {
313 (void) vprintf(fmt
, ap
);
318 * Return a property value for the specified alias in /aliases.
321 get_alias(char *alias
, char *buf
)
326 /* The /aliases node only exists in OBP >= 2.4. */
327 if ((node
= prom_alias_node()) == OBP_BADNODE
)
330 if ((len
= prom_getproplen(node
, (caddr_t
)alias
)) <= 0)
333 (void) prom_getprop(node
, (caddr_t
)alias
, (caddr_t
)buf
);
336 * The IEEE 1275 standard specifies that /aliases string property
337 * values should be null-terminated. Unfortunatly the reality
338 * is that most aren't and the OBP can't easily be modified to
339 * add null termination to these strings. So we'll add the
340 * null termination here. If the string already contains a
341 * null termination character then that's ok too because we'll
342 * just be adding a second one.
351 * i_consconfig_createvp:
352 * This routine is a convenience routine that is passed a path and returns
356 i_consconfig_createvp(char *path
)
360 char *buf
= NULL
, *fullpath
;
362 DPRINTF(DPRINT_L0
, "i_consconfig_createvp: %s\n", path
);
363 fullpath
= kmem_alloc(MAXPATHLEN
, KM_SLEEP
);
365 if (strchr(path
, ':') == NULL
) {
366 /* convert an OBP path to a /devices path */
367 buf
= kmem_alloc(MAXPATHLEN
, KM_SLEEP
);
368 if (i_ddi_prompath_to_devfspath(path
, buf
) != DDI_SUCCESS
) {
369 kmem_free(buf
, MAXPATHLEN
);
370 kmem_free(fullpath
, MAXPATHLEN
);
373 (void) snprintf(fullpath
, MAXPATHLEN
, "/devices%s", buf
);
374 kmem_free(buf
, MAXPATHLEN
);
376 /* convert a devfs path to a /devices path */
377 (void) snprintf(fullpath
, MAXPATHLEN
, "/devices%s", path
);
380 DPRINTF(DPRINT_L0
, "lookupname(%s)\n", fullpath
);
381 error
= lookupname(fullpath
, UIO_SYSSPACE
, FOLLOW
, NULLVPP
, &vp
);
382 kmem_free(fullpath
, MAXPATHLEN
);
386 DPRINTF(DPRINT_L0
, "create vnode = 0x%p - dev 0x%lx\n", vp
, vp
->v_rdev
);
387 ASSERT(vn_matchops(vp
, spec_getvnodeops()));
393 * consconfig_print_paths:
394 * Function to print out the various paths
397 consconfig_print_paths(void)
401 if (usb_kb_path
!= NULL
)
403 "consconfig_dacf:usb_kb_path has been deprecated, "
404 "use consconfig:usb_kb_path instead");
406 if (usb_ms_path
!= NULL
)
408 "consconfig_dacf:usb_ms_path has been deprecated, "
409 "use consconfig:usb_ms_path instead");
411 if (consconfig_errlevel
> DPRINT_L0
)
415 if (consconfig_usb_kb_path
!= NULL
)
416 path
= consconfig_usb_kb_path
;
417 else if (usb_kb_path
!= NULL
)
420 DPRINTF(DPRINT_L0
, "usb keyboard path = %s\n", path
);
422 path
= plat_kbdpath();
424 DPRINTF(DPRINT_L0
, "keyboard path = %s\n", path
);
427 if (consconfig_usb_ms_path
!= NULL
)
428 path
= consconfig_usb_ms_path
;
429 else if (usb_ms_path
!= NULL
)
432 DPRINTF(DPRINT_L0
, "usb mouse path = %s\n", path
);
434 path
= plat_mousepath();
436 DPRINTF(DPRINT_L0
, "mouse path = %s\n", path
);
438 path
= plat_stdinpath();
440 DPRINTF(DPRINT_L0
, "stdin path = %s\n", path
);
442 path
= plat_stdoutpath();
444 DPRINTF(DPRINT_L0
, "stdout path = %s\n", path
);
446 path
= plat_diagpath();
448 DPRINTF(DPRINT_L0
, "diag path = %s\n", path
);
450 path
= plat_fbpath();
452 DPRINTF(DPRINT_L0
, "fb path = %s\n", path
);
456 * consconfig_kbd_abort_enable:
457 * Send the CONSSETABORTENABLE ioctl to the lower layers. This ioctl
458 * will only be sent to the device if it is the console device.
459 * This ioctl tells the device to pay attention to abort sequences.
460 * In the case of kbtrans, this would tell the driver to pay attention
461 * to the two key abort sequences like STOP-A. In the case of the
462 * serial keyboard, it would be an abort sequence like a break.
465 consconfig_kbd_abort_enable(ldi_handle_t lh
)
469 DPRINTF(DPRINT_L0
, "consconfig_kbd_abort_enable\n");
471 err
= ldi_ioctl(lh
, CONSSETABORTENABLE
, (uintptr_t)B_TRUE
,
472 FKIOCTL
, kcred
, &rval
);
477 * consconfig_kbd_abort_disable:
478 * Send CONSSETABORTENABLE ioctl to lower layers. This ioctl
479 * will only be sent to the device if it is the console device.
480 * This ioctl tells the physical device to ignore abort sequences,
481 * and send the sequences up to virtual keyboard(conskbd) so that
482 * STOP and A (or F1 and A) can be combined.
485 consconfig_kbd_abort_disable(ldi_handle_t lh
)
489 DPRINTF(DPRINT_L0
, "consconfig_kbd_abort_disable\n");
491 err
= ldi_ioctl(lh
, CONSSETABORTENABLE
, (uintptr_t)B_FALSE
,
492 FKIOCTL
, kcred
, &rval
);
496 #ifdef _HAVE_TEM_FIRMWARE
498 consconfig_tem_supported(cons_state_t
*sp
)
506 if (sp
->cons_fb_path
== NULL
)
509 if ((dev
= ddi_pathname_to_dev_t(sp
->cons_fb_path
)) == NODEV
)
510 return (0); /* warning printed later by common code */
513 * Here we hold the driver and check "tem-support" property.
514 * We're doing this with e_ddi_hold_devi_by_dev and
515 * ddi_prop_lookup_int_array without opening the driver since
516 * some video cards that don't support the kernel terminal
517 * emulator could hang or crash if opened too early during
520 if ((dip
= e_ddi_hold_devi_by_dev(dev
, 0)) == NULL
) {
521 cmn_err(CE_WARN
, "consconfig: cannot hold fb dev %s",
527 * Check that the tem-support property exists AND that
530 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY
, dip
,
531 DDI_PROP_DONTPASS
, "tem-support", &int_array
, &nint
) ==
534 rv
= int_array
[0] == 1;
535 ddi_prop_free(int_array
);
538 ddi_release_devi(dip
);
542 #endif /* _HAVE_TEM_FIRMWARE */
545 * consconfig_get_polledio:
546 * Query the console with the CONSPOLLEDIO ioctl.
547 * The polled I/O routines are used by debuggers to perform I/O while
548 * interrupts and normal kernel services are disabled.
550 static cons_polledio_t
*
551 consconfig_get_polledio(ldi_handle_t lh
)
554 struct strioctl strioc
;
555 cons_polledio_t
*polled_io
;
558 * Setup the ioctl to be sent down to the lower driver.
560 strioc
.ic_cmd
= CONSOPENPOLLEDIO
;
561 strioc
.ic_timout
= INFTIM
;
562 strioc
.ic_len
= sizeof (polled_io
);
563 strioc
.ic_dp
= (char *)&polled_io
;
566 * Send the ioctl to the driver. The ioctl will wait for
567 * the response to come back from wc. wc has already issued
568 * the CONSOPENPOLLEDIO to the lower layer driver.
570 err
= ldi_ioctl(lh
, I_STR
, (intptr_t)&strioc
, FKIOCTL
, kcred
, &rval
);
574 * If the lower driver does not support polled I/O, then
575 * return NULL. This will be the case if the driver does
576 * not handle polled I/O, or OBP is going to handle polled
577 * I/O for the device.
584 * Return the polled I/O structure.
590 * consconfig_setup_polledio:
591 * This routine does the setup work for polled I/O. First we get
592 * the polled_io structure from the lower layers
593 * and then we register the polled I/O
594 * callbacks with the debugger that will be using them.
597 consconfig_setup_polledio(cons_state_t
*sp
, dev_t dev
)
599 cons_polledio_t
*polled_io
;
602 DPRINTF(DPRINT_L0
, "consconfig_setup_polledio: start\n");
605 if (ldi_open_by_dev(&dev
, OTYP_CHR
,
606 FREAD
|FWRITE
|FNOCTTY
, kcred
, &lh
, sp
->cons_li
) != 0)
611 * Get the polled io routines so that we can use this
612 * device with the debuggers.
614 polled_io
= consconfig_get_polledio(lh
);
617 * If the get polledio failed, then we do not want to throw
618 * the polled I/O switch.
620 if (polled_io
== NULL
) {
622 "consconfig_setup_polledio: get_polledio failed\n");
623 (void) ldi_close(lh
, FREAD
|FWRITE
, kcred
);
627 /* Initialize the polled input */
630 /* Register the callbacks */
632 "consconfig_setup_polledio: registering callbacks\n");
633 (void) polled_io_register_callbacks(polled_io
, 0);
635 (void) ldi_close(lh
, FREAD
|FWRITE
, kcred
);
637 DPRINTF(DPRINT_L0
, "consconfig_setup_polledio: end\n");
640 static cons_state_t
*
641 consconfig_state_init(void)
646 /* Initialize console information */
647 sp
= kmem_zalloc(sizeof (cons_state_t
), KM_SLEEP
);
648 sp
->cons_keyboard_problem
= B_FALSE
;
650 mutex_init(&sp
->cons_lock
, NULL
, MUTEX_DRIVER
, NULL
);
652 /* check if consconfig:usb_kb_path is set in /etc/system */
653 consconfig_usb_kb_path
= consconfig_get_usb_kb_path();
655 /* check if consconfig:usb_ms_path is set in /etc/system */
656 consconfig_usb_ms_path
= consconfig_get_usb_ms_path();
658 consconfig_print_paths();
660 /* init external globals */
664 * Find keyboard, mouse, stdin, stdout and diag devices, if they
665 * exist on this platform.
667 sp
->cons_diag_path
= plat_diagpath();
669 if (consconfig_usb_kb_path
!= NULL
) {
670 sp
->cons_keyboard_path
= consconfig_usb_kb_path
;
671 } else if (usb_kb_path
!= NULL
) {
672 sp
->cons_keyboard_path
= usb_kb_path
;
674 sp
->cons_keyboard_path
= plat_kbdpath();
677 if (consconfig_usb_ms_path
!= NULL
) {
678 sp
->cons_mouse_path
= consconfig_usb_ms_path
;
679 } else if (usb_ms_path
!= NULL
) {
680 sp
->cons_mouse_path
= usb_ms_path
;
682 sp
->cons_mouse_path
= plat_mousepath();
685 /* Identify the stdout driver */
686 sp
->cons_stdout_path
= plat_stdoutpath();
687 sp
->cons_stdout_is_fb
= plat_stdout_is_framebuffer();
689 sp
->cons_stdin_is_kbd
= plat_stdin_is_keyboard();
691 if (sp
->cons_stdin_is_kbd
&&
692 (usb_kb_path
!= NULL
|| consconfig_usb_kb_path
!= NULL
)) {
693 sp
->cons_stdin_path
= sp
->cons_keyboard_path
;
696 * The standard in device may or may not be the same as
697 * the keyboard. Even if the keyboard is not the
698 * standard input, the keyboard console stream will
699 * still be built if the keyboard alias provided by the
700 * firmware exists and is valid.
702 sp
->cons_stdin_path
= plat_stdinpath();
705 if (sp
->cons_stdout_is_fb
) {
706 sp
->cons_fb_path
= sp
->cons_stdout_path
;
708 #ifdef _HAVE_TEM_FIRMWARE
709 sp
->cons_tem_supported
= consconfig_tem_supported(sp
);
712 * Systems which offer a virtual console must use that
713 * as a fallback whenever the fb doesn't support tem.
714 * Such systems cannot render characters to the screen
717 if (!sp
->cons_tem_supported
) {
720 if (plat_virtual_console_path(&path
) >= 0) {
721 sp
->cons_stdin_is_kbd
= 0;
722 sp
->cons_stdout_is_fb
= 0;
723 sp
->cons_stdin_path
= path
;
724 sp
->cons_stdout_path
= path
;
725 sp
->cons_fb_path
= plat_fbpath();
728 "%s doesn't support terminal emulation "
729 "mode; switching to virtual console.",
733 #endif /* _HAVE_TEM_FIRMWARE */
735 sp
->cons_fb_path
= plat_fbpath();
736 #ifdef _HAVE_TEM_FIRMWARE
737 sp
->cons_tem_supported
= consconfig_tem_supported(sp
);
738 #endif /* _HAVE_TEM_FIRMWARE */
741 sp
->cons_li
= ldi_ident_from_anon();
743 /* Save the pointer for retrieval by the dacf functions */
744 rval
= space_store("consconfig", (uintptr_t)sp
);
751 consconfig_relink_wc(cons_state_t
*sp
, ldi_handle_t new_lh
, int *muxid
)
757 ASSERT(muxid
!= NULL
);
760 * NOTE: we could be in a dacf callback context right now. normally
761 * it's not legal to call any ldi_open_*() function from this context
762 * because we're currently holding device tree locks and if the
763 * ldi_open_*() call could try to acquire other device tree locks
764 * (to attach the device we're trying to open.) if this happens then
765 * we could deadlock. To avoid this situation, during initialization
766 * we made sure to grab a hold on the dip of the device we plan to
767 * open so that it can never be detached. Then we use
768 * ldi_open_by_dev() to actually open the device since it will see
769 * that the device is already attached and held and instead of
770 * acquire any locks it will only increase the reference count
773 wc_dev
= sp
->cons_wc_vp
->v_rdev
;
774 err
= ldi_open_by_dev(&wc_dev
, OTYP_CHR
, FREAD
|FWRITE
|FNOCTTY
,
775 kcred
, &wc_lh
, sp
->cons_li
);
776 ASSERT(wc_dev
== sp
->cons_wc_vp
->v_rdev
);
778 cmn_err(CE_WARN
, "consconfig_relink_wc: "
779 "unable to open wc device");
783 if (new_lh
!= NULL
) {
784 DPRINTF(DPRINT_L0
, "linking stream under wc\n");
786 err
= ldi_ioctl(wc_lh
, I_PLINK
, (uintptr_t)new_lh
,
787 FKIOCTL
, kcred
, muxid
);
789 cmn_err(CE_WARN
, "consconfig_relink_wc: "
790 "wc link failed, error %d", err
);
793 DPRINTF(DPRINT_L0
, "unlinking stream from under wc\n");
795 err
= ldi_ioctl(wc_lh
, I_PUNLINK
, *muxid
,
796 FKIOCTL
, kcred
, &rval
);
798 cmn_err(CE_WARN
, "consconfig_relink_wc: "
799 "wc unlink failed, error %d", err
);
805 (void) ldi_close(wc_lh
, FREAD
|FWRITE
, kcred
);
810 cons_build_upper_layer(cons_state_t
*sp
)
813 struct strioctl strioc
;
819 * Build the wc->conskbd portion of the keyboard console stream.
820 * Even if no keyboard is attached to the system, the upper
821 * layer of the stream will be built. If the user attaches
822 * a keyboard after the system is booted, the keyboard driver
823 * and module will be linked under conskbd.
825 * Errors are generally ignored here because conskbd and wc
826 * are pseudo drivers and should be present on the system.
829 /* open the console keyboard device. will never be closed */
830 if (ldi_open_by_name(CONSKBD_PATH
, FREAD
|FWRITE
|FNOCTTY
,
831 kcred
, &sp
->conskbd_lh
, sp
->cons_li
) != 0) {
832 panic("consconfig: unable to open conskbd device");
836 DPRINTF(DPRINT_L0
, "conskbd_lh = %p\n", sp
->conskbd_lh
);
838 /* open the console mouse device. will never be closed */
839 if (ldi_open_by_name(CONSMS_PATH
, FREAD
|FWRITE
|FNOCTTY
,
840 kcred
, &sp
->consms_lh
, sp
->cons_li
) != 0) {
841 panic("consconfig: unable to open consms device");
845 DPRINTF(DPRINT_L0
, "consms_lh = %p\n", sp
->consms_lh
);
848 * Get a vnode for the wc device and then grab a hold on the
849 * device dip so it can never detach. We need to do this now
850 * because later we'll have to open the wc device in a context
851 * were it isn't safe to acquire any device tree locks (ie, during
854 sp
->cons_wc_vp
= i_consconfig_createvp(WC_PATH
);
855 if (sp
->cons_wc_vp
== NULL
)
856 panic("consconfig: unable to find wc device");
858 if (e_ddi_hold_devi_by_dev(sp
->cons_wc_vp
->v_rdev
, 0) == NULL
)
859 panic("consconfig: unable to hold wc device");
862 * Build the wc->conskbd portion of the keyboard console stream.
863 * Even if no keyboard is attached to the system, the upper
864 * layer of the stream will be built. If the user attaches
865 * a keyboard after the system is booted, the keyboard driver
866 * and module will be linked under conskbd.
868 * The act of linking conskbd under wc will cause wc to
869 * query the lower layers about their polled I/O routines
870 * using CONSOPENPOLLEDIO. This will fail on this link because
871 * there is not a physical keyboard linked under conskbd.
873 * Since conskbd and wc are pseudo drivers, errors are
874 * generally ignored when linking and unlinking them.
876 (void) consconfig_relink_wc(sp
, sp
->conskbd_lh
, &sp
->conskbd_muxid
);
879 * Get a vnode for the redirection device. (It has the
880 * connection to the workstation console device wired into it,
881 * so that it's not necessary to establish the connection
882 * here. If the redirection device is ever generalized to
883 * handle multiple client devices, it won't be able to
884 * establish the connection itself, and we'll have to do it
887 wsconsvp
= i_consconfig_createvp(IWSCN_PATH
);
888 if (wsconsvp
== NULL
) {
889 panic("consconfig: unable to find iwscn device");
893 if (cons_tem_disable
)
896 if (sp
->cons_fb_path
== NULL
) {
898 if (sp
->cons_stdout_is_fb
)
899 cmn_err(CE_WARN
, "consconfig: no screen found");
904 /* make sure the frame buffer device exists */
905 dev
= ddi_pathname_to_dev_t(sp
->cons_fb_path
);
907 cmn_err(CE_WARN
, "consconfig: "
908 "cannot find driver for screen device %s",
913 #ifdef _HAVE_TEM_FIRMWARE
915 * If the underlying fb device doesn't support terminal emulation,
916 * we don't want to open the wc device (below) because it depends
917 * on features which aren't available (polled mode io).
919 if (!sp
->cons_tem_supported
)
921 #endif /* _HAVE_TEM_FIRMWARE */
923 /* tell wc to open the frame buffer device */
924 wc_dev
= sp
->cons_wc_vp
->v_rdev
;
925 if (ldi_open_by_dev(&wc_dev
, OTYP_CHR
, FREAD
|FWRITE
|FNOCTTY
, kcred
,
926 &wc_lh
, sp
->cons_li
)) {
927 cmn_err(CE_PANIC
, "cons_build_upper_layer: "
928 "unable to open wc device");
931 ASSERT(wc_dev
== sp
->cons_wc_vp
->v_rdev
);
933 strioc
.ic_cmd
= WC_OPEN_FB
;
934 strioc
.ic_timout
= INFTIM
;
935 strioc
.ic_len
= strlen(sp
->cons_fb_path
) + 1;
936 strioc
.ic_dp
= sp
->cons_fb_path
;
938 if (ldi_ioctl(wc_lh
, I_STR
, (intptr_t)&strioc
,
939 FKIOCTL
, kcred
, &rval
) == 0)
943 "consconfig: terminal emulator failed to initialize");
944 (void) ldi_close(wc_lh
, FREAD
|FWRITE
, kcred
);
948 consconfig_load_drivers(cons_state_t
*sp
)
951 * Calling ddi_pathname_to_dev_t may cause the USB Host Controller
952 * drivers to be loaded. Here we make sure that EHCI is loaded
953 * earlier than {U, O}HCI. The order here is important. As
954 * we have observed many systems on which hangs occur if the
955 * {U,O}HCI companion controllers take over control from the BIOS
956 * before EHCI does. These hangs are also caused by BIOSes leaving
957 * interrupt-on-port-change enabled in the ehci controller, so that
958 * when uhci/ohci reset themselves, it induces a port change on
959 * the ehci companion controller. Since there's no interrupt handler
960 * installed at the time, the moment that interrupt is unmasked, an
961 * interrupt storm will occur. All this is averted when ehci is
962 * loaded first. And now you know..... the REST of the story.
964 * Regardless of platform, ehci needs to initialize first to avoid
965 * unnecessary connects and disconnects on the companion controller
966 * when ehci sets up the routing.
968 * The same is generally true of xhci. Many platforms have routing
969 * between the xhci controller and the ehci controller. To avoid those
970 * same disconnects, we load xhci before ehci.
972 (void) ddi_hold_installed_driver(ddi_name_to_major("xhci"));
973 (void) ddi_hold_installed_driver(ddi_name_to_major("ehci"));
974 (void) ddi_hold_installed_driver(ddi_name_to_major("uhci"));
975 (void) ddi_hold_installed_driver(ddi_name_to_major("ohci"));
978 * The attaching of the drivers will cause the creation of the
979 * keyboard and mouse minor nodes, which will in turn trigger the
980 * dacf framework to call the keyboard and mouse configuration
981 * tasks. See PSARC/1998/212 for more details about the dacf
984 * on sparc, when the console is ttya, zs0 is stdin/stdout, and zs1
985 * is kb/mouse. zs0 must be attached before zs1. The zs driver
986 * is written this way and the hardware may depend on this, too.
987 * It would be better to enforce this by attaching zs in sibling
988 * order with a driver property, such as ddi-attachall.
990 if (sp
->cons_stdin_path
!= NULL
)
991 stdindev
= ddi_pathname_to_dev_t(sp
->cons_stdin_path
);
992 if (stdindev
== NODEV
) {
994 "!fail to attach stdin: %s\n", sp
->cons_stdin_path
);
996 if (sp
->cons_stdout_path
!= NULL
)
997 stdoutdev
= ddi_pathname_to_dev_t(sp
->cons_stdout_path
);
998 if (sp
->cons_keyboard_path
!= NULL
)
999 kbddev
= ddi_pathname_to_dev_t(sp
->cons_keyboard_path
);
1000 if (sp
->cons_mouse_path
!= NULL
)
1001 mousedev
= ddi_pathname_to_dev_t(sp
->cons_mouse_path
);
1002 if (sp
->cons_diag_path
!= NULL
)
1003 diagdev
= ddi_pathname_to_dev_t(sp
->cons_diag_path
);
1006 * On x86, make sure the fb driver is loaded even if we don't use it
1007 * for the console. This will ensure that we create a /dev/fb link
1008 * which is required to start Xorg.
1011 if (sp
->cons_fb_path
!= NULL
)
1012 fbdev
= ddi_pathname_to_dev_t(sp
->cons_fb_path
);
1015 DPRINTF(DPRINT_L0
, "stdindev %lx, stdoutdev %lx, kbddev %lx, "
1016 "mousedev %lx diagdev %lx\n", stdindev
, stdoutdev
, kbddev
,
1022 consconfig_virtual_console_vp(cons_state_t
*sp
)
1024 char *virtual_cons_path
;
1026 if (plat_virtual_console_path(&virtual_cons_path
) < 0)
1029 DPRINTF(DPRINT_L0
, "consconfig_virtual_console_vp: "
1030 "virtual console device path %s\n", virtual_cons_path
);
1032 ASSERT(sp
->cons_stdout_path
!= NULL
);
1033 if (strcmp(virtual_cons_path
, sp
->cons_stdout_path
) == 0) {
1034 /* virtual console already in use */
1038 vsconsvp
= i_consconfig_createvp(virtual_cons_path
);
1039 if (vsconsvp
== NULL
) {
1040 cmn_err(CE_WARN
, "consconfig_virtual_console_vp: "
1041 "unable to find serial virtual console device %s",
1046 (void) e_ddi_hold_devi_by_dev(vsconsvp
->v_rdev
, 0);
1051 consconfig_init_framebuffer(cons_state_t
*sp
)
1053 if (!sp
->cons_stdout_is_fb
)
1056 DPRINTF(DPRINT_L0
, "stdout is framebuffer\n");
1057 ASSERT(strcmp(sp
->cons_fb_path
, sp
->cons_stdout_path
) == 0);
1060 * Console output is a framebuffer.
1061 * Find the framebuffer driver if we can, and make
1062 * ourselves a shadow vnode to track it with.
1065 if (fbdev
== NODEV
) {
1067 "Can't find driver for console framebuffer\n");
1069 /* stdoutdev is valid, of fbvp should exist */
1070 fbvp
= i_consconfig_createvp(sp
->cons_stdout_path
);
1072 panic("consconfig_init_framebuffer: "
1073 "unable to find frame buffer device");
1076 ASSERT(fbvp
->v_rdev
== fbdev
);
1078 /* console device is never released */
1079 fbdip
= e_ddi_hold_devi_by_dev(fbdev
, 0);
1081 pm_cfb_setup(sp
->cons_stdout_path
);
1085 * consconfig_prepare_dev:
1086 * Flush the stream, push "pushmod" onto the stream.
1087 * for keyboard, issue the KIOCTRANSABLE ioctl, and
1088 * possible enable abort.
1091 consconfig_prepare_dev(
1092 ldi_handle_t new_lh
,
1093 const char *pushmod
,
1094 int kbdtranslatable
,
1100 /* send a flush down the stream to the keyboard driver */
1101 (void) ldi_ioctl(new_lh
, I_FLUSH
, (intptr_t)FLUSHRW
,
1102 FKIOCTL
, kcred
, &rval
);
1105 err
= ldi_ioctl(new_lh
, I_PUSH
, (intptr_t)pushmod
,
1106 FKIOCTL
, kcred
, &rval
);
1108 cmn_err(CE_WARN
, "consconfig_prepare_dev: "
1109 "can't push streams module \"%s\", error %d",
1114 if (dev_type
== CONS_MS
)
1117 ASSERT(dev_type
== CONS_KBD
);
1119 err
= ldi_ioctl(new_lh
, KIOCTRANSABLE
,
1120 (intptr_t)&kbdtranslatable
, FKIOCTL
, kcred
, &rval
);
1122 cmn_err(CE_WARN
, "consconfig_prepare_dev: "
1123 "KIOCTRANSABLE failed, error: %d", err
);
1127 * During boot, dynamic_console_config() will call the
1128 * function to enable abort on the console. If the
1129 * keyboard is hotplugged after boot, check to see if
1130 * the keyboard is the console input. If it is
1131 * enable abort on it.
1133 if (input_type
== CONSOLE_LOCAL
)
1134 (void) consconfig_kbd_abort_enable(new_lh
);
1138 * consconfig_relink_conskbd:
1139 * If new_lh is not NULL it should represent a driver with a
1140 * keyboard module pushed on top of it. The driver is then linked
1141 * underneath conskbd. the resulting stream will be
1142 * wc->conskbd->"new_lh driver".
1144 * If new_lh is NULL, then an unlink operation is done on conskbd
1145 * that attempts to unlink the stream specified by *muxid.
1146 * the resulting stream will be wc->conskbd.
1149 consconfig_relink_conskbd(cons_state_t
*sp
, ldi_handle_t new_lh
, int *muxid
)
1152 int conskbd_relink
= 0;
1154 ASSERT(muxid
!= NULL
);
1156 DPRINTF(DPRINT_L0
, "consconfig_relink_conskbd: "
1157 "conskbd_lh = %p, new_lh = %p, muxid = %x\n",
1158 sp
->conskbd_lh
, new_lh
, *muxid
);
1161 * If conskbd is linked under wc then temporarily unlink it
1162 * from under wc so that the new_lh stream may be linked under
1163 * conskbd. This has to be done because streams are built bottom
1164 * up and linking a stream under conskbd isn't allowed when
1165 * conskbd is linked under wc.
1167 if (sp
->conskbd_muxid
!= -1) {
1168 DPRINTF(DPRINT_L0
, "unlinking conskbd from under wc\n");
1170 err
= consconfig_relink_wc(sp
, NULL
, &sp
->conskbd_muxid
);
1172 cmn_err(CE_WARN
, "consconfig_relink_conskbd: "
1173 "wc unlink failed, error %d", err
);
1178 if (new_lh
!= NULL
) {
1179 DPRINTF(DPRINT_L0
, "linking keyboard under conskbd\n");
1181 /* Link the stream represented by new_lh under conskbd */
1182 err
= ldi_ioctl(sp
->conskbd_lh
, I_PLINK
, (uintptr_t)new_lh
,
1183 FKIOCTL
, kcred
, muxid
);
1185 cmn_err(CE_WARN
, "consconfig_relink_conskbd: "
1186 "conskbd link failed, error %d", err
);
1190 DPRINTF(DPRINT_L0
, "unlinking keyboard from under conskbd\n");
1193 * This will cause the keyboard driver to be closed,
1194 * all modules to be popped, and the keyboard vnode released.
1196 err
= ldi_ioctl(sp
->conskbd_lh
, I_PUNLINK
, *muxid
,
1197 FKIOCTL
, kcred
, &rval
);
1199 cmn_err(CE_WARN
, "consconfig_relink_conskbd: "
1200 "conskbd unlink failed, error %d", err
);
1206 consconfig_check_phys_kbd(sp
);
1209 if (!conskbd_relink
)
1213 * Link consbkd back under wc.
1215 * The act of linking conskbd back under wc will cause wc
1216 * to query the lower lower layers about their polled I/O
1217 * routines. This time the request will succeed because there
1218 * is a physical keyboard linked under conskbd.
1220 DPRINTF(DPRINT_L0
, "re-linking conskbd under wc\n");
1221 err
= consconfig_relink_wc(sp
, sp
->conskbd_lh
, &sp
->conskbd_muxid
);
1223 cmn_err(CE_WARN
, "consconfig_relink_conskbd: "
1224 "wc link failed, error %d", err
);
1229 if (!conskbd_relink
)
1232 /* something went wrong, try to reconnect conskbd back under wc */
1233 DPRINTF(DPRINT_L0
, "re-linking conskbd under wc\n");
1234 (void) consconfig_relink_wc(sp
, sp
->conskbd_lh
, &sp
->conskbd_muxid
);
1239 * consconfig_relink_consms:
1240 * If new_lh is not NULL it should represent a driver with a
1241 * mouse module pushed on top of it. The driver is then linked
1242 * underneath consms. the resulting stream will be
1243 * consms->"new_lh driver".
1245 * If new_lh is NULL, then an unlink operation is done on consms
1246 * that attempts to unlink the stream specified by *muxid.
1249 consconfig_relink_consms(cons_state_t
*sp
, ldi_handle_t new_lh
, int *muxid
)
1253 DPRINTF(DPRINT_L0
, "consconfig_relink_consms: "
1254 "consms_lh = %p, new_lh = %p, muxid = %x\n",
1255 (void *)sp
->consms_lh
, (void *)new_lh
, *muxid
);
1257 if (new_lh
!= NULL
) {
1258 DPRINTF(DPRINT_L0
, "linking mouse under consms\n");
1260 /* Link ms/usbms stream underneath consms multiplexor. */
1261 err
= ldi_ioctl(sp
->consms_lh
, I_PLINK
, (uintptr_t)new_lh
,
1262 FKIOCTL
, kcred
, muxid
);
1264 cmn_err(CE_WARN
, "consconfig_relink_consms: "
1265 "mouse link failed, error %d", err
);
1268 DPRINTF(DPRINT_L0
, "unlinking mouse from under consms\n");
1270 /* Tear down the mouse stream */
1271 err
= ldi_ioctl(sp
->consms_lh
, I_PUNLINK
, *muxid
,
1272 FKIOCTL
, kcred
, &rval
);
1274 cmn_err(CE_WARN
, "consconfig_relink_consms: "
1275 "mouse unlink failed, error %d", err
);
1284 cons_get_input_type(cons_state_t
*sp
)
1289 * Now that we know what all the devices are, we can figure out
1290 * what kind of console we have.
1292 if (sp
->cons_stdin_is_kbd
) {
1293 /* Stdin is from the system keyboard */
1294 type
= CONSOLE_LOCAL
;
1295 } else if ((stdindev
!= NODEV
) && (stdindev
== stdoutdev
)) {
1297 * A reliable indicator that we are doing a remote console
1298 * is that stdin and stdout are the same.
1299 * This is probably a tip line.
1303 type
= CONSOLE_SERIAL_KEYBOARD
;
1310 consconfig_init_input(cons_state_t
*sp
)
1312 ldi_handle_t new_lh
;
1313 dev_t cons_final_dev
;
1316 cons_final_dev
= NODEV
;
1318 switch (sp
->cons_input_type
) {
1320 DPRINTF(DPRINT_L0
, "stdin is keyboard\n");
1323 * The machine is allowed to boot without a keyboard.
1324 * If a user attaches a keyboard later, the keyboard
1325 * will be hooked into the console stream with the dacf
1328 * The only drivers that look at kbbdev are the
1329 * serial drivers, which looks at kbdev to see if
1330 * they should allow abort on a break. In the absence
1331 * of keyboard, the serial drivers won't be attached
1332 * for any keyboard instance.
1334 if (kbddev
== NODEV
) {
1336 * If there is a problem with the keyboard
1337 * during the driver loading, then the polled
1338 * input won't get setup properly if polled
1339 * input is needed. This means that if the
1340 * keyboard is hotplugged, the keyboard would
1341 * work normally, but going down to the
1342 * debugger would not work if polled input is
1343 * required. This field is set here. The next
1344 * time a keyboard is plugged in, the field is
1345 * checked in order to give the next keyboard a
1346 * chance at being registered for console
1349 * Although this code will rarely be needed,
1350 * USB keyboards can be flaky, so this code
1351 * will be useful on the occasion that the
1352 * keyboard doesn't enumerate when the drivers
1355 DPRINTF(DPRINT_L2
, "Error with console keyboard\n");
1356 sp
->cons_keyboard_problem
= B_TRUE
;
1359 cons_final_dev
= sp
->cons_wc_vp
->v_rdev
;
1363 DPRINTF(DPRINT_L0
, "console input is tty (%s)\n",
1364 sp
->cons_stdin_path
);
1367 * Console device drivers must be able to output
1368 * after being closed.
1370 rconsvp
= i_consconfig_createvp(sp
->cons_stdin_path
);
1371 if (rconsvp
== NULL
) {
1372 panic("consconfig_init_input: "
1373 "unable to find stdin device (%s)",
1374 sp
->cons_stdin_path
);
1377 rconsdev
= rconsvp
->v_rdev
;
1379 ASSERT(rconsdev
== stdindev
);
1381 cons_final_dev
= rconsdev
;
1384 case CONSOLE_SERIAL_KEYBOARD
:
1385 DPRINTF(DPRINT_L0
, "stdin is serial keyboard\n");
1388 * Non-keyboard input device, but not rconsdev.
1389 * This is known as the "serial keyboard" case - the
1390 * most likely use is someone has a keyboard attached
1391 * to a serial port (tip) and still has output on a
1394 * In this case, the serial driver must be linked
1395 * directly beneath wc. Since conskbd was linked
1396 * underneath wc above, first we unlink conskbd.
1398 (void) consconfig_relink_wc(sp
, NULL
, &sp
->conskbd_muxid
);
1399 sp
->conskbd_muxid
= -1;
1402 * Open the serial keyboard, configure it,
1403 * and link it underneath wc.
1405 err
= ldi_open_by_name(sp
->cons_stdin_path
,
1406 FREAD
|FWRITE
|FNOCTTY
, kcred
, &new_lh
, sp
->cons_li
);
1408 struct termios termios
;
1412 consconfig_prepare_dev(new_lh
,
1413 "kb", TR_CANNOT
, sp
->cons_input_type
, CONS_KBD
);
1415 /* Re-set baud rate */
1416 (void) ldi_ioctl(new_lh
, TCGETS
, (intptr_t)&termios
,
1417 FKIOCTL
, kcred
, &rval
);
1420 if (consconfig_setmodes(stdindev
, &termios
) == 0) {
1421 err
= ldi_ioctl(new_lh
,
1422 TCSETSF
, (intptr_t)&termios
,
1423 FKIOCTL
, kcred
, &rval
);
1426 "consconfig_init_input: "
1427 "TCSETSF failed, error %d", err
);
1432 * Now link the serial keyboard direcly under wc
1433 * we don't save the returned muxid because we
1434 * don't support changing/hotplugging the console
1435 * keyboard when it is a serial keyboard.
1437 (void) consconfig_relink_wc(sp
, new_lh
, &stdin_muxid
);
1439 (void) ldi_close(new_lh
, FREAD
|FWRITE
, kcred
);
1442 cons_final_dev
= sp
->cons_wc_vp
->v_rdev
;
1446 panic("consconfig_init_input: "
1447 "unsupported console input/output combination");
1452 * Use the redirection device/workstation console pair as the "real"
1453 * console if the latter hasn't already been set.
1454 * The workstation console driver needs to see rwsconsvp, but
1455 * all other access should be through the redirecting driver.
1457 if (rconsvp
== NULL
) {
1458 consconfig_dprintf(DPRINT_L0
, "setup redirection driver\n");
1460 rconsdev
= wsconsvp
->v_rdev
;
1463 ASSERT(cons_final_dev
!= NODEV
);
1465 err
= ldi_open_by_dev(&cons_final_dev
, OTYP_CHR
, FREAD
|FWRITE
|FNOCTTY
,
1466 kcred
, &new_lh
, sp
->cons_li
);
1468 panic("consconfig_init_input: "
1469 "unable to open console device");
1473 /* Enable abort on the console */
1474 (void) consconfig_kbd_abort_enable(new_lh
);
1476 /* Now we must close it to make console logins happy */
1477 (void) ldi_close(new_lh
, FREAD
|FWRITE
, kcred
);
1479 /* Set up polled input if it is supported by the console device */
1480 if (plat_use_polled_debug()) {
1482 * In the debug case, register the keyboard polled entry
1483 * points, but don't throw the switch in the debugger. This
1484 * allows the polled entry points to be checked by hand
1486 consconfig_setup_polledio(sp
, sp
->cons_wc_vp
->v_rdev
);
1488 if (diagdev
!= NODEV
)
1489 consconfig_setup_polledio(sp
, diagdev
);
1491 consconfig_setup_polledio(sp
, cons_final_dev
);
1498 * This function kicks off the console configuration.
1499 * Configure keyboard and mouse. Main entry here.
1502 dynamic_console_config(void)
1504 /* initialize space.c globals */
1518 /* Initialize cons_state_t structure and console device paths */
1519 consconfig_sp
= consconfig_state_init();
1520 ASSERT(consconfig_sp
);
1522 /* Build upper layer of console stream */
1523 cons_build_upper_layer(consconfig_sp
);
1526 * Load keyboard/mouse drivers. The dacf routines will
1527 * plumb the devices into the console stream
1529 * At the conclusion of the ddi_pathname_to_dev_t calls, the keyboard
1530 * and mouse drivers are linked into their respective console
1531 * streams if the pathnames are valid.
1533 consconfig_load_drivers(consconfig_sp
);
1534 consconfig_sp
->cons_input_type
= cons_get_input_type(consconfig_sp
);
1536 rwsconsvp
= consconfig_sp
->cons_wc_vp
;
1537 rwsconsdev
= consconfig_sp
->cons_wc_vp
->v_rdev
;
1540 /* initialize framebuffer, console input, and redirection device */
1541 consconfig_init_framebuffer(consconfig_sp
);
1542 consconfig_init_input(consconfig_sp
);
1545 /* initialize virtual console vp for logging if needed */
1546 consconfig_virtual_console_vp(consconfig_sp
);
1550 "mousedev %lx, kbddev %lx, fbdev %lx, rconsdev %lx\n",
1551 mousedev
, kbddev
, fbdev
, rconsdev
);
1553 flush_deferred_console_buf();
1555 consconfig_sp
->cons_initialized
= B_TRUE
;
1560 * Start of DACF interfaces
1564 * Do the real job for keyboard/mouse auto-configuration.
1567 do_config(cons_state_t
*sp
, cons_prop_t
*prop
)
1573 ASSERT((prop
->cp_type
== CONS_KBD
) || (prop
->cp_type
== CONS_MS
));
1576 error
= ldi_open_by_dev(&dev
, OTYP_CHR
,
1577 FREAD
|FWRITE
|FNOCTTY
, kcred
, &lh
, sp
->cons_li
);
1579 return (DACF_FAILURE
);
1581 ASSERT(dev
== prop
->cp_dev
); /* clone not supported */
1584 * Prepare the new keyboard/mouse driver
1585 * to be linked under conskbd/consms.
1587 consconfig_prepare_dev(lh
, prop
->cp_pushmod
, TR_CAN
,
1588 sp
->cons_input_type
, prop
->cp_type
);
1590 if (prop
->cp_type
== CONS_KBD
) {
1592 * Tell the physical keyboard driver to send
1593 * the abort sequences up to the virtual keyboard
1594 * driver so that STOP and A (or F1 and A)
1595 * can be applied to different keyboards.
1597 (void) consconfig_kbd_abort_disable(lh
);
1599 /* Link the stream underneath conskbd */
1600 error
= consconfig_relink_conskbd(sp
, lh
, &prop
->cp_muxid
);
1602 /* Link the stream underneath consms */
1603 error
= consconfig_relink_consms(sp
, lh
, &prop
->cp_muxid
);
1607 * At this point, the stream is:
1608 * for keyboard: wc->conskbd->["pushmod"->"kbd_vp driver"]
1609 * for mouse: consms->["module_name"->]"mouse_avp driver"
1612 /* Close the driver stream, it will stay linked under conskbd */
1613 (void) ldi_close(lh
, FREAD
|FWRITE
, kcred
);
1616 return (DACF_FAILURE
);
1619 return (DACF_SUCCESS
);
1623 do_unconfig(cons_state_t
*sp
, cons_prop_t
*prop
)
1625 ASSERT((prop
->cp_type
== CONS_KBD
) || (prop
->cp_type
== CONS_MS
));
1627 if (prop
->cp_type
== CONS_KBD
)
1628 return (consconfig_relink_conskbd(sp
, NULL
, &prop
->cp_muxid
));
1630 return (consconfig_relink_consms(sp
, NULL
, &prop
->cp_muxid
));
1634 kb_ms_config(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int type
)
1642 const char *pushmod
;
1645 * Retrieve the state information
1646 * Some platforms may use the old-style "consconfig" to configure
1647 * console stream modules but may also support devices that happen
1648 * to match a rule in /etc/dacf.conf. This will cause a problem
1649 * since the console state structure will not be initialized.
1650 * In that case, these entry points should silently fail and
1651 * permit console to be plumbed later in boot.
1653 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
1654 return (DACF_FAILURE
);
1656 dip
= dacf_devinfo_node(minor_hdl
);
1657 major
= ddi_driver_major(dip
);
1658 ASSERT(major
!= DDI_MAJOR_T_NONE
);
1659 minor
= dacf_minor_number(minor_hdl
);
1660 dev
= makedevice(major
, minor
);
1661 ASSERT(dev
!= NODEV
);
1663 DPRINTF(DPRINT_L0
, "driver name = \"%s\", dev = 0x%lx, major = 0x%x\n",
1664 (char *)dacf_driver_name(minor_hdl
), dev
, major
);
1666 /* Access to the global variables is synchronized */
1667 mutex_enter(&sp
->cons_lock
);
1670 * Check if the keyboard/mouse has already configured.
1672 if (consconfig_find_dev(sp
, dev
) != NULL
) {
1673 mutex_exit(&sp
->cons_lock
);
1674 return (DACF_SUCCESS
);
1677 prop
= kmem_zalloc(sizeof (cons_prop_t
), KM_SLEEP
);
1679 /* Config the new keyboard/mouse device */
1682 pushmod
= dacf_get_arg(arg_hdl
, "pushmod");
1683 prop
->cp_pushmod
= i_ddi_strdup((char *)pushmod
, KM_SLEEP
);
1685 prop
->cp_type
= type
;
1686 if (do_config(sp
, prop
) != DACF_SUCCESS
) {
1688 * The keyboard/mouse node failed to open.
1689 * Set the major and minor numbers to 0 so
1690 * kb_unconfig/ms_unconfig won't unconfigure
1691 * this node if it is detached.
1693 mutex_exit(&sp
->cons_lock
);
1694 consconfig_free_prop(prop
);
1695 return (DACF_FAILURE
);
1698 consconfig_add_dev(sp
, prop
);
1701 * See if there was a problem with the console keyboard during boot.
1702 * If so, try to register polled input for this keyboard.
1704 if ((type
== CONS_KBD
) && (sp
->cons_keyboard_problem
)) {
1705 consconfig_setup_polledio(sp
, sp
->cons_wc_vp
->v_rdev
);
1706 sp
->cons_keyboard_problem
= B_FALSE
;
1709 /* Prevent autodetach due to memory pressure */
1710 (void) ddi_prop_update_int(DDI_DEV_T_NONE
, dip
, DDI_NO_AUTODETACH
, 1);
1712 mutex_exit(&sp
->cons_lock
);
1714 return (DACF_SUCCESS
);
1718 kb_ms_unconfig(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
)
1720 _NOTE(ARGUNUSED(arg_hdl
))
1730 * Retrieve the state information
1731 * So if there isn't a state available, then this entry point just
1732 * returns. See note in kb_config().
1734 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
1735 return (DACF_SUCCESS
);
1737 dip
= dacf_devinfo_node(minor_hdl
);
1738 major
= ddi_driver_major(dip
);
1739 ASSERT(major
!= DDI_MAJOR_T_NONE
);
1740 minor
= dacf_minor_number(minor_hdl
);
1741 dev
= makedevice(major
, minor
);
1742 ASSERT(dev
!= NODEV
);
1745 * Check if the keyboard/mouse that is being detached
1746 * is the console keyboard/mouse or not.
1748 mutex_enter(&sp
->cons_lock
);
1749 if ((prop
= consconfig_find_dev(sp
, dev
)) == NULL
) {
1750 mutex_exit(&sp
->cons_lock
);
1751 return (DACF_SUCCESS
);
1755 * This dev may be opened physically and then hotplugged out.
1757 if (prop
->cp_muxid
!= -1) {
1758 (void) do_unconfig(sp
, prop
);
1759 consconfig_rem_dev(sp
, dev
);
1762 mutex_exit(&sp
->cons_lock
);
1764 return (DACF_SUCCESS
);
1768 * This is the post-attach / pre-detach action function for the keyboard
1769 * and mouse. This function is associated with a node type in /etc/dacf.conf.
1772 kb_config(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int flags
)
1774 _NOTE(ARGUNUSED(flags
))
1776 return (kb_ms_config(minor_hdl
, arg_hdl
, CONS_KBD
));
1780 ms_config(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int flags
)
1782 _NOTE(ARGUNUSED(flags
))
1784 return (kb_ms_config(minor_hdl
, arg_hdl
, CONS_MS
));
1788 kb_unconfig(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int flags
)
1790 _NOTE(ARGUNUSED(flags
))
1792 return (kb_ms_unconfig(minor_hdl
, arg_hdl
));
1796 ms_unconfig(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int flags
)
1798 _NOTE(ARGUNUSED(flags
))
1800 return (kb_ms_unconfig(minor_hdl
, arg_hdl
));
1804 * consconfig_link and consconfig_unlink are provided to support
1805 * direct access to physical keyboard/mouse underlying conskbd/
1807 * When the keyboard/mouse is opened physically via its device
1808 * file, it will be unlinked from the virtual one, and when it
1809 * is closed physically, it will be linked back under the virtual
1813 consconfig_link(major_t major
, minor_t minor
)
1815 char buf
[MAXPATHLEN
];
1820 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
1823 dev
= makedevice(major
, minor
);
1824 ASSERT(dev
!= NODEV
);
1826 mutex_enter(&sp
->cons_lock
);
1827 if ((prop
= consconfig_find_dev(sp
, dev
)) == NULL
) {
1828 mutex_exit(&sp
->cons_lock
);
1832 if (do_config(sp
, prop
) != DACF_SUCCESS
) {
1833 (void) ddi_dev_pathname(dev
, 0, buf
);
1834 if (prop
->cp_type
== CONS_KBD
)
1835 cmn_err(CE_WARN
, "Failed to relink the keyboard "
1836 "(%s) underneath virtual keyboard", buf
);
1838 cmn_err(CE_WARN
, "Failed to relink the mouse "
1839 "(%s) underneath virtual mouse", buf
);
1840 consconfig_rem_dev(sp
, dev
);
1843 mutex_exit(&sp
->cons_lock
);
1848 consconfig_unlink(major_t major
, minor_t minor
)
1855 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
1856 return (DACF_SUCCESS
);
1858 dev
= makedevice(major
, minor
);
1859 ASSERT(dev
!= NODEV
);
1861 mutex_enter(&sp
->cons_lock
);
1862 if ((prop
= consconfig_find_dev(sp
, dev
)) == NULL
) {
1863 mutex_exit(&sp
->cons_lock
);
1864 return (DACF_FAILURE
);
1867 error
= do_unconfig(sp
, prop
);
1870 * Keep this dev on the list, for this dev is still online.
1872 mutex_exit(&sp
->cons_lock
);
1878 * Routine to set baud rate, bits-per-char, parity and stop bits
1879 * on the console line when necessary.
1882 consconfig_setmodes(dev_t dev
, struct termios
*termiosp
)
1884 char buf
[MAXPATHLEN
];
1885 int len
= MAXPATHLEN
;
1892 * First, search for a devalias which matches this dev_t.
1893 * Try all of ttya through ttyz until no such alias
1895 (void) strcpy(name
, "ttya");
1896 for (i
= 0; i
< ('z'-'a'); i
++) {
1897 name
[3] = 'a' + i
; /* increment device name */
1898 path
= get_alias(name
, buf
);
1902 tdev
= ddi_pathname_to_dev_t(path
);
1904 break; /* Exit loop if found */
1908 return (1); /* If we didn't find it, return */
1911 * Now that we know which "tty" this corresponds to, retrieve
1912 * the "ttya-mode" options property, which tells us how to configure
1915 (void) strcpy(name
, "ttya-mode"); /* name of option we want */
1916 name
[3] = 'a' + i
; /* Adjust to correct line */
1918 if (ddi_getlongprop_buf(DDI_DEV_T_ANY
, ddi_root_node(), 0, name
,
1919 buf
, &len
) != DDI_PROP_SUCCESS
)
1920 return (1); /* if no such option, just return */
1923 * The IEEE 1275 standard specifies that /aliases string property
1924 * values should be null-terminated. Unfortunately the reality
1925 * is that most aren't and the OBP can't easily be modified to
1926 * add null termination to these strings. So we'll add the
1927 * null termination here. If the string already contains a
1928 * null termination character then that's ok too because we'll
1929 * just be adding a second one.
1933 /* Clear out options we will be setting */
1934 termiosp
->c_cflag
&=
1935 ~(CSIZE
| CBAUD
| CBAUDEXT
| PARODD
| PARENB
| CSTOPB
);
1937 /* Clear options which potentially conflict with new settings */
1938 termiosp
->c_cflag
&= ~(CIBAUD
| CIBAUDEXT
);
1941 * Now, parse the string. Wish I could use sscanf().
1942 * Format 9600,8,n,1,-
1943 * baud rate, bits-per-char, parity, stop-bits, ignored
1945 for (ppos
= 0; ppos
< (MAXPATHLEN
-8); ppos
++) { /* Find first comma */
1946 if ((buf
[ppos
] == 0) || (buf
[ppos
] == ','))
1950 if (buf
[ppos
] != ',') {
1951 cmn_err(CE_WARN
, "consconfig_setmodes: "
1952 "invalid mode string %s", buf
);
1956 for (i
= 0; i
< MAX_SPEEDS
; i
++) {
1957 if (strncmp(buf
, speedtab
[i
].name
, ppos
) == 0)
1961 if (i
>= MAX_SPEEDS
) {
1963 "consconfig_setmodes: unrecognized speed in %s", buf
);
1967 /* Found the baud rate, set it */
1968 termiosp
->c_cflag
|= speedtab
[i
].code
& CBAUD
;
1969 if (speedtab
[i
].code
> 16) /* cfsetospeed! */
1970 termiosp
->c_cflag
|= CBAUDEXT
;
1972 /* Set bits per character */
1973 switch (buf
[ppos
+1]) {
1975 termiosp
->c_cflag
|= CS8
;
1978 termiosp
->c_cflag
|= CS7
;
1982 "consconfig_setmodes: illegal bits-per-char %s", buf
);
1987 switch (buf
[ppos
+3]) {
1989 termiosp
->c_cflag
|= PARENB
| PARODD
;
1992 termiosp
->c_cflag
|= PARENB
; /* enabled, not odd */
1995 break; /* not enabled. */
1997 cmn_err(CE_WARN
, "consconfig_setmodes: illegal parity %s", buf
);
2002 switch (buf
[ppos
+5]) {
2004 break; /* No extra stop bit */
2006 termiosp
->c_cflag
|= CSTOPB
; /* 1 extra stop bit */
2009 cmn_err(CE_WARN
, "consconfig_setmodes: "
2010 "illegal stop bits %s", buf
);
2018 * Check to see if underlying keyboard devices are still online,
2019 * if any one is offline now, unlink it.
2022 consconfig_check_phys_kbd(cons_state_t
*sp
)
2029 for (prop
= sp
->cons_km_prop
; prop
; prop
= prop
->cp_next
) {
2030 if ((prop
->cp_type
!= CONS_KBD
) || (prop
->cp_muxid
== -1))
2033 error
= ldi_open_by_dev(&prop
->cp_dev
, OTYP_CHR
,
2034 FREAD
|FWRITE
|FNOCTTY
, kcred
, &kb_lh
, sp
->cons_li
);
2037 (void) ldi_ioctl(sp
->conskbd_lh
, I_PUNLINK
,
2038 prop
->cp_muxid
, FKIOCTL
, kcred
, &rval
);
2039 prop
->cp_dev
= NODEV
;
2041 (void) ldi_close(kb_lh
, FREAD
|FWRITE
, kcred
);
2046 * Remove all disconnected keyboards,
2047 * whose dev is turned into NODEV above.
2049 consconfig_rem_dev(sp
, NODEV
);
2053 * Remove devices according to dev, which may be NODEV
2056 consconfig_rem_dev(cons_state_t
*sp
, dev_t dev
)
2059 cons_prop_t
*prev_prop
;
2060 cons_prop_t
*tmp_prop
;
2061 cons_prop_t
*head_prop
;
2065 for (prop
= sp
->cons_km_prop
; prop
!= NULL
; ) {
2066 if (prop
->cp_dev
== dev
) {
2067 tmp_prop
= prop
->cp_next
;
2068 consconfig_free_prop(prop
);
2071 prev_prop
->cp_next
= prop
;
2073 if (head_prop
== NULL
)
2076 prop
= prop
->cp_next
;
2079 sp
->cons_km_prop
= head_prop
;
2083 * Add a dev according to prop
2086 consconfig_add_dev(cons_state_t
*sp
, cons_prop_t
*prop
)
2088 prop
->cp_next
= sp
->cons_km_prop
;
2089 sp
->cons_km_prop
= prop
;
2093 * Find a device from our list according to dev
2095 static cons_prop_t
*
2096 consconfig_find_dev(cons_state_t
*sp
, dev_t dev
)
2100 for (prop
= sp
->cons_km_prop
; prop
; prop
= prop
->cp_next
) {
2101 if (prop
->cp_dev
== dev
)
2109 * Free a cons prop associated with a keyboard or mouse
2112 consconfig_free_prop(cons_prop_t
*prop
)
2114 if (prop
->cp_pushmod
)
2115 kmem_free(prop
->cp_pushmod
, strlen(prop
->cp_pushmod
) + 1);
2116 kmem_free(prop
, sizeof (cons_prop_t
));
2120 * The early boot code can't print to a usb serial device or the
2121 * graphical boot screen.
2123 * The early boot messages are saved in a buffer at the address indicated
2124 * by "deferred-console-buf" This function flushes the message to the
2125 * current console now that it is set up.
2128 flush_deferred_console_buf(void)
2133 char *kc
, *bc
, *defcons_kern_buf
;
2135 /* defcons_buf is in low memory, so an int works here */
2136 defcons_buf
= ddi_prop_get_int(DDI_DEV_T_ANY
, ddi_root_node(),
2137 DDI_PROP_DONTPASS
, "deferred-console-buf", 0);
2139 if (defcons_buf
== 0)
2143 * After consconfig() and before userland opens /dev/sysmsg,
2144 * console I/O is goes to polled I/O entry points.
2146 * If usb-serial doesn't implement polled I/O, we need
2147 * to open /dev/console now to get kernel console I/O to work.
2148 * We also push ttcompat and ldterm explicitly to get the
2149 * correct output format (autopush isn't set up yet). We
2150 * ignore push errors because they are non-fatal.
2151 * Note that opening /dev/console causes rconsvp to be
2154 if (cons_polledio
== NULL
) {
2155 if (vn_open("/dev/console", UIO_SYSSPACE
, FWRITE
| FNOCTTY
,
2160 (void) strioctl(rconsvp
, __I_PUSH_NOCTTY
,
2161 (intptr_t)"ldterm", FKIOCTL
, K_TO_K
, kcred
, &rval
);
2162 (void) strioctl(rconsvp
, __I_PUSH_NOCTTY
,
2163 (intptr_t)"ttcompat", FKIOCTL
, K_TO_K
,
2169 * Copy message to a kernel buffer. Various kernel routines
2170 * expect buffer to be above kernelbase
2172 kc
= defcons_kern_buf
= kmem_zalloc(MMU_PAGESIZE
, KM_SLEEP
);
2173 bc
= (char *)(uintptr_t)defcons_buf
;
2174 while (*kc
++ = *bc
++)
2176 console_printf("%s", defcons_kern_buf
);
2178 kmem_free(defcons_kern_buf
, MMU_PAGESIZE
);
2182 consconfig_console_is_tipline(void)
2186 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
2189 if (sp
->cons_input_type
== CONSOLE_TIP
)
2196 consconfig_dacf_initialized(void)
2200 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
2203 return (sp
->cons_initialized
);