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*12195SAaron.Zang@Sun.COM * Copyright (c) 1987, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate * "Workstation console" multiplexor driver for Sun.
280Sstevel@tonic-gate *
290Sstevel@tonic-gate * Sends output to the primary frame buffer using the PROM monitor;
300Sstevel@tonic-gate * gets input from a stream linked below us that is the "keyboard
310Sstevel@tonic-gate * driver", below which is linked the primary keyboard.
320Sstevel@tonic-gate */
330Sstevel@tonic-gate
347688SAaron.Zang@Sun.COM /*
357688SAaron.Zang@Sun.COM * Locking Policy:
367688SAaron.Zang@Sun.COM * This module has a D_MTPERMOD inner perimeter which means STREAMS
377688SAaron.Zang@Sun.COM * only allows one thread to enter this module through STREAMS entry
387688SAaron.Zang@Sun.COM * points each time -- open() close() put() srv() qtimeout().
397688SAaron.Zang@Sun.COM * So for the most time we do not need locking in this module, but with
407688SAaron.Zang@Sun.COM * the following exceptions:
417688SAaron.Zang@Sun.COM *
42*12195SAaron.Zang@Sun.COM * - wc shares three global variables (wc_dip, vc_active_console,
43*12195SAaron.Zang@Sun.COM * vc_cons_user, vc_avl_root) with virtual console devname part
44*12195SAaron.Zang@Sun.COM * (fs/dev/sdev_vtops.c) which get compiled into genunix.
457688SAaron.Zang@Sun.COM *
467688SAaron.Zang@Sun.COM * - wc_modechg_cb() is a callback function which will triggered when
477688SAaron.Zang@Sun.COM * framebuffer display mode is changed.
487688SAaron.Zang@Sun.COM *
497688SAaron.Zang@Sun.COM * - vt_send_hotkeys() is triggered by timeout() which is not STREAMS MT
507688SAaron.Zang@Sun.COM * safe.
517688SAaron.Zang@Sun.COM *
527688SAaron.Zang@Sun.COM * Based on the fact that virtual console devname part and wc_modechg_cb()
53*12195SAaron.Zang@Sun.COM * only do read access to the above mentioned shared four global variables,
547688SAaron.Zang@Sun.COM * It is safe to do locking this way:
55*12195SAaron.Zang@Sun.COM * 1) all read access to the four global variables in THIS WC MODULE do not
567688SAaron.Zang@Sun.COM * need locking;
57*12195SAaron.Zang@Sun.COM * 2) all write access to the four global variables in THIS WC MODULE must
587688SAaron.Zang@Sun.COM * hold vc_lock;
59*12195SAaron.Zang@Sun.COM * 3) any access to the four global variables in either DEVNAME PART or the
607688SAaron.Zang@Sun.COM * CALLBACK must hold vc_lock;
617688SAaron.Zang@Sun.COM * 4) other global variables which are only shared in this wc module and only
627688SAaron.Zang@Sun.COM * accessible through STREAMS entry points such as "vc_last_console",
637688SAaron.Zang@Sun.COM * "vc_inuse_max_minor", "vc_target_console" and "vc_waitactive_list"
647688SAaron.Zang@Sun.COM * do not need explict locking.
657688SAaron.Zang@Sun.COM *
667688SAaron.Zang@Sun.COM * wc_modechg_cb() does read access to vc_state_t::vc_flags,
677688SAaron.Zang@Sun.COM * vc_state_t::vc_state_lock is used to protect concurrently accesses to
687688SAaron.Zang@Sun.COM * vc_state_t::vc_flags which may happen from both through STREAMS entry
697688SAaron.Zang@Sun.COM * points and wc_modechg_cb().
707688SAaron.Zang@Sun.COM * Since wc_modechg_cb() only does read access to vc_state_t::vc_flags,
717688SAaron.Zang@Sun.COM * The other parts of wc module (except wc_modechg_cb()) only has to hold
727688SAaron.Zang@Sun.COM * vc_state_t::vc_flags when writing to vc_state_t::vc_flags.
737688SAaron.Zang@Sun.COM *
747688SAaron.Zang@Sun.COM * vt_send_hotkeys() could access vt_pending_vtno at the same time with
757688SAaron.Zang@Sun.COM * the rest of wc module, vt_pending_vtno_lock is used to protect
767688SAaron.Zang@Sun.COM * vt_pending_vtno.
777688SAaron.Zang@Sun.COM *
787688SAaron.Zang@Sun.COM * Lock order: vc_lock -> vc_state_t::vc_state_lock.
797688SAaron.Zang@Sun.COM * No overlap between vc_lock and vt_pending_vtno_lock.
807688SAaron.Zang@Sun.COM */
817688SAaron.Zang@Sun.COM
820Sstevel@tonic-gate #include <sys/types.h>
830Sstevel@tonic-gate #include <sys/param.h>
840Sstevel@tonic-gate #include <sys/signal.h>
850Sstevel@tonic-gate #include <sys/cred.h>
860Sstevel@tonic-gate #include <sys/vnode.h>
870Sstevel@tonic-gate #include <sys/termios.h>
880Sstevel@tonic-gate #include <sys/termio.h>
890Sstevel@tonic-gate #include <sys/ttold.h>
900Sstevel@tonic-gate #include <sys/stropts.h>
910Sstevel@tonic-gate #include <sys/stream.h>
920Sstevel@tonic-gate #include <sys/strsun.h>
930Sstevel@tonic-gate #include <sys/tty.h>
940Sstevel@tonic-gate #include <sys/buf.h>
950Sstevel@tonic-gate #include <sys/uio.h>
960Sstevel@tonic-gate #include <sys/stat.h>
977688SAaron.Zang@Sun.COM #include <sys/sysmacros.h>
987688SAaron.Zang@Sun.COM #include <sys/errno.h>
997688SAaron.Zang@Sun.COM #include <sys/proc.h>
1007688SAaron.Zang@Sun.COM #include <sys/procset.h>
1017688SAaron.Zang@Sun.COM #include <sys/fault.h>
1027688SAaron.Zang@Sun.COM #include <sys/siginfo.h>
1037688SAaron.Zang@Sun.COM #include <sys/debug.h>
1047688SAaron.Zang@Sun.COM #include <sys/session.h>
1050Sstevel@tonic-gate #include <sys/kmem.h>
1060Sstevel@tonic-gate #include <sys/cpuvar.h>
1070Sstevel@tonic-gate #include <sys/kbio.h>
1080Sstevel@tonic-gate #include <sys/strredir.h>
1090Sstevel@tonic-gate #include <sys/fs/snode.h>
1100Sstevel@tonic-gate #include <sys/consdev.h>
1110Sstevel@tonic-gate #include <sys/conf.h>
1127688SAaron.Zang@Sun.COM #include <sys/cmn_err.h>
1137688SAaron.Zang@Sun.COM #include <sys/console.h>
1147688SAaron.Zang@Sun.COM #include <sys/promif.h>
1157688SAaron.Zang@Sun.COM #include <sys/note.h>
1167688SAaron.Zang@Sun.COM #include <sys/polled_io.h>
1177688SAaron.Zang@Sun.COM #include <sys/systm.h>
1180Sstevel@tonic-gate #include <sys/ddi.h>
1190Sstevel@tonic-gate #include <sys/sunddi.h>
1207688SAaron.Zang@Sun.COM #include <sys/sunndi.h>
1217688SAaron.Zang@Sun.COM #include <sys/esunddi.h>
1227688SAaron.Zang@Sun.COM #include <sys/sunldi.h>
1230Sstevel@tonic-gate #include <sys/debug.h>
1240Sstevel@tonic-gate #include <sys/console.h>
1250Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
1260Sstevel@tonic-gate #include <sys/policy.h>
1277688SAaron.Zang@Sun.COM #include <sys/modctl.h>
1281253Slq150181 #include <sys/tem.h>
1291253Slq150181 #include <sys/wscons.h>
1307688SAaron.Zang@Sun.COM #include <sys/vt_impl.h>
1317688SAaron.Zang@Sun.COM
1327688SAaron.Zang@Sun.COM /* streams stuff */
1337688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("Unshared data", copyreq))
1347688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("Unshared data", copyresp))
1357688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("Unshared data", datab))
1367688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("Unshared data", iocblk))
1377688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("Unshared data", msgb))
1387688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("Unshared data", queue))
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate #define MINLINES 10
1410Sstevel@tonic-gate #define MAXLINES 48
1420Sstevel@tonic-gate #define LOSCREENLINES 34
1430Sstevel@tonic-gate #define HISCREENLINES 48
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate #define MINCOLS 10
1460Sstevel@tonic-gate #define MAXCOLS 120
1470Sstevel@tonic-gate #define LOSCREENCOLS 80
1480Sstevel@tonic-gate #define HISCREENCOLS 120
1490Sstevel@tonic-gate
1507688SAaron.Zang@Sun.COM struct wscons_state {
1510Sstevel@tonic-gate dev_t wc_dev; /* major/minor for this device */
1521253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
1530Sstevel@tonic-gate int wc_defer_output; /* set if output device is "slow" */
1541253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
1550Sstevel@tonic-gate queue_t *wc_kbdqueue; /* "console keyboard" device queue */
1560Sstevel@tonic-gate /* below us */
1570Sstevel@tonic-gate cons_polledio_t wc_polledio; /* polled I/O function pointers */
1580Sstevel@tonic-gate cons_polledio_t *wc_kb_polledio; /* keyboard's polledio */
1590Sstevel@tonic-gate unsigned int wc_kb_getpolledio_id; /* id for kb CONSOPENPOLLEDIO */
1607688SAaron.Zang@Sun.COM queue_t *wc_pending_wq;
1610Sstevel@tonic-gate mblk_t *wc_pending_link; /* I_PLINK pending for kb polledio */
1620Sstevel@tonic-gate } wscons;
1630Sstevel@tonic-gate
1647688SAaron.Zang@Sun.COM /*
1657688SAaron.Zang@Sun.COM * This module has a D_MTPERMOD inner perimeter, so we don't need to protect
1667688SAaron.Zang@Sun.COM * the variables only shared within this module
1677688SAaron.Zang@Sun.COM */
1687688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", wscons))
1697688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", wscons_state))
1707688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_stat))
1717688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vc_waitactive_msg))
1727688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", tty_common))
1737688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_mode))
1747688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_dispinfo))
1757688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", winsize))
1767688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vc_last_console))
1777688SAaron.Zang@Sun.COM
1787688SAaron.Zang@Sun.COM #ifdef _HAVE_TEM_FIRMWARE
1797688SAaron.Zang@Sun.COM ssize_t wc_cons_wrtvec(promif_redir_arg_t arg, uchar_t *s, size_t n);
1807688SAaron.Zang@Sun.COM #endif /* _HAVE_TEM_FIRMWARE */
1810Sstevel@tonic-gate
1820Sstevel@tonic-gate static int wcopen(queue_t *, dev_t *, int, int, cred_t *);
1830Sstevel@tonic-gate static int wcclose(queue_t *, int, cred_t *);
1840Sstevel@tonic-gate static int wcuwput(queue_t *, mblk_t *);
1850Sstevel@tonic-gate static int wclrput(queue_t *, mblk_t *);
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate static struct module_info wcm_info = {
1880Sstevel@tonic-gate 0,
1890Sstevel@tonic-gate "wc",
1900Sstevel@tonic-gate 0,
1910Sstevel@tonic-gate INFPSZ,
1920Sstevel@tonic-gate 2048,
1930Sstevel@tonic-gate 128
1940Sstevel@tonic-gate };
1950Sstevel@tonic-gate
1960Sstevel@tonic-gate static struct qinit wcurinit = {
1970Sstevel@tonic-gate putq,
1980Sstevel@tonic-gate NULL,
1990Sstevel@tonic-gate wcopen,
2000Sstevel@tonic-gate wcclose,
2010Sstevel@tonic-gate NULL,
2020Sstevel@tonic-gate &wcm_info,
2030Sstevel@tonic-gate NULL
2040Sstevel@tonic-gate };
2050Sstevel@tonic-gate
2060Sstevel@tonic-gate static struct qinit wcuwinit = {
2070Sstevel@tonic-gate wcuwput,
2080Sstevel@tonic-gate NULL,
2090Sstevel@tonic-gate wcopen,
2100Sstevel@tonic-gate wcclose,
2110Sstevel@tonic-gate NULL,
2120Sstevel@tonic-gate &wcm_info,
2130Sstevel@tonic-gate NULL
2140Sstevel@tonic-gate };
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate static struct qinit wclrinit = {
2170Sstevel@tonic-gate wclrput,
2180Sstevel@tonic-gate NULL,
2190Sstevel@tonic-gate NULL,
2200Sstevel@tonic-gate NULL,
2210Sstevel@tonic-gate NULL,
2220Sstevel@tonic-gate &wcm_info,
2230Sstevel@tonic-gate NULL
2240Sstevel@tonic-gate };
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate /*
2270Sstevel@tonic-gate * We always putnext directly to the underlying queue.
2280Sstevel@tonic-gate */
2290Sstevel@tonic-gate static struct qinit wclwinit = {
2300Sstevel@tonic-gate NULL,
2310Sstevel@tonic-gate NULL,
2320Sstevel@tonic-gate NULL,
2330Sstevel@tonic-gate NULL,
2340Sstevel@tonic-gate NULL,
2350Sstevel@tonic-gate &wcm_info,
2360Sstevel@tonic-gate NULL
2370Sstevel@tonic-gate };
2380Sstevel@tonic-gate
2390Sstevel@tonic-gate static struct streamtab wcinfo = {
2400Sstevel@tonic-gate &wcurinit,
2410Sstevel@tonic-gate &wcuwinit,
2420Sstevel@tonic-gate &wclrinit,
2430Sstevel@tonic-gate &wclwinit,
2440Sstevel@tonic-gate };
2450Sstevel@tonic-gate
2460Sstevel@tonic-gate static int wc_info(dev_info_t *, ddi_info_cmd_t, void *, void **result);
2470Sstevel@tonic-gate static int wc_attach(dev_info_t *, ddi_attach_cmd_t);
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(wc_ops, nulldev, nulldev, wc_attach, nodev, nodev,
2507656SSherry.Moore@Sun.COM wc_info, D_MTPERMOD | D_MP, &wcinfo, ddi_quiesce_not_supported);
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate static void wcreioctl(void *);
2530Sstevel@tonic-gate static void wcioctl(queue_t *, mblk_t *);
2541253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
2550Sstevel@tonic-gate static void wcopoll(void *);
2560Sstevel@tonic-gate static void wconsout(void *);
2571253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
2580Sstevel@tonic-gate static void wcrstrt(void *);
2597688SAaron.Zang@Sun.COM static void wcstart(void *);
2607688SAaron.Zang@Sun.COM static void wc_open_kb_polledio(struct wscons_state *wc, queue_t *q,
2617688SAaron.Zang@Sun.COM mblk_t *mp);
2627688SAaron.Zang@Sun.COM static void wc_close_kb_polledio(struct wscons_state *wc, queue_t *q,
2637688SAaron.Zang@Sun.COM mblk_t *mp);
2647688SAaron.Zang@Sun.COM static void wc_polled_putchar(cons_polledio_arg_t arg,
2657688SAaron.Zang@Sun.COM unsigned char c);
2661762Slt200341 static boolean_t wc_polled_ischar(cons_polledio_arg_t arg);
2671762Slt200341 static int wc_polled_getchar(cons_polledio_arg_t arg);
2681762Slt200341 static void wc_polled_enter(cons_polledio_arg_t arg);
2691762Slt200341 static void wc_polled_exit(cons_polledio_arg_t arg);
2707688SAaron.Zang@Sun.COM void wc_get_size(vc_state_t *pvc);
2711253Slq150181 static void wc_modechg_cb(tem_modechg_cb_arg_t arg);
2720Sstevel@tonic-gate
2730Sstevel@tonic-gate static struct dev_ops wc_ops;
2740Sstevel@tonic-gate
2750Sstevel@tonic-gate /*
2760Sstevel@tonic-gate * Debug printing
2770Sstevel@tonic-gate */
2780Sstevel@tonic-gate #ifndef DPRINTF
2790Sstevel@tonic-gate #ifdef DEBUG
2800Sstevel@tonic-gate /*PRINTFLIKE1*/
2810Sstevel@tonic-gate static void wc_dprintf(const char *fmt, ...) __KPRINTFLIKE(1);
2820Sstevel@tonic-gate #define DPRINTF(l, m, args) \
2830Sstevel@tonic-gate (((l) >= wc_errlevel) && ((m) & wc_errmask) ? \
2841253Slq150181 wc_dprintf args : \
2850Sstevel@tonic-gate (void) 0)
2860Sstevel@tonic-gate /*
2870Sstevel@tonic-gate * Severity levels for printing
2880Sstevel@tonic-gate */
2890Sstevel@tonic-gate #define PRINT_L0 0 /* print every message */
2900Sstevel@tonic-gate #define PRINT_L1 1 /* debug */
2910Sstevel@tonic-gate #define PRINT_L2 2 /* quiet */
2920Sstevel@tonic-gate
2930Sstevel@tonic-gate /*
2940Sstevel@tonic-gate * Masks
2950Sstevel@tonic-gate */
2960Sstevel@tonic-gate #define PRINT_MASK_ALL 0xFFFFFFFFU
2970Sstevel@tonic-gate uint_t wc_errmask = PRINT_MASK_ALL;
2980Sstevel@tonic-gate uint_t wc_errlevel = PRINT_L2;
2990Sstevel@tonic-gate
3000Sstevel@tonic-gate #else
3010Sstevel@tonic-gate #define DPRINTF(l, m, args) /* NOTHING */
3020Sstevel@tonic-gate #endif
3030Sstevel@tonic-gate #endif
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate /*
3060Sstevel@tonic-gate * Module linkage information for the kernel.
3070Sstevel@tonic-gate */
3080Sstevel@tonic-gate static struct modldrv modldrv = {
3090Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a pseudo driver */
3107656SSherry.Moore@Sun.COM "Workstation multiplexer Driver 'wc'",
3110Sstevel@tonic-gate &wc_ops, /* driver ops */
3120Sstevel@tonic-gate };
3130Sstevel@tonic-gate
3140Sstevel@tonic-gate static struct modlinkage modlinkage = {
3150Sstevel@tonic-gate MODREV_1,
3160Sstevel@tonic-gate &modldrv,
3170Sstevel@tonic-gate NULL
3180Sstevel@tonic-gate };
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate int
_init(void)3210Sstevel@tonic-gate _init(void)
3220Sstevel@tonic-gate {
3237688SAaron.Zang@Sun.COM int rc;
3247688SAaron.Zang@Sun.COM if ((rc = mod_install(&modlinkage)) == 0)
3257688SAaron.Zang@Sun.COM vt_init();
3267688SAaron.Zang@Sun.COM return (rc);
3270Sstevel@tonic-gate }
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate int
_fini(void)3300Sstevel@tonic-gate _fini(void)
3310Sstevel@tonic-gate {
3320Sstevel@tonic-gate return (mod_remove(&modlinkage));
3330Sstevel@tonic-gate }
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate int
_info(struct modinfo * modinfop)3360Sstevel@tonic-gate _info(struct modinfo *modinfop)
3370Sstevel@tonic-gate {
3380Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
3390Sstevel@tonic-gate }
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate /*ARGSUSED*/
3420Sstevel@tonic-gate static int
wc_attach(dev_info_t * devi,ddi_attach_cmd_t cmd)3430Sstevel@tonic-gate wc_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
3440Sstevel@tonic-gate {
3457688SAaron.Zang@Sun.COM /* create minor node for workstation hard console */
3460Sstevel@tonic-gate if (ddi_create_minor_node(devi, "wscons", S_IFCHR,
3470Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) {
3480Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL);
3497688SAaron.Zang@Sun.COM return (DDI_FAILURE);
3500Sstevel@tonic-gate }
3517688SAaron.Zang@Sun.COM
3527688SAaron.Zang@Sun.COM mutex_enter(&vc_lock);
3537688SAaron.Zang@Sun.COM
3540Sstevel@tonic-gate wc_dip = devi;
3551253Slq150181
3561253Slq150181 bzero(&(wscons.wc_polledio), sizeof (wscons.wc_polledio));
3571253Slq150181
3587688SAaron.Zang@Sun.COM vt_resize(VC_DEFAULT_COUNT);
3597688SAaron.Zang@Sun.COM
3607688SAaron.Zang@Sun.COM mutex_exit(&vc_lock);
3617688SAaron.Zang@Sun.COM
3620Sstevel@tonic-gate return (DDI_SUCCESS);
3630Sstevel@tonic-gate }
3640Sstevel@tonic-gate
3650Sstevel@tonic-gate /* ARGSUSED */
3660Sstevel@tonic-gate static int
wc_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)3670Sstevel@tonic-gate wc_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg,
3680Sstevel@tonic-gate void **result)
3690Sstevel@tonic-gate {
3700Sstevel@tonic-gate int error;
3710Sstevel@tonic-gate
3720Sstevel@tonic-gate switch (infocmd) {
3730Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
3740Sstevel@tonic-gate if (wc_dip == NULL) {
3750Sstevel@tonic-gate error = DDI_FAILURE;
3760Sstevel@tonic-gate } else {
3770Sstevel@tonic-gate *result = (void *) wc_dip;
3780Sstevel@tonic-gate error = DDI_SUCCESS;
3790Sstevel@tonic-gate }
3800Sstevel@tonic-gate break;
3810Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
3820Sstevel@tonic-gate *result = (void *)0;
3830Sstevel@tonic-gate error = DDI_SUCCESS;
3840Sstevel@tonic-gate break;
3850Sstevel@tonic-gate default:
3860Sstevel@tonic-gate error = DDI_FAILURE;
3870Sstevel@tonic-gate }
3880Sstevel@tonic-gate return (error);
3890Sstevel@tonic-gate }
3900Sstevel@tonic-gate
3911253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
3920Sstevel@tonic-gate /*
3930Sstevel@tonic-gate * Output buffer. Protected by the per-module inner perimeter.
3940Sstevel@tonic-gate */
3950Sstevel@tonic-gate #define MAXHIWAT 2000
3960Sstevel@tonic-gate static char obuf[MAXHIWAT];
3971253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
3980Sstevel@tonic-gate
3997688SAaron.Zang@Sun.COM static void
wc_init_polledio(void)4007688SAaron.Zang@Sun.COM wc_init_polledio(void)
4017688SAaron.Zang@Sun.COM {
4027688SAaron.Zang@Sun.COM static boolean_t polledio_inited = B_FALSE;
4037688SAaron.Zang@Sun.COM _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data",
4047688SAaron.Zang@Sun.COM polledio_inited))
4057688SAaron.Zang@Sun.COM
4067688SAaron.Zang@Sun.COM if (polledio_inited)
4077688SAaron.Zang@Sun.COM return;
4087688SAaron.Zang@Sun.COM
4097688SAaron.Zang@Sun.COM polledio_inited = B_TRUE;
4107688SAaron.Zang@Sun.COM
4117688SAaron.Zang@Sun.COM /*
4127688SAaron.Zang@Sun.COM * Initialize the parts of the polled I/O struct that
4137688SAaron.Zang@Sun.COM * are common to both input and output modes, but which
4147688SAaron.Zang@Sun.COM * don't flag to the upper layers, which if any of the
4157688SAaron.Zang@Sun.COM * two modes are available. We don't know at this point
4167688SAaron.Zang@Sun.COM * if system is configured CONS_KFB, but we will when
4177688SAaron.Zang@Sun.COM * consconfig_dacf asks us with CONSOPENPOLLED I/O.
4187688SAaron.Zang@Sun.COM */
4197688SAaron.Zang@Sun.COM bzero(&(wscons.wc_polledio), sizeof (wscons.wc_polledio));
4207688SAaron.Zang@Sun.COM wscons.wc_polledio.cons_polledio_version =
4217688SAaron.Zang@Sun.COM CONSPOLLEDIO_V0;
4227688SAaron.Zang@Sun.COM wscons.wc_polledio.cons_polledio_argument =
4237688SAaron.Zang@Sun.COM (cons_polledio_arg_t)&wscons;
4247688SAaron.Zang@Sun.COM wscons.wc_polledio.cons_polledio_enter =
4257688SAaron.Zang@Sun.COM wc_polled_enter;
4267688SAaron.Zang@Sun.COM wscons.wc_polledio.cons_polledio_exit =
4277688SAaron.Zang@Sun.COM wc_polled_exit;
4287688SAaron.Zang@Sun.COM
4297688SAaron.Zang@Sun.COM #ifdef _HAVE_TEM_FIRMWARE
4307688SAaron.Zang@Sun.COM /*
4317688SAaron.Zang@Sun.COM * If we're talking directly to a framebuffer, we assume
4327688SAaron.Zang@Sun.COM * that it's a "slow" device, so that rendering should
4337688SAaron.Zang@Sun.COM * be deferred to a timeout or softcall so that we write
4347688SAaron.Zang@Sun.COM * a bunch of characters at once.
4357688SAaron.Zang@Sun.COM */
4367688SAaron.Zang@Sun.COM wscons.wc_defer_output = prom_stdout_is_framebuffer();
4377688SAaron.Zang@Sun.COM #endif /* _HAVE_TEM_FIRMWARE */
4387688SAaron.Zang@Sun.COM }
4397688SAaron.Zang@Sun.COM
4400Sstevel@tonic-gate /*ARGSUSED*/
4410Sstevel@tonic-gate static int
wcopen(queue_t * q,dev_t * devp,int flag,int sflag,cred_t * crp)4420Sstevel@tonic-gate wcopen(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *crp)
4430Sstevel@tonic-gate {
4447688SAaron.Zang@Sun.COM int minor;
4450Sstevel@tonic-gate
4467688SAaron.Zang@Sun.COM wc_init_polledio();
4477688SAaron.Zang@Sun.COM minor = (int)getminor(*devp);
4487688SAaron.Zang@Sun.COM return (vt_open(minor, q, crp));
4490Sstevel@tonic-gate }
4500Sstevel@tonic-gate
4510Sstevel@tonic-gate /*ARGSUSED*/
4520Sstevel@tonic-gate static int
wcclose(queue_t * q,int flag,cred_t * crp)4530Sstevel@tonic-gate wcclose(queue_t *q, int flag, cred_t *crp)
4540Sstevel@tonic-gate {
4557688SAaron.Zang@Sun.COM vc_state_t *pvc = (vc_state_t *)q->q_ptr;
4567688SAaron.Zang@Sun.COM
4570Sstevel@tonic-gate qprocsoff(q);
4587688SAaron.Zang@Sun.COM
4597688SAaron.Zang@Sun.COM mutex_enter(&vc_lock);
4607688SAaron.Zang@Sun.COM
461*12195SAaron.Zang@Sun.COM /*
462*12195SAaron.Zang@Sun.COM * If we are closing the VT node which
463*12195SAaron.Zang@Sun.COM * /dev/vt/console_user points to, revert
464*12195SAaron.Zang@Sun.COM * /dev/vt/console to /dev/console
465*12195SAaron.Zang@Sun.COM */
466*12195SAaron.Zang@Sun.COM if (vc_cons_user == pvc->vc_minor)
467*12195SAaron.Zang@Sun.COM vc_cons_user = VT_MINOR_INVALID;
468*12195SAaron.Zang@Sun.COM
4697688SAaron.Zang@Sun.COM if (pvc->vc_minor == 0 || pvc->vc_minor == vc_active_console) {
4707688SAaron.Zang@Sun.COM
4717688SAaron.Zang@Sun.COM /*
4727688SAaron.Zang@Sun.COM * If we lose the system console,
4737688SAaron.Zang@Sun.COM * no any other active consoles.
4747688SAaron.Zang@Sun.COM */
4757688SAaron.Zang@Sun.COM if (pvc->vc_minor == 0 && pvc->vc_minor == vc_active_console) {
4767688SAaron.Zang@Sun.COM vc_active_console = VT_MINOR_INVALID;
4777688SAaron.Zang@Sun.COM vc_last_console = VT_MINOR_INVALID;
4787688SAaron.Zang@Sun.COM }
4797688SAaron.Zang@Sun.COM
4807688SAaron.Zang@Sun.COM /*
4817688SAaron.Zang@Sun.COM * just clean for our primary console
4827688SAaron.Zang@Sun.COM * and active console
4837688SAaron.Zang@Sun.COM */
4847688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
4857688SAaron.Zang@Sun.COM vt_clean(q, pvc);
4867688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
4877688SAaron.Zang@Sun.COM
4887688SAaron.Zang@Sun.COM mutex_exit(&vc_lock);
4897688SAaron.Zang@Sun.COM
4907688SAaron.Zang@Sun.COM return (0);
4910Sstevel@tonic-gate }
4927688SAaron.Zang@Sun.COM vt_close(q, pvc, crp);
4937688SAaron.Zang@Sun.COM
4947688SAaron.Zang@Sun.COM mutex_exit(&vc_lock);
4957688SAaron.Zang@Sun.COM
4960Sstevel@tonic-gate return (0);
4970Sstevel@tonic-gate }
4980Sstevel@tonic-gate
4990Sstevel@tonic-gate /*
5000Sstevel@tonic-gate * Put procedure for upper write queue.
5010Sstevel@tonic-gate * Respond to M_STOP, M_START, M_IOCTL, and M_FLUSH messages here;
5020Sstevel@tonic-gate * queue up M_BREAK, M_DELAY, and M_DATA messages for processing by
5030Sstevel@tonic-gate * the start routine, and then call the start routine; discard
5040Sstevel@tonic-gate * everything else.
5050Sstevel@tonic-gate */
5060Sstevel@tonic-gate static int
wcuwput(queue_t * q,mblk_t * mp)5070Sstevel@tonic-gate wcuwput(queue_t *q, mblk_t *mp)
5080Sstevel@tonic-gate {
5097688SAaron.Zang@Sun.COM vc_state_t *pvc = (vc_state_t *)q->q_ptr;
5107688SAaron.Zang@Sun.COM
5110Sstevel@tonic-gate switch (mp->b_datap->db_type) {
5120Sstevel@tonic-gate
5130Sstevel@tonic-gate case M_STOP:
5147688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
5157688SAaron.Zang@Sun.COM pvc->vc_flags |= WCS_STOPPED;
5167688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
5177688SAaron.Zang@Sun.COM
5180Sstevel@tonic-gate freemsg(mp);
5190Sstevel@tonic-gate break;
5200Sstevel@tonic-gate
5210Sstevel@tonic-gate case M_START:
5227688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
5237688SAaron.Zang@Sun.COM pvc->vc_flags &= ~WCS_STOPPED;
5247688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
5257688SAaron.Zang@Sun.COM
5267688SAaron.Zang@Sun.COM wcstart(pvc);
5270Sstevel@tonic-gate freemsg(mp);
5280Sstevel@tonic-gate break;
5290Sstevel@tonic-gate
5300Sstevel@tonic-gate case M_IOCTL: {
5310Sstevel@tonic-gate struct iocblk *iocp;
5320Sstevel@tonic-gate struct linkblk *linkp;
5330Sstevel@tonic-gate
5347688SAaron.Zang@Sun.COM iocp = (struct iocblk *)(void *)mp->b_rptr;
5350Sstevel@tonic-gate switch (iocp->ioc_cmd) {
5360Sstevel@tonic-gate
5370Sstevel@tonic-gate case I_LINK: /* stupid, but permitted */
5380Sstevel@tonic-gate case I_PLINK:
5390Sstevel@tonic-gate if (wscons.wc_kbdqueue != NULL) {
5400Sstevel@tonic-gate /* somebody already linked */
5410Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL);
5420Sstevel@tonic-gate return (0);
5430Sstevel@tonic-gate }
5447688SAaron.Zang@Sun.COM linkp = (struct linkblk *)(void *)mp->b_cont->b_rptr;
5450Sstevel@tonic-gate wscons.wc_kbdqueue = WR(linkp->l_qbot);
5460Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
5470Sstevel@tonic-gate iocp->ioc_count = 0;
5480Sstevel@tonic-gate wc_open_kb_polledio(&wscons, q, mp);
5490Sstevel@tonic-gate break;
5500Sstevel@tonic-gate
5510Sstevel@tonic-gate case I_UNLINK: /* stupid, but permitted */
5520Sstevel@tonic-gate case I_PUNLINK:
5537688SAaron.Zang@Sun.COM linkp = (struct linkblk *)(void *)mp->b_cont->b_rptr;
5540Sstevel@tonic-gate if (wscons.wc_kbdqueue != WR(linkp->l_qbot)) {
5550Sstevel@tonic-gate /* not us */
5560Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL);
5570Sstevel@tonic-gate return (0);
5580Sstevel@tonic-gate }
5590Sstevel@tonic-gate
5600Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
5610Sstevel@tonic-gate iocp->ioc_count = 0;
5620Sstevel@tonic-gate wc_close_kb_polledio(&wscons, q, mp);
5630Sstevel@tonic-gate break;
5640Sstevel@tonic-gate
5650Sstevel@tonic-gate case TCSETSW:
5660Sstevel@tonic-gate case TCSETSF:
5670Sstevel@tonic-gate case TCSETAW:
5680Sstevel@tonic-gate case TCSETAF:
5690Sstevel@tonic-gate case TCSBRK:
5700Sstevel@tonic-gate /*
5710Sstevel@tonic-gate * The changes do not take effect until all
5720Sstevel@tonic-gate * output queued before them is drained.
5730Sstevel@tonic-gate * Put this message on the queue, so that
5740Sstevel@tonic-gate * "wcstart" will see it when it's done
5750Sstevel@tonic-gate * with the output before it. Poke the
5760Sstevel@tonic-gate * start routine, just in case.
5770Sstevel@tonic-gate */
5780Sstevel@tonic-gate (void) putq(q, mp);
5797688SAaron.Zang@Sun.COM wcstart(pvc);
5800Sstevel@tonic-gate break;
5810Sstevel@tonic-gate
5820Sstevel@tonic-gate case CONSSETABORTENABLE:
5830Sstevel@tonic-gate case CONSGETABORTENABLE:
5840Sstevel@tonic-gate case KIOCSDIRECT:
5850Sstevel@tonic-gate if (wscons.wc_kbdqueue != NULL) {
5867688SAaron.Zang@Sun.COM wscons.wc_pending_wq = q;
5870Sstevel@tonic-gate (void) putnext(wscons.wc_kbdqueue, mp);
5880Sstevel@tonic-gate break;
5890Sstevel@tonic-gate }
5900Sstevel@tonic-gate /* fall through */
5910Sstevel@tonic-gate
5920Sstevel@tonic-gate default:
5930Sstevel@tonic-gate /*
5940Sstevel@tonic-gate * Do it now.
5950Sstevel@tonic-gate */
5960Sstevel@tonic-gate wcioctl(q, mp);
5970Sstevel@tonic-gate break;
5980Sstevel@tonic-gate }
5990Sstevel@tonic-gate break;
6000Sstevel@tonic-gate }
6010Sstevel@tonic-gate
6020Sstevel@tonic-gate case M_FLUSH:
6030Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) {
6040Sstevel@tonic-gate /*
6050Sstevel@tonic-gate * Flush our write queue.
6060Sstevel@tonic-gate */
6070Sstevel@tonic-gate flushq(q, FLUSHDATA); /* XXX doesn't flush M_DELAY */
6080Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHW; /* it has been flushed */
6090Sstevel@tonic-gate }
6100Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) {
6110Sstevel@tonic-gate flushq(RD(q), FLUSHDATA);
6120Sstevel@tonic-gate qreply(q, mp); /* give the read queues a crack at it */
6130Sstevel@tonic-gate } else
6140Sstevel@tonic-gate freemsg(mp);
6150Sstevel@tonic-gate break;
6160Sstevel@tonic-gate
6170Sstevel@tonic-gate case M_BREAK:
6180Sstevel@tonic-gate /*
6190Sstevel@tonic-gate * Ignore these, as they make no sense.
6200Sstevel@tonic-gate */
6210Sstevel@tonic-gate freemsg(mp);
6220Sstevel@tonic-gate break;
6230Sstevel@tonic-gate
6240Sstevel@tonic-gate case M_DELAY:
6250Sstevel@tonic-gate case M_DATA:
6260Sstevel@tonic-gate /*
6270Sstevel@tonic-gate * Queue the message up to be transmitted,
6280Sstevel@tonic-gate * and poke the start routine.
6290Sstevel@tonic-gate */
6300Sstevel@tonic-gate (void) putq(q, mp);
6317688SAaron.Zang@Sun.COM wcstart(pvc);
6327688SAaron.Zang@Sun.COM break;
6337688SAaron.Zang@Sun.COM
6347688SAaron.Zang@Sun.COM case M_IOCDATA:
6357688SAaron.Zang@Sun.COM vt_miocdata(q, mp);
6360Sstevel@tonic-gate break;
6370Sstevel@tonic-gate
6380Sstevel@tonic-gate default:
6390Sstevel@tonic-gate /*
6400Sstevel@tonic-gate * "No, I don't want a subscription to Chain Store Age,
6410Sstevel@tonic-gate * thank you anyway."
6420Sstevel@tonic-gate */
6430Sstevel@tonic-gate freemsg(mp);
6440Sstevel@tonic-gate break;
6450Sstevel@tonic-gate }
6460Sstevel@tonic-gate
6470Sstevel@tonic-gate return (0);
6480Sstevel@tonic-gate }
6490Sstevel@tonic-gate
6500Sstevel@tonic-gate /*
6510Sstevel@tonic-gate * Retry an "ioctl", now that "qbufcall" claims we may be able to allocate
6520Sstevel@tonic-gate * the buffer we need.
6530Sstevel@tonic-gate */
6540Sstevel@tonic-gate /*ARGSUSED*/
6550Sstevel@tonic-gate static void
wcreioctl(void * arg)6560Sstevel@tonic-gate wcreioctl(void *arg)
6570Sstevel@tonic-gate {
6587688SAaron.Zang@Sun.COM vc_state_t *pvc = (vc_state_t *)arg;
6590Sstevel@tonic-gate queue_t *q;
6600Sstevel@tonic-gate mblk_t *mp;
6610Sstevel@tonic-gate
6627688SAaron.Zang@Sun.COM pvc->vc_bufcallid = 0;
6637688SAaron.Zang@Sun.COM q = pvc->vc_ttycommon.t_writeq;
6647688SAaron.Zang@Sun.COM if ((mp = pvc->vc_ttycommon.t_iocpending) != NULL) {
6650Sstevel@tonic-gate /* not pending any more */
6667688SAaron.Zang@Sun.COM pvc->vc_ttycommon.t_iocpending = NULL;
6670Sstevel@tonic-gate wcioctl(q, mp);
6680Sstevel@tonic-gate }
6690Sstevel@tonic-gate }
6700Sstevel@tonic-gate
6711253Slq150181 static int
wc_getterm(mblk_t * mp)6721253Slq150181 wc_getterm(mblk_t *mp)
6731253Slq150181 {
6741253Slq150181 char *term;
6751253Slq150181 intptr_t arg;
6766990Sgd78059 int flag = ((struct iocblk *)(void *)mp->b_rptr)->ioc_flag;
6771253Slq150181
6781253Slq150181 STRUCT_DECL(cons_getterm, wcterm);
6791253Slq150181 STRUCT_INIT(wcterm, flag);
6801253Slq150181
6816990Sgd78059 arg = *((intptr_t *)(void *)mp->b_cont->b_rptr);
6821253Slq150181
6831253Slq150181 if (ddi_copyin((void *)arg, STRUCT_BUF(wcterm),
6841253Slq150181 STRUCT_SIZE(wcterm), flag) != 0) {
6851253Slq150181 return (EFAULT);
6861253Slq150181 }
6871253Slq150181
6881253Slq150181 if (consmode == CONS_FW) {
6891253Slq150181 /* PROM terminal emulator */
6901253Slq150181 term = "sun";
6911253Slq150181 } else {
6921253Slq150181 /* Kernel terminal emulator */
6931253Slq150181 ASSERT(consmode == CONS_KFB);
6941253Slq150181 term = "sun-color";
6951253Slq150181 }
6961253Slq150181
6971253Slq150181 if (STRUCT_FGET(wcterm, cn_term_len) <
6981253Slq150181 strlen(term) + 1) {
6991253Slq150181 return (EOVERFLOW);
7001253Slq150181 }
7011253Slq150181
7021253Slq150181 if (ddi_copyout(term,
7031253Slq150181 STRUCT_FGETP(wcterm, cn_term_type),
7041253Slq150181 strlen(term) + 1, flag) != 0) {
7051253Slq150181 return (EFAULT);
7061253Slq150181 }
7071253Slq150181
7081253Slq150181 return (0);
7091253Slq150181 }
7101253Slq150181
7110Sstevel@tonic-gate /*
7120Sstevel@tonic-gate * Process an "ioctl" message sent down to us.
7130Sstevel@tonic-gate */
7140Sstevel@tonic-gate static void
wcioctl(queue_t * q,mblk_t * mp)7150Sstevel@tonic-gate wcioctl(queue_t *q, mblk_t *mp)
7160Sstevel@tonic-gate {
7177688SAaron.Zang@Sun.COM vc_state_t *pvc = (vc_state_t *)q->q_ptr;
7180Sstevel@tonic-gate struct iocblk *iocp;
7190Sstevel@tonic-gate size_t datasize;
7200Sstevel@tonic-gate int error;
7211253Slq150181 long len;
7220Sstevel@tonic-gate
7237688SAaron.Zang@Sun.COM iocp = (struct iocblk *)(void *)mp->b_rptr;
7247688SAaron.Zang@Sun.COM
7257688SAaron.Zang@Sun.COM if ((iocp->ioc_cmd & VTIOC) == VTIOC ||
7267688SAaron.Zang@Sun.COM (iocp->ioc_cmd & KDIOC) == KDIOC) {
7277688SAaron.Zang@Sun.COM vt_ioctl(q, mp);
7287688SAaron.Zang@Sun.COM return;
7297688SAaron.Zang@Sun.COM }
7300Sstevel@tonic-gate
7310Sstevel@tonic-gate switch (iocp->ioc_cmd) {
7320Sstevel@tonic-gate case TIOCSWINSZ:
7330Sstevel@tonic-gate /*
7340Sstevel@tonic-gate * Ignore all attempts to set the screen size; the
7350Sstevel@tonic-gate * value in the EEPROM is guaranteed (modulo PROM bugs)
7360Sstevel@tonic-gate * to be the value used by the PROM monitor code, so it
7370Sstevel@tonic-gate * is by definition correct. Many programs (e.g.,
7380Sstevel@tonic-gate * "login" and "tset") will attempt to reset the size
7390Sstevel@tonic-gate * to (0, 0) or (34, 80), neither of which is
7400Sstevel@tonic-gate * necessarily correct.
7410Sstevel@tonic-gate * We just ACK the message, so as not to disturb
7420Sstevel@tonic-gate * programs that set the sizes.
7430Sstevel@tonic-gate */
7440Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */
7450Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
7460Sstevel@tonic-gate qreply(q, mp);
7470Sstevel@tonic-gate return;
7480Sstevel@tonic-gate
7490Sstevel@tonic-gate case CONSOPENPOLLEDIO:
7500Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL,
7516990Sgd78059 ("wcioctl: CONSOPENPOLLEDIO\n"));
7520Sstevel@tonic-gate
7530Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct cons_polledio *));
7540Sstevel@tonic-gate if (error != 0) {
7550Sstevel@tonic-gate miocnak(q, mp, 0, error);
7560Sstevel@tonic-gate return;
7570Sstevel@tonic-gate }
7580Sstevel@tonic-gate
7590Sstevel@tonic-gate /*
7601253Slq150181 * We are given an appropriate-sized data block,
7611253Slq150181 * and return a pointer to our structure in it.
7620Sstevel@tonic-gate */
7631253Slq150181 if (consmode == CONS_KFB)
7641253Slq150181 wscons.wc_polledio.cons_polledio_putchar =
7651253Slq150181 wc_polled_putchar;
7666990Sgd78059 *(struct cons_polledio **)(void *)mp->b_cont->b_rptr =
7676990Sgd78059 &wscons.wc_polledio;
7680Sstevel@tonic-gate
7691253Slq150181 mp->b_datap->db_type = M_IOCACK;
7700Sstevel@tonic-gate
7710Sstevel@tonic-gate qreply(q, mp);
7720Sstevel@tonic-gate break;
7730Sstevel@tonic-gate
7741253Slq150181 case CONS_GETTERM:
7751253Slq150181 if ((error = wc_getterm(mp)) != 0)
7761253Slq150181 miocnak(q, mp, 0, error);
7771253Slq150181 else
7781253Slq150181 miocack(q, mp, 0, 0);
7791253Slq150181 return;
7801253Slq150181
7810Sstevel@tonic-gate case WC_OPEN_FB:
7820Sstevel@tonic-gate /*
7830Sstevel@tonic-gate * Start out pessimistic, so that we can just jump to
7840Sstevel@tonic-gate * the reply to bail out.
7850Sstevel@tonic-gate */
7860Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK;
7870Sstevel@tonic-gate
7880Sstevel@tonic-gate /*
7890Sstevel@tonic-gate * First test: really, this should be done only from
7900Sstevel@tonic-gate * inside the kernel. Unfortunately, that information
7910Sstevel@tonic-gate * doesn't seem to be available in a streams ioctl,
7920Sstevel@tonic-gate * so restrict it to root only. (Perhaps we could check
7930Sstevel@tonic-gate * for ioc_cr == kcred.)
7940Sstevel@tonic-gate */
7950Sstevel@tonic-gate if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0)
7960Sstevel@tonic-gate goto open_fail;
7970Sstevel@tonic-gate
7980Sstevel@tonic-gate /*
7990Sstevel@tonic-gate * Some miscellaneous checks...
8000Sstevel@tonic-gate */
8010Sstevel@tonic-gate iocp->ioc_error = EINVAL;
8020Sstevel@tonic-gate
8030Sstevel@tonic-gate /*
8040Sstevel@tonic-gate * If we don't have exactly one continuation block, fail.
8050Sstevel@tonic-gate */
8067688SAaron.Zang@Sun.COM if (mp->b_cont == NULL ||
8077688SAaron.Zang@Sun.COM mp->b_cont->b_cont != NULL)
8080Sstevel@tonic-gate goto open_fail;
8090Sstevel@tonic-gate
8100Sstevel@tonic-gate /*
8110Sstevel@tonic-gate * If there's no null terminator in the string, fail.
8120Sstevel@tonic-gate */
8137688SAaron.Zang@Sun.COM /* LINTED E_PTRDIFF_OVERFLOW */
8147688SAaron.Zang@Sun.COM len = mp->b_cont->b_wptr - mp->b_cont->b_rptr;
8150Sstevel@tonic-gate if (memchr(mp->b_cont->b_rptr, 0, len) == NULL)
8160Sstevel@tonic-gate goto open_fail;
8170Sstevel@tonic-gate
8180Sstevel@tonic-gate /*
8190Sstevel@tonic-gate * NOTE: should eventually get default
8200Sstevel@tonic-gate * dimensions from a property, e.g. screen-#rows.
8210Sstevel@tonic-gate */
8227688SAaron.Zang@Sun.COM iocp->ioc_error = tem_info_init((char *)mp->b_cont->b_rptr,
8237688SAaron.Zang@Sun.COM iocp->ioc_cr);
8240Sstevel@tonic-gate /*
8250Sstevel@tonic-gate * Of course, if the terminal emulator initialization
8260Sstevel@tonic-gate * failed, fail.
8270Sstevel@tonic-gate */
8280Sstevel@tonic-gate if (iocp->ioc_error != 0)
8290Sstevel@tonic-gate goto open_fail;
8300Sstevel@tonic-gate
8317688SAaron.Zang@Sun.COM #ifdef _HAVE_TEM_FIRMWARE
8327688SAaron.Zang@Sun.COM if (prom_stdout_is_framebuffer()) {
8337688SAaron.Zang@Sun.COM /*
8347688SAaron.Zang@Sun.COM * Drivers in the console stream may emit additional
8357688SAaron.Zang@Sun.COM * messages before we are ready. This causes text
8367688SAaron.Zang@Sun.COM * overwrite on the screen. So we set the redirection
8377688SAaron.Zang@Sun.COM * here. It is safe because the ioctl in consconfig_dacf
8387688SAaron.Zang@Sun.COM * will succeed and consmode will be set to CONS_KFB.
8397688SAaron.Zang@Sun.COM */
8407688SAaron.Zang@Sun.COM prom_set_stdout_redirect(wc_cons_wrtvec,
8417688SAaron.Zang@Sun.COM (promif_redir_arg_t)NULL);
8421253Slq150181
8437688SAaron.Zang@Sun.COM }
8447688SAaron.Zang@Sun.COM #endif /* _HAVE_TEM_FIRMWARE */
8457688SAaron.Zang@Sun.COM
8467688SAaron.Zang@Sun.COM tem_register_modechg_cb(wc_modechg_cb,
8477688SAaron.Zang@Sun.COM (tem_modechg_cb_arg_t)&wscons);
8480Sstevel@tonic-gate
8490Sstevel@tonic-gate /*
8500Sstevel@tonic-gate * ... and succeed.
8510Sstevel@tonic-gate */
8520Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK;
8530Sstevel@tonic-gate
8540Sstevel@tonic-gate open_fail:
8550Sstevel@tonic-gate qreply(q, mp);
8560Sstevel@tonic-gate break;
8570Sstevel@tonic-gate
8580Sstevel@tonic-gate case WC_CLOSE_FB:
8590Sstevel@tonic-gate /*
8600Sstevel@tonic-gate * There's nothing that can call this, so it's not
8610Sstevel@tonic-gate * really implemented.
8620Sstevel@tonic-gate */
8630Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK;
8640Sstevel@tonic-gate /*
8650Sstevel@tonic-gate * However, if it were implemented, it would clearly
8660Sstevel@tonic-gate * be root-only.
8670Sstevel@tonic-gate */
8680Sstevel@tonic-gate if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0)
8690Sstevel@tonic-gate goto close_fail;
8700Sstevel@tonic-gate
8710Sstevel@tonic-gate iocp->ioc_error = EINVAL;
8720Sstevel@tonic-gate
8730Sstevel@tonic-gate close_fail:
8740Sstevel@tonic-gate qreply(q, mp);
8750Sstevel@tonic-gate break;
8760Sstevel@tonic-gate
8770Sstevel@tonic-gate default:
8780Sstevel@tonic-gate
8790Sstevel@tonic-gate /*
8800Sstevel@tonic-gate * The only way in which "ttycommon_ioctl" can fail is
8810Sstevel@tonic-gate * if the "ioctl" requires a response containing data
8820Sstevel@tonic-gate * to be returned to the user, and no mblk could be
8830Sstevel@tonic-gate * allocated for the data. No such "ioctl" alters our
8840Sstevel@tonic-gate * state. Thus, we always go ahead and do any
8850Sstevel@tonic-gate * state-changes the "ioctl" calls for. If we couldn't
8860Sstevel@tonic-gate * allocate the data, "ttycommon_ioctl" has stashed the
8870Sstevel@tonic-gate * "ioctl" away safely, so we just call "qbufcall" to
8880Sstevel@tonic-gate * request that we be called back when we stand a
8890Sstevel@tonic-gate * better chance of allocating the data.
8900Sstevel@tonic-gate */
8917688SAaron.Zang@Sun.COM datasize = ttycommon_ioctl(&pvc->vc_ttycommon, q, mp, &error);
8920Sstevel@tonic-gate if (datasize != 0) {
8937688SAaron.Zang@Sun.COM if (pvc->vc_bufcallid != 0)
8947688SAaron.Zang@Sun.COM qunbufcall(q, pvc->vc_bufcallid);
8957688SAaron.Zang@Sun.COM pvc->vc_bufcallid = qbufcall(q, datasize, BPRI_HI,
8967688SAaron.Zang@Sun.COM wcreioctl, pvc);
8970Sstevel@tonic-gate return;
8980Sstevel@tonic-gate }
8990Sstevel@tonic-gate
9000Sstevel@tonic-gate if (error < 0) {
9010Sstevel@tonic-gate if (iocp->ioc_cmd == TCSBRK)
9020Sstevel@tonic-gate error = 0;
9030Sstevel@tonic-gate else
9040Sstevel@tonic-gate error = EINVAL;
9050Sstevel@tonic-gate }
9060Sstevel@tonic-gate if (error != 0) {
9070Sstevel@tonic-gate iocp->ioc_error = error;
9080Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK;
9090Sstevel@tonic-gate }
9100Sstevel@tonic-gate qreply(q, mp);
9110Sstevel@tonic-gate break;
9120Sstevel@tonic-gate }
9130Sstevel@tonic-gate }
9140Sstevel@tonic-gate
9150Sstevel@tonic-gate /*
9160Sstevel@tonic-gate * This function gets the polled I/O structures from the lower
9170Sstevel@tonic-gate * keyboard driver. If any initialization or resource allocation
9180Sstevel@tonic-gate * needs to be done by the lower driver, it will be done when
9190Sstevel@tonic-gate * the lower driver services this message.
9200Sstevel@tonic-gate */
9210Sstevel@tonic-gate static void
wc_open_kb_polledio(struct wscons_state * wscons,queue_t * q,mblk_t * mp)9227688SAaron.Zang@Sun.COM wc_open_kb_polledio(struct wscons_state *wscons, queue_t *q, mblk_t *mp)
9230Sstevel@tonic-gate {
9240Sstevel@tonic-gate mblk_t *mp2;
9250Sstevel@tonic-gate struct iocblk *iocp;
9260Sstevel@tonic-gate
9270Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL,
9286990Sgd78059 ("wc_open_kb_polledio: sending CONSOPENPOLLEDIO\n"));
9290Sstevel@tonic-gate
9300Sstevel@tonic-gate mp2 = mkiocb(CONSOPENPOLLEDIO);
9310Sstevel@tonic-gate
9320Sstevel@tonic-gate if (mp2 == NULL) {
9330Sstevel@tonic-gate /*
9340Sstevel@tonic-gate * If we can't get an mblk, then wait for it.
9350Sstevel@tonic-gate */
9360Sstevel@tonic-gate goto nomem;
9370Sstevel@tonic-gate }
9380Sstevel@tonic-gate
9390Sstevel@tonic-gate mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI);
9400Sstevel@tonic-gate
9410Sstevel@tonic-gate if (mp2->b_cont == NULL) {
9420Sstevel@tonic-gate /*
9430Sstevel@tonic-gate * If we can't get an mblk, then wait for it, and release
9440Sstevel@tonic-gate * the mblk that we have already allocated.
9450Sstevel@tonic-gate */
9460Sstevel@tonic-gate freemsg(mp2);
9470Sstevel@tonic-gate goto nomem;
9480Sstevel@tonic-gate }
9490Sstevel@tonic-gate
9507688SAaron.Zang@Sun.COM iocp = (struct iocblk *)(void *)mp2->b_rptr;
9510Sstevel@tonic-gate
9520Sstevel@tonic-gate iocp->ioc_count = sizeof (struct cons_polledio *);
9530Sstevel@tonic-gate mp2->b_cont->b_wptr = mp2->b_cont->b_rptr +
9546990Sgd78059 sizeof (struct cons_polledio *);
9550Sstevel@tonic-gate
9567688SAaron.Zang@Sun.COM wscons->wc_pending_wq = q;
9570Sstevel@tonic-gate wscons->wc_pending_link = mp;
9580Sstevel@tonic-gate wscons->wc_kb_getpolledio_id = iocp->ioc_id;
9590Sstevel@tonic-gate
9600Sstevel@tonic-gate putnext(wscons->wc_kbdqueue, mp2);
9610Sstevel@tonic-gate
9620Sstevel@tonic-gate return;
9630Sstevel@tonic-gate
9640Sstevel@tonic-gate nomem:
9657688SAaron.Zang@Sun.COM iocp = (struct iocblk *)(void *)mp->b_rptr;
9660Sstevel@tonic-gate iocp->ioc_error = ENOMEM;
9670Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK;
9680Sstevel@tonic-gate qreply(q, mp);
9690Sstevel@tonic-gate }
9700Sstevel@tonic-gate
9710Sstevel@tonic-gate /*
9720Sstevel@tonic-gate * This function releases the polled I/O structures from the lower
9730Sstevel@tonic-gate * keyboard driver. If any de-initialization needs to be done, or
9740Sstevel@tonic-gate * any resources need to be released, it will be done when the lower
9750Sstevel@tonic-gate * driver services this message.
9760Sstevel@tonic-gate */
9770Sstevel@tonic-gate static void
wc_close_kb_polledio(struct wscons_state * wscons,queue_t * q,mblk_t * mp)9787688SAaron.Zang@Sun.COM wc_close_kb_polledio(struct wscons_state *wscons, queue_t *q, mblk_t *mp)
9790Sstevel@tonic-gate {
9800Sstevel@tonic-gate mblk_t *mp2;
9810Sstevel@tonic-gate struct iocblk *iocp;
9820Sstevel@tonic-gate
9830Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL,
9846990Sgd78059 ("wc_close_kb_polledio: sending CONSCLOSEPOLLEDIO\n"));
9850Sstevel@tonic-gate
9860Sstevel@tonic-gate mp2 = mkiocb(CONSCLOSEPOLLEDIO);
9870Sstevel@tonic-gate
9880Sstevel@tonic-gate if (mp2 == NULL) {
9890Sstevel@tonic-gate /*
9900Sstevel@tonic-gate * If we can't get an mblk, then wait for it.
9910Sstevel@tonic-gate */
9920Sstevel@tonic-gate goto nomem;
9930Sstevel@tonic-gate }
9940Sstevel@tonic-gate
9950Sstevel@tonic-gate mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI);
9960Sstevel@tonic-gate
9970Sstevel@tonic-gate if (mp2->b_cont == NULL) {
9980Sstevel@tonic-gate /*
9990Sstevel@tonic-gate * If we can't get an mblk, then wait for it, and release
10000Sstevel@tonic-gate * the mblk that we have already allocated.
10010Sstevel@tonic-gate */
10020Sstevel@tonic-gate freemsg(mp2);
10030Sstevel@tonic-gate
10040Sstevel@tonic-gate goto nomem;
10050Sstevel@tonic-gate }
10060Sstevel@tonic-gate
10077688SAaron.Zang@Sun.COM iocp = (struct iocblk *)(void *)mp2->b_rptr;
10080Sstevel@tonic-gate
10090Sstevel@tonic-gate iocp->ioc_count = 0;
10100Sstevel@tonic-gate
10117688SAaron.Zang@Sun.COM wscons->wc_pending_wq = q;
10120Sstevel@tonic-gate wscons->wc_pending_link = mp;
10130Sstevel@tonic-gate wscons->wc_kb_getpolledio_id = iocp->ioc_id;
10140Sstevel@tonic-gate
10150Sstevel@tonic-gate putnext(wscons->wc_kbdqueue, mp2);
10160Sstevel@tonic-gate
10170Sstevel@tonic-gate return;
10180Sstevel@tonic-gate
10190Sstevel@tonic-gate nomem:
10207688SAaron.Zang@Sun.COM iocp = (struct iocblk *)(void *)mp->b_rptr;
10210Sstevel@tonic-gate iocp->ioc_error = ENOMEM;
10220Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK;
10230Sstevel@tonic-gate qreply(q, mp);
10240Sstevel@tonic-gate }
10250Sstevel@tonic-gate
10261253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
10270Sstevel@tonic-gate /* ARGSUSED */
10280Sstevel@tonic-gate static void
wcopoll(void * arg)10290Sstevel@tonic-gate wcopoll(void *arg)
10300Sstevel@tonic-gate {
10317688SAaron.Zang@Sun.COM vc_state_t *pvc = (vc_state_t *)arg;
10320Sstevel@tonic-gate queue_t *q;
10330Sstevel@tonic-gate
10347688SAaron.Zang@Sun.COM q = pvc->vc_ttycommon.t_writeq;
10357688SAaron.Zang@Sun.COM pvc->vc_timeoutid = 0;
10367688SAaron.Zang@Sun.COM
10377688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
10387688SAaron.Zang@Sun.COM
10390Sstevel@tonic-gate /* See if we can continue output */
10407688SAaron.Zang@Sun.COM if ((pvc->vc_flags & WCS_BUSY) && pvc->vc_pendc != -1) {
10417688SAaron.Zang@Sun.COM if (prom_mayput((char)pvc->vc_pendc) == 0) {
10427688SAaron.Zang@Sun.COM pvc->vc_pendc = -1;
10437688SAaron.Zang@Sun.COM pvc->vc_flags &= ~WCS_BUSY;
10447688SAaron.Zang@Sun.COM if (!(pvc->vc_flags&(WCS_DELAY|WCS_STOPPED)))
10457688SAaron.Zang@Sun.COM wcstart(pvc);
10460Sstevel@tonic-gate } else
10477688SAaron.Zang@Sun.COM pvc->vc_timeoutid = qtimeout(q, wcopoll, pvc, 1);
10480Sstevel@tonic-gate }
10497688SAaron.Zang@Sun.COM
10507688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
10510Sstevel@tonic-gate }
10521253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
10530Sstevel@tonic-gate
10540Sstevel@tonic-gate /*
10550Sstevel@tonic-gate * Restart output on the console after a timeout.
10560Sstevel@tonic-gate */
10570Sstevel@tonic-gate /* ARGSUSED */
10580Sstevel@tonic-gate static void
wcrstrt(void * arg)10590Sstevel@tonic-gate wcrstrt(void *arg)
10600Sstevel@tonic-gate {
10617688SAaron.Zang@Sun.COM vc_state_t *pvc = (vc_state_t *)arg;
10627688SAaron.Zang@Sun.COM
10637688SAaron.Zang@Sun.COM ASSERT(pvc->vc_ttycommon.t_writeq != NULL);
10647688SAaron.Zang@Sun.COM
10657688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
10667688SAaron.Zang@Sun.COM pvc->vc_flags &= ~WCS_DELAY;
10677688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
10687688SAaron.Zang@Sun.COM
10697688SAaron.Zang@Sun.COM wcstart(pvc);
10707688SAaron.Zang@Sun.COM }
10717688SAaron.Zang@Sun.COM
10727688SAaron.Zang@Sun.COM /*
10737688SAaron.Zang@Sun.COM * get screen terminal for current output
10747688SAaron.Zang@Sun.COM */
10757688SAaron.Zang@Sun.COM static tem_vt_state_t
wc_get_screen_tem(vc_state_t * pvc)10767688SAaron.Zang@Sun.COM wc_get_screen_tem(vc_state_t *pvc)
10777688SAaron.Zang@Sun.COM {
10787688SAaron.Zang@Sun.COM if (!tem_initialized(pvc->vc_tem) ||
10797688SAaron.Zang@Sun.COM tem_get_fbmode(pvc->vc_tem) != KD_TEXT)
10807688SAaron.Zang@Sun.COM return (NULL);
10817688SAaron.Zang@Sun.COM
10827688SAaron.Zang@Sun.COM return (pvc->vc_tem);
10830Sstevel@tonic-gate }
10840Sstevel@tonic-gate
10850Sstevel@tonic-gate /*
10860Sstevel@tonic-gate * Start console output
10870Sstevel@tonic-gate */
10880Sstevel@tonic-gate static void
wcstart(void * arg)10897688SAaron.Zang@Sun.COM wcstart(void *arg)
10900Sstevel@tonic-gate {
10917688SAaron.Zang@Sun.COM vc_state_t *pvc = (vc_state_t *)arg;
10927688SAaron.Zang@Sun.COM tem_vt_state_t ptem = NULL;
10931253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
10940Sstevel@tonic-gate int c;
10950Sstevel@tonic-gate ssize_t cc;
10961253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
10970Sstevel@tonic-gate queue_t *q;
10980Sstevel@tonic-gate mblk_t *bp;
10990Sstevel@tonic-gate mblk_t *nbp;
11000Sstevel@tonic-gate
11010Sstevel@tonic-gate /*
11020Sstevel@tonic-gate * If we're waiting for something to happen (delay timeout to
11030Sstevel@tonic-gate * expire, current transmission to finish, output to be
11040Sstevel@tonic-gate * restarted, output to finish draining), don't grab anything
11050Sstevel@tonic-gate * new.
11060Sstevel@tonic-gate */
11077688SAaron.Zang@Sun.COM if (pvc->vc_flags & (WCS_DELAY|WCS_BUSY|WCS_STOPPED))
11081253Slq150181 return;
11090Sstevel@tonic-gate
11107688SAaron.Zang@Sun.COM q = pvc->vc_ttycommon.t_writeq;
11110Sstevel@tonic-gate /*
11120Sstevel@tonic-gate * assumes that we have been called by whoever holds the
11130Sstevel@tonic-gate * exclusionary lock on the write-side queue (protects
11147688SAaron.Zang@Sun.COM * vc_flags and vc_pendc).
11150Sstevel@tonic-gate */
11160Sstevel@tonic-gate for (;;) {
11170Sstevel@tonic-gate if ((bp = getq(q)) == NULL)
11181253Slq150181 return; /* nothing to transmit */
11190Sstevel@tonic-gate
11200Sstevel@tonic-gate /*
11210Sstevel@tonic-gate * We have a new message to work on.
11220Sstevel@tonic-gate * Check whether it's a delay or an ioctl (the latter
11230Sstevel@tonic-gate * occurs if the ioctl in question was waiting for the output
11240Sstevel@tonic-gate * to drain). If it's one of those, process it immediately.
11250Sstevel@tonic-gate */
11260Sstevel@tonic-gate switch (bp->b_datap->db_type) {
11270Sstevel@tonic-gate
11280Sstevel@tonic-gate case M_DELAY:
11290Sstevel@tonic-gate /*
11300Sstevel@tonic-gate * Arrange for "wcrstrt" to be called when the
11310Sstevel@tonic-gate * delay expires; it will turn WCS_DELAY off,
11320Sstevel@tonic-gate * and call "wcstart" to grab the next message.
11330Sstevel@tonic-gate */
11347688SAaron.Zang@Sun.COM if (pvc->vc_timeoutid != 0)
11357688SAaron.Zang@Sun.COM (void) quntimeout(q, pvc->vc_timeoutid);
11367688SAaron.Zang@Sun.COM pvc->vc_timeoutid = qtimeout(q, wcrstrt, pvc,
11370Sstevel@tonic-gate (clock_t)(*(unsigned char *)bp->b_rptr + 6));
11387688SAaron.Zang@Sun.COM
11397688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
11407688SAaron.Zang@Sun.COM pvc->vc_flags |= WCS_DELAY;
11417688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
11427688SAaron.Zang@Sun.COM
11430Sstevel@tonic-gate freemsg(bp);
11441253Slq150181 return; /* wait for this to finish */
11450Sstevel@tonic-gate
11460Sstevel@tonic-gate case M_IOCTL:
11470Sstevel@tonic-gate /*
11480Sstevel@tonic-gate * This ioctl was waiting for the output ahead of
11490Sstevel@tonic-gate * it to drain; obviously, it has. Do it, and
11500Sstevel@tonic-gate * then grab the next message after it.
11510Sstevel@tonic-gate */
11520Sstevel@tonic-gate wcioctl(q, bp);
11530Sstevel@tonic-gate continue;
11540Sstevel@tonic-gate }
11550Sstevel@tonic-gate
11561253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
11571253Slq150181 if (consmode == CONS_KFB) {
11581253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
11597688SAaron.Zang@Sun.COM if ((ptem = wc_get_screen_tem(pvc)) != NULL) {
11607688SAaron.Zang@Sun.COM
11611253Slq150181 for (nbp = bp; nbp != NULL; nbp = nbp->b_cont) {
11621253Slq150181 if (nbp->b_wptr > nbp->b_rptr) {
11637688SAaron.Zang@Sun.COM (void) tem_write(ptem,
11641253Slq150181 nbp->b_rptr,
11657688SAaron.Zang@Sun.COM /* LINTED */
11667688SAaron.Zang@Sun.COM nbp->b_wptr - nbp->b_rptr,
11671253Slq150181 kcred);
11681253Slq150181 }
11691253Slq150181 }
11707688SAaron.Zang@Sun.COM
11711253Slq150181 }
11727688SAaron.Zang@Sun.COM
11737688SAaron.Zang@Sun.COM freemsg(bp);
11747688SAaron.Zang@Sun.COM
11751253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
11761253Slq150181 continue;
11770Sstevel@tonic-gate }
11781253Slq150181
11791253Slq150181 /* consmode = CONS_FW */
11807688SAaron.Zang@Sun.COM if (pvc->vc_minor != 0) {
11817688SAaron.Zang@Sun.COM freemsg(bp);
11827688SAaron.Zang@Sun.COM continue;
11837688SAaron.Zang@Sun.COM }
11847688SAaron.Zang@Sun.COM
11857688SAaron.Zang@Sun.COM /* LINTED E_PTRDIFF_OVERFLOW */
11867688SAaron.Zang@Sun.COM if ((cc = bp->b_wptr - bp->b_rptr) == 0) {
11870Sstevel@tonic-gate freemsg(bp);
11880Sstevel@tonic-gate continue;
11890Sstevel@tonic-gate }
11900Sstevel@tonic-gate /*
11910Sstevel@tonic-gate * Direct output to the frame buffer if this device
11920Sstevel@tonic-gate * is not the "hardware" console.
11930Sstevel@tonic-gate */
11940Sstevel@tonic-gate if (wscons.wc_defer_output) {
11950Sstevel@tonic-gate /*
11960Sstevel@tonic-gate * Never do output here;
11970Sstevel@tonic-gate * it takes forever.
11980Sstevel@tonic-gate */
11997688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
12007688SAaron.Zang@Sun.COM pvc->vc_flags |= WCS_BUSY;
12017688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
12027688SAaron.Zang@Sun.COM
12037688SAaron.Zang@Sun.COM pvc->vc_pendc = -1;
12040Sstevel@tonic-gate (void) putbq(q, bp);
12051253Slq150181 if (q->q_count > 128) { /* do it soon */
12067688SAaron.Zang@Sun.COM softcall(wconsout, pvc);
12071253Slq150181 } else { /* wait a bit */
12087688SAaron.Zang@Sun.COM if (pvc->vc_timeoutid != 0)
12090Sstevel@tonic-gate (void) quntimeout(q,
12107688SAaron.Zang@Sun.COM pvc->vc_timeoutid);
12117688SAaron.Zang@Sun.COM pvc->vc_timeoutid = qtimeout(q, wconsout,
12127688SAaron.Zang@Sun.COM pvc, hz / 30);
12130Sstevel@tonic-gate }
12141253Slq150181 return;
12150Sstevel@tonic-gate }
12160Sstevel@tonic-gate for (;;) {
12170Sstevel@tonic-gate c = *bp->b_rptr++;
12180Sstevel@tonic-gate cc--;
12190Sstevel@tonic-gate if (prom_mayput((char)c) != 0) {
12207688SAaron.Zang@Sun.COM
12217688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
12227688SAaron.Zang@Sun.COM pvc->vc_flags |= WCS_BUSY;
12237688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
12247688SAaron.Zang@Sun.COM
12257688SAaron.Zang@Sun.COM pvc->vc_pendc = c;
12267688SAaron.Zang@Sun.COM if (pvc->vc_timeoutid != 0)
12270Sstevel@tonic-gate (void) quntimeout(q,
12287688SAaron.Zang@Sun.COM pvc->vc_timeoutid);
12297688SAaron.Zang@Sun.COM pvc->vc_timeoutid = qtimeout(q, wcopoll,
12307688SAaron.Zang@Sun.COM pvc, 1);
12310Sstevel@tonic-gate if (bp != NULL)
12321253Slq150181 /* not done with this message yet */
12330Sstevel@tonic-gate (void) putbq(q, bp);
12341253Slq150181 return;
12350Sstevel@tonic-gate }
12360Sstevel@tonic-gate while (cc <= 0) {
12370Sstevel@tonic-gate nbp = bp;
12380Sstevel@tonic-gate bp = bp->b_cont;
12390Sstevel@tonic-gate freeb(nbp);
12400Sstevel@tonic-gate if (bp == NULL)
12411253Slq150181 return;
12427688SAaron.Zang@Sun.COM /* LINTED E_PTRDIFF_OVERFLOW */
12437688SAaron.Zang@Sun.COM cc = bp->b_wptr - bp->b_rptr;
12440Sstevel@tonic-gate }
12450Sstevel@tonic-gate }
12461253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
12470Sstevel@tonic-gate }
12480Sstevel@tonic-gate }
12490Sstevel@tonic-gate
12501253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
12510Sstevel@tonic-gate /*
12520Sstevel@tonic-gate * Output to frame buffer console.
12530Sstevel@tonic-gate * It takes a long time to scroll.
12540Sstevel@tonic-gate */
12550Sstevel@tonic-gate /* ARGSUSED */
12560Sstevel@tonic-gate static void
wconsout(void * arg)12577688SAaron.Zang@Sun.COM wconsout(void *arg)
12580Sstevel@tonic-gate {
12597688SAaron.Zang@Sun.COM vc_state_t *pvc = (vc_state_t *)arg;
12600Sstevel@tonic-gate uchar_t *cp;
12610Sstevel@tonic-gate ssize_t cc;
12620Sstevel@tonic-gate queue_t *q;
12630Sstevel@tonic-gate mblk_t *bp;
12640Sstevel@tonic-gate mblk_t *nbp;
12650Sstevel@tonic-gate char *current_position;
12660Sstevel@tonic-gate ssize_t bytes_left;
12670Sstevel@tonic-gate
12687688SAaron.Zang@Sun.COM if ((q = pvc->vc_ttycommon.t_writeq) == NULL) {
12690Sstevel@tonic-gate return; /* not attached to a stream */
12700Sstevel@tonic-gate }
12710Sstevel@tonic-gate
12720Sstevel@tonic-gate /*
12730Sstevel@tonic-gate * Set up to copy up to MAXHIWAT bytes.
12740Sstevel@tonic-gate */
12750Sstevel@tonic-gate current_position = &obuf[0];
12760Sstevel@tonic-gate bytes_left = MAXHIWAT;
12770Sstevel@tonic-gate while ((bp = getq(q)) != NULL) {
12780Sstevel@tonic-gate if (bp->b_datap->db_type == M_IOCTL) {
12790Sstevel@tonic-gate /*
12800Sstevel@tonic-gate * This ioctl was waiting for the output ahead of
12810Sstevel@tonic-gate * it to drain; obviously, it has. Put it back
12820Sstevel@tonic-gate * so that "wcstart" can handle it, and transmit
12830Sstevel@tonic-gate * what we've got.
12840Sstevel@tonic-gate */
12850Sstevel@tonic-gate (void) putbq(q, bp);
12860Sstevel@tonic-gate goto transmit;
12870Sstevel@tonic-gate }
12880Sstevel@tonic-gate
12890Sstevel@tonic-gate do {
12900Sstevel@tonic-gate cp = bp->b_rptr;
12917688SAaron.Zang@Sun.COM /* LINTED E_PTRDIFF_OVERFLOW */
12927688SAaron.Zang@Sun.COM cc = bp->b_wptr - cp;
12930Sstevel@tonic-gate while (cc != 0) {
12940Sstevel@tonic-gate if (bytes_left == 0) {
12950Sstevel@tonic-gate /*
12960Sstevel@tonic-gate * Out of buffer space; put this
12970Sstevel@tonic-gate * buffer back on the queue, and
12980Sstevel@tonic-gate * transmit what we have.
12990Sstevel@tonic-gate */
13000Sstevel@tonic-gate bp->b_rptr = cp;
13010Sstevel@tonic-gate (void) putbq(q, bp);
13020Sstevel@tonic-gate goto transmit;
13030Sstevel@tonic-gate }
13040Sstevel@tonic-gate *current_position++ = *cp++;
13050Sstevel@tonic-gate cc--;
13060Sstevel@tonic-gate bytes_left--;
13070Sstevel@tonic-gate }
13080Sstevel@tonic-gate nbp = bp;
13090Sstevel@tonic-gate bp = bp->b_cont;
13100Sstevel@tonic-gate freeb(nbp);
13110Sstevel@tonic-gate } while (bp != NULL);
13120Sstevel@tonic-gate }
13130Sstevel@tonic-gate
13140Sstevel@tonic-gate transmit:
13150Sstevel@tonic-gate if ((cc = MAXHIWAT - bytes_left) != 0)
13160Sstevel@tonic-gate console_puts(obuf, cc);
13170Sstevel@tonic-gate
13187688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
13197688SAaron.Zang@Sun.COM pvc->vc_flags &= ~WCS_BUSY;
13207688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
13217688SAaron.Zang@Sun.COM
13227688SAaron.Zang@Sun.COM wcstart(pvc);
13230Sstevel@tonic-gate }
13241253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
13250Sstevel@tonic-gate
13260Sstevel@tonic-gate /*
13270Sstevel@tonic-gate * Put procedure for lower read queue.
13280Sstevel@tonic-gate * Pass everything up to queue above "upper half".
13290Sstevel@tonic-gate */
13300Sstevel@tonic-gate static int
wclrput(queue_t * q,mblk_t * mp)13310Sstevel@tonic-gate wclrput(queue_t *q, mblk_t *mp)
13320Sstevel@tonic-gate {
13337688SAaron.Zang@Sun.COM vc_state_t *pvc;
13340Sstevel@tonic-gate queue_t *upq;
13350Sstevel@tonic-gate struct iocblk *iocp;
13360Sstevel@tonic-gate
13377688SAaron.Zang@Sun.COM pvc = vt_minor2vc(VT_ACTIVE);
13387688SAaron.Zang@Sun.COM
13390Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL,
13406990Sgd78059 ("wclrput: wclrput type = 0x%x\n", mp->b_datap->db_type));
13410Sstevel@tonic-gate
13420Sstevel@tonic-gate switch (mp->b_datap->db_type) {
13430Sstevel@tonic-gate
13440Sstevel@tonic-gate case M_FLUSH:
13450Sstevel@tonic-gate if (*mp->b_rptr == FLUSHW || *mp->b_rptr == FLUSHRW) {
13460Sstevel@tonic-gate /*
13470Sstevel@tonic-gate * Flush our write queue.
13480Sstevel@tonic-gate */
13490Sstevel@tonic-gate /* XXX doesn't flush M_DELAY */
13500Sstevel@tonic-gate flushq(WR(q), FLUSHDATA);
13510Sstevel@tonic-gate *mp->b_rptr = FLUSHR; /* it has been flushed */
13520Sstevel@tonic-gate }
13530Sstevel@tonic-gate if (*mp->b_rptr == FLUSHR || *mp->b_rptr == FLUSHRW) {
13540Sstevel@tonic-gate flushq(q, FLUSHDATA);
13550Sstevel@tonic-gate *mp->b_rptr = FLUSHW; /* it has been flushed */
13560Sstevel@tonic-gate qreply(q, mp); /* give the read queues a crack at it */
13570Sstevel@tonic-gate } else
13580Sstevel@tonic-gate freemsg(mp);
13590Sstevel@tonic-gate break;
13600Sstevel@tonic-gate
13610Sstevel@tonic-gate case M_DATA:
13627688SAaron.Zang@Sun.COM if (consmode == CONS_KFB && vt_check_hotkeys(mp)) {
13637688SAaron.Zang@Sun.COM freemsg(mp);
13647688SAaron.Zang@Sun.COM break;
13657688SAaron.Zang@Sun.COM }
13667688SAaron.Zang@Sun.COM
13677688SAaron.Zang@Sun.COM if ((upq = pvc->vc_ttycommon.t_readq) != NULL) {
13680Sstevel@tonic-gate if (!canput(upq->q_next)) {
13697688SAaron.Zang@Sun.COM ttycommon_qfull(&pvc->vc_ttycommon, upq);
13707688SAaron.Zang@Sun.COM wcstart(pvc);
13710Sstevel@tonic-gate freemsg(mp);
13727688SAaron.Zang@Sun.COM } else {
13730Sstevel@tonic-gate putnext(upq, mp);
13747688SAaron.Zang@Sun.COM }
13750Sstevel@tonic-gate } else
13760Sstevel@tonic-gate freemsg(mp);
13770Sstevel@tonic-gate break;
13780Sstevel@tonic-gate
13790Sstevel@tonic-gate case M_IOCACK:
13800Sstevel@tonic-gate case M_IOCNAK:
13817688SAaron.Zang@Sun.COM iocp = (struct iocblk *)(void *)mp->b_rptr;
13820Sstevel@tonic-gate if (wscons.wc_pending_link != NULL &&
13830Sstevel@tonic-gate iocp->ioc_id == wscons.wc_kb_getpolledio_id) {
13840Sstevel@tonic-gate switch (mp->b_datap->db_type) {
13850Sstevel@tonic-gate
13860Sstevel@tonic-gate case M_IOCACK:
13870Sstevel@tonic-gate switch (iocp->ioc_cmd) {
13880Sstevel@tonic-gate
13890Sstevel@tonic-gate case CONSOPENPOLLEDIO:
13900Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL,
13916990Sgd78059 ("wclrput: "
13926990Sgd78059 "ACK CONSOPENPOLLEDIO\n"));
13930Sstevel@tonic-gate wscons.wc_kb_polledio =
13947688SAaron.Zang@Sun.COM *(struct cons_polledio **)
13957688SAaron.Zang@Sun.COM (void *)mp->b_cont->b_rptr;
13961253Slq150181 wscons.wc_polledio.
13971253Slq150181 cons_polledio_getchar =
13986990Sgd78059 wc_polled_getchar;
13991253Slq150181 wscons.wc_polledio.
14001253Slq150181 cons_polledio_ischar =
14016990Sgd78059 wc_polled_ischar;
14020Sstevel@tonic-gate break;
14030Sstevel@tonic-gate
14040Sstevel@tonic-gate case CONSCLOSEPOLLEDIO:
14050Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL,
14066990Sgd78059 ("wclrput: "
14076990Sgd78059 "ACK CONSCLOSEPOLLEDIO\n"));
14080Sstevel@tonic-gate wscons.wc_kb_polledio = NULL;
14090Sstevel@tonic-gate wscons.wc_kbdqueue = NULL;
14101253Slq150181 wscons.wc_polledio.
14111253Slq150181 cons_polledio_getchar = NULL;
14121253Slq150181 wscons.wc_polledio.
14131253Slq150181 cons_polledio_ischar = NULL;
14140Sstevel@tonic-gate break;
14150Sstevel@tonic-gate default:
14160Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL,
14177688SAaron.Zang@Sun.COM ("wclrput: "
14187688SAaron.Zang@Sun.COM "ACK UNKNOWN\n"));
14190Sstevel@tonic-gate }
14200Sstevel@tonic-gate
14210Sstevel@tonic-gate break;
14220Sstevel@tonic-gate case M_IOCNAK:
14230Sstevel@tonic-gate /*
14240Sstevel@tonic-gate * Keyboard may or may not support polled I/O.
14250Sstevel@tonic-gate * This ioctl may have been rejected because
14260Sstevel@tonic-gate * we only have the wc->conskbd chain built,
14270Sstevel@tonic-gate * and the keyboard driver has not been linked
14280Sstevel@tonic-gate * underneath conskbd yet.
14290Sstevel@tonic-gate */
14300Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL,
14316990Sgd78059 ("wclrput: NAK\n"));
14320Sstevel@tonic-gate
14330Sstevel@tonic-gate switch (iocp->ioc_cmd) {
14340Sstevel@tonic-gate
14350Sstevel@tonic-gate case CONSCLOSEPOLLEDIO:
14360Sstevel@tonic-gate wscons.wc_kb_polledio = NULL;
14370Sstevel@tonic-gate wscons.wc_kbdqueue = NULL;
14381253Slq150181 wscons.wc_polledio.
14391253Slq150181 cons_polledio_getchar = NULL;
14401253Slq150181 wscons.wc_polledio.
14411253Slq150181 cons_polledio_ischar = NULL;
14420Sstevel@tonic-gate break;
14430Sstevel@tonic-gate }
14440Sstevel@tonic-gate break;
14450Sstevel@tonic-gate }
14460Sstevel@tonic-gate
14470Sstevel@tonic-gate /*
14480Sstevel@tonic-gate * Discard the response, replace it with the
14490Sstevel@tonic-gate * pending response to the I_PLINK, then let it
14500Sstevel@tonic-gate * flow upward.
14510Sstevel@tonic-gate */
14520Sstevel@tonic-gate freemsg(mp);
14530Sstevel@tonic-gate mp = wscons.wc_pending_link;
14540Sstevel@tonic-gate wscons.wc_pending_link = NULL;
14550Sstevel@tonic-gate wscons.wc_kb_getpolledio_id = 0;
14560Sstevel@tonic-gate }
14570Sstevel@tonic-gate /* FALLTHROUGH */
14580Sstevel@tonic-gate
14590Sstevel@tonic-gate default: /* inc M_ERROR, M_HANGUP, M_IOCACK, M_IOCNAK, ... */
14607688SAaron.Zang@Sun.COM if (wscons.wc_pending_wq != NULL) {
14617688SAaron.Zang@Sun.COM qreply(wscons.wc_pending_wq, mp);
14627688SAaron.Zang@Sun.COM wscons.wc_pending_wq = NULL;
14637688SAaron.Zang@Sun.COM break;
14647688SAaron.Zang@Sun.COM }
14657688SAaron.Zang@Sun.COM
14667688SAaron.Zang@Sun.COM if ((upq = pvc->vc_ttycommon.t_readq) != NULL) {
14670Sstevel@tonic-gate putnext(upq, mp);
14680Sstevel@tonic-gate } else {
14697688SAaron.Zang@Sun.COM DPRINTF(PRINT_L1, PRINT_MASK_ALL,
14707688SAaron.Zang@Sun.COM ("wclrput: Message DISCARDED\n"));
14710Sstevel@tonic-gate freemsg(mp);
14720Sstevel@tonic-gate }
14730Sstevel@tonic-gate break;
14740Sstevel@tonic-gate }
14750Sstevel@tonic-gate
14760Sstevel@tonic-gate return (0);
14770Sstevel@tonic-gate }
14780Sstevel@tonic-gate
14797688SAaron.Zang@Sun.COM #ifdef _HAVE_TEM_FIRMWARE
14807688SAaron.Zang@Sun.COM /*
14817688SAaron.Zang@Sun.COM * This routine exists so that prom_write() can redirect writes
14827688SAaron.Zang@Sun.COM * to the framebuffer through the kernel terminal emulator, if
14837688SAaron.Zang@Sun.COM * that configuration is selected during consconfig.
14847688SAaron.Zang@Sun.COM * When the kernel terminal emulator is enabled, consconfig_dacf
14857688SAaron.Zang@Sun.COM * sets up the PROM output redirect vector to enter this function.
14867688SAaron.Zang@Sun.COM * During panic the console will already be powered up as part of
14877688SAaron.Zang@Sun.COM * calling into the prom_*() layer.
14887688SAaron.Zang@Sun.COM */
14897688SAaron.Zang@Sun.COM /* ARGSUSED */
14907688SAaron.Zang@Sun.COM ssize_t
wc_cons_wrtvec(promif_redir_arg_t arg,uchar_t * s,size_t n)14917688SAaron.Zang@Sun.COM wc_cons_wrtvec(promif_redir_arg_t arg, uchar_t *s, size_t n)
14927688SAaron.Zang@Sun.COM {
14937688SAaron.Zang@Sun.COM vc_state_t *pvc;
14947688SAaron.Zang@Sun.COM
14957688SAaron.Zang@Sun.COM pvc = vt_minor2vc(VT_ACTIVE);
14967688SAaron.Zang@Sun.COM
14977688SAaron.Zang@Sun.COM if (pvc->vc_tem == NULL)
14987688SAaron.Zang@Sun.COM return (0);
14997688SAaron.Zang@Sun.COM
15007688SAaron.Zang@Sun.COM ASSERT(consmode == CONS_KFB);
15017688SAaron.Zang@Sun.COM
15027688SAaron.Zang@Sun.COM if (panicstr)
15037688SAaron.Zang@Sun.COM polled_io_cons_write(s, n);
15047688SAaron.Zang@Sun.COM else
15057688SAaron.Zang@Sun.COM (void) tem_write(pvc->vc_tem, s, n, kcred);
15067688SAaron.Zang@Sun.COM
15077688SAaron.Zang@Sun.COM return (n);
15087688SAaron.Zang@Sun.COM }
15097688SAaron.Zang@Sun.COM #endif /* _HAVE_TEM_FIRMWARE */
15107688SAaron.Zang@Sun.COM
15110Sstevel@tonic-gate /*
15121253Slq150181 * These are for systems without OBP, and for devices that cannot be
15131253Slq150181 * shared between Solaris and the OBP.
15140Sstevel@tonic-gate */
15150Sstevel@tonic-gate static void
wc_polled_putchar(cons_polledio_arg_t arg,unsigned char c)15161762Slt200341 wc_polled_putchar(cons_polledio_arg_t arg, unsigned char c)
15170Sstevel@tonic-gate {
15187688SAaron.Zang@Sun.COM vc_state_t *pvc;
15197688SAaron.Zang@Sun.COM
15207688SAaron.Zang@Sun.COM pvc = vt_minor2vc(VT_ACTIVE);
15217688SAaron.Zang@Sun.COM
15220Sstevel@tonic-gate if (c == '\n')
15231253Slq150181 wc_polled_putchar(arg, '\r');
15240Sstevel@tonic-gate
15257688SAaron.Zang@Sun.COM if (pvc->vc_tem == NULL) {
15260Sstevel@tonic-gate /*
15270Sstevel@tonic-gate * We have no terminal emulator configured. We have no
15280Sstevel@tonic-gate * recourse but to drop the output on the floor.
15290Sstevel@tonic-gate */
15300Sstevel@tonic-gate return;
15310Sstevel@tonic-gate }
15320Sstevel@tonic-gate
15337688SAaron.Zang@Sun.COM tem_safe_polled_write(pvc->vc_tem, &c, 1);
15340Sstevel@tonic-gate }
15350Sstevel@tonic-gate
15360Sstevel@tonic-gate /*
15370Sstevel@tonic-gate * These are for systems without OBP, and for devices that cannot be
15380Sstevel@tonic-gate * shared between Solaris and the OBP.
15390Sstevel@tonic-gate */
15400Sstevel@tonic-gate static int
wc_polled_getchar(cons_polledio_arg_t arg)15411762Slt200341 wc_polled_getchar(cons_polledio_arg_t arg)
15420Sstevel@tonic-gate {
15437688SAaron.Zang@Sun.COM struct wscons_state *wscons = (struct wscons_state *)arg;
15440Sstevel@tonic-gate
15450Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) {
15460Sstevel@tonic-gate prom_printf("wscons: getchar with no keyboard support");
15470Sstevel@tonic-gate prom_printf("Halted...");
15480Sstevel@tonic-gate for (;;)
15490Sstevel@tonic-gate /* HANG FOREVER */;
15500Sstevel@tonic-gate }
15510Sstevel@tonic-gate
15520Sstevel@tonic-gate return (wscons->wc_kb_polledio->cons_polledio_getchar(
15531253Slq150181 wscons->wc_kb_polledio->cons_polledio_argument));
15540Sstevel@tonic-gate }
15550Sstevel@tonic-gate
15560Sstevel@tonic-gate static boolean_t
wc_polled_ischar(cons_polledio_arg_t arg)15571762Slt200341 wc_polled_ischar(cons_polledio_arg_t arg)
15580Sstevel@tonic-gate {
15597688SAaron.Zang@Sun.COM struct wscons_state *wscons = (struct wscons_state *)arg;
15600Sstevel@tonic-gate
15610Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL)
15620Sstevel@tonic-gate return (B_FALSE);
15630Sstevel@tonic-gate
15640Sstevel@tonic-gate return (wscons->wc_kb_polledio->cons_polledio_ischar(
15651253Slq150181 wscons->wc_kb_polledio->cons_polledio_argument));
15660Sstevel@tonic-gate }
15670Sstevel@tonic-gate
15680Sstevel@tonic-gate static void
wc_polled_enter(cons_polledio_arg_t arg)15691762Slt200341 wc_polled_enter(cons_polledio_arg_t arg)
15700Sstevel@tonic-gate {
15717688SAaron.Zang@Sun.COM struct wscons_state *wscons = (struct wscons_state *)arg;
15720Sstevel@tonic-gate
15730Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL)
15740Sstevel@tonic-gate return;
15750Sstevel@tonic-gate
15760Sstevel@tonic-gate if (wscons->wc_kb_polledio->cons_polledio_enter != NULL) {
15770Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_enter(
15781253Slq150181 wscons->wc_kb_polledio->cons_polledio_argument);
15790Sstevel@tonic-gate }
15800Sstevel@tonic-gate }
15810Sstevel@tonic-gate
15820Sstevel@tonic-gate static void
wc_polled_exit(cons_polledio_arg_t arg)15831762Slt200341 wc_polled_exit(cons_polledio_arg_t arg)
15840Sstevel@tonic-gate {
15857688SAaron.Zang@Sun.COM struct wscons_state *wscons = (struct wscons_state *)arg;
15860Sstevel@tonic-gate
15870Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL)
15880Sstevel@tonic-gate return;
15890Sstevel@tonic-gate
15900Sstevel@tonic-gate if (wscons->wc_kb_polledio->cons_polledio_exit != NULL) {
15910Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_exit(
15921253Slq150181 wscons->wc_kb_polledio->cons_polledio_argument);
15930Sstevel@tonic-gate }
15940Sstevel@tonic-gate }
15950Sstevel@tonic-gate
15960Sstevel@tonic-gate
15970Sstevel@tonic-gate #ifdef DEBUG
15980Sstevel@tonic-gate static void
wc_dprintf(const char * fmt,...)15990Sstevel@tonic-gate wc_dprintf(const char *fmt, ...)
16000Sstevel@tonic-gate {
16010Sstevel@tonic-gate char buf[256];
16020Sstevel@tonic-gate va_list ap;
16030Sstevel@tonic-gate
16040Sstevel@tonic-gate va_start(ap, fmt);
16050Sstevel@tonic-gate (void) vsprintf(buf, fmt, ap);
16060Sstevel@tonic-gate va_end(ap);
16070Sstevel@tonic-gate
16081253Slq150181 cmn_err(CE_WARN, "wc: %s", buf);
16090Sstevel@tonic-gate }
16100Sstevel@tonic-gate #endif
16110Sstevel@tonic-gate
16127688SAaron.Zang@Sun.COM /*ARGSUSED*/
16131253Slq150181 static void
update_property(vc_state_t * pvc,char * name,ushort_t value)16147688SAaron.Zang@Sun.COM update_property(vc_state_t *pvc, char *name, ushort_t value)
16150Sstevel@tonic-gate {
16161253Slq150181 char data[8];
16170Sstevel@tonic-gate
16181253Slq150181 (void) snprintf(data, sizeof (data), "%u", value);
16197688SAaron.Zang@Sun.COM
16207688SAaron.Zang@Sun.COM (void) ddi_prop_update_string(wscons.wc_dev, wc_dip, name, data);
16210Sstevel@tonic-gate }
16220Sstevel@tonic-gate
16230Sstevel@tonic-gate /*
16240Sstevel@tonic-gate * Gets the number of text rows and columns and the
16250Sstevel@tonic-gate * width and height (in pixels) of the console.
16260Sstevel@tonic-gate */
16277688SAaron.Zang@Sun.COM void
wc_get_size(vc_state_t * pvc)16287688SAaron.Zang@Sun.COM wc_get_size(vc_state_t *pvc)
16290Sstevel@tonic-gate {
16307688SAaron.Zang@Sun.COM struct winsize *t = &pvc->vc_ttycommon.t_size;
16311253Slq150181 ushort_t r = LOSCREENLINES, c = LOSCREENCOLS, x = 0, y = 0;
16320Sstevel@tonic-gate
16337688SAaron.Zang@Sun.COM if (pvc->vc_tem != NULL)
16347688SAaron.Zang@Sun.COM tem_get_size(&r, &c, &x, &y);
16351253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
16367688SAaron.Zang@Sun.COM else
16371253Slq150181 console_get_size(&r, &c, &x, &y);
16381253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
16390Sstevel@tonic-gate
16407688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_ttycommon.t_excl);
16417688SAaron.Zang@Sun.COM t->ws_col = c;
16427688SAaron.Zang@Sun.COM t->ws_row = r;
16437688SAaron.Zang@Sun.COM t->ws_xpixel = x;
16447688SAaron.Zang@Sun.COM t->ws_ypixel = y;
16457688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_ttycommon.t_excl);
16467688SAaron.Zang@Sun.COM
16477688SAaron.Zang@Sun.COM if (pvc->vc_minor != 0)
16487688SAaron.Zang@Sun.COM return;
16497688SAaron.Zang@Sun.COM
16507688SAaron.Zang@Sun.COM /* only for the wscons:0 */
16517688SAaron.Zang@Sun.COM update_property(pvc, "screen-#cols", c);
16527688SAaron.Zang@Sun.COM update_property(pvc, "screen-#rows", r);
16537688SAaron.Zang@Sun.COM update_property(pvc, "screen-width", x);
16547688SAaron.Zang@Sun.COM update_property(pvc, "screen-height", y);
16551253Slq150181 }
16560Sstevel@tonic-gate
16577688SAaron.Zang@Sun.COM /*ARGSUSED*/
16581253Slq150181 static void
wc_modechg_cb(tem_modechg_cb_arg_t arg)16591253Slq150181 wc_modechg_cb(tem_modechg_cb_arg_t arg)
16601253Slq150181 {
16617688SAaron.Zang@Sun.COM minor_t index;
16627688SAaron.Zang@Sun.COM vc_state_t *pvc;
16637688SAaron.Zang@Sun.COM
16647688SAaron.Zang@Sun.COM mutex_enter(&vc_lock);
16657688SAaron.Zang@Sun.COM for (index = 0; index < VC_INSTANCES_COUNT; index++) {
16667688SAaron.Zang@Sun.COM pvc = vt_minor2vc(index);
16677688SAaron.Zang@Sun.COM
16687688SAaron.Zang@Sun.COM mutex_enter(&pvc->vc_state_lock);
16697688SAaron.Zang@Sun.COM
16707688SAaron.Zang@Sun.COM if ((pvc->vc_flags & WCS_ISOPEN) &&
16717688SAaron.Zang@Sun.COM (pvc->vc_flags & WCS_INIT))
16727688SAaron.Zang@Sun.COM wc_get_size(pvc);
16737688SAaron.Zang@Sun.COM
16747688SAaron.Zang@Sun.COM mutex_exit(&pvc->vc_state_lock);
16757688SAaron.Zang@Sun.COM }
16767688SAaron.Zang@Sun.COM mutex_exit(&vc_lock);
16770Sstevel@tonic-gate }
1678