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 /* 236990Sgd78059 * Copyright 2008 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 /* 290Sstevel@tonic-gate * "Workstation console" multiplexor driver for Sun. 300Sstevel@tonic-gate * 310Sstevel@tonic-gate * Sends output to the primary frame buffer using the PROM monitor; 320Sstevel@tonic-gate * gets input from a stream linked below us that is the "keyboard 330Sstevel@tonic-gate * driver", below which is linked the primary keyboard. 340Sstevel@tonic-gate */ 350Sstevel@tonic-gate 360Sstevel@tonic-gate #include <sys/types.h> 370Sstevel@tonic-gate #include <sys/param.h> 380Sstevel@tonic-gate #include <sys/signal.h> 390Sstevel@tonic-gate #include <sys/cred.h> 400Sstevel@tonic-gate #include <sys/vnode.h> 410Sstevel@tonic-gate #include <sys/termios.h> 420Sstevel@tonic-gate #include <sys/termio.h> 430Sstevel@tonic-gate #include <sys/ttold.h> 440Sstevel@tonic-gate #include <sys/stropts.h> 450Sstevel@tonic-gate #include <sys/stream.h> 460Sstevel@tonic-gate #include <sys/strsun.h> 470Sstevel@tonic-gate #include <sys/tty.h> 480Sstevel@tonic-gate #include <sys/buf.h> 490Sstevel@tonic-gate #include <sys/uio.h> 500Sstevel@tonic-gate #include <sys/stat.h> 510Sstevel@tonic-gate #include <sys/kmem.h> 520Sstevel@tonic-gate #include <sys/cpuvar.h> 530Sstevel@tonic-gate #include <sys/kbio.h> 540Sstevel@tonic-gate #include <sys/strredir.h> 550Sstevel@tonic-gate #include <sys/fs/snode.h> 560Sstevel@tonic-gate #include <sys/consdev.h> 570Sstevel@tonic-gate #include <sys/conf.h> 580Sstevel@tonic-gate #include <sys/ddi.h> 590Sstevel@tonic-gate #include <sys/sunddi.h> 600Sstevel@tonic-gate #include <sys/debug.h> 610Sstevel@tonic-gate #include <sys/console.h> 620Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 630Sstevel@tonic-gate #include <sys/promif.h> 640Sstevel@tonic-gate #include <sys/policy.h> 651253Slq150181 #include <sys/tem.h> 661253Slq150181 #include <sys/wscons.h> 670Sstevel@tonic-gate 680Sstevel@tonic-gate #define MINLINES 10 690Sstevel@tonic-gate #define MAXLINES 48 700Sstevel@tonic-gate #define LOSCREENLINES 34 710Sstevel@tonic-gate #define HISCREENLINES 48 720Sstevel@tonic-gate 730Sstevel@tonic-gate #define MINCOLS 10 740Sstevel@tonic-gate #define MAXCOLS 120 750Sstevel@tonic-gate #define LOSCREENCOLS 80 760Sstevel@tonic-gate #define HISCREENCOLS 120 770Sstevel@tonic-gate 781253Slq150181 struct wscons { 791253Slq150181 struct tem *wc_tem; /* Terminal emulator state */ 800Sstevel@tonic-gate int wc_flags; /* random flags (protected by */ 810Sstevel@tonic-gate /* write-side exclusion lock */ 820Sstevel@tonic-gate dev_t wc_dev; /* major/minor for this device */ 830Sstevel@tonic-gate tty_common_t wc_ttycommon; /* data common to all tty drivers */ 841253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 850Sstevel@tonic-gate int wc_pendc; /* pending output character */ 860Sstevel@tonic-gate int wc_defer_output; /* set if output device is "slow" */ 871253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 880Sstevel@tonic-gate queue_t *wc_kbdqueue; /* "console keyboard" device queue */ 890Sstevel@tonic-gate /* below us */ 900Sstevel@tonic-gate bufcall_id_t wc_bufcallid; /* id returned by qbufcall */ 910Sstevel@tonic-gate timeout_id_t wc_timeoutid; /* id returned by qtimeout */ 920Sstevel@tonic-gate cons_polledio_t wc_polledio; /* polled I/O function pointers */ 930Sstevel@tonic-gate cons_polledio_t *wc_kb_polledio; /* keyboard's polledio */ 940Sstevel@tonic-gate unsigned int wc_kb_getpolledio_id; /* id for kb CONSOPENPOLLEDIO */ 950Sstevel@tonic-gate mblk_t *wc_pending_link; /* I_PLINK pending for kb polledio */ 960Sstevel@tonic-gate } wscons; 970Sstevel@tonic-gate 980Sstevel@tonic-gate #define WCS_ISOPEN 0x00000001 /* open is complete */ 990Sstevel@tonic-gate #define WCS_STOPPED 0x00000002 /* output is stopped */ 1000Sstevel@tonic-gate #define WCS_DELAY 0x00000004 /* waiting for delay to finish */ 1010Sstevel@tonic-gate #define WCS_BUSY 0x00000008 /* waiting for transmission to finish */ 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate static int wcopen(queue_t *, dev_t *, int, int, cred_t *); 1040Sstevel@tonic-gate static int wcclose(queue_t *, int, cred_t *); 1050Sstevel@tonic-gate static int wcuwput(queue_t *, mblk_t *); 1060Sstevel@tonic-gate static int wclrput(queue_t *, mblk_t *); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate static struct module_info wcm_info = { 1090Sstevel@tonic-gate 0, 1100Sstevel@tonic-gate "wc", 1110Sstevel@tonic-gate 0, 1120Sstevel@tonic-gate INFPSZ, 1130Sstevel@tonic-gate 2048, 1140Sstevel@tonic-gate 128 1150Sstevel@tonic-gate }; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate static struct qinit wcurinit = { 1180Sstevel@tonic-gate putq, 1190Sstevel@tonic-gate NULL, 1200Sstevel@tonic-gate wcopen, 1210Sstevel@tonic-gate wcclose, 1220Sstevel@tonic-gate NULL, 1230Sstevel@tonic-gate &wcm_info, 1240Sstevel@tonic-gate NULL 1250Sstevel@tonic-gate }; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate static struct qinit wcuwinit = { 1280Sstevel@tonic-gate wcuwput, 1290Sstevel@tonic-gate NULL, 1300Sstevel@tonic-gate wcopen, 1310Sstevel@tonic-gate wcclose, 1320Sstevel@tonic-gate NULL, 1330Sstevel@tonic-gate &wcm_info, 1340Sstevel@tonic-gate NULL 1350Sstevel@tonic-gate }; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate static struct qinit wclrinit = { 1380Sstevel@tonic-gate wclrput, 1390Sstevel@tonic-gate NULL, 1400Sstevel@tonic-gate NULL, 1410Sstevel@tonic-gate NULL, 1420Sstevel@tonic-gate NULL, 1430Sstevel@tonic-gate &wcm_info, 1440Sstevel@tonic-gate NULL 1450Sstevel@tonic-gate }; 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate /* 1480Sstevel@tonic-gate * We always putnext directly to the underlying queue. 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate static struct qinit wclwinit = { 1510Sstevel@tonic-gate NULL, 1520Sstevel@tonic-gate NULL, 1530Sstevel@tonic-gate NULL, 1540Sstevel@tonic-gate NULL, 1550Sstevel@tonic-gate NULL, 1560Sstevel@tonic-gate &wcm_info, 1570Sstevel@tonic-gate NULL 1580Sstevel@tonic-gate }; 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate static struct streamtab wcinfo = { 1610Sstevel@tonic-gate &wcurinit, 1620Sstevel@tonic-gate &wcuwinit, 1630Sstevel@tonic-gate &wclrinit, 1640Sstevel@tonic-gate &wclwinit, 1650Sstevel@tonic-gate }; 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate static int wc_info(dev_info_t *, ddi_info_cmd_t, void *, void **result); 1680Sstevel@tonic-gate static int wc_attach(dev_info_t *, ddi_attach_cmd_t); 1690Sstevel@tonic-gate static dev_info_t *wc_dip; 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(wc_ops, nulldev, nulldev, wc_attach, nodev, nodev, 172*7656SSherry.Moore@Sun.COM wc_info, D_MTPERMOD | D_MP, &wcinfo, ddi_quiesce_not_supported); 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate static void wcreioctl(void *); 1750Sstevel@tonic-gate static void wcioctl(queue_t *, mblk_t *); 1761253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 1770Sstevel@tonic-gate static void wcopoll(void *); 1780Sstevel@tonic-gate static void wconsout(void *); 1791253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 1800Sstevel@tonic-gate static void wcrstrt(void *); 1810Sstevel@tonic-gate static void wcstart(void); 1820Sstevel@tonic-gate static void wc_open_kb_polledio(struct wscons *wc, queue_t *q, mblk_t *mp); 1830Sstevel@tonic-gate static void wc_close_kb_polledio(struct wscons *wc, queue_t *q, mblk_t *mp); 1841762Slt200341 static void wc_polled_putchar(cons_polledio_arg_t arg, unsigned char c); 1851762Slt200341 static boolean_t wc_polled_ischar(cons_polledio_arg_t arg); 1861762Slt200341 static int wc_polled_getchar(cons_polledio_arg_t arg); 1871762Slt200341 static void wc_polled_enter(cons_polledio_arg_t arg); 1881762Slt200341 static void wc_polled_exit(cons_polledio_arg_t arg); 1890Sstevel@tonic-gate static void wc_get_size(struct wscons *wscons); 1901253Slq150181 static void wc_modechg_cb(tem_modechg_cb_arg_t arg); 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate #include <sys/types.h> 1930Sstevel@tonic-gate #include <sys/conf.h> 1940Sstevel@tonic-gate #include <sys/param.h> 1950Sstevel@tonic-gate #include <sys/systm.h> 1960Sstevel@tonic-gate #include <sys/errno.h> 1970Sstevel@tonic-gate #include <sys/modctl.h> 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate static struct dev_ops wc_ops; 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate /* 2020Sstevel@tonic-gate * Debug printing 2030Sstevel@tonic-gate */ 2040Sstevel@tonic-gate #ifndef DPRINTF 2050Sstevel@tonic-gate #ifdef DEBUG 2060Sstevel@tonic-gate /*PRINTFLIKE1*/ 2070Sstevel@tonic-gate static void wc_dprintf(const char *fmt, ...) __KPRINTFLIKE(1); 2080Sstevel@tonic-gate #define DPRINTF(l, m, args) \ 2090Sstevel@tonic-gate (((l) >= wc_errlevel) && ((m) & wc_errmask) ? \ 2101253Slq150181 wc_dprintf args : \ 2110Sstevel@tonic-gate (void) 0) 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* 2140Sstevel@tonic-gate * Severity levels for printing 2150Sstevel@tonic-gate */ 2160Sstevel@tonic-gate #define PRINT_L0 0 /* print every message */ 2170Sstevel@tonic-gate #define PRINT_L1 1 /* debug */ 2180Sstevel@tonic-gate #define PRINT_L2 2 /* quiet */ 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate /* 2210Sstevel@tonic-gate * Masks 2220Sstevel@tonic-gate */ 2230Sstevel@tonic-gate #define PRINT_MASK_ALL 0xFFFFFFFFU 2240Sstevel@tonic-gate uint_t wc_errmask = PRINT_MASK_ALL; 2250Sstevel@tonic-gate uint_t wc_errlevel = PRINT_L2; 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate #else 2280Sstevel@tonic-gate #define DPRINTF(l, m, args) /* NOTHING */ 2290Sstevel@tonic-gate #endif 2300Sstevel@tonic-gate #endif 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate /* 2330Sstevel@tonic-gate * Module linkage information for the kernel. 2340Sstevel@tonic-gate */ 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate static struct modldrv modldrv = { 2370Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a pseudo driver */ 238*7656SSherry.Moore@Sun.COM "Workstation multiplexer Driver 'wc'", 2390Sstevel@tonic-gate &wc_ops, /* driver ops */ 2400Sstevel@tonic-gate }; 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate static struct modlinkage modlinkage = { 2430Sstevel@tonic-gate MODREV_1, 2440Sstevel@tonic-gate &modldrv, 2450Sstevel@tonic-gate NULL 2460Sstevel@tonic-gate }; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate int 2490Sstevel@tonic-gate _init(void) 2500Sstevel@tonic-gate { 2510Sstevel@tonic-gate return (mod_install(&modlinkage)); 2520Sstevel@tonic-gate } 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate int 2550Sstevel@tonic-gate _fini(void) 2560Sstevel@tonic-gate { 2570Sstevel@tonic-gate return (mod_remove(&modlinkage)); 2580Sstevel@tonic-gate } 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate int 2610Sstevel@tonic-gate _info(struct modinfo *modinfop) 2620Sstevel@tonic-gate { 2630Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2640Sstevel@tonic-gate } 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate /*ARGSUSED*/ 2670Sstevel@tonic-gate static int 2680Sstevel@tonic-gate wc_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 2690Sstevel@tonic-gate { 2700Sstevel@tonic-gate if (ddi_create_minor_node(devi, "wscons", S_IFCHR, 2710Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 2720Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 2730Sstevel@tonic-gate return (-1); 2740Sstevel@tonic-gate } 2750Sstevel@tonic-gate wc_dip = devi; 2761253Slq150181 2771253Slq150181 bzero(&(wscons.wc_polledio), sizeof (wscons.wc_polledio)); 2781253Slq150181 2790Sstevel@tonic-gate return (DDI_SUCCESS); 2800Sstevel@tonic-gate } 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate /* ARGSUSED */ 2830Sstevel@tonic-gate static int 2840Sstevel@tonic-gate wc_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 2850Sstevel@tonic-gate void **result) 2860Sstevel@tonic-gate { 2870Sstevel@tonic-gate int error; 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate switch (infocmd) { 2900Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 2910Sstevel@tonic-gate if (wc_dip == NULL) { 2920Sstevel@tonic-gate error = DDI_FAILURE; 2930Sstevel@tonic-gate } else { 2940Sstevel@tonic-gate *result = (void *) wc_dip; 2950Sstevel@tonic-gate error = DDI_SUCCESS; 2960Sstevel@tonic-gate } 2970Sstevel@tonic-gate break; 2980Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 2990Sstevel@tonic-gate *result = (void *)0; 3000Sstevel@tonic-gate error = DDI_SUCCESS; 3010Sstevel@tonic-gate break; 3020Sstevel@tonic-gate default: 3030Sstevel@tonic-gate error = DDI_FAILURE; 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate return (error); 3060Sstevel@tonic-gate } 3070Sstevel@tonic-gate 3081253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 3090Sstevel@tonic-gate /* 3100Sstevel@tonic-gate * Output buffer. Protected by the per-module inner perimeter. 3110Sstevel@tonic-gate */ 3120Sstevel@tonic-gate #define MAXHIWAT 2000 3130Sstevel@tonic-gate static char obuf[MAXHIWAT]; 3141253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate /*ARGSUSED*/ 3170Sstevel@tonic-gate static int 3180Sstevel@tonic-gate wcopen(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *crp) 3190Sstevel@tonic-gate { 3201253Slq150181 static boolean_t polledio_inited = B_FALSE; 3210Sstevel@tonic-gate struct termios *termiosp; 3220Sstevel@tonic-gate int len; 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate if (getminor(*devp) != 0) 3250Sstevel@tonic-gate return (ENXIO); /* sorry, only one per customer */ 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate if (!(wscons.wc_flags & WCS_ISOPEN)) { 3280Sstevel@tonic-gate mutex_init(&wscons.wc_ttycommon.t_excl, NULL, MUTEX_DEFAULT, 3290Sstevel@tonic-gate NULL); 3300Sstevel@tonic-gate wscons.wc_ttycommon.t_iflag = 0; 3310Sstevel@tonic-gate /* 3320Sstevel@tonic-gate * Get the default termios settings (cflag). 3330Sstevel@tonic-gate * These are stored as a property in the 3340Sstevel@tonic-gate * "options" node. 3350Sstevel@tonic-gate */ 3360Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, 3370Sstevel@tonic-gate ddi_root_node(), 0, "ttymodes", 3380Sstevel@tonic-gate (caddr_t)&termiosp, &len) == DDI_PROP_SUCCESS && 3390Sstevel@tonic-gate len == sizeof (struct termios)) { 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate wscons.wc_ttycommon.t_cflag = termiosp->c_cflag; 3420Sstevel@tonic-gate kmem_free(termiosp, len); 3430Sstevel@tonic-gate } else { 3440Sstevel@tonic-gate /* 3450Sstevel@tonic-gate * Gack! Whine about it. 3460Sstevel@tonic-gate */ 3470Sstevel@tonic-gate cmn_err(CE_WARN, 3480Sstevel@tonic-gate "wc: Couldn't get ttymodes property!\n"); 3490Sstevel@tonic-gate } 3500Sstevel@tonic-gate wscons.wc_ttycommon.t_iocpending = NULL; 3510Sstevel@tonic-gate wscons.wc_flags = WCS_ISOPEN; 3520Sstevel@tonic-gate 3531253Slq150181 wscons.wc_dev = *devp; 3540Sstevel@tonic-gate wc_get_size(&wscons); 3550Sstevel@tonic-gate 3561253Slq150181 if (!polledio_inited) { 3571253Slq150181 polledio_inited = B_TRUE; 3580Sstevel@tonic-gate 3591253Slq150181 /* 3601253Slq150181 * Initialize the parts of the polled I/O struct that 3611253Slq150181 * are common to both input and output modes, but which 3621253Slq150181 * don't flag to the upper layers, which if any of the 3631253Slq150181 * two modes are available. We don't know at this point 3641253Slq150181 * if system is configured CONS_KFB, but we will when 3651253Slq150181 * consconfig_dacf asks us with CONSOPENPOLLED I/O. 3661253Slq150181 */ 3671253Slq150181 wscons.wc_polledio.cons_polledio_version = 3686990Sgd78059 CONSPOLLEDIO_V0; 3691253Slq150181 wscons.wc_polledio.cons_polledio_argument = 3706990Sgd78059 (cons_polledio_arg_t)&wscons; 3711253Slq150181 wscons.wc_polledio.cons_polledio_enter = 3726990Sgd78059 wc_polled_enter; 3731253Slq150181 wscons.wc_polledio.cons_polledio_exit = 3746990Sgd78059 wc_polled_exit; 3751253Slq150181 3761253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 3771253Slq150181 /* 3781253Slq150181 * If we're talking directly to a framebuffer, we assume 3791253Slq150181 * that it's a "slow" device, so that rendering should 3801253Slq150181 * be deferred to a timeout or softcall so that we write 3811253Slq150181 * a bunch of characters at once. 3821253Slq150181 */ 3831253Slq150181 wscons.wc_defer_output = prom_stdout_is_framebuffer(); 3841253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 3851253Slq150181 } 3860Sstevel@tonic-gate } 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate if (wscons.wc_ttycommon.t_flags & TS_XCLUDE) { 3890Sstevel@tonic-gate if (secpolicy_excl_open(crp) != 0) { 3900Sstevel@tonic-gate return (EBUSY); 3910Sstevel@tonic-gate } 3920Sstevel@tonic-gate } 3930Sstevel@tonic-gate wscons.wc_ttycommon.t_readq = q; 3940Sstevel@tonic-gate wscons.wc_ttycommon.t_writeq = WR(q); 3950Sstevel@tonic-gate qprocson(q); 3960Sstevel@tonic-gate return (0); 3970Sstevel@tonic-gate } 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate /*ARGSUSED*/ 4000Sstevel@tonic-gate static int 4010Sstevel@tonic-gate wcclose(queue_t *q, int flag, cred_t *crp) 4020Sstevel@tonic-gate { 4030Sstevel@tonic-gate qprocsoff(q); 4040Sstevel@tonic-gate if (wscons.wc_bufcallid != 0) { 4050Sstevel@tonic-gate qunbufcall(q, wscons.wc_bufcallid); 4060Sstevel@tonic-gate wscons.wc_bufcallid = 0; 4070Sstevel@tonic-gate } 4080Sstevel@tonic-gate if (wscons.wc_timeoutid != 0) { 4090Sstevel@tonic-gate (void) quntimeout(q, wscons.wc_timeoutid); 4100Sstevel@tonic-gate wscons.wc_timeoutid = 0; 4110Sstevel@tonic-gate } 4120Sstevel@tonic-gate ttycommon_close(&wscons.wc_ttycommon); 4130Sstevel@tonic-gate wscons.wc_flags = 0; 4140Sstevel@tonic-gate return (0); 4150Sstevel@tonic-gate } 4160Sstevel@tonic-gate 4170Sstevel@tonic-gate /* 4180Sstevel@tonic-gate * Put procedure for upper write queue. 4190Sstevel@tonic-gate * Respond to M_STOP, M_START, M_IOCTL, and M_FLUSH messages here; 4200Sstevel@tonic-gate * queue up M_BREAK, M_DELAY, and M_DATA messages for processing by 4210Sstevel@tonic-gate * the start routine, and then call the start routine; discard 4220Sstevel@tonic-gate * everything else. 4230Sstevel@tonic-gate */ 4240Sstevel@tonic-gate static int 4250Sstevel@tonic-gate wcuwput(queue_t *q, mblk_t *mp) 4260Sstevel@tonic-gate { 4270Sstevel@tonic-gate switch (mp->b_datap->db_type) { 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate case M_STOP: 4300Sstevel@tonic-gate wscons.wc_flags |= WCS_STOPPED; 4310Sstevel@tonic-gate freemsg(mp); 4320Sstevel@tonic-gate break; 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate case M_START: 4350Sstevel@tonic-gate wscons.wc_flags &= ~WCS_STOPPED; 4360Sstevel@tonic-gate wcstart(); 4370Sstevel@tonic-gate freemsg(mp); 4380Sstevel@tonic-gate break; 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate case M_IOCTL: { 4410Sstevel@tonic-gate struct iocblk *iocp; 4420Sstevel@tonic-gate struct linkblk *linkp; 4430Sstevel@tonic-gate 4446990Sgd78059 iocp = (void *)mp->b_rptr; 4450Sstevel@tonic-gate switch (iocp->ioc_cmd) { 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate case I_LINK: /* stupid, but permitted */ 4480Sstevel@tonic-gate case I_PLINK: 4490Sstevel@tonic-gate if (wscons.wc_kbdqueue != NULL) { 4500Sstevel@tonic-gate /* somebody already linked */ 4510Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL); 4520Sstevel@tonic-gate return (0); 4530Sstevel@tonic-gate } 4546990Sgd78059 linkp = (void *)mp->b_cont->b_rptr; 4550Sstevel@tonic-gate wscons.wc_kbdqueue = WR(linkp->l_qbot); 4560Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 4570Sstevel@tonic-gate iocp->ioc_count = 0; 4580Sstevel@tonic-gate wc_open_kb_polledio(&wscons, q, mp); 4590Sstevel@tonic-gate break; 4600Sstevel@tonic-gate 4610Sstevel@tonic-gate case I_UNLINK: /* stupid, but permitted */ 4620Sstevel@tonic-gate case I_PUNLINK: 4636990Sgd78059 linkp = (void *)mp->b_cont->b_rptr; 4640Sstevel@tonic-gate if (wscons.wc_kbdqueue != WR(linkp->l_qbot)) { 4650Sstevel@tonic-gate /* not us */ 4660Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL); 4670Sstevel@tonic-gate return (0); 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 4710Sstevel@tonic-gate iocp->ioc_count = 0; 4720Sstevel@tonic-gate wc_close_kb_polledio(&wscons, q, mp); 4730Sstevel@tonic-gate break; 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate case TCSETSW: 4760Sstevel@tonic-gate case TCSETSF: 4770Sstevel@tonic-gate case TCSETAW: 4780Sstevel@tonic-gate case TCSETAF: 4790Sstevel@tonic-gate case TCSBRK: 4800Sstevel@tonic-gate /* 4810Sstevel@tonic-gate * The changes do not take effect until all 4820Sstevel@tonic-gate * output queued before them is drained. 4830Sstevel@tonic-gate * Put this message on the queue, so that 4840Sstevel@tonic-gate * "wcstart" will see it when it's done 4850Sstevel@tonic-gate * with the output before it. Poke the 4860Sstevel@tonic-gate * start routine, just in case. 4870Sstevel@tonic-gate */ 4880Sstevel@tonic-gate (void) putq(q, mp); 4890Sstevel@tonic-gate wcstart(); 4900Sstevel@tonic-gate break; 4910Sstevel@tonic-gate 4920Sstevel@tonic-gate case CONSSETABORTENABLE: 4930Sstevel@tonic-gate case CONSGETABORTENABLE: 4940Sstevel@tonic-gate case KIOCSDIRECT: 4950Sstevel@tonic-gate if (wscons.wc_kbdqueue != NULL) { 4960Sstevel@tonic-gate (void) putnext(wscons.wc_kbdqueue, mp); 4970Sstevel@tonic-gate break; 4980Sstevel@tonic-gate } 4990Sstevel@tonic-gate /* fall through */ 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate default: 5020Sstevel@tonic-gate /* 5030Sstevel@tonic-gate * Do it now. 5040Sstevel@tonic-gate */ 5050Sstevel@tonic-gate wcioctl(q, mp); 5060Sstevel@tonic-gate break; 5070Sstevel@tonic-gate } 5080Sstevel@tonic-gate break; 5090Sstevel@tonic-gate } 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate case M_FLUSH: 5120Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) { 5130Sstevel@tonic-gate /* 5140Sstevel@tonic-gate * Flush our write queue. 5150Sstevel@tonic-gate */ 5160Sstevel@tonic-gate flushq(q, FLUSHDATA); /* XXX doesn't flush M_DELAY */ 5170Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHW; /* it has been flushed */ 5180Sstevel@tonic-gate } 5190Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) { 5200Sstevel@tonic-gate flushq(RD(q), FLUSHDATA); 5210Sstevel@tonic-gate qreply(q, mp); /* give the read queues a crack at it */ 5220Sstevel@tonic-gate } else 5230Sstevel@tonic-gate freemsg(mp); 5240Sstevel@tonic-gate break; 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate case M_BREAK: 5270Sstevel@tonic-gate /* 5280Sstevel@tonic-gate * Ignore these, as they make no sense. 5290Sstevel@tonic-gate */ 5300Sstevel@tonic-gate freemsg(mp); 5310Sstevel@tonic-gate break; 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate case M_DELAY: 5340Sstevel@tonic-gate case M_DATA: 5350Sstevel@tonic-gate /* 5360Sstevel@tonic-gate * Queue the message up to be transmitted, 5370Sstevel@tonic-gate * and poke the start routine. 5380Sstevel@tonic-gate */ 5390Sstevel@tonic-gate (void) putq(q, mp); 5400Sstevel@tonic-gate wcstart(); 5410Sstevel@tonic-gate break; 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate default: 5440Sstevel@tonic-gate /* 5450Sstevel@tonic-gate * "No, I don't want a subscription to Chain Store Age, 5460Sstevel@tonic-gate * thank you anyway." 5470Sstevel@tonic-gate */ 5480Sstevel@tonic-gate freemsg(mp); 5490Sstevel@tonic-gate break; 5500Sstevel@tonic-gate } 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate return (0); 5530Sstevel@tonic-gate } 5540Sstevel@tonic-gate 5550Sstevel@tonic-gate /* 5560Sstevel@tonic-gate * Retry an "ioctl", now that "qbufcall" claims we may be able to allocate 5570Sstevel@tonic-gate * the buffer we need. 5580Sstevel@tonic-gate */ 5590Sstevel@tonic-gate /*ARGSUSED*/ 5600Sstevel@tonic-gate static void 5610Sstevel@tonic-gate wcreioctl(void *arg) 5620Sstevel@tonic-gate { 5630Sstevel@tonic-gate queue_t *q; 5640Sstevel@tonic-gate mblk_t *mp; 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate wscons.wc_bufcallid = 0; 5670Sstevel@tonic-gate q = wscons.wc_ttycommon.t_writeq; 5680Sstevel@tonic-gate if ((mp = wscons.wc_ttycommon.t_iocpending) != NULL) { 5690Sstevel@tonic-gate /* not pending any more */ 5700Sstevel@tonic-gate wscons.wc_ttycommon.t_iocpending = NULL; 5710Sstevel@tonic-gate wcioctl(q, mp); 5720Sstevel@tonic-gate } 5730Sstevel@tonic-gate } 5740Sstevel@tonic-gate 5751253Slq150181 static int 5761253Slq150181 wc_getterm(mblk_t *mp) 5771253Slq150181 { 5781253Slq150181 char *term; 5791253Slq150181 intptr_t arg; 5806990Sgd78059 int flag = ((struct iocblk *)(void *)mp->b_rptr)->ioc_flag; 5811253Slq150181 5821253Slq150181 STRUCT_DECL(cons_getterm, wcterm); 5831253Slq150181 STRUCT_INIT(wcterm, flag); 5841253Slq150181 5856990Sgd78059 arg = *((intptr_t *)(void *)mp->b_cont->b_rptr); 5861253Slq150181 5871253Slq150181 if (ddi_copyin((void *)arg, STRUCT_BUF(wcterm), 5881253Slq150181 STRUCT_SIZE(wcterm), flag) != 0) { 5891253Slq150181 return (EFAULT); 5901253Slq150181 } 5911253Slq150181 5921253Slq150181 if (consmode == CONS_FW) { 5931253Slq150181 /* PROM terminal emulator */ 5941253Slq150181 term = "sun"; 5951253Slq150181 } else { 5961253Slq150181 /* Kernel terminal emulator */ 5971253Slq150181 ASSERT(consmode == CONS_KFB); 5981253Slq150181 term = "sun-color"; 5991253Slq150181 } 6001253Slq150181 6011253Slq150181 if (STRUCT_FGET(wcterm, cn_term_len) < 6021253Slq150181 strlen(term) + 1) { 6031253Slq150181 return (EOVERFLOW); 6041253Slq150181 } 6051253Slq150181 6061253Slq150181 if (ddi_copyout(term, 6071253Slq150181 STRUCT_FGETP(wcterm, cn_term_type), 6081253Slq150181 strlen(term) + 1, flag) != 0) { 6091253Slq150181 return (EFAULT); 6101253Slq150181 } 6111253Slq150181 6121253Slq150181 return (0); 6131253Slq150181 } 6141253Slq150181 6150Sstevel@tonic-gate /* 6160Sstevel@tonic-gate * Process an "ioctl" message sent down to us. 6170Sstevel@tonic-gate */ 6180Sstevel@tonic-gate static void 6190Sstevel@tonic-gate wcioctl(queue_t *q, mblk_t *mp) 6200Sstevel@tonic-gate { 6210Sstevel@tonic-gate struct iocblk *iocp; 6220Sstevel@tonic-gate size_t datasize; 6230Sstevel@tonic-gate int error; 6241253Slq150181 long len; 6250Sstevel@tonic-gate 6266990Sgd78059 iocp = (void *)mp->b_rptr; 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate switch (iocp->ioc_cmd) { 6290Sstevel@tonic-gate case TIOCSWINSZ: 6300Sstevel@tonic-gate /* 6310Sstevel@tonic-gate * Ignore all attempts to set the screen size; the 6320Sstevel@tonic-gate * value in the EEPROM is guaranteed (modulo PROM bugs) 6330Sstevel@tonic-gate * to be the value used by the PROM monitor code, so it 6340Sstevel@tonic-gate * is by definition correct. Many programs (e.g., 6350Sstevel@tonic-gate * "login" and "tset") will attempt to reset the size 6360Sstevel@tonic-gate * to (0, 0) or (34, 80), neither of which is 6370Sstevel@tonic-gate * necessarily correct. 6380Sstevel@tonic-gate * We just ACK the message, so as not to disturb 6390Sstevel@tonic-gate * programs that set the sizes. 6400Sstevel@tonic-gate */ 6410Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */ 6420Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 6430Sstevel@tonic-gate qreply(q, mp); 6440Sstevel@tonic-gate return; 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate case CONSOPENPOLLEDIO: 6470Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 6486990Sgd78059 ("wcioctl: CONSOPENPOLLEDIO\n")); 6490Sstevel@tonic-gate 6500Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct cons_polledio *)); 6510Sstevel@tonic-gate if (error != 0) { 6520Sstevel@tonic-gate miocnak(q, mp, 0, error); 6530Sstevel@tonic-gate return; 6540Sstevel@tonic-gate } 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate /* 6571253Slq150181 * We are given an appropriate-sized data block, 6581253Slq150181 * and return a pointer to our structure in it. 6590Sstevel@tonic-gate */ 6601253Slq150181 if (consmode == CONS_KFB) 6611253Slq150181 wscons.wc_polledio.cons_polledio_putchar = 6621253Slq150181 wc_polled_putchar; 6636990Sgd78059 *(struct cons_polledio **)(void *)mp->b_cont->b_rptr = 6646990Sgd78059 &wscons.wc_polledio; 6650Sstevel@tonic-gate 6661253Slq150181 mp->b_datap->db_type = M_IOCACK; 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate qreply(q, mp); 6690Sstevel@tonic-gate break; 6700Sstevel@tonic-gate 6711253Slq150181 case CONS_GETTERM: 6721253Slq150181 if ((error = wc_getterm(mp)) != 0) 6731253Slq150181 miocnak(q, mp, 0, error); 6741253Slq150181 else 6751253Slq150181 miocack(q, mp, 0, 0); 6761253Slq150181 return; 6771253Slq150181 6780Sstevel@tonic-gate case WC_OPEN_FB: 6790Sstevel@tonic-gate /* 6800Sstevel@tonic-gate * Start out pessimistic, so that we can just jump to 6810Sstevel@tonic-gate * the reply to bail out. 6820Sstevel@tonic-gate */ 6830Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 6840Sstevel@tonic-gate 6850Sstevel@tonic-gate /* 6860Sstevel@tonic-gate * First test: really, this should be done only from 6870Sstevel@tonic-gate * inside the kernel. Unfortunately, that information 6880Sstevel@tonic-gate * doesn't seem to be available in a streams ioctl, 6890Sstevel@tonic-gate * so restrict it to root only. (Perhaps we could check 6900Sstevel@tonic-gate * for ioc_cr == kcred.) 6910Sstevel@tonic-gate */ 6920Sstevel@tonic-gate if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0) 6930Sstevel@tonic-gate goto open_fail; 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate /* 6960Sstevel@tonic-gate * Some miscellaneous checks... 6970Sstevel@tonic-gate */ 6980Sstevel@tonic-gate iocp->ioc_error = EINVAL; 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate /* 7010Sstevel@tonic-gate * If we're already open, fail. 7020Sstevel@tonic-gate */ 7030Sstevel@tonic-gate if (wscons.wc_tem != NULL) 7040Sstevel@tonic-gate goto open_fail; 7050Sstevel@tonic-gate 7060Sstevel@tonic-gate /* 7070Sstevel@tonic-gate * If we don't have exactly one continuation block, fail. 7080Sstevel@tonic-gate */ 7096990Sgd78059 if (mp->b_cont == NULL || mp->b_cont->b_cont != NULL) 7100Sstevel@tonic-gate goto open_fail; 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate /* 7130Sstevel@tonic-gate * If there's no null terminator in the string, fail. 7140Sstevel@tonic-gate */ 7156990Sgd78059 len = MBLKL(mp->b_cont); 7160Sstevel@tonic-gate if (memchr(mp->b_cont->b_rptr, 0, len) == NULL) 7170Sstevel@tonic-gate goto open_fail; 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate /* 7200Sstevel@tonic-gate * NOTE: should eventually get default 7210Sstevel@tonic-gate * dimensions from a property, e.g. screen-#rows. 7220Sstevel@tonic-gate */ 7230Sstevel@tonic-gate iocp->ioc_error = tem_init(&wscons.wc_tem, 7246990Sgd78059 (char *)mp->b_cont->b_rptr, iocp->ioc_cr); 7250Sstevel@tonic-gate /* 7260Sstevel@tonic-gate * Of course, if the terminal emulator initialization 7270Sstevel@tonic-gate * failed, fail. 7280Sstevel@tonic-gate */ 7290Sstevel@tonic-gate if (iocp->ioc_error != 0) 7300Sstevel@tonic-gate goto open_fail; 7310Sstevel@tonic-gate 7321253Slq150181 tem_register_modechg_cb(wscons.wc_tem, wc_modechg_cb, 7336990Sgd78059 (tem_modechg_cb_arg_t)&wscons); 7341253Slq150181 7350Sstevel@tonic-gate /* 7360Sstevel@tonic-gate * Refresh terminal size with info from terminal emulator. 7370Sstevel@tonic-gate */ 7380Sstevel@tonic-gate wc_get_size(&wscons); 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate /* 7410Sstevel@tonic-gate * ... and succeed. 7420Sstevel@tonic-gate */ 7430Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate open_fail: 7460Sstevel@tonic-gate qreply(q, mp); 7470Sstevel@tonic-gate break; 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate case WC_CLOSE_FB: 7500Sstevel@tonic-gate /* 7510Sstevel@tonic-gate * There's nothing that can call this, so it's not 7520Sstevel@tonic-gate * really implemented. 7530Sstevel@tonic-gate */ 7540Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 7550Sstevel@tonic-gate /* 7560Sstevel@tonic-gate * However, if it were implemented, it would clearly 7570Sstevel@tonic-gate * be root-only. 7580Sstevel@tonic-gate */ 7590Sstevel@tonic-gate if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0) 7600Sstevel@tonic-gate goto close_fail; 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate iocp->ioc_error = EINVAL; 7630Sstevel@tonic-gate 7640Sstevel@tonic-gate close_fail: 7650Sstevel@tonic-gate qreply(q, mp); 7660Sstevel@tonic-gate break; 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate default: 7690Sstevel@tonic-gate 7700Sstevel@tonic-gate /* 7710Sstevel@tonic-gate * The only way in which "ttycommon_ioctl" can fail is 7720Sstevel@tonic-gate * if the "ioctl" requires a response containing data 7730Sstevel@tonic-gate * to be returned to the user, and no mblk could be 7740Sstevel@tonic-gate * allocated for the data. No such "ioctl" alters our 7750Sstevel@tonic-gate * state. Thus, we always go ahead and do any 7760Sstevel@tonic-gate * state-changes the "ioctl" calls for. If we couldn't 7770Sstevel@tonic-gate * allocate the data, "ttycommon_ioctl" has stashed the 7780Sstevel@tonic-gate * "ioctl" away safely, so we just call "qbufcall" to 7790Sstevel@tonic-gate * request that we be called back when we stand a 7800Sstevel@tonic-gate * better chance of allocating the data. 7810Sstevel@tonic-gate */ 7820Sstevel@tonic-gate datasize = ttycommon_ioctl(&wscons.wc_ttycommon, q, mp, &error); 7830Sstevel@tonic-gate if (datasize != 0) { 7840Sstevel@tonic-gate if (wscons.wc_bufcallid != 0) 7850Sstevel@tonic-gate qunbufcall(q, wscons.wc_bufcallid); 7860Sstevel@tonic-gate wscons.wc_bufcallid = qbufcall(q, datasize, BPRI_HI, 7870Sstevel@tonic-gate wcreioctl, NULL); 7880Sstevel@tonic-gate return; 7890Sstevel@tonic-gate } 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate if (error < 0) { 7920Sstevel@tonic-gate if (iocp->ioc_cmd == TCSBRK) 7930Sstevel@tonic-gate error = 0; 7940Sstevel@tonic-gate else 7950Sstevel@tonic-gate error = EINVAL; 7960Sstevel@tonic-gate } 7970Sstevel@tonic-gate if (error != 0) { 7980Sstevel@tonic-gate iocp->ioc_error = error; 7990Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 8000Sstevel@tonic-gate } 8010Sstevel@tonic-gate qreply(q, mp); 8020Sstevel@tonic-gate break; 8030Sstevel@tonic-gate } 8040Sstevel@tonic-gate } 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate /* 8070Sstevel@tonic-gate * This function gets the polled I/O structures from the lower 8080Sstevel@tonic-gate * keyboard driver. If any initialization or resource allocation 8090Sstevel@tonic-gate * needs to be done by the lower driver, it will be done when 8100Sstevel@tonic-gate * the lower driver services this message. 8110Sstevel@tonic-gate */ 8120Sstevel@tonic-gate static void 8130Sstevel@tonic-gate wc_open_kb_polledio(struct wscons *wscons, queue_t *q, mblk_t *mp) 8140Sstevel@tonic-gate { 8150Sstevel@tonic-gate mblk_t *mp2; 8160Sstevel@tonic-gate struct iocblk *iocp; 8170Sstevel@tonic-gate 8180Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 8196990Sgd78059 ("wc_open_kb_polledio: sending CONSOPENPOLLEDIO\n")); 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate mp2 = mkiocb(CONSOPENPOLLEDIO); 8220Sstevel@tonic-gate 8230Sstevel@tonic-gate if (mp2 == NULL) { 8240Sstevel@tonic-gate /* 8250Sstevel@tonic-gate * If we can't get an mblk, then wait for it. 8260Sstevel@tonic-gate */ 8270Sstevel@tonic-gate goto nomem; 8280Sstevel@tonic-gate } 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI); 8310Sstevel@tonic-gate 8320Sstevel@tonic-gate if (mp2->b_cont == NULL) { 8330Sstevel@tonic-gate /* 8340Sstevel@tonic-gate * If we can't get an mblk, then wait for it, and release 8350Sstevel@tonic-gate * the mblk that we have already allocated. 8360Sstevel@tonic-gate */ 8370Sstevel@tonic-gate freemsg(mp2); 8380Sstevel@tonic-gate goto nomem; 8390Sstevel@tonic-gate } 8400Sstevel@tonic-gate 8416990Sgd78059 iocp = (void *)mp2->b_rptr; 8420Sstevel@tonic-gate 8430Sstevel@tonic-gate iocp->ioc_count = sizeof (struct cons_polledio *); 8440Sstevel@tonic-gate mp2->b_cont->b_wptr = mp2->b_cont->b_rptr + 8456990Sgd78059 sizeof (struct cons_polledio *); 8460Sstevel@tonic-gate 8470Sstevel@tonic-gate wscons->wc_pending_link = mp; 8480Sstevel@tonic-gate wscons->wc_kb_getpolledio_id = iocp->ioc_id; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate putnext(wscons->wc_kbdqueue, mp2); 8510Sstevel@tonic-gate 8520Sstevel@tonic-gate return; 8530Sstevel@tonic-gate 8540Sstevel@tonic-gate nomem: 8556990Sgd78059 iocp = (void *)mp->b_rptr; 8560Sstevel@tonic-gate iocp->ioc_error = ENOMEM; 8570Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 8580Sstevel@tonic-gate qreply(q, mp); 8590Sstevel@tonic-gate } 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate /* 8620Sstevel@tonic-gate * This function releases the polled I/O structures from the lower 8630Sstevel@tonic-gate * keyboard driver. If any de-initialization needs to be done, or 8640Sstevel@tonic-gate * any resources need to be released, it will be done when the lower 8650Sstevel@tonic-gate * driver services this message. 8660Sstevel@tonic-gate */ 8670Sstevel@tonic-gate static void 8680Sstevel@tonic-gate wc_close_kb_polledio(struct wscons *wscons, queue_t *q, mblk_t *mp) 8690Sstevel@tonic-gate { 8700Sstevel@tonic-gate mblk_t *mp2; 8710Sstevel@tonic-gate struct iocblk *iocp; 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 8746990Sgd78059 ("wc_close_kb_polledio: sending CONSCLOSEPOLLEDIO\n")); 8750Sstevel@tonic-gate 8760Sstevel@tonic-gate mp2 = mkiocb(CONSCLOSEPOLLEDIO); 8770Sstevel@tonic-gate 8780Sstevel@tonic-gate if (mp2 == NULL) { 8790Sstevel@tonic-gate /* 8800Sstevel@tonic-gate * If we can't get an mblk, then wait for it. 8810Sstevel@tonic-gate */ 8820Sstevel@tonic-gate goto nomem; 8830Sstevel@tonic-gate } 8840Sstevel@tonic-gate 8850Sstevel@tonic-gate mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI); 8860Sstevel@tonic-gate 8870Sstevel@tonic-gate if (mp2->b_cont == NULL) { 8880Sstevel@tonic-gate /* 8890Sstevel@tonic-gate * If we can't get an mblk, then wait for it, and release 8900Sstevel@tonic-gate * the mblk that we have already allocated. 8910Sstevel@tonic-gate */ 8920Sstevel@tonic-gate freemsg(mp2); 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate goto nomem; 8950Sstevel@tonic-gate } 8960Sstevel@tonic-gate 8976990Sgd78059 iocp = (void *)mp2->b_rptr; 8980Sstevel@tonic-gate 8990Sstevel@tonic-gate iocp->ioc_count = 0; 9000Sstevel@tonic-gate 9010Sstevel@tonic-gate wscons->wc_pending_link = mp; 9020Sstevel@tonic-gate wscons->wc_kb_getpolledio_id = iocp->ioc_id; 9030Sstevel@tonic-gate 9040Sstevel@tonic-gate putnext(wscons->wc_kbdqueue, mp2); 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate return; 9070Sstevel@tonic-gate 9080Sstevel@tonic-gate nomem: 9096990Sgd78059 iocp = (void *)mp->b_rptr; 9100Sstevel@tonic-gate iocp->ioc_error = ENOMEM; 9110Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 9120Sstevel@tonic-gate qreply(q, mp); 9130Sstevel@tonic-gate } 9140Sstevel@tonic-gate 9151253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 9160Sstevel@tonic-gate /* ARGSUSED */ 9170Sstevel@tonic-gate static void 9180Sstevel@tonic-gate wcopoll(void *arg) 9190Sstevel@tonic-gate { 9200Sstevel@tonic-gate queue_t *q; 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate q = wscons.wc_ttycommon.t_writeq; 9230Sstevel@tonic-gate wscons.wc_timeoutid = 0; 9240Sstevel@tonic-gate /* See if we can continue output */ 9250Sstevel@tonic-gate if ((wscons.wc_flags & WCS_BUSY) && wscons.wc_pendc != -1) { 9260Sstevel@tonic-gate if (prom_mayput((char)wscons.wc_pendc) == 0) { 9270Sstevel@tonic-gate wscons.wc_pendc = -1; 9280Sstevel@tonic-gate wscons.wc_flags &= ~WCS_BUSY; 9290Sstevel@tonic-gate if (!(wscons.wc_flags&(WCS_DELAY|WCS_STOPPED))) 9300Sstevel@tonic-gate wcstart(); 9310Sstevel@tonic-gate } else 9320Sstevel@tonic-gate wscons.wc_timeoutid = qtimeout(q, wcopoll, NULL, 1); 9330Sstevel@tonic-gate } 9340Sstevel@tonic-gate } 9351253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate /* 9380Sstevel@tonic-gate * Restart output on the console after a timeout. 9390Sstevel@tonic-gate */ 9400Sstevel@tonic-gate /* ARGSUSED */ 9410Sstevel@tonic-gate static void 9420Sstevel@tonic-gate wcrstrt(void *arg) 9430Sstevel@tonic-gate { 9440Sstevel@tonic-gate ASSERT(wscons.wc_ttycommon.t_writeq != NULL); 9450Sstevel@tonic-gate wscons.wc_flags &= ~WCS_DELAY; 9460Sstevel@tonic-gate wcstart(); 9470Sstevel@tonic-gate } 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate /* 9500Sstevel@tonic-gate * Start console output 9510Sstevel@tonic-gate */ 9520Sstevel@tonic-gate static void 9530Sstevel@tonic-gate wcstart(void) 9540Sstevel@tonic-gate { 9551253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 9560Sstevel@tonic-gate int c; 9570Sstevel@tonic-gate ssize_t cc; 9581253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 9590Sstevel@tonic-gate queue_t *q; 9600Sstevel@tonic-gate mblk_t *bp; 9610Sstevel@tonic-gate mblk_t *nbp; 9620Sstevel@tonic-gate 9630Sstevel@tonic-gate /* 9640Sstevel@tonic-gate * If we're waiting for something to happen (delay timeout to 9650Sstevel@tonic-gate * expire, current transmission to finish, output to be 9660Sstevel@tonic-gate * restarted, output to finish draining), don't grab anything 9670Sstevel@tonic-gate * new. 9680Sstevel@tonic-gate */ 9690Sstevel@tonic-gate if (wscons.wc_flags & (WCS_DELAY|WCS_BUSY|WCS_STOPPED)) 9701253Slq150181 return; 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate q = wscons.wc_ttycommon.t_writeq; 9730Sstevel@tonic-gate /* 9740Sstevel@tonic-gate * assumes that we have been called by whoever holds the 9750Sstevel@tonic-gate * exclusionary lock on the write-side queue (protects 9760Sstevel@tonic-gate * wc_flags and wc_pendc). 9770Sstevel@tonic-gate */ 9780Sstevel@tonic-gate for (;;) { 9790Sstevel@tonic-gate if ((bp = getq(q)) == NULL) 9801253Slq150181 return; /* nothing to transmit */ 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate /* 9830Sstevel@tonic-gate * We have a new message to work on. 9840Sstevel@tonic-gate * Check whether it's a delay or an ioctl (the latter 9850Sstevel@tonic-gate * occurs if the ioctl in question was waiting for the output 9860Sstevel@tonic-gate * to drain). If it's one of those, process it immediately. 9870Sstevel@tonic-gate */ 9880Sstevel@tonic-gate switch (bp->b_datap->db_type) { 9890Sstevel@tonic-gate 9900Sstevel@tonic-gate case M_DELAY: 9910Sstevel@tonic-gate /* 9920Sstevel@tonic-gate * Arrange for "wcrstrt" to be called when the 9930Sstevel@tonic-gate * delay expires; it will turn WCS_DELAY off, 9940Sstevel@tonic-gate * and call "wcstart" to grab the next message. 9950Sstevel@tonic-gate */ 9960Sstevel@tonic-gate if (wscons.wc_timeoutid != 0) 9970Sstevel@tonic-gate (void) quntimeout(q, wscons.wc_timeoutid); 9980Sstevel@tonic-gate wscons.wc_timeoutid = qtimeout(q, wcrstrt, NULL, 9990Sstevel@tonic-gate (clock_t)(*(unsigned char *)bp->b_rptr + 6)); 10000Sstevel@tonic-gate wscons.wc_flags |= WCS_DELAY; 10010Sstevel@tonic-gate freemsg(bp); 10021253Slq150181 return; /* wait for this to finish */ 10030Sstevel@tonic-gate 10040Sstevel@tonic-gate case M_IOCTL: 10050Sstevel@tonic-gate /* 10060Sstevel@tonic-gate * This ioctl was waiting for the output ahead of 10070Sstevel@tonic-gate * it to drain; obviously, it has. Do it, and 10080Sstevel@tonic-gate * then grab the next message after it. 10090Sstevel@tonic-gate */ 10100Sstevel@tonic-gate wcioctl(q, bp); 10110Sstevel@tonic-gate continue; 10120Sstevel@tonic-gate } 10130Sstevel@tonic-gate 10141253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 10151253Slq150181 if (consmode == CONS_KFB) { 10161253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 10171253Slq150181 if (wscons.wc_tem != NULL) { 10181253Slq150181 for (nbp = bp; nbp != NULL; nbp = nbp->b_cont) { 10191253Slq150181 if (nbp->b_wptr > nbp->b_rptr) { 10201253Slq150181 (void) tem_write(wscons.wc_tem, 10211253Slq150181 nbp->b_rptr, 10226990Sgd78059 MBLKL(nbp), 10231253Slq150181 kcred); 10241253Slq150181 } 10251253Slq150181 } 10261253Slq150181 freemsg(bp); 10271253Slq150181 } 10281253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 10291253Slq150181 continue; 10300Sstevel@tonic-gate } 10311253Slq150181 10321253Slq150181 /* consmode = CONS_FW */ 10336990Sgd78059 if ((cc = MBLKL(bp)) == 0) { 10340Sstevel@tonic-gate freemsg(bp); 10350Sstevel@tonic-gate continue; 10360Sstevel@tonic-gate } 10370Sstevel@tonic-gate /* 10380Sstevel@tonic-gate * Direct output to the frame buffer if this device 10390Sstevel@tonic-gate * is not the "hardware" console. 10400Sstevel@tonic-gate */ 10410Sstevel@tonic-gate if (wscons.wc_defer_output) { 10420Sstevel@tonic-gate /* 10430Sstevel@tonic-gate * Never do output here; 10440Sstevel@tonic-gate * it takes forever. 10450Sstevel@tonic-gate */ 10460Sstevel@tonic-gate wscons.wc_flags |= WCS_BUSY; 10470Sstevel@tonic-gate wscons.wc_pendc = -1; 10480Sstevel@tonic-gate (void) putbq(q, bp); 10491253Slq150181 if (q->q_count > 128) { /* do it soon */ 10500Sstevel@tonic-gate softcall(wconsout, NULL); 10511253Slq150181 } else { /* wait a bit */ 10520Sstevel@tonic-gate if (wscons.wc_timeoutid != 0) 10530Sstevel@tonic-gate (void) quntimeout(q, 10540Sstevel@tonic-gate wscons.wc_timeoutid); 10550Sstevel@tonic-gate wscons.wc_timeoutid = qtimeout(q, wconsout, 10560Sstevel@tonic-gate NULL, hz / 30); 10570Sstevel@tonic-gate } 10581253Slq150181 return; 10590Sstevel@tonic-gate } 10600Sstevel@tonic-gate for (;;) { 10610Sstevel@tonic-gate c = *bp->b_rptr++; 10620Sstevel@tonic-gate cc--; 10630Sstevel@tonic-gate if (prom_mayput((char)c) != 0) { 10640Sstevel@tonic-gate wscons.wc_flags |= WCS_BUSY; 10650Sstevel@tonic-gate wscons.wc_pendc = c; 10660Sstevel@tonic-gate if (wscons.wc_timeoutid != 0) 10670Sstevel@tonic-gate (void) quntimeout(q, 10680Sstevel@tonic-gate wscons.wc_timeoutid); 10690Sstevel@tonic-gate wscons.wc_timeoutid = qtimeout(q, wcopoll, 10700Sstevel@tonic-gate NULL, 1); 10710Sstevel@tonic-gate if (bp != NULL) 10721253Slq150181 /* not done with this message yet */ 10730Sstevel@tonic-gate (void) putbq(q, bp); 10741253Slq150181 return; 10750Sstevel@tonic-gate } 10760Sstevel@tonic-gate while (cc <= 0) { 10770Sstevel@tonic-gate nbp = bp; 10780Sstevel@tonic-gate bp = bp->b_cont; 10790Sstevel@tonic-gate freeb(nbp); 10800Sstevel@tonic-gate if (bp == NULL) 10811253Slq150181 return; 10826990Sgd78059 cc = MBLKL(bp); 10830Sstevel@tonic-gate } 10840Sstevel@tonic-gate } 10851253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 10860Sstevel@tonic-gate } 10870Sstevel@tonic-gate } 10880Sstevel@tonic-gate 10891253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 10900Sstevel@tonic-gate /* 10910Sstevel@tonic-gate * Output to frame buffer console. 10920Sstevel@tonic-gate * It takes a long time to scroll. 10930Sstevel@tonic-gate */ 10940Sstevel@tonic-gate /* ARGSUSED */ 10950Sstevel@tonic-gate static void 10960Sstevel@tonic-gate wconsout(void *dummy) 10970Sstevel@tonic-gate { 10980Sstevel@tonic-gate uchar_t *cp; 10990Sstevel@tonic-gate ssize_t cc; 11000Sstevel@tonic-gate queue_t *q; 11010Sstevel@tonic-gate mblk_t *bp; 11020Sstevel@tonic-gate mblk_t *nbp; 11030Sstevel@tonic-gate char *current_position; 11040Sstevel@tonic-gate ssize_t bytes_left; 11050Sstevel@tonic-gate 11060Sstevel@tonic-gate if ((q = wscons.wc_ttycommon.t_writeq) == NULL) { 11070Sstevel@tonic-gate return; /* not attached to a stream */ 11080Sstevel@tonic-gate } 11090Sstevel@tonic-gate 11100Sstevel@tonic-gate /* 11110Sstevel@tonic-gate * Set up to copy up to MAXHIWAT bytes. 11120Sstevel@tonic-gate */ 11130Sstevel@tonic-gate current_position = &obuf[0]; 11140Sstevel@tonic-gate bytes_left = MAXHIWAT; 11150Sstevel@tonic-gate while ((bp = getq(q)) != NULL) { 11160Sstevel@tonic-gate if (bp->b_datap->db_type == M_IOCTL) { 11170Sstevel@tonic-gate /* 11180Sstevel@tonic-gate * This ioctl was waiting for the output ahead of 11190Sstevel@tonic-gate * it to drain; obviously, it has. Put it back 11200Sstevel@tonic-gate * so that "wcstart" can handle it, and transmit 11210Sstevel@tonic-gate * what we've got. 11220Sstevel@tonic-gate */ 11230Sstevel@tonic-gate (void) putbq(q, bp); 11240Sstevel@tonic-gate goto transmit; 11250Sstevel@tonic-gate } 11260Sstevel@tonic-gate 11270Sstevel@tonic-gate do { 11280Sstevel@tonic-gate cp = bp->b_rptr; 11296990Sgd78059 cc = MBLKL(bp); 11300Sstevel@tonic-gate while (cc != 0) { 11310Sstevel@tonic-gate if (bytes_left == 0) { 11320Sstevel@tonic-gate /* 11330Sstevel@tonic-gate * Out of buffer space; put this 11340Sstevel@tonic-gate * buffer back on the queue, and 11350Sstevel@tonic-gate * transmit what we have. 11360Sstevel@tonic-gate */ 11370Sstevel@tonic-gate bp->b_rptr = cp; 11380Sstevel@tonic-gate (void) putbq(q, bp); 11390Sstevel@tonic-gate goto transmit; 11400Sstevel@tonic-gate } 11410Sstevel@tonic-gate *current_position++ = *cp++; 11420Sstevel@tonic-gate cc--; 11430Sstevel@tonic-gate bytes_left--; 11440Sstevel@tonic-gate } 11450Sstevel@tonic-gate nbp = bp; 11460Sstevel@tonic-gate bp = bp->b_cont; 11470Sstevel@tonic-gate freeb(nbp); 11480Sstevel@tonic-gate } while (bp != NULL); 11490Sstevel@tonic-gate } 11500Sstevel@tonic-gate 11510Sstevel@tonic-gate transmit: 11520Sstevel@tonic-gate if ((cc = MAXHIWAT - bytes_left) != 0) 11530Sstevel@tonic-gate console_puts(obuf, cc); 11540Sstevel@tonic-gate 11550Sstevel@tonic-gate wscons.wc_flags &= ~WCS_BUSY; 11560Sstevel@tonic-gate wcstart(); 11570Sstevel@tonic-gate } 11581253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 11590Sstevel@tonic-gate 11600Sstevel@tonic-gate /* 11610Sstevel@tonic-gate * Put procedure for lower read queue. 11620Sstevel@tonic-gate * Pass everything up to queue above "upper half". 11630Sstevel@tonic-gate */ 11640Sstevel@tonic-gate static int 11650Sstevel@tonic-gate wclrput(queue_t *q, mblk_t *mp) 11660Sstevel@tonic-gate { 11670Sstevel@tonic-gate queue_t *upq; 11680Sstevel@tonic-gate struct iocblk *iocp; 11690Sstevel@tonic-gate 11700Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 11716990Sgd78059 ("wclrput: wclrput type = 0x%x\n", mp->b_datap->db_type)); 11720Sstevel@tonic-gate 11730Sstevel@tonic-gate switch (mp->b_datap->db_type) { 11740Sstevel@tonic-gate 11750Sstevel@tonic-gate case M_FLUSH: 11760Sstevel@tonic-gate if (*mp->b_rptr == FLUSHW || *mp->b_rptr == FLUSHRW) { 11770Sstevel@tonic-gate /* 11780Sstevel@tonic-gate * Flush our write queue. 11790Sstevel@tonic-gate */ 11800Sstevel@tonic-gate /* XXX doesn't flush M_DELAY */ 11810Sstevel@tonic-gate flushq(WR(q), FLUSHDATA); 11820Sstevel@tonic-gate *mp->b_rptr = FLUSHR; /* it has been flushed */ 11830Sstevel@tonic-gate } 11840Sstevel@tonic-gate if (*mp->b_rptr == FLUSHR || *mp->b_rptr == FLUSHRW) { 11850Sstevel@tonic-gate flushq(q, FLUSHDATA); 11860Sstevel@tonic-gate *mp->b_rptr = FLUSHW; /* it has been flushed */ 11870Sstevel@tonic-gate qreply(q, mp); /* give the read queues a crack at it */ 11880Sstevel@tonic-gate } else 11890Sstevel@tonic-gate freemsg(mp); 11900Sstevel@tonic-gate break; 11910Sstevel@tonic-gate 11920Sstevel@tonic-gate case M_DATA: 11930Sstevel@tonic-gate if ((upq = wscons.wc_ttycommon.t_readq) != NULL) { 11940Sstevel@tonic-gate if (!canput(upq->q_next)) { 11950Sstevel@tonic-gate ttycommon_qfull(&wscons.wc_ttycommon, upq); 11960Sstevel@tonic-gate wcstart(); 11970Sstevel@tonic-gate freemsg(mp); 11980Sstevel@tonic-gate } else 11990Sstevel@tonic-gate putnext(upq, mp); 12000Sstevel@tonic-gate } else 12010Sstevel@tonic-gate freemsg(mp); 12020Sstevel@tonic-gate break; 12030Sstevel@tonic-gate 12040Sstevel@tonic-gate case M_IOCACK: 12050Sstevel@tonic-gate case M_IOCNAK: 12066990Sgd78059 iocp = (void *)mp->b_rptr; 12070Sstevel@tonic-gate if (wscons.wc_pending_link != NULL && 12080Sstevel@tonic-gate iocp->ioc_id == wscons.wc_kb_getpolledio_id) { 12090Sstevel@tonic-gate switch (mp->b_datap->db_type) { 12100Sstevel@tonic-gate 12110Sstevel@tonic-gate case M_IOCACK: 12120Sstevel@tonic-gate switch (iocp->ioc_cmd) { 12130Sstevel@tonic-gate 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate case CONSOPENPOLLEDIO: 12160Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 12176990Sgd78059 ("wclrput: " 12186990Sgd78059 "ACK CONSOPENPOLLEDIO\n")); 12190Sstevel@tonic-gate wscons.wc_kb_polledio = 12206990Sgd78059 *(struct cons_polledio **)(void *) 12211253Slq150181 mp->b_cont->b_rptr; 12221253Slq150181 wscons.wc_polledio. 12231253Slq150181 cons_polledio_getchar = 12246990Sgd78059 wc_polled_getchar; 12251253Slq150181 wscons.wc_polledio. 12261253Slq150181 cons_polledio_ischar = 12276990Sgd78059 wc_polled_ischar; 12280Sstevel@tonic-gate break; 12290Sstevel@tonic-gate 12300Sstevel@tonic-gate case CONSCLOSEPOLLEDIO: 12310Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 12326990Sgd78059 ("wclrput: " 12336990Sgd78059 "ACK CONSCLOSEPOLLEDIO\n")); 12340Sstevel@tonic-gate wscons.wc_kb_polledio = NULL; 12350Sstevel@tonic-gate wscons.wc_kbdqueue = NULL; 12361253Slq150181 wscons.wc_polledio. 12371253Slq150181 cons_polledio_getchar = NULL; 12381253Slq150181 wscons.wc_polledio. 12391253Slq150181 cons_polledio_ischar = NULL; 12400Sstevel@tonic-gate break; 12410Sstevel@tonic-gate default: 12420Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 12436990Sgd78059 ("wclrput: ACK UNKNOWN\n")); 12440Sstevel@tonic-gate } 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate break; 12470Sstevel@tonic-gate case M_IOCNAK: 12480Sstevel@tonic-gate /* 12490Sstevel@tonic-gate * Keyboard may or may not support polled I/O. 12500Sstevel@tonic-gate * This ioctl may have been rejected because 12510Sstevel@tonic-gate * we only have the wc->conskbd chain built, 12520Sstevel@tonic-gate * and the keyboard driver has not been linked 12530Sstevel@tonic-gate * underneath conskbd yet. 12540Sstevel@tonic-gate */ 12550Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 12566990Sgd78059 ("wclrput: NAK\n")); 12570Sstevel@tonic-gate 12580Sstevel@tonic-gate switch (iocp->ioc_cmd) { 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate case CONSCLOSEPOLLEDIO: 12610Sstevel@tonic-gate wscons.wc_kb_polledio = NULL; 12620Sstevel@tonic-gate wscons.wc_kbdqueue = NULL; 12631253Slq150181 wscons.wc_polledio. 12641253Slq150181 cons_polledio_getchar = NULL; 12651253Slq150181 wscons.wc_polledio. 12661253Slq150181 cons_polledio_ischar = NULL; 12670Sstevel@tonic-gate break; 12680Sstevel@tonic-gate } 12690Sstevel@tonic-gate break; 12700Sstevel@tonic-gate } 12710Sstevel@tonic-gate 12720Sstevel@tonic-gate /* 12730Sstevel@tonic-gate * Discard the response, replace it with the 12740Sstevel@tonic-gate * pending response to the I_PLINK, then let it 12750Sstevel@tonic-gate * flow upward. 12760Sstevel@tonic-gate */ 12770Sstevel@tonic-gate freemsg(mp); 12780Sstevel@tonic-gate mp = wscons.wc_pending_link; 12790Sstevel@tonic-gate wscons.wc_pending_link = NULL; 12800Sstevel@tonic-gate wscons.wc_kb_getpolledio_id = 0; 12810Sstevel@tonic-gate } 12820Sstevel@tonic-gate /* FALLTHROUGH */ 12830Sstevel@tonic-gate 12840Sstevel@tonic-gate default: /* inc M_ERROR, M_HANGUP, M_IOCACK, M_IOCNAK, ... */ 12850Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 12866990Sgd78059 ("wclrput: Message DISCARDED\n")); 12870Sstevel@tonic-gate if ((upq = wscons.wc_ttycommon.t_readq) != NULL) { 12880Sstevel@tonic-gate putnext(upq, mp); 12890Sstevel@tonic-gate } else { 12900Sstevel@tonic-gate freemsg(mp); 12910Sstevel@tonic-gate } 12920Sstevel@tonic-gate break; 12930Sstevel@tonic-gate } 12940Sstevel@tonic-gate 12950Sstevel@tonic-gate return (0); 12960Sstevel@tonic-gate } 12970Sstevel@tonic-gate 12980Sstevel@tonic-gate /* 12991253Slq150181 * These are for systems without OBP, and for devices that cannot be 13001253Slq150181 * shared between Solaris and the OBP. 13010Sstevel@tonic-gate */ 13020Sstevel@tonic-gate static void 13031762Slt200341 wc_polled_putchar(cons_polledio_arg_t arg, unsigned char c) 13040Sstevel@tonic-gate { 13050Sstevel@tonic-gate if (c == '\n') 13061253Slq150181 wc_polled_putchar(arg, '\r'); 13070Sstevel@tonic-gate 13080Sstevel@tonic-gate if (wscons.wc_tem == NULL) { 13090Sstevel@tonic-gate /* 13100Sstevel@tonic-gate * We have no terminal emulator configured. We have no 13110Sstevel@tonic-gate * recourse but to drop the output on the floor. 13120Sstevel@tonic-gate */ 13130Sstevel@tonic-gate return; 13140Sstevel@tonic-gate } 13150Sstevel@tonic-gate 13161253Slq150181 tem_polled_write(wscons.wc_tem, &c, 1); 13170Sstevel@tonic-gate } 13180Sstevel@tonic-gate 13190Sstevel@tonic-gate /* 13200Sstevel@tonic-gate * These are for systems without OBP, and for devices that cannot be 13210Sstevel@tonic-gate * shared between Solaris and the OBP. 13220Sstevel@tonic-gate */ 13230Sstevel@tonic-gate static int 13241762Slt200341 wc_polled_getchar(cons_polledio_arg_t arg) 13250Sstevel@tonic-gate { 13260Sstevel@tonic-gate struct wscons *wscons = (struct wscons *)arg; 13270Sstevel@tonic-gate 13280Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) { 13290Sstevel@tonic-gate prom_printf("wscons: getchar with no keyboard support"); 13300Sstevel@tonic-gate prom_printf("Halted..."); 13310Sstevel@tonic-gate for (;;) 13320Sstevel@tonic-gate /* HANG FOREVER */; 13330Sstevel@tonic-gate } 13340Sstevel@tonic-gate 13350Sstevel@tonic-gate return (wscons->wc_kb_polledio->cons_polledio_getchar( 13361253Slq150181 wscons->wc_kb_polledio->cons_polledio_argument)); 13370Sstevel@tonic-gate } 13380Sstevel@tonic-gate 13390Sstevel@tonic-gate static boolean_t 13401762Slt200341 wc_polled_ischar(cons_polledio_arg_t arg) 13410Sstevel@tonic-gate { 13420Sstevel@tonic-gate struct wscons *wscons = (struct wscons *)arg; 13430Sstevel@tonic-gate 13440Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) 13450Sstevel@tonic-gate return (B_FALSE); 13460Sstevel@tonic-gate 13470Sstevel@tonic-gate return (wscons->wc_kb_polledio->cons_polledio_ischar( 13481253Slq150181 wscons->wc_kb_polledio->cons_polledio_argument)); 13490Sstevel@tonic-gate } 13500Sstevel@tonic-gate 13510Sstevel@tonic-gate static void 13521762Slt200341 wc_polled_enter(cons_polledio_arg_t arg) 13530Sstevel@tonic-gate { 13540Sstevel@tonic-gate struct wscons *wscons = (struct wscons *)arg; 13550Sstevel@tonic-gate 13560Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) 13570Sstevel@tonic-gate return; 13580Sstevel@tonic-gate 13590Sstevel@tonic-gate if (wscons->wc_kb_polledio->cons_polledio_enter != NULL) { 13600Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_enter( 13611253Slq150181 wscons->wc_kb_polledio->cons_polledio_argument); 13620Sstevel@tonic-gate } 13630Sstevel@tonic-gate } 13640Sstevel@tonic-gate 13650Sstevel@tonic-gate static void 13661762Slt200341 wc_polled_exit(cons_polledio_arg_t arg) 13670Sstevel@tonic-gate { 13680Sstevel@tonic-gate struct wscons *wscons = (struct wscons *)arg; 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) 13710Sstevel@tonic-gate return; 13720Sstevel@tonic-gate 13730Sstevel@tonic-gate if (wscons->wc_kb_polledio->cons_polledio_exit != NULL) { 13740Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_exit( 13751253Slq150181 wscons->wc_kb_polledio->cons_polledio_argument); 13760Sstevel@tonic-gate } 13770Sstevel@tonic-gate } 13780Sstevel@tonic-gate 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate #ifdef DEBUG 13810Sstevel@tonic-gate static void 13820Sstevel@tonic-gate wc_dprintf(const char *fmt, ...) 13830Sstevel@tonic-gate { 13840Sstevel@tonic-gate char buf[256]; 13850Sstevel@tonic-gate va_list ap; 13860Sstevel@tonic-gate 13870Sstevel@tonic-gate va_start(ap, fmt); 13880Sstevel@tonic-gate (void) vsprintf(buf, fmt, ap); 13890Sstevel@tonic-gate va_end(ap); 13900Sstevel@tonic-gate 13911253Slq150181 cmn_err(CE_WARN, "wc: %s", buf); 13920Sstevel@tonic-gate } 13930Sstevel@tonic-gate #endif 13940Sstevel@tonic-gate 13951253Slq150181 static void 13961253Slq150181 update_property(struct wscons *wscons, char *name, ushort_t value) 13970Sstevel@tonic-gate { 13981253Slq150181 char data[8]; 13990Sstevel@tonic-gate 14001253Slq150181 (void) snprintf(data, sizeof (data), "%u", value); 14011253Slq150181 (void) ddi_prop_update_string(wscons->wc_dev, wc_dip, name, data); 14020Sstevel@tonic-gate } 14030Sstevel@tonic-gate 14040Sstevel@tonic-gate /* 14050Sstevel@tonic-gate * Gets the number of text rows and columns and the 14060Sstevel@tonic-gate * width and height (in pixels) of the console. 14070Sstevel@tonic-gate */ 14080Sstevel@tonic-gate static void 14090Sstevel@tonic-gate wc_get_size(struct wscons *wscons) 14100Sstevel@tonic-gate { 14111253Slq150181 struct winsize *t = &wscons->wc_ttycommon.t_size; 14121253Slq150181 ushort_t r = LOSCREENLINES, c = LOSCREENCOLS, x = 0, y = 0; 14130Sstevel@tonic-gate 14141253Slq150181 if (wscons->wc_tem != NULL) 14151253Slq150181 tem_get_size(wscons->wc_tem, &r, &c, &x, &y); 14161253Slq150181 #ifdef _HAVE_TEM_FIRMWARE 14171253Slq150181 else { 14181253Slq150181 console_get_size(&r, &c, &x, &y); 14191253Slq150181 } 14201253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 14210Sstevel@tonic-gate 14221253Slq150181 update_property(wscons, "screen-#cols", t->ws_col = c); 14231253Slq150181 update_property(wscons, "screen-#rows", t->ws_row = r); 14241253Slq150181 update_property(wscons, "screen-width", t->ws_xpixel = x); 14251253Slq150181 update_property(wscons, "screen-height", t->ws_ypixel = y); 14261253Slq150181 } 14270Sstevel@tonic-gate 14281253Slq150181 static void 14291253Slq150181 wc_modechg_cb(tem_modechg_cb_arg_t arg) 14301253Slq150181 { 14311253Slq150181 wc_get_size((struct wscons *)arg); 14320Sstevel@tonic-gate } 1433