10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51253Slq150181 * Common Development and Distribution License (the "License").
61253Slq150181 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211253Slq150181
220Sstevel@tonic-gate /*
23*11585SVincent.Wang@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate * This module performs two functions. First, it kicks off the driver loading
290Sstevel@tonic-gate * of the console devices during boot in dynamic_console_config().
300Sstevel@tonic-gate * The loading of the drivers for the console devices triggers the
310Sstevel@tonic-gate * additional device autoconfiguration to link the drivers into the keyboard
320Sstevel@tonic-gate * and mouse console streams.
330Sstevel@tonic-gate *
340Sstevel@tonic-gate * The second function of this module is to provide the dacf functions
350Sstevel@tonic-gate * to be called after a driver has attached and before it detaches. For
360Sstevel@tonic-gate * example, a driver associated with the keyboard will have kb_config called
370Sstevel@tonic-gate * after the driver attaches and kb_unconfig before it detaches. Similar
380Sstevel@tonic-gate * configuration actions are performed on behalf of minor nodes representing
390Sstevel@tonic-gate * mice. The configuration functions for the attach case take a module
400Sstevel@tonic-gate * name as a parameter. The module is pushed on top of the driver during
410Sstevel@tonic-gate * the configuration.
420Sstevel@tonic-gate *
430Sstevel@tonic-gate * Although the dacf framework is used to configure all keyboards and mice,
440Sstevel@tonic-gate * its primary function is to allow keyboard and mouse hotplugging.
450Sstevel@tonic-gate *
460Sstevel@tonic-gate * This module supports multiple keyboards and mice at the same time.
470Sstevel@tonic-gate *
480Sstevel@tonic-gate * From the kernel perspective, there are roughly three different possible
490Sstevel@tonic-gate * console configurations. Across these three configurations, the following
500Sstevel@tonic-gate * elements are constant:
510Sstevel@tonic-gate * wsconsvp = IWSCN_PATH
520Sstevel@tonic-gate * rwsconsvp = WC_PATH
530Sstevel@tonic-gate * consms -> msdev
540Sstevel@tonic-gate *
550Sstevel@tonic-gate * The "->" syntax indicates that the streams device on the right is
560Sstevel@tonic-gate * linked under the streams device on the left.
570Sstevel@tonic-gate *
580Sstevel@tonic-gate * The following lists how the system is configured for different setups:
590Sstevel@tonic-gate *
600Sstevel@tonic-gate * stdin is a local keyboard. use stdin and stdout as the console.
610Sstevel@tonic-gate * sp->cons_input_type = CONSOLE_LOCAL
620Sstevel@tonic-gate * rconsvp = IWSCN_PATH
630Sstevel@tonic-gate * wc -> conskbd -> kbddev
640Sstevel@tonic-gate *
650Sstevel@tonic-gate * stdin is not a keyboard and stdin is the same as stdout.
660Sstevel@tonic-gate * assume we running on a tip line and use stdin/stdout as the console.
670Sstevel@tonic-gate * sp->cons_input_type = CONSOLE_TIP
680Sstevel@tonic-gate * rconsvp = (stdindev/stdoutdev)
690Sstevel@tonic-gate * wc -> conskbd -> kbddev
700Sstevel@tonic-gate *
710Sstevel@tonic-gate * stdin is not a keyboard device and it's not the same as stdout.
720Sstevel@tonic-gate * assume we have a serial keyboard hooked up and use it along with
730Sstevel@tonic-gate * stdout as the console.
740Sstevel@tonic-gate * sp->cons_input_type = CONSOLE_SERIAL_KEYBOARD
750Sstevel@tonic-gate * rconsvp = IWSCN_PATH
760Sstevel@tonic-gate * wc -> stdindev
770Sstevel@tonic-gate * conskbd -> kbddev
780Sstevel@tonic-gate *
790Sstevel@tonic-gate * CAVEAT:
800Sstevel@tonic-gate * The above is all true except for one possible Intel configuration.
810Sstevel@tonic-gate * If stdin is set to a local keyboard but stdout is set to something
820Sstevel@tonic-gate * other than the local display (a tip port for example) stdout will
830Sstevel@tonic-gate * still go to the local display. This is an artifact of the console
840Sstevel@tonic-gate * implementation on intel.
850Sstevel@tonic-gate */
860Sstevel@tonic-gate
870Sstevel@tonic-gate #include <sys/types.h>
880Sstevel@tonic-gate #include <sys/param.h>
890Sstevel@tonic-gate #include <sys/cmn_err.h>
900Sstevel@tonic-gate #include <sys/user.h>
910Sstevel@tonic-gate #include <sys/vfs.h>
920Sstevel@tonic-gate #include <sys/vnode.h>
930Sstevel@tonic-gate #include <sys/pathname.h>
940Sstevel@tonic-gate #include <sys/systm.h>
950Sstevel@tonic-gate #include <sys/file.h>
960Sstevel@tonic-gate #include <sys/stropts.h>
970Sstevel@tonic-gate #include <sys/stream.h>
980Sstevel@tonic-gate #include <sys/strsubr.h>
990Sstevel@tonic-gate
1000Sstevel@tonic-gate #include <sys/consdev.h>
1011253Slq150181 #include <sys/console.h>
1021253Slq150181 #include <sys/wscons.h>
1030Sstevel@tonic-gate #include <sys/kbio.h>
1040Sstevel@tonic-gate #include <sys/debug.h>
1050Sstevel@tonic-gate #include <sys/reboot.h>
1060Sstevel@tonic-gate #include <sys/termios.h>
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate #include <sys/ddi.h>
1090Sstevel@tonic-gate #include <sys/sunddi.h>
1100Sstevel@tonic-gate #include <sys/sunldi.h>
1110Sstevel@tonic-gate #include <sys/sunndi.h>
1120Sstevel@tonic-gate #include <sys/ndi_impldefs.h>
1130Sstevel@tonic-gate #include <sys/modctl.h>
1140Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
1150Sstevel@tonic-gate #include <sys/ddi_implfuncs.h>
1160Sstevel@tonic-gate #include <sys/promif.h>
1170Sstevel@tonic-gate #include <sys/fs/snode.h>
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate #include <sys/errno.h>
1200Sstevel@tonic-gate #include <sys/devops.h>
1210Sstevel@tonic-gate #include <sys/note.h>
1220Sstevel@tonic-gate
1231253Slq150181 #include <sys/tem_impl.h>
1240Sstevel@tonic-gate #include <sys/polled_io.h>
1250Sstevel@tonic-gate #include <sys/kmem.h>
1260Sstevel@tonic-gate #include <sys/dacf.h>
1270Sstevel@tonic-gate #include <sys/consconfig_dacf.h>
1287335SLipeng.Sang@Sun.COM #include <sys/consplat.h>
1292191Sszhou #include <sys/log.h>
1302191Sszhou #include <sys/disp.h>
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate /*
1330Sstevel@tonic-gate * External global variables
1340Sstevel@tonic-gate */
1350Sstevel@tonic-gate extern vnode_t *rconsvp;
1360Sstevel@tonic-gate extern dev_t rwsconsdev;
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate /*
1390Sstevel@tonic-gate * External functions
1400Sstevel@tonic-gate */
1410Sstevel@tonic-gate extern uintptr_t space_fetch(char *key);
1420Sstevel@tonic-gate extern int space_store(char *key, uintptr_t ptr);
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate /*
1450Sstevel@tonic-gate * Tasks
1460Sstevel@tonic-gate */
1470Sstevel@tonic-gate static int kb_config(dacf_infohdl_t, dacf_arghdl_t, int);
1480Sstevel@tonic-gate static int kb_unconfig(dacf_infohdl_t, dacf_arghdl_t, int);
1490Sstevel@tonic-gate static int ms_config(dacf_infohdl_t, dacf_arghdl_t, int);
1500Sstevel@tonic-gate static int ms_unconfig(dacf_infohdl_t, dacf_arghdl_t, int);
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate /*
1530Sstevel@tonic-gate * Internal functions
1540Sstevel@tonic-gate */
1550Sstevel@tonic-gate static int consconfig_setmodes(dev_t dev, struct termios *termiosp);
1560Sstevel@tonic-gate static void consconfig_check_phys_kbd(cons_state_t *);
1570Sstevel@tonic-gate static void consconfig_rem_dev(cons_state_t *, dev_t);
1580Sstevel@tonic-gate static void consconfig_add_dev(cons_state_t *, cons_prop_t *);
1590Sstevel@tonic-gate static cons_prop_t *consconfig_find_dev(cons_state_t *, dev_t);
1600Sstevel@tonic-gate static void consconfig_free_prop(cons_prop_t *prop);
1618960SJan.Setje-Eilers@Sun.COM static void flush_deferred_console_buf(void);
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate
1640Sstevel@tonic-gate /*
1650Sstevel@tonic-gate * On supported configurations, the firmware defines the keyboard and mouse
1660Sstevel@tonic-gate * paths. However, during USB development, it is useful to be able to use
1670Sstevel@tonic-gate * the USB keyboard and mouse on machines without full USB firmware support.
1680Sstevel@tonic-gate * These variables may be set in /etc/system according to a machine's
1690Sstevel@tonic-gate * USB configuration. This module will override the firmware's values
1700Sstevel@tonic-gate * with these.
1710Sstevel@tonic-gate *
1720Sstevel@tonic-gate * NOTE:
1730Sstevel@tonic-gate * The master copies of these variables in the misc/consconfig module.
1740Sstevel@tonic-gate * The reason for this is historic. In versions of solaris up to and
1750Sstevel@tonic-gate * including solaris 9 the conscole configuration code was split into a
1760Sstevel@tonic-gate * seperate sparc and intel version. These variables were defined
1770Sstevel@tonic-gate * in misc/consconfig on sparc and dacf/consconfig_dacf on intel.
1780Sstevel@tonic-gate *
1790Sstevel@tonic-gate * Unfortunatly the sparc variables were well documented.
1800Sstevel@tonic-gate * So to aviod breaking either sparc or intel we'll declare the variables
1810Sstevel@tonic-gate * in both modules. This will allow any /etc/system entries that
1820Sstevel@tonic-gate * users may have to continue working.
1830Sstevel@tonic-gate *
1840Sstevel@tonic-gate * The variables in misc/consconfig will take precedence over the variables
1850Sstevel@tonic-gate * found in this file. Since we eventually want to remove the variables
1860Sstevel@tonic-gate * local to this this file, if the user set them we'll emmit an error
1870Sstevel@tonic-gate * message telling them they need to set the variables in misc/consconfig
1880Sstevel@tonic-gate * instead.
1890Sstevel@tonic-gate */
1900Sstevel@tonic-gate static char *usb_kb_path = NULL;
1910Sstevel@tonic-gate static char *usb_ms_path = NULL;
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate /*
1940Sstevel@tonic-gate * Access functions in the misc/consconfig module used to retrieve the
1950Sstevel@tonic-gate * values of it local usb_kb_path and usb_ms_path variables
1960Sstevel@tonic-gate */
1970Sstevel@tonic-gate extern char *consconfig_get_usb_kb_path();
1980Sstevel@tonic-gate extern char *consconfig_get_usb_ms_path();
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate * Local variables used to store the value of the usb_kb_path and
2020Sstevel@tonic-gate * usb_ms_path variables found in misc/consconfig
2030Sstevel@tonic-gate */
2040Sstevel@tonic-gate static char *consconfig_usb_kb_path = NULL;
2050Sstevel@tonic-gate static char *consconfig_usb_ms_path = NULL;
2060Sstevel@tonic-gate
2070Sstevel@tonic-gate /*
2080Sstevel@tonic-gate * Internal variables
2090Sstevel@tonic-gate */
2100Sstevel@tonic-gate static dev_t stdoutdev;
2113446Smrj static cons_state_t *consconfig_sp;
2120Sstevel@tonic-gate
2130Sstevel@tonic-gate /*
2140Sstevel@tonic-gate * consconfig_errlevel: debug verbosity; smaller numbers are more
2150Sstevel@tonic-gate * verbose.
2160Sstevel@tonic-gate */
2173446Smrj int consconfig_errlevel = DPRINT_L3;
2180Sstevel@tonic-gate
2190Sstevel@tonic-gate /*
2200Sstevel@tonic-gate * Baud rate table
2210Sstevel@tonic-gate */
2220Sstevel@tonic-gate static struct speed {
2230Sstevel@tonic-gate char *name;
2240Sstevel@tonic-gate int code;
2259354STim.Marsland@Sun.COM } speedtab[] = {
2260Sstevel@tonic-gate {"0", B0}, {"50", B50}, {"75", B75},
2270Sstevel@tonic-gate {"110", B110}, {"134", B134}, {"150", B150},
2280Sstevel@tonic-gate {"200", B200}, {"300", B300}, {"600", B600},
2290Sstevel@tonic-gate {"1200", B1200}, {"1800", B1800}, {"2400", B2400},
2300Sstevel@tonic-gate {"4800", B4800}, {"9600", B9600}, {"19200", B19200},
2310Sstevel@tonic-gate {"38400", B38400}, {"57600", B57600}, {"76800", B76800},
2320Sstevel@tonic-gate {"115200", B115200}, {"153600", B153600}, {"230400", B230400},
2339354STim.Marsland@Sun.COM {"307200", B307200}, {"460800", B460800}, {"921600", B921600},
2349354STim.Marsland@Sun.COM {"", 0}
2350Sstevel@tonic-gate };
2360Sstevel@tonic-gate
2379354STim.Marsland@Sun.COM static const int MAX_SPEEDS = sizeof (speedtab) / sizeof (speedtab[0]);
2389354STim.Marsland@Sun.COM
2390Sstevel@tonic-gate static dacf_op_t kbconfig_op[] = {
2400Sstevel@tonic-gate { DACF_OPID_POSTATTACH, kb_config },
2410Sstevel@tonic-gate { DACF_OPID_PREDETACH, kb_unconfig },
2420Sstevel@tonic-gate { DACF_OPID_END, NULL },
2430Sstevel@tonic-gate };
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate static dacf_op_t msconfig_op[] = {
2460Sstevel@tonic-gate { DACF_OPID_POSTATTACH, ms_config },
2470Sstevel@tonic-gate { DACF_OPID_PREDETACH, ms_unconfig },
2480Sstevel@tonic-gate { DACF_OPID_END, NULL },
2490Sstevel@tonic-gate };
2500Sstevel@tonic-gate
2510Sstevel@tonic-gate static dacf_opset_t opsets[] = {
2520Sstevel@tonic-gate { "kb_config", kbconfig_op },
2530Sstevel@tonic-gate { "ms_config", msconfig_op },
2540Sstevel@tonic-gate { NULL, NULL }
2550Sstevel@tonic-gate };
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate struct dacfsw dacfsw = {
2580Sstevel@tonic-gate DACF_MODREV_1,
2590Sstevel@tonic-gate opsets,
2600Sstevel@tonic-gate };
2610Sstevel@tonic-gate
2627767SJohn.Beck@Sun.COM static struct modldacf modldacf = {
2630Sstevel@tonic-gate &mod_dacfops, /* Type of module */
2647335SLipeng.Sang@Sun.COM "Consconfig DACF",
2650Sstevel@tonic-gate &dacfsw
2660Sstevel@tonic-gate };
2670Sstevel@tonic-gate
2687767SJohn.Beck@Sun.COM static struct modlinkage modlinkage = {
2690Sstevel@tonic-gate MODREV_1, (void *)&modldacf, NULL
2700Sstevel@tonic-gate };
2710Sstevel@tonic-gate
2720Sstevel@tonic-gate int
_init(void)2730Sstevel@tonic-gate _init(void) {
2740Sstevel@tonic-gate return (mod_install(&modlinkage));
2750Sstevel@tonic-gate }
2760Sstevel@tonic-gate
2770Sstevel@tonic-gate int
_fini(void)2780Sstevel@tonic-gate _fini(void)
2790Sstevel@tonic-gate {
2800Sstevel@tonic-gate /*
2810Sstevel@tonic-gate * This modules state is held in the kernel by space.c
2820Sstevel@tonic-gate * allowing this module to be unloaded.
2830Sstevel@tonic-gate */
2840Sstevel@tonic-gate return (mod_remove(&modlinkage));
2850Sstevel@tonic-gate }
2860Sstevel@tonic-gate
2870Sstevel@tonic-gate int
_info(struct modinfo * modinfop)2880Sstevel@tonic-gate _info(struct modinfo *modinfop)
2890Sstevel@tonic-gate {
2900Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
2910Sstevel@tonic-gate }
2920Sstevel@tonic-gate
2930Sstevel@tonic-gate /*PRINTFLIKE2*/
2940Sstevel@tonic-gate static void consconfig_dprintf(int, const char *, ...)
2950Sstevel@tonic-gate __KPRINTFLIKE(2);
2960Sstevel@tonic-gate
2970Sstevel@tonic-gate static void
consconfig_dprintf(int l,const char * fmt,...)2980Sstevel@tonic-gate consconfig_dprintf(int l, const char *fmt, ...)
2990Sstevel@tonic-gate {
3000Sstevel@tonic-gate va_list ap;
3010Sstevel@tonic-gate
3020Sstevel@tonic-gate #ifndef DEBUG
3030Sstevel@tonic-gate if (!l) {
3040Sstevel@tonic-gate return;
3050Sstevel@tonic-gate }
3061253Slq150181 #endif /* DEBUG */
3070Sstevel@tonic-gate if (l < consconfig_errlevel) {
3080Sstevel@tonic-gate return;
3090Sstevel@tonic-gate }
3100Sstevel@tonic-gate
3110Sstevel@tonic-gate va_start(ap, fmt);
3120Sstevel@tonic-gate (void) vprintf(fmt, ap);
3130Sstevel@tonic-gate va_end(ap);
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate /*
3176128Sedp * Return a property value for the specified alias in /aliases.
3180Sstevel@tonic-gate */
3190Sstevel@tonic-gate char *
get_alias(char * alias,char * buf)3200Sstevel@tonic-gate get_alias(char *alias, char *buf)
3210Sstevel@tonic-gate {
322789Sahrens pnode_t node;
3236128Sedp int len;
3240Sstevel@tonic-gate
3256128Sedp /* The /aliases node only exists in OBP >= 2.4. */
3260Sstevel@tonic-gate if ((node = prom_alias_node()) == OBP_BADNODE)
3270Sstevel@tonic-gate return (NULL);
3280Sstevel@tonic-gate
3296128Sedp if ((len = prom_getproplen(node, (caddr_t)alias)) <= 0)
3300Sstevel@tonic-gate return (NULL);
3310Sstevel@tonic-gate
3320Sstevel@tonic-gate (void) prom_getprop(node, (caddr_t)alias, (caddr_t)buf);
3336128Sedp
3346128Sedp /*
3356128Sedp * The IEEE 1275 standard specifies that /aliases string property
3366128Sedp * values should be null-terminated. Unfortunatly the reality
3376128Sedp * is that most aren't and the OBP can't easily be modified to
3386128Sedp * add null termination to these strings. So we'll add the
3396128Sedp * null termination here. If the string already contains a
3406128Sedp * null termination character then that's ok too because we'll
3416128Sedp * just be adding a second one.
3426128Sedp */
3436128Sedp buf[len] = '\0';
3446128Sedp
3450Sstevel@tonic-gate prom_pathname(buf);
3460Sstevel@tonic-gate return (buf);
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate /*
3500Sstevel@tonic-gate * i_consconfig_createvp:
3510Sstevel@tonic-gate * This routine is a convenience routine that is passed a path and returns
3520Sstevel@tonic-gate * a vnode.
3530Sstevel@tonic-gate */
3540Sstevel@tonic-gate static vnode_t *
i_consconfig_createvp(char * path)3550Sstevel@tonic-gate i_consconfig_createvp(char *path)
3560Sstevel@tonic-gate {
3570Sstevel@tonic-gate int error;
3580Sstevel@tonic-gate vnode_t *vp;
3590Sstevel@tonic-gate char *buf = NULL, *fullpath;
3600Sstevel@tonic-gate
3610Sstevel@tonic-gate DPRINTF(DPRINT_L0, "i_consconfig_createvp: %s\n", path);
3620Sstevel@tonic-gate fullpath = kmem_alloc(MAXPATHLEN, KM_SLEEP);
3630Sstevel@tonic-gate
3640Sstevel@tonic-gate if (strchr(path, ':') == NULL) {
3650Sstevel@tonic-gate /* convert an OBP path to a /devices path */
3660Sstevel@tonic-gate buf = kmem_alloc(MAXPATHLEN, KM_SLEEP);
3670Sstevel@tonic-gate if (i_ddi_prompath_to_devfspath(path, buf) != DDI_SUCCESS) {
3680Sstevel@tonic-gate kmem_free(buf, MAXPATHLEN);
3690Sstevel@tonic-gate kmem_free(fullpath, MAXPATHLEN);
3700Sstevel@tonic-gate return (NULL);
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate (void) snprintf(fullpath, MAXPATHLEN, "/devices%s", buf);
3730Sstevel@tonic-gate kmem_free(buf, MAXPATHLEN);
3740Sstevel@tonic-gate } else {
3750Sstevel@tonic-gate /* convert a devfs path to a /devices path */
3760Sstevel@tonic-gate (void) snprintf(fullpath, MAXPATHLEN, "/devices%s", path);
3770Sstevel@tonic-gate }
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate DPRINTF(DPRINT_L0, "lookupname(%s)\n", fullpath);
3800Sstevel@tonic-gate error = lookupname(fullpath, UIO_SYSSPACE, FOLLOW, NULLVPP, &vp);
3810Sstevel@tonic-gate kmem_free(fullpath, MAXPATHLEN);
3820Sstevel@tonic-gate if (error)
3830Sstevel@tonic-gate return (NULL);
3840Sstevel@tonic-gate
3850Sstevel@tonic-gate DPRINTF(DPRINT_L0, "create vnode = 0x%p - dev 0x%lx\n", vp, vp->v_rdev);
3860Sstevel@tonic-gate ASSERT(vn_matchops(vp, spec_getvnodeops()));
3870Sstevel@tonic-gate
3880Sstevel@tonic-gate return (vp);
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate
3910Sstevel@tonic-gate /*
3920Sstevel@tonic-gate * consconfig_print_paths:
3930Sstevel@tonic-gate * Function to print out the various paths
3940Sstevel@tonic-gate */
3950Sstevel@tonic-gate static void
consconfig_print_paths(void)3960Sstevel@tonic-gate consconfig_print_paths(void)
3970Sstevel@tonic-gate {
3980Sstevel@tonic-gate char *path;
3990Sstevel@tonic-gate
4000Sstevel@tonic-gate if (usb_kb_path != NULL)
4010Sstevel@tonic-gate cmn_err(CE_WARN,
4020Sstevel@tonic-gate "consconfig_dacf:usb_kb_path has been deprecated, "
4030Sstevel@tonic-gate "use consconfig:usb_kb_path instead");
4040Sstevel@tonic-gate
4050Sstevel@tonic-gate if (usb_ms_path != NULL)
4060Sstevel@tonic-gate cmn_err(CE_WARN,
4070Sstevel@tonic-gate "consconfig_dacf:usb_ms_path has been deprecated, "
4080Sstevel@tonic-gate "use consconfig:usb_ms_path instead");
4090Sstevel@tonic-gate
4100Sstevel@tonic-gate if (consconfig_errlevel > DPRINT_L0)
4110Sstevel@tonic-gate return;
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate path = NULL;
4140Sstevel@tonic-gate if (consconfig_usb_kb_path != NULL)
4150Sstevel@tonic-gate path = consconfig_usb_kb_path;
4160Sstevel@tonic-gate else if (usb_kb_path != NULL)
4170Sstevel@tonic-gate path = usb_kb_path;
4180Sstevel@tonic-gate if (path != NULL)
4190Sstevel@tonic-gate DPRINTF(DPRINT_L0, "usb keyboard path = %s\n", path);
4200Sstevel@tonic-gate
4210Sstevel@tonic-gate path = plat_kbdpath();
4220Sstevel@tonic-gate if (path != NULL)
4230Sstevel@tonic-gate DPRINTF(DPRINT_L0, "keyboard path = %s\n", path);
4240Sstevel@tonic-gate
4250Sstevel@tonic-gate path = NULL;
4260Sstevel@tonic-gate if (consconfig_usb_ms_path != NULL)
4270Sstevel@tonic-gate path = consconfig_usb_ms_path;
4280Sstevel@tonic-gate else if (usb_ms_path != NULL)
4290Sstevel@tonic-gate path = usb_ms_path;
4300Sstevel@tonic-gate if (path != NULL)
4310Sstevel@tonic-gate DPRINTF(DPRINT_L0, "usb mouse path = %s\n", path);
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate path = plat_mousepath();
4340Sstevel@tonic-gate if (path != NULL)
4350Sstevel@tonic-gate DPRINTF(DPRINT_L0, "mouse path = %s\n", path);
4360Sstevel@tonic-gate
4370Sstevel@tonic-gate path = plat_stdinpath();
4380Sstevel@tonic-gate if (path != NULL)
4390Sstevel@tonic-gate DPRINTF(DPRINT_L0, "stdin path = %s\n", path);
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate path = plat_stdoutpath();
4420Sstevel@tonic-gate if (path != NULL)
4430Sstevel@tonic-gate DPRINTF(DPRINT_L0, "stdout path = %s\n", path);
4440Sstevel@tonic-gate
4450Sstevel@tonic-gate path = plat_fbpath();
4460Sstevel@tonic-gate if (path != NULL)
4470Sstevel@tonic-gate DPRINTF(DPRINT_L0, "fb path = %s\n", path);
4480Sstevel@tonic-gate }
4490Sstevel@tonic-gate
4500Sstevel@tonic-gate /*
4510Sstevel@tonic-gate * consconfig_kbd_abort_enable:
4520Sstevel@tonic-gate * Send the CONSSETABORTENABLE ioctl to the lower layers. This ioctl
4530Sstevel@tonic-gate * will only be sent to the device if it is the console device.
4540Sstevel@tonic-gate * This ioctl tells the device to pay attention to abort sequences.
4550Sstevel@tonic-gate * In the case of kbtrans, this would tell the driver to pay attention
4560Sstevel@tonic-gate * to the two key abort sequences like STOP-A. In the case of the
4570Sstevel@tonic-gate * serial keyboard, it would be an abort sequence like a break.
4580Sstevel@tonic-gate */
4590Sstevel@tonic-gate static int
consconfig_kbd_abort_enable(ldi_handle_t lh)4600Sstevel@tonic-gate consconfig_kbd_abort_enable(ldi_handle_t lh)
4610Sstevel@tonic-gate {
4620Sstevel@tonic-gate int err, rval;
4630Sstevel@tonic-gate
4640Sstevel@tonic-gate DPRINTF(DPRINT_L0, "consconfig_kbd_abort_enable\n");
4650Sstevel@tonic-gate
4660Sstevel@tonic-gate err = ldi_ioctl(lh, CONSSETABORTENABLE, (uintptr_t)B_TRUE,
4670Sstevel@tonic-gate FKIOCTL, kcred, &rval);
4680Sstevel@tonic-gate return (err);
4690Sstevel@tonic-gate }
4700Sstevel@tonic-gate
4710Sstevel@tonic-gate /*
4720Sstevel@tonic-gate * consconfig_kbd_abort_disable:
4730Sstevel@tonic-gate * Send CONSSETABORTENABLE ioctl to lower layers. This ioctl
4740Sstevel@tonic-gate * will only be sent to the device if it is the console device.
4750Sstevel@tonic-gate * This ioctl tells the physical device to ignore abort sequences,
4760Sstevel@tonic-gate * and send the sequences up to virtual keyboard(conskbd) so that
4770Sstevel@tonic-gate * STOP and A (or F1 and A) can be combined.
4780Sstevel@tonic-gate */
4790Sstevel@tonic-gate static int
consconfig_kbd_abort_disable(ldi_handle_t lh)4800Sstevel@tonic-gate consconfig_kbd_abort_disable(ldi_handle_t lh)
4810Sstevel@tonic-gate {
4820Sstevel@tonic-gate int err, rval;
4830Sstevel@tonic-gate
4840Sstevel@tonic-gate DPRINTF(DPRINT_L0, "consconfig_kbd_abort_disable\n");
4850Sstevel@tonic-gate
4860Sstevel@tonic-gate err = ldi_ioctl(lh, CONSSETABORTENABLE, (uintptr_t)B_FALSE,
4870Sstevel@tonic-gate FKIOCTL, kcred, &rval);
4880Sstevel@tonic-gate return (err);
4890Sstevel@tonic-gate }
4900Sstevel@tonic-gate
4915974Sjm22469 #ifdef _HAVE_TEM_FIRMWARE
4925974Sjm22469 static int
consconfig_tem_supported(cons_state_t * sp)4935974Sjm22469 consconfig_tem_supported(cons_state_t *sp)
4945974Sjm22469 {
4955974Sjm22469 dev_t dev;
4965974Sjm22469 dev_info_t *dip;
4975974Sjm22469 int *int_array;
4985974Sjm22469 uint_t nint;
4995974Sjm22469 int rv = 0;
5005974Sjm22469
5017688SAaron.Zang@Sun.COM if (sp->cons_fb_path == NULL)
5027688SAaron.Zang@Sun.COM return (0);
5037688SAaron.Zang@Sun.COM
5045974Sjm22469 if ((dev = ddi_pathname_to_dev_t(sp->cons_fb_path)) == NODEV)
5055974Sjm22469 return (0); /* warning printed later by common code */
5065974Sjm22469
5075974Sjm22469 /*
5085974Sjm22469 * Here we hold the driver and check "tem-support" property.
5095974Sjm22469 * We're doing this with e_ddi_hold_devi_by_dev and
5105974Sjm22469 * ddi_prop_lookup_int_array without opening the driver since
5115974Sjm22469 * some video cards that don't support the kernel terminal
5125974Sjm22469 * emulator could hang or crash if opened too early during
5135974Sjm22469 * boot.
5145974Sjm22469 */
5155974Sjm22469 if ((dip = e_ddi_hold_devi_by_dev(dev, 0)) == NULL) {
5165974Sjm22469 cmn_err(CE_WARN, "consconfig: cannot hold fb dev %s",
5175974Sjm22469 sp->cons_fb_path);
5185974Sjm22469 return (0);
5195974Sjm22469 }
5205974Sjm22469
5215974Sjm22469 /*
5225974Sjm22469 * Check that the tem-support property exists AND that
5235974Sjm22469 * it is equal to 1.
5245974Sjm22469 */
5255974Sjm22469 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip,
5265974Sjm22469 DDI_PROP_DONTPASS, "tem-support", &int_array, &nint) ==
5275974Sjm22469 DDI_SUCCESS) {
5285974Sjm22469 if (nint > 0)
5295974Sjm22469 rv = int_array[0] == 1;
5305974Sjm22469 ddi_prop_free(int_array);
5315974Sjm22469 }
5325974Sjm22469
5335974Sjm22469 ddi_release_devi(dip);
5345974Sjm22469
5355974Sjm22469 return (rv);
5365974Sjm22469 }
5375974Sjm22469 #endif /* _HAVE_TEM_FIRMWARE */
5385974Sjm22469
5390Sstevel@tonic-gate /*
5400Sstevel@tonic-gate * consconfig_get_polledio:
5410Sstevel@tonic-gate * Query the console with the CONSPOLLEDIO ioctl.
5420Sstevel@tonic-gate * The polled I/O routines are used by debuggers to perform I/O while
5430Sstevel@tonic-gate * interrupts and normal kernel services are disabled.
5440Sstevel@tonic-gate */
5450Sstevel@tonic-gate static cons_polledio_t *
consconfig_get_polledio(ldi_handle_t lh)5460Sstevel@tonic-gate consconfig_get_polledio(ldi_handle_t lh)
5470Sstevel@tonic-gate {
5480Sstevel@tonic-gate int err, rval;
5490Sstevel@tonic-gate struct strioctl strioc;
5500Sstevel@tonic-gate cons_polledio_t *polled_io;
5510Sstevel@tonic-gate
5520Sstevel@tonic-gate /*
5530Sstevel@tonic-gate * Setup the ioctl to be sent down to the lower driver.
5540Sstevel@tonic-gate */
5550Sstevel@tonic-gate strioc.ic_cmd = CONSOPENPOLLEDIO;
5560Sstevel@tonic-gate strioc.ic_timout = INFTIM;
5570Sstevel@tonic-gate strioc.ic_len = sizeof (polled_io);
5580Sstevel@tonic-gate strioc.ic_dp = (char *)&polled_io;
5590Sstevel@tonic-gate
5600Sstevel@tonic-gate /*
5610Sstevel@tonic-gate * Send the ioctl to the driver. The ioctl will wait for
5620Sstevel@tonic-gate * the response to come back from wc. wc has already issued
5630Sstevel@tonic-gate * the CONSOPENPOLLEDIO to the lower layer driver.
5640Sstevel@tonic-gate */
5650Sstevel@tonic-gate err = ldi_ioctl(lh, I_STR, (intptr_t)&strioc, FKIOCTL, kcred, &rval);
5660Sstevel@tonic-gate
5670Sstevel@tonic-gate if (err != 0) {
5680Sstevel@tonic-gate /*
5690Sstevel@tonic-gate * If the lower driver does not support polled I/O, then
5700Sstevel@tonic-gate * return NULL. This will be the case if the driver does
5710Sstevel@tonic-gate * not handle polled I/O, or OBP is going to handle polled
5720Sstevel@tonic-gate * I/O for the device.
5730Sstevel@tonic-gate */
5740Sstevel@tonic-gate
5750Sstevel@tonic-gate return (NULL);
5760Sstevel@tonic-gate }
5770Sstevel@tonic-gate
5780Sstevel@tonic-gate /*
5790Sstevel@tonic-gate * Return the polled I/O structure.
5800Sstevel@tonic-gate */
5810Sstevel@tonic-gate return (polled_io);
5820Sstevel@tonic-gate }
5830Sstevel@tonic-gate
5840Sstevel@tonic-gate /*
5850Sstevel@tonic-gate * consconfig_setup_polledio:
5860Sstevel@tonic-gate * This routine does the setup work for polled I/O. First we get
5870Sstevel@tonic-gate * the polled_io structure from the lower layers
5880Sstevel@tonic-gate * and then we register the polled I/O
5890Sstevel@tonic-gate * callbacks with the debugger that will be using them.
5900Sstevel@tonic-gate */
5910Sstevel@tonic-gate static void
consconfig_setup_polledio(cons_state_t * sp,dev_t dev)5920Sstevel@tonic-gate consconfig_setup_polledio(cons_state_t *sp, dev_t dev)
5930Sstevel@tonic-gate {
5940Sstevel@tonic-gate cons_polledio_t *polled_io;
5950Sstevel@tonic-gate ldi_handle_t lh;
5960Sstevel@tonic-gate
5970Sstevel@tonic-gate DPRINTF(DPRINT_L0, "consconfig_setup_polledio: start\n");
5980Sstevel@tonic-gate
5990Sstevel@tonic-gate
6000Sstevel@tonic-gate if (ldi_open_by_dev(&dev, OTYP_CHR,
6010Sstevel@tonic-gate FREAD|FWRITE|FNOCTTY, kcred, &lh, sp->cons_li) != 0)
6020Sstevel@tonic-gate return;
6030Sstevel@tonic-gate
6040Sstevel@tonic-gate
6050Sstevel@tonic-gate /*
6060Sstevel@tonic-gate * Get the polled io routines so that we can use this
6070Sstevel@tonic-gate * device with the debuggers.
6080Sstevel@tonic-gate */
6090Sstevel@tonic-gate polled_io = consconfig_get_polledio(lh);
6100Sstevel@tonic-gate
6110Sstevel@tonic-gate /*
6120Sstevel@tonic-gate * If the get polledio failed, then we do not want to throw
6130Sstevel@tonic-gate * the polled I/O switch.
6140Sstevel@tonic-gate */
6150Sstevel@tonic-gate if (polled_io == NULL) {
6160Sstevel@tonic-gate DPRINTF(DPRINT_L0,
6170Sstevel@tonic-gate "consconfig_setup_polledio: get_polledio failed\n");
6180Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, kcred);
6190Sstevel@tonic-gate return;
6200Sstevel@tonic-gate }
6210Sstevel@tonic-gate
6220Sstevel@tonic-gate /* Initialize the polled input */
6230Sstevel@tonic-gate polled_io_init();
6240Sstevel@tonic-gate
6250Sstevel@tonic-gate /* Register the callbacks */
6260Sstevel@tonic-gate DPRINTF(DPRINT_L0,
6270Sstevel@tonic-gate "consconfig_setup_polledio: registering callbacks\n");
6280Sstevel@tonic-gate (void) polled_io_register_callbacks(polled_io, 0);
6290Sstevel@tonic-gate
6300Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, kcred);
6310Sstevel@tonic-gate
6320Sstevel@tonic-gate DPRINTF(DPRINT_L0, "consconfig_setup_polledio: end\n");
6330Sstevel@tonic-gate }
6340Sstevel@tonic-gate
6350Sstevel@tonic-gate static cons_state_t *
consconfig_state_init(void)6360Sstevel@tonic-gate consconfig_state_init(void)
6370Sstevel@tonic-gate {
6380Sstevel@tonic-gate cons_state_t *sp;
6390Sstevel@tonic-gate int rval;
6400Sstevel@tonic-gate
6410Sstevel@tonic-gate /* Initialize console information */
6420Sstevel@tonic-gate sp = kmem_zalloc(sizeof (cons_state_t), KM_SLEEP);
6430Sstevel@tonic-gate sp->cons_keyboard_problem = B_FALSE;
6440Sstevel@tonic-gate
6450Sstevel@tonic-gate mutex_init(&sp->cons_lock, NULL, MUTEX_DRIVER, NULL);
6460Sstevel@tonic-gate
6470Sstevel@tonic-gate /* check if consconfig:usb_kb_path is set in /etc/system */
6480Sstevel@tonic-gate consconfig_usb_kb_path = consconfig_get_usb_kb_path();
6490Sstevel@tonic-gate
6500Sstevel@tonic-gate /* check if consconfig:usb_ms_path is set in /etc/system */
6510Sstevel@tonic-gate consconfig_usb_ms_path = consconfig_get_usb_ms_path();
6520Sstevel@tonic-gate
6530Sstevel@tonic-gate consconfig_print_paths();
6540Sstevel@tonic-gate
6550Sstevel@tonic-gate /* init external globals */
6560Sstevel@tonic-gate stdoutdev = NODEV;
6570Sstevel@tonic-gate
6580Sstevel@tonic-gate /*
6590Sstevel@tonic-gate * Find keyboard, mouse, stdin and stdout devices, if they
6600Sstevel@tonic-gate * exist on this platform.
6610Sstevel@tonic-gate */
6620Sstevel@tonic-gate
6630Sstevel@tonic-gate if (consconfig_usb_kb_path != NULL) {
6640Sstevel@tonic-gate sp->cons_keyboard_path = consconfig_usb_kb_path;
6650Sstevel@tonic-gate } else if (usb_kb_path != NULL) {
6660Sstevel@tonic-gate sp->cons_keyboard_path = usb_kb_path;
6670Sstevel@tonic-gate } else {
6680Sstevel@tonic-gate sp->cons_keyboard_path = plat_kbdpath();
6690Sstevel@tonic-gate }
6700Sstevel@tonic-gate
6710Sstevel@tonic-gate if (consconfig_usb_ms_path != NULL) {
6720Sstevel@tonic-gate sp->cons_mouse_path = consconfig_usb_ms_path;
6730Sstevel@tonic-gate } else if (usb_ms_path != NULL) {
6740Sstevel@tonic-gate sp->cons_mouse_path = usb_ms_path;
6750Sstevel@tonic-gate } else {
6760Sstevel@tonic-gate sp->cons_mouse_path = plat_mousepath();
6770Sstevel@tonic-gate }
6780Sstevel@tonic-gate
6790Sstevel@tonic-gate /* Identify the stdout driver */
6800Sstevel@tonic-gate sp->cons_stdout_path = plat_stdoutpath();
6815974Sjm22469 sp->cons_stdout_is_fb = plat_stdout_is_framebuffer();
6820Sstevel@tonic-gate
6835974Sjm22469 sp->cons_stdin_is_kbd = plat_stdin_is_keyboard();
6845974Sjm22469
6855974Sjm22469 if (sp->cons_stdin_is_kbd &&
686539Sry162471 (usb_kb_path != NULL || consconfig_usb_kb_path != NULL)) {
6870Sstevel@tonic-gate sp->cons_stdin_path = sp->cons_keyboard_path;
6880Sstevel@tonic-gate } else {
6890Sstevel@tonic-gate /*
6900Sstevel@tonic-gate * The standard in device may or may not be the same as
6910Sstevel@tonic-gate * the keyboard. Even if the keyboard is not the
6920Sstevel@tonic-gate * standard input, the keyboard console stream will
6930Sstevel@tonic-gate * still be built if the keyboard alias provided by the
6940Sstevel@tonic-gate * firmware exists and is valid.
6950Sstevel@tonic-gate */
6960Sstevel@tonic-gate sp->cons_stdin_path = plat_stdinpath();
6970Sstevel@tonic-gate }
6980Sstevel@tonic-gate
6995974Sjm22469 if (sp->cons_stdout_is_fb) {
7005974Sjm22469 sp->cons_fb_path = sp->cons_stdout_path;
7015974Sjm22469
7025974Sjm22469 #ifdef _HAVE_TEM_FIRMWARE
7035974Sjm22469 sp->cons_tem_supported = consconfig_tem_supported(sp);
7045974Sjm22469
7055974Sjm22469 /*
7065974Sjm22469 * Systems which offer a virtual console must use that
7075974Sjm22469 * as a fallback whenever the fb doesn't support tem.
7085974Sjm22469 * Such systems cannot render characters to the screen
7095974Sjm22469 * using OBP.
7105974Sjm22469 */
7115974Sjm22469 if (!sp->cons_tem_supported) {
7125974Sjm22469 char *path;
7135974Sjm22469
7145974Sjm22469 if (plat_virtual_console_path(&path) >= 0) {
7155974Sjm22469 sp->cons_stdin_is_kbd = 0;
7165974Sjm22469 sp->cons_stdout_is_fb = 0;
7175974Sjm22469 sp->cons_stdin_path = path;
7185974Sjm22469 sp->cons_stdout_path = path;
7195974Sjm22469 sp->cons_fb_path = plat_fbpath();
7205974Sjm22469
7215974Sjm22469 cmn_err(CE_WARN,
7225974Sjm22469 "%s doesn't support terminal emulation "
7235974Sjm22469 "mode; switching to virtual console.",
7245974Sjm22469 sp->cons_fb_path);
7255974Sjm22469 }
7265974Sjm22469 }
7275974Sjm22469 #endif /* _HAVE_TEM_FIRMWARE */
7285974Sjm22469 } else {
7295974Sjm22469 sp->cons_fb_path = plat_fbpath();
7307688SAaron.Zang@Sun.COM #ifdef _HAVE_TEM_FIRMWARE
7317688SAaron.Zang@Sun.COM sp->cons_tem_supported = consconfig_tem_supported(sp);
7327688SAaron.Zang@Sun.COM #endif /* _HAVE_TEM_FIRMWARE */
7335974Sjm22469 }
7345974Sjm22469
7350Sstevel@tonic-gate sp->cons_li = ldi_ident_from_anon();
7360Sstevel@tonic-gate
7370Sstevel@tonic-gate /* Save the pointer for retrieval by the dacf functions */
7380Sstevel@tonic-gate rval = space_store("consconfig", (uintptr_t)sp);
7390Sstevel@tonic-gate ASSERT(rval == 0);
7400Sstevel@tonic-gate
7410Sstevel@tonic-gate return (sp);
7420Sstevel@tonic-gate }
7430Sstevel@tonic-gate
7440Sstevel@tonic-gate static int
consconfig_relink_wc(cons_state_t * sp,ldi_handle_t new_lh,int * muxid)7450Sstevel@tonic-gate consconfig_relink_wc(cons_state_t *sp, ldi_handle_t new_lh, int *muxid)
7460Sstevel@tonic-gate {
7470Sstevel@tonic-gate int err, rval;
7480Sstevel@tonic-gate ldi_handle_t wc_lh;
7490Sstevel@tonic-gate dev_t wc_dev;
7500Sstevel@tonic-gate
7510Sstevel@tonic-gate ASSERT(muxid != NULL);
7520Sstevel@tonic-gate
7530Sstevel@tonic-gate /*
7540Sstevel@tonic-gate * NOTE: we could be in a dacf callback context right now. normally
7550Sstevel@tonic-gate * it's not legal to call any ldi_open_*() function from this context
7560Sstevel@tonic-gate * because we're currently holding device tree locks and if the
7570Sstevel@tonic-gate * ldi_open_*() call could try to acquire other device tree locks
7580Sstevel@tonic-gate * (to attach the device we're trying to open.) if this happens then
7590Sstevel@tonic-gate * we could deadlock. To avoid this situation, during initialization
7600Sstevel@tonic-gate * we made sure to grab a hold on the dip of the device we plan to
7610Sstevel@tonic-gate * open so that it can never be detached. Then we use
7620Sstevel@tonic-gate * ldi_open_by_dev() to actually open the device since it will see
7630Sstevel@tonic-gate * that the device is already attached and held and instead of
7640Sstevel@tonic-gate * acquire any locks it will only increase the reference count
7650Sstevel@tonic-gate * on the device.
7660Sstevel@tonic-gate */
7670Sstevel@tonic-gate wc_dev = sp->cons_wc_vp->v_rdev;
7680Sstevel@tonic-gate err = ldi_open_by_dev(&wc_dev, OTYP_CHR, FREAD|FWRITE|FNOCTTY,
7690Sstevel@tonic-gate kcred, &wc_lh, sp->cons_li);
7700Sstevel@tonic-gate ASSERT(wc_dev == sp->cons_wc_vp->v_rdev);
7710Sstevel@tonic-gate if (err) {
7720Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_relink_wc: "
7730Sstevel@tonic-gate "unable to open wc device");
7740Sstevel@tonic-gate return (err);
7750Sstevel@tonic-gate }
7760Sstevel@tonic-gate
7770Sstevel@tonic-gate if (new_lh != NULL) {
7780Sstevel@tonic-gate DPRINTF(DPRINT_L0, "linking stream under wc\n");
7790Sstevel@tonic-gate
7800Sstevel@tonic-gate err = ldi_ioctl(wc_lh, I_PLINK, (uintptr_t)new_lh,
7810Sstevel@tonic-gate FKIOCTL, kcred, muxid);
7820Sstevel@tonic-gate if (err != 0) {
7830Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_relink_wc: "
7840Sstevel@tonic-gate "wc link failed, error %d", err);
7850Sstevel@tonic-gate }
7860Sstevel@tonic-gate } else {
7870Sstevel@tonic-gate DPRINTF(DPRINT_L0, "unlinking stream from under wc\n");
7880Sstevel@tonic-gate
7890Sstevel@tonic-gate err = ldi_ioctl(wc_lh, I_PUNLINK, *muxid,
7900Sstevel@tonic-gate FKIOCTL, kcred, &rval);
7910Sstevel@tonic-gate if (err != 0) {
7920Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_relink_wc: "
7930Sstevel@tonic-gate "wc unlink failed, error %d", err);
7940Sstevel@tonic-gate } else {
7950Sstevel@tonic-gate *muxid = -1;
7960Sstevel@tonic-gate }
7970Sstevel@tonic-gate }
7980Sstevel@tonic-gate
7990Sstevel@tonic-gate (void) ldi_close(wc_lh, FREAD|FWRITE, kcred);
8000Sstevel@tonic-gate return (err);
8010Sstevel@tonic-gate }
8020Sstevel@tonic-gate
8030Sstevel@tonic-gate static void
cons_build_upper_layer(cons_state_t * sp)8040Sstevel@tonic-gate cons_build_upper_layer(cons_state_t *sp)
8050Sstevel@tonic-gate {
8061253Slq150181 ldi_handle_t wc_lh;
8071253Slq150181 struct strioctl strioc;
8081253Slq150181 int rval;
8095974Sjm22469 dev_t dev;
8101253Slq150181 dev_t wc_dev;
8111253Slq150181
8120Sstevel@tonic-gate /*
8130Sstevel@tonic-gate * Build the wc->conskbd portion of the keyboard console stream.
8140Sstevel@tonic-gate * Even if no keyboard is attached to the system, the upper
8150Sstevel@tonic-gate * layer of the stream will be built. If the user attaches
8160Sstevel@tonic-gate * a keyboard after the system is booted, the keyboard driver
8170Sstevel@tonic-gate * and module will be linked under conskbd.
8180Sstevel@tonic-gate *
8190Sstevel@tonic-gate * Errors are generally ignored here because conskbd and wc
8200Sstevel@tonic-gate * are pseudo drivers and should be present on the system.
8210Sstevel@tonic-gate */
8220Sstevel@tonic-gate
8230Sstevel@tonic-gate /* open the console keyboard device. will never be closed */
8243446Smrj if (ldi_open_by_name(CONSKBD_PATH, FREAD|FWRITE|FNOCTTY,
8253446Smrj kcred, &sp->conskbd_lh, sp->cons_li) != 0) {
8263446Smrj panic("consconfig: unable to open conskbd device");
8273446Smrj /*NOTREACHED*/
8283446Smrj }
8290Sstevel@tonic-gate
8300Sstevel@tonic-gate DPRINTF(DPRINT_L0, "conskbd_lh = %p\n", sp->conskbd_lh);
8310Sstevel@tonic-gate
8320Sstevel@tonic-gate /* open the console mouse device. will never be closed */
8333446Smrj if (ldi_open_by_name(CONSMS_PATH, FREAD|FWRITE|FNOCTTY,
8343446Smrj kcred, &sp->consms_lh, sp->cons_li) != 0) {
8353446Smrj panic("consconfig: unable to open consms device");
8363446Smrj /*NOTREACHED*/
8373446Smrj }
8380Sstevel@tonic-gate
8390Sstevel@tonic-gate DPRINTF(DPRINT_L0, "consms_lh = %p\n", sp->consms_lh);
8400Sstevel@tonic-gate
8410Sstevel@tonic-gate /*
8420Sstevel@tonic-gate * Get a vnode for the wc device and then grab a hold on the
8430Sstevel@tonic-gate * device dip so it can never detach. We need to do this now
8440Sstevel@tonic-gate * because later we'll have to open the wc device in a context
8450Sstevel@tonic-gate * were it isn't safe to acquire any device tree locks (ie, during
8460Sstevel@tonic-gate * a dacf callback.)
8470Sstevel@tonic-gate */
8480Sstevel@tonic-gate sp->cons_wc_vp = i_consconfig_createvp(WC_PATH);
8490Sstevel@tonic-gate if (sp->cons_wc_vp == NULL)
8500Sstevel@tonic-gate panic("consconfig: unable to find wc device");
8510Sstevel@tonic-gate
8520Sstevel@tonic-gate if (e_ddi_hold_devi_by_dev(sp->cons_wc_vp->v_rdev, 0) == NULL)
8530Sstevel@tonic-gate panic("consconfig: unable to hold wc device");
8540Sstevel@tonic-gate
8550Sstevel@tonic-gate /*
8560Sstevel@tonic-gate * Build the wc->conskbd portion of the keyboard console stream.
8570Sstevel@tonic-gate * Even if no keyboard is attached to the system, the upper
8580Sstevel@tonic-gate * layer of the stream will be built. If the user attaches
8590Sstevel@tonic-gate * a keyboard after the system is booted, the keyboard driver
8600Sstevel@tonic-gate * and module will be linked under conskbd.
8610Sstevel@tonic-gate *
8620Sstevel@tonic-gate * The act of linking conskbd under wc will cause wc to
8630Sstevel@tonic-gate * query the lower layers about their polled I/O routines
8640Sstevel@tonic-gate * using CONSOPENPOLLEDIO. This will fail on this link because
8650Sstevel@tonic-gate * there is not a physical keyboard linked under conskbd.
8660Sstevel@tonic-gate *
8670Sstevel@tonic-gate * Since conskbd and wc are pseudo drivers, errors are
8680Sstevel@tonic-gate * generally ignored when linking and unlinking them.
8690Sstevel@tonic-gate */
8700Sstevel@tonic-gate (void) consconfig_relink_wc(sp, sp->conskbd_lh, &sp->conskbd_muxid);
8710Sstevel@tonic-gate
8720Sstevel@tonic-gate /*
8730Sstevel@tonic-gate * Get a vnode for the redirection device. (It has the
8740Sstevel@tonic-gate * connection to the workstation console device wired into it,
8750Sstevel@tonic-gate * so that it's not necessary to establish the connection
8760Sstevel@tonic-gate * here. If the redirection device is ever generalized to
8770Sstevel@tonic-gate * handle multiple client devices, it won't be able to
8780Sstevel@tonic-gate * establish the connection itself, and we'll have to do it
8790Sstevel@tonic-gate * here.)
8800Sstevel@tonic-gate */
8810Sstevel@tonic-gate wsconsvp = i_consconfig_createvp(IWSCN_PATH);
8823446Smrj if (wsconsvp == NULL) {
8833446Smrj panic("consconfig: unable to find iwscn device");
8843446Smrj /*NOTREACHED*/
8853446Smrj }
8860Sstevel@tonic-gate
8871253Slq150181 if (cons_tem_disable)
8881253Slq150181 return;
8891253Slq150181
8900Sstevel@tonic-gate if (sp->cons_fb_path == NULL) {
8913446Smrj #if defined(__x86)
8925974Sjm22469 if (sp->cons_stdout_is_fb)
8933446Smrj cmn_err(CE_WARN, "consconfig: no screen found");
8943446Smrj #endif
8951253Slq150181 return;
8961253Slq150181 }
8971253Slq150181
8981253Slq150181 /* make sure the frame buffer device exists */
8991253Slq150181 dev = ddi_pathname_to_dev_t(sp->cons_fb_path);
9001253Slq150181 if (dev == NODEV) {
9011253Slq150181 cmn_err(CE_WARN, "consconfig: "
9021253Slq150181 "cannot find driver for screen device %s",
9031253Slq150181 sp->cons_fb_path);
9040Sstevel@tonic-gate return;
9051253Slq150181 }
9060Sstevel@tonic-gate
9071253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
9081253Slq150181 /*
9095974Sjm22469 * If the underlying fb device doesn't support terminal emulation,
9105974Sjm22469 * we don't want to open the wc device (below) because it depends
9115974Sjm22469 * on features which aren't available (polled mode io).
9121253Slq150181 */
9135974Sjm22469 if (!sp->cons_tem_supported)
9141253Slq150181 return;
9151253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
9160Sstevel@tonic-gate
9171253Slq150181 /* tell wc to open the frame buffer device */
9181253Slq150181 wc_dev = sp->cons_wc_vp->v_rdev;
9191253Slq150181 if (ldi_open_by_dev(&wc_dev, OTYP_CHR, FREAD|FWRITE|FNOCTTY, kcred,
9201253Slq150181 &wc_lh, sp->cons_li)) {
9211253Slq150181 cmn_err(CE_PANIC, "cons_build_upper_layer: "
9221253Slq150181 "unable to open wc device");
9231253Slq150181 return;
9241253Slq150181 }
9251253Slq150181 ASSERT(wc_dev == sp->cons_wc_vp->v_rdev);
9260Sstevel@tonic-gate
9271253Slq150181 strioc.ic_cmd = WC_OPEN_FB;
9281253Slq150181 strioc.ic_timout = INFTIM;
9291253Slq150181 strioc.ic_len = strlen(sp->cons_fb_path) + 1;
9301253Slq150181 strioc.ic_dp = sp->cons_fb_path;
9310Sstevel@tonic-gate
9321253Slq150181 if (ldi_ioctl(wc_lh, I_STR, (intptr_t)&strioc,
9331253Slq150181 FKIOCTL, kcred, &rval) == 0)
9341253Slq150181 consmode = CONS_KFB;
9351253Slq150181 else
9361253Slq150181 cmn_err(CE_WARN,
9371253Slq150181 "consconfig: terminal emulator failed to initialize");
9381253Slq150181 (void) ldi_close(wc_lh, FREAD|FWRITE, kcred);
9390Sstevel@tonic-gate }
9400Sstevel@tonic-gate
9410Sstevel@tonic-gate static void
consconfig_load_drivers(cons_state_t * sp)9420Sstevel@tonic-gate consconfig_load_drivers(cons_state_t *sp)
9430Sstevel@tonic-gate {
9440Sstevel@tonic-gate /*
945*11585SVincent.Wang@Sun.COM * Calling ddi_pathname_to_dev_t may cause the USB Host Controller
946*11585SVincent.Wang@Sun.COM * drivers to be loaded. Here we make sure that EHCI is loaded
947*11585SVincent.Wang@Sun.COM * earlier than {U, O}HCI. The order here is important. As
948*11585SVincent.Wang@Sun.COM * we have observed many systems on which hangs occur if the
949*11585SVincent.Wang@Sun.COM * {U,O}HCI companion controllers take over control from the BIOS
950*11585SVincent.Wang@Sun.COM * before EHCI does. These hangs are also caused by BIOSes leaving
951*11585SVincent.Wang@Sun.COM * interrupt-on-port-change enabled in the ehci controller, so that
952*11585SVincent.Wang@Sun.COM * when uhci/ohci reset themselves, it induces a port change on
953*11585SVincent.Wang@Sun.COM * the ehci companion controller. Since there's no interrupt handler
954*11585SVincent.Wang@Sun.COM * installed at the time, the moment that interrupt is unmasked, an
955*11585SVincent.Wang@Sun.COM * interrupt storm will occur. All this is averted when ehci is
956*11585SVincent.Wang@Sun.COM * loaded first. And now you know..... the REST of the story.
957*11585SVincent.Wang@Sun.COM *
958*11585SVincent.Wang@Sun.COM * Regardless of platform, ehci needs to initialize first to avoid
959*11585SVincent.Wang@Sun.COM * unnecessary connects and disconnects on the companion controller
960*11585SVincent.Wang@Sun.COM * when ehci sets up the routing.
961*11585SVincent.Wang@Sun.COM */
962*11585SVincent.Wang@Sun.COM (void) ddi_hold_installed_driver(ddi_name_to_major("ehci"));
963*11585SVincent.Wang@Sun.COM (void) ddi_hold_installed_driver(ddi_name_to_major("uhci"));
964*11585SVincent.Wang@Sun.COM (void) ddi_hold_installed_driver(ddi_name_to_major("ohci"));
965*11585SVincent.Wang@Sun.COM
966*11585SVincent.Wang@Sun.COM /*
9670Sstevel@tonic-gate * The attaching of the drivers will cause the creation of the
9680Sstevel@tonic-gate * keyboard and mouse minor nodes, which will in turn trigger the
9690Sstevel@tonic-gate * dacf framework to call the keyboard and mouse configuration
9700Sstevel@tonic-gate * tasks. See PSARC/1998/212 for more details about the dacf
9710Sstevel@tonic-gate * framework.
9720Sstevel@tonic-gate *
9730Sstevel@tonic-gate * on sparc, when the console is ttya, zs0 is stdin/stdout, and zs1
9740Sstevel@tonic-gate * is kb/mouse. zs0 must be attached before zs1. The zs driver
9750Sstevel@tonic-gate * is written this way and the hardware may depend on this, too.
9760Sstevel@tonic-gate * It would be better to enforce this by attaching zs in sibling
9770Sstevel@tonic-gate * order with a driver property, such as ddi-attachall.
9780Sstevel@tonic-gate */
9790Sstevel@tonic-gate if (sp->cons_stdin_path != NULL)
9800Sstevel@tonic-gate stdindev = ddi_pathname_to_dev_t(sp->cons_stdin_path);
9810Sstevel@tonic-gate if (stdindev == NODEV) {
9820Sstevel@tonic-gate DPRINTF(DPRINT_L0,
9830Sstevel@tonic-gate "!fail to attach stdin: %s\n", sp->cons_stdin_path);
9840Sstevel@tonic-gate }
9850Sstevel@tonic-gate if (sp->cons_stdout_path != NULL)
9860Sstevel@tonic-gate stdoutdev = ddi_pathname_to_dev_t(sp->cons_stdout_path);
9870Sstevel@tonic-gate if (sp->cons_keyboard_path != NULL)
9880Sstevel@tonic-gate kbddev = ddi_pathname_to_dev_t(sp->cons_keyboard_path);
9890Sstevel@tonic-gate if (sp->cons_mouse_path != NULL)
9900Sstevel@tonic-gate mousedev = ddi_pathname_to_dev_t(sp->cons_mouse_path);
9913446Smrj
9923446Smrj /*
9933446Smrj * On x86, make sure the fb driver is loaded even if we don't use it
9943446Smrj * for the console. This will ensure that we create a /dev/fb link
9953446Smrj * which is required to start Xorg.
9963446Smrj */
9973446Smrj #if defined(__x86)
9983446Smrj if (sp->cons_fb_path != NULL)
9993446Smrj fbdev = ddi_pathname_to_dev_t(sp->cons_fb_path);
10003446Smrj #endif
10013446Smrj
10020Sstevel@tonic-gate DPRINTF(DPRINT_L0, "stdindev %lx, stdoutdev %lx, kbddev %lx, "
10030Sstevel@tonic-gate "mousedev %lx\n", stdindev, stdoutdev, kbddev, mousedev);
10040Sstevel@tonic-gate }
10050Sstevel@tonic-gate
100610064SJames.Anderson@Sun.COM #if !defined(__x86)
100710064SJames.Anderson@Sun.COM void
consconfig_virtual_console_vp(cons_state_t * sp)100810064SJames.Anderson@Sun.COM consconfig_virtual_console_vp(cons_state_t *sp)
100910064SJames.Anderson@Sun.COM {
101010064SJames.Anderson@Sun.COM char *virtual_cons_path;
101110064SJames.Anderson@Sun.COM
101210064SJames.Anderson@Sun.COM if (plat_virtual_console_path(&virtual_cons_path) < 0)
101310064SJames.Anderson@Sun.COM return;
101410064SJames.Anderson@Sun.COM
101510064SJames.Anderson@Sun.COM DPRINTF(DPRINT_L0, "consconfig_virtual_console_vp: "
101610064SJames.Anderson@Sun.COM "virtual console device path %s\n", virtual_cons_path);
101710064SJames.Anderson@Sun.COM
101810064SJames.Anderson@Sun.COM ASSERT(sp->cons_stdout_path != NULL);
101910064SJames.Anderson@Sun.COM if (strcmp(virtual_cons_path, sp->cons_stdout_path) == 0) {
102010064SJames.Anderson@Sun.COM /* virtual console already in use */
102110064SJames.Anderson@Sun.COM return;
102210064SJames.Anderson@Sun.COM }
102310064SJames.Anderson@Sun.COM
102410064SJames.Anderson@Sun.COM vsconsvp = i_consconfig_createvp(virtual_cons_path);
102510064SJames.Anderson@Sun.COM if (vsconsvp == NULL) {
102610064SJames.Anderson@Sun.COM cmn_err(CE_WARN, "consconfig_virtual_console_vp: "
102710064SJames.Anderson@Sun.COM "unable to find serial virtual console device %s",
102810064SJames.Anderson@Sun.COM virtual_cons_path);
102910064SJames.Anderson@Sun.COM return;
103010064SJames.Anderson@Sun.COM }
103110064SJames.Anderson@Sun.COM
103210064SJames.Anderson@Sun.COM (void) e_ddi_hold_devi_by_dev(vsconsvp->v_rdev, 0);
103310064SJames.Anderson@Sun.COM }
103410064SJames.Anderson@Sun.COM #endif
103510064SJames.Anderson@Sun.COM
10360Sstevel@tonic-gate static void
consconfig_init_framebuffer(cons_state_t * sp)10370Sstevel@tonic-gate consconfig_init_framebuffer(cons_state_t *sp)
10380Sstevel@tonic-gate {
10395974Sjm22469 if (!sp->cons_stdout_is_fb)
10400Sstevel@tonic-gate return;
10410Sstevel@tonic-gate
10420Sstevel@tonic-gate DPRINTF(DPRINT_L0, "stdout is framebuffer\n");
10430Sstevel@tonic-gate ASSERT(strcmp(sp->cons_fb_path, sp->cons_stdout_path) == 0);
10440Sstevel@tonic-gate
10450Sstevel@tonic-gate /*
10460Sstevel@tonic-gate * Console output is a framebuffer.
10470Sstevel@tonic-gate * Find the framebuffer driver if we can, and make
10480Sstevel@tonic-gate * ourselves a shadow vnode to track it with.
10490Sstevel@tonic-gate */
10500Sstevel@tonic-gate fbdev = stdoutdev;
10510Sstevel@tonic-gate if (fbdev == NODEV) {
10520Sstevel@tonic-gate DPRINTF(DPRINT_L3,
10530Sstevel@tonic-gate "Can't find driver for console framebuffer\n");
10540Sstevel@tonic-gate } else {
10550Sstevel@tonic-gate /* stdoutdev is valid, of fbvp should exist */
10560Sstevel@tonic-gate fbvp = i_consconfig_createvp(sp->cons_stdout_path);
10570Sstevel@tonic-gate if (fbvp == NULL) {
105810064SJames.Anderson@Sun.COM panic("consconfig_init_framebuffer: "
10590Sstevel@tonic-gate "unable to find frame buffer device");
10600Sstevel@tonic-gate /*NOTREACHED*/
10610Sstevel@tonic-gate }
10620Sstevel@tonic-gate ASSERT(fbvp->v_rdev == fbdev);
10630Sstevel@tonic-gate
10640Sstevel@tonic-gate /* console device is never released */
10650Sstevel@tonic-gate fbdip = e_ddi_hold_devi_by_dev(fbdev, 0);
10660Sstevel@tonic-gate }
10670Sstevel@tonic-gate pm_cfb_setup(sp->cons_stdout_path);
10680Sstevel@tonic-gate }
10690Sstevel@tonic-gate
10700Sstevel@tonic-gate /*
10710Sstevel@tonic-gate * consconfig_prepare_dev:
10720Sstevel@tonic-gate * Flush the stream, push "pushmod" onto the stream.
10730Sstevel@tonic-gate * for keyboard, issue the KIOCTRANSABLE ioctl, and
10740Sstevel@tonic-gate * possible enable abort.
10750Sstevel@tonic-gate */
10760Sstevel@tonic-gate static void
consconfig_prepare_dev(ldi_handle_t new_lh,const char * pushmod,int kbdtranslatable,int input_type,int dev_type)10770Sstevel@tonic-gate consconfig_prepare_dev(
10780Sstevel@tonic-gate ldi_handle_t new_lh,
10790Sstevel@tonic-gate const char *pushmod,
10800Sstevel@tonic-gate int kbdtranslatable,
10810Sstevel@tonic-gate int input_type,
10820Sstevel@tonic-gate int dev_type)
10830Sstevel@tonic-gate {
10840Sstevel@tonic-gate int err, rval;
10850Sstevel@tonic-gate
10860Sstevel@tonic-gate /* send a flush down the stream to the keyboard driver */
10870Sstevel@tonic-gate (void) ldi_ioctl(new_lh, I_FLUSH, (intptr_t)FLUSHRW,
10880Sstevel@tonic-gate FKIOCTL, kcred, &rval);
10890Sstevel@tonic-gate
10900Sstevel@tonic-gate if (pushmod) {
10910Sstevel@tonic-gate err = ldi_ioctl(new_lh, I_PUSH, (intptr_t)pushmod,
10920Sstevel@tonic-gate FKIOCTL, kcred, &rval);
10930Sstevel@tonic-gate if (err) {
10940Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_prepare_dev: "
10950Sstevel@tonic-gate "can't push streams module \"%s\", error %d",
10960Sstevel@tonic-gate pushmod, err);
10970Sstevel@tonic-gate }
10980Sstevel@tonic-gate }
10990Sstevel@tonic-gate
11000Sstevel@tonic-gate if (dev_type == CONS_MS)
11010Sstevel@tonic-gate return;
11020Sstevel@tonic-gate
11030Sstevel@tonic-gate ASSERT(dev_type == CONS_KBD);
11040Sstevel@tonic-gate
11050Sstevel@tonic-gate err = ldi_ioctl(new_lh, KIOCTRANSABLE,
11060Sstevel@tonic-gate (intptr_t)&kbdtranslatable, FKIOCTL, kcred, &rval);
11070Sstevel@tonic-gate if (err) {
11080Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_prepare_dev: "
11090Sstevel@tonic-gate "KIOCTRANSABLE failed, error: %d", err);
11100Sstevel@tonic-gate }
11110Sstevel@tonic-gate
11120Sstevel@tonic-gate /*
11130Sstevel@tonic-gate * During boot, dynamic_console_config() will call the
11140Sstevel@tonic-gate * function to enable abort on the console. If the
11150Sstevel@tonic-gate * keyboard is hotplugged after boot, check to see if
11160Sstevel@tonic-gate * the keyboard is the console input. If it is
11170Sstevel@tonic-gate * enable abort on it.
11180Sstevel@tonic-gate */
11190Sstevel@tonic-gate if (input_type == CONSOLE_LOCAL)
11200Sstevel@tonic-gate (void) consconfig_kbd_abort_enable(new_lh);
11210Sstevel@tonic-gate }
11220Sstevel@tonic-gate
11230Sstevel@tonic-gate /*
11240Sstevel@tonic-gate * consconfig_relink_conskbd:
11250Sstevel@tonic-gate * If new_lh is not NULL it should represent a driver with a
11260Sstevel@tonic-gate * keyboard module pushed on top of it. The driver is then linked
11270Sstevel@tonic-gate * underneath conskbd. the resulting stream will be
11280Sstevel@tonic-gate * wc->conskbd->"new_lh driver".
11290Sstevel@tonic-gate *
11300Sstevel@tonic-gate * If new_lh is NULL, then an unlink operation is done on conskbd
11310Sstevel@tonic-gate * that attempts to unlink the stream specified by *muxid.
11320Sstevel@tonic-gate * the resulting stream will be wc->conskbd.
11330Sstevel@tonic-gate */
11340Sstevel@tonic-gate static int
consconfig_relink_conskbd(cons_state_t * sp,ldi_handle_t new_lh,int * muxid)11350Sstevel@tonic-gate consconfig_relink_conskbd(cons_state_t *sp, ldi_handle_t new_lh, int *muxid)
11360Sstevel@tonic-gate {
11370Sstevel@tonic-gate int err, rval;
11380Sstevel@tonic-gate int conskbd_relink = 0;
11390Sstevel@tonic-gate
11400Sstevel@tonic-gate ASSERT(muxid != NULL);
11410Sstevel@tonic-gate
11420Sstevel@tonic-gate DPRINTF(DPRINT_L0, "consconfig_relink_conskbd: "
11430Sstevel@tonic-gate "conskbd_lh = %p, new_lh = %p, muxid = %x\n",
11440Sstevel@tonic-gate sp->conskbd_lh, new_lh, *muxid);
11450Sstevel@tonic-gate
11460Sstevel@tonic-gate /*
11470Sstevel@tonic-gate * If conskbd is linked under wc then temporarily unlink it
11480Sstevel@tonic-gate * from under wc so that the new_lh stream may be linked under
11490Sstevel@tonic-gate * conskbd. This has to be done because streams are built bottom
11500Sstevel@tonic-gate * up and linking a stream under conskbd isn't allowed when
11510Sstevel@tonic-gate * conskbd is linked under wc.
11520Sstevel@tonic-gate */
11530Sstevel@tonic-gate if (sp->conskbd_muxid != -1) {
11540Sstevel@tonic-gate DPRINTF(DPRINT_L0, "unlinking conskbd from under wc\n");
11550Sstevel@tonic-gate conskbd_relink = 1;
11560Sstevel@tonic-gate err = consconfig_relink_wc(sp, NULL, &sp->conskbd_muxid);
11570Sstevel@tonic-gate if (err) {
11580Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_relink_conskbd: "
11590Sstevel@tonic-gate "wc unlink failed, error %d", err);
11600Sstevel@tonic-gate return (err);
11610Sstevel@tonic-gate }
11620Sstevel@tonic-gate }
11630Sstevel@tonic-gate
11640Sstevel@tonic-gate if (new_lh != NULL) {
11650Sstevel@tonic-gate DPRINTF(DPRINT_L0, "linking keyboard under conskbd\n");
11660Sstevel@tonic-gate
11670Sstevel@tonic-gate /* Link the stream represented by new_lh under conskbd */
11680Sstevel@tonic-gate err = ldi_ioctl(sp->conskbd_lh, I_PLINK, (uintptr_t)new_lh,
11696128Sedp FKIOCTL, kcred, muxid);
11700Sstevel@tonic-gate if (err != 0) {
11710Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_relink_conskbd: "
11720Sstevel@tonic-gate "conskbd link failed, error %d", err);
11730Sstevel@tonic-gate goto relink_failed;
11740Sstevel@tonic-gate }
11750Sstevel@tonic-gate } else {
11760Sstevel@tonic-gate DPRINTF(DPRINT_L0, "unlinking keyboard from under conskbd\n");
11770Sstevel@tonic-gate
11780Sstevel@tonic-gate /*
11790Sstevel@tonic-gate * This will cause the keyboard driver to be closed,
11800Sstevel@tonic-gate * all modules to be popped, and the keyboard vnode released.
11810Sstevel@tonic-gate */
11820Sstevel@tonic-gate err = ldi_ioctl(sp->conskbd_lh, I_PUNLINK, *muxid,
11836128Sedp FKIOCTL, kcred, &rval);
11840Sstevel@tonic-gate if (err != 0) {
11850Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_relink_conskbd: "
11860Sstevel@tonic-gate "conskbd unlink failed, error %d", err);
11870Sstevel@tonic-gate goto relink_failed;
11880Sstevel@tonic-gate } else {
11890Sstevel@tonic-gate *muxid = -1;
11900Sstevel@tonic-gate }
11910Sstevel@tonic-gate
11920Sstevel@tonic-gate consconfig_check_phys_kbd(sp);
11930Sstevel@tonic-gate }
11940Sstevel@tonic-gate
11950Sstevel@tonic-gate if (!conskbd_relink)
11960Sstevel@tonic-gate return (err);
11970Sstevel@tonic-gate
11980Sstevel@tonic-gate /*
11990Sstevel@tonic-gate * Link consbkd back under wc.
12000Sstevel@tonic-gate *
12010Sstevel@tonic-gate * The act of linking conskbd back under wc will cause wc
12020Sstevel@tonic-gate * to query the lower lower layers about their polled I/O
12030Sstevel@tonic-gate * routines. This time the request will succeed because there
12040Sstevel@tonic-gate * is a physical keyboard linked under conskbd.
12050Sstevel@tonic-gate */
12060Sstevel@tonic-gate DPRINTF(DPRINT_L0, "re-linking conskbd under wc\n");
12070Sstevel@tonic-gate err = consconfig_relink_wc(sp, sp->conskbd_lh, &sp->conskbd_muxid);
12080Sstevel@tonic-gate if (err) {
12090Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_relink_conskbd: "
12100Sstevel@tonic-gate "wc link failed, error %d", err);
12110Sstevel@tonic-gate }
12120Sstevel@tonic-gate return (err);
12130Sstevel@tonic-gate
12140Sstevel@tonic-gate relink_failed:
12150Sstevel@tonic-gate if (!conskbd_relink)
12160Sstevel@tonic-gate return (err);
12170Sstevel@tonic-gate
12180Sstevel@tonic-gate /* something went wrong, try to reconnect conskbd back under wc */
12190Sstevel@tonic-gate DPRINTF(DPRINT_L0, "re-linking conskbd under wc\n");
12200Sstevel@tonic-gate (void) consconfig_relink_wc(sp, sp->conskbd_lh, &sp->conskbd_muxid);
12210Sstevel@tonic-gate return (err);
12220Sstevel@tonic-gate }
12230Sstevel@tonic-gate
12240Sstevel@tonic-gate /*
12250Sstevel@tonic-gate * consconfig_relink_consms:
12260Sstevel@tonic-gate * If new_lh is not NULL it should represent a driver with a
12270Sstevel@tonic-gate * mouse module pushed on top of it. The driver is then linked
12280Sstevel@tonic-gate * underneath consms. the resulting stream will be
12290Sstevel@tonic-gate * consms->"new_lh driver".
12300Sstevel@tonic-gate *
12310Sstevel@tonic-gate * If new_lh is NULL, then an unlink operation is done on consms
12320Sstevel@tonic-gate * that attempts to unlink the stream specified by *muxid.
12330Sstevel@tonic-gate */
12340Sstevel@tonic-gate static int
consconfig_relink_consms(cons_state_t * sp,ldi_handle_t new_lh,int * muxid)12350Sstevel@tonic-gate consconfig_relink_consms(cons_state_t *sp, ldi_handle_t new_lh, int *muxid)
12360Sstevel@tonic-gate {
12370Sstevel@tonic-gate int err, rval;
12380Sstevel@tonic-gate
12390Sstevel@tonic-gate DPRINTF(DPRINT_L0, "consconfig_relink_consms: "
12400Sstevel@tonic-gate "consms_lh = %p, new_lh = %p, muxid = %x\n",
12410Sstevel@tonic-gate (void *)sp->consms_lh, (void *)new_lh, *muxid);
12420Sstevel@tonic-gate
12430Sstevel@tonic-gate if (new_lh != NULL) {
12440Sstevel@tonic-gate DPRINTF(DPRINT_L0, "linking mouse under consms\n");
12450Sstevel@tonic-gate
12460Sstevel@tonic-gate /* Link ms/usbms stream underneath consms multiplexor. */
12470Sstevel@tonic-gate err = ldi_ioctl(sp->consms_lh, I_PLINK, (uintptr_t)new_lh,
12480Sstevel@tonic-gate FKIOCTL, kcred, muxid);
12490Sstevel@tonic-gate if (err != 0) {
12500Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_relink_consms: "
12510Sstevel@tonic-gate "mouse link failed, error %d", err);
12520Sstevel@tonic-gate }
12530Sstevel@tonic-gate } else {
12540Sstevel@tonic-gate DPRINTF(DPRINT_L0, "unlinking mouse from under consms\n");
12550Sstevel@tonic-gate
12560Sstevel@tonic-gate /* Tear down the mouse stream */
12570Sstevel@tonic-gate err = ldi_ioctl(sp->consms_lh, I_PUNLINK, *muxid,
12580Sstevel@tonic-gate FKIOCTL, kcred, &rval);
12590Sstevel@tonic-gate if (err != 0) {
12600Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_relink_consms: "
12610Sstevel@tonic-gate "mouse unlink failed, error %d", err);
12620Sstevel@tonic-gate } else {
12630Sstevel@tonic-gate *muxid = -1;
12640Sstevel@tonic-gate }
12650Sstevel@tonic-gate }
12660Sstevel@tonic-gate return (err);
12670Sstevel@tonic-gate }
12680Sstevel@tonic-gate
12690Sstevel@tonic-gate static int
cons_get_input_type(cons_state_t * sp)12705974Sjm22469 cons_get_input_type(cons_state_t *sp)
12710Sstevel@tonic-gate {
12720Sstevel@tonic-gate int type;
12735974Sjm22469
12740Sstevel@tonic-gate /*
12750Sstevel@tonic-gate * Now that we know what all the devices are, we can figure out
12760Sstevel@tonic-gate * what kind of console we have.
12770Sstevel@tonic-gate */
12785974Sjm22469 if (sp->cons_stdin_is_kbd) {
12790Sstevel@tonic-gate /* Stdin is from the system keyboard */
12800Sstevel@tonic-gate type = CONSOLE_LOCAL;
12810Sstevel@tonic-gate } else if ((stdindev != NODEV) && (stdindev == stdoutdev)) {
12820Sstevel@tonic-gate /*
12830Sstevel@tonic-gate * A reliable indicator that we are doing a remote console
12840Sstevel@tonic-gate * is that stdin and stdout are the same.
12850Sstevel@tonic-gate * This is probably a tip line.
12860Sstevel@tonic-gate */
12870Sstevel@tonic-gate type = CONSOLE_TIP;
12880Sstevel@tonic-gate } else {
12890Sstevel@tonic-gate type = CONSOLE_SERIAL_KEYBOARD;
12900Sstevel@tonic-gate }
12910Sstevel@tonic-gate
12920Sstevel@tonic-gate return (type);
12930Sstevel@tonic-gate }
12940Sstevel@tonic-gate
12950Sstevel@tonic-gate static void
consconfig_init_input(cons_state_t * sp)12960Sstevel@tonic-gate consconfig_init_input(cons_state_t *sp)
12970Sstevel@tonic-gate {
12980Sstevel@tonic-gate ldi_handle_t new_lh;
12990Sstevel@tonic-gate dev_t cons_final_dev;
13000Sstevel@tonic-gate int err;
13010Sstevel@tonic-gate
13020Sstevel@tonic-gate cons_final_dev = NODEV;
13030Sstevel@tonic-gate
13040Sstevel@tonic-gate switch (sp->cons_input_type) {
13050Sstevel@tonic-gate case CONSOLE_LOCAL:
13060Sstevel@tonic-gate DPRINTF(DPRINT_L0, "stdin is keyboard\n");
13070Sstevel@tonic-gate
13080Sstevel@tonic-gate /*
13090Sstevel@tonic-gate * The machine is allowed to boot without a keyboard.
13100Sstevel@tonic-gate * If a user attaches a keyboard later, the keyboard
13110Sstevel@tonic-gate * will be hooked into the console stream with the dacf
13120Sstevel@tonic-gate * functions.
13130Sstevel@tonic-gate *
13140Sstevel@tonic-gate * The only drivers that look at kbbdev are the
13150Sstevel@tonic-gate * serial drivers, which looks at kbdev to see if
13160Sstevel@tonic-gate * they should allow abort on a break. In the absence
13170Sstevel@tonic-gate * of keyboard, the serial drivers won't be attached
13180Sstevel@tonic-gate * for any keyboard instance.
13190Sstevel@tonic-gate */
13200Sstevel@tonic-gate if (kbddev == NODEV) {
13210Sstevel@tonic-gate /*
13220Sstevel@tonic-gate * If there is a problem with the keyboard
13230Sstevel@tonic-gate * during the driver loading, then the polled
13240Sstevel@tonic-gate * input won't get setup properly if polled
13250Sstevel@tonic-gate * input is needed. This means that if the
13260Sstevel@tonic-gate * keyboard is hotplugged, the keyboard would
13270Sstevel@tonic-gate * work normally, but going down to the
13280Sstevel@tonic-gate * debugger would not work if polled input is
13290Sstevel@tonic-gate * required. This field is set here. The next
13300Sstevel@tonic-gate * time a keyboard is plugged in, the field is
13310Sstevel@tonic-gate * checked in order to give the next keyboard a
13320Sstevel@tonic-gate * chance at being registered for console
13330Sstevel@tonic-gate * input.
13340Sstevel@tonic-gate *
13350Sstevel@tonic-gate * Although this code will rarely be needed,
13360Sstevel@tonic-gate * USB keyboards can be flaky, so this code
13370Sstevel@tonic-gate * will be useful on the occasion that the
13380Sstevel@tonic-gate * keyboard doesn't enumerate when the drivers
13390Sstevel@tonic-gate * are loaded.
13400Sstevel@tonic-gate */
13410Sstevel@tonic-gate DPRINTF(DPRINT_L2, "Error with console keyboard\n");
13420Sstevel@tonic-gate sp->cons_keyboard_problem = B_TRUE;
13430Sstevel@tonic-gate }
13440Sstevel@tonic-gate stdindev = kbddev;
13450Sstevel@tonic-gate cons_final_dev = sp->cons_wc_vp->v_rdev;
13460Sstevel@tonic-gate break;
13470Sstevel@tonic-gate
13480Sstevel@tonic-gate case CONSOLE_TIP:
13490Sstevel@tonic-gate DPRINTF(DPRINT_L0, "console input is tty (%s)\n",
13500Sstevel@tonic-gate sp->cons_stdin_path);
13510Sstevel@tonic-gate
13520Sstevel@tonic-gate /*
13530Sstevel@tonic-gate * Console device drivers must be able to output
13540Sstevel@tonic-gate * after being closed.
13550Sstevel@tonic-gate */
13560Sstevel@tonic-gate rconsvp = i_consconfig_createvp(sp->cons_stdin_path);
13573446Smrj if (rconsvp == NULL) {
13583446Smrj panic("consconfig_init_input: "
13590Sstevel@tonic-gate "unable to find stdin device (%s)",
13600Sstevel@tonic-gate sp->cons_stdin_path);
13613446Smrj /*NOTREACHED*/
13623446Smrj }
13630Sstevel@tonic-gate rconsdev = rconsvp->v_rdev;
13640Sstevel@tonic-gate
13650Sstevel@tonic-gate ASSERT(rconsdev == stdindev);
13660Sstevel@tonic-gate
13670Sstevel@tonic-gate cons_final_dev = rconsdev;
13680Sstevel@tonic-gate break;
13690Sstevel@tonic-gate
13700Sstevel@tonic-gate case CONSOLE_SERIAL_KEYBOARD:
13710Sstevel@tonic-gate DPRINTF(DPRINT_L0, "stdin is serial keyboard\n");
13720Sstevel@tonic-gate
13730Sstevel@tonic-gate /*
13740Sstevel@tonic-gate * Non-keyboard input device, but not rconsdev.
13750Sstevel@tonic-gate * This is known as the "serial keyboard" case - the
13760Sstevel@tonic-gate * most likely use is someone has a keyboard attached
13770Sstevel@tonic-gate * to a serial port (tip) and still has output on a
13780Sstevel@tonic-gate * framebuffer.
13790Sstevel@tonic-gate *
13800Sstevel@tonic-gate * In this case, the serial driver must be linked
13810Sstevel@tonic-gate * directly beneath wc. Since conskbd was linked
13820Sstevel@tonic-gate * underneath wc above, first we unlink conskbd.
13830Sstevel@tonic-gate */
13840Sstevel@tonic-gate (void) consconfig_relink_wc(sp, NULL, &sp->conskbd_muxid);
13850Sstevel@tonic-gate sp->conskbd_muxid = -1;
13860Sstevel@tonic-gate
13870Sstevel@tonic-gate /*
13880Sstevel@tonic-gate * Open the serial keyboard, configure it,
13890Sstevel@tonic-gate * and link it underneath wc.
13900Sstevel@tonic-gate */
13910Sstevel@tonic-gate err = ldi_open_by_name(sp->cons_stdin_path,
13920Sstevel@tonic-gate FREAD|FWRITE|FNOCTTY, kcred, &new_lh, sp->cons_li);
13930Sstevel@tonic-gate if (err == 0) {
13940Sstevel@tonic-gate struct termios termios;
13950Sstevel@tonic-gate int rval;
13960Sstevel@tonic-gate int stdin_muxid;
13970Sstevel@tonic-gate
13980Sstevel@tonic-gate consconfig_prepare_dev(new_lh,
13990Sstevel@tonic-gate "kb", TR_CANNOT, sp->cons_input_type, CONS_KBD);
14000Sstevel@tonic-gate
14010Sstevel@tonic-gate /* Re-set baud rate */
14020Sstevel@tonic-gate (void) ldi_ioctl(new_lh, TCGETS, (intptr_t)&termios,
14036128Sedp FKIOCTL, kcred, &rval);
14040Sstevel@tonic-gate
14050Sstevel@tonic-gate /* Set baud rate */
14060Sstevel@tonic-gate if (consconfig_setmodes(stdindev, &termios) == 0) {
14070Sstevel@tonic-gate err = ldi_ioctl(new_lh,
14080Sstevel@tonic-gate TCSETSF, (intptr_t)&termios,
14090Sstevel@tonic-gate FKIOCTL, kcred, &rval);
14100Sstevel@tonic-gate if (err) {
14110Sstevel@tonic-gate cmn_err(CE_WARN,
14120Sstevel@tonic-gate "consconfig_init_input: "
14130Sstevel@tonic-gate "TCSETSF failed, error %d", err);
14140Sstevel@tonic-gate }
14150Sstevel@tonic-gate }
14160Sstevel@tonic-gate
14170Sstevel@tonic-gate /*
14180Sstevel@tonic-gate * Now link the serial keyboard direcly under wc
14190Sstevel@tonic-gate * we don't save the returned muxid because we
14200Sstevel@tonic-gate * don't support changing/hotplugging the console
14210Sstevel@tonic-gate * keyboard when it is a serial keyboard.
14220Sstevel@tonic-gate */
14230Sstevel@tonic-gate (void) consconfig_relink_wc(sp, new_lh, &stdin_muxid);
14240Sstevel@tonic-gate
14250Sstevel@tonic-gate (void) ldi_close(new_lh, FREAD|FWRITE, kcred);
14260Sstevel@tonic-gate }
14270Sstevel@tonic-gate
14280Sstevel@tonic-gate cons_final_dev = sp->cons_wc_vp->v_rdev;
14290Sstevel@tonic-gate break;
14300Sstevel@tonic-gate
14310Sstevel@tonic-gate default:
14320Sstevel@tonic-gate panic("consconfig_init_input: "
14330Sstevel@tonic-gate "unsupported console input/output combination");
14340Sstevel@tonic-gate /*NOTREACHED*/
14350Sstevel@tonic-gate }
14360Sstevel@tonic-gate
14370Sstevel@tonic-gate /*
14380Sstevel@tonic-gate * Use the redirection device/workstation console pair as the "real"
14390Sstevel@tonic-gate * console if the latter hasn't already been set.
14400Sstevel@tonic-gate * The workstation console driver needs to see rwsconsvp, but
14410Sstevel@tonic-gate * all other access should be through the redirecting driver.
14420Sstevel@tonic-gate */
14430Sstevel@tonic-gate if (rconsvp == NULL) {
14440Sstevel@tonic-gate consconfig_dprintf(DPRINT_L0, "setup redirection driver\n");
14450Sstevel@tonic-gate rconsvp = wsconsvp;
14460Sstevel@tonic-gate rconsdev = wsconsvp->v_rdev;
14470Sstevel@tonic-gate }
14480Sstevel@tonic-gate
14490Sstevel@tonic-gate ASSERT(cons_final_dev != NODEV);
14500Sstevel@tonic-gate
14510Sstevel@tonic-gate err = ldi_open_by_dev(&cons_final_dev, OTYP_CHR, FREAD|FWRITE|FNOCTTY,
14520Sstevel@tonic-gate kcred, &new_lh, sp->cons_li);
14530Sstevel@tonic-gate if (err) {
14540Sstevel@tonic-gate panic("consconfig_init_input: "
14550Sstevel@tonic-gate "unable to open console device");
14560Sstevel@tonic-gate /*NOTREACHED*/
14570Sstevel@tonic-gate }
14580Sstevel@tonic-gate
14590Sstevel@tonic-gate /* Enable abort on the console */
14600Sstevel@tonic-gate (void) consconfig_kbd_abort_enable(new_lh);
14610Sstevel@tonic-gate
14620Sstevel@tonic-gate /* Now we must close it to make console logins happy */
14630Sstevel@tonic-gate (void) ldi_close(new_lh, FREAD|FWRITE, kcred);
14640Sstevel@tonic-gate
14650Sstevel@tonic-gate /* Set up polled input if it is supported by the console device */
14660Sstevel@tonic-gate if (plat_use_polled_debug()) {
14670Sstevel@tonic-gate /*
14680Sstevel@tonic-gate * In the debug case, register the keyboard polled entry
14690Sstevel@tonic-gate * points, but don't throw the switch in the debugger. This
14700Sstevel@tonic-gate * allows the polled entry points to be checked by hand
14710Sstevel@tonic-gate */
14720Sstevel@tonic-gate consconfig_setup_polledio(sp, sp->cons_wc_vp->v_rdev);
14730Sstevel@tonic-gate } else {
14740Sstevel@tonic-gate consconfig_setup_polledio(sp, cons_final_dev);
14750Sstevel@tonic-gate }
14760Sstevel@tonic-gate
14770Sstevel@tonic-gate kadb_uses_kernel();
14780Sstevel@tonic-gate }
14790Sstevel@tonic-gate
14800Sstevel@tonic-gate /*
14810Sstevel@tonic-gate * This function kicks off the console configuration.
14820Sstevel@tonic-gate * Configure keyboard and mouse. Main entry here.
14830Sstevel@tonic-gate */
14840Sstevel@tonic-gate void
dynamic_console_config(void)14850Sstevel@tonic-gate dynamic_console_config(void)
14860Sstevel@tonic-gate {
14870Sstevel@tonic-gate /* initialize space.c globals */
14880Sstevel@tonic-gate stdindev = NODEV;
14890Sstevel@tonic-gate mousedev = NODEV;
14900Sstevel@tonic-gate kbddev = NODEV;
14910Sstevel@tonic-gate fbdev = NODEV;
14920Sstevel@tonic-gate fbvp = NULL;
14930Sstevel@tonic-gate fbdip = NULL;
14940Sstevel@tonic-gate wsconsvp = NULL;
14950Sstevel@tonic-gate rwsconsvp = NULL;
14960Sstevel@tonic-gate rwsconsdev = NODEV;
14970Sstevel@tonic-gate rconsvp = NULL;
14980Sstevel@tonic-gate rconsdev = NODEV;
14990Sstevel@tonic-gate
15000Sstevel@tonic-gate /* Initialize cons_state_t structure and console device paths */
15013446Smrj consconfig_sp = consconfig_state_init();
15023446Smrj ASSERT(consconfig_sp);
15030Sstevel@tonic-gate
15040Sstevel@tonic-gate /* Build upper layer of console stream */
15053446Smrj cons_build_upper_layer(consconfig_sp);
15060Sstevel@tonic-gate
15070Sstevel@tonic-gate /*
15080Sstevel@tonic-gate * Load keyboard/mouse drivers. The dacf routines will
15090Sstevel@tonic-gate * plumb the devices into the console stream
15100Sstevel@tonic-gate *
15110Sstevel@tonic-gate * At the conclusion of the ddi_pathname_to_dev_t calls, the keyboard
15120Sstevel@tonic-gate * and mouse drivers are linked into their respective console
15130Sstevel@tonic-gate * streams if the pathnames are valid.
15140Sstevel@tonic-gate */
15153446Smrj consconfig_load_drivers(consconfig_sp);
15165974Sjm22469 consconfig_sp->cons_input_type = cons_get_input_type(consconfig_sp);
15170Sstevel@tonic-gate
15180Sstevel@tonic-gate /*
15190Sstevel@tonic-gate * This is legacy special case code for the "cool" virtual console
15200Sstevel@tonic-gate * for the Starfire project. Starfire has a dummy "ssp-serial"
15210Sstevel@tonic-gate * node in the OBP device tree and cvc is a pseudo driver.
15220Sstevel@tonic-gate */
15233446Smrj if (consconfig_sp->cons_stdout_path != NULL && stdindev == NODEV &&
15243446Smrj strstr(consconfig_sp->cons_stdout_path, "ssp-serial")) {
15250Sstevel@tonic-gate /*
15260Sstevel@tonic-gate * Setup the virtual console driver for Starfire
15270Sstevel@tonic-gate * Note that console I/O will still go through prom for now
15280Sstevel@tonic-gate * (notice we don't open the driver here). The cvc driver
15290Sstevel@tonic-gate * will be activated when /dev/console is opened by init.
15300Sstevel@tonic-gate * During that time, a cvcd daemon will be started that
15310Sstevel@tonic-gate * will open the cvcredirection driver to facilitate
15320Sstevel@tonic-gate * the redirection of console I/O from cvc to cvcd.
15330Sstevel@tonic-gate */
15340Sstevel@tonic-gate rconsvp = i_consconfig_createvp(CVC_PATH);
15350Sstevel@tonic-gate if (rconsvp == NULL)
153610783SVincent.Wang@Sun.COM goto done;
15370Sstevel@tonic-gate rconsdev = rconsvp->v_rdev;
153810783SVincent.Wang@Sun.COM goto done;
15390Sstevel@tonic-gate }
15400Sstevel@tonic-gate
15413446Smrj rwsconsvp = consconfig_sp->cons_wc_vp;
15423446Smrj rwsconsdev = consconfig_sp->cons_wc_vp->v_rdev;
15430Sstevel@tonic-gate
15440Sstevel@tonic-gate
15450Sstevel@tonic-gate /* initialize framebuffer, console input, and redirection device */
15463446Smrj consconfig_init_framebuffer(consconfig_sp);
15473446Smrj consconfig_init_input(consconfig_sp);
15480Sstevel@tonic-gate
154910064SJames.Anderson@Sun.COM #if !defined(__x86)
155010064SJames.Anderson@Sun.COM /* initialize virtual console vp for logging if needed */
155110064SJames.Anderson@Sun.COM consconfig_virtual_console_vp(consconfig_sp);
155210064SJames.Anderson@Sun.COM #endif
155310064SJames.Anderson@Sun.COM
15540Sstevel@tonic-gate DPRINTF(DPRINT_L0,
15556128Sedp "mousedev %lx, kbddev %lx, fbdev %lx, rconsdev %lx\n",
15566128Sedp mousedev, kbddev, fbdev, rconsdev);
15572191Sszhou
15588960SJan.Setje-Eilers@Sun.COM flush_deferred_console_buf();
155910783SVincent.Wang@Sun.COM done:
156010783SVincent.Wang@Sun.COM consconfig_sp->cons_initialized = B_TRUE;
15610Sstevel@tonic-gate }
15620Sstevel@tonic-gate
15630Sstevel@tonic-gate
15640Sstevel@tonic-gate /*
15650Sstevel@tonic-gate * Start of DACF interfaces
15660Sstevel@tonic-gate */
15670Sstevel@tonic-gate
15680Sstevel@tonic-gate /*
15690Sstevel@tonic-gate * Do the real job for keyboard/mouse auto-configuration.
15700Sstevel@tonic-gate */
15710Sstevel@tonic-gate static int
do_config(cons_state_t * sp,cons_prop_t * prop)15720Sstevel@tonic-gate do_config(cons_state_t *sp, cons_prop_t *prop)
15730Sstevel@tonic-gate {
15740Sstevel@tonic-gate ldi_handle_t lh;
15750Sstevel@tonic-gate dev_t dev;
15760Sstevel@tonic-gate int error;
15770Sstevel@tonic-gate
15780Sstevel@tonic-gate ASSERT((prop->cp_type == CONS_KBD) || (prop->cp_type == CONS_MS));
15790Sstevel@tonic-gate
15800Sstevel@tonic-gate dev = prop->cp_dev;
15810Sstevel@tonic-gate error = ldi_open_by_dev(&dev, OTYP_CHR,
15820Sstevel@tonic-gate FREAD|FWRITE|FNOCTTY, kcred, &lh, sp->cons_li);
15830Sstevel@tonic-gate if (error) {
15840Sstevel@tonic-gate return (DACF_FAILURE);
15850Sstevel@tonic-gate }
15860Sstevel@tonic-gate ASSERT(dev == prop->cp_dev); /* clone not supported */
15870Sstevel@tonic-gate
15880Sstevel@tonic-gate /*
15890Sstevel@tonic-gate * Prepare the new keyboard/mouse driver
15900Sstevel@tonic-gate * to be linked under conskbd/consms.
15910Sstevel@tonic-gate */
15920Sstevel@tonic-gate consconfig_prepare_dev(lh, prop->cp_pushmod, TR_CAN,
15930Sstevel@tonic-gate sp->cons_input_type, prop->cp_type);
15940Sstevel@tonic-gate
15950Sstevel@tonic-gate if (prop->cp_type == CONS_KBD) {
15960Sstevel@tonic-gate /*
15970Sstevel@tonic-gate * Tell the physical keyboard driver to send
15980Sstevel@tonic-gate * the abort sequences up to the virtual keyboard
15990Sstevel@tonic-gate * driver so that STOP and A (or F1 and A)
16000Sstevel@tonic-gate * can be applied to different keyboards.
16010Sstevel@tonic-gate */
16020Sstevel@tonic-gate (void) consconfig_kbd_abort_disable(lh);
16030Sstevel@tonic-gate
16040Sstevel@tonic-gate /* Link the stream underneath conskbd */
16050Sstevel@tonic-gate error = consconfig_relink_conskbd(sp, lh, &prop->cp_muxid);
16060Sstevel@tonic-gate } else {
16070Sstevel@tonic-gate /* Link the stream underneath consms */
16080Sstevel@tonic-gate error = consconfig_relink_consms(sp, lh, &prop->cp_muxid);
16090Sstevel@tonic-gate }
16100Sstevel@tonic-gate
16110Sstevel@tonic-gate /*
16120Sstevel@tonic-gate * At this point, the stream is:
16130Sstevel@tonic-gate * for keyboard: wc->conskbd->["pushmod"->"kbd_vp driver"]
16140Sstevel@tonic-gate * for mouse: consms->["module_name"->]"mouse_avp driver"
16150Sstevel@tonic-gate */
16160Sstevel@tonic-gate
16170Sstevel@tonic-gate /* Close the driver stream, it will stay linked under conskbd */
16180Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, kcred);
16190Sstevel@tonic-gate
16200Sstevel@tonic-gate if (error) {
16210Sstevel@tonic-gate return (DACF_FAILURE);
16220Sstevel@tonic-gate }
16230Sstevel@tonic-gate
16240Sstevel@tonic-gate return (DACF_SUCCESS);
16250Sstevel@tonic-gate }
16260Sstevel@tonic-gate
16270Sstevel@tonic-gate static int
do_unconfig(cons_state_t * sp,cons_prop_t * prop)16280Sstevel@tonic-gate do_unconfig(cons_state_t *sp, cons_prop_t *prop)
16290Sstevel@tonic-gate {
16300Sstevel@tonic-gate ASSERT((prop->cp_type == CONS_KBD) || (prop->cp_type == CONS_MS));
16310Sstevel@tonic-gate
16320Sstevel@tonic-gate if (prop->cp_type == CONS_KBD)
16330Sstevel@tonic-gate return (consconfig_relink_conskbd(sp, NULL, &prop->cp_muxid));
16340Sstevel@tonic-gate else
16350Sstevel@tonic-gate return (consconfig_relink_consms(sp, NULL, &prop->cp_muxid));
16360Sstevel@tonic-gate }
16370Sstevel@tonic-gate
16380Sstevel@tonic-gate static int
kb_ms_config(dacf_infohdl_t minor_hdl,dacf_arghdl_t arg_hdl,int type)16390Sstevel@tonic-gate kb_ms_config(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int type)
16400Sstevel@tonic-gate {
16410Sstevel@tonic-gate major_t major;
16420Sstevel@tonic-gate minor_t minor;
16430Sstevel@tonic-gate dev_t dev;
16440Sstevel@tonic-gate dev_info_t *dip;
16450Sstevel@tonic-gate cons_state_t *sp;
16460Sstevel@tonic-gate cons_prop_t *prop;
16470Sstevel@tonic-gate const char *pushmod;
16480Sstevel@tonic-gate
16490Sstevel@tonic-gate /*
16500Sstevel@tonic-gate * Retrieve the state information
16510Sstevel@tonic-gate * Some platforms may use the old-style "consconfig" to configure
16520Sstevel@tonic-gate * console stream modules but may also support devices that happen
16530Sstevel@tonic-gate * to match a rule in /etc/dacf.conf. This will cause a problem
16540Sstevel@tonic-gate * since the console state structure will not be initialized.
16550Sstevel@tonic-gate * In that case, these entry points should silently fail and
16560Sstevel@tonic-gate * permit console to be plumbed later in boot.
16570Sstevel@tonic-gate */
16580Sstevel@tonic-gate if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
16590Sstevel@tonic-gate return (DACF_FAILURE);
16600Sstevel@tonic-gate
16610Sstevel@tonic-gate dip = dacf_devinfo_node(minor_hdl);
16620Sstevel@tonic-gate major = ddi_driver_major(dip);
16637009Scth ASSERT(major != DDI_MAJOR_T_NONE);
16640Sstevel@tonic-gate minor = dacf_minor_number(minor_hdl);
16650Sstevel@tonic-gate dev = makedevice(major, minor);
16660Sstevel@tonic-gate ASSERT(dev != NODEV);
16670Sstevel@tonic-gate
16680Sstevel@tonic-gate DPRINTF(DPRINT_L0, "driver name = \"%s\", dev = 0x%lx, major = 0x%x\n",
16690Sstevel@tonic-gate (char *)dacf_driver_name(minor_hdl), dev, major);
16700Sstevel@tonic-gate
16710Sstevel@tonic-gate /* Access to the global variables is synchronized */
16720Sstevel@tonic-gate mutex_enter(&sp->cons_lock);
16730Sstevel@tonic-gate
16740Sstevel@tonic-gate /*
16750Sstevel@tonic-gate * Check if the keyboard/mouse has already configured.
16760Sstevel@tonic-gate */
16770Sstevel@tonic-gate if (consconfig_find_dev(sp, dev) != NULL) {
16780Sstevel@tonic-gate mutex_exit(&sp->cons_lock);
16790Sstevel@tonic-gate return (DACF_SUCCESS);
16800Sstevel@tonic-gate }
16810Sstevel@tonic-gate
16820Sstevel@tonic-gate prop = kmem_zalloc(sizeof (cons_prop_t), KM_SLEEP);
16830Sstevel@tonic-gate
16840Sstevel@tonic-gate /* Config the new keyboard/mouse device */
16850Sstevel@tonic-gate prop->cp_dev = dev;
16860Sstevel@tonic-gate
16870Sstevel@tonic-gate pushmod = dacf_get_arg(arg_hdl, "pushmod");
16880Sstevel@tonic-gate prop->cp_pushmod = i_ddi_strdup((char *)pushmod, KM_SLEEP);
16890Sstevel@tonic-gate
16900Sstevel@tonic-gate prop->cp_type = type;
16910Sstevel@tonic-gate if (do_config(sp, prop) != DACF_SUCCESS) {
16920Sstevel@tonic-gate /*
16930Sstevel@tonic-gate * The keyboard/mouse node failed to open.
16940Sstevel@tonic-gate * Set the major and minor numbers to 0 so
16950Sstevel@tonic-gate * kb_unconfig/ms_unconfig won't unconfigure
16960Sstevel@tonic-gate * this node if it is detached.
16970Sstevel@tonic-gate */
16980Sstevel@tonic-gate mutex_exit(&sp->cons_lock);
16990Sstevel@tonic-gate consconfig_free_prop(prop);
17000Sstevel@tonic-gate return (DACF_FAILURE);
17010Sstevel@tonic-gate }
17020Sstevel@tonic-gate
17030Sstevel@tonic-gate consconfig_add_dev(sp, prop);
17040Sstevel@tonic-gate
17050Sstevel@tonic-gate /*
17060Sstevel@tonic-gate * See if there was a problem with the console keyboard during boot.
17070Sstevel@tonic-gate * If so, try to register polled input for this keyboard.
17080Sstevel@tonic-gate */
17090Sstevel@tonic-gate if ((type == CONS_KBD) && (sp->cons_keyboard_problem)) {
17100Sstevel@tonic-gate consconfig_setup_polledio(sp, sp->cons_wc_vp->v_rdev);
17110Sstevel@tonic-gate sp->cons_keyboard_problem = B_FALSE;
17120Sstevel@tonic-gate }
17130Sstevel@tonic-gate
17140Sstevel@tonic-gate /* Prevent autodetach due to memory pressure */
17150Sstevel@tonic-gate (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, DDI_NO_AUTODETACH, 1);
17160Sstevel@tonic-gate
17170Sstevel@tonic-gate mutex_exit(&sp->cons_lock);
17180Sstevel@tonic-gate
17190Sstevel@tonic-gate return (DACF_SUCCESS);
17200Sstevel@tonic-gate }
17210Sstevel@tonic-gate
17220Sstevel@tonic-gate static int
kb_ms_unconfig(dacf_infohdl_t minor_hdl,dacf_arghdl_t arg_hdl)17230Sstevel@tonic-gate kb_ms_unconfig(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl)
17240Sstevel@tonic-gate {
17250Sstevel@tonic-gate _NOTE(ARGUNUSED(arg_hdl))
17260Sstevel@tonic-gate
17270Sstevel@tonic-gate major_t major;
17280Sstevel@tonic-gate minor_t minor;
17290Sstevel@tonic-gate dev_t dev;
17300Sstevel@tonic-gate dev_info_t *dip;
17310Sstevel@tonic-gate cons_state_t *sp;
17320Sstevel@tonic-gate cons_prop_t *prop;
17330Sstevel@tonic-gate
17340Sstevel@tonic-gate /*
17350Sstevel@tonic-gate * Retrieve the state information
17360Sstevel@tonic-gate * So if there isn't a state available, then this entry point just
17370Sstevel@tonic-gate * returns. See note in kb_config().
17380Sstevel@tonic-gate */
17390Sstevel@tonic-gate if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
17400Sstevel@tonic-gate return (DACF_SUCCESS);
17410Sstevel@tonic-gate
17420Sstevel@tonic-gate dip = dacf_devinfo_node(minor_hdl);
17430Sstevel@tonic-gate major = ddi_driver_major(dip);
17447009Scth ASSERT(major != DDI_MAJOR_T_NONE);
17450Sstevel@tonic-gate minor = dacf_minor_number(minor_hdl);
17460Sstevel@tonic-gate dev = makedevice(major, minor);
17470Sstevel@tonic-gate ASSERT(dev != NODEV);
17480Sstevel@tonic-gate
17490Sstevel@tonic-gate /*
17500Sstevel@tonic-gate * Check if the keyboard/mouse that is being detached
17510Sstevel@tonic-gate * is the console keyboard/mouse or not.
17520Sstevel@tonic-gate */
17530Sstevel@tonic-gate mutex_enter(&sp->cons_lock);
17540Sstevel@tonic-gate if ((prop = consconfig_find_dev(sp, dev)) == NULL) {
17550Sstevel@tonic-gate mutex_exit(&sp->cons_lock);
17560Sstevel@tonic-gate return (DACF_SUCCESS);
17570Sstevel@tonic-gate }
17580Sstevel@tonic-gate
17590Sstevel@tonic-gate /*
17600Sstevel@tonic-gate * This dev may be opened physically and then hotplugged out.
17610Sstevel@tonic-gate */
17620Sstevel@tonic-gate if (prop->cp_muxid != -1) {
17630Sstevel@tonic-gate (void) do_unconfig(sp, prop);
17640Sstevel@tonic-gate consconfig_rem_dev(sp, dev);
17650Sstevel@tonic-gate }
17660Sstevel@tonic-gate
17670Sstevel@tonic-gate mutex_exit(&sp->cons_lock);
17680Sstevel@tonic-gate
17690Sstevel@tonic-gate return (DACF_SUCCESS);
17700Sstevel@tonic-gate }
17710Sstevel@tonic-gate
17720Sstevel@tonic-gate /*
17730Sstevel@tonic-gate * This is the post-attach / pre-detach action function for the keyboard
17740Sstevel@tonic-gate * and mouse. This function is associated with a node type in /etc/dacf.conf.
17750Sstevel@tonic-gate */
17760Sstevel@tonic-gate static int
kb_config(dacf_infohdl_t minor_hdl,dacf_arghdl_t arg_hdl,int flags)17770Sstevel@tonic-gate kb_config(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags)
17780Sstevel@tonic-gate {
17790Sstevel@tonic-gate _NOTE(ARGUNUSED(flags))
17800Sstevel@tonic-gate
17810Sstevel@tonic-gate return (kb_ms_config(minor_hdl, arg_hdl, CONS_KBD));
17820Sstevel@tonic-gate }
17830Sstevel@tonic-gate
17840Sstevel@tonic-gate static int
ms_config(dacf_infohdl_t minor_hdl,dacf_arghdl_t arg_hdl,int flags)17850Sstevel@tonic-gate ms_config(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags)
17860Sstevel@tonic-gate {
17870Sstevel@tonic-gate _NOTE(ARGUNUSED(flags))
17880Sstevel@tonic-gate
17890Sstevel@tonic-gate return (kb_ms_config(minor_hdl, arg_hdl, CONS_MS));
17900Sstevel@tonic-gate }
17910Sstevel@tonic-gate
17920Sstevel@tonic-gate static int
kb_unconfig(dacf_infohdl_t minor_hdl,dacf_arghdl_t arg_hdl,int flags)17930Sstevel@tonic-gate kb_unconfig(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags)
17940Sstevel@tonic-gate {
17950Sstevel@tonic-gate _NOTE(ARGUNUSED(flags))
17960Sstevel@tonic-gate
17970Sstevel@tonic-gate return (kb_ms_unconfig(minor_hdl, arg_hdl));
17980Sstevel@tonic-gate }
17990Sstevel@tonic-gate
18000Sstevel@tonic-gate static int
ms_unconfig(dacf_infohdl_t minor_hdl,dacf_arghdl_t arg_hdl,int flags)18010Sstevel@tonic-gate ms_unconfig(dacf_infohdl_t minor_hdl, dacf_arghdl_t arg_hdl, int flags)
18020Sstevel@tonic-gate {
18030Sstevel@tonic-gate _NOTE(ARGUNUSED(flags))
18040Sstevel@tonic-gate
18050Sstevel@tonic-gate return (kb_ms_unconfig(minor_hdl, arg_hdl));
18060Sstevel@tonic-gate }
18070Sstevel@tonic-gate
18080Sstevel@tonic-gate /*
18090Sstevel@tonic-gate * consconfig_link and consconfig_unlink are provided to support
18100Sstevel@tonic-gate * direct access to physical keyboard/mouse underlying conskbd/
18110Sstevel@tonic-gate * consms.
18120Sstevel@tonic-gate * When the keyboard/mouse is opened physically via its device
18130Sstevel@tonic-gate * file, it will be unlinked from the virtual one, and when it
18140Sstevel@tonic-gate * is closed physically, it will be linked back under the virtual
18150Sstevel@tonic-gate * one.
18160Sstevel@tonic-gate */
18170Sstevel@tonic-gate void
consconfig_link(major_t major,minor_t minor)18180Sstevel@tonic-gate consconfig_link(major_t major, minor_t minor)
18190Sstevel@tonic-gate {
18200Sstevel@tonic-gate char buf[MAXPATHLEN];
18210Sstevel@tonic-gate dev_t dev;
18220Sstevel@tonic-gate cons_state_t *sp;
18230Sstevel@tonic-gate cons_prop_t *prop;
18240Sstevel@tonic-gate
18250Sstevel@tonic-gate if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
18260Sstevel@tonic-gate return;
18270Sstevel@tonic-gate
18280Sstevel@tonic-gate dev = makedevice(major, minor);
18290Sstevel@tonic-gate ASSERT(dev != NODEV);
18300Sstevel@tonic-gate
18310Sstevel@tonic-gate mutex_enter(&sp->cons_lock);
18320Sstevel@tonic-gate if ((prop = consconfig_find_dev(sp, dev)) == NULL) {
18330Sstevel@tonic-gate mutex_exit(&sp->cons_lock);
18340Sstevel@tonic-gate return;
18350Sstevel@tonic-gate }
18360Sstevel@tonic-gate
18370Sstevel@tonic-gate if (do_config(sp, prop) != DACF_SUCCESS) {
18380Sstevel@tonic-gate (void) ddi_dev_pathname(dev, 0, buf);
18390Sstevel@tonic-gate if (prop->cp_type == CONS_KBD)
18400Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to relink the keyboard "
18410Sstevel@tonic-gate "(%s) underneath virtual keyboard", buf);
18420Sstevel@tonic-gate else
18430Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to relink the mouse "
18440Sstevel@tonic-gate "(%s) underneath virtual mouse", buf);
18450Sstevel@tonic-gate consconfig_rem_dev(sp, dev);
18460Sstevel@tonic-gate }
18470Sstevel@tonic-gate
18480Sstevel@tonic-gate mutex_exit(&sp->cons_lock);
18490Sstevel@tonic-gate }
18500Sstevel@tonic-gate
18510Sstevel@tonic-gate
18520Sstevel@tonic-gate int
consconfig_unlink(major_t major,minor_t minor)18530Sstevel@tonic-gate consconfig_unlink(major_t major, minor_t minor)
18540Sstevel@tonic-gate {
18550Sstevel@tonic-gate dev_t dev;
18560Sstevel@tonic-gate cons_state_t *sp;
18570Sstevel@tonic-gate cons_prop_t *prop;
18580Sstevel@tonic-gate int error;
18590Sstevel@tonic-gate
18600Sstevel@tonic-gate if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
18610Sstevel@tonic-gate return (DACF_SUCCESS);
18620Sstevel@tonic-gate
18630Sstevel@tonic-gate dev = makedevice(major, minor);
18640Sstevel@tonic-gate ASSERT(dev != NODEV);
18650Sstevel@tonic-gate
18660Sstevel@tonic-gate mutex_enter(&sp->cons_lock);
18670Sstevel@tonic-gate if ((prop = consconfig_find_dev(sp, dev)) == NULL) {
18680Sstevel@tonic-gate mutex_exit(&sp->cons_lock);
18690Sstevel@tonic-gate return (DACF_FAILURE);
18700Sstevel@tonic-gate }
18710Sstevel@tonic-gate
18720Sstevel@tonic-gate error = do_unconfig(sp, prop);
18730Sstevel@tonic-gate
18740Sstevel@tonic-gate /*
18750Sstevel@tonic-gate * Keep this dev on the list, for this dev is still online.
18760Sstevel@tonic-gate */
18770Sstevel@tonic-gate mutex_exit(&sp->cons_lock);
18780Sstevel@tonic-gate
18790Sstevel@tonic-gate return (error);
18800Sstevel@tonic-gate }
18810Sstevel@tonic-gate
18820Sstevel@tonic-gate /*
18830Sstevel@tonic-gate * Routine to set baud rate, bits-per-char, parity and stop bits
18840Sstevel@tonic-gate * on the console line when necessary.
18850Sstevel@tonic-gate */
18860Sstevel@tonic-gate static int
consconfig_setmodes(dev_t dev,struct termios * termiosp)18870Sstevel@tonic-gate consconfig_setmodes(dev_t dev, struct termios *termiosp)
18880Sstevel@tonic-gate {
18890Sstevel@tonic-gate char buf[MAXPATHLEN];
18900Sstevel@tonic-gate int len = MAXPATHLEN;
18910Sstevel@tonic-gate char name[16];
18926128Sedp int ppos, i;
18930Sstevel@tonic-gate char *path;
18940Sstevel@tonic-gate dev_t tdev;
18950Sstevel@tonic-gate
18960Sstevel@tonic-gate /*
18970Sstevel@tonic-gate * First, search for a devalias which matches this dev_t.
18980Sstevel@tonic-gate * Try all of ttya through ttyz until no such alias
18990Sstevel@tonic-gate */
19000Sstevel@tonic-gate (void) strcpy(name, "ttya");
19010Sstevel@tonic-gate for (i = 0; i < ('z'-'a'); i++) {
19020Sstevel@tonic-gate name[3] = 'a' + i; /* increment device name */
19030Sstevel@tonic-gate path = get_alias(name, buf);
19040Sstevel@tonic-gate if (path == NULL)
19050Sstevel@tonic-gate return (1);
19060Sstevel@tonic-gate
19070Sstevel@tonic-gate tdev = ddi_pathname_to_dev_t(path);
19080Sstevel@tonic-gate if (tdev == dev)
19090Sstevel@tonic-gate break; /* Exit loop if found */
19100Sstevel@tonic-gate }
19110Sstevel@tonic-gate
19120Sstevel@tonic-gate if (i >= ('z'-'a'))
19130Sstevel@tonic-gate return (1); /* If we didn't find it, return */
19140Sstevel@tonic-gate
19150Sstevel@tonic-gate /*
19160Sstevel@tonic-gate * Now that we know which "tty" this corresponds to, retrieve
19170Sstevel@tonic-gate * the "ttya-mode" options property, which tells us how to configure
19180Sstevel@tonic-gate * the line.
19190Sstevel@tonic-gate */
19200Sstevel@tonic-gate (void) strcpy(name, "ttya-mode"); /* name of option we want */
19210Sstevel@tonic-gate name[3] = 'a' + i; /* Adjust to correct line */
19220Sstevel@tonic-gate
19230Sstevel@tonic-gate if (ddi_getlongprop_buf(DDI_DEV_T_ANY, ddi_root_node(), 0, name,
19240Sstevel@tonic-gate buf, &len) != DDI_PROP_SUCCESS)
19250Sstevel@tonic-gate return (1); /* if no such option, just return */
19260Sstevel@tonic-gate
19276128Sedp /*
19286128Sedp * The IEEE 1275 standard specifies that /aliases string property
19299674SGeorge.Shepherd@Sun.COM * values should be null-terminated. Unfortunately the reality
19306128Sedp * is that most aren't and the OBP can't easily be modified to
19316128Sedp * add null termination to these strings. So we'll add the
19326128Sedp * null termination here. If the string already contains a
19336128Sedp * null termination character then that's ok too because we'll
19346128Sedp * just be adding a second one.
19356128Sedp */
19366128Sedp buf[len] = '\0';
19376128Sedp
19380Sstevel@tonic-gate /* Clear out options we will be setting */
19390Sstevel@tonic-gate termiosp->c_cflag &=
19400Sstevel@tonic-gate ~(CSIZE | CBAUD | CBAUDEXT | PARODD | PARENB | CSTOPB);
19410Sstevel@tonic-gate
19429674SGeorge.Shepherd@Sun.COM /* Clear options which potentially conflict with new settings */
19439674SGeorge.Shepherd@Sun.COM termiosp->c_cflag &= ~(CIBAUD | CIBAUDEXT);
19449674SGeorge.Shepherd@Sun.COM
19450Sstevel@tonic-gate /*
19460Sstevel@tonic-gate * Now, parse the string. Wish I could use sscanf().
19470Sstevel@tonic-gate * Format 9600,8,n,1,-
19480Sstevel@tonic-gate * baud rate, bits-per-char, parity, stop-bits, ignored
19490Sstevel@tonic-gate */
19500Sstevel@tonic-gate for (ppos = 0; ppos < (MAXPATHLEN-8); ppos++) { /* Find first comma */
19510Sstevel@tonic-gate if ((buf[ppos] == 0) || (buf[ppos] == ','))
19520Sstevel@tonic-gate break;
19530Sstevel@tonic-gate }
19540Sstevel@tonic-gate
19550Sstevel@tonic-gate if (buf[ppos] != ',') {
19560Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_setmodes: "
19570Sstevel@tonic-gate "invalid mode string %s", buf);
19580Sstevel@tonic-gate return (1);
19590Sstevel@tonic-gate }
19600Sstevel@tonic-gate
19610Sstevel@tonic-gate for (i = 0; i < MAX_SPEEDS; i++) {
19620Sstevel@tonic-gate if (strncmp(buf, speedtab[i].name, ppos) == 0)
19636128Sedp break;
19640Sstevel@tonic-gate }
19650Sstevel@tonic-gate
19660Sstevel@tonic-gate if (i >= MAX_SPEEDS) {
19670Sstevel@tonic-gate cmn_err(CE_WARN,
19686128Sedp "consconfig_setmodes: unrecognized speed in %s", buf);
19690Sstevel@tonic-gate return (1);
19700Sstevel@tonic-gate }
19710Sstevel@tonic-gate
19720Sstevel@tonic-gate /* Found the baud rate, set it */
19730Sstevel@tonic-gate termiosp->c_cflag |= speedtab[i].code & CBAUD;
19740Sstevel@tonic-gate if (speedtab[i].code > 16) /* cfsetospeed! */
19750Sstevel@tonic-gate termiosp->c_cflag |= CBAUDEXT;
19760Sstevel@tonic-gate
19770Sstevel@tonic-gate /* Set bits per character */
19780Sstevel@tonic-gate switch (buf[ppos+1]) {
19790Sstevel@tonic-gate case '8':
19800Sstevel@tonic-gate termiosp->c_cflag |= CS8;
19810Sstevel@tonic-gate break;
19820Sstevel@tonic-gate case '7':
19830Sstevel@tonic-gate termiosp->c_cflag |= CS7;
19840Sstevel@tonic-gate break;
19850Sstevel@tonic-gate default:
19860Sstevel@tonic-gate cmn_err(CE_WARN,
19870Sstevel@tonic-gate "consconfig_setmodes: illegal bits-per-char %s", buf);
19880Sstevel@tonic-gate return (1);
19890Sstevel@tonic-gate }
19900Sstevel@tonic-gate
19910Sstevel@tonic-gate /* Set parity */
19920Sstevel@tonic-gate switch (buf[ppos+3]) {
19930Sstevel@tonic-gate case 'o':
19940Sstevel@tonic-gate termiosp->c_cflag |= PARENB | PARODD;
19950Sstevel@tonic-gate break;
19960Sstevel@tonic-gate case 'e':
19970Sstevel@tonic-gate termiosp->c_cflag |= PARENB; /* enabled, not odd */
19980Sstevel@tonic-gate break;
19990Sstevel@tonic-gate case 'n':
20000Sstevel@tonic-gate break; /* not enabled. */
20010Sstevel@tonic-gate default:
20020Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_setmodes: illegal parity %s", buf);
20030Sstevel@tonic-gate return (1);
20040Sstevel@tonic-gate }
20050Sstevel@tonic-gate
20060Sstevel@tonic-gate /* Set stop bits */
20070Sstevel@tonic-gate switch (buf[ppos+5]) {
20080Sstevel@tonic-gate case '1':
20090Sstevel@tonic-gate break; /* No extra stop bit */
20100Sstevel@tonic-gate case '2':
20110Sstevel@tonic-gate termiosp->c_cflag |= CSTOPB; /* 1 extra stop bit */
20120Sstevel@tonic-gate break;
20130Sstevel@tonic-gate default:
20140Sstevel@tonic-gate cmn_err(CE_WARN, "consconfig_setmodes: "
20150Sstevel@tonic-gate "illegal stop bits %s", buf);
20160Sstevel@tonic-gate return (1);
20170Sstevel@tonic-gate }
20180Sstevel@tonic-gate
20190Sstevel@tonic-gate return (0);
20200Sstevel@tonic-gate }
20210Sstevel@tonic-gate
20220Sstevel@tonic-gate /*
20230Sstevel@tonic-gate * Check to see if underlying keyboard devices are still online,
20240Sstevel@tonic-gate * if any one is offline now, unlink it.
20250Sstevel@tonic-gate */
20260Sstevel@tonic-gate static void
consconfig_check_phys_kbd(cons_state_t * sp)20270Sstevel@tonic-gate consconfig_check_phys_kbd(cons_state_t *sp)
20280Sstevel@tonic-gate {
20290Sstevel@tonic-gate ldi_handle_t kb_lh;
20300Sstevel@tonic-gate cons_prop_t *prop;
20310Sstevel@tonic-gate int error;
20320Sstevel@tonic-gate int rval;
20330Sstevel@tonic-gate
20340Sstevel@tonic-gate for (prop = sp->cons_km_prop; prop; prop = prop->cp_next) {
20350Sstevel@tonic-gate if ((prop->cp_type != CONS_KBD) || (prop->cp_muxid == -1))
20360Sstevel@tonic-gate continue;
20370Sstevel@tonic-gate
20380Sstevel@tonic-gate error = ldi_open_by_dev(&prop->cp_dev, OTYP_CHR,
20390Sstevel@tonic-gate FREAD|FWRITE|FNOCTTY, kcred, &kb_lh, sp->cons_li);
20400Sstevel@tonic-gate
20410Sstevel@tonic-gate if (error) {
20420Sstevel@tonic-gate (void) ldi_ioctl(sp->conskbd_lh, I_PUNLINK,
20430Sstevel@tonic-gate prop->cp_muxid, FKIOCTL, kcred, &rval);
20440Sstevel@tonic-gate prop->cp_dev = NODEV;
20450Sstevel@tonic-gate } else {
20460Sstevel@tonic-gate (void) ldi_close(kb_lh, FREAD|FWRITE, kcred);
20470Sstevel@tonic-gate }
20480Sstevel@tonic-gate }
20490Sstevel@tonic-gate
20500Sstevel@tonic-gate /*
20510Sstevel@tonic-gate * Remove all disconnected keyboards,
20520Sstevel@tonic-gate * whose dev is turned into NODEV above.
20530Sstevel@tonic-gate */
20540Sstevel@tonic-gate consconfig_rem_dev(sp, NODEV);
20550Sstevel@tonic-gate }
20560Sstevel@tonic-gate
20570Sstevel@tonic-gate /*
20580Sstevel@tonic-gate * Remove devices according to dev, which may be NODEV
20590Sstevel@tonic-gate */
20600Sstevel@tonic-gate static void
consconfig_rem_dev(cons_state_t * sp,dev_t dev)20610Sstevel@tonic-gate consconfig_rem_dev(cons_state_t *sp, dev_t dev)
20620Sstevel@tonic-gate {
20630Sstevel@tonic-gate cons_prop_t *prop;
20640Sstevel@tonic-gate cons_prop_t *prev_prop;
20650Sstevel@tonic-gate cons_prop_t *tmp_prop;
20660Sstevel@tonic-gate cons_prop_t *head_prop;
20670Sstevel@tonic-gate
20680Sstevel@tonic-gate head_prop = NULL;
20690Sstevel@tonic-gate prev_prop = NULL;
20700Sstevel@tonic-gate for (prop = sp->cons_km_prop; prop != NULL; ) {
20710Sstevel@tonic-gate if (prop->cp_dev == dev) {
20720Sstevel@tonic-gate tmp_prop = prop->cp_next;
20730Sstevel@tonic-gate consconfig_free_prop(prop);
20740Sstevel@tonic-gate prop = tmp_prop;
20750Sstevel@tonic-gate if (prev_prop)
20760Sstevel@tonic-gate prev_prop->cp_next = prop;
20770Sstevel@tonic-gate } else {
20780Sstevel@tonic-gate if (head_prop == NULL)
20790Sstevel@tonic-gate head_prop = prop;
20800Sstevel@tonic-gate prev_prop = prop;
20810Sstevel@tonic-gate prop = prop->cp_next;
20820Sstevel@tonic-gate }
20830Sstevel@tonic-gate }
20840Sstevel@tonic-gate sp->cons_km_prop = head_prop;
20850Sstevel@tonic-gate }
20860Sstevel@tonic-gate
20870Sstevel@tonic-gate /*
20880Sstevel@tonic-gate * Add a dev according to prop
20890Sstevel@tonic-gate */
20900Sstevel@tonic-gate static void
consconfig_add_dev(cons_state_t * sp,cons_prop_t * prop)20910Sstevel@tonic-gate consconfig_add_dev(cons_state_t *sp, cons_prop_t *prop)
20920Sstevel@tonic-gate {
20930Sstevel@tonic-gate prop->cp_next = sp->cons_km_prop;
20940Sstevel@tonic-gate sp->cons_km_prop = prop;
20950Sstevel@tonic-gate }
20960Sstevel@tonic-gate
20970Sstevel@tonic-gate /*
20980Sstevel@tonic-gate * Find a device from our list according to dev
20990Sstevel@tonic-gate */
21000Sstevel@tonic-gate static cons_prop_t *
consconfig_find_dev(cons_state_t * sp,dev_t dev)21010Sstevel@tonic-gate consconfig_find_dev(cons_state_t *sp, dev_t dev)
21020Sstevel@tonic-gate {
21030Sstevel@tonic-gate cons_prop_t *prop;
21040Sstevel@tonic-gate
21050Sstevel@tonic-gate for (prop = sp->cons_km_prop; prop; prop = prop->cp_next) {
21060Sstevel@tonic-gate if (prop->cp_dev == dev)
21070Sstevel@tonic-gate break;
21080Sstevel@tonic-gate }
21090Sstevel@tonic-gate
21100Sstevel@tonic-gate return (prop);
21110Sstevel@tonic-gate }
21120Sstevel@tonic-gate
21130Sstevel@tonic-gate /*
21140Sstevel@tonic-gate * Free a cons prop associated with a keyboard or mouse
21150Sstevel@tonic-gate */
21160Sstevel@tonic-gate static void
consconfig_free_prop(cons_prop_t * prop)21170Sstevel@tonic-gate consconfig_free_prop(cons_prop_t *prop)
21180Sstevel@tonic-gate {
21190Sstevel@tonic-gate if (prop->cp_pushmod)
21200Sstevel@tonic-gate kmem_free(prop->cp_pushmod, strlen(prop->cp_pushmod) + 1);
21210Sstevel@tonic-gate kmem_free(prop, sizeof (cons_prop_t));
21220Sstevel@tonic-gate }
21232191Sszhou
21242191Sszhou /*
21258960SJan.Setje-Eilers@Sun.COM * The early boot code can't print to a usb serial device or the
21268960SJan.Setje-Eilers@Sun.COM * graphical boot screen.
21278960SJan.Setje-Eilers@Sun.COM *
21288960SJan.Setje-Eilers@Sun.COM * The early boot messages are saved in a buffer at the address indicated
21298960SJan.Setje-Eilers@Sun.COM * by "deferred-console-buf" This function flushes the message to the
21308960SJan.Setje-Eilers@Sun.COM * current console now that it is set up.
21312191Sszhou */
21322191Sszhou static void
flush_deferred_console_buf(void)21338960SJan.Setje-Eilers@Sun.COM flush_deferred_console_buf(void)
21342191Sszhou {
21352191Sszhou int rval;
21362191Sszhou vnode_t *vp;
21378960SJan.Setje-Eilers@Sun.COM uint_t defcons_buf;
21388960SJan.Setje-Eilers@Sun.COM char *kc, *bc, *defcons_kern_buf;
21392191Sszhou
21408960SJan.Setje-Eilers@Sun.COM /* defcons_buf is in low memory, so an int works here */
21418960SJan.Setje-Eilers@Sun.COM defcons_buf = ddi_prop_get_int(DDI_DEV_T_ANY, ddi_root_node(),
21428960SJan.Setje-Eilers@Sun.COM DDI_PROP_DONTPASS, "deferred-console-buf", 0);
21432191Sszhou
21448960SJan.Setje-Eilers@Sun.COM if (defcons_buf == 0)
21452191Sszhou return;
21462191Sszhou
21472191Sszhou /*
21482191Sszhou * After consconfig() and before userland opens /dev/sysmsg,
21492191Sszhou * console I/O is goes to polled I/O entry points.
21502191Sszhou *
21512191Sszhou * If usb-serial doesn't implement polled I/O, we need
21522191Sszhou * to open /dev/console now to get kernel console I/O to work.
21532191Sszhou * We also push ttcompat and ldterm explicitly to get the
21542191Sszhou * correct output format (autopush isn't set up yet). We
21552191Sszhou * ignore push errors because they are non-fatal.
21562191Sszhou * Note that opening /dev/console causes rconsvp to be
21572191Sszhou * opened as well.
21582191Sszhou */
21592191Sszhou if (cons_polledio == NULL) {
21602191Sszhou if (vn_open("/dev/console", UIO_SYSSPACE, FWRITE | FNOCTTY,
21612191Sszhou 0, &vp, 0, 0) != 0)
21622191Sszhou return;
21632191Sszhou
21642191Sszhou if (rconsvp) {
21652191Sszhou (void) strioctl(rconsvp, __I_PUSH_NOCTTY,
21662191Sszhou (intptr_t)"ldterm", FKIOCTL, K_TO_K, kcred, &rval);
21672191Sszhou (void) strioctl(rconsvp, __I_PUSH_NOCTTY,
21682191Sszhou (intptr_t)"ttcompat", FKIOCTL, K_TO_K,
21692191Sszhou kcred, &rval);
21702191Sszhou }
21712191Sszhou }
21722191Sszhou
21732191Sszhou /*
21742191Sszhou * Copy message to a kernel buffer. Various kernel routines
21752191Sszhou * expect buffer to be above kernelbase
21762191Sszhou */
21779354STim.Marsland@Sun.COM kc = defcons_kern_buf = kmem_zalloc(MMU_PAGESIZE, KM_SLEEP);
21788960SJan.Setje-Eilers@Sun.COM bc = (char *)(uintptr_t)defcons_buf;
21792191Sszhou while (*kc++ = *bc++)
21802191Sszhou ;
21818960SJan.Setje-Eilers@Sun.COM console_printf("%s", defcons_kern_buf);
21822191Sszhou
21838960SJan.Setje-Eilers@Sun.COM kmem_free(defcons_kern_buf, MMU_PAGESIZE);
21842191Sszhou }
21857688SAaron.Zang@Sun.COM
21867688SAaron.Zang@Sun.COM boolean_t
consconfig_console_is_tipline(void)21877688SAaron.Zang@Sun.COM consconfig_console_is_tipline(void)
21887688SAaron.Zang@Sun.COM {
21897688SAaron.Zang@Sun.COM cons_state_t *sp;
21907688SAaron.Zang@Sun.COM
21917688SAaron.Zang@Sun.COM if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
21927688SAaron.Zang@Sun.COM return (B_FALSE);
21937688SAaron.Zang@Sun.COM
21947688SAaron.Zang@Sun.COM if (sp->cons_input_type == CONSOLE_TIP)
21957688SAaron.Zang@Sun.COM return (B_TRUE);
21967688SAaron.Zang@Sun.COM
21977688SAaron.Zang@Sun.COM return (B_FALSE);
21987688SAaron.Zang@Sun.COM }
219910783SVincent.Wang@Sun.COM
220010783SVincent.Wang@Sun.COM boolean_t
consconfig_dacf_initialized(void)220110783SVincent.Wang@Sun.COM consconfig_dacf_initialized(void)
220210783SVincent.Wang@Sun.COM {
220310783SVincent.Wang@Sun.COM cons_state_t *sp;
220410783SVincent.Wang@Sun.COM
220510783SVincent.Wang@Sun.COM if ((sp = (cons_state_t *)space_fetch("consconfig")) == NULL)
220610783SVincent.Wang@Sun.COM return (B_FALSE);
220710783SVincent.Wang@Sun.COM
220810783SVincent.Wang@Sun.COM return (sp->cons_initialized);
220910783SVincent.Wang@Sun.COM }
2210