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_fbpath();
448 DPRINTF(DPRINT_L0
, "fb path = %s\n", path
);
452 * consconfig_kbd_abort_enable:
453 * Send the CONSSETABORTENABLE ioctl to the lower layers. This ioctl
454 * will only be sent to the device if it is the console device.
455 * This ioctl tells the device to pay attention to abort sequences.
456 * In the case of kbtrans, this would tell the driver to pay attention
457 * to the two key abort sequences like STOP-A. In the case of the
458 * serial keyboard, it would be an abort sequence like a break.
461 consconfig_kbd_abort_enable(ldi_handle_t lh
)
465 DPRINTF(DPRINT_L0
, "consconfig_kbd_abort_enable\n");
467 err
= ldi_ioctl(lh
, CONSSETABORTENABLE
, (uintptr_t)B_TRUE
,
468 FKIOCTL
, kcred
, &rval
);
473 * consconfig_kbd_abort_disable:
474 * Send CONSSETABORTENABLE ioctl to lower layers. This ioctl
475 * will only be sent to the device if it is the console device.
476 * This ioctl tells the physical device to ignore abort sequences,
477 * and send the sequences up to virtual keyboard(conskbd) so that
478 * STOP and A (or F1 and A) can be combined.
481 consconfig_kbd_abort_disable(ldi_handle_t lh
)
485 DPRINTF(DPRINT_L0
, "consconfig_kbd_abort_disable\n");
487 err
= ldi_ioctl(lh
, CONSSETABORTENABLE
, (uintptr_t)B_FALSE
,
488 FKIOCTL
, kcred
, &rval
);
492 #ifdef _HAVE_TEM_FIRMWARE
494 consconfig_tem_supported(cons_state_t
*sp
)
502 if (sp
->cons_fb_path
== NULL
)
505 if ((dev
= ddi_pathname_to_dev_t(sp
->cons_fb_path
)) == NODEV
)
506 return (0); /* warning printed later by common code */
509 * Here we hold the driver and check "tem-support" property.
510 * We're doing this with e_ddi_hold_devi_by_dev and
511 * ddi_prop_lookup_int_array without opening the driver since
512 * some video cards that don't support the kernel terminal
513 * emulator could hang or crash if opened too early during
516 if ((dip
= e_ddi_hold_devi_by_dev(dev
, 0)) == NULL
) {
517 cmn_err(CE_WARN
, "consconfig: cannot hold fb dev %s",
523 * Check that the tem-support property exists AND that
526 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY
, dip
,
527 DDI_PROP_DONTPASS
, "tem-support", &int_array
, &nint
) ==
530 rv
= int_array
[0] == 1;
531 ddi_prop_free(int_array
);
534 ddi_release_devi(dip
);
538 #endif /* _HAVE_TEM_FIRMWARE */
541 * consconfig_get_polledio:
542 * Query the console with the CONSPOLLEDIO ioctl.
543 * The polled I/O routines are used by debuggers to perform I/O while
544 * interrupts and normal kernel services are disabled.
546 static cons_polledio_t
*
547 consconfig_get_polledio(ldi_handle_t lh
)
550 struct strioctl strioc
;
551 cons_polledio_t
*polled_io
;
554 * Setup the ioctl to be sent down to the lower driver.
556 strioc
.ic_cmd
= CONSOPENPOLLEDIO
;
557 strioc
.ic_timout
= INFTIM
;
558 strioc
.ic_len
= sizeof (polled_io
);
559 strioc
.ic_dp
= (char *)&polled_io
;
562 * Send the ioctl to the driver. The ioctl will wait for
563 * the response to come back from wc. wc has already issued
564 * the CONSOPENPOLLEDIO to the lower layer driver.
566 err
= ldi_ioctl(lh
, I_STR
, (intptr_t)&strioc
, FKIOCTL
, kcred
, &rval
);
570 * If the lower driver does not support polled I/O, then
571 * return NULL. This will be the case if the driver does
572 * not handle polled I/O, or OBP is going to handle polled
573 * I/O for the device.
580 * Return the polled I/O structure.
586 * consconfig_setup_polledio:
587 * This routine does the setup work for polled I/O. First we get
588 * the polled_io structure from the lower layers
589 * and then we register the polled I/O
590 * callbacks with the debugger that will be using them.
593 consconfig_setup_polledio(cons_state_t
*sp
, dev_t dev
)
595 cons_polledio_t
*polled_io
;
598 DPRINTF(DPRINT_L0
, "consconfig_setup_polledio: start\n");
601 if (ldi_open_by_dev(&dev
, OTYP_CHR
,
602 FREAD
|FWRITE
|FNOCTTY
, kcred
, &lh
, sp
->cons_li
) != 0)
607 * Get the polled io routines so that we can use this
608 * device with the debuggers.
610 polled_io
= consconfig_get_polledio(lh
);
613 * If the get polledio failed, then we do not want to throw
614 * the polled I/O switch.
616 if (polled_io
== NULL
) {
618 "consconfig_setup_polledio: get_polledio failed\n");
619 (void) ldi_close(lh
, FREAD
|FWRITE
, kcred
);
623 /* Initialize the polled input */
626 /* Register the callbacks */
628 "consconfig_setup_polledio: registering callbacks\n");
629 (void) polled_io_register_callbacks(polled_io
, 0);
631 (void) ldi_close(lh
, FREAD
|FWRITE
, kcred
);
633 DPRINTF(DPRINT_L0
, "consconfig_setup_polledio: end\n");
636 static cons_state_t
*
637 consconfig_state_init(void)
642 /* Initialize console information */
643 sp
= kmem_zalloc(sizeof (cons_state_t
), KM_SLEEP
);
644 sp
->cons_keyboard_problem
= B_FALSE
;
646 mutex_init(&sp
->cons_lock
, NULL
, MUTEX_DRIVER
, NULL
);
648 /* check if consconfig:usb_kb_path is set in /etc/system */
649 consconfig_usb_kb_path
= consconfig_get_usb_kb_path();
651 /* check if consconfig:usb_ms_path is set in /etc/system */
652 consconfig_usb_ms_path
= consconfig_get_usb_ms_path();
654 consconfig_print_paths();
656 /* init external globals */
660 * Find keyboard, mouse, stdin and stdout devices, if they
661 * exist on this platform.
664 if (consconfig_usb_kb_path
!= NULL
) {
665 sp
->cons_keyboard_path
= consconfig_usb_kb_path
;
666 } else if (usb_kb_path
!= NULL
) {
667 sp
->cons_keyboard_path
= usb_kb_path
;
669 sp
->cons_keyboard_path
= plat_kbdpath();
672 if (consconfig_usb_ms_path
!= NULL
) {
673 sp
->cons_mouse_path
= consconfig_usb_ms_path
;
674 } else if (usb_ms_path
!= NULL
) {
675 sp
->cons_mouse_path
= usb_ms_path
;
677 sp
->cons_mouse_path
= plat_mousepath();
680 /* Identify the stdout driver */
681 sp
->cons_stdout_path
= plat_stdoutpath();
682 sp
->cons_stdout_is_fb
= plat_stdout_is_framebuffer();
684 sp
->cons_stdin_is_kbd
= plat_stdin_is_keyboard();
686 if (sp
->cons_stdin_is_kbd
&&
687 (usb_kb_path
!= NULL
|| consconfig_usb_kb_path
!= NULL
)) {
688 sp
->cons_stdin_path
= sp
->cons_keyboard_path
;
691 * The standard in device may or may not be the same as
692 * the keyboard. Even if the keyboard is not the
693 * standard input, the keyboard console stream will
694 * still be built if the keyboard alias provided by the
695 * firmware exists and is valid.
697 sp
->cons_stdin_path
= plat_stdinpath();
700 if (sp
->cons_stdout_is_fb
) {
701 sp
->cons_fb_path
= sp
->cons_stdout_path
;
703 #ifdef _HAVE_TEM_FIRMWARE
704 sp
->cons_tem_supported
= consconfig_tem_supported(sp
);
707 * Systems which offer a virtual console must use that
708 * as a fallback whenever the fb doesn't support tem.
709 * Such systems cannot render characters to the screen
712 if (!sp
->cons_tem_supported
) {
715 if (plat_virtual_console_path(&path
) >= 0) {
716 sp
->cons_stdin_is_kbd
= 0;
717 sp
->cons_stdout_is_fb
= 0;
718 sp
->cons_stdin_path
= path
;
719 sp
->cons_stdout_path
= path
;
720 sp
->cons_fb_path
= plat_fbpath();
723 "%s doesn't support terminal emulation "
724 "mode; switching to virtual console.",
728 #endif /* _HAVE_TEM_FIRMWARE */
730 sp
->cons_fb_path
= plat_fbpath();
731 #ifdef _HAVE_TEM_FIRMWARE
732 sp
->cons_tem_supported
= consconfig_tem_supported(sp
);
733 #endif /* _HAVE_TEM_FIRMWARE */
736 sp
->cons_li
= ldi_ident_from_anon();
738 /* Save the pointer for retrieval by the dacf functions */
739 rval
= space_store("consconfig", (uintptr_t)sp
);
746 consconfig_relink_wc(cons_state_t
*sp
, ldi_handle_t new_lh
, int *muxid
)
752 ASSERT(muxid
!= NULL
);
755 * NOTE: we could be in a dacf callback context right now. normally
756 * it's not legal to call any ldi_open_*() function from this context
757 * because we're currently holding device tree locks and if the
758 * ldi_open_*() call could try to acquire other device tree locks
759 * (to attach the device we're trying to open.) if this happens then
760 * we could deadlock. To avoid this situation, during initialization
761 * we made sure to grab a hold on the dip of the device we plan to
762 * open so that it can never be detached. Then we use
763 * ldi_open_by_dev() to actually open the device since it will see
764 * that the device is already attached and held and instead of
765 * acquire any locks it will only increase the reference count
768 wc_dev
= sp
->cons_wc_vp
->v_rdev
;
769 err
= ldi_open_by_dev(&wc_dev
, OTYP_CHR
, FREAD
|FWRITE
|FNOCTTY
,
770 kcred
, &wc_lh
, sp
->cons_li
);
771 ASSERT(wc_dev
== sp
->cons_wc_vp
->v_rdev
);
773 cmn_err(CE_WARN
, "consconfig_relink_wc: "
774 "unable to open wc device");
778 if (new_lh
!= NULL
) {
779 DPRINTF(DPRINT_L0
, "linking stream under wc\n");
781 err
= ldi_ioctl(wc_lh
, I_PLINK
, (uintptr_t)new_lh
,
782 FKIOCTL
, kcred
, muxid
);
784 cmn_err(CE_WARN
, "consconfig_relink_wc: "
785 "wc link failed, error %d", err
);
788 DPRINTF(DPRINT_L0
, "unlinking stream from under wc\n");
790 err
= ldi_ioctl(wc_lh
, I_PUNLINK
, *muxid
,
791 FKIOCTL
, kcred
, &rval
);
793 cmn_err(CE_WARN
, "consconfig_relink_wc: "
794 "wc unlink failed, error %d", err
);
800 (void) ldi_close(wc_lh
, FREAD
|FWRITE
, kcred
);
805 cons_build_upper_layer(cons_state_t
*sp
)
808 struct strioctl strioc
;
814 * Build the wc->conskbd portion of the keyboard console stream.
815 * Even if no keyboard is attached to the system, the upper
816 * layer of the stream will be built. If the user attaches
817 * a keyboard after the system is booted, the keyboard driver
818 * and module will be linked under conskbd.
820 * Errors are generally ignored here because conskbd and wc
821 * are pseudo drivers and should be present on the system.
824 /* open the console keyboard device. will never be closed */
825 if (ldi_open_by_name(CONSKBD_PATH
, FREAD
|FWRITE
|FNOCTTY
,
826 kcred
, &sp
->conskbd_lh
, sp
->cons_li
) != 0) {
827 panic("consconfig: unable to open conskbd device");
831 DPRINTF(DPRINT_L0
, "conskbd_lh = %p\n", sp
->conskbd_lh
);
833 /* open the console mouse device. will never be closed */
834 if (ldi_open_by_name(CONSMS_PATH
, FREAD
|FWRITE
|FNOCTTY
,
835 kcred
, &sp
->consms_lh
, sp
->cons_li
) != 0) {
836 panic("consconfig: unable to open consms device");
840 DPRINTF(DPRINT_L0
, "consms_lh = %p\n", sp
->consms_lh
);
843 * Get a vnode for the wc device and then grab a hold on the
844 * device dip so it can never detach. We need to do this now
845 * because later we'll have to open the wc device in a context
846 * were it isn't safe to acquire any device tree locks (ie, during
849 sp
->cons_wc_vp
= i_consconfig_createvp(WC_PATH
);
850 if (sp
->cons_wc_vp
== NULL
)
851 panic("consconfig: unable to find wc device");
853 if (e_ddi_hold_devi_by_dev(sp
->cons_wc_vp
->v_rdev
, 0) == NULL
)
854 panic("consconfig: unable to hold wc device");
857 * Build the wc->conskbd portion of the keyboard console stream.
858 * Even if no keyboard is attached to the system, the upper
859 * layer of the stream will be built. If the user attaches
860 * a keyboard after the system is booted, the keyboard driver
861 * and module will be linked under conskbd.
863 * The act of linking conskbd under wc will cause wc to
864 * query the lower layers about their polled I/O routines
865 * using CONSOPENPOLLEDIO. This will fail on this link because
866 * there is not a physical keyboard linked under conskbd.
868 * Since conskbd and wc are pseudo drivers, errors are
869 * generally ignored when linking and unlinking them.
871 (void) consconfig_relink_wc(sp
, sp
->conskbd_lh
, &sp
->conskbd_muxid
);
874 * Get a vnode for the redirection device. (It has the
875 * connection to the workstation console device wired into it,
876 * so that it's not necessary to establish the connection
877 * here. If the redirection device is ever generalized to
878 * handle multiple client devices, it won't be able to
879 * establish the connection itself, and we'll have to do it
882 wsconsvp
= i_consconfig_createvp(IWSCN_PATH
);
883 if (wsconsvp
== NULL
) {
884 panic("consconfig: unable to find iwscn device");
888 if (cons_tem_disable
)
891 if (sp
->cons_fb_path
== NULL
) {
893 if (sp
->cons_stdout_is_fb
)
894 cmn_err(CE_WARN
, "consconfig: no screen found");
899 /* make sure the frame buffer device exists */
900 dev
= ddi_pathname_to_dev_t(sp
->cons_fb_path
);
902 cmn_err(CE_WARN
, "consconfig: "
903 "cannot find driver for screen device %s",
908 #ifdef _HAVE_TEM_FIRMWARE
910 * If the underlying fb device doesn't support terminal emulation,
911 * we don't want to open the wc device (below) because it depends
912 * on features which aren't available (polled mode io).
914 if (!sp
->cons_tem_supported
)
916 #endif /* _HAVE_TEM_FIRMWARE */
918 /* tell wc to open the frame buffer device */
919 wc_dev
= sp
->cons_wc_vp
->v_rdev
;
920 if (ldi_open_by_dev(&wc_dev
, OTYP_CHR
, FREAD
|FWRITE
|FNOCTTY
, kcred
,
921 &wc_lh
, sp
->cons_li
)) {
922 cmn_err(CE_PANIC
, "cons_build_upper_layer: "
923 "unable to open wc device");
926 ASSERT(wc_dev
== sp
->cons_wc_vp
->v_rdev
);
928 strioc
.ic_cmd
= WC_OPEN_FB
;
929 strioc
.ic_timout
= INFTIM
;
930 strioc
.ic_len
= strlen(sp
->cons_fb_path
) + 1;
931 strioc
.ic_dp
= sp
->cons_fb_path
;
933 if (ldi_ioctl(wc_lh
, I_STR
, (intptr_t)&strioc
,
934 FKIOCTL
, kcred
, &rval
) == 0)
938 "consconfig: terminal emulator failed to initialize");
939 (void) ldi_close(wc_lh
, FREAD
|FWRITE
, kcred
);
943 consconfig_load_drivers(cons_state_t
*sp
)
946 * Calling ddi_pathname_to_dev_t may cause the USB Host Controller
947 * drivers to be loaded. Here we make sure that EHCI is loaded
948 * earlier than {U, O}HCI. The order here is important. As
949 * we have observed many systems on which hangs occur if the
950 * {U,O}HCI companion controllers take over control from the BIOS
951 * before EHCI does. These hangs are also caused by BIOSes leaving
952 * interrupt-on-port-change enabled in the ehci controller, so that
953 * when uhci/ohci reset themselves, it induces a port change on
954 * the ehci companion controller. Since there's no interrupt handler
955 * installed at the time, the moment that interrupt is unmasked, an
956 * interrupt storm will occur. All this is averted when ehci is
957 * loaded first. And now you know..... the REST of the story.
959 * Regardless of platform, ehci needs to initialize first to avoid
960 * unnecessary connects and disconnects on the companion controller
961 * when ehci sets up the routing.
963 * The same is generally true of xhci. Many platforms have routing
964 * between the xhci controller and the ehci controller. To avoid those
965 * same disconnects, we load xhci before ehci.
967 (void) ddi_hold_installed_driver(ddi_name_to_major("xhci"));
968 (void) ddi_hold_installed_driver(ddi_name_to_major("ehci"));
969 (void) ddi_hold_installed_driver(ddi_name_to_major("uhci"));
970 (void) ddi_hold_installed_driver(ddi_name_to_major("ohci"));
973 * The attaching of the drivers will cause the creation of the
974 * keyboard and mouse minor nodes, which will in turn trigger the
975 * dacf framework to call the keyboard and mouse configuration
976 * tasks. See PSARC/1998/212 for more details about the dacf
979 * on sparc, when the console is ttya, zs0 is stdin/stdout, and zs1
980 * is kb/mouse. zs0 must be attached before zs1. The zs driver
981 * is written this way and the hardware may depend on this, too.
982 * It would be better to enforce this by attaching zs in sibling
983 * order with a driver property, such as ddi-attachall.
985 if (sp
->cons_stdin_path
!= NULL
)
986 stdindev
= ddi_pathname_to_dev_t(sp
->cons_stdin_path
);
987 if (stdindev
== NODEV
) {
989 "!fail to attach stdin: %s\n", sp
->cons_stdin_path
);
991 if (sp
->cons_stdout_path
!= NULL
)
992 stdoutdev
= ddi_pathname_to_dev_t(sp
->cons_stdout_path
);
993 if (sp
->cons_keyboard_path
!= NULL
)
994 kbddev
= ddi_pathname_to_dev_t(sp
->cons_keyboard_path
);
995 if (sp
->cons_mouse_path
!= NULL
)
996 mousedev
= ddi_pathname_to_dev_t(sp
->cons_mouse_path
);
999 * On x86, make sure the fb driver is loaded even if we don't use it
1000 * for the console. This will ensure that we create a /dev/fb link
1001 * which is required to start Xorg.
1004 if (sp
->cons_fb_path
!= NULL
)
1005 fbdev
= ddi_pathname_to_dev_t(sp
->cons_fb_path
);
1008 DPRINTF(DPRINT_L0
, "stdindev %lx, stdoutdev %lx, kbddev %lx, "
1009 "mousedev %lx\n", stdindev
, stdoutdev
, kbddev
, mousedev
);
1014 consconfig_virtual_console_vp(cons_state_t
*sp
)
1016 char *virtual_cons_path
;
1018 if (plat_virtual_console_path(&virtual_cons_path
) < 0)
1021 DPRINTF(DPRINT_L0
, "consconfig_virtual_console_vp: "
1022 "virtual console device path %s\n", virtual_cons_path
);
1024 ASSERT(sp
->cons_stdout_path
!= NULL
);
1025 if (strcmp(virtual_cons_path
, sp
->cons_stdout_path
) == 0) {
1026 /* virtual console already in use */
1030 vsconsvp
= i_consconfig_createvp(virtual_cons_path
);
1031 if (vsconsvp
== NULL
) {
1032 cmn_err(CE_WARN
, "consconfig_virtual_console_vp: "
1033 "unable to find serial virtual console device %s",
1038 (void) e_ddi_hold_devi_by_dev(vsconsvp
->v_rdev
, 0);
1043 consconfig_init_framebuffer(cons_state_t
*sp
)
1045 if (!sp
->cons_stdout_is_fb
)
1048 DPRINTF(DPRINT_L0
, "stdout is framebuffer\n");
1049 ASSERT(strcmp(sp
->cons_fb_path
, sp
->cons_stdout_path
) == 0);
1052 * Console output is a framebuffer.
1053 * Find the framebuffer driver if we can, and make
1054 * ourselves a shadow vnode to track it with.
1057 if (fbdev
== NODEV
) {
1059 "Can't find driver for console framebuffer\n");
1061 /* stdoutdev is valid, of fbvp should exist */
1062 fbvp
= i_consconfig_createvp(sp
->cons_stdout_path
);
1064 panic("consconfig_init_framebuffer: "
1065 "unable to find frame buffer device");
1068 ASSERT(fbvp
->v_rdev
== fbdev
);
1070 /* console device is never released */
1071 fbdip
= e_ddi_hold_devi_by_dev(fbdev
, 0);
1073 pm_cfb_setup(sp
->cons_stdout_path
);
1077 * consconfig_prepare_dev:
1078 * Flush the stream, push "pushmod" onto the stream.
1079 * for keyboard, issue the KIOCTRANSABLE ioctl, and
1080 * possible enable abort.
1083 consconfig_prepare_dev(
1084 ldi_handle_t new_lh
,
1085 const char *pushmod
,
1086 int kbdtranslatable
,
1092 /* send a flush down the stream to the keyboard driver */
1093 (void) ldi_ioctl(new_lh
, I_FLUSH
, (intptr_t)FLUSHRW
,
1094 FKIOCTL
, kcred
, &rval
);
1097 err
= ldi_ioctl(new_lh
, I_PUSH
, (intptr_t)pushmod
,
1098 FKIOCTL
, kcred
, &rval
);
1100 cmn_err(CE_WARN
, "consconfig_prepare_dev: "
1101 "can't push streams module \"%s\", error %d",
1106 if (dev_type
== CONS_MS
)
1109 ASSERT(dev_type
== CONS_KBD
);
1111 err
= ldi_ioctl(new_lh
, KIOCTRANSABLE
,
1112 (intptr_t)&kbdtranslatable
, FKIOCTL
, kcred
, &rval
);
1114 cmn_err(CE_WARN
, "consconfig_prepare_dev: "
1115 "KIOCTRANSABLE failed, error: %d", err
);
1119 * During boot, dynamic_console_config() will call the
1120 * function to enable abort on the console. If the
1121 * keyboard is hotplugged after boot, check to see if
1122 * the keyboard is the console input. If it is
1123 * enable abort on it.
1125 if (input_type
== CONSOLE_LOCAL
)
1126 (void) consconfig_kbd_abort_enable(new_lh
);
1130 * consconfig_relink_conskbd:
1131 * If new_lh is not NULL it should represent a driver with a
1132 * keyboard module pushed on top of it. The driver is then linked
1133 * underneath conskbd. the resulting stream will be
1134 * wc->conskbd->"new_lh driver".
1136 * If new_lh is NULL, then an unlink operation is done on conskbd
1137 * that attempts to unlink the stream specified by *muxid.
1138 * the resulting stream will be wc->conskbd.
1141 consconfig_relink_conskbd(cons_state_t
*sp
, ldi_handle_t new_lh
, int *muxid
)
1144 int conskbd_relink
= 0;
1146 ASSERT(muxid
!= NULL
);
1148 DPRINTF(DPRINT_L0
, "consconfig_relink_conskbd: "
1149 "conskbd_lh = %p, new_lh = %p, muxid = %x\n",
1150 sp
->conskbd_lh
, new_lh
, *muxid
);
1153 * If conskbd is linked under wc then temporarily unlink it
1154 * from under wc so that the new_lh stream may be linked under
1155 * conskbd. This has to be done because streams are built bottom
1156 * up and linking a stream under conskbd isn't allowed when
1157 * conskbd is linked under wc.
1159 if (sp
->conskbd_muxid
!= -1) {
1160 DPRINTF(DPRINT_L0
, "unlinking conskbd from under wc\n");
1162 err
= consconfig_relink_wc(sp
, NULL
, &sp
->conskbd_muxid
);
1164 cmn_err(CE_WARN
, "consconfig_relink_conskbd: "
1165 "wc unlink failed, error %d", err
);
1170 if (new_lh
!= NULL
) {
1171 DPRINTF(DPRINT_L0
, "linking keyboard under conskbd\n");
1173 /* Link the stream represented by new_lh under conskbd */
1174 err
= ldi_ioctl(sp
->conskbd_lh
, I_PLINK
, (uintptr_t)new_lh
,
1175 FKIOCTL
, kcred
, muxid
);
1177 cmn_err(CE_WARN
, "consconfig_relink_conskbd: "
1178 "conskbd link failed, error %d", err
);
1182 DPRINTF(DPRINT_L0
, "unlinking keyboard from under conskbd\n");
1185 * This will cause the keyboard driver to be closed,
1186 * all modules to be popped, and the keyboard vnode released.
1188 err
= ldi_ioctl(sp
->conskbd_lh
, I_PUNLINK
, *muxid
,
1189 FKIOCTL
, kcred
, &rval
);
1191 cmn_err(CE_WARN
, "consconfig_relink_conskbd: "
1192 "conskbd unlink failed, error %d", err
);
1198 consconfig_check_phys_kbd(sp
);
1201 if (!conskbd_relink
)
1205 * Link consbkd back under wc.
1207 * The act of linking conskbd back under wc will cause wc
1208 * to query the lower lower layers about their polled I/O
1209 * routines. This time the request will succeed because there
1210 * is a physical keyboard linked under conskbd.
1212 DPRINTF(DPRINT_L0
, "re-linking conskbd under wc\n");
1213 err
= consconfig_relink_wc(sp
, sp
->conskbd_lh
, &sp
->conskbd_muxid
);
1215 cmn_err(CE_WARN
, "consconfig_relink_conskbd: "
1216 "wc link failed, error %d", err
);
1221 if (!conskbd_relink
)
1224 /* something went wrong, try to reconnect conskbd back under wc */
1225 DPRINTF(DPRINT_L0
, "re-linking conskbd under wc\n");
1226 (void) consconfig_relink_wc(sp
, sp
->conskbd_lh
, &sp
->conskbd_muxid
);
1231 * consconfig_relink_consms:
1232 * If new_lh is not NULL it should represent a driver with a
1233 * mouse module pushed on top of it. The driver is then linked
1234 * underneath consms. the resulting stream will be
1235 * consms->"new_lh driver".
1237 * If new_lh is NULL, then an unlink operation is done on consms
1238 * that attempts to unlink the stream specified by *muxid.
1241 consconfig_relink_consms(cons_state_t
*sp
, ldi_handle_t new_lh
, int *muxid
)
1245 DPRINTF(DPRINT_L0
, "consconfig_relink_consms: "
1246 "consms_lh = %p, new_lh = %p, muxid = %x\n",
1247 (void *)sp
->consms_lh
, (void *)new_lh
, *muxid
);
1249 if (new_lh
!= NULL
) {
1250 DPRINTF(DPRINT_L0
, "linking mouse under consms\n");
1252 /* Link ms/usbms stream underneath consms multiplexor. */
1253 err
= ldi_ioctl(sp
->consms_lh
, I_PLINK
, (uintptr_t)new_lh
,
1254 FKIOCTL
, kcred
, muxid
);
1256 cmn_err(CE_WARN
, "consconfig_relink_consms: "
1257 "mouse link failed, error %d", err
);
1260 DPRINTF(DPRINT_L0
, "unlinking mouse from under consms\n");
1262 /* Tear down the mouse stream */
1263 err
= ldi_ioctl(sp
->consms_lh
, I_PUNLINK
, *muxid
,
1264 FKIOCTL
, kcred
, &rval
);
1266 cmn_err(CE_WARN
, "consconfig_relink_consms: "
1267 "mouse unlink failed, error %d", err
);
1276 cons_get_input_type(cons_state_t
*sp
)
1281 * Now that we know what all the devices are, we can figure out
1282 * what kind of console we have.
1284 if (sp
->cons_stdin_is_kbd
) {
1285 /* Stdin is from the system keyboard */
1286 type
= CONSOLE_LOCAL
;
1287 } else if ((stdindev
!= NODEV
) && (stdindev
== stdoutdev
)) {
1289 * A reliable indicator that we are doing a remote console
1290 * is that stdin and stdout are the same.
1291 * This is probably a tip line.
1295 type
= CONSOLE_SERIAL_KEYBOARD
;
1302 consconfig_init_input(cons_state_t
*sp
)
1304 ldi_handle_t new_lh
;
1305 dev_t cons_final_dev
;
1308 cons_final_dev
= NODEV
;
1310 switch (sp
->cons_input_type
) {
1312 DPRINTF(DPRINT_L0
, "stdin is keyboard\n");
1315 * The machine is allowed to boot without a keyboard.
1316 * If a user attaches a keyboard later, the keyboard
1317 * will be hooked into the console stream with the dacf
1320 * The only drivers that look at kbbdev are the
1321 * serial drivers, which looks at kbdev to see if
1322 * they should allow abort on a break. In the absence
1323 * of keyboard, the serial drivers won't be attached
1324 * for any keyboard instance.
1326 if (kbddev
== NODEV
) {
1328 * If there is a problem with the keyboard
1329 * during the driver loading, then the polled
1330 * input won't get setup properly if polled
1331 * input is needed. This means that if the
1332 * keyboard is hotplugged, the keyboard would
1333 * work normally, but going down to the
1334 * debugger would not work if polled input is
1335 * required. This field is set here. The next
1336 * time a keyboard is plugged in, the field is
1337 * checked in order to give the next keyboard a
1338 * chance at being registered for console
1341 * Although this code will rarely be needed,
1342 * USB keyboards can be flaky, so this code
1343 * will be useful on the occasion that the
1344 * keyboard doesn't enumerate when the drivers
1347 DPRINTF(DPRINT_L2
, "Error with console keyboard\n");
1348 sp
->cons_keyboard_problem
= B_TRUE
;
1351 cons_final_dev
= sp
->cons_wc_vp
->v_rdev
;
1355 DPRINTF(DPRINT_L0
, "console input is tty (%s)\n",
1356 sp
->cons_stdin_path
);
1359 * Console device drivers must be able to output
1360 * after being closed.
1362 rconsvp
= i_consconfig_createvp(sp
->cons_stdin_path
);
1363 if (rconsvp
== NULL
) {
1364 panic("consconfig_init_input: "
1365 "unable to find stdin device (%s)",
1366 sp
->cons_stdin_path
);
1369 rconsdev
= rconsvp
->v_rdev
;
1371 ASSERT(rconsdev
== stdindev
);
1373 cons_final_dev
= rconsdev
;
1376 case CONSOLE_SERIAL_KEYBOARD
:
1377 DPRINTF(DPRINT_L0
, "stdin is serial keyboard\n");
1380 * Non-keyboard input device, but not rconsdev.
1381 * This is known as the "serial keyboard" case - the
1382 * most likely use is someone has a keyboard attached
1383 * to a serial port (tip) and still has output on a
1386 * In this case, the serial driver must be linked
1387 * directly beneath wc. Since conskbd was linked
1388 * underneath wc above, first we unlink conskbd.
1390 (void) consconfig_relink_wc(sp
, NULL
, &sp
->conskbd_muxid
);
1391 sp
->conskbd_muxid
= -1;
1394 * Open the serial keyboard, configure it,
1395 * and link it underneath wc.
1397 err
= ldi_open_by_name(sp
->cons_stdin_path
,
1398 FREAD
|FWRITE
|FNOCTTY
, kcred
, &new_lh
, sp
->cons_li
);
1400 struct termios termios
;
1404 consconfig_prepare_dev(new_lh
,
1405 "kb", TR_CANNOT
, sp
->cons_input_type
, CONS_KBD
);
1407 /* Re-set baud rate */
1408 (void) ldi_ioctl(new_lh
, TCGETS
, (intptr_t)&termios
,
1409 FKIOCTL
, kcred
, &rval
);
1412 if (consconfig_setmodes(stdindev
, &termios
) == 0) {
1413 err
= ldi_ioctl(new_lh
,
1414 TCSETSF
, (intptr_t)&termios
,
1415 FKIOCTL
, kcred
, &rval
);
1418 "consconfig_init_input: "
1419 "TCSETSF failed, error %d", err
);
1424 * Now link the serial keyboard direcly under wc
1425 * we don't save the returned muxid because we
1426 * don't support changing/hotplugging the console
1427 * keyboard when it is a serial keyboard.
1429 (void) consconfig_relink_wc(sp
, new_lh
, &stdin_muxid
);
1431 (void) ldi_close(new_lh
, FREAD
|FWRITE
, kcred
);
1434 cons_final_dev
= sp
->cons_wc_vp
->v_rdev
;
1438 panic("consconfig_init_input: "
1439 "unsupported console input/output combination");
1444 * Use the redirection device/workstation console pair as the "real"
1445 * console if the latter hasn't already been set.
1446 * The workstation console driver needs to see rwsconsvp, but
1447 * all other access should be through the redirecting driver.
1449 if (rconsvp
== NULL
) {
1450 consconfig_dprintf(DPRINT_L0
, "setup redirection driver\n");
1452 rconsdev
= wsconsvp
->v_rdev
;
1455 ASSERT(cons_final_dev
!= NODEV
);
1457 err
= ldi_open_by_dev(&cons_final_dev
, OTYP_CHR
, FREAD
|FWRITE
|FNOCTTY
,
1458 kcred
, &new_lh
, sp
->cons_li
);
1460 panic("consconfig_init_input: "
1461 "unable to open console device");
1465 /* Enable abort on the console */
1466 (void) consconfig_kbd_abort_enable(new_lh
);
1468 /* Now we must close it to make console logins happy */
1469 (void) ldi_close(new_lh
, FREAD
|FWRITE
, kcred
);
1471 /* Set up polled input if it is supported by the console device */
1472 if (plat_use_polled_debug()) {
1474 * In the debug case, register the keyboard polled entry
1475 * points, but don't throw the switch in the debugger. This
1476 * allows the polled entry points to be checked by hand
1478 consconfig_setup_polledio(sp
, sp
->cons_wc_vp
->v_rdev
);
1480 consconfig_setup_polledio(sp
, cons_final_dev
);
1487 * This function kicks off the console configuration.
1488 * Configure keyboard and mouse. Main entry here.
1491 dynamic_console_config(void)
1493 /* initialize space.c globals */
1506 /* Initialize cons_state_t structure and console device paths */
1507 consconfig_sp
= consconfig_state_init();
1508 ASSERT(consconfig_sp
);
1510 /* Build upper layer of console stream */
1511 cons_build_upper_layer(consconfig_sp
);
1514 * Load keyboard/mouse drivers. The dacf routines will
1515 * plumb the devices into the console stream
1517 * At the conclusion of the ddi_pathname_to_dev_t calls, the keyboard
1518 * and mouse drivers are linked into their respective console
1519 * streams if the pathnames are valid.
1521 consconfig_load_drivers(consconfig_sp
);
1522 consconfig_sp
->cons_input_type
= cons_get_input_type(consconfig_sp
);
1524 rwsconsvp
= consconfig_sp
->cons_wc_vp
;
1525 rwsconsdev
= consconfig_sp
->cons_wc_vp
->v_rdev
;
1528 /* initialize framebuffer, console input, and redirection device */
1529 consconfig_init_framebuffer(consconfig_sp
);
1530 consconfig_init_input(consconfig_sp
);
1533 /* initialize virtual console vp for logging if needed */
1534 consconfig_virtual_console_vp(consconfig_sp
);
1538 "mousedev %lx, kbddev %lx, fbdev %lx, rconsdev %lx\n",
1539 mousedev
, kbddev
, fbdev
, rconsdev
);
1541 flush_deferred_console_buf();
1543 consconfig_sp
->cons_initialized
= B_TRUE
;
1548 * Start of DACF interfaces
1552 * Do the real job for keyboard/mouse auto-configuration.
1555 do_config(cons_state_t
*sp
, cons_prop_t
*prop
)
1561 ASSERT((prop
->cp_type
== CONS_KBD
) || (prop
->cp_type
== CONS_MS
));
1564 error
= ldi_open_by_dev(&dev
, OTYP_CHR
,
1565 FREAD
|FWRITE
|FNOCTTY
, kcred
, &lh
, sp
->cons_li
);
1567 return (DACF_FAILURE
);
1569 ASSERT(dev
== prop
->cp_dev
); /* clone not supported */
1572 * Prepare the new keyboard/mouse driver
1573 * to be linked under conskbd/consms.
1575 consconfig_prepare_dev(lh
, prop
->cp_pushmod
, TR_CAN
,
1576 sp
->cons_input_type
, prop
->cp_type
);
1578 if (prop
->cp_type
== CONS_KBD
) {
1580 * Tell the physical keyboard driver to send
1581 * the abort sequences up to the virtual keyboard
1582 * driver so that STOP and A (or F1 and A)
1583 * can be applied to different keyboards.
1585 (void) consconfig_kbd_abort_disable(lh
);
1587 /* Link the stream underneath conskbd */
1588 error
= consconfig_relink_conskbd(sp
, lh
, &prop
->cp_muxid
);
1590 /* Link the stream underneath consms */
1591 error
= consconfig_relink_consms(sp
, lh
, &prop
->cp_muxid
);
1595 * At this point, the stream is:
1596 * for keyboard: wc->conskbd->["pushmod"->"kbd_vp driver"]
1597 * for mouse: consms->["module_name"->]"mouse_avp driver"
1600 /* Close the driver stream, it will stay linked under conskbd */
1601 (void) ldi_close(lh
, FREAD
|FWRITE
, kcred
);
1604 return (DACF_FAILURE
);
1607 return (DACF_SUCCESS
);
1611 do_unconfig(cons_state_t
*sp
, cons_prop_t
*prop
)
1613 ASSERT((prop
->cp_type
== CONS_KBD
) || (prop
->cp_type
== CONS_MS
));
1615 if (prop
->cp_type
== CONS_KBD
)
1616 return (consconfig_relink_conskbd(sp
, NULL
, &prop
->cp_muxid
));
1618 return (consconfig_relink_consms(sp
, NULL
, &prop
->cp_muxid
));
1622 kb_ms_config(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int type
)
1630 const char *pushmod
;
1633 * Retrieve the state information
1634 * Some platforms may use the old-style "consconfig" to configure
1635 * console stream modules but may also support devices that happen
1636 * to match a rule in /etc/dacf.conf. This will cause a problem
1637 * since the console state structure will not be initialized.
1638 * In that case, these entry points should silently fail and
1639 * permit console to be plumbed later in boot.
1641 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
1642 return (DACF_FAILURE
);
1644 dip
= dacf_devinfo_node(minor_hdl
);
1645 major
= ddi_driver_major(dip
);
1646 ASSERT(major
!= DDI_MAJOR_T_NONE
);
1647 minor
= dacf_minor_number(minor_hdl
);
1648 dev
= makedevice(major
, minor
);
1649 ASSERT(dev
!= NODEV
);
1651 DPRINTF(DPRINT_L0
, "driver name = \"%s\", dev = 0x%lx, major = 0x%x\n",
1652 (char *)dacf_driver_name(minor_hdl
), dev
, major
);
1654 /* Access to the global variables is synchronized */
1655 mutex_enter(&sp
->cons_lock
);
1658 * Check if the keyboard/mouse has already configured.
1660 if (consconfig_find_dev(sp
, dev
) != NULL
) {
1661 mutex_exit(&sp
->cons_lock
);
1662 return (DACF_SUCCESS
);
1665 prop
= kmem_zalloc(sizeof (cons_prop_t
), KM_SLEEP
);
1667 /* Config the new keyboard/mouse device */
1670 pushmod
= dacf_get_arg(arg_hdl
, "pushmod");
1671 prop
->cp_pushmod
= i_ddi_strdup((char *)pushmod
, KM_SLEEP
);
1673 prop
->cp_type
= type
;
1674 if (do_config(sp
, prop
) != DACF_SUCCESS
) {
1676 * The keyboard/mouse node failed to open.
1677 * Set the major and minor numbers to 0 so
1678 * kb_unconfig/ms_unconfig won't unconfigure
1679 * this node if it is detached.
1681 mutex_exit(&sp
->cons_lock
);
1682 consconfig_free_prop(prop
);
1683 return (DACF_FAILURE
);
1686 consconfig_add_dev(sp
, prop
);
1689 * See if there was a problem with the console keyboard during boot.
1690 * If so, try to register polled input for this keyboard.
1692 if ((type
== CONS_KBD
) && (sp
->cons_keyboard_problem
)) {
1693 consconfig_setup_polledio(sp
, sp
->cons_wc_vp
->v_rdev
);
1694 sp
->cons_keyboard_problem
= B_FALSE
;
1697 /* Prevent autodetach due to memory pressure */
1698 (void) ddi_prop_update_int(DDI_DEV_T_NONE
, dip
, DDI_NO_AUTODETACH
, 1);
1700 mutex_exit(&sp
->cons_lock
);
1702 return (DACF_SUCCESS
);
1706 kb_ms_unconfig(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
)
1708 _NOTE(ARGUNUSED(arg_hdl
))
1718 * Retrieve the state information
1719 * So if there isn't a state available, then this entry point just
1720 * returns. See note in kb_config().
1722 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
1723 return (DACF_SUCCESS
);
1725 dip
= dacf_devinfo_node(minor_hdl
);
1726 major
= ddi_driver_major(dip
);
1727 ASSERT(major
!= DDI_MAJOR_T_NONE
);
1728 minor
= dacf_minor_number(minor_hdl
);
1729 dev
= makedevice(major
, minor
);
1730 ASSERT(dev
!= NODEV
);
1733 * Check if the keyboard/mouse that is being detached
1734 * is the console keyboard/mouse or not.
1736 mutex_enter(&sp
->cons_lock
);
1737 if ((prop
= consconfig_find_dev(sp
, dev
)) == NULL
) {
1738 mutex_exit(&sp
->cons_lock
);
1739 return (DACF_SUCCESS
);
1743 * This dev may be opened physically and then hotplugged out.
1745 if (prop
->cp_muxid
!= -1) {
1746 (void) do_unconfig(sp
, prop
);
1747 consconfig_rem_dev(sp
, dev
);
1750 mutex_exit(&sp
->cons_lock
);
1752 return (DACF_SUCCESS
);
1756 * This is the post-attach / pre-detach action function for the keyboard
1757 * and mouse. This function is associated with a node type in /etc/dacf.conf.
1760 kb_config(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int flags
)
1762 _NOTE(ARGUNUSED(flags
))
1764 return (kb_ms_config(minor_hdl
, arg_hdl
, CONS_KBD
));
1768 ms_config(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int flags
)
1770 _NOTE(ARGUNUSED(flags
))
1772 return (kb_ms_config(minor_hdl
, arg_hdl
, CONS_MS
));
1776 kb_unconfig(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int flags
)
1778 _NOTE(ARGUNUSED(flags
))
1780 return (kb_ms_unconfig(minor_hdl
, arg_hdl
));
1784 ms_unconfig(dacf_infohdl_t minor_hdl
, dacf_arghdl_t arg_hdl
, int flags
)
1786 _NOTE(ARGUNUSED(flags
))
1788 return (kb_ms_unconfig(minor_hdl
, arg_hdl
));
1792 * consconfig_link and consconfig_unlink are provided to support
1793 * direct access to physical keyboard/mouse underlying conskbd/
1795 * When the keyboard/mouse is opened physically via its device
1796 * file, it will be unlinked from the virtual one, and when it
1797 * is closed physically, it will be linked back under the virtual
1801 consconfig_link(major_t major
, minor_t minor
)
1803 char buf
[MAXPATHLEN
];
1808 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
1811 dev
= makedevice(major
, minor
);
1812 ASSERT(dev
!= NODEV
);
1814 mutex_enter(&sp
->cons_lock
);
1815 if ((prop
= consconfig_find_dev(sp
, dev
)) == NULL
) {
1816 mutex_exit(&sp
->cons_lock
);
1820 if (do_config(sp
, prop
) != DACF_SUCCESS
) {
1821 (void) ddi_dev_pathname(dev
, 0, buf
);
1822 if (prop
->cp_type
== CONS_KBD
)
1823 cmn_err(CE_WARN
, "Failed to relink the keyboard "
1824 "(%s) underneath virtual keyboard", buf
);
1826 cmn_err(CE_WARN
, "Failed to relink the mouse "
1827 "(%s) underneath virtual mouse", buf
);
1828 consconfig_rem_dev(sp
, dev
);
1831 mutex_exit(&sp
->cons_lock
);
1836 consconfig_unlink(major_t major
, minor_t minor
)
1843 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
1844 return (DACF_SUCCESS
);
1846 dev
= makedevice(major
, minor
);
1847 ASSERT(dev
!= NODEV
);
1849 mutex_enter(&sp
->cons_lock
);
1850 if ((prop
= consconfig_find_dev(sp
, dev
)) == NULL
) {
1851 mutex_exit(&sp
->cons_lock
);
1852 return (DACF_FAILURE
);
1855 error
= do_unconfig(sp
, prop
);
1858 * Keep this dev on the list, for this dev is still online.
1860 mutex_exit(&sp
->cons_lock
);
1866 * Routine to set baud rate, bits-per-char, parity and stop bits
1867 * on the console line when necessary.
1870 consconfig_setmodes(dev_t dev
, struct termios
*termiosp
)
1872 char buf
[MAXPATHLEN
];
1873 int len
= MAXPATHLEN
;
1880 * First, search for a devalias which matches this dev_t.
1881 * Try all of ttya through ttyz until no such alias
1883 (void) strcpy(name
, "ttya");
1884 for (i
= 0; i
< ('z'-'a'); i
++) {
1885 name
[3] = 'a' + i
; /* increment device name */
1886 path
= get_alias(name
, buf
);
1890 tdev
= ddi_pathname_to_dev_t(path
);
1892 break; /* Exit loop if found */
1896 return (1); /* If we didn't find it, return */
1899 * Now that we know which "tty" this corresponds to, retrieve
1900 * the "ttya-mode" options property, which tells us how to configure
1903 (void) strcpy(name
, "ttya-mode"); /* name of option we want */
1904 name
[3] = 'a' + i
; /* Adjust to correct line */
1906 if (ddi_getlongprop_buf(DDI_DEV_T_ANY
, ddi_root_node(), 0, name
,
1907 buf
, &len
) != DDI_PROP_SUCCESS
)
1908 return (1); /* if no such option, just return */
1911 * The IEEE 1275 standard specifies that /aliases string property
1912 * values should be null-terminated. Unfortunately the reality
1913 * is that most aren't and the OBP can't easily be modified to
1914 * add null termination to these strings. So we'll add the
1915 * null termination here. If the string already contains a
1916 * null termination character then that's ok too because we'll
1917 * just be adding a second one.
1921 /* Clear out options we will be setting */
1922 termiosp
->c_cflag
&=
1923 ~(CSIZE
| CBAUD
| CBAUDEXT
| PARODD
| PARENB
| CSTOPB
);
1925 /* Clear options which potentially conflict with new settings */
1926 termiosp
->c_cflag
&= ~(CIBAUD
| CIBAUDEXT
);
1929 * Now, parse the string. Wish I could use sscanf().
1930 * Format 9600,8,n,1,-
1931 * baud rate, bits-per-char, parity, stop-bits, ignored
1933 for (ppos
= 0; ppos
< (MAXPATHLEN
-8); ppos
++) { /* Find first comma */
1934 if ((buf
[ppos
] == 0) || (buf
[ppos
] == ','))
1938 if (buf
[ppos
] != ',') {
1939 cmn_err(CE_WARN
, "consconfig_setmodes: "
1940 "invalid mode string %s", buf
);
1944 for (i
= 0; i
< MAX_SPEEDS
; i
++) {
1945 if (strncmp(buf
, speedtab
[i
].name
, ppos
) == 0)
1949 if (i
>= MAX_SPEEDS
) {
1951 "consconfig_setmodes: unrecognized speed in %s", buf
);
1955 /* Found the baud rate, set it */
1956 termiosp
->c_cflag
|= speedtab
[i
].code
& CBAUD
;
1957 if (speedtab
[i
].code
> 16) /* cfsetospeed! */
1958 termiosp
->c_cflag
|= CBAUDEXT
;
1960 /* Set bits per character */
1961 switch (buf
[ppos
+1]) {
1963 termiosp
->c_cflag
|= CS8
;
1966 termiosp
->c_cflag
|= CS7
;
1970 "consconfig_setmodes: illegal bits-per-char %s", buf
);
1975 switch (buf
[ppos
+3]) {
1977 termiosp
->c_cflag
|= PARENB
| PARODD
;
1980 termiosp
->c_cflag
|= PARENB
; /* enabled, not odd */
1983 break; /* not enabled. */
1985 cmn_err(CE_WARN
, "consconfig_setmodes: illegal parity %s", buf
);
1990 switch (buf
[ppos
+5]) {
1992 break; /* No extra stop bit */
1994 termiosp
->c_cflag
|= CSTOPB
; /* 1 extra stop bit */
1997 cmn_err(CE_WARN
, "consconfig_setmodes: "
1998 "illegal stop bits %s", buf
);
2006 * Check to see if underlying keyboard devices are still online,
2007 * if any one is offline now, unlink it.
2010 consconfig_check_phys_kbd(cons_state_t
*sp
)
2017 for (prop
= sp
->cons_km_prop
; prop
; prop
= prop
->cp_next
) {
2018 if ((prop
->cp_type
!= CONS_KBD
) || (prop
->cp_muxid
== -1))
2021 error
= ldi_open_by_dev(&prop
->cp_dev
, OTYP_CHR
,
2022 FREAD
|FWRITE
|FNOCTTY
, kcred
, &kb_lh
, sp
->cons_li
);
2025 (void) ldi_ioctl(sp
->conskbd_lh
, I_PUNLINK
,
2026 prop
->cp_muxid
, FKIOCTL
, kcred
, &rval
);
2027 prop
->cp_dev
= NODEV
;
2029 (void) ldi_close(kb_lh
, FREAD
|FWRITE
, kcred
);
2034 * Remove all disconnected keyboards,
2035 * whose dev is turned into NODEV above.
2037 consconfig_rem_dev(sp
, NODEV
);
2041 * Remove devices according to dev, which may be NODEV
2044 consconfig_rem_dev(cons_state_t
*sp
, dev_t dev
)
2047 cons_prop_t
*prev_prop
;
2048 cons_prop_t
*tmp_prop
;
2049 cons_prop_t
*head_prop
;
2053 for (prop
= sp
->cons_km_prop
; prop
!= NULL
; ) {
2054 if (prop
->cp_dev
== dev
) {
2055 tmp_prop
= prop
->cp_next
;
2056 consconfig_free_prop(prop
);
2059 prev_prop
->cp_next
= prop
;
2061 if (head_prop
== NULL
)
2064 prop
= prop
->cp_next
;
2067 sp
->cons_km_prop
= head_prop
;
2071 * Add a dev according to prop
2074 consconfig_add_dev(cons_state_t
*sp
, cons_prop_t
*prop
)
2076 prop
->cp_next
= sp
->cons_km_prop
;
2077 sp
->cons_km_prop
= prop
;
2081 * Find a device from our list according to dev
2083 static cons_prop_t
*
2084 consconfig_find_dev(cons_state_t
*sp
, dev_t dev
)
2088 for (prop
= sp
->cons_km_prop
; prop
; prop
= prop
->cp_next
) {
2089 if (prop
->cp_dev
== dev
)
2097 * Free a cons prop associated with a keyboard or mouse
2100 consconfig_free_prop(cons_prop_t
*prop
)
2102 if (prop
->cp_pushmod
)
2103 kmem_free(prop
->cp_pushmod
, strlen(prop
->cp_pushmod
) + 1);
2104 kmem_free(prop
, sizeof (cons_prop_t
));
2108 * The early boot code can't print to a usb serial device or the
2109 * graphical boot screen.
2111 * The early boot messages are saved in a buffer at the address indicated
2112 * by "deferred-console-buf" This function flushes the message to the
2113 * current console now that it is set up.
2116 flush_deferred_console_buf(void)
2121 char *kc
, *bc
, *defcons_kern_buf
;
2123 /* defcons_buf is in low memory, so an int works here */
2124 defcons_buf
= ddi_prop_get_int(DDI_DEV_T_ANY
, ddi_root_node(),
2125 DDI_PROP_DONTPASS
, "deferred-console-buf", 0);
2127 if (defcons_buf
== 0)
2131 * After consconfig() and before userland opens /dev/sysmsg,
2132 * console I/O is goes to polled I/O entry points.
2134 * If usb-serial doesn't implement polled I/O, we need
2135 * to open /dev/console now to get kernel console I/O to work.
2136 * We also push ttcompat and ldterm explicitly to get the
2137 * correct output format (autopush isn't set up yet). We
2138 * ignore push errors because they are non-fatal.
2139 * Note that opening /dev/console causes rconsvp to be
2142 if (cons_polledio
== NULL
) {
2143 if (vn_open("/dev/console", UIO_SYSSPACE
, FWRITE
| FNOCTTY
,
2148 (void) strioctl(rconsvp
, __I_PUSH_NOCTTY
,
2149 (intptr_t)"ldterm", FKIOCTL
, K_TO_K
, kcred
, &rval
);
2150 (void) strioctl(rconsvp
, __I_PUSH_NOCTTY
,
2151 (intptr_t)"ttcompat", FKIOCTL
, K_TO_K
,
2157 * Copy message to a kernel buffer. Various kernel routines
2158 * expect buffer to be above kernelbase
2160 kc
= defcons_kern_buf
= kmem_zalloc(MMU_PAGESIZE
, KM_SLEEP
);
2161 bc
= (char *)(uintptr_t)defcons_buf
;
2162 while (*kc
++ = *bc
++)
2164 console_printf("%s", defcons_kern_buf
);
2166 kmem_free(defcons_kern_buf
, MMU_PAGESIZE
);
2170 consconfig_console_is_tipline(void)
2174 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
2177 if (sp
->cons_input_type
== CONSOLE_TIP
)
2184 consconfig_dacf_initialized(void)
2188 if ((sp
= (cons_state_t
*)space_fetch("consconfig")) == NULL
)
2191 return (sp
->cons_initialized
);