17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5fea9cb91Slq150181 * Common Development and Distribution License (the "License"). 6fea9cb91Slq150181 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21fea9cb91Slq150181 227c478bd9Sstevel@tonic-gate /* 2322eb7cb5Sgd78059 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * "Workstation console" multiplexor driver for Sun. 297c478bd9Sstevel@tonic-gate * 307c478bd9Sstevel@tonic-gate * Sends output to the primary frame buffer using the PROM monitor; 317c478bd9Sstevel@tonic-gate * gets input from a stream linked below us that is the "keyboard 327c478bd9Sstevel@tonic-gate * driver", below which is linked the primary keyboard. 337c478bd9Sstevel@tonic-gate */ 347c478bd9Sstevel@tonic-gate 35*aecfc01dSrui zang - Sun Microsystems - Beijing China /* 36*aecfc01dSrui zang - Sun Microsystems - Beijing China * Locking Policy: 37*aecfc01dSrui zang - Sun Microsystems - Beijing China * This module has a D_MTPERMOD inner perimeter which means STREAMS 38*aecfc01dSrui zang - Sun Microsystems - Beijing China * only allows one thread to enter this module through STREAMS entry 39*aecfc01dSrui zang - Sun Microsystems - Beijing China * points each time -- open() close() put() srv() qtimeout(). 40*aecfc01dSrui zang - Sun Microsystems - Beijing China * So for the most time we do not need locking in this module, but with 41*aecfc01dSrui zang - Sun Microsystems - Beijing China * the following exceptions: 42*aecfc01dSrui zang - Sun Microsystems - Beijing China * 43*aecfc01dSrui zang - Sun Microsystems - Beijing China * - wc shares three global variables (wc_dip, vc_active_consle, vc_avl_root) 44*aecfc01dSrui zang - Sun Microsystems - Beijing China * with virtual console devname part (fs/dev/sdev_vtops.c) which get 45*aecfc01dSrui zang - Sun Microsystems - Beijing China * compiled into genunix. 46*aecfc01dSrui zang - Sun Microsystems - Beijing China * 47*aecfc01dSrui zang - Sun Microsystems - Beijing China * - wc_modechg_cb() is a callback function which will triggered when 48*aecfc01dSrui zang - Sun Microsystems - Beijing China * framebuffer display mode is changed. 49*aecfc01dSrui zang - Sun Microsystems - Beijing China * 50*aecfc01dSrui zang - Sun Microsystems - Beijing China * - vt_send_hotkeys() is triggered by timeout() which is not STREAMS MT 51*aecfc01dSrui zang - Sun Microsystems - Beijing China * safe. 52*aecfc01dSrui zang - Sun Microsystems - Beijing China * 53*aecfc01dSrui zang - Sun Microsystems - Beijing China * Based on the fact that virtual console devname part and wc_modechg_cb() 54*aecfc01dSrui zang - Sun Microsystems - Beijing China * only do read access to the above mentioned shared three global variables, 55*aecfc01dSrui zang - Sun Microsystems - Beijing China * It is safe to do locking this way: 56*aecfc01dSrui zang - Sun Microsystems - Beijing China * 1) all read access to the three global variables in THIS WC MODULE do not 57*aecfc01dSrui zang - Sun Microsystems - Beijing China * need locking; 58*aecfc01dSrui zang - Sun Microsystems - Beijing China * 2) all write access to the three global variables in THIS WC MODULE must 59*aecfc01dSrui zang - Sun Microsystems - Beijing China * hold vc_lock; 60*aecfc01dSrui zang - Sun Microsystems - Beijing China * 3) any access to the three global variables in either DEVNAME PART or the 61*aecfc01dSrui zang - Sun Microsystems - Beijing China * CALLBACK must hold vc_lock; 62*aecfc01dSrui zang - Sun Microsystems - Beijing China * 4) other global variables which are only shared in this wc module and only 63*aecfc01dSrui zang - Sun Microsystems - Beijing China * accessible through STREAMS entry points such as "vc_last_console", 64*aecfc01dSrui zang - Sun Microsystems - Beijing China * "vc_inuse_max_minor", "vc_target_console" and "vc_waitactive_list" 65*aecfc01dSrui zang - Sun Microsystems - Beijing China * do not need explict locking. 66*aecfc01dSrui zang - Sun Microsystems - Beijing China * 67*aecfc01dSrui zang - Sun Microsystems - Beijing China * wc_modechg_cb() does read access to vc_state_t::vc_flags, 68*aecfc01dSrui zang - Sun Microsystems - Beijing China * vc_state_t::vc_state_lock is used to protect concurrently accesses to 69*aecfc01dSrui zang - Sun Microsystems - Beijing China * vc_state_t::vc_flags which may happen from both through STREAMS entry 70*aecfc01dSrui zang - Sun Microsystems - Beijing China * points and wc_modechg_cb(). 71*aecfc01dSrui zang - Sun Microsystems - Beijing China * Since wc_modechg_cb() only does read access to vc_state_t::vc_flags, 72*aecfc01dSrui zang - Sun Microsystems - Beijing China * The other parts of wc module (except wc_modechg_cb()) only has to hold 73*aecfc01dSrui zang - Sun Microsystems - Beijing China * vc_state_t::vc_flags when writing to vc_state_t::vc_flags. 74*aecfc01dSrui zang - Sun Microsystems - Beijing China * 75*aecfc01dSrui zang - Sun Microsystems - Beijing China * vt_send_hotkeys() could access vt_pending_vtno at the same time with 76*aecfc01dSrui zang - Sun Microsystems - Beijing China * the rest of wc module, vt_pending_vtno_lock is used to protect 77*aecfc01dSrui zang - Sun Microsystems - Beijing China * vt_pending_vtno. 78*aecfc01dSrui zang - Sun Microsystems - Beijing China * 79*aecfc01dSrui zang - Sun Microsystems - Beijing China * Lock order: vc_lock -> vc_state_t::vc_state_lock. 80*aecfc01dSrui zang - Sun Microsystems - Beijing China * No overlap between vc_lock and vt_pending_vtno_lock. 81*aecfc01dSrui zang - Sun Microsystems - Beijing China */ 82*aecfc01dSrui zang - Sun Microsystems - Beijing China 837c478bd9Sstevel@tonic-gate #include <sys/types.h> 847c478bd9Sstevel@tonic-gate #include <sys/param.h> 857c478bd9Sstevel@tonic-gate #include <sys/signal.h> 867c478bd9Sstevel@tonic-gate #include <sys/cred.h> 877c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 887c478bd9Sstevel@tonic-gate #include <sys/termios.h> 897c478bd9Sstevel@tonic-gate #include <sys/termio.h> 907c478bd9Sstevel@tonic-gate #include <sys/ttold.h> 917c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 927c478bd9Sstevel@tonic-gate #include <sys/stream.h> 937c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 947c478bd9Sstevel@tonic-gate #include <sys/tty.h> 957c478bd9Sstevel@tonic-gate #include <sys/buf.h> 967c478bd9Sstevel@tonic-gate #include <sys/uio.h> 977c478bd9Sstevel@tonic-gate #include <sys/stat.h> 98*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/sysmacros.h> 99*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/errno.h> 100*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/proc.h> 101*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/procset.h> 102*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/fault.h> 103*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/siginfo.h> 104*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/debug.h> 105*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/session.h> 1067c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 1077c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 1087c478bd9Sstevel@tonic-gate #include <sys/kbio.h> 1097c478bd9Sstevel@tonic-gate #include <sys/strredir.h> 1107c478bd9Sstevel@tonic-gate #include <sys/fs/snode.h> 1117c478bd9Sstevel@tonic-gate #include <sys/consdev.h> 1127c478bd9Sstevel@tonic-gate #include <sys/conf.h> 113*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/cmn_err.h> 114*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/console.h> 115*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/promif.h> 116*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/note.h> 117*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/polled_io.h> 118*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/systm.h> 1197c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 1207c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 121*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/sunndi.h> 122*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/esunddi.h> 123*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/sunldi.h> 1247c478bd9Sstevel@tonic-gate #include <sys/debug.h> 1257c478bd9Sstevel@tonic-gate #include <sys/console.h> 1267c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 1277c478bd9Sstevel@tonic-gate #include <sys/policy.h> 128*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/modctl.h> 129fea9cb91Slq150181 #include <sys/tem.h> 130fea9cb91Slq150181 #include <sys/wscons.h> 131*aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/vt_impl.h> 132*aecfc01dSrui zang - Sun Microsystems - Beijing China 133*aecfc01dSrui zang - Sun Microsystems - Beijing China /* streams stuff */ 134*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", copyreq)) 135*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", copyresp)) 136*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", datab)) 137*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", iocblk)) 138*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", msgb)) 139*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", queue)) 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate #define MINLINES 10 1427c478bd9Sstevel@tonic-gate #define MAXLINES 48 1437c478bd9Sstevel@tonic-gate #define LOSCREENLINES 34 1447c478bd9Sstevel@tonic-gate #define HISCREENLINES 48 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate #define MINCOLS 10 1477c478bd9Sstevel@tonic-gate #define MAXCOLS 120 1487c478bd9Sstevel@tonic-gate #define LOSCREENCOLS 80 1497c478bd9Sstevel@tonic-gate #define HISCREENCOLS 120 1507c478bd9Sstevel@tonic-gate 151*aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state { 1527c478bd9Sstevel@tonic-gate dev_t wc_dev; /* major/minor for this device */ 153fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 1547c478bd9Sstevel@tonic-gate int wc_defer_output; /* set if output device is "slow" */ 155fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 1567c478bd9Sstevel@tonic-gate queue_t *wc_kbdqueue; /* "console keyboard" device queue */ 1577c478bd9Sstevel@tonic-gate /* below us */ 1587c478bd9Sstevel@tonic-gate cons_polledio_t wc_polledio; /* polled I/O function pointers */ 1597c478bd9Sstevel@tonic-gate cons_polledio_t *wc_kb_polledio; /* keyboard's polledio */ 1607c478bd9Sstevel@tonic-gate unsigned int wc_kb_getpolledio_id; /* id for kb CONSOPENPOLLEDIO */ 161*aecfc01dSrui zang - Sun Microsystems - Beijing China queue_t *wc_pending_wq; 1627c478bd9Sstevel@tonic-gate mblk_t *wc_pending_link; /* I_PLINK pending for kb polledio */ 1637c478bd9Sstevel@tonic-gate } wscons; 1647c478bd9Sstevel@tonic-gate 165*aecfc01dSrui zang - Sun Microsystems - Beijing China /* 166*aecfc01dSrui zang - Sun Microsystems - Beijing China * This module has a D_MTPERMOD inner perimeter, so we don't need to protect 167*aecfc01dSrui zang - Sun Microsystems - Beijing China * the variables only shared within this module 168*aecfc01dSrui zang - Sun Microsystems - Beijing China */ 169*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", wscons)) 170*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", wscons_state)) 171*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_stat)) 172*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vc_waitactive_msg)) 173*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", tty_common)) 174*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_mode)) 175*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_dispinfo)) 176*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", winsize)) 177*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vc_last_console)) 178*aecfc01dSrui zang - Sun Microsystems - Beijing China 179*aecfc01dSrui zang - Sun Microsystems - Beijing China #ifdef _HAVE_TEM_FIRMWARE 180*aecfc01dSrui zang - Sun Microsystems - Beijing China ssize_t wc_cons_wrtvec(promif_redir_arg_t arg, uchar_t *s, size_t n); 181*aecfc01dSrui zang - Sun Microsystems - Beijing China #endif /* _HAVE_TEM_FIRMWARE */ 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate static int wcopen(queue_t *, dev_t *, int, int, cred_t *); 1847c478bd9Sstevel@tonic-gate static int wcclose(queue_t *, int, cred_t *); 1857c478bd9Sstevel@tonic-gate static int wcuwput(queue_t *, mblk_t *); 1867c478bd9Sstevel@tonic-gate static int wclrput(queue_t *, mblk_t *); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate static struct module_info wcm_info = { 1897c478bd9Sstevel@tonic-gate 0, 1907c478bd9Sstevel@tonic-gate "wc", 1917c478bd9Sstevel@tonic-gate 0, 1927c478bd9Sstevel@tonic-gate INFPSZ, 1937c478bd9Sstevel@tonic-gate 2048, 1947c478bd9Sstevel@tonic-gate 128 1957c478bd9Sstevel@tonic-gate }; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate static struct qinit wcurinit = { 1987c478bd9Sstevel@tonic-gate putq, 1997c478bd9Sstevel@tonic-gate NULL, 2007c478bd9Sstevel@tonic-gate wcopen, 2017c478bd9Sstevel@tonic-gate wcclose, 2027c478bd9Sstevel@tonic-gate NULL, 2037c478bd9Sstevel@tonic-gate &wcm_info, 2047c478bd9Sstevel@tonic-gate NULL 2057c478bd9Sstevel@tonic-gate }; 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate static struct qinit wcuwinit = { 2087c478bd9Sstevel@tonic-gate wcuwput, 2097c478bd9Sstevel@tonic-gate NULL, 2107c478bd9Sstevel@tonic-gate wcopen, 2117c478bd9Sstevel@tonic-gate wcclose, 2127c478bd9Sstevel@tonic-gate NULL, 2137c478bd9Sstevel@tonic-gate &wcm_info, 2147c478bd9Sstevel@tonic-gate NULL 2157c478bd9Sstevel@tonic-gate }; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate static struct qinit wclrinit = { 2187c478bd9Sstevel@tonic-gate wclrput, 2197c478bd9Sstevel@tonic-gate NULL, 2207c478bd9Sstevel@tonic-gate NULL, 2217c478bd9Sstevel@tonic-gate NULL, 2227c478bd9Sstevel@tonic-gate NULL, 2237c478bd9Sstevel@tonic-gate &wcm_info, 2247c478bd9Sstevel@tonic-gate NULL 2257c478bd9Sstevel@tonic-gate }; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate /* 2287c478bd9Sstevel@tonic-gate * We always putnext directly to the underlying queue. 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate static struct qinit wclwinit = { 2317c478bd9Sstevel@tonic-gate NULL, 2327c478bd9Sstevel@tonic-gate NULL, 2337c478bd9Sstevel@tonic-gate NULL, 2347c478bd9Sstevel@tonic-gate NULL, 2357c478bd9Sstevel@tonic-gate NULL, 2367c478bd9Sstevel@tonic-gate &wcm_info, 2377c478bd9Sstevel@tonic-gate NULL 2387c478bd9Sstevel@tonic-gate }; 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate static struct streamtab wcinfo = { 2417c478bd9Sstevel@tonic-gate &wcurinit, 2427c478bd9Sstevel@tonic-gate &wcuwinit, 2437c478bd9Sstevel@tonic-gate &wclrinit, 2447c478bd9Sstevel@tonic-gate &wclwinit, 2457c478bd9Sstevel@tonic-gate }; 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate static int wc_info(dev_info_t *, ddi_info_cmd_t, void *, void **result); 2487c478bd9Sstevel@tonic-gate static int wc_attach(dev_info_t *, ddi_attach_cmd_t); 2497c478bd9Sstevel@tonic-gate 2507c478bd9Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(wc_ops, nulldev, nulldev, wc_attach, nodev, nodev, 25119397407SSherry Moore wc_info, D_MTPERMOD | D_MP, &wcinfo, ddi_quiesce_not_supported); 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate static void wcreioctl(void *); 2547c478bd9Sstevel@tonic-gate static void wcioctl(queue_t *, mblk_t *); 255fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 2567c478bd9Sstevel@tonic-gate static void wcopoll(void *); 2577c478bd9Sstevel@tonic-gate static void wconsout(void *); 258fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 2597c478bd9Sstevel@tonic-gate static void wcrstrt(void *); 260*aecfc01dSrui zang - Sun Microsystems - Beijing China static void wcstart(void *); 261*aecfc01dSrui zang - Sun Microsystems - Beijing China static void wc_open_kb_polledio(struct wscons_state *wc, queue_t *q, 262*aecfc01dSrui zang - Sun Microsystems - Beijing China mblk_t *mp); 263*aecfc01dSrui zang - Sun Microsystems - Beijing China static void wc_close_kb_polledio(struct wscons_state *wc, queue_t *q, 264*aecfc01dSrui zang - Sun Microsystems - Beijing China mblk_t *mp); 265*aecfc01dSrui zang - Sun Microsystems - Beijing China static void wc_polled_putchar(cons_polledio_arg_t arg, 266*aecfc01dSrui zang - Sun Microsystems - Beijing China unsigned char c); 267281f0747Slt200341 static boolean_t wc_polled_ischar(cons_polledio_arg_t arg); 268281f0747Slt200341 static int wc_polled_getchar(cons_polledio_arg_t arg); 269281f0747Slt200341 static void wc_polled_enter(cons_polledio_arg_t arg); 270281f0747Slt200341 static void wc_polled_exit(cons_polledio_arg_t arg); 271*aecfc01dSrui zang - Sun Microsystems - Beijing China void wc_get_size(vc_state_t *pvc); 272fea9cb91Slq150181 static void wc_modechg_cb(tem_modechg_cb_arg_t arg); 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate static struct dev_ops wc_ops; 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate /* 2777c478bd9Sstevel@tonic-gate * Debug printing 2787c478bd9Sstevel@tonic-gate */ 2797c478bd9Sstevel@tonic-gate #ifndef DPRINTF 2807c478bd9Sstevel@tonic-gate #ifdef DEBUG 2817c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/ 2827c478bd9Sstevel@tonic-gate static void wc_dprintf(const char *fmt, ...) __KPRINTFLIKE(1); 2837c478bd9Sstevel@tonic-gate #define DPRINTF(l, m, args) \ 2847c478bd9Sstevel@tonic-gate (((l) >= wc_errlevel) && ((m) & wc_errmask) ? \ 2857c478bd9Sstevel@tonic-gate wc_dprintf args : \ 2867c478bd9Sstevel@tonic-gate (void) 0) 2877c478bd9Sstevel@tonic-gate /* 2887c478bd9Sstevel@tonic-gate * Severity levels for printing 2897c478bd9Sstevel@tonic-gate */ 2907c478bd9Sstevel@tonic-gate #define PRINT_L0 0 /* print every message */ 2917c478bd9Sstevel@tonic-gate #define PRINT_L1 1 /* debug */ 2927c478bd9Sstevel@tonic-gate #define PRINT_L2 2 /* quiet */ 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate /* 2957c478bd9Sstevel@tonic-gate * Masks 2967c478bd9Sstevel@tonic-gate */ 2977c478bd9Sstevel@tonic-gate #define PRINT_MASK_ALL 0xFFFFFFFFU 2987c478bd9Sstevel@tonic-gate uint_t wc_errmask = PRINT_MASK_ALL; 2997c478bd9Sstevel@tonic-gate uint_t wc_errlevel = PRINT_L2; 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate #else 3027c478bd9Sstevel@tonic-gate #define DPRINTF(l, m, args) /* NOTHING */ 3037c478bd9Sstevel@tonic-gate #endif 3047c478bd9Sstevel@tonic-gate #endif 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate /* 3077c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 3087c478bd9Sstevel@tonic-gate */ 3097c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 3107c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a pseudo driver */ 31119397407SSherry Moore "Workstation multiplexer Driver 'wc'", 3127c478bd9Sstevel@tonic-gate &wc_ops, /* driver ops */ 3137c478bd9Sstevel@tonic-gate }; 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 3167c478bd9Sstevel@tonic-gate MODREV_1, 3177c478bd9Sstevel@tonic-gate &modldrv, 3187c478bd9Sstevel@tonic-gate NULL 3197c478bd9Sstevel@tonic-gate }; 3207c478bd9Sstevel@tonic-gate 3217c478bd9Sstevel@tonic-gate int 3227c478bd9Sstevel@tonic-gate _init(void) 3237c478bd9Sstevel@tonic-gate { 324*aecfc01dSrui zang - Sun Microsystems - Beijing China int rc; 325*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((rc = mod_install(&modlinkage)) == 0) 326*aecfc01dSrui zang - Sun Microsystems - Beijing China vt_init(); 327*aecfc01dSrui zang - Sun Microsystems - Beijing China return (rc); 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate int 3317c478bd9Sstevel@tonic-gate _fini(void) 3327c478bd9Sstevel@tonic-gate { 3337c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 3347c478bd9Sstevel@tonic-gate } 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate int 3377c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 3387c478bd9Sstevel@tonic-gate { 3397c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3437c478bd9Sstevel@tonic-gate static int 3447c478bd9Sstevel@tonic-gate wc_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 3457c478bd9Sstevel@tonic-gate { 346*aecfc01dSrui zang - Sun Microsystems - Beijing China /* create minor node for workstation hard console */ 3477c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(devi, "wscons", S_IFCHR, 3487c478bd9Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 3497c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 350*aecfc01dSrui zang - Sun Microsystems - Beijing China return (DDI_FAILURE); 3517c478bd9Sstevel@tonic-gate } 352*aecfc01dSrui zang - Sun Microsystems - Beijing China 353*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 354*aecfc01dSrui zang - Sun Microsystems - Beijing China 3557c478bd9Sstevel@tonic-gate wc_dip = devi; 356fea9cb91Slq150181 357fea9cb91Slq150181 bzero(&(wscons.wc_polledio), sizeof (wscons.wc_polledio)); 358fea9cb91Slq150181 359*aecfc01dSrui zang - Sun Microsystems - Beijing China vt_resize(VC_DEFAULT_COUNT); 360*aecfc01dSrui zang - Sun Microsystems - Beijing China 361*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 362*aecfc01dSrui zang - Sun Microsystems - Beijing China 3637c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 3647c478bd9Sstevel@tonic-gate } 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate /* ARGSUSED */ 3677c478bd9Sstevel@tonic-gate static int 3687c478bd9Sstevel@tonic-gate wc_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 3697c478bd9Sstevel@tonic-gate void **result) 3707c478bd9Sstevel@tonic-gate { 3717c478bd9Sstevel@tonic-gate int error; 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate switch (infocmd) { 3747c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 3757c478bd9Sstevel@tonic-gate if (wc_dip == NULL) { 3767c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 3777c478bd9Sstevel@tonic-gate } else { 3787c478bd9Sstevel@tonic-gate *result = (void *) wc_dip; 3797c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate break; 3827c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 3837c478bd9Sstevel@tonic-gate *result = (void *)0; 3847c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 3857c478bd9Sstevel@tonic-gate break; 3867c478bd9Sstevel@tonic-gate default: 3877c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate return (error); 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate 392fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 3937c478bd9Sstevel@tonic-gate /* 3947c478bd9Sstevel@tonic-gate * Output buffer. Protected by the per-module inner perimeter. 3957c478bd9Sstevel@tonic-gate */ 3967c478bd9Sstevel@tonic-gate #define MAXHIWAT 2000 3977c478bd9Sstevel@tonic-gate static char obuf[MAXHIWAT]; 398fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 3997c478bd9Sstevel@tonic-gate 400*aecfc01dSrui zang - Sun Microsystems - Beijing China static void 401*aecfc01dSrui zang - Sun Microsystems - Beijing China wc_init_polledio(void) 4027c478bd9Sstevel@tonic-gate { 403fea9cb91Slq150181 static boolean_t polledio_inited = B_FALSE; 404*aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", 405*aecfc01dSrui zang - Sun Microsystems - Beijing China polledio_inited)) 4067c478bd9Sstevel@tonic-gate 407*aecfc01dSrui zang - Sun Microsystems - Beijing China if (polledio_inited) 408*aecfc01dSrui zang - Sun Microsystems - Beijing China return; 4097c478bd9Sstevel@tonic-gate 410fea9cb91Slq150181 polledio_inited = B_TRUE; 411fea9cb91Slq150181 412fea9cb91Slq150181 /* 413fea9cb91Slq150181 * Initialize the parts of the polled I/O struct that 414fea9cb91Slq150181 * are common to both input and output modes, but which 415fea9cb91Slq150181 * don't flag to the upper layers, which if any of the 416fea9cb91Slq150181 * two modes are available. We don't know at this point 417fea9cb91Slq150181 * if system is configured CONS_KFB, but we will when 418fea9cb91Slq150181 * consconfig_dacf asks us with CONSOPENPOLLED I/O. 419fea9cb91Slq150181 */ 420*aecfc01dSrui zang - Sun Microsystems - Beijing China bzero(&(wscons.wc_polledio), sizeof (wscons.wc_polledio)); 421fea9cb91Slq150181 wscons.wc_polledio.cons_polledio_version = 422fea9cb91Slq150181 CONSPOLLEDIO_V0; 4237c478bd9Sstevel@tonic-gate wscons.wc_polledio.cons_polledio_argument = 424281f0747Slt200341 (cons_polledio_arg_t)&wscons; 425fea9cb91Slq150181 wscons.wc_polledio.cons_polledio_enter = 426fea9cb91Slq150181 wc_polled_enter; 427fea9cb91Slq150181 wscons.wc_polledio.cons_polledio_exit = 428fea9cb91Slq150181 wc_polled_exit; 4297c478bd9Sstevel@tonic-gate 430fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 4317c478bd9Sstevel@tonic-gate /* 4327c478bd9Sstevel@tonic-gate * If we're talking directly to a framebuffer, we assume 433fea9cb91Slq150181 * that it's a "slow" device, so that rendering should 434fea9cb91Slq150181 * be deferred to a timeout or softcall so that we write 4357c478bd9Sstevel@tonic-gate * a bunch of characters at once. 4367c478bd9Sstevel@tonic-gate */ 4377c478bd9Sstevel@tonic-gate wscons.wc_defer_output = prom_stdout_is_framebuffer(); 438fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 439fea9cb91Slq150181 } 4407c478bd9Sstevel@tonic-gate 441*aecfc01dSrui zang - Sun Microsystems - Beijing China /*ARGSUSED*/ 442*aecfc01dSrui zang - Sun Microsystems - Beijing China static int 443*aecfc01dSrui zang - Sun Microsystems - Beijing China wcopen(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *crp) 444*aecfc01dSrui zang - Sun Microsystems - Beijing China { 445*aecfc01dSrui zang - Sun Microsystems - Beijing China int minor; 446*aecfc01dSrui zang - Sun Microsystems - Beijing China 447*aecfc01dSrui zang - Sun Microsystems - Beijing China wc_init_polledio(); 448*aecfc01dSrui zang - Sun Microsystems - Beijing China minor = (int)getminor(*devp); 449*aecfc01dSrui zang - Sun Microsystems - Beijing China return (vt_open(minor, q, crp)); 4507c478bd9Sstevel@tonic-gate } 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4537c478bd9Sstevel@tonic-gate static int 4547c478bd9Sstevel@tonic-gate wcclose(queue_t *q, int flag, cred_t *crp) 4557c478bd9Sstevel@tonic-gate { 456*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)q->q_ptr; 457*aecfc01dSrui zang - Sun Microsystems - Beijing China 4587c478bd9Sstevel@tonic-gate qprocsoff(q); 459*aecfc01dSrui zang - Sun Microsystems - Beijing China 460*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 461*aecfc01dSrui zang - Sun Microsystems - Beijing China 462*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_minor == 0 || pvc->vc_minor == vc_active_console) { 463*aecfc01dSrui zang - Sun Microsystems - Beijing China 464*aecfc01dSrui zang - Sun Microsystems - Beijing China /* 465*aecfc01dSrui zang - Sun Microsystems - Beijing China * If we lose the system console, 466*aecfc01dSrui zang - Sun Microsystems - Beijing China * no any other active consoles. 467*aecfc01dSrui zang - Sun Microsystems - Beijing China */ 468*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_minor == 0 && pvc->vc_minor == vc_active_console) { 469*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_active_console = VT_MINOR_INVALID; 470*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_last_console = VT_MINOR_INVALID; 4717c478bd9Sstevel@tonic-gate } 472*aecfc01dSrui zang - Sun Microsystems - Beijing China 473*aecfc01dSrui zang - Sun Microsystems - Beijing China /* 474*aecfc01dSrui zang - Sun Microsystems - Beijing China * just clean for our primary console 475*aecfc01dSrui zang - Sun Microsystems - Beijing China * and active console 476*aecfc01dSrui zang - Sun Microsystems - Beijing China */ 477*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 478*aecfc01dSrui zang - Sun Microsystems - Beijing China vt_clean(q, pvc); 479*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 480*aecfc01dSrui zang - Sun Microsystems - Beijing China 481*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 482*aecfc01dSrui zang - Sun Microsystems - Beijing China 483*aecfc01dSrui zang - Sun Microsystems - Beijing China return (0); 4847c478bd9Sstevel@tonic-gate } 485*aecfc01dSrui zang - Sun Microsystems - Beijing China vt_close(q, pvc, crp); 486*aecfc01dSrui zang - Sun Microsystems - Beijing China 487*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 488*aecfc01dSrui zang - Sun Microsystems - Beijing China 4897c478bd9Sstevel@tonic-gate return (0); 4907c478bd9Sstevel@tonic-gate } 4917c478bd9Sstevel@tonic-gate 4927c478bd9Sstevel@tonic-gate /* 4937c478bd9Sstevel@tonic-gate * Put procedure for upper write queue. 4947c478bd9Sstevel@tonic-gate * Respond to M_STOP, M_START, M_IOCTL, and M_FLUSH messages here; 4957c478bd9Sstevel@tonic-gate * queue up M_BREAK, M_DELAY, and M_DATA messages for processing by 4967c478bd9Sstevel@tonic-gate * the start routine, and then call the start routine; discard 4977c478bd9Sstevel@tonic-gate * everything else. 4987c478bd9Sstevel@tonic-gate */ 4997c478bd9Sstevel@tonic-gate static int 5007c478bd9Sstevel@tonic-gate wcuwput(queue_t *q, mblk_t *mp) 5017c478bd9Sstevel@tonic-gate { 502*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)q->q_ptr; 503*aecfc01dSrui zang - Sun Microsystems - Beijing China 5047c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) { 5057c478bd9Sstevel@tonic-gate 5067c478bd9Sstevel@tonic-gate case M_STOP: 507*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 508*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags |= WCS_STOPPED; 509*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 510*aecfc01dSrui zang - Sun Microsystems - Beijing China 5117c478bd9Sstevel@tonic-gate freemsg(mp); 5127c478bd9Sstevel@tonic-gate break; 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate case M_START: 515*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 516*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags &= ~WCS_STOPPED; 517*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 518*aecfc01dSrui zang - Sun Microsystems - Beijing China 519*aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 5207c478bd9Sstevel@tonic-gate freemsg(mp); 5217c478bd9Sstevel@tonic-gate break; 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate case M_IOCTL: { 5247c478bd9Sstevel@tonic-gate struct iocblk *iocp; 5257c478bd9Sstevel@tonic-gate struct linkblk *linkp; 5267c478bd9Sstevel@tonic-gate 527*aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 5287c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) { 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate case I_LINK: /* stupid, but permitted */ 5317c478bd9Sstevel@tonic-gate case I_PLINK: 5327c478bd9Sstevel@tonic-gate if (wscons.wc_kbdqueue != NULL) { 5337c478bd9Sstevel@tonic-gate /* somebody already linked */ 5347c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL); 5357c478bd9Sstevel@tonic-gate return (0); 5367c478bd9Sstevel@tonic-gate } 537*aecfc01dSrui zang - Sun Microsystems - Beijing China linkp = (struct linkblk *)(void *)mp->b_cont->b_rptr; 5387c478bd9Sstevel@tonic-gate wscons.wc_kbdqueue = WR(linkp->l_qbot); 5397c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 5407c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; 5417c478bd9Sstevel@tonic-gate wc_open_kb_polledio(&wscons, q, mp); 5427c478bd9Sstevel@tonic-gate break; 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate case I_UNLINK: /* stupid, but permitted */ 5457c478bd9Sstevel@tonic-gate case I_PUNLINK: 546*aecfc01dSrui zang - Sun Microsystems - Beijing China linkp = (struct linkblk *)(void *)mp->b_cont->b_rptr; 5477c478bd9Sstevel@tonic-gate if (wscons.wc_kbdqueue != WR(linkp->l_qbot)) { 5487c478bd9Sstevel@tonic-gate /* not us */ 5497c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL); 5507c478bd9Sstevel@tonic-gate return (0); 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 5547c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; 5557c478bd9Sstevel@tonic-gate wc_close_kb_polledio(&wscons, q, mp); 5567c478bd9Sstevel@tonic-gate break; 5577c478bd9Sstevel@tonic-gate 5587c478bd9Sstevel@tonic-gate case TCSETSW: 5597c478bd9Sstevel@tonic-gate case TCSETSF: 5607c478bd9Sstevel@tonic-gate case TCSETAW: 5617c478bd9Sstevel@tonic-gate case TCSETAF: 5627c478bd9Sstevel@tonic-gate case TCSBRK: 5637c478bd9Sstevel@tonic-gate /* 5647c478bd9Sstevel@tonic-gate * The changes do not take effect until all 5657c478bd9Sstevel@tonic-gate * output queued before them is drained. 5667c478bd9Sstevel@tonic-gate * Put this message on the queue, so that 5677c478bd9Sstevel@tonic-gate * "wcstart" will see it when it's done 5687c478bd9Sstevel@tonic-gate * with the output before it. Poke the 5697c478bd9Sstevel@tonic-gate * start routine, just in case. 5707c478bd9Sstevel@tonic-gate */ 5717c478bd9Sstevel@tonic-gate (void) putq(q, mp); 572*aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 5737c478bd9Sstevel@tonic-gate break; 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate case CONSSETABORTENABLE: 5767c478bd9Sstevel@tonic-gate case CONSGETABORTENABLE: 5777c478bd9Sstevel@tonic-gate case KIOCSDIRECT: 5787c478bd9Sstevel@tonic-gate if (wscons.wc_kbdqueue != NULL) { 579*aecfc01dSrui zang - Sun Microsystems - Beijing China wscons.wc_pending_wq = q; 5807c478bd9Sstevel@tonic-gate (void) putnext(wscons.wc_kbdqueue, mp); 5817c478bd9Sstevel@tonic-gate break; 5827c478bd9Sstevel@tonic-gate } 5837c478bd9Sstevel@tonic-gate /* fall through */ 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate default: 5867c478bd9Sstevel@tonic-gate /* 5877c478bd9Sstevel@tonic-gate * Do it now. 5887c478bd9Sstevel@tonic-gate */ 5897c478bd9Sstevel@tonic-gate wcioctl(q, mp); 5907c478bd9Sstevel@tonic-gate break; 5917c478bd9Sstevel@tonic-gate } 5927c478bd9Sstevel@tonic-gate break; 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate case M_FLUSH: 5967c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) { 5977c478bd9Sstevel@tonic-gate /* 5987c478bd9Sstevel@tonic-gate * Flush our write queue. 5997c478bd9Sstevel@tonic-gate */ 6007c478bd9Sstevel@tonic-gate flushq(q, FLUSHDATA); /* XXX doesn't flush M_DELAY */ 6017c478bd9Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHW; /* it has been flushed */ 6027c478bd9Sstevel@tonic-gate } 6037c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) { 6047c478bd9Sstevel@tonic-gate flushq(RD(q), FLUSHDATA); 6057c478bd9Sstevel@tonic-gate qreply(q, mp); /* give the read queues a crack at it */ 6067c478bd9Sstevel@tonic-gate } else 6077c478bd9Sstevel@tonic-gate freemsg(mp); 6087c478bd9Sstevel@tonic-gate break; 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate case M_BREAK: 6117c478bd9Sstevel@tonic-gate /* 6127c478bd9Sstevel@tonic-gate * Ignore these, as they make no sense. 6137c478bd9Sstevel@tonic-gate */ 6147c478bd9Sstevel@tonic-gate freemsg(mp); 6157c478bd9Sstevel@tonic-gate break; 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate case M_DELAY: 6187c478bd9Sstevel@tonic-gate case M_DATA: 6197c478bd9Sstevel@tonic-gate /* 6207c478bd9Sstevel@tonic-gate * Queue the message up to be transmitted, 6217c478bd9Sstevel@tonic-gate * and poke the start routine. 6227c478bd9Sstevel@tonic-gate */ 6237c478bd9Sstevel@tonic-gate (void) putq(q, mp); 624*aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 625*aecfc01dSrui zang - Sun Microsystems - Beijing China break; 626*aecfc01dSrui zang - Sun Microsystems - Beijing China 627*aecfc01dSrui zang - Sun Microsystems - Beijing China case M_IOCDATA: 628*aecfc01dSrui zang - Sun Microsystems - Beijing China vt_miocdata(q, mp); 6297c478bd9Sstevel@tonic-gate break; 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate default: 6327c478bd9Sstevel@tonic-gate /* 6337c478bd9Sstevel@tonic-gate * "No, I don't want a subscription to Chain Store Age, 6347c478bd9Sstevel@tonic-gate * thank you anyway." 6357c478bd9Sstevel@tonic-gate */ 6367c478bd9Sstevel@tonic-gate freemsg(mp); 6377c478bd9Sstevel@tonic-gate break; 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate return (0); 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate /* 6447c478bd9Sstevel@tonic-gate * Retry an "ioctl", now that "qbufcall" claims we may be able to allocate 6457c478bd9Sstevel@tonic-gate * the buffer we need. 6467c478bd9Sstevel@tonic-gate */ 6477c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6487c478bd9Sstevel@tonic-gate static void 6497c478bd9Sstevel@tonic-gate wcreioctl(void *arg) 6507c478bd9Sstevel@tonic-gate { 651*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 6527c478bd9Sstevel@tonic-gate queue_t *q; 6537c478bd9Sstevel@tonic-gate mblk_t *mp; 6547c478bd9Sstevel@tonic-gate 655*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_bufcallid = 0; 656*aecfc01dSrui zang - Sun Microsystems - Beijing China q = pvc->vc_ttycommon.t_writeq; 657*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((mp = pvc->vc_ttycommon.t_iocpending) != NULL) { 6587c478bd9Sstevel@tonic-gate /* not pending any more */ 659*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_ttycommon.t_iocpending = NULL; 6607c478bd9Sstevel@tonic-gate wcioctl(q, mp); 6617c478bd9Sstevel@tonic-gate } 6627c478bd9Sstevel@tonic-gate } 6637c478bd9Sstevel@tonic-gate 664fea9cb91Slq150181 static int 665fea9cb91Slq150181 wc_getterm(mblk_t *mp) 666fea9cb91Slq150181 { 667fea9cb91Slq150181 char *term; 668fea9cb91Slq150181 intptr_t arg; 66922eb7cb5Sgd78059 int flag = ((struct iocblk *)(void *)mp->b_rptr)->ioc_flag; 670fea9cb91Slq150181 671fea9cb91Slq150181 STRUCT_DECL(cons_getterm, wcterm); 672fea9cb91Slq150181 STRUCT_INIT(wcterm, flag); 673fea9cb91Slq150181 67422eb7cb5Sgd78059 arg = *((intptr_t *)(void *)mp->b_cont->b_rptr); 675fea9cb91Slq150181 676fea9cb91Slq150181 if (ddi_copyin((void *)arg, STRUCT_BUF(wcterm), 677fea9cb91Slq150181 STRUCT_SIZE(wcterm), flag) != 0) { 678fea9cb91Slq150181 return (EFAULT); 679fea9cb91Slq150181 } 680fea9cb91Slq150181 681fea9cb91Slq150181 if (consmode == CONS_FW) { 682fea9cb91Slq150181 /* PROM terminal emulator */ 683fea9cb91Slq150181 term = "sun"; 684fea9cb91Slq150181 } else { 685fea9cb91Slq150181 /* Kernel terminal emulator */ 686fea9cb91Slq150181 ASSERT(consmode == CONS_KFB); 687fea9cb91Slq150181 term = "sun-color"; 688fea9cb91Slq150181 } 689fea9cb91Slq150181 690fea9cb91Slq150181 if (STRUCT_FGET(wcterm, cn_term_len) < 691fea9cb91Slq150181 strlen(term) + 1) { 692fea9cb91Slq150181 return (EOVERFLOW); 693fea9cb91Slq150181 } 694fea9cb91Slq150181 695fea9cb91Slq150181 if (ddi_copyout(term, 696fea9cb91Slq150181 STRUCT_FGETP(wcterm, cn_term_type), 697fea9cb91Slq150181 strlen(term) + 1, flag) != 0) { 698fea9cb91Slq150181 return (EFAULT); 699fea9cb91Slq150181 } 700fea9cb91Slq150181 701fea9cb91Slq150181 return (0); 702fea9cb91Slq150181 } 703fea9cb91Slq150181 7047c478bd9Sstevel@tonic-gate /* 7057c478bd9Sstevel@tonic-gate * Process an "ioctl" message sent down to us. 7067c478bd9Sstevel@tonic-gate */ 7077c478bd9Sstevel@tonic-gate static void 7087c478bd9Sstevel@tonic-gate wcioctl(queue_t *q, mblk_t *mp) 7097c478bd9Sstevel@tonic-gate { 710*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)q->q_ptr; 7117c478bd9Sstevel@tonic-gate struct iocblk *iocp; 7127c478bd9Sstevel@tonic-gate size_t datasize; 7137c478bd9Sstevel@tonic-gate int error; 714fea9cb91Slq150181 long len; 7157c478bd9Sstevel@tonic-gate 716*aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 717*aecfc01dSrui zang - Sun Microsystems - Beijing China 718*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((iocp->ioc_cmd & VTIOC) == VTIOC || 719*aecfc01dSrui zang - Sun Microsystems - Beijing China (iocp->ioc_cmd & KDIOC) == KDIOC) { 720*aecfc01dSrui zang - Sun Microsystems - Beijing China vt_ioctl(q, mp); 721*aecfc01dSrui zang - Sun Microsystems - Beijing China return; 722*aecfc01dSrui zang - Sun Microsystems - Beijing China } 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) { 7257c478bd9Sstevel@tonic-gate case TIOCSWINSZ: 7267c478bd9Sstevel@tonic-gate /* 7277c478bd9Sstevel@tonic-gate * Ignore all attempts to set the screen size; the 7287c478bd9Sstevel@tonic-gate * value in the EEPROM is guaranteed (modulo PROM bugs) 7297c478bd9Sstevel@tonic-gate * to be the value used by the PROM monitor code, so it 7307c478bd9Sstevel@tonic-gate * is by definition correct. Many programs (e.g., 7317c478bd9Sstevel@tonic-gate * "login" and "tset") will attempt to reset the size 7327c478bd9Sstevel@tonic-gate * to (0, 0) or (34, 80), neither of which is 7337c478bd9Sstevel@tonic-gate * necessarily correct. 7347c478bd9Sstevel@tonic-gate * We just ACK the message, so as not to disturb 7357c478bd9Sstevel@tonic-gate * programs that set the sizes. 7367c478bd9Sstevel@tonic-gate */ 7377c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */ 7387c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7397c478bd9Sstevel@tonic-gate qreply(q, mp); 7407c478bd9Sstevel@tonic-gate return; 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate case CONSOPENPOLLEDIO: 7437c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 7447c478bd9Sstevel@tonic-gate ("wcioctl: CONSOPENPOLLEDIO\n")); 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct cons_polledio *)); 7477c478bd9Sstevel@tonic-gate if (error != 0) { 7487c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, error); 7497c478bd9Sstevel@tonic-gate return; 7507c478bd9Sstevel@tonic-gate } 7517c478bd9Sstevel@tonic-gate 7527c478bd9Sstevel@tonic-gate /* 7537c478bd9Sstevel@tonic-gate * We are given an appropriate-sized data block, 7547c478bd9Sstevel@tonic-gate * and return a pointer to our structure in it. 7557c478bd9Sstevel@tonic-gate */ 756fea9cb91Slq150181 if (consmode == CONS_KFB) 757fea9cb91Slq150181 wscons.wc_polledio.cons_polledio_putchar = 758fea9cb91Slq150181 wc_polled_putchar; 75922eb7cb5Sgd78059 *(struct cons_polledio **)(void *)mp->b_cont->b_rptr = 7607c478bd9Sstevel@tonic-gate &wscons.wc_polledio; 7617c478bd9Sstevel@tonic-gate 7627c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate qreply(q, mp); 7657c478bd9Sstevel@tonic-gate break; 7667c478bd9Sstevel@tonic-gate 767fea9cb91Slq150181 case CONS_GETTERM: 768fea9cb91Slq150181 if ((error = wc_getterm(mp)) != 0) 769fea9cb91Slq150181 miocnak(q, mp, 0, error); 770fea9cb91Slq150181 else 771fea9cb91Slq150181 miocack(q, mp, 0, 0); 772fea9cb91Slq150181 return; 773fea9cb91Slq150181 7747c478bd9Sstevel@tonic-gate case WC_OPEN_FB: 7757c478bd9Sstevel@tonic-gate /* 7767c478bd9Sstevel@tonic-gate * Start out pessimistic, so that we can just jump to 7777c478bd9Sstevel@tonic-gate * the reply to bail out. 7787c478bd9Sstevel@tonic-gate */ 7797c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 7807c478bd9Sstevel@tonic-gate 7817c478bd9Sstevel@tonic-gate /* 7827c478bd9Sstevel@tonic-gate * First test: really, this should be done only from 7837c478bd9Sstevel@tonic-gate * inside the kernel. Unfortunately, that information 7847c478bd9Sstevel@tonic-gate * doesn't seem to be available in a streams ioctl, 7857c478bd9Sstevel@tonic-gate * so restrict it to root only. (Perhaps we could check 7867c478bd9Sstevel@tonic-gate * for ioc_cr == kcred.) 7877c478bd9Sstevel@tonic-gate */ 7887c478bd9Sstevel@tonic-gate if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0) 7897c478bd9Sstevel@tonic-gate goto open_fail; 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate /* 7927c478bd9Sstevel@tonic-gate * Some miscellaneous checks... 7937c478bd9Sstevel@tonic-gate */ 7947c478bd9Sstevel@tonic-gate iocp->ioc_error = EINVAL; 7957c478bd9Sstevel@tonic-gate 7967c478bd9Sstevel@tonic-gate /* 7977c478bd9Sstevel@tonic-gate * If we don't have exactly one continuation block, fail. 7987c478bd9Sstevel@tonic-gate */ 799*aecfc01dSrui zang - Sun Microsystems - Beijing China if (mp->b_cont == NULL || 800*aecfc01dSrui zang - Sun Microsystems - Beijing China mp->b_cont->b_cont != NULL) 8017c478bd9Sstevel@tonic-gate goto open_fail; 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate /* 8047c478bd9Sstevel@tonic-gate * If there's no null terminator in the string, fail. 8057c478bd9Sstevel@tonic-gate */ 806*aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED E_PTRDIFF_OVERFLOW */ 807*aecfc01dSrui zang - Sun Microsystems - Beijing China len = mp->b_cont->b_wptr - mp->b_cont->b_rptr; 8087c478bd9Sstevel@tonic-gate if (memchr(mp->b_cont->b_rptr, 0, len) == NULL) 8097c478bd9Sstevel@tonic-gate goto open_fail; 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate /* 8127c478bd9Sstevel@tonic-gate * NOTE: should eventually get default 8137c478bd9Sstevel@tonic-gate * dimensions from a property, e.g. screen-#rows. 8147c478bd9Sstevel@tonic-gate */ 815*aecfc01dSrui zang - Sun Microsystems - Beijing China iocp->ioc_error = tem_info_init((char *)mp->b_cont->b_rptr, 816*aecfc01dSrui zang - Sun Microsystems - Beijing China iocp->ioc_cr); 8177c478bd9Sstevel@tonic-gate /* 8187c478bd9Sstevel@tonic-gate * Of course, if the terminal emulator initialization 8197c478bd9Sstevel@tonic-gate * failed, fail. 8207c478bd9Sstevel@tonic-gate */ 8217c478bd9Sstevel@tonic-gate if (iocp->ioc_error != 0) 8227c478bd9Sstevel@tonic-gate goto open_fail; 8237c478bd9Sstevel@tonic-gate 824*aecfc01dSrui zang - Sun Microsystems - Beijing China #ifdef _HAVE_TEM_FIRMWARE 825*aecfc01dSrui zang - Sun Microsystems - Beijing China if (prom_stdout_is_framebuffer()) { 8267c478bd9Sstevel@tonic-gate /* 827*aecfc01dSrui zang - Sun Microsystems - Beijing China * Drivers in the console stream may emit additional 828*aecfc01dSrui zang - Sun Microsystems - Beijing China * messages before we are ready. This causes text 829*aecfc01dSrui zang - Sun Microsystems - Beijing China * overwrite on the screen. So we set the redirection 830*aecfc01dSrui zang - Sun Microsystems - Beijing China * here. It is safe because the ioctl in consconfig_dacf 831*aecfc01dSrui zang - Sun Microsystems - Beijing China * will succeed and consmode will be set to CONS_KFB. 8327c478bd9Sstevel@tonic-gate */ 833*aecfc01dSrui zang - Sun Microsystems - Beijing China prom_set_stdout_redirect(wc_cons_wrtvec, 834*aecfc01dSrui zang - Sun Microsystems - Beijing China (promif_redir_arg_t)NULL); 835*aecfc01dSrui zang - Sun Microsystems - Beijing China 836*aecfc01dSrui zang - Sun Microsystems - Beijing China } 837*aecfc01dSrui zang - Sun Microsystems - Beijing China #endif /* _HAVE_TEM_FIRMWARE */ 838*aecfc01dSrui zang - Sun Microsystems - Beijing China 839*aecfc01dSrui zang - Sun Microsystems - Beijing China tem_register_modechg_cb(wc_modechg_cb, 840*aecfc01dSrui zang - Sun Microsystems - Beijing China (tem_modechg_cb_arg_t)&wscons); 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate /* 8437c478bd9Sstevel@tonic-gate * ... and succeed. 8447c478bd9Sstevel@tonic-gate */ 8457c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 8467c478bd9Sstevel@tonic-gate 8477c478bd9Sstevel@tonic-gate open_fail: 8487c478bd9Sstevel@tonic-gate qreply(q, mp); 8497c478bd9Sstevel@tonic-gate break; 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate case WC_CLOSE_FB: 8527c478bd9Sstevel@tonic-gate /* 8537c478bd9Sstevel@tonic-gate * There's nothing that can call this, so it's not 8547c478bd9Sstevel@tonic-gate * really implemented. 8557c478bd9Sstevel@tonic-gate */ 8567c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 8577c478bd9Sstevel@tonic-gate /* 8587c478bd9Sstevel@tonic-gate * However, if it were implemented, it would clearly 8597c478bd9Sstevel@tonic-gate * be root-only. 8607c478bd9Sstevel@tonic-gate */ 8617c478bd9Sstevel@tonic-gate if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0) 8627c478bd9Sstevel@tonic-gate goto close_fail; 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate iocp->ioc_error = EINVAL; 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate close_fail: 8677c478bd9Sstevel@tonic-gate qreply(q, mp); 8687c478bd9Sstevel@tonic-gate break; 8697c478bd9Sstevel@tonic-gate 8707c478bd9Sstevel@tonic-gate default: 8717c478bd9Sstevel@tonic-gate 8727c478bd9Sstevel@tonic-gate /* 8737c478bd9Sstevel@tonic-gate * The only way in which "ttycommon_ioctl" can fail is 8747c478bd9Sstevel@tonic-gate * if the "ioctl" requires a response containing data 8757c478bd9Sstevel@tonic-gate * to be returned to the user, and no mblk could be 8767c478bd9Sstevel@tonic-gate * allocated for the data. No such "ioctl" alters our 8777c478bd9Sstevel@tonic-gate * state. Thus, we always go ahead and do any 8787c478bd9Sstevel@tonic-gate * state-changes the "ioctl" calls for. If we couldn't 8797c478bd9Sstevel@tonic-gate * allocate the data, "ttycommon_ioctl" has stashed the 8807c478bd9Sstevel@tonic-gate * "ioctl" away safely, so we just call "qbufcall" to 8817c478bd9Sstevel@tonic-gate * request that we be called back when we stand a 8827c478bd9Sstevel@tonic-gate * better chance of allocating the data. 8837c478bd9Sstevel@tonic-gate */ 884*aecfc01dSrui zang - Sun Microsystems - Beijing China datasize = ttycommon_ioctl(&pvc->vc_ttycommon, q, mp, &error); 8857c478bd9Sstevel@tonic-gate if (datasize != 0) { 886*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_bufcallid != 0) 887*aecfc01dSrui zang - Sun Microsystems - Beijing China qunbufcall(q, pvc->vc_bufcallid); 888*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_bufcallid = qbufcall(q, datasize, BPRI_HI, 889*aecfc01dSrui zang - Sun Microsystems - Beijing China wcreioctl, pvc); 8907c478bd9Sstevel@tonic-gate return; 8917c478bd9Sstevel@tonic-gate } 8927c478bd9Sstevel@tonic-gate 8937c478bd9Sstevel@tonic-gate if (error < 0) { 8947c478bd9Sstevel@tonic-gate if (iocp->ioc_cmd == TCSBRK) 8957c478bd9Sstevel@tonic-gate error = 0; 8967c478bd9Sstevel@tonic-gate else 8977c478bd9Sstevel@tonic-gate error = EINVAL; 8987c478bd9Sstevel@tonic-gate } 8997c478bd9Sstevel@tonic-gate if (error != 0) { 9007c478bd9Sstevel@tonic-gate iocp->ioc_error = error; 9017c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 9027c478bd9Sstevel@tonic-gate } 9037c478bd9Sstevel@tonic-gate qreply(q, mp); 9047c478bd9Sstevel@tonic-gate break; 9057c478bd9Sstevel@tonic-gate } 9067c478bd9Sstevel@tonic-gate } 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate /* 9097c478bd9Sstevel@tonic-gate * This function gets the polled I/O structures from the lower 9107c478bd9Sstevel@tonic-gate * keyboard driver. If any initialization or resource allocation 9117c478bd9Sstevel@tonic-gate * needs to be done by the lower driver, it will be done when 9127c478bd9Sstevel@tonic-gate * the lower driver services this message. 9137c478bd9Sstevel@tonic-gate */ 9147c478bd9Sstevel@tonic-gate static void 915*aecfc01dSrui zang - Sun Microsystems - Beijing China wc_open_kb_polledio(struct wscons_state *wscons, queue_t *q, mblk_t *mp) 9167c478bd9Sstevel@tonic-gate { 9177c478bd9Sstevel@tonic-gate mblk_t *mp2; 9187c478bd9Sstevel@tonic-gate struct iocblk *iocp; 9197c478bd9Sstevel@tonic-gate 9207c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 9217c478bd9Sstevel@tonic-gate ("wc_open_kb_polledio: sending CONSOPENPOLLEDIO\n")); 9227c478bd9Sstevel@tonic-gate 9237c478bd9Sstevel@tonic-gate mp2 = mkiocb(CONSOPENPOLLEDIO); 9247c478bd9Sstevel@tonic-gate 9257c478bd9Sstevel@tonic-gate if (mp2 == NULL) { 9267c478bd9Sstevel@tonic-gate /* 9277c478bd9Sstevel@tonic-gate * If we can't get an mblk, then wait for it. 9287c478bd9Sstevel@tonic-gate */ 9297c478bd9Sstevel@tonic-gate goto nomem; 9307c478bd9Sstevel@tonic-gate } 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI); 9337c478bd9Sstevel@tonic-gate 9347c478bd9Sstevel@tonic-gate if (mp2->b_cont == NULL) { 9357c478bd9Sstevel@tonic-gate /* 9367c478bd9Sstevel@tonic-gate * If we can't get an mblk, then wait for it, and release 9377c478bd9Sstevel@tonic-gate * the mblk that we have already allocated. 9387c478bd9Sstevel@tonic-gate */ 9397c478bd9Sstevel@tonic-gate freemsg(mp2); 9407c478bd9Sstevel@tonic-gate goto nomem; 9417c478bd9Sstevel@tonic-gate } 9427c478bd9Sstevel@tonic-gate 943*aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp2->b_rptr; 9447c478bd9Sstevel@tonic-gate 9457c478bd9Sstevel@tonic-gate iocp->ioc_count = sizeof (struct cons_polledio *); 9467c478bd9Sstevel@tonic-gate mp2->b_cont->b_wptr = mp2->b_cont->b_rptr + 9477c478bd9Sstevel@tonic-gate sizeof (struct cons_polledio *); 9487c478bd9Sstevel@tonic-gate 949*aecfc01dSrui zang - Sun Microsystems - Beijing China wscons->wc_pending_wq = q; 9507c478bd9Sstevel@tonic-gate wscons->wc_pending_link = mp; 9517c478bd9Sstevel@tonic-gate wscons->wc_kb_getpolledio_id = iocp->ioc_id; 9527c478bd9Sstevel@tonic-gate 9537c478bd9Sstevel@tonic-gate putnext(wscons->wc_kbdqueue, mp2); 9547c478bd9Sstevel@tonic-gate 9557c478bd9Sstevel@tonic-gate return; 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate nomem: 958*aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 9597c478bd9Sstevel@tonic-gate iocp->ioc_error = ENOMEM; 9607c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 9617c478bd9Sstevel@tonic-gate qreply(q, mp); 9627c478bd9Sstevel@tonic-gate } 9637c478bd9Sstevel@tonic-gate 9647c478bd9Sstevel@tonic-gate /* 9657c478bd9Sstevel@tonic-gate * This function releases the polled I/O structures from the lower 9667c478bd9Sstevel@tonic-gate * keyboard driver. If any de-initialization needs to be done, or 9677c478bd9Sstevel@tonic-gate * any resources need to be released, it will be done when the lower 9687c478bd9Sstevel@tonic-gate * driver services this message. 9697c478bd9Sstevel@tonic-gate */ 9707c478bd9Sstevel@tonic-gate static void 971*aecfc01dSrui zang - Sun Microsystems - Beijing China wc_close_kb_polledio(struct wscons_state *wscons, queue_t *q, mblk_t *mp) 9727c478bd9Sstevel@tonic-gate { 9737c478bd9Sstevel@tonic-gate mblk_t *mp2; 9747c478bd9Sstevel@tonic-gate struct iocblk *iocp; 9757c478bd9Sstevel@tonic-gate 9767c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 9777c478bd9Sstevel@tonic-gate ("wc_close_kb_polledio: sending CONSCLOSEPOLLEDIO\n")); 9787c478bd9Sstevel@tonic-gate 9797c478bd9Sstevel@tonic-gate mp2 = mkiocb(CONSCLOSEPOLLEDIO); 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate if (mp2 == NULL) { 9827c478bd9Sstevel@tonic-gate /* 9837c478bd9Sstevel@tonic-gate * If we can't get an mblk, then wait for it. 9847c478bd9Sstevel@tonic-gate */ 9857c478bd9Sstevel@tonic-gate goto nomem; 9867c478bd9Sstevel@tonic-gate } 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI); 9897c478bd9Sstevel@tonic-gate 9907c478bd9Sstevel@tonic-gate if (mp2->b_cont == NULL) { 9917c478bd9Sstevel@tonic-gate /* 9927c478bd9Sstevel@tonic-gate * If we can't get an mblk, then wait for it, and release 9937c478bd9Sstevel@tonic-gate * the mblk that we have already allocated. 9947c478bd9Sstevel@tonic-gate */ 9957c478bd9Sstevel@tonic-gate freemsg(mp2); 9967c478bd9Sstevel@tonic-gate 9977c478bd9Sstevel@tonic-gate goto nomem; 9987c478bd9Sstevel@tonic-gate } 9997c478bd9Sstevel@tonic-gate 1000*aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp2->b_rptr; 10017c478bd9Sstevel@tonic-gate 10027c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; 10037c478bd9Sstevel@tonic-gate 1004*aecfc01dSrui zang - Sun Microsystems - Beijing China wscons->wc_pending_wq = q; 10057c478bd9Sstevel@tonic-gate wscons->wc_pending_link = mp; 10067c478bd9Sstevel@tonic-gate wscons->wc_kb_getpolledio_id = iocp->ioc_id; 10077c478bd9Sstevel@tonic-gate 10087c478bd9Sstevel@tonic-gate putnext(wscons->wc_kbdqueue, mp2); 10097c478bd9Sstevel@tonic-gate 10107c478bd9Sstevel@tonic-gate return; 10117c478bd9Sstevel@tonic-gate 10127c478bd9Sstevel@tonic-gate nomem: 1013*aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 10147c478bd9Sstevel@tonic-gate iocp->ioc_error = ENOMEM; 10157c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 10167c478bd9Sstevel@tonic-gate qreply(q, mp); 10177c478bd9Sstevel@tonic-gate } 10187c478bd9Sstevel@tonic-gate 1019fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 10207c478bd9Sstevel@tonic-gate /* ARGSUSED */ 10217c478bd9Sstevel@tonic-gate static void 10227c478bd9Sstevel@tonic-gate wcopoll(void *arg) 10237c478bd9Sstevel@tonic-gate { 1024*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 10257c478bd9Sstevel@tonic-gate queue_t *q; 10267c478bd9Sstevel@tonic-gate 1027*aecfc01dSrui zang - Sun Microsystems - Beijing China q = pvc->vc_ttycommon.t_writeq; 1028*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = 0; 1029*aecfc01dSrui zang - Sun Microsystems - Beijing China 1030*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1031*aecfc01dSrui zang - Sun Microsystems - Beijing China 10327c478bd9Sstevel@tonic-gate /* See if we can continue output */ 1033*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((pvc->vc_flags & WCS_BUSY) && pvc->vc_pendc != -1) { 1034*aecfc01dSrui zang - Sun Microsystems - Beijing China if (prom_mayput((char)pvc->vc_pendc) == 0) { 1035*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_pendc = -1; 1036*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags &= ~WCS_BUSY; 1037*aecfc01dSrui zang - Sun Microsystems - Beijing China if (!(pvc->vc_flags&(WCS_DELAY|WCS_STOPPED))) 1038*aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 10397c478bd9Sstevel@tonic-gate } else 1040*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = qtimeout(q, wcopoll, pvc, 1); 10417c478bd9Sstevel@tonic-gate } 1042*aecfc01dSrui zang - Sun Microsystems - Beijing China 1043*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 10447c478bd9Sstevel@tonic-gate } 1045fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate /* 10487c478bd9Sstevel@tonic-gate * Restart output on the console after a timeout. 10497c478bd9Sstevel@tonic-gate */ 10507c478bd9Sstevel@tonic-gate /* ARGSUSED */ 10517c478bd9Sstevel@tonic-gate static void 10527c478bd9Sstevel@tonic-gate wcrstrt(void *arg) 10537c478bd9Sstevel@tonic-gate { 1054*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 1055*aecfc01dSrui zang - Sun Microsystems - Beijing China 1056*aecfc01dSrui zang - Sun Microsystems - Beijing China ASSERT(pvc->vc_ttycommon.t_writeq != NULL); 1057*aecfc01dSrui zang - Sun Microsystems - Beijing China 1058*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1059*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags &= ~WCS_DELAY; 1060*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1061*aecfc01dSrui zang - Sun Microsystems - Beijing China 1062*aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 1063*aecfc01dSrui zang - Sun Microsystems - Beijing China } 1064*aecfc01dSrui zang - Sun Microsystems - Beijing China 1065*aecfc01dSrui zang - Sun Microsystems - Beijing China /* 1066*aecfc01dSrui zang - Sun Microsystems - Beijing China * get screen terminal for current output 1067*aecfc01dSrui zang - Sun Microsystems - Beijing China */ 1068*aecfc01dSrui zang - Sun Microsystems - Beijing China static tem_vt_state_t 1069*aecfc01dSrui zang - Sun Microsystems - Beijing China wc_get_screen_tem(vc_state_t *pvc) 1070*aecfc01dSrui zang - Sun Microsystems - Beijing China { 1071*aecfc01dSrui zang - Sun Microsystems - Beijing China if (!tem_initialized(pvc->vc_tem) || 1072*aecfc01dSrui zang - Sun Microsystems - Beijing China tem_get_fbmode(pvc->vc_tem) != KD_TEXT) 1073*aecfc01dSrui zang - Sun Microsystems - Beijing China return (NULL); 1074*aecfc01dSrui zang - Sun Microsystems - Beijing China 1075*aecfc01dSrui zang - Sun Microsystems - Beijing China return (pvc->vc_tem); 10767c478bd9Sstevel@tonic-gate } 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate /* 10797c478bd9Sstevel@tonic-gate * Start console output 10807c478bd9Sstevel@tonic-gate */ 10817c478bd9Sstevel@tonic-gate static void 1082*aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(void *arg) 10837c478bd9Sstevel@tonic-gate { 1084*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 1085*aecfc01dSrui zang - Sun Microsystems - Beijing China tem_vt_state_t ptem = NULL; 1086fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 10877c478bd9Sstevel@tonic-gate int c; 10887c478bd9Sstevel@tonic-gate ssize_t cc; 1089fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 10907c478bd9Sstevel@tonic-gate queue_t *q; 10917c478bd9Sstevel@tonic-gate mblk_t *bp; 10927c478bd9Sstevel@tonic-gate mblk_t *nbp; 10937c478bd9Sstevel@tonic-gate 10947c478bd9Sstevel@tonic-gate /* 10957c478bd9Sstevel@tonic-gate * If we're waiting for something to happen (delay timeout to 10967c478bd9Sstevel@tonic-gate * expire, current transmission to finish, output to be 10977c478bd9Sstevel@tonic-gate * restarted, output to finish draining), don't grab anything 10987c478bd9Sstevel@tonic-gate * new. 10997c478bd9Sstevel@tonic-gate */ 1100*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_flags & (WCS_DELAY|WCS_BUSY|WCS_STOPPED)) 1101fea9cb91Slq150181 return; 11027c478bd9Sstevel@tonic-gate 1103*aecfc01dSrui zang - Sun Microsystems - Beijing China q = pvc->vc_ttycommon.t_writeq; 11047c478bd9Sstevel@tonic-gate /* 11057c478bd9Sstevel@tonic-gate * assumes that we have been called by whoever holds the 11067c478bd9Sstevel@tonic-gate * exclusionary lock on the write-side queue (protects 1107*aecfc01dSrui zang - Sun Microsystems - Beijing China * vc_flags and vc_pendc). 11087c478bd9Sstevel@tonic-gate */ 11097c478bd9Sstevel@tonic-gate for (;;) { 11107c478bd9Sstevel@tonic-gate if ((bp = getq(q)) == NULL) 1111fea9cb91Slq150181 return; /* nothing to transmit */ 11127c478bd9Sstevel@tonic-gate 11137c478bd9Sstevel@tonic-gate /* 11147c478bd9Sstevel@tonic-gate * We have a new message to work on. 11157c478bd9Sstevel@tonic-gate * Check whether it's a delay or an ioctl (the latter 11167c478bd9Sstevel@tonic-gate * occurs if the ioctl in question was waiting for the output 11177c478bd9Sstevel@tonic-gate * to drain). If it's one of those, process it immediately. 11187c478bd9Sstevel@tonic-gate */ 11197c478bd9Sstevel@tonic-gate switch (bp->b_datap->db_type) { 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate case M_DELAY: 11227c478bd9Sstevel@tonic-gate /* 11237c478bd9Sstevel@tonic-gate * Arrange for "wcrstrt" to be called when the 11247c478bd9Sstevel@tonic-gate * delay expires; it will turn WCS_DELAY off, 11257c478bd9Sstevel@tonic-gate * and call "wcstart" to grab the next message. 11267c478bd9Sstevel@tonic-gate */ 1127*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_timeoutid != 0) 1128*aecfc01dSrui zang - Sun Microsystems - Beijing China (void) quntimeout(q, pvc->vc_timeoutid); 1129*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = qtimeout(q, wcrstrt, pvc, 11307c478bd9Sstevel@tonic-gate (clock_t)(*(unsigned char *)bp->b_rptr + 6)); 1131*aecfc01dSrui zang - Sun Microsystems - Beijing China 1132*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1133*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags |= WCS_DELAY; 1134*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1135*aecfc01dSrui zang - Sun Microsystems - Beijing China 11367c478bd9Sstevel@tonic-gate freemsg(bp); 1137fea9cb91Slq150181 return; /* wait for this to finish */ 11387c478bd9Sstevel@tonic-gate 11397c478bd9Sstevel@tonic-gate case M_IOCTL: 11407c478bd9Sstevel@tonic-gate /* 11417c478bd9Sstevel@tonic-gate * This ioctl was waiting for the output ahead of 11427c478bd9Sstevel@tonic-gate * it to drain; obviously, it has. Do it, and 11437c478bd9Sstevel@tonic-gate * then grab the next message after it. 11447c478bd9Sstevel@tonic-gate */ 11457c478bd9Sstevel@tonic-gate wcioctl(q, bp); 11467c478bd9Sstevel@tonic-gate continue; 11477c478bd9Sstevel@tonic-gate } 11487c478bd9Sstevel@tonic-gate 1149fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 1150fea9cb91Slq150181 if (consmode == CONS_KFB) { 1151fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 1152*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((ptem = wc_get_screen_tem(pvc)) != NULL) { 1153*aecfc01dSrui zang - Sun Microsystems - Beijing China 11547c478bd9Sstevel@tonic-gate for (nbp = bp; nbp != NULL; nbp = nbp->b_cont) { 11557c478bd9Sstevel@tonic-gate if (nbp->b_wptr > nbp->b_rptr) { 1156*aecfc01dSrui zang - Sun Microsystems - Beijing China (void) tem_write(ptem, 1157fea9cb91Slq150181 nbp->b_rptr, 1158*aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED */ 1159*aecfc01dSrui zang - Sun Microsystems - Beijing China nbp->b_wptr - nbp->b_rptr, 11607c478bd9Sstevel@tonic-gate kcred); 11617c478bd9Sstevel@tonic-gate } 11627c478bd9Sstevel@tonic-gate } 1163*aecfc01dSrui zang - Sun Microsystems - Beijing China 1164fea9cb91Slq150181 } 1165*aecfc01dSrui zang - Sun Microsystems - Beijing China 1166*aecfc01dSrui zang - Sun Microsystems - Beijing China freemsg(bp); 1167*aecfc01dSrui zang - Sun Microsystems - Beijing China 1168fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 1169fea9cb91Slq150181 continue; 1170fea9cb91Slq150181 } 1171fea9cb91Slq150181 1172fea9cb91Slq150181 /* consmode = CONS_FW */ 1173*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_minor != 0) { 1174*aecfc01dSrui zang - Sun Microsystems - Beijing China freemsg(bp); 1175*aecfc01dSrui zang - Sun Microsystems - Beijing China continue; 1176*aecfc01dSrui zang - Sun Microsystems - Beijing China } 1177*aecfc01dSrui zang - Sun Microsystems - Beijing China 1178*aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED E_PTRDIFF_OVERFLOW */ 1179*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((cc = bp->b_wptr - bp->b_rptr) == 0) { 11807c478bd9Sstevel@tonic-gate freemsg(bp); 11817c478bd9Sstevel@tonic-gate continue; 11827c478bd9Sstevel@tonic-gate } 11837c478bd9Sstevel@tonic-gate /* 11847c478bd9Sstevel@tonic-gate * Direct output to the frame buffer if this device 11857c478bd9Sstevel@tonic-gate * is not the "hardware" console. 11867c478bd9Sstevel@tonic-gate */ 11877c478bd9Sstevel@tonic-gate if (wscons.wc_defer_output) { 11887c478bd9Sstevel@tonic-gate /* 11897c478bd9Sstevel@tonic-gate * Never do output here; 11907c478bd9Sstevel@tonic-gate * it takes forever. 11917c478bd9Sstevel@tonic-gate */ 1192*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1193*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags |= WCS_BUSY; 1194*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1195*aecfc01dSrui zang - Sun Microsystems - Beijing China 1196*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_pendc = -1; 11977c478bd9Sstevel@tonic-gate (void) putbq(q, bp); 11987c478bd9Sstevel@tonic-gate if (q->q_count > 128) { /* do it soon */ 1199*aecfc01dSrui zang - Sun Microsystems - Beijing China softcall(wconsout, pvc); 12007c478bd9Sstevel@tonic-gate } else { /* wait a bit */ 1201*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_timeoutid != 0) 12027c478bd9Sstevel@tonic-gate (void) quntimeout(q, 1203*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid); 1204*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = qtimeout(q, wconsout, 1205*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc, hz / 30); 12067c478bd9Sstevel@tonic-gate } 1207fea9cb91Slq150181 return; 12087c478bd9Sstevel@tonic-gate } 12097c478bd9Sstevel@tonic-gate for (;;) { 12107c478bd9Sstevel@tonic-gate c = *bp->b_rptr++; 12117c478bd9Sstevel@tonic-gate cc--; 12127c478bd9Sstevel@tonic-gate if (prom_mayput((char)c) != 0) { 1213*aecfc01dSrui zang - Sun Microsystems - Beijing China 1214*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1215*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags |= WCS_BUSY; 1216*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1217*aecfc01dSrui zang - Sun Microsystems - Beijing China 1218*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_pendc = c; 1219*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_timeoutid != 0) 12207c478bd9Sstevel@tonic-gate (void) quntimeout(q, 1221*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid); 1222*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = qtimeout(q, wcopoll, 1223*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc, 1); 12247c478bd9Sstevel@tonic-gate if (bp != NULL) 12257c478bd9Sstevel@tonic-gate /* not done with this message yet */ 12267c478bd9Sstevel@tonic-gate (void) putbq(q, bp); 1227fea9cb91Slq150181 return; 12287c478bd9Sstevel@tonic-gate } 12297c478bd9Sstevel@tonic-gate while (cc <= 0) { 12307c478bd9Sstevel@tonic-gate nbp = bp; 12317c478bd9Sstevel@tonic-gate bp = bp->b_cont; 12327c478bd9Sstevel@tonic-gate freeb(nbp); 12337c478bd9Sstevel@tonic-gate if (bp == NULL) 1234fea9cb91Slq150181 return; 1235*aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED E_PTRDIFF_OVERFLOW */ 1236*aecfc01dSrui zang - Sun Microsystems - Beijing China cc = bp->b_wptr - bp->b_rptr; 12377c478bd9Sstevel@tonic-gate } 12387c478bd9Sstevel@tonic-gate } 1239fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 12407c478bd9Sstevel@tonic-gate } 12417c478bd9Sstevel@tonic-gate } 12427c478bd9Sstevel@tonic-gate 1243fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 12447c478bd9Sstevel@tonic-gate /* 12457c478bd9Sstevel@tonic-gate * Output to frame buffer console. 12467c478bd9Sstevel@tonic-gate * It takes a long time to scroll. 12477c478bd9Sstevel@tonic-gate */ 12487c478bd9Sstevel@tonic-gate /* ARGSUSED */ 12497c478bd9Sstevel@tonic-gate static void 1250*aecfc01dSrui zang - Sun Microsystems - Beijing China wconsout(void *arg) 12517c478bd9Sstevel@tonic-gate { 1252*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 12537c478bd9Sstevel@tonic-gate uchar_t *cp; 12547c478bd9Sstevel@tonic-gate ssize_t cc; 12557c478bd9Sstevel@tonic-gate queue_t *q; 12567c478bd9Sstevel@tonic-gate mblk_t *bp; 12577c478bd9Sstevel@tonic-gate mblk_t *nbp; 12587c478bd9Sstevel@tonic-gate char *current_position; 12597c478bd9Sstevel@tonic-gate ssize_t bytes_left; 12607c478bd9Sstevel@tonic-gate 1261*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((q = pvc->vc_ttycommon.t_writeq) == NULL) { 12627c478bd9Sstevel@tonic-gate return; /* not attached to a stream */ 12637c478bd9Sstevel@tonic-gate } 12647c478bd9Sstevel@tonic-gate 12657c478bd9Sstevel@tonic-gate /* 12667c478bd9Sstevel@tonic-gate * Set up to copy up to MAXHIWAT bytes. 12677c478bd9Sstevel@tonic-gate */ 12687c478bd9Sstevel@tonic-gate current_position = &obuf[0]; 12697c478bd9Sstevel@tonic-gate bytes_left = MAXHIWAT; 12707c478bd9Sstevel@tonic-gate while ((bp = getq(q)) != NULL) { 12717c478bd9Sstevel@tonic-gate if (bp->b_datap->db_type == M_IOCTL) { 12727c478bd9Sstevel@tonic-gate /* 12737c478bd9Sstevel@tonic-gate * This ioctl was waiting for the output ahead of 12747c478bd9Sstevel@tonic-gate * it to drain; obviously, it has. Put it back 12757c478bd9Sstevel@tonic-gate * so that "wcstart" can handle it, and transmit 12767c478bd9Sstevel@tonic-gate * what we've got. 12777c478bd9Sstevel@tonic-gate */ 12787c478bd9Sstevel@tonic-gate (void) putbq(q, bp); 12797c478bd9Sstevel@tonic-gate goto transmit; 12807c478bd9Sstevel@tonic-gate } 12817c478bd9Sstevel@tonic-gate 12827c478bd9Sstevel@tonic-gate do { 12837c478bd9Sstevel@tonic-gate cp = bp->b_rptr; 1284*aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED E_PTRDIFF_OVERFLOW */ 1285*aecfc01dSrui zang - Sun Microsystems - Beijing China cc = bp->b_wptr - cp; 12867c478bd9Sstevel@tonic-gate while (cc != 0) { 12877c478bd9Sstevel@tonic-gate if (bytes_left == 0) { 12887c478bd9Sstevel@tonic-gate /* 12897c478bd9Sstevel@tonic-gate * Out of buffer space; put this 12907c478bd9Sstevel@tonic-gate * buffer back on the queue, and 12917c478bd9Sstevel@tonic-gate * transmit what we have. 12927c478bd9Sstevel@tonic-gate */ 12937c478bd9Sstevel@tonic-gate bp->b_rptr = cp; 12947c478bd9Sstevel@tonic-gate (void) putbq(q, bp); 12957c478bd9Sstevel@tonic-gate goto transmit; 12967c478bd9Sstevel@tonic-gate } 12977c478bd9Sstevel@tonic-gate *current_position++ = *cp++; 12987c478bd9Sstevel@tonic-gate cc--; 12997c478bd9Sstevel@tonic-gate bytes_left--; 13007c478bd9Sstevel@tonic-gate } 13017c478bd9Sstevel@tonic-gate nbp = bp; 13027c478bd9Sstevel@tonic-gate bp = bp->b_cont; 13037c478bd9Sstevel@tonic-gate freeb(nbp); 13047c478bd9Sstevel@tonic-gate } while (bp != NULL); 13057c478bd9Sstevel@tonic-gate } 13067c478bd9Sstevel@tonic-gate 13077c478bd9Sstevel@tonic-gate transmit: 13087c478bd9Sstevel@tonic-gate if ((cc = MAXHIWAT - bytes_left) != 0) 13097c478bd9Sstevel@tonic-gate console_puts(obuf, cc); 13107c478bd9Sstevel@tonic-gate 1311*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1312*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags &= ~WCS_BUSY; 1313*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1314*aecfc01dSrui zang - Sun Microsystems - Beijing China 1315*aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 13167c478bd9Sstevel@tonic-gate } 1317fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 13187c478bd9Sstevel@tonic-gate 13197c478bd9Sstevel@tonic-gate /* 13207c478bd9Sstevel@tonic-gate * Put procedure for lower read queue. 13217c478bd9Sstevel@tonic-gate * Pass everything up to queue above "upper half". 13227c478bd9Sstevel@tonic-gate */ 13237c478bd9Sstevel@tonic-gate static int 13247c478bd9Sstevel@tonic-gate wclrput(queue_t *q, mblk_t *mp) 13257c478bd9Sstevel@tonic-gate { 1326*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc; 13277c478bd9Sstevel@tonic-gate queue_t *upq; 13287c478bd9Sstevel@tonic-gate struct iocblk *iocp; 13297c478bd9Sstevel@tonic-gate 1330*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc = vt_minor2vc(VT_ACTIVE); 1331*aecfc01dSrui zang - Sun Microsystems - Beijing China 13327c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 13337c478bd9Sstevel@tonic-gate ("wclrput: wclrput type = 0x%x\n", mp->b_datap->db_type)); 13347c478bd9Sstevel@tonic-gate 13357c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) { 13367c478bd9Sstevel@tonic-gate 13377c478bd9Sstevel@tonic-gate case M_FLUSH: 13387c478bd9Sstevel@tonic-gate if (*mp->b_rptr == FLUSHW || *mp->b_rptr == FLUSHRW) { 13397c478bd9Sstevel@tonic-gate /* 13407c478bd9Sstevel@tonic-gate * Flush our write queue. 13417c478bd9Sstevel@tonic-gate */ 13427c478bd9Sstevel@tonic-gate /* XXX doesn't flush M_DELAY */ 13437c478bd9Sstevel@tonic-gate flushq(WR(q), FLUSHDATA); 13447c478bd9Sstevel@tonic-gate *mp->b_rptr = FLUSHR; /* it has been flushed */ 13457c478bd9Sstevel@tonic-gate } 13467c478bd9Sstevel@tonic-gate if (*mp->b_rptr == FLUSHR || *mp->b_rptr == FLUSHRW) { 13477c478bd9Sstevel@tonic-gate flushq(q, FLUSHDATA); 13487c478bd9Sstevel@tonic-gate *mp->b_rptr = FLUSHW; /* it has been flushed */ 13497c478bd9Sstevel@tonic-gate qreply(q, mp); /* give the read queues a crack at it */ 13507c478bd9Sstevel@tonic-gate } else 13517c478bd9Sstevel@tonic-gate freemsg(mp); 13527c478bd9Sstevel@tonic-gate break; 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate case M_DATA: 1355*aecfc01dSrui zang - Sun Microsystems - Beijing China if (consmode == CONS_KFB && vt_check_hotkeys(mp)) { 13567c478bd9Sstevel@tonic-gate freemsg(mp); 1357*aecfc01dSrui zang - Sun Microsystems - Beijing China break; 1358*aecfc01dSrui zang - Sun Microsystems - Beijing China } 1359*aecfc01dSrui zang - Sun Microsystems - Beijing China 1360*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((upq = pvc->vc_ttycommon.t_readq) != NULL) { 1361*aecfc01dSrui zang - Sun Microsystems - Beijing China if (!canput(upq->q_next)) { 1362*aecfc01dSrui zang - Sun Microsystems - Beijing China ttycommon_qfull(&pvc->vc_ttycommon, upq); 1363*aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 1364*aecfc01dSrui zang - Sun Microsystems - Beijing China freemsg(mp); 1365*aecfc01dSrui zang - Sun Microsystems - Beijing China } else { 13667c478bd9Sstevel@tonic-gate putnext(upq, mp); 1367*aecfc01dSrui zang - Sun Microsystems - Beijing China } 13687c478bd9Sstevel@tonic-gate } else 13697c478bd9Sstevel@tonic-gate freemsg(mp); 13707c478bd9Sstevel@tonic-gate break; 13717c478bd9Sstevel@tonic-gate 13727c478bd9Sstevel@tonic-gate case M_IOCACK: 13737c478bd9Sstevel@tonic-gate case M_IOCNAK: 1374*aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 13757c478bd9Sstevel@tonic-gate if (wscons.wc_pending_link != NULL && 13767c478bd9Sstevel@tonic-gate iocp->ioc_id == wscons.wc_kb_getpolledio_id) { 13777c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) { 13787c478bd9Sstevel@tonic-gate 13797c478bd9Sstevel@tonic-gate case M_IOCACK: 13807c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) { 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate case CONSOPENPOLLEDIO: 13837c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 13847c478bd9Sstevel@tonic-gate ("wclrput: " 13857c478bd9Sstevel@tonic-gate "ACK CONSOPENPOLLEDIO\n")); 13867c478bd9Sstevel@tonic-gate wscons.wc_kb_polledio = 1387*aecfc01dSrui zang - Sun Microsystems - Beijing China *(struct cons_polledio **) 1388*aecfc01dSrui zang - Sun Microsystems - Beijing China (void *)mp->b_cont->b_rptr; 1389fea9cb91Slq150181 wscons.wc_polledio. 1390fea9cb91Slq150181 cons_polledio_getchar = 1391fea9cb91Slq150181 wc_polled_getchar; 1392fea9cb91Slq150181 wscons.wc_polledio. 1393fea9cb91Slq150181 cons_polledio_ischar = 1394fea9cb91Slq150181 wc_polled_ischar; 13957c478bd9Sstevel@tonic-gate break; 13967c478bd9Sstevel@tonic-gate 13977c478bd9Sstevel@tonic-gate case CONSCLOSEPOLLEDIO: 13987c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 13997c478bd9Sstevel@tonic-gate ("wclrput: " 14007c478bd9Sstevel@tonic-gate "ACK CONSCLOSEPOLLEDIO\n")); 14017c478bd9Sstevel@tonic-gate wscons.wc_kb_polledio = NULL; 14027c478bd9Sstevel@tonic-gate wscons.wc_kbdqueue = NULL; 1403fea9cb91Slq150181 wscons.wc_polledio. 1404fea9cb91Slq150181 cons_polledio_getchar = NULL; 1405fea9cb91Slq150181 wscons.wc_polledio. 1406fea9cb91Slq150181 cons_polledio_ischar = NULL; 14077c478bd9Sstevel@tonic-gate break; 14087c478bd9Sstevel@tonic-gate default: 14097c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 1410*aecfc01dSrui zang - Sun Microsystems - Beijing China ("wclrput: " 1411*aecfc01dSrui zang - Sun Microsystems - Beijing China "ACK UNKNOWN\n")); 14127c478bd9Sstevel@tonic-gate } 14137c478bd9Sstevel@tonic-gate 14147c478bd9Sstevel@tonic-gate break; 14157c478bd9Sstevel@tonic-gate case M_IOCNAK: 14167c478bd9Sstevel@tonic-gate /* 14177c478bd9Sstevel@tonic-gate * Keyboard may or may not support polled I/O. 14187c478bd9Sstevel@tonic-gate * This ioctl may have been rejected because 14197c478bd9Sstevel@tonic-gate * we only have the wc->conskbd chain built, 14207c478bd9Sstevel@tonic-gate * and the keyboard driver has not been linked 14217c478bd9Sstevel@tonic-gate * underneath conskbd yet. 14227c478bd9Sstevel@tonic-gate */ 14237c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 14247c478bd9Sstevel@tonic-gate ("wclrput: NAK\n")); 14257c478bd9Sstevel@tonic-gate 14267c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) { 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate case CONSCLOSEPOLLEDIO: 14297c478bd9Sstevel@tonic-gate wscons.wc_kb_polledio = NULL; 14307c478bd9Sstevel@tonic-gate wscons.wc_kbdqueue = NULL; 1431fea9cb91Slq150181 wscons.wc_polledio. 1432fea9cb91Slq150181 cons_polledio_getchar = NULL; 1433fea9cb91Slq150181 wscons.wc_polledio. 1434fea9cb91Slq150181 cons_polledio_ischar = NULL; 14357c478bd9Sstevel@tonic-gate break; 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate break; 14387c478bd9Sstevel@tonic-gate } 14397c478bd9Sstevel@tonic-gate 14407c478bd9Sstevel@tonic-gate /* 14417c478bd9Sstevel@tonic-gate * Discard the response, replace it with the 14427c478bd9Sstevel@tonic-gate * pending response to the I_PLINK, then let it 14437c478bd9Sstevel@tonic-gate * flow upward. 14447c478bd9Sstevel@tonic-gate */ 14457c478bd9Sstevel@tonic-gate freemsg(mp); 14467c478bd9Sstevel@tonic-gate mp = wscons.wc_pending_link; 14477c478bd9Sstevel@tonic-gate wscons.wc_pending_link = NULL; 14487c478bd9Sstevel@tonic-gate wscons.wc_kb_getpolledio_id = 0; 14497c478bd9Sstevel@tonic-gate } 14507c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 14517c478bd9Sstevel@tonic-gate 14527c478bd9Sstevel@tonic-gate default: /* inc M_ERROR, M_HANGUP, M_IOCACK, M_IOCNAK, ... */ 1453*aecfc01dSrui zang - Sun Microsystems - Beijing China if (wscons.wc_pending_wq != NULL) { 1454*aecfc01dSrui zang - Sun Microsystems - Beijing China qreply(wscons.wc_pending_wq, mp); 1455*aecfc01dSrui zang - Sun Microsystems - Beijing China wscons.wc_pending_wq = NULL; 1456*aecfc01dSrui zang - Sun Microsystems - Beijing China break; 1457*aecfc01dSrui zang - Sun Microsystems - Beijing China } 1458*aecfc01dSrui zang - Sun Microsystems - Beijing China 1459*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((upq = pvc->vc_ttycommon.t_readq) != NULL) { 14607c478bd9Sstevel@tonic-gate putnext(upq, mp); 14617c478bd9Sstevel@tonic-gate } else { 1462*aecfc01dSrui zang - Sun Microsystems - Beijing China DPRINTF(PRINT_L1, PRINT_MASK_ALL, 1463*aecfc01dSrui zang - Sun Microsystems - Beijing China ("wclrput: Message DISCARDED\n")); 14647c478bd9Sstevel@tonic-gate freemsg(mp); 14657c478bd9Sstevel@tonic-gate } 14667c478bd9Sstevel@tonic-gate break; 14677c478bd9Sstevel@tonic-gate } 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate return (0); 14707c478bd9Sstevel@tonic-gate } 14717c478bd9Sstevel@tonic-gate 1472*aecfc01dSrui zang - Sun Microsystems - Beijing China #ifdef _HAVE_TEM_FIRMWARE 1473*aecfc01dSrui zang - Sun Microsystems - Beijing China /* 1474*aecfc01dSrui zang - Sun Microsystems - Beijing China * This routine exists so that prom_write() can redirect writes 1475*aecfc01dSrui zang - Sun Microsystems - Beijing China * to the framebuffer through the kernel terminal emulator, if 1476*aecfc01dSrui zang - Sun Microsystems - Beijing China * that configuration is selected during consconfig. 1477*aecfc01dSrui zang - Sun Microsystems - Beijing China * When the kernel terminal emulator is enabled, consconfig_dacf 1478*aecfc01dSrui zang - Sun Microsystems - Beijing China * sets up the PROM output redirect vector to enter this function. 1479*aecfc01dSrui zang - Sun Microsystems - Beijing China * During panic the console will already be powered up as part of 1480*aecfc01dSrui zang - Sun Microsystems - Beijing China * calling into the prom_*() layer. 1481*aecfc01dSrui zang - Sun Microsystems - Beijing China */ 1482*aecfc01dSrui zang - Sun Microsystems - Beijing China /* ARGSUSED */ 1483*aecfc01dSrui zang - Sun Microsystems - Beijing China ssize_t 1484*aecfc01dSrui zang - Sun Microsystems - Beijing China wc_cons_wrtvec(promif_redir_arg_t arg, uchar_t *s, size_t n) 1485*aecfc01dSrui zang - Sun Microsystems - Beijing China { 1486*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc; 1487*aecfc01dSrui zang - Sun Microsystems - Beijing China 1488*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc = vt_minor2vc(VT_ACTIVE); 1489*aecfc01dSrui zang - Sun Microsystems - Beijing China 1490*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_tem == NULL) 1491*aecfc01dSrui zang - Sun Microsystems - Beijing China return (0); 1492*aecfc01dSrui zang - Sun Microsystems - Beijing China 1493*aecfc01dSrui zang - Sun Microsystems - Beijing China ASSERT(consmode == CONS_KFB); 1494*aecfc01dSrui zang - Sun Microsystems - Beijing China 1495*aecfc01dSrui zang - Sun Microsystems - Beijing China if (panicstr) 1496*aecfc01dSrui zang - Sun Microsystems - Beijing China polled_io_cons_write(s, n); 1497*aecfc01dSrui zang - Sun Microsystems - Beijing China else 1498*aecfc01dSrui zang - Sun Microsystems - Beijing China (void) tem_write(pvc->vc_tem, s, n, kcred); 1499*aecfc01dSrui zang - Sun Microsystems - Beijing China 1500*aecfc01dSrui zang - Sun Microsystems - Beijing China return (n); 1501*aecfc01dSrui zang - Sun Microsystems - Beijing China } 1502*aecfc01dSrui zang - Sun Microsystems - Beijing China #endif /* _HAVE_TEM_FIRMWARE */ 1503*aecfc01dSrui zang - Sun Microsystems - Beijing China 15047c478bd9Sstevel@tonic-gate /* 1505fea9cb91Slq150181 * These are for systems without OBP, and for devices that cannot be 1506fea9cb91Slq150181 * shared between Solaris and the OBP. 15077c478bd9Sstevel@tonic-gate */ 15087c478bd9Sstevel@tonic-gate static void 1509281f0747Slt200341 wc_polled_putchar(cons_polledio_arg_t arg, unsigned char c) 15107c478bd9Sstevel@tonic-gate { 1511*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc; 1512*aecfc01dSrui zang - Sun Microsystems - Beijing China 1513*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc = vt_minor2vc(VT_ACTIVE); 1514*aecfc01dSrui zang - Sun Microsystems - Beijing China 15157c478bd9Sstevel@tonic-gate if (c == '\n') 1516fea9cb91Slq150181 wc_polled_putchar(arg, '\r'); 15177c478bd9Sstevel@tonic-gate 1518*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_tem == NULL) { 15197c478bd9Sstevel@tonic-gate /* 15207c478bd9Sstevel@tonic-gate * We have no terminal emulator configured. We have no 15217c478bd9Sstevel@tonic-gate * recourse but to drop the output on the floor. 15227c478bd9Sstevel@tonic-gate */ 15237c478bd9Sstevel@tonic-gate return; 15247c478bd9Sstevel@tonic-gate } 15257c478bd9Sstevel@tonic-gate 1526*aecfc01dSrui zang - Sun Microsystems - Beijing China tem_safe_polled_write(pvc->vc_tem, &c, 1); 15277c478bd9Sstevel@tonic-gate } 15287c478bd9Sstevel@tonic-gate 15297c478bd9Sstevel@tonic-gate /* 15307c478bd9Sstevel@tonic-gate * These are for systems without OBP, and for devices that cannot be 15317c478bd9Sstevel@tonic-gate * shared between Solaris and the OBP. 15327c478bd9Sstevel@tonic-gate */ 15337c478bd9Sstevel@tonic-gate static int 1534281f0747Slt200341 wc_polled_getchar(cons_polledio_arg_t arg) 15357c478bd9Sstevel@tonic-gate { 1536*aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state *wscons = (struct wscons_state *)arg; 15377c478bd9Sstevel@tonic-gate 15387c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) { 15397c478bd9Sstevel@tonic-gate prom_printf("wscons: getchar with no keyboard support"); 15407c478bd9Sstevel@tonic-gate prom_printf("Halted..."); 15417c478bd9Sstevel@tonic-gate for (;;) 15427c478bd9Sstevel@tonic-gate /* HANG FOREVER */; 15437c478bd9Sstevel@tonic-gate } 15447c478bd9Sstevel@tonic-gate 15457c478bd9Sstevel@tonic-gate return (wscons->wc_kb_polledio->cons_polledio_getchar( 15467c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_argument)); 15477c478bd9Sstevel@tonic-gate } 15487c478bd9Sstevel@tonic-gate 15497c478bd9Sstevel@tonic-gate static boolean_t 1550281f0747Slt200341 wc_polled_ischar(cons_polledio_arg_t arg) 15517c478bd9Sstevel@tonic-gate { 1552*aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state *wscons = (struct wscons_state *)arg; 15537c478bd9Sstevel@tonic-gate 15547c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) 15557c478bd9Sstevel@tonic-gate return (B_FALSE); 15567c478bd9Sstevel@tonic-gate 15577c478bd9Sstevel@tonic-gate return (wscons->wc_kb_polledio->cons_polledio_ischar( 15587c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_argument)); 15597c478bd9Sstevel@tonic-gate } 15607c478bd9Sstevel@tonic-gate 15617c478bd9Sstevel@tonic-gate static void 1562281f0747Slt200341 wc_polled_enter(cons_polledio_arg_t arg) 15637c478bd9Sstevel@tonic-gate { 1564*aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state *wscons = (struct wscons_state *)arg; 15657c478bd9Sstevel@tonic-gate 15667c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) 15677c478bd9Sstevel@tonic-gate return; 15687c478bd9Sstevel@tonic-gate 15697c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio->cons_polledio_enter != NULL) { 15707c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_enter( 15717c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_argument); 15727c478bd9Sstevel@tonic-gate } 15737c478bd9Sstevel@tonic-gate } 15747c478bd9Sstevel@tonic-gate 15757c478bd9Sstevel@tonic-gate static void 1576281f0747Slt200341 wc_polled_exit(cons_polledio_arg_t arg) 15777c478bd9Sstevel@tonic-gate { 1578*aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state *wscons = (struct wscons_state *)arg; 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) 15817c478bd9Sstevel@tonic-gate return; 15827c478bd9Sstevel@tonic-gate 15837c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio->cons_polledio_exit != NULL) { 15847c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_exit( 15857c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_argument); 15867c478bd9Sstevel@tonic-gate } 15877c478bd9Sstevel@tonic-gate } 15887c478bd9Sstevel@tonic-gate 15897c478bd9Sstevel@tonic-gate 15907c478bd9Sstevel@tonic-gate #ifdef DEBUG 15917c478bd9Sstevel@tonic-gate static void 15927c478bd9Sstevel@tonic-gate wc_dprintf(const char *fmt, ...) 15937c478bd9Sstevel@tonic-gate { 15947c478bd9Sstevel@tonic-gate char buf[256]; 15957c478bd9Sstevel@tonic-gate va_list ap; 15967c478bd9Sstevel@tonic-gate 15977c478bd9Sstevel@tonic-gate va_start(ap, fmt); 15987c478bd9Sstevel@tonic-gate (void) vsprintf(buf, fmt, ap); 15997c478bd9Sstevel@tonic-gate va_end(ap); 16007c478bd9Sstevel@tonic-gate 1601fea9cb91Slq150181 cmn_err(CE_WARN, "wc: %s", buf); 16027c478bd9Sstevel@tonic-gate } 16037c478bd9Sstevel@tonic-gate #endif 16047c478bd9Sstevel@tonic-gate 1605*aecfc01dSrui zang - Sun Microsystems - Beijing China /*ARGSUSED*/ 1606fea9cb91Slq150181 static void 1607*aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(vc_state_t *pvc, char *name, ushort_t value) 16087c478bd9Sstevel@tonic-gate { 1609fea9cb91Slq150181 char data[8]; 16107c478bd9Sstevel@tonic-gate 1611fea9cb91Slq150181 (void) snprintf(data, sizeof (data), "%u", value); 1612*aecfc01dSrui zang - Sun Microsystems - Beijing China 1613*aecfc01dSrui zang - Sun Microsystems - Beijing China (void) ddi_prop_update_string(wscons.wc_dev, wc_dip, name, data); 16147c478bd9Sstevel@tonic-gate } 16157c478bd9Sstevel@tonic-gate 16167c478bd9Sstevel@tonic-gate /* 16177c478bd9Sstevel@tonic-gate * Gets the number of text rows and columns and the 16187c478bd9Sstevel@tonic-gate * width and height (in pixels) of the console. 16197c478bd9Sstevel@tonic-gate */ 1620*aecfc01dSrui zang - Sun Microsystems - Beijing China void 1621*aecfc01dSrui zang - Sun Microsystems - Beijing China wc_get_size(vc_state_t *pvc) 16227c478bd9Sstevel@tonic-gate { 1623*aecfc01dSrui zang - Sun Microsystems - Beijing China struct winsize *t = &pvc->vc_ttycommon.t_size; 1624fea9cb91Slq150181 ushort_t r = LOSCREENLINES, c = LOSCREENCOLS, x = 0, y = 0; 16257c478bd9Sstevel@tonic-gate 1626*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_tem != NULL) 1627*aecfc01dSrui zang - Sun Microsystems - Beijing China tem_get_size(&r, &c, &x, &y); 1628fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 1629*aecfc01dSrui zang - Sun Microsystems - Beijing China else 1630fea9cb91Slq150181 console_get_size(&r, &c, &x, &y); 1631fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 1632fea9cb91Slq150181 1633*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_ttycommon.t_excl); 1634*aecfc01dSrui zang - Sun Microsystems - Beijing China t->ws_col = c; 1635*aecfc01dSrui zang - Sun Microsystems - Beijing China t->ws_row = r; 1636*aecfc01dSrui zang - Sun Microsystems - Beijing China t->ws_xpixel = x; 1637*aecfc01dSrui zang - Sun Microsystems - Beijing China t->ws_ypixel = y; 1638*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_ttycommon.t_excl); 1639*aecfc01dSrui zang - Sun Microsystems - Beijing China 1640*aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_minor != 0) 1641*aecfc01dSrui zang - Sun Microsystems - Beijing China return; 1642*aecfc01dSrui zang - Sun Microsystems - Beijing China 1643*aecfc01dSrui zang - Sun Microsystems - Beijing China /* only for the wscons:0 */ 1644*aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(pvc, "screen-#cols", c); 1645*aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(pvc, "screen-#rows", r); 1646*aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(pvc, "screen-width", x); 1647*aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(pvc, "screen-height", y); 1648fea9cb91Slq150181 } 1649fea9cb91Slq150181 1650*aecfc01dSrui zang - Sun Microsystems - Beijing China /*ARGSUSED*/ 1651fea9cb91Slq150181 static void 1652fea9cb91Slq150181 wc_modechg_cb(tem_modechg_cb_arg_t arg) 1653fea9cb91Slq150181 { 1654*aecfc01dSrui zang - Sun Microsystems - Beijing China minor_t index; 1655*aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc; 1656*aecfc01dSrui zang - Sun Microsystems - Beijing China 1657*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 1658*aecfc01dSrui zang - Sun Microsystems - Beijing China for (index = 0; index < VC_INSTANCES_COUNT; index++) { 1659*aecfc01dSrui zang - Sun Microsystems - Beijing China pvc = vt_minor2vc(index); 1660*aecfc01dSrui zang - Sun Microsystems - Beijing China 1661*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1662*aecfc01dSrui zang - Sun Microsystems - Beijing China 1663*aecfc01dSrui zang - Sun Microsystems - Beijing China if ((pvc->vc_flags & WCS_ISOPEN) && 1664*aecfc01dSrui zang - Sun Microsystems - Beijing China (pvc->vc_flags & WCS_INIT)) 1665*aecfc01dSrui zang - Sun Microsystems - Beijing China wc_get_size(pvc); 1666*aecfc01dSrui zang - Sun Microsystems - Beijing China 1667*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1668*aecfc01dSrui zang - Sun Microsystems - Beijing China } 1669*aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 16707c478bd9Sstevel@tonic-gate } 1671