consconfig_dacf.c revision 361ed64a5abddd9ed26f47e25824bbce82557ab4
0N/A/*
0N/A * CDDL HEADER START
0N/A *
0N/A * The contents of this file are subject to the terms of the
0N/A * Common Development and Distribution License (the "License").
0N/A * You may not use this file except in compliance with the License.
0N/A *
0N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0N/A * or http://www.opensolaris.org/os/licensing.
0N/A * See the License for the specific language governing permissions
0N/A * and limitations under the License.
0N/A *
0N/A * When distributing Covered Code, include this CDDL HEADER in each
0N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0N/A * If applicable, add the following below this CDDL HEADER, with the
0N/A * fields enclosed by brackets "[]" replaced with your own identifying
0N/A * information: Portions Copyright [yyyy] [name of copyright owner]
0N/A *
0N/A * CDDL HEADER END
0N/A */
0N/A
0N/A/*
0N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
0N/A * Use is subject to license terms.
0N/A */
0N/A
0N/A/*
0N/A * This module performs two functions. First, it kicks off the driver loading
0N/A * of the console devices during boot in dynamic_console_config().
0N/A * The loading of the drivers for the console devices triggers the
0N/A * additional device autoconfiguration to link the drivers into the keyboard
0N/A * and mouse console streams.
0N/A *
0N/A * The second function of this module is to provide the dacf functions
0N/A * to be called after a driver has attached and before it detaches. For
0N/A * example, a driver associated with the keyboard will have kb_config called
0N/A * after the driver attaches and kb_unconfig before it detaches. Similar
0N/A * configuration actions are performed on behalf of minor nodes representing
0N/A * mice. The configuration functions for the attach case take a module
0N/A * name as a parameter. The module is pushed on top of the driver during
0N/A * the configuration.
0N/A *
0N/A * Although the dacf framework is used to configure all keyboards and mice,
0N/A * its primary function is to allow keyboard and mouse hotplugging.
0N/A *
0N/A * This module supports multiple keyboards and mice at the same time.
0N/A *
0N/A * From the kernel perspective, there are roughly three different possible
0N/A * console configurations. Across these three configurations, the following
0N/A * elements are constant:
0N/A * wsconsvp = IWSCN_PATH
0N/A * rwsconsvp = WC_PATH
0N/A * consms -> msdev
0N/A *
0N/A * The "->" syntax indicates that the streams device on the right is
0N/A * linked under the streams device on the left.
0N/A *
0N/A * The following lists how the system is configured for different setups:
0N/A *
0N/A * stdin is a local keyboard. use stdin and stdout as the console.
0N/A * sp->cons_input_type = CONSOLE_LOCAL
0N/A * rconsvp = IWSCN_PATH
0N/A * wc -> conskbd -> kbddev
0N/A *
0N/A * stdin is not a keyboard and stdin is the same as stdout.
0N/A * assume we running on a tip line and use stdin/stdout as the console.
0N/A * sp->cons_input_type = CONSOLE_TIP
0N/A * rconsvp = (stdindev/stdoutdev)
0N/A * wc -> conskbd -> kbddev
0N/A *
0N/A * stdin is not a keyboard device and it's not the same as stdout.
0N/A * assume we have a serial keyboard hooked up and use it along with
0N/A * stdout as the console.
0N/A * sp->cons_input_type = CONSOLE_SERIAL_KEYBOARD
0N/A * rconsvp = IWSCN_PATH
0N/A * wc -> stdindev
0N/A * conskbd -> kbddev
0N/A *
0N/A * CAVEAT:
0N/A * The above is all true except for one possible Intel configuration.
0N/A * If stdin is set to a local keyboard but stdout is set to something
0N/A * other than the local display (a tip port for example) stdout will
0N/A * still go to the local display. This is an artifact of the console
0N/A * implementation on intel.
0N/A */
0N/A
0N/A#include <sys/types.h>
0N/A#include <sys/param.h>
0N/A#include <sys/cmn_err.h>
0N/A#include <sys/user.h>
0N/A#include <sys/vfs.h>
0N/A#include <sys/vnode.h>
0N/A#include <sys/pathname.h>
0N/A#include <sys/systm.h>
0N/A#include <sys/file.h>
0N/A#include <sys/stropts.h>
0N/A#include <sys/stream.h>
0N/A#include <sys/strsubr.h>
0N/A
0N/A#include <sys/consdev.h>
0N/A#include <sys/console.h>
0N/A#include <sys/wscons.h>
0N/A#include <sys/kbio.h>
0N/A#include <sys/debug.h>
0N/A#include <sys/reboot.h>
0N/A#include <sys/termios.h>
0N/A
0N/A#include <sys/ddi.h>
0N/A#include <sys/sunddi.h>
0N/A#include <sys/sunldi.h>
0N/A#include <sys/sunndi.h>
0N/A#include <sys/ndi_impldefs.h>
0N/A#include <sys/modctl.h>
0N/A#include <sys/ddi_impldefs.h>
0N/A#include <sys/ddi_implfuncs.h>
0N/A#include <sys/promif.h>
0N/A#include <sys/fs/snode.h>
0N/A
0N/A#include <sys/errno.h>
0N/A#include <sys/devops.h>
0N/A#include <sys/note.h>
0N/A
0N/A#include <sys/tem_impl.h>
0N/A#include <sys/polled_io.h>
0N/A#include <sys/kmem.h>
0N/A#include <sys/dacf.h>
0N/A#include <sys/consconfig_dacf.h>
0N/A#include <sys/consplat.h>
0N/A#include <sys/log.h>
0N/A#include <sys/disp.h>
0N/A
0N/A/*
0N/A * External global variables
0N/A */
0N/Aextern vnode_t *rconsvp;
0N/Aextern dev_t rwsconsdev;
0N/A
0N/A/*
0N/A * External functions
0N/A */
0N/Aextern uintptr_t space_fetch(char *key);
0N/Aextern int space_store(char *key, uintptr_t ptr);
0N/A
0N/A/*
0N/A * Tasks
0N/A */
0N/Astatic int kb_config(dacf_infohdl_t, dacf_arghdl_t, int);
0N/Astatic int kb_unconfig(dacf_infohdl_t, dacf_arghdl_t, int);
0N/Astatic int ms_config(dacf_infohdl_t, dacf_arghdl_t, int);
0N/Astatic int ms_unconfig(dacf_infohdl_t, dacf_arghdl_t, int);
0N/A
0N/A/*
0N/A * Internal functions
0N/A */
0N/Astatic int consconfig_setmodes(dev_t dev, struct termios *termiosp);
0N/Astatic void consconfig_check_phys_kbd(cons_state_t *);
0N/Astatic void consconfig_rem_dev(cons_state_t *, dev_t);
0N/Astatic void consconfig_add_dev(cons_state_t *, cons_prop_t *);
0N/Astatic cons_prop_t *consconfig_find_dev(cons_state_t *, dev_t);
0N/Astatic void consconfig_free_prop(cons_prop_t *prop);
0N/Astatic void flush_deferred_console_buf(void);
0N/A
0N/A
0N/A/*
0N/A * On supported configurations, the firmware defines the keyboard and mouse
0N/A * paths. However, during USB development, it is useful to be able to use
0N/A * the USB keyboard and mouse on machines without full USB firmware support.
0N/A * These variables may be set in /etc/system according to a machine's
0N/A * USB configuration. This module will override the firmware's values
0N/A * with these.
0N/A *
0N/A * NOTE:
0N/A * The master copies of these variables in the misc/consconfig module.
0N/A * The reason for this is historic. In versions of solaris up to and
0N/A * including solaris 9 the conscole configuration code was split into a
0N/A * seperate sparc and intel version. These variables were defined
0N/A * in misc/consconfig on sparc and dacf/consconfig_dacf on intel.
0N/A *
0N/A * Unfortunatly the sparc variables were well documented.
0N/A * So to aviod breaking either sparc or intel we'll declare the variables
0N/A * in both modules. This will allow any /etc/system entries that
0N/A * users may have to continue working.
0N/A *
0N/A * The variables in misc/consconfig will take precedence over the variables
0N/A * found in this file. Since we eventually want to remove the variables
0N/A * local to this this file, if the user set them we'll emmit an error
0N/A * message telling them they need to set the variables in misc/consconfig
0N/A * instead.
0N/A */
0N/Astatic char *usb_kb_path = NULL;
0N/Astatic char *usb_ms_path = NULL;
0N/A
0N/A/*
0N/A * Access functions in the misc/consconfig module used to retrieve the
0N/A * values of it local usb_kb_path and usb_ms_path variables
0N/A */
0N/Aextern char *consconfig_get_usb_kb_path();
0N/Aextern char *consconfig_get_usb_ms_path();
0N/A
0N/A/*
0N/A * Local variables used to store the value of the usb_kb_path and
0N/A * usb_ms_path variables found in misc/consconfig
0N/A */
0N/Astatic char *consconfig_usb_kb_path = NULL;
0N/Astatic char *consconfig_usb_ms_path = NULL;
0N/A
0N/A/*
0N/A * Internal variables
0N/A */
0N/Astatic dev_t stdoutdev;
0N/Astatic cons_state_t *consconfig_sp;
0N/A
0N/A/*
0N/A * consconfig_errlevel: debug verbosity; smaller numbers are more
0N/A * verbose.
0N/A */
0N/Aint consconfig_errlevel = DPRINT_L3;
0N/A
0N/A/*
0N/A * Baud rate table
0N/A */
0N/Astatic struct speed {
0N/A char *name;
0N/A int code;
0N/A} speedtab[] = {
0N/A {"0", B0}, {"50", B50}, {"75", B75},
0N/A {"110", B110}, {"134", B134}, {"150", B150},
0N/A {"200", B200}, {"300", B300}, {"600", B600},
0N/A {"1200", B1200}, {"1800", B1800}, {"2400", B2400},
0N/A {"4800", B4800}, {"9600", B9600}, {"19200", B19200},
0N/A {"38400", B38400}, {"57600", B57600}, {"76800", B76800},
0N/A {"115200", B115200}, {"153600", B153600}, {"230400", B230400},
0N/A {"307200", B307200}, {"460800", B460800}, {"921600", B921600},
0N/A {"", 0}
0N/A};
0N/A
0N/Astatic const int MAX_SPEEDS = sizeof (speedtab) / sizeof (speedtab[0]);
0N/A
0N/Astatic dacf_op_t kbconfig_op[] = {
0N/A { DACF_OPID_POSTATTACH, kb_config },
0N/A { DACF_OPID_PREDETACH, kb_unconfig },
0N/A { DACF_OPID_END, NULL },
0N/A};
0N/A
0N/Astatic dacf_op_t msconfig_op[] = {
0N/A { DACF_OPID_POSTATTACH, ms_config },
0N/A { DACF_OPID_PREDETACH, ms_unconfig },
0N/A { DACF_OPID_END, NULL },
0N/A};
0N/A
0N/Astatic dacf_opset_t opsets[] = {
0N/A { "kb_config", kbconfig_op },
0N/A { "ms_config", msconfig_op },
0N/A { NULL, NULL }
0N/A};
0N/A
0N/Astruct dacfsw dacfsw = {
0N/A DACF_MODREV_1,
0N/A opsets,
0N/A};
0N/A
0N/Astatic struct modldacf modldacf = {
0N/A &mod_dacfops, /* Type of module */
0N/A "Consconfig DACF",
0N/A &dacfsw
0N/A};
0N/A
0N/Astatic struct modlinkage modlinkage = {
0N/A MODREV_1, (void *)&modldacf, NULL
0N/A};
0N/A
0N/Aint
0N/A_init(void) {
0N/A return (mod_install(&modlinkage));
0N/A}
0N/A
0N/Aint
0N/A_fini(void)
0N/A{
0N/A /*
0N/A * This modules state is held in the kernel by space.c
0N/A * allowing this module to be unloaded.
0N/A */
0N/A return (mod_remove(&modlinkage));
0N/A}
0N/A
0N/Aint
0N/A_info(struct modinfo *modinfop)
0N/A{
0N/A return (mod_info(&modlinkage, modinfop));
0N/A}
0N/A
0N/A/*PRINTFLIKE2*/
0N/Astatic void consconfig_dprintf(int, const char *, ...)
0N/A __KPRINTFLIKE(2);
0N/A
0N/Astatic void
0N/Aconsconfig_dprintf(int l, const char *fmt, ...)
0N/A{
0N/A va_list ap;
0N/A
0N/A#ifndef DEBUG
0N/A if (!l) {
0N/A return;
0N/A }
0N/A#endif /* DEBUG */
0N/A if (l < consconfig_errlevel) {
0N/A return;
0N/A }
0N/A
0N/A va_start(ap, fmt);
0N/A (void) vprintf(fmt, ap);
0N/A va_end(ap);
0N/A}
0N/A
0N/A/*
0N/A * Return a property value for the specified alias in /aliases.
0N/A */
0N/Achar *
0N/Aget_alias(char *alias, char *buf)
0N/A{
0N/A pnode_t node;
0N/A int len;
0N/A
0N/A /* The /aliases node only exists in OBP >= 2.4. */
0N/A if ((node = prom_alias_node()) == OBP_BADNODE)
0N/A return (NULL);
0N/A
0N/A if ((len = prom_getproplen(node, (caddr_t)alias)) <= 0)
0N/A return (NULL);
0N/A
0N/A (void) prom_getprop(node, (caddr_t)alias, (caddr_t)buf);
0N/A
0N/A /*
0N/A * The IEEE 1275 standard specifies that /aliases string property
0N/A * values should be null-terminated. Unfortunatly the reality
0N/A * is that most aren't and the OBP can't easily be modified to
0N/A * add null termination to these strings. So we'll add the
0N/A * null termination here. If the string already contains a
0N/A * null termination character then that's ok too because we'll
0N/A * just be adding a second one.
0N/A */
0N/A buf[len] = '\0';
0N/A
0N/A prom_pathname(buf);
0N/A return (buf);
0N/A}
0N/A
0N/A/*
0N/A * i_consconfig_createvp:
0N/A * This routine is a convenience routine that is passed a path and returns
0N/A * a vnode.
0N/A */
0N/Astatic vnode_t *
0N/Ai_consconfig_createvp(char *path)
0N/A{
0N/A int error;
0N/A vnode_t *vp;
0N/A char *buf = NULL, *fullpath;
0N/A
0N/A DPRINTF(DPRINT_L0, "i_consconfig_createvp: %s\n", path);
0N/A fullpath = kmem_alloc(MAXPATHLEN, KM_SLEEP);
0N/A
0N/A if (strchr(path, ':') == NULL) {
0N/A /* convert an OBP path to a /devices path */
0N/A buf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
0N/A if (i_ddi_prompath_to_devfspath(path, buf) != DDI_SUCCESS) {
0N/A kmem_free(buf, MAXPATHLEN);
0N/A kmem_free(fullpath, MAXPATHLEN);
0N/A return (NULL);
0N/A }
0N/A (void) snprintf(fullpath, MAXPATHLEN, "/devices%s", buf);
0N/A kmem_free(buf, MAXPATHLEN);
0N/A } else {
0N/A /* convert a devfs path to a /devices path */
0N/A (void) snprintf(fullpath, MAXPATHLEN, "/devices%s", path);
0N/A }
0N/A
0N/A DPRINTF(DPRINT_L0, "lookupname(%s)\n", fullpath);
0N/A error = lookupname(fullpath, UIO_SYSSPACE, FOLLOW, NULLVPP, &vp);
0N/A kmem_free(fullpath, MAXPATHLEN);
0N/A if (error)
0N/A return (NULL);
0N/A
0N/A DPRINTF(DPRINT_L0, "create vnode = 0x%p - dev 0x%lx\n", vp, vp->v_rdev);
0N/A ASSERT(vn_matchops(vp, spec_getvnodeops()));
0N/A
0N/A return (vp);
0N/A}
0N/A
0N/A/*
0N/A * consconfig_print_paths:
0N/A * Function to print out the various paths
0N/A */
0N/Astatic void
0N/Aconsconfig_print_paths(void)
0N/A{
0N/A char *path;
0N/A
0N/A if (usb_kb_path != NULL)
0N/A cmn_err(CE_WARN,
0N/A "consconfig_dacf:usb_kb_path has been deprecated, "
0N/A "use consconfig:usb_kb_path instead");
0N/A
0N/A if (usb_ms_path != NULL)
0N/A cmn_err(CE_WARN,
0N/A "consconfig_dacf:usb_ms_path has been deprecated, "
0N/A "use consconfig:usb_ms_path instead");
0N/A
0N/A if (consconfig_errlevel > DPRINT_L0)
0N/A return;
0N/A
0N/A path = NULL;
0N/A if (consconfig_usb_kb_path != NULL)
0N/A path = consconfig_usb_kb_path;
0N/A else if (usb_kb_path != NULL)
0N/A path = usb_kb_path;
0N/A if (path != NULL)
0N/A DPRINTF(DPRINT_L0, "usb keyboard path = %s\n", path);
0N/A
0N/A path = plat_kbdpath();
0N/A if (path != NULL)
0N/A DPRINTF(DPRINT_L0, "keyboard path = %s\n", path);
0N/A
0N/A path = NULL;
0N/A if (consconfig_usb_ms_path != NULL)
0N/A path = consconfig_usb_ms_path;
0N/A else if (usb_ms_path != NULL)
0N/A path = usb_ms_path;
0N/A if (path != NULL)
0N/A DPRINTF(DPRINT_L0, "usb mouse path = %s\n", path);
0N/A
0N/A path = plat_mousepath();
0N/A if (path != NULL)
0N/A DPRINTF(DPRINT_L0, "mouse path = %s\n", path);
0N/A
0N/A path = plat_stdinpath();
0N/A if (path != NULL)
0N/A DPRINTF(DPRINT_L0, "stdin path = %s\n", path);
0N/A
0N/A path = plat_stdoutpath();
0N/A if (path != NULL)
0N/A DPRINTF(DPRINT_L0, "stdout path = %s\n", path);
0N/A
0N/A path = plat_fbpath();
0N/A if (path != NULL)
0N/A DPRINTF(DPRINT_L0, "fb path = %s\n", path);
0N/A}
0N/A
0N/A/*
0N/A * consconfig_kbd_abort_enable:
0N/A * Send the CONSSETABORTENABLE ioctl to the lower layers. This ioctl
0N/A * will only be sent to the device if it is the console device.
0N/A * This ioctl tells the device to pay attention to abort sequences.
0N/A * In the case of kbtrans, this would tell the driver to pay attention
0N/A * to the two key abort sequences like STOP-A. In the case of the
0N/A * serial keyboard, it would be an abort sequence like a break.
0N/A */
0N/Astatic int
0N/Aconsconfig_kbd_abort_enable(ldi_handle_t lh)
0N/A{
0N/A int err, rval;
0N/A
0N/A DPRINTF(DPRINT_L0, "consconfig_kbd_abort_enable\n");
0N/A
0N/A err = ldi_ioctl(lh, CONSSETABORTENABLE, (uintptr_t)B_TRUE,
0N/A FKIOCTL, kcred, &rval);
0N/A return (err);
0N/A}
0N/A
0N/A/*
0N/A * consconfig_kbd_abort_disable:
0N/A * Send CONSSETABORTENABLE ioctl to lower layers. This ioctl
0N/A * will only be sent to the device if it is the console device.
0N/A * This ioctl tells the physical device to ignore abort sequences,
0N/A * and send the sequences up to virtual keyboard(conskbd) so that
0N/A * STOP and A (or F1 and A) can be combined.
0N/A */
0N/Astatic int
0N/Aconsconfig_kbd_abort_disable(ldi_handle_t lh)
0N/A{
0N/A int err, rval;
0N/A
0N/A DPRINTF(DPRINT_L0, "consconfig_kbd_abort_disable\n");
0N/A
0N/A err = ldi_ioctl(lh, CONSSETABORTENABLE, (uintptr_t)B_FALSE,
0N/A FKIOCTL, kcred, &rval);
0N/A return (err);
0N/A}
0N/A
0N/A#ifdef _HAVE_TEM_FIRMWARE
0N/Astatic int
0N/Aconsconfig_tem_supported(cons_state_t *sp)
0N/A{
0N/A dev_t dev;
0N/A dev_info_t *dip;
0N/A int *int_array;
0N/A uint_t nint;
0N/A int rv = 0;
0N/A
0N/A if (sp->cons_fb_path == NULL)
0N/A return (0);
0N/A
0N/A if ((dev = ddi_pathname_to_dev_t(sp->cons_fb_path)) == NODEV)
0N/A return (0); /* warning printed later by common code */
0N/A
0N/A /*
0N/A * Here we hold the driver and check "tem-support" property.
0N/A * We're doing this with e_ddi_hold_devi_by_dev and
0N/A * ddi_prop_lookup_int_array without opening the driver since
0N/A * some video cards that don't support the kernel terminal
0N/A * emulator could hang or crash if opened too early during
0N/A * boot.
0N/A */
0N/A if ((dip = e_ddi_hold_devi_by_dev(dev, 0)) == NULL) {
0N/A cmn_err(CE_WARN, "consconfig: cannot hold fb dev %s",
0N/A sp->cons_fb_path);
0N/A return (0);
0N/A }
0N/A
0N/A /*
0N/A * Check that the tem-support property exists AND that
0N/A * it is equal to 1.
0N/A */
0N/A if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
0N/A DDI_PROP_DONTPASS, "tem-support", &int_array, &nint) ==
0N/A DDI_SUCCESS) {
0N/A if (nint > 0)
0N/A rv = int_array[0] == 1;
0N/A ddi_prop_free(int_array);
0N/A }
0N/A
0N/A ddi_release_devi(dip);
0N/A
0N/A return (rv);
0N/A}
0N/A#endif /* _HAVE_TEM_FIRMWARE */
0N/A
0N/A/*
0N/A * consconfig_get_polledio:
0N/A * Query the console with the CONSPOLLEDIO ioctl.
0N/A * The polled I/O routines are used by debuggers to perform I/O while
0N/A * interrupts and normal kernel services are disabled.
0N/A */
0N/Astatic cons_polledio_t *
0N/Aconsconfig_get_polledio(ldi_handle_t lh)
0N/A{
0N/A int err, rval;
0N/A struct strioctl strioc;
0N/A cons_polledio_t *polled_io;
0N/A
0N/A /*
0N/A * Setup the ioctl to be sent down to the lower driver.
0N/A */
0N/A strioc.ic_cmd = CONSOPENPOLLEDIO;
0N/A strioc.ic_timout = INFTIM;
0N/A strioc.ic_len = sizeof (polled_io);
0N/A strioc.ic_dp = (char *)&polled_io;
0N/A
0N/A /*
0N/A * Send the ioctl to the driver. The ioctl will wait for
0N/A * the response to come back from wc. wc has already issued
0N/A * the CONSOPENPOLLEDIO to the lower layer driver.
0N/A */
0N/A err = ldi_ioctl(lh, I_STR, (intptr_t)&strioc, FKIOCTL, kcred, &rval);
0N/A
0N/A if (err != 0) {
0N/A /*
0N/A * If the lower driver does not support polled I/O, then
0N/A * return NULL. This will be the case if the driver does
0N/A * not handle polled I/O, or OBP is going to handle polled
0N/A * I/O for the device.
0N/A */
0N/A
0N/A return (NULL);
0N/A }
0N/A
0N/A /*
0N/A * Return the polled I/O structure.
0N/A */
0N/A return (polled_io);
0N/A}
0N/A
0N/A/*
0N/A * consconfig_setup_polledio:
0N/A * This routine does the setup work for polled I/O. First we get
0N/A * the polled_io structure from the lower layers
0N/A * and then we register the polled I/O
0N/A * callbacks with the debugger that will be using them.
0N/A */
0N/Astatic void
0N/Aconsconfig_setup_polledio(cons_state_t *sp, dev_t dev)
0N/A{
0N/A cons_polledio_t *polled_io;
0N/A ldi_handle_t lh;
0N/A
0N/A DPRINTF(DPRINT_L0, "consconfig_setup_polledio: start\n");
0N/A
0N/A
0N/A if (ldi_open_by_dev(&dev, OTYP_CHR,
0N/A FREAD|FWRITE|FNOCTTY, kcred, &lh, sp->cons_li) != 0)
0N/A return;
0N/A
0N/A
0N/A /*
0N/A * Get the polled io routines so that we can use this
0N/A * device with the debuggers.
0N/A */
0N/A polled_io = consconfig_get_polledio(lh);
0N/A
0N/A /*
0N/A * If the get polledio failed, then we do not want to throw
0N/A * the polled I/O switch.
0N/A */
0N/A if (polled_io == NULL) {
0N/A DPRINTF(DPRINT_L0,
0N/A "consconfig_setup_polledio: get_polledio failed\n");
0N/A (void) ldi_close(lh, FREAD|FWRITE, kcred);
0N/A return;
0N/A }
0N/A
0N/A /* Initialize the polled input */
0N/A polled_io_init();
0N/A
0N/A /* Register the callbacks */
0N/A DPRINTF(DPRINT_L0,
0N/A "consconfig_setup_polledio: registering callbacks\n");
0N/A (void) polled_io_register_callbacks(polled_io, 0);
0N/A
0N/A (void) ldi_close(lh, FREAD|FWRITE, kcred);
0N/A
0N/A DPRINTF(DPRINT_L0, "consconfig_setup_polledio: end\n");
0N/A}
0N/A
0N/Astatic cons_state_t *
0N/Aconsconfig_state_init(void)
0N/A{
0N/A cons_state_t *sp;
0N/A int rval;
0N/A
0N/A /* Initialize console information */
0N/A sp = kmem_zalloc(sizeof (cons_state_t), KM_SLEEP);
0N/A sp->cons_keyboard_problem = B_FALSE;
0N/A
0N/A mutex_init(&sp->cons_lock, NULL, MUTEX_DRIVER, NULL);
0N/A
0N/A /* check if consconfig:usb_kb_path is set in /etc/system */
0N/A consconfig_usb_kb_path = consconfig_get_usb_kb_path();
0N/A
0N/A /* check if consconfig:usb_ms_path is set in /etc/system */
0N/A consconfig_usb_ms_path = consconfig_get_usb_ms_path();
0N/A
0N/A consconfig_print_paths();
0N/A
0N/A /* init external globals */
0N/A stdoutdev = NODEV;
0N/A
0N/A /*
0N/A * Find keyboard, mouse, stdin and stdout devices, if they
0N/A * exist on this platform.
0N/A */
0N/A
0N/A if (consconfig_usb_kb_path != NULL) {
0N/A sp->cons_keyboard_path = consconfig_usb_kb_path;
0N/A } else if (usb_kb_path != NULL) {
0N/A sp->cons_keyboard_path = usb_kb_path;
0N/A } else {
0N/A sp->cons_keyboard_path = plat_kbdpath();
0N/A }
0N/A
0N/A if (consconfig_usb_ms_path != NULL) {
0N/A sp->cons_mouse_path = consconfig_usb_ms_path;
0N/A } else if (usb_ms_path != NULL) {
0N/A sp->cons_mouse_path = usb_ms_path;
0N/A } else {
0N/A sp->cons_mouse_path = plat_mousepath();
0N/A }
0N/A
0N/A /* Identify the stdout driver */
0N/A sp->cons_stdout_path = plat_stdoutpath();
0N/A sp->cons_stdout_is_fb = plat_stdout_is_framebuffer();
0N/A
0N/A sp->cons_stdin_is_kbd = plat_stdin_is_keyboard();
0N/A
0N/A if (sp->cons_stdin_is_kbd &&
0N/A (usb_kb_path != NULL || consconfig_usb_kb_path != NULL)) {
0N/A sp->cons_stdin_path = sp->cons_keyboard_path;
0N/A } else {
0N/A /*
0N/A * The standard in device may or may not be the same as
0N/A * the keyboard. Even if the keyboard is not the
0N/A * standard input, the keyboard console stream will
0N/A * still be built if the keyboard alias provided by the
0N/A * firmware exists and is valid.
0N/A */
0N/A sp->cons_stdin_path = plat_stdinpath();
0N/A }
0N/A
0N/A if (sp->cons_stdout_is_fb) {
0N/A sp->cons_fb_path = sp->cons_stdout_path;
0N/A
0N/A#ifdef _HAVE_TEM_FIRMWARE
0N/A sp->cons_tem_supported = consconfig_tem_supported(sp);
0N/A
0N/A /*
0N/A * Systems which offer a virtual console must use that
0N/A * as a fallback whenever the fb doesn't support tem.
0N/A * Such systems cannot render characters to the screen
0N/A * using OBP.
0N/A */
0N/A if (!sp->cons_tem_supported) {
0N/A char *path;
0N/A
0N/A if (plat_virtual_console_path(&path) >= 0) {
0N/A sp->cons_stdin_is_kbd = 0;
0N/A sp->cons_stdout_is_fb = 0;
0N/A sp->cons_stdin_path = path;
0N/A sp->cons_stdout_path = path;
0N/A sp->cons_fb_path = plat_fbpath();
0N/A
0N/A cmn_err(CE_WARN,
0N/A "%s doesn't support terminal emulation "
0N/A "mode; switching to virtual console.",
0N/A sp->cons_fb_path);
0N/A }
0N/A }
0N/A#endif /* _HAVE_TEM_FIRMWARE */
0N/A } else {
0N/A sp->cons_fb_path = plat_fbpath();
0N/A#ifdef _HAVE_TEM_FIRMWARE
0N/A sp->cons_tem_supported = consconfig_tem_supported(sp);
0N/A#endif /* _HAVE_TEM_FIRMWARE */
0N/A }
0N/A
0N/A sp->cons_li = ldi_ident_from_anon();
0N/A
0N/A /* Save the pointer for retrieval by the dacf functions */
0N/A rval = space_store("consconfig", (uintptr_t)sp);
0N/A ASSERT(rval == 0);
0N/A
0N/A return (sp);
0N/A}
0N/A
0N/Astatic int
0N/Aconsconfig_relink_wc(cons_state_t *sp, ldi_handle_t new_lh, int *muxid)
0N/A{
0N/A int err, rval;
0N/A ldi_handle_t wc_lh;
0N/A dev_t wc_dev;
0N/A
0N/A ASSERT(muxid != NULL);
0N/A
0N/A /*
0N/A * NOTE: we could be in a dacf callback context right now. normally
0N/A * it's not legal to call any ldi_open_*() function from this context
0N/A * because we're currently holding device tree locks and if the
0N/A * ldi_open_*() call could try to acquire other device tree locks
0N/A * (to attach the device we're trying to open.) if this happens then
0N/A * we could deadlock. To avoid this situation, during initialization
0N/A * we made sure to grab a hold on the dip of the device we plan to
0N/A * open so that it can never be detached. Then we use
0N/A * ldi_open_by_dev() to actually open the device since it will see
0N/A * that the device is already attached and held and instead of
0N/A * acquire any locks it will only increase the reference count
0N/A * on the device.
0N/A */
0N/A wc_dev = sp->cons_wc_vp->v_rdev;
0N/A err = ldi_open_by_dev(&wc_dev, OTYP_CHR, FREAD|FWRITE|FNOCTTY,
0N/A kcred, &wc_lh, sp->cons_li);
0N/A ASSERT(wc_dev == sp->cons_wc_vp->v_rdev);
0N/A if (err) {
0N/A cmn_err(CE_WARN, "consconfig_relink_wc: "
0N/A "unable to open wc device");
0N/A return (err);
0N/A }
0N/A
0N/A if (new_lh != NULL) {
0N/A DPRINTF(DPRINT_L0, "linking stream under wc\n");
0N/A
0N/A err = ldi_ioctl(wc_lh, I_PLINK, (uintptr_t)new_lh,
0N/A FKIOCTL, kcred, muxid);
0N/A if (err != 0) {
0N/A cmn_err(CE_WARN, "consconfig_relink_wc: "
0N/A "wc link failed, error %d", err);
0N/A }
0N/A } else {
0N/A DPRINTF(DPRINT_L0, "unlinking stream from under wc\n");
0N/A
0N/A err = ldi_ioctl(wc_lh, I_PUNLINK, *muxid,
0N/A FKIOCTL, kcred, &rval);
0N/A if (err != 0) {
0N/A cmn_err(CE_WARN, "consconfig_relink_wc: "
0N/A "wc unlink failed, error %d", err);
0N/A } else {
0N/A *muxid = -1;
0N/A }
0N/A }
0N/A
0N/A (void) ldi_close(wc_lh, FREAD|FWRITE, kcred);
0N/A return (err);
0N/A}
0N/A
0N/Astatic void
0N/Acons_build_upper_layer(cons_state_t *sp)
0N/A{
0N/A ldi_handle_t wc_lh;
0N/A struct strioctl strioc;
0N/A int rval;
0N/A dev_t dev;
0N/A dev_t wc_dev;
0N/A
0N/A /*
0N/A * Build the wc->conskbd portion of the keyboard console stream.
0N/A * Even if no keyboard is attached to the system, the upper
0N/A * layer of the stream will be built. If the user attaches
0N/A * a keyboard after the system is booted, the keyboard driver
0N/A * and module will be linked under conskbd.
0N/A *
0N/A * Errors are generally ignored here because conskbd and wc
0N/A * are pseudo drivers and should be present on the system.
0N/A */
0N/A
0N/A /* open the console keyboard device. will never be closed */
0N/A if (ldi_open_by_name(CONSKBD_PATH, FREAD|FWRITE|FNOCTTY,
0N/A kcred, &sp->conskbd_lh, sp->cons_li) != 0) {
0N/A panic("consconfig: unable to open conskbd device");
0N/A /*NOTREACHED*/
0N/A }
0N/A
0N/A DPRINTF(DPRINT_L0, "conskbd_lh = %p\n", sp->conskbd_lh);
0N/A
0N/A /* open the console mouse device. will never be closed */
0N/A if (ldi_open_by_name(CONSMS_PATH, FREAD|FWRITE|FNOCTTY,
0N/A kcred, &sp->consms_lh, sp->cons_li) != 0) {
0N/A panic("consconfig: unable to open consms device");
0N/A /*NOTREACHED*/
0N/A }
0N/A
0N/A DPRINTF(DPRINT_L0, "consms_lh = %p\n", sp->consms_lh);
0N/A
0N/A /*
0N/A * Get a vnode for the wc device and then grab a hold on the
0N/A * device dip so it can never detach. We need to do this now
0N/A * because later we'll have to open the wc device in a context
0N/A * were it isn't safe to acquire any device tree locks (ie, during
0N/A * a dacf callback.)
0N/A */
0N/A sp->cons_wc_vp = i_consconfig_createvp(WC_PATH);
0N/A if (sp->cons_wc_vp == NULL)
0N/A panic("consconfig: unable to find wc device");
0N/A
0N/A if (e_ddi_hold_devi_by_dev(sp->cons_wc_vp->v_rdev, 0) == NULL)
0N/A panic("consconfig: unable to hold wc device");
0N/A
0N/A /*
0N/A * Build the wc->conskbd portion of the keyboard console stream.
0N/A * Even if no keyboard is attached to the system, the upper
0N/A * layer of the stream will be built. If the user attaches
0N/A * a keyboard after the system is booted, the keyboard driver
0N/A * and module will be linked under conskbd.
0N/A *
0N/A * The act of linking conskbd under wc will cause wc to
0N/A * query the lower layers about their polled I/O routines
0N/A * using CONSOPENPOLLEDIO. This will fail on this link because
0N/A * there is not a physical keyboard linked under conskbd.
0N/A *
0N/A * Since conskbd and wc are pseudo drivers, errors are
0N/A * generally ignored when linking and unlinking them.
0N/A */
0N/A (void) consconfig_relink_wc(sp, sp->conskbd_lh, &sp->conskbd_muxid);
0N/A
0N/A /*
0N/A * Get a vnode for the redirection device. (It has the
0N/A * connection to the workstation console device wired into it,
0N/A * so that it's not necessary to establish the connection
0N/A * here. If the redirection device is ever generalized to
0N/A * handle multiple client devices, it won't be able to
0N/A * establish the connection itself, and we'll have to do it
0N/A * here.)
0N/A */
0N/A wsconsvp = i_consconfig_createvp(IWSCN_PATH);
0N/A if (wsconsvp == NULL) {
0N/A panic("consconfig: unable to find iwscn device");
0N/A /*NOTREACHED*/
0N/A }
0N/A
0N/A if (cons_tem_disable)
0N/A return;
0N/A
0N/A if (sp->cons_fb_path == NULL) {
0N/A#if defined(__x86)
0N/A if (sp->cons_stdout_is_fb)
0N/A cmn_err(CE_WARN, "consconfig: no screen found");
0N/A#endif
0N/A return;
0N/A }
0N/A
0N/A /* make sure the frame buffer device exists */
0N/A dev = ddi_pathname_to_dev_t(sp->cons_fb_path);
0N/A if (dev == NODEV) {
0N/A cmn_err(CE_WARN, "consconfig: "
0N/A "cannot find driver for screen device %s",
0N/A sp->cons_fb_path);
0N/A return;
0N/A }
0N/A
0N/A#ifdef _HAVE_TEM_FIRMWARE
0N/A /*
0N/A * If the underlying fb device doesn't support terminal emulation,
0N/A * we don't want to open the wc device (below) because it depends
0N/A * on features which aren't available (polled mode io).
0N/A */
0N/A if (!sp->cons_tem_supported)
0N/A return;
0N/A#endif /* _HAVE_TEM_FIRMWARE */
0N/A
0N/A /* tell wc to open the frame buffer device */
0N/A wc_dev = sp->cons_wc_vp->v_rdev;
0N/A if (ldi_open_by_dev(&wc_dev, OTYP_CHR, FREAD|FWRITE|FNOCTTY, kcred,
0N/A &wc_lh, sp->cons_li)) {
0N/A cmn_err(CE_PANIC, "cons_build_upper_layer: "
0N/A "unable to open wc device");
0N/A return;
0N/A }
0N/A ASSERT(wc_dev == sp->cons_wc_vp->v_rdev);
0N/A
0N/A strioc.ic_cmd = WC_OPEN_FB;
0N/A strioc.ic_timout = INFTIM;
0N/A strioc.ic_len = strlen(sp->cons_fb_path) + 1;
0N/A strioc.ic_dp = sp->cons_fb_path;
0N/A
0N/A if (ldi_ioctl(wc_lh, I_STR, (intptr_t)&strioc,
0N/A FKIOCTL, kcred, &rval) == 0)
0N/A consmode = CONS_KFB;
0N/A else
0N/A cmn_err(CE_WARN,
0N/A "consconfig: terminal emulator failed to initialize");
0N/A (void) ldi_close(wc_lh, FREAD|FWRITE, kcred);
0N/A}
0N/A
0N/Astatic void
0N/Aconsconfig_load_drivers(cons_state_t *sp)
0N/A{
0N/A /*
0N/A * Calling ddi_pathname_to_dev_t causes the drivers to be loaded.
0N/A * The attaching of the drivers will cause the creation of the
0N/A * keyboard and mouse minor nodes, which will in turn trigger the
0N/A * dacf framework to call the keyboard and mouse configuration
0N/A * tasks. See PSARC/1998/212 for more details about the dacf
0N/A * framework.
0N/A *
0N/A * on sparc, when the console is ttya, zs0 is stdin/stdout, and zs1
0N/A * is kb/mouse. zs0 must be attached before zs1. The zs driver
0N/A * is written this way and the hardware may depend on this, too.
0N/A * It would be better to enforce this by attaching zs in sibling
0N/A * order with a driver property, such as ddi-attachall.
0N/A */
0N/A if (sp->cons_stdin_path != NULL)
0N/A stdindev = ddi_pathname_to_dev_t(sp->cons_stdin_path);
0N/A if (stdindev == NODEV) {
0N/A DPRINTF(DPRINT_L0,
0N/A "!fail to attach stdin: %s\n", sp->cons_stdin_path);
0N/A }
0N/A if (sp->cons_stdout_path != NULL)
0N/A stdoutdev = ddi_pathname_to_dev_t(sp->cons_stdout_path);
0N/A if (sp->cons_keyboard_path != NULL)
0N/A kbddev = ddi_pathname_to_dev_t(sp->cons_keyboard_path);
0N/A if (sp->cons_mouse_path != NULL)
0N/A mousedev = ddi_pathname_to_dev_t(sp->cons_mouse_path);
0N/A
0N/A /*
0N/A * On x86, make sure the fb driver is loaded even if we don't use it
0N/A * for the console. This will ensure that we create a /dev/fb link
0N/A * which is required to start Xorg.
0N/A */
0N/A#if defined(__x86)
0N/A if (sp->cons_fb_path != NULL)
0N/A fbdev = ddi_pathname_to_dev_t(sp->cons_fb_path);
0N/A#endif
0N/A
0N/A DPRINTF(DPRINT_L0, "stdindev %lx, stdoutdev %lx, kbddev %lx, "
0N/A "mousedev %lx\n", stdindev, stdoutdev, kbddev, mousedev);
0N/A}
0N/A
0N/A#if !defined(__x86)
0N/Avoid
0N/Aconsconfig_virtual_console_vp(cons_state_t *sp)
0N/A{
0N/A char *virtual_cons_path;
0N/A
0N/A if (plat_virtual_console_path(&virtual_cons_path) < 0)
0N/A return;
0N/A
0N/A DPRINTF(DPRINT_L0, "consconfig_virtual_console_vp: "
0N/A "virtual console device path %s\n", virtual_cons_path);
0N/A
0N/A ASSERT(sp->cons_stdout_path != NULL);
0N/A if (strcmp(virtual_cons_path, sp->cons_stdout_path) == 0) {
0N/A /* virtual console already in use */
0N/A return;
0N/A }
0N/A
0N/A vsconsvp = i_consconfig_createvp(virtual_cons_path);
0N/A if (vsconsvp == NULL) {
0N/A cmn_err(CE_WARN, "consconfig_virtual_console_vp: "
0N/A "unable to find serial virtual console device %s",
0N/A virtual_cons_path);
0N/A return;
0N/A }
0N/A
0N/A (void) e_ddi_hold_devi_by_dev(vsconsvp->v_rdev, 0);
0N/A}
0N/A#endif
0N/A
0N/Astatic void
0N/Aconsconfig_init_framebuffer(cons_state_t *sp)
0N/A{
0N/A if (!sp->cons_stdout_is_fb)
0N/A return;
0N/A
0N/A DPRINTF(DPRINT_L0, "stdout is framebuffer\n");
0N/A ASSERT(strcmp(sp->cons_fb_path, sp->cons_stdout_path) == 0);
0N/A
0N/A /*
0N/A * Console output is a framebuffer.
0N/A * Find the framebuffer driver if we can, and make
0N/A * ourselves a shadow vnode to track it with.
0N/A */
0N/A fbdev = stdoutdev;
0N/A if (fbdev == NODEV) {
0N/A DPRINTF(DPRINT_L3,
0N/A "Can't find driver for console framebuffer\n");
0N/A } else {
0N/A /* stdoutdev is valid, of fbvp should exist */
0N/A fbvp = i_consconfig_createvp(sp->cons_stdout_path);
0N/A if (fbvp == NULL) {
0N/A panic("consconfig_init_framebuffer: "
0N/A "unable to find frame buffer device");
0N/A /*NOTREACHED*/
0N/A }
0N/A ASSERT(fbvp->v_rdev == fbdev);
0N/A
0N/A /* console device is never released */
0N/A fbdip = e_ddi_hold_devi_by_dev(fbdev, 0);
0N/A }
0N/A pm_cfb_setup(sp->cons_stdout_path);
0N/A}
0N/A
0N/A/*
0N/A * consconfig_prepare_dev:
0N/A * Flush the stream, push "pushmod" onto the stream.
0N/A * for keyboard, issue the KIOCTRANSABLE ioctl, and
0N/A * possible enable abort.
0N/A */
0N/Astatic void
0N/Aconsconfig_prepare_dev(
0N/A ldi_handle_t new_lh,
0N/A const char *pushmod,
0N/A int kbdtranslatable,
0N/A int input_type,
0N/A int dev_type)
0N/A{
0N/A int err, rval;
0N/A
0N/A /* send a flush down the stream to the keyboard driver */
0N/A (void) ldi_ioctl(new_lh, I_FLUSH, (intptr_t)FLUSHRW,
0N/A FKIOCTL, kcred, &rval);
0N/A
0N/A if (pushmod) {
0N/A err = ldi_ioctl(new_lh, I_PUSH, (intptr_t)pushmod,
0N/A FKIOCTL, kcred, &rval);
0N/A if (err) {
0N/A cmn_err(CE_WARN, "consconfig_prepare_dev: "
0N/A "can't push streams module \"%s\", error %d",
0N/A pushmod, err);
0N/A }
0N/A }
0N/A
0N/A if (dev_type == CONS_MS)
0N/A return;
0N/A
0N/A ASSERT(dev_type == CONS_KBD);
0N/A
0N/A err = ldi_ioctl(new_lh, KIOCTRANSABLE,
0N/A (intptr_t)&kbdtranslatable, FKIOCTL, kcred, &rval);
0N/A if (err) {
0N/A cmn_err(CE_WARN, "consconfig_prepare_dev: "
0N/A "KIOCTRANSABLE failed, error: %d", err);
0N/A }
0N/A
0N/A /*
0N/A * During boot, dynamic_console_config() will call the
0N/A * function to enable abort on the console. If the
0N/A * keyboard is hotplugged after boot, check to see if
0N/A * the keyboard is the console input. If it is
0N/A * enable abort on it.
0N/A */
0N/A if (input_type == CONSOLE_LOCAL)
0N/A (void) consconfig_kbd_abort_enable(new_lh);
0N/A}
0N/A
0N/A/*
0N/A * consconfig_relink_conskbd:
0N/A * If new_lh is not NULL it should represent a driver with a
0N/A * keyboard module pushed on top of it. The driver is then linked
0N/A * underneath conskbd. the resulting stream will be
0N/A * wc->conskbd->"new_lh driver".
0N/A *
0N/A * If new_lh is NULL, then an unlink operation is done on conskbd
0N/A * that attempts to unlink the stream specified by *muxid.
0N/A * the resulting stream will be wc->conskbd.
0N/A */
0N/Astatic int
0N/Aconsconfig_relink_conskbd(cons_state_t *sp, ldi_handle_t new_lh, int *muxid)
0N/A{
0N/A int err, rval;
0N/A int conskbd_relink = 0;
0N/A
0N/A ASSERT(muxid != NULL);
0N/A
0N/A DPRINTF(DPRINT_L0, "consconfig_relink_conskbd: "
0N/A "conskbd_lh = %p, new_lh = %p, muxid = %x\n",
0N/A sp->conskbd_lh, new_lh, *muxid);
0N/A
0N/A /*
0N/A * If conskbd is linked under wc then temporarily unlink it
0N/A * from under wc so that the new_lh stream may be linked under
0N/A * conskbd. This has to be done because streams are built bottom
0N/A * up and linking a stream under conskbd isn't allowed when
0N/A * conskbd is linked under wc.
0N/A */
0N/A if (sp->conskbd_muxid != -1) {
0N/A DPRINTF(DPRINT_L0, "unlinking conskbd from under wc\n");
0N/A conskbd_relink = 1;
0N/A err = consconfig_relink_wc(sp, NULL, &sp->conskbd_muxid);
0N/A if (err) {
0N/A cmn_err(CE_WARN, "consconfig_relink_conskbd: "
0N/A "wc unlink failed, error %d", err);
0N/A return (err);
0N/A }
0N/A }
0N/A
0N/A if (new_lh != NULL) {
0N/A DPRINTF(DPRINT_L0, "linking keyboard under conskbd\n");
0N/A
0N/A /* Link the stream represented by new_lh under conskbd */
0N/A err = ldi_ioctl(sp->conskbd_lh, I_PLINK, (uintptr_t)new_lh,
0N/A FKIOCTL, kcred, muxid);
0N/A if (err != 0) {
0N/A cmn_err(CE_WARN, "consconfig_relink_conskbd: "
0N/A "conskbd link failed, error %d", err);
0N/A goto relink_failed;
0N/A }
0N/A } else {
0N/A DPRINTF(DPRINT_L0, "unlinking keyboard from under conskbd\n");
0N/A
0N/A /*
0N/A * This will cause the keyboard driver to be closed,
0N/A * all modules to be popped, and the keyboard vnode released.
0N/A */
0N/A err = ldi_ioctl(sp->conskbd_lh, I_PUNLINK, *muxid,
0N/A FKIOCTL, kcred, &rval);
0N/A if (err != 0) {
0N/A cmn_err(CE_WARN, "consconfig_relink_conskbd: "
0N/A "conskbd unlink failed, error %d", err);
0N/A goto relink_failed;
0N/A } else {
0N/A *muxid = -1;
0N/A }
0N/A
0N/A consconfig_check_phys_kbd(sp);
0N/A }
0N/A
0N/A if (!conskbd_relink)
0N/A return (err);
0N/A
0N/A /*
0N/A * Link consbkd back under wc.
0N/A *
0N/A * The act of linking conskbd back under wc will cause wc
0N/A * to query the lower lower layers about their polled I/O
0N/A * routines. This time the request will succeed because there
0N/A * is a physical keyboard linked under conskbd.
0N/A */
0N/A DPRINTF(DPRINT_L0, "re-linking conskbd under wc\n");
0N/A err = consconfig_relink_wc(sp, sp->conskbd_lh, &sp->conskbd_muxid);
0N/A if (err) {
0N/A cmn_err(CE_WARN, "consconfig_relink_conskbd: "
0N/A "wc link failed, error %d", err);
0N/A }
0N/A return (err);
0N/A
0N/Arelink_failed:
0N/A if (!conskbd_relink)
0N/A return (err);
0N/A
0N/A /* something went wrong, try to reconnect conskbd back under wc */
0N/A DPRINTF(DPRINT_L0, "re-linking conskbd under wc\n");
0N/A (void) consconfig_relink_wc(sp, sp->conskbd_lh, &sp->conskbd_muxid);
0N/A return (err);
0N/A}
0N/A
0N/A/*
0N/A * consconfig_relink_consms:
0N/A * If new_lh is not NULL it should represent a driver with a
0N/A * mouse module pushed on top of it. The driver is then linked
0N/A * underneath consms. the resulting stream will be
0N/A * consms->"new_lh driver".
0N/A *
0N/A * If new_lh is NULL, then an unlink operation is done on consms
0N/A * that attempts to unlink the stream specified by *muxid.
0N/A */
0N/Astatic int
0N/Aconsconfig_relink_consms(cons_state_t *sp, ldi_handle_t new_lh, int *muxid)
0N/A{
0N/A int err, rval;
0N/A
0N/A DPRINTF(DPRINT_L0, "consconfig_relink_consms: "
0N/A "consms_lh = %p, new_lh = %p, muxid = %x\n",
0N/A (void *)sp->consms_lh, (void *)new_lh, *muxid);
0N/A
0N/A if (new_lh != NULL) {
0N/A DPRINTF(DPRINT_L0, "linking mouse under consms\n");
0N/A
0N/A /* Link ms/usbms stream underneath consms multiplexor. */
0N/A err = ldi_ioctl(sp->consms_lh, I_PLINK, (uintptr_t)new_lh,
0N/A FKIOCTL, kcred, muxid);
0N/A if (err != 0) {
0N/A cmn_err(CE_WARN, "consconfig_relink_consms: "
0N/A "mouse link failed, error %d", err);
0N/A }
0N/A } else {
0N/A DPRINTF(DPRINT_L0, "unlinking mouse from under consms\n");
0N/A
0N/A /* Tear down the mouse stream */
0N/A err = ldi_ioctl(sp->consms_lh, I_PUNLINK, *muxid,
0N/A FKIOCTL, kcred, &rval);
0N/A if (err != 0) {
0N/A cmn_err(CE_WARN, "consconfig_relink_consms: "
0N/A "mouse unlink failed, error %d", err);
0N/A } else {
0N/A *muxid = -1;
0N/A }
0N/A }
0N/A return (err);
0N/A}
0N/A
0N/Astatic int
0N/Acons_get_input_type(cons_state_t *sp)
0N/A{
0N/A int type;
0N/A
0N/A /*
0N/A * Now that we know what all the devices are, we can figure out
0N/A * what kind of console we have.
0N/A */
0N/A if (sp->cons_stdin_is_kbd) {
0N/A /* Stdin is from the system keyboard */
0N/A type = CONSOLE_LOCAL;
0N/A } else if ((stdindev != NODEV) && (stdindev == stdoutdev)) {
0N/A /*
0N/A * A reliable indicator that we are doing a remote console
0N/A * is that stdin and stdout are the same.
0N/A * This is probably a tip line.
0N/A */
0N/A type = CONSOLE_TIP;
0N/A } else {
0N/A type = CONSOLE_SERIAL_KEYBOARD;
0N/A }
0N/A
0N/A return (type);
0N/A}
0N/A
0N/Astatic void
0N/Aconsconfig_init_input(cons_state_t *sp)
0N/A{
0N/A ldi_handle_t new_lh;
0N/A dev_t cons_final_dev;
0N/A int err;
0N/A
0N/A cons_final_dev = NODEV;
0N/A
0N/A switch (sp->cons_input_type) {
0N/A case CONSOLE_LOCAL:
0N/A DPRINTF(DPRINT_L0, "stdin is keyboard\n");
0N/A
0N/A /*
0N/A * The machine is allowed to boot without a keyboard.
0N/A * If a user attaches a keyboard later, the keyboard
0N/A * will be hooked into the console stream with the dacf
0N/A * functions.
0N/A *
0N/A * The only drivers that look at kbbdev are the
0N/A * serial drivers, which looks at kbdev to see if
0N/A * they should allow abort on a break. In the absence
0N/A * of keyboard, the serial drivers won't be attached
0N/A * for any keyboard instance.
0N/A */
0N/A if (kbddev == NODEV) {
0N/A /*
0N/A * If there is a problem with the keyboard
0N/A * during the driver loading, then the polled
0N/A * input won't get setup properly if polled
0N/A * input is needed. This means that if the
0N/A * keyboard is hotplugged, the keyboard would
0N/A * work normally, but going down to the
0N/A * debugger would not work if polled input is
0N/A * required. This field is set here. The next
0N/A * time a keyboard is plugged in, the field is
0N/A * checked in order to give the next keyboard a
0N/A * chance at being registered for console
0N/A * input.
0N/A *
0N/A * Although this code will rarely be needed,
0N/A * USB keyboards can be flaky, so this code
0N/A * will be useful on the occasion that the
0N/A * keyboard doesn't enumerate when the drivers
0N/A * are loaded.
0N/A */
0N/A DPRINTF(DPRINT_L2, "Error with console keyboard\n");
0N/A sp->cons_keyboard_problem = B_TRUE;
0N/A }
0N/A stdindev = kbddev;
0N/A cons_final_dev = sp->cons_wc_vp->v_rdev;
0N/A break;
0N/A
0N/A case CONSOLE_TIP:
0N/A DPRINTF(DPRINT_L0, "console input is tty (%s)\n",
0N/A sp->cons_stdin_path);
0N/A
0N/A /*
0N/A * Console device drivers must be able to output
0N/A * after being closed.
0N/A */
0N/A rconsvp = i_consconfig_createvp(sp->cons_stdin_path);
0N/A if (rconsvp == NULL) {
0N/A panic("consconfig_init_input: "
0N/A "unable to find stdin device (%s)",
0N/A sp->cons_stdin_path);
0N/A /*NOTREACHED*/
0N/A }
0N/A rconsdev = rconsvp->v_rdev;
0N/A
0N/A ASSERT(rconsdev == stdindev);
0N/A
0N/A cons_final_dev = rconsdev;
0N/A break;
0N/A
0N/A case CONSOLE_SERIAL_KEYBOARD:
0N/A DPRINTF(DPRINT_L0, "stdin is serial keyboard\n");
0N/A
0N/A /*
0N/A * Non-keyboard input device, but not rconsdev.
0N/A * This is known as the "serial keyboard" case - the
0N/A * most likely use is someone has a keyboard attached
0N/A * to a serial port (tip) and still has output on a
0N/A * framebuffer.
0N/A *
0N/A * In this case, the serial driver must be linked
0N/A * directly beneath wc. Since conskbd was linked
0N/A * underneath wc above, first we unlink conskbd.
0N/A */
0N/A (void) consconfig_relink_wc(sp, NULL, &sp->conskbd_muxid);
0N/A sp->conskbd_muxid = -1;
0N/A
0N/A /*
0N/A * Open the serial keyboard, configure it,
0N/A * and link it underneath wc.
0N/A */
0N/A err = ldi_open_by_name(sp->cons_stdin_path,
0N/A FREAD|FWRITE|FNOCTTY, kcred, &new_lh, sp->cons_li);
0N/A if (err == 0) {
0N/A struct termios termios;
0N/A int rval;
0N/A int stdin_muxid;
0N/A
0N/A consconfig_prepare_dev(new_lh,
0N/A "kb", TR_CANNOT, sp->cons_input_type, CONS_KBD);
0N/A
0N/A /* Re-set baud rate */
0N/A (void) ldi_ioctl(new_lh, TCGETS, (intptr_t)&termios,
0N/A FKIOCTL, kcred, &rval);
0N/A
0N/A /* Set baud rate */
0N/A if (consconfig_setmodes(stdindev, &termios) == 0) {
0N/A err = ldi_ioctl(new_lh,
0N/A TCSETSF, (intptr_t)&termios,
0N/A FKIOCTL, kcred, &rval);
0N/A if (err) {
0N/A cmn_err(CE_WARN,
0N/A "consconfig_init_input: "
0N/A "TCSETSF failed, error %d", err);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Now link the serial keyboard direcly under wc
0N/A * we don't save the returned muxid because we
0N/A * don't support changing/hotplugging the console
0N/A * keyboard when it is a serial keyboard.
0N/A */
0N/A (void) consconfig_relink_wc(sp, new_lh, &stdin_muxid);
0N/A
0N/A (void) ldi_close(new_lh, FREAD|FWRITE, kcred);
0N/A }
0N/A
0N/A cons_final_dev = sp->cons_wc_vp->v_rdev;
0N/A break;
0N/A
0N/A default:
0N/A panic("consconfig_init_input: "
0N/A "unsupported console input/output combination");
0N/A /*NOTREACHED*/
0N/A }
0N/A
0N/A /*
0N/A * Use the redirection device/workstation console pair as the "real"
0N/A * console if the latter hasn't already been set.
0N/A * The workstation console driver needs to see rwsconsvp, but
0N/A * all other access should be through the redirecting driver.
0N/A */
0N/A if (rconsvp == NULL) {
0N/A consconfig_dprintf(DPRINT_L0, "setup redirection driver\n");
0N/A rconsvp = wsconsvp;
0N/A rconsdev = wsconsvp->v_rdev;
0N/A }
0N/A
0N/A ASSERT(cons_final_dev != NODEV);
0N/A
0N/A err = ldi_open_by_dev(&cons_final_dev, OTYP_CHR, FREAD|FWRITE|FNOCTTY,
0N/A kcred, &new_lh, sp->cons_li);
0N/A if (err) {
0N/A panic("consconfig_init_input: "
0N/A "unable to open console device");
0N/A /*NOTREACHED*/
0N/A }
0N/A
0N/A /* Enable abort on the console */
0N/A (void) consconfig_kbd_abort_enable(new_lh);
0N/A
0N/A /* Now we must close it to make console logins happy */
0N/A (void) ldi_close(new_lh, FREAD|FWRITE, kcred);
0N/A
0N/A /* Set up polled input if it is supported by the console device */
0N/A if (plat_use_polled_debug()) {
0N/A /*
0N/A * In the debug case, register the keyboard polled entry
0N/A * points, but don't throw the switch in the debugger. This
0N/A * allows the polled entry points to be checked by hand
0N/A */
0N/A consconfig_setup_polledio(sp, sp->cons_wc_vp->v_rdev);
0N/A } else {
0N/A consconfig_setup_polledio(sp, cons_final_dev);
0N/A }
0N/A
0N/A kadb_uses_kernel();
0N/A}
0N/A
0N/A/*
0N/A * This function kicks off the console configuration.
0N/A * Configure keyboard and mouse. Main entry here.
0N/A */
0N/Avoid
0N/Adynamic_console_config(void)
0N/A{
0N/A /* initialize space.c globals */
0N/A stdindev = NODEV;
0N/A mousedev = NODEV;
0N/A kbddev = NODEV;
0N/A fbdev = NODEV;
0N/A fbvp = NULL;
0N/A fbdip = NULL;
0N/A wsconsvp = NULL;
0N/A rwsconsvp = NULL;
0N/A rwsconsdev = NODEV;
0N/A rconsvp = NULL;
0N/A rconsdev = NODEV;
0N/A
0N/A /* Initialize cons_state_t structure and console device paths */
0N/A consconfig_sp = consconfig_state_init();
0N/A ASSERT(consconfig_sp);
0N/A
0N/A /* Build upper layer of console stream */
0N/A cons_build_upper_layer(consconfig_sp);
0N/A
0N/A /*
0N/A * Load keyboard/mouse drivers. The dacf routines will
0N/A * plumb the devices into the console stream
0N/A *
0N/A * At the conclusion of the ddi_pathname_to_dev_t calls, the keyboard
0N/A * and mouse drivers are linked into their respective console
0N/A * streams if the pathnames are valid.
0N/A */
0N/A consconfig_load_drivers(consconfig_sp);
0N/A consconfig_sp->cons_input_type = cons_get_input_type(consconfig_sp);
0N/A
0N/A /*
0N/A * This is legacy special case code for the "cool" virtual console
0N/A * for the Starfire project. Starfire has a dummy "ssp-serial"
0N/A * node in the OBP device tree and cvc is a pseudo driver.
0N/A */
0N/A if (consconfig_sp->cons_stdout_path != NULL && stdindev == NODEV &&
0N/A strstr(consconfig_sp->cons_stdout_path, "ssp-serial")) {
0N/A /*
0N/A * Setup the virtual console driver for Starfire
0N/A * Note that console I/O will still go through prom for now
0N/A * (notice we don't open the driver here). The cvc driver
0N/A * will be activated when /dev/console is opened by init.
0N/A * During that time, a cvcd daemon will be started that
0N/A * will open the cvcredirection driver to facilitate
0N/A * the redirection of console I/O from cvc to cvcd.
0N/A */
0N/A rconsvp = i_consconfig_createvp(CVC_PATH);
0N/A if (rconsvp == NULL)
0N/A return;
0N/A rconsdev = rconsvp->v_rdev;
0N/A return;
0N/A }
0N/A
0N/A rwsconsvp = consconfig_sp->cons_wc_vp;
0N/A rwsconsdev = consconfig_sp->cons_wc_vp->v_rdev;
0N/A
0N/A
0N/A /* initialize framebuffer, console input, and redirection device */
0N/A consconfig_init_framebuffer(consconfig_sp);
0N/A consconfig_init_input(consconfig_sp);
0N/A
0N/A#if !defined(__x86)
0N/A /* initialize virtual console vp for logging if needed */
0N/A consconfig_virtual_console_vp(consconfig_sp);
0N/A#endif
0N/A
0N/A DPRINTF(DPRINT_L0,
0N/A "mousedev %lx, kbddev %lx, fbdev %lx, rconsdev %lx\n",
0N/A mousedev, kbddev, fbdev, rconsdev);
0N/A
0N/A flush_deferred_console_buf();
0N/A}
0N/A
0N/A
0N/A/*
0N/A * Start of DACF interfaces
0N/A */
0N/A
0N/A/*
0N/A * Do the real job for keyboard/mouse auto-configuration.
0N/A */
0N/Astatic int
0N/Ado_config(cons_state_t *sp, cons_prop_t *prop)
0N/A{
0N/A ldi_handle_t lh;
0N/A dev_t dev;
0N/A int error;
0N/A
0N/A ASSERT((prop->cp_type == CONS_KBD) || (prop->cp_type == CONS_MS));
0N/A
0N/A dev = prop->cp_dev;
0N/A error = ldi_open_by_dev(&dev, OTYP_CHR,
0N/A FREAD|FWRITE|FNOCTTY, kcred, &lh, sp->cons_li);
0N/A if (error) {
0N/A return (DACF_FAILURE);
0N/A }
0N/A ASSERT(dev == prop->cp_dev); /* clone not supported */
0N/A
0N/A /*
0N/A * Prepare the new keyboard/mouse driver
0N/A * to be linked under conskbd/consms.
0N/A */
0N/A consconfig_prepare_dev(lh, prop->cp_pushmod, TR_CAN,
0N/A sp->cons_input_type, prop->cp_type);
0N/A
0N/A if (prop->cp_type == CONS_KBD) {
0N/A /*
0N/A * Tell the physical keyboard driver to send
0N/A * the abort sequences up to the virtual keyboard
0N/A * driver so that STOP and A (or F1 and A)
0N/A * can be applied to different keyboards.
0N/A */
0N/A (void) consconfig_kbd_abort_disable(lh);
0N/A
0N/A /* Link the stream underneath conskbd */
0N/A error = consconfig_relink_conskbd(sp, lh, &prop->cp_muxid);
0N/A } else {
0N/A /* Link the stream underneath consms */
0N/A error = consconfig_relink_consms(sp, lh, &prop->cp_muxid);
0N/A }
0N/A
0N/A /*
0N/A * At this point, the stream is:
0N/A * for keyboard: wc->conskbd->["pushmod"->"kbd_vp driver"]
0N/A * for mouse: consms->["module_name"->]"mouse_avp driver"
0N/A */
0N/A
0N/A /* Close the driver stream, it will stay linked under conskbd */
0N/A (void) ldi_close(lh, FREAD|FWRITE, kcred);
0N/A
0N/A if (error) {
0N/A return (DACF_FAILURE);
0N/A }
0N/A
0N/A return (DACF_SUCCESS);
0N/A}
0N/A
0N/Astatic int
0N/Ado_unconfig(cons_state_t *sp, cons_prop_t *prop)
0N/A{
0N/A ASSERT((prop->cp_type == CONS_KBD) || (prop->cp_type == CONS_MS));
0N/A
0N/A if (prop->cp_type == CONS_KBD)
0N/A return (consconfig_relink_conskbd(sp, NULL, &prop->cp_muxid));
0N/A else
0N/A return (consconfig_relink_consms(sp, NULL, &prop->cp_muxid));
0N/A}
0N/A
0N/Astatic int
0N/Akb_ms_config(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int type)
0N/A{
0N/A major_t major;
0N/A minor_t minor;
0N/A dev_t dev;
0N/A dev_info_t *dip;
0N/A cons_state_t *sp;
0N/A cons_prop_t *prop;
0N/A const char *pushmod;
0N/A
0N/A /*
0N/A * Retrieve the state information
0N/A * Some platforms may use the old-style "consconfig" to configure
0N/A * console stream modules but may also support devices that happen
0N/A * to match a rule in /etc/dacf.conf. This will cause a problem
0N/A * since the console state structure will not be initialized.
0N/A * In that case, these entry points should silently fail and
0N/A * permit console to be plumbed later in boot.
0N/A */
0N/A if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
0N/A return (DACF_FAILURE);
0N/A
0N/A dip = dacf_devinfo_node(minor_hdl);
0N/A major = ddi_driver_major(dip);
0N/A ASSERT(major != DDI_MAJOR_T_NONE);
0N/A minor = dacf_minor_number(minor_hdl);
0N/A dev = makedevice(major, minor);
0N/A ASSERT(dev != NODEV);
0N/A
0N/A DPRINTF(DPRINT_L0, "driver name = \"%s\", dev = 0x%lx, major = 0x%x\n",
0N/A (char *)dacf_driver_name(minor_hdl), dev, major);
0N/A
0N/A /* Access to the global variables is synchronized */
0N/A mutex_enter(&sp->cons_lock);
0N/A
0N/A /*
0N/A * Check if the keyboard/mouse has already configured.
0N/A */
0N/A if (consconfig_find_dev(sp, dev) != NULL) {
0N/A mutex_exit(&sp->cons_lock);
0N/A return (DACF_SUCCESS);
0N/A }
0N/A
0N/A prop = kmem_zalloc(sizeof (cons_prop_t), KM_SLEEP);
0N/A
0N/A /* Config the new keyboard/mouse device */
0N/A prop->cp_dev = dev;
0N/A
0N/A pushmod = dacf_get_arg(arg_hdl, "pushmod");
0N/A prop->cp_pushmod = i_ddi_strdup((char *)pushmod, KM_SLEEP);
0N/A
0N/A prop->cp_type = type;
0N/A if (do_config(sp, prop) != DACF_SUCCESS) {
0N/A /*
0N/A * The keyboard/mouse node failed to open.
0N/A * Set the major and minor numbers to 0 so
0N/A * kb_unconfig/ms_unconfig won't unconfigure
0N/A * this node if it is detached.
0N/A */
0N/A mutex_exit(&sp->cons_lock);
0N/A consconfig_free_prop(prop);
0N/A return (DACF_FAILURE);
0N/A }
0N/A
0N/A consconfig_add_dev(sp, prop);
0N/A
0N/A /*
0N/A * See if there was a problem with the console keyboard during boot.
0N/A * If so, try to register polled input for this keyboard.
0N/A */
0N/A if ((type == CONS_KBD) && (sp->cons_keyboard_problem)) {
0N/A consconfig_setup_polledio(sp, sp->cons_wc_vp->v_rdev);
0N/A sp->cons_keyboard_problem = B_FALSE;
0N/A }
0N/A
0N/A /* Prevent autodetach due to memory pressure */
0N/A (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, DDI_NO_AUTODETACH, 1);
0N/A
0N/A mutex_exit(&sp->cons_lock);
0N/A
0N/A return (DACF_SUCCESS);
0N/A}
0N/A
0N/Astatic int
0N/Akb_ms_unconfig(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl)
0N/A{
0N/A _NOTE(ARGUNUSED(arg_hdl))
0N/A
0N/A major_t major;
0N/A minor_t minor;
0N/A dev_t dev;
0N/A dev_info_t *dip;
0N/A cons_state_t *sp;
0N/A cons_prop_t *prop;
0N/A
0N/A /*
0N/A * Retrieve the state information
0N/A * So if there isn't a state available, then this entry point just
0N/A * returns. See note in kb_config().
0N/A */
0N/A if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
0N/A return (DACF_SUCCESS);
0N/A
0N/A dip = dacf_devinfo_node(minor_hdl);
0N/A major = ddi_driver_major(dip);
0N/A ASSERT(major != DDI_MAJOR_T_NONE);
0N/A minor = dacf_minor_number(minor_hdl);
0N/A dev = makedevice(major, minor);
0N/A ASSERT(dev != NODEV);
0N/A
0N/A /*
0N/A * Check if the keyboard/mouse that is being detached
0N/A * is the console keyboard/mouse or not.
0N/A */
0N/A mutex_enter(&sp->cons_lock);
0N/A if ((prop = consconfig_find_dev(sp, dev)) == NULL) {
0N/A mutex_exit(&sp->cons_lock);
0N/A return (DACF_SUCCESS);
0N/A }
0N/A
0N/A /*
0N/A * This dev may be opened physically and then hotplugged out.
0N/A */
0N/A if (prop->cp_muxid != -1) {
0N/A (void) do_unconfig(sp, prop);
0N/A consconfig_rem_dev(sp, dev);
0N/A }
0N/A
0N/A mutex_exit(&sp->cons_lock);
0N/A
0N/A return (DACF_SUCCESS);
0N/A}
0N/A
0N/A/*
0N/A * This is the post-attach / pre-detach action function for the keyboard
0N/A * and mouse. This function is associated with a node type in /etc/dacf.conf.
0N/A */
0N/Astatic int
0N/Akb_config(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags)
0N/A{
0N/A _NOTE(ARGUNUSED(flags))
0N/A
0N/A return (kb_ms_config(minor_hdl, arg_hdl, CONS_KBD));
0N/A}
0N/A
0N/Astatic int
0N/Ams_config(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags)
0N/A{
0N/A _NOTE(ARGUNUSED(flags))
0N/A
0N/A return (kb_ms_config(minor_hdl, arg_hdl, CONS_MS));
0N/A}
0N/A
0N/Astatic int
0N/Akb_unconfig(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags)
0N/A{
0N/A _NOTE(ARGUNUSED(flags))
0N/A
0N/A return (kb_ms_unconfig(minor_hdl, arg_hdl));
0N/A}
0N/A
0N/Astatic int
0N/Ams_unconfig(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags)
0N/A{
0N/A _NOTE(ARGUNUSED(flags))
0N/A
0N/A return (kb_ms_unconfig(minor_hdl, arg_hdl));
0N/A}
0N/A
0N/A/*
0N/A * consconfig_link and consconfig_unlink are provided to support
0N/A * direct access to physical keyboard/mouse underlying conskbd/
0N/A * consms.
0N/A * When the keyboard/mouse is opened physically via its device
0N/A * file, it will be unlinked from the virtual one, and when it
0N/A * is closed physically, it will be linked back under the virtual
0N/A * one.
0N/A */
0N/Avoid
0N/Aconsconfig_link(major_t major, minor_t minor)
0N/A{
10N/A char buf[MAXPATHLEN];
10N/A dev_t dev;
10N/A cons_state_t *sp;
0N/A cons_prop_t *prop;
0N/A
0N/A if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
0N/A return;
0N/A
0N/A dev = makedevice(major, minor);
0N/A ASSERT(dev != NODEV);
0N/A
0N/A mutex_enter(&sp->cons_lock);
0N/A if ((prop = consconfig_find_dev(sp, dev)) == NULL) {
0N/A mutex_exit(&sp->cons_lock);
0N/A return;
0N/A }
0N/A
0N/A if (do_config(sp, prop) != DACF_SUCCESS) {
0N/A (void) ddi_dev_pathname(dev, 0, buf);
0N/A if (prop->cp_type == CONS_KBD)
0N/A cmn_err(CE_WARN, "Failed to relink the keyboard "
0N/A "(%s) underneath virtual keyboard", buf);
0N/A else
0N/A cmn_err(CE_WARN, "Failed to relink the mouse "
0N/A "(%s) underneath virtual mouse", buf);
0N/A consconfig_rem_dev(sp, dev);
0N/A }
0N/A
0N/A mutex_exit(&sp->cons_lock);
0N/A}
0N/A
0N/A
0N/Aint
0N/Aconsconfig_unlink(major_t major, minor_t minor)
0N/A{
0N/A dev_t dev;
0N/A cons_state_t *sp;
0N/A cons_prop_t *prop;
0N/A int error;
0N/A
0N/A if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
0N/A return (DACF_SUCCESS);
0N/A
0N/A dev = makedevice(major, minor);
0N/A ASSERT(dev != NODEV);
0N/A
0N/A mutex_enter(&sp->cons_lock);
0N/A if ((prop = consconfig_find_dev(sp, dev)) == NULL) {
0N/A mutex_exit(&sp->cons_lock);
0N/A return (DACF_FAILURE);
0N/A }
0N/A
0N/A error = do_unconfig(sp, prop);
0N/A
0N/A /*
0N/A * Keep this dev on the list, for this dev is still online.
0N/A */
0N/A mutex_exit(&sp->cons_lock);
0N/A
0N/A return (error);
0N/A}
0N/A
0N/A/*
0N/A * Routine to set baud rate, bits-per-char, parity and stop bits
0N/A * on the console line when necessary.
0N/A */
0N/Astatic int
0N/Aconsconfig_setmodes(dev_t dev, struct termios *termiosp)
0N/A{
0N/A char buf[MAXPATHLEN];
0N/A int len = MAXPATHLEN;
0N/A char name[16];
0N/A int ppos, i;
0N/A char *path;
0N/A dev_t tdev;
0N/A
0N/A /*
0N/A * First, search for a devalias which matches this dev_t.
0N/A * Try all of ttya through ttyz until no such alias
0N/A */
0N/A (void) strcpy(name, "ttya");
0N/A for (i = 0; i < ('z'-'a'); i++) {
0N/A name[3] = 'a' + i; /* increment device name */
0N/A path = get_alias(name, buf);
0N/A if (path == NULL)
0N/A return (1);
0N/A
0N/A tdev = ddi_pathname_to_dev_t(path);
0N/A if (tdev == dev)
0N/A break; /* Exit loop if found */
0N/A }
0N/A
0N/A if (i >= ('z'-'a'))
0N/A return (1); /* If we didn't find it, return */
0N/A
0N/A /*
0N/A * Now that we know which "tty" this corresponds to, retrieve
0N/A * the "ttya-mode" options property, which tells us how to configure
0N/A * the line.
0N/A */
0N/A (void) strcpy(name, "ttya-mode"); /* name of option we want */
0N/A name[3] = 'a' + i; /* Adjust to correct line */
0N/A
0N/A if (ddi_getlongprop_buf(DDI_DEV_T_ANY, ddi_root_node(), 0, name,
0N/A buf, &len) != DDI_PROP_SUCCESS)
0N/A return (1); /* if no such option, just return */
0N/A
0N/A /*
0N/A * The IEEE 1275 standard specifies that /aliases string property
0N/A * values should be null-terminated. Unfortunately the reality
0N/A * is that most aren't and the OBP can't easily be modified to
0N/A * add null termination to these strings. So we'll add the
0N/A * null termination here. If the string already contains a
0N/A * null termination character then that's ok too because we'll
0N/A * just be adding a second one.
0N/A */
0N/A buf[len] = '\0';
0N/A
0N/A /* Clear out options we will be setting */
0N/A termiosp->c_cflag &=
0N/A ~(CSIZE | CBAUD | CBAUDEXT | PARODD | PARENB | CSTOPB);
0N/A
0N/A /* Clear options which potentially conflict with new settings */
0N/A termiosp->c_cflag &= ~(CIBAUD | CIBAUDEXT);
0N/A
0N/A /*
0N/A * Now, parse the string. Wish I could use sscanf().
0N/A * Format 9600,8,n,1,-
0N/A * baud rate, bits-per-char, parity, stop-bits, ignored
0N/A */
0N/A for (ppos = 0; ppos < (MAXPATHLEN-8); ppos++) { /* Find first comma */
0N/A if ((buf[ppos] == 0) || (buf[ppos] == ','))
0N/A break;
0N/A }
0N/A
0N/A if (buf[ppos] != ',') {
0N/A cmn_err(CE_WARN, "consconfig_setmodes: "
0N/A "invalid mode string %s", buf);
0N/A return (1);
0N/A }
0N/A
0N/A for (i = 0; i < MAX_SPEEDS; i++) {
0N/A if (strncmp(buf, speedtab[i].name, ppos) == 0)
0N/A break;
0N/A }
0N/A
0N/A if (i >= MAX_SPEEDS) {
0N/A cmn_err(CE_WARN,
0N/A "consconfig_setmodes: unrecognized speed in %s", buf);
0N/A return (1);
0N/A }
0N/A
0N/A /* Found the baud rate, set it */
0N/A termiosp->c_cflag |= speedtab[i].code & CBAUD;
0N/A if (speedtab[i].code > 16) /* cfsetospeed! */
0N/A termiosp->c_cflag |= CBAUDEXT;
0N/A
0N/A /* Set bits per character */
0N/A switch (buf[ppos+1]) {
0N/A case '8':
0N/A termiosp->c_cflag |= CS8;
0N/A break;
0N/A case '7':
0N/A termiosp->c_cflag |= CS7;
0N/A break;
0N/A default:
0N/A cmn_err(CE_WARN,
0N/A "consconfig_setmodes: illegal bits-per-char %s", buf);
0N/A return (1);
0N/A }
0N/A
0N/A /* Set parity */
0N/A switch (buf[ppos+3]) {
0N/A case 'o':
0N/A termiosp->c_cflag |= PARENB | PARODD;
0N/A break;
0N/A case 'e':
0N/A termiosp->c_cflag |= PARENB; /* enabled, not odd */
0N/A break;
0N/A case 'n':
0N/A break; /* not enabled. */
0N/A default:
0N/A cmn_err(CE_WARN, "consconfig_setmodes: illegal parity %s", buf);
0N/A return (1);
0N/A }
0N/A
0N/A /* Set stop bits */
0N/A switch (buf[ppos+5]) {
0N/A case '1':
0N/A break; /* No extra stop bit */
0N/A case '2':
0N/A termiosp->c_cflag |= CSTOPB; /* 1 extra stop bit */
0N/A break;
0N/A default:
0N/A cmn_err(CE_WARN, "consconfig_setmodes: "
0N/A "illegal stop bits %s", buf);
0N/A return (1);
0N/A }
0N/A
0N/A return (0);
0N/A}
0N/A
0N/A/*
0N/A * Check to see if underlying keyboard devices are still online,
0N/A * if any one is offline now, unlink it.
0N/A */
0N/Astatic void
0N/Aconsconfig_check_phys_kbd(cons_state_t *sp)
0N/A{
0N/A ldi_handle_t kb_lh;
0N/A cons_prop_t *prop;
0N/A int error;
0N/A int rval;
0N/A
0N/A for (prop = sp->cons_km_prop; prop; prop = prop->cp_next) {
0N/A if ((prop->cp_type != CONS_KBD) || (prop->cp_muxid == -1))
0N/A continue;
0N/A
0N/A error = ldi_open_by_dev(&prop->cp_dev, OTYP_CHR,
0N/A FREAD|FWRITE|FNOCTTY, kcred, &kb_lh, sp->cons_li);
0N/A
0N/A if (error) {
0N/A (void) ldi_ioctl(sp->conskbd_lh, I_PUNLINK,
0N/A prop->cp_muxid, FKIOCTL, kcred, &rval);
0N/A prop->cp_dev = NODEV;
0N/A } else {
0N/A (void) ldi_close(kb_lh, FREAD|FWRITE, kcred);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Remove all disconnected keyboards,
0N/A * whose dev is turned into NODEV above.
0N/A */
0N/A consconfig_rem_dev(sp, NODEV);
0N/A}
0N/A
0N/A/*
0N/A * Remove devices according to dev, which may be NODEV
0N/A */
0N/Astatic void
0N/Aconsconfig_rem_dev(cons_state_t *sp, dev_t dev)
0N/A{
0N/A cons_prop_t *prop;
0N/A cons_prop_t *prev_prop;
0N/A cons_prop_t *tmp_prop;
0N/A cons_prop_t *head_prop;
0N/A
0N/A head_prop = NULL;
0N/A prev_prop = NULL;
0N/A for (prop = sp->cons_km_prop; prop != NULL; ) {
0N/A if (prop->cp_dev == dev) {
0N/A tmp_prop = prop->cp_next;
0N/A consconfig_free_prop(prop);
0N/A prop = tmp_prop;
0N/A if (prev_prop)
0N/A prev_prop->cp_next = prop;
0N/A } else {
0N/A if (head_prop == NULL)
0N/A head_prop = prop;
0N/A prev_prop = prop;
0N/A prop = prop->cp_next;
0N/A }
0N/A }
0N/A sp->cons_km_prop = head_prop;
0N/A}
0N/A
0N/A/*
0N/A * Add a dev according to prop
0N/A */
0N/Astatic void
0N/Aconsconfig_add_dev(cons_state_t *sp, cons_prop_t *prop)
0N/A{
0N/A prop->cp_next = sp->cons_km_prop;
0N/A sp->cons_km_prop = prop;
0N/A}
0N/A
0N/A/*
0N/A * Find a device from our list according to dev
0N/A */
0N/Astatic cons_prop_t *
0N/Aconsconfig_find_dev(cons_state_t *sp, dev_t dev)
0N/A{
0N/A cons_prop_t *prop;
0N/A
0N/A for (prop = sp->cons_km_prop; prop; prop = prop->cp_next) {
0N/A if (prop->cp_dev == dev)
0N/A break;
0N/A }
0N/A
0N/A return (prop);
0N/A}
0N/A
0N/A/*
0N/A * Free a cons prop associated with a keyboard or mouse
0N/A */
0N/Astatic void
0N/Aconsconfig_free_prop(cons_prop_t *prop)
0N/A{
0N/A if (prop->cp_pushmod)
0N/A kmem_free(prop->cp_pushmod, strlen(prop->cp_pushmod) + 1);
0N/A kmem_free(prop, sizeof (cons_prop_t));
0N/A}
0N/A
0N/A/*
0N/A * The early boot code can't print to a usb serial device or the
0N/A * graphical boot screen.
0N/A *
0N/A * The early boot messages are saved in a buffer at the address indicated
0N/A * by "deferred-console-buf" This function flushes the message to the
0N/A * current console now that it is set up.
0N/A */
0N/Astatic void
0N/Aflush_deferred_console_buf(void)
0N/A{
0N/A int rval;
0N/A vnode_t *vp;
0N/A uint_t defcons_buf;
0N/A char *kc, *bc, *defcons_kern_buf;
0N/A
0N/A /* defcons_buf is in low memory, so an int works here */
0N/A defcons_buf = ddi_prop_get_int(DDI_DEV_T_ANY, ddi_root_node(),
0N/A DDI_PROP_DONTPASS, "deferred-console-buf", 0);
0N/A
0N/A if (defcons_buf == 0)
0N/A return;
0N/A
0N/A /*
0N/A * After consconfig() and before userland opens /dev/sysmsg,
0N/A * console I/O is goes to polled I/O entry points.
0N/A *
0N/A * If usb-serial doesn't implement polled I/O, we need
0N/A * to open /dev/console now to get kernel console I/O to work.
0N/A * We also push ttcompat and ldterm explicitly to get the
0N/A * correct output format (autopush isn't set up yet). We
0N/A * ignore push errors because they are non-fatal.
0N/A * Note that opening /dev/console causes rconsvp to be
0N/A * opened as well.
0N/A */
0N/A if (cons_polledio == NULL) {
0N/A if (vn_open("/dev/console", UIO_SYSSPACE, FWRITE | FNOCTTY,
0N/A 0, &vp, 0, 0) != 0)
0N/A return;
0N/A
0N/A if (rconsvp) {
0N/A (void) strioctl(rconsvp, __I_PUSH_NOCTTY,
0N/A (intptr_t)"ldterm", FKIOCTL, K_TO_K, kcred, &rval);
0N/A (void) strioctl(rconsvp, __I_PUSH_NOCTTY,
0N/A (intptr_t)"ttcompat", FKIOCTL, K_TO_K,
0N/A kcred, &rval);
0N/A }
0N/A }
0N/A
0N/A /*
0N/A * Copy message to a kernel buffer. Various kernel routines
0N/A * expect buffer to be above kernelbase
0N/A */
0N/A kc = defcons_kern_buf = kmem_zalloc(MMU_PAGESIZE, KM_SLEEP);
0N/A bc = (char *)(uintptr_t)defcons_buf;
0N/A while (*kc++ = *bc++)
0N/A ;
0N/A console_printf("%s", defcons_kern_buf);
0N/A
0N/A kmem_free(defcons_kern_buf, MMU_PAGESIZE);
0N/A}
0N/A
0N/Aboolean_t
0N/Aconsconfig_console_is_tipline(void)
0N/A{
0N/A cons_state_t *sp;
0N/A
0N/A if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
0N/A return (B_FALSE);
0N/A
0N/A if (sp->cons_input_type == CONSOLE_TIP)
0N/A return (B_TRUE);
0N/A
0N/A return (B_FALSE);
0N/A}
0N/A