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 /* 23*ceeba6f9Srui zang - Sun Microsystems - Beijing China * Copyright (c) 1987, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * "Workstation console" multiplexor driver for Sun. 287c478bd9Sstevel@tonic-gate * 297c478bd9Sstevel@tonic-gate * Sends output to the primary frame buffer using the PROM monitor; 307c478bd9Sstevel@tonic-gate * gets input from a stream linked below us that is the "keyboard 317c478bd9Sstevel@tonic-gate * driver", below which is linked the primary keyboard. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 34aecfc01dSrui zang - Sun Microsystems - Beijing China /* 35aecfc01dSrui zang - Sun Microsystems - Beijing China * Locking Policy: 36aecfc01dSrui zang - Sun Microsystems - Beijing China * This module has a D_MTPERMOD inner perimeter which means STREAMS 37aecfc01dSrui zang - Sun Microsystems - Beijing China * only allows one thread to enter this module through STREAMS entry 38aecfc01dSrui zang - Sun Microsystems - Beijing China * points each time -- open() close() put() srv() qtimeout(). 39aecfc01dSrui zang - Sun Microsystems - Beijing China * So for the most time we do not need locking in this module, but with 40aecfc01dSrui zang - Sun Microsystems - Beijing China * the following exceptions: 41aecfc01dSrui zang - Sun Microsystems - Beijing China * 42*ceeba6f9Srui zang - Sun Microsystems - Beijing China * - wc shares three global variables (wc_dip, vc_active_console, 43*ceeba6f9Srui zang - Sun Microsystems - Beijing China * vc_cons_user, vc_avl_root) with virtual console devname part 44*ceeba6f9Srui zang - Sun Microsystems - Beijing China * (fs/dev/sdev_vtops.c) which get compiled into genunix. 45aecfc01dSrui zang - Sun Microsystems - Beijing China * 46aecfc01dSrui zang - Sun Microsystems - Beijing China * - wc_modechg_cb() is a callback function which will triggered when 47aecfc01dSrui zang - Sun Microsystems - Beijing China * framebuffer display mode is changed. 48aecfc01dSrui zang - Sun Microsystems - Beijing China * 49aecfc01dSrui zang - Sun Microsystems - Beijing China * - vt_send_hotkeys() is triggered by timeout() which is not STREAMS MT 50aecfc01dSrui zang - Sun Microsystems - Beijing China * safe. 51aecfc01dSrui zang - Sun Microsystems - Beijing China * 52aecfc01dSrui zang - Sun Microsystems - Beijing China * Based on the fact that virtual console devname part and wc_modechg_cb() 53*ceeba6f9Srui zang - Sun Microsystems - Beijing China * only do read access to the above mentioned shared four global variables, 54aecfc01dSrui zang - Sun Microsystems - Beijing China * It is safe to do locking this way: 55*ceeba6f9Srui zang - Sun Microsystems - Beijing China * 1) all read access to the four global variables in THIS WC MODULE do not 56aecfc01dSrui zang - Sun Microsystems - Beijing China * need locking; 57*ceeba6f9Srui zang - Sun Microsystems - Beijing China * 2) all write access to the four global variables in THIS WC MODULE must 58aecfc01dSrui zang - Sun Microsystems - Beijing China * hold vc_lock; 59*ceeba6f9Srui zang - Sun Microsystems - Beijing China * 3) any access to the four global variables in either DEVNAME PART or the 60aecfc01dSrui zang - Sun Microsystems - Beijing China * CALLBACK must hold vc_lock; 61aecfc01dSrui zang - Sun Microsystems - Beijing China * 4) other global variables which are only shared in this wc module and only 62aecfc01dSrui zang - Sun Microsystems - Beijing China * accessible through STREAMS entry points such as "vc_last_console", 63aecfc01dSrui zang - Sun Microsystems - Beijing China * "vc_inuse_max_minor", "vc_target_console" and "vc_waitactive_list" 64aecfc01dSrui zang - Sun Microsystems - Beijing China * do not need explict locking. 65aecfc01dSrui zang - Sun Microsystems - Beijing China * 66aecfc01dSrui zang - Sun Microsystems - Beijing China * wc_modechg_cb() does read access to vc_state_t::vc_flags, 67aecfc01dSrui zang - Sun Microsystems - Beijing China * vc_state_t::vc_state_lock is used to protect concurrently accesses to 68aecfc01dSrui zang - Sun Microsystems - Beijing China * vc_state_t::vc_flags which may happen from both through STREAMS entry 69aecfc01dSrui zang - Sun Microsystems - Beijing China * points and wc_modechg_cb(). 70aecfc01dSrui zang - Sun Microsystems - Beijing China * Since wc_modechg_cb() only does read access to vc_state_t::vc_flags, 71aecfc01dSrui zang - Sun Microsystems - Beijing China * The other parts of wc module (except wc_modechg_cb()) only has to hold 72aecfc01dSrui zang - Sun Microsystems - Beijing China * vc_state_t::vc_flags when writing to vc_state_t::vc_flags. 73aecfc01dSrui zang - Sun Microsystems - Beijing China * 74aecfc01dSrui zang - Sun Microsystems - Beijing China * vt_send_hotkeys() could access vt_pending_vtno at the same time with 75aecfc01dSrui zang - Sun Microsystems - Beijing China * the rest of wc module, vt_pending_vtno_lock is used to protect 76aecfc01dSrui zang - Sun Microsystems - Beijing China * vt_pending_vtno. 77aecfc01dSrui zang - Sun Microsystems - Beijing China * 78aecfc01dSrui zang - Sun Microsystems - Beijing China * Lock order: vc_lock -> vc_state_t::vc_state_lock. 79aecfc01dSrui zang - Sun Microsystems - Beijing China * No overlap between vc_lock and vt_pending_vtno_lock. 80aecfc01dSrui zang - Sun Microsystems - Beijing China */ 81aecfc01dSrui zang - Sun Microsystems - Beijing China 827c478bd9Sstevel@tonic-gate #include <sys/types.h> 837c478bd9Sstevel@tonic-gate #include <sys/param.h> 847c478bd9Sstevel@tonic-gate #include <sys/signal.h> 857c478bd9Sstevel@tonic-gate #include <sys/cred.h> 867c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 877c478bd9Sstevel@tonic-gate #include <sys/termios.h> 887c478bd9Sstevel@tonic-gate #include <sys/termio.h> 897c478bd9Sstevel@tonic-gate #include <sys/ttold.h> 907c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 917c478bd9Sstevel@tonic-gate #include <sys/stream.h> 927c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 937c478bd9Sstevel@tonic-gate #include <sys/tty.h> 947c478bd9Sstevel@tonic-gate #include <sys/buf.h> 957c478bd9Sstevel@tonic-gate #include <sys/uio.h> 967c478bd9Sstevel@tonic-gate #include <sys/stat.h> 97aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/sysmacros.h> 98aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/errno.h> 99aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/proc.h> 100aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/procset.h> 101aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/fault.h> 102aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/siginfo.h> 103aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/debug.h> 104aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/session.h> 1057c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 1067c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 1077c478bd9Sstevel@tonic-gate #include <sys/kbio.h> 1087c478bd9Sstevel@tonic-gate #include <sys/strredir.h> 1097c478bd9Sstevel@tonic-gate #include <sys/fs/snode.h> 1107c478bd9Sstevel@tonic-gate #include <sys/consdev.h> 1117c478bd9Sstevel@tonic-gate #include <sys/conf.h> 112aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/cmn_err.h> 113aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/console.h> 114aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/promif.h> 115aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/note.h> 116aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/polled_io.h> 117aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/systm.h> 1187c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 1197c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 120aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/sunndi.h> 121aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/esunddi.h> 122aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/sunldi.h> 1237c478bd9Sstevel@tonic-gate #include <sys/debug.h> 1247c478bd9Sstevel@tonic-gate #include <sys/console.h> 1257c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 1267c478bd9Sstevel@tonic-gate #include <sys/policy.h> 127aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/modctl.h> 128fea9cb91Slq150181 #include <sys/tem.h> 129fea9cb91Slq150181 #include <sys/wscons.h> 130aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/vt_impl.h> 131aecfc01dSrui zang - Sun Microsystems - Beijing China 132aecfc01dSrui zang - Sun Microsystems - Beijing China /* streams stuff */ 133aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", copyreq)) 134aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", copyresp)) 135aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", datab)) 136aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", iocblk)) 137aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", msgb)) 138aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("Unshared data", queue)) 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate #define MINLINES 10 1417c478bd9Sstevel@tonic-gate #define MAXLINES 48 1427c478bd9Sstevel@tonic-gate #define LOSCREENLINES 34 1437c478bd9Sstevel@tonic-gate #define HISCREENLINES 48 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate #define MINCOLS 10 1467c478bd9Sstevel@tonic-gate #define MAXCOLS 120 1477c478bd9Sstevel@tonic-gate #define LOSCREENCOLS 80 1487c478bd9Sstevel@tonic-gate #define HISCREENCOLS 120 1497c478bd9Sstevel@tonic-gate 150aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state { 1517c478bd9Sstevel@tonic-gate dev_t wc_dev; /* major/minor for this device */ 152fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 1537c478bd9Sstevel@tonic-gate int wc_defer_output; /* set if output device is "slow" */ 154fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 1557c478bd9Sstevel@tonic-gate queue_t *wc_kbdqueue; /* "console keyboard" device queue */ 1567c478bd9Sstevel@tonic-gate /* below us */ 1577c478bd9Sstevel@tonic-gate cons_polledio_t wc_polledio; /* polled I/O function pointers */ 1587c478bd9Sstevel@tonic-gate cons_polledio_t *wc_kb_polledio; /* keyboard's polledio */ 1597c478bd9Sstevel@tonic-gate unsigned int wc_kb_getpolledio_id; /* id for kb CONSOPENPOLLEDIO */ 160aecfc01dSrui zang - Sun Microsystems - Beijing China queue_t *wc_pending_wq; 1617c478bd9Sstevel@tonic-gate mblk_t *wc_pending_link; /* I_PLINK pending for kb polledio */ 1627c478bd9Sstevel@tonic-gate } wscons; 1637c478bd9Sstevel@tonic-gate 164aecfc01dSrui zang - Sun Microsystems - Beijing China /* 165aecfc01dSrui zang - Sun Microsystems - Beijing China * This module has a D_MTPERMOD inner perimeter, so we don't need to protect 166aecfc01dSrui zang - Sun Microsystems - Beijing China * the variables only shared within this module 167aecfc01dSrui zang - Sun Microsystems - Beijing China */ 168aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", wscons)) 169aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", wscons_state)) 170aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_stat)) 171aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vc_waitactive_msg)) 172aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", tty_common)) 173aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_mode)) 174aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vt_dispinfo)) 175aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", winsize)) 176aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", vc_last_console)) 177aecfc01dSrui zang - Sun Microsystems - Beijing China 178aecfc01dSrui zang - Sun Microsystems - Beijing China #ifdef _HAVE_TEM_FIRMWARE 179aecfc01dSrui zang - Sun Microsystems - Beijing China ssize_t wc_cons_wrtvec(promif_redir_arg_t arg, uchar_t *s, size_t n); 180aecfc01dSrui zang - Sun Microsystems - Beijing China #endif /* _HAVE_TEM_FIRMWARE */ 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate static int wcopen(queue_t *, dev_t *, int, int, cred_t *); 1837c478bd9Sstevel@tonic-gate static int wcclose(queue_t *, int, cred_t *); 1847c478bd9Sstevel@tonic-gate static int wcuwput(queue_t *, mblk_t *); 1857c478bd9Sstevel@tonic-gate static int wclrput(queue_t *, mblk_t *); 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate static struct module_info wcm_info = { 1887c478bd9Sstevel@tonic-gate 0, 1897c478bd9Sstevel@tonic-gate "wc", 1907c478bd9Sstevel@tonic-gate 0, 1917c478bd9Sstevel@tonic-gate INFPSZ, 1927c478bd9Sstevel@tonic-gate 2048, 1937c478bd9Sstevel@tonic-gate 128 1947c478bd9Sstevel@tonic-gate }; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate static struct qinit wcurinit = { 1977c478bd9Sstevel@tonic-gate putq, 1987c478bd9Sstevel@tonic-gate NULL, 1997c478bd9Sstevel@tonic-gate wcopen, 2007c478bd9Sstevel@tonic-gate wcclose, 2017c478bd9Sstevel@tonic-gate NULL, 2027c478bd9Sstevel@tonic-gate &wcm_info, 2037c478bd9Sstevel@tonic-gate NULL 2047c478bd9Sstevel@tonic-gate }; 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate static struct qinit wcuwinit = { 2077c478bd9Sstevel@tonic-gate wcuwput, 2087c478bd9Sstevel@tonic-gate NULL, 2097c478bd9Sstevel@tonic-gate wcopen, 2107c478bd9Sstevel@tonic-gate wcclose, 2117c478bd9Sstevel@tonic-gate NULL, 2127c478bd9Sstevel@tonic-gate &wcm_info, 2137c478bd9Sstevel@tonic-gate NULL 2147c478bd9Sstevel@tonic-gate }; 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate static struct qinit wclrinit = { 2177c478bd9Sstevel@tonic-gate wclrput, 2187c478bd9Sstevel@tonic-gate NULL, 2197c478bd9Sstevel@tonic-gate NULL, 2207c478bd9Sstevel@tonic-gate NULL, 2217c478bd9Sstevel@tonic-gate NULL, 2227c478bd9Sstevel@tonic-gate &wcm_info, 2237c478bd9Sstevel@tonic-gate NULL 2247c478bd9Sstevel@tonic-gate }; 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* 2277c478bd9Sstevel@tonic-gate * We always putnext directly to the underlying queue. 2287c478bd9Sstevel@tonic-gate */ 2297c478bd9Sstevel@tonic-gate static struct qinit wclwinit = { 2307c478bd9Sstevel@tonic-gate NULL, 2317c478bd9Sstevel@tonic-gate NULL, 2327c478bd9Sstevel@tonic-gate NULL, 2337c478bd9Sstevel@tonic-gate NULL, 2347c478bd9Sstevel@tonic-gate NULL, 2357c478bd9Sstevel@tonic-gate &wcm_info, 2367c478bd9Sstevel@tonic-gate NULL 2377c478bd9Sstevel@tonic-gate }; 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate static struct streamtab wcinfo = { 2407c478bd9Sstevel@tonic-gate &wcurinit, 2417c478bd9Sstevel@tonic-gate &wcuwinit, 2427c478bd9Sstevel@tonic-gate &wclrinit, 2437c478bd9Sstevel@tonic-gate &wclwinit, 2447c478bd9Sstevel@tonic-gate }; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate static int wc_info(dev_info_t *, ddi_info_cmd_t, void *, void **result); 2477c478bd9Sstevel@tonic-gate static int wc_attach(dev_info_t *, ddi_attach_cmd_t); 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(wc_ops, nulldev, nulldev, wc_attach, nodev, nodev, 25019397407SSherry Moore wc_info, D_MTPERMOD | D_MP, &wcinfo, ddi_quiesce_not_supported); 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate static void wcreioctl(void *); 2537c478bd9Sstevel@tonic-gate static void wcioctl(queue_t *, mblk_t *); 254fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 2557c478bd9Sstevel@tonic-gate static void wcopoll(void *); 2567c478bd9Sstevel@tonic-gate static void wconsout(void *); 257fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 2587c478bd9Sstevel@tonic-gate static void wcrstrt(void *); 259aecfc01dSrui zang - Sun Microsystems - Beijing China static void wcstart(void *); 260aecfc01dSrui zang - Sun Microsystems - Beijing China static void wc_open_kb_polledio(struct wscons_state *wc, queue_t *q, 261aecfc01dSrui zang - Sun Microsystems - Beijing China mblk_t *mp); 262aecfc01dSrui zang - Sun Microsystems - Beijing China static void wc_close_kb_polledio(struct wscons_state *wc, queue_t *q, 263aecfc01dSrui zang - Sun Microsystems - Beijing China mblk_t *mp); 264aecfc01dSrui zang - Sun Microsystems - Beijing China static void wc_polled_putchar(cons_polledio_arg_t arg, 265aecfc01dSrui zang - Sun Microsystems - Beijing China unsigned char c); 266281f0747Slt200341 static boolean_t wc_polled_ischar(cons_polledio_arg_t arg); 267281f0747Slt200341 static int wc_polled_getchar(cons_polledio_arg_t arg); 268281f0747Slt200341 static void wc_polled_enter(cons_polledio_arg_t arg); 269281f0747Slt200341 static void wc_polled_exit(cons_polledio_arg_t arg); 270aecfc01dSrui zang - Sun Microsystems - Beijing China void wc_get_size(vc_state_t *pvc); 271fea9cb91Slq150181 static void wc_modechg_cb(tem_modechg_cb_arg_t arg); 2727c478bd9Sstevel@tonic-gate 2737c478bd9Sstevel@tonic-gate static struct dev_ops wc_ops; 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate /* 2767c478bd9Sstevel@tonic-gate * Debug printing 2777c478bd9Sstevel@tonic-gate */ 2787c478bd9Sstevel@tonic-gate #ifndef DPRINTF 2797c478bd9Sstevel@tonic-gate #ifdef DEBUG 2807c478bd9Sstevel@tonic-gate /*PRINTFLIKE1*/ 2817c478bd9Sstevel@tonic-gate static void wc_dprintf(const char *fmt, ...) __KPRINTFLIKE(1); 2827c478bd9Sstevel@tonic-gate #define DPRINTF(l, m, args) \ 2837c478bd9Sstevel@tonic-gate (((l) >= wc_errlevel) && ((m) & wc_errmask) ? \ 2847c478bd9Sstevel@tonic-gate wc_dprintf args : \ 2857c478bd9Sstevel@tonic-gate (void) 0) 2867c478bd9Sstevel@tonic-gate /* 2877c478bd9Sstevel@tonic-gate * Severity levels for printing 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate #define PRINT_L0 0 /* print every message */ 2907c478bd9Sstevel@tonic-gate #define PRINT_L1 1 /* debug */ 2917c478bd9Sstevel@tonic-gate #define PRINT_L2 2 /* quiet */ 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate /* 2947c478bd9Sstevel@tonic-gate * Masks 2957c478bd9Sstevel@tonic-gate */ 2967c478bd9Sstevel@tonic-gate #define PRINT_MASK_ALL 0xFFFFFFFFU 2977c478bd9Sstevel@tonic-gate uint_t wc_errmask = PRINT_MASK_ALL; 2987c478bd9Sstevel@tonic-gate uint_t wc_errlevel = PRINT_L2; 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate #else 3017c478bd9Sstevel@tonic-gate #define DPRINTF(l, m, args) /* NOTHING */ 3027c478bd9Sstevel@tonic-gate #endif 3037c478bd9Sstevel@tonic-gate #endif 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate /* 3067c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 3077c478bd9Sstevel@tonic-gate */ 3087c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 3097c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a pseudo driver */ 31019397407SSherry Moore "Workstation multiplexer Driver 'wc'", 3117c478bd9Sstevel@tonic-gate &wc_ops, /* driver ops */ 3127c478bd9Sstevel@tonic-gate }; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 3157c478bd9Sstevel@tonic-gate MODREV_1, 3167c478bd9Sstevel@tonic-gate &modldrv, 3177c478bd9Sstevel@tonic-gate NULL 3187c478bd9Sstevel@tonic-gate }; 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate int 3217c478bd9Sstevel@tonic-gate _init(void) 3227c478bd9Sstevel@tonic-gate { 323aecfc01dSrui zang - Sun Microsystems - Beijing China int rc; 324aecfc01dSrui zang - Sun Microsystems - Beijing China if ((rc = mod_install(&modlinkage)) == 0) 325aecfc01dSrui zang - Sun Microsystems - Beijing China vt_init(); 326aecfc01dSrui zang - Sun Microsystems - Beijing China return (rc); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate int 3307c478bd9Sstevel@tonic-gate _fini(void) 3317c478bd9Sstevel@tonic-gate { 3327c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 3337c478bd9Sstevel@tonic-gate } 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate int 3367c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 3377c478bd9Sstevel@tonic-gate { 3387c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 3397c478bd9Sstevel@tonic-gate } 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3427c478bd9Sstevel@tonic-gate static int 3437c478bd9Sstevel@tonic-gate wc_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 3447c478bd9Sstevel@tonic-gate { 345aecfc01dSrui zang - Sun Microsystems - Beijing China /* create minor node for workstation hard console */ 3467c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(devi, "wscons", S_IFCHR, 3477c478bd9Sstevel@tonic-gate 0, DDI_PSEUDO, NULL) == DDI_FAILURE) { 3487c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 349aecfc01dSrui zang - Sun Microsystems - Beijing China return (DDI_FAILURE); 3507c478bd9Sstevel@tonic-gate } 351aecfc01dSrui zang - Sun Microsystems - Beijing China 352aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 353aecfc01dSrui zang - Sun Microsystems - Beijing China 3547c478bd9Sstevel@tonic-gate wc_dip = devi; 355fea9cb91Slq150181 356fea9cb91Slq150181 bzero(&(wscons.wc_polledio), sizeof (wscons.wc_polledio)); 357fea9cb91Slq150181 358aecfc01dSrui zang - Sun Microsystems - Beijing China vt_resize(VC_DEFAULT_COUNT); 359aecfc01dSrui zang - Sun Microsystems - Beijing China 360aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 361aecfc01dSrui zang - Sun Microsystems - Beijing China 3627c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 3637c478bd9Sstevel@tonic-gate } 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate /* ARGSUSED */ 3667c478bd9Sstevel@tonic-gate static int 3677c478bd9Sstevel@tonic-gate wc_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, 3687c478bd9Sstevel@tonic-gate void **result) 3697c478bd9Sstevel@tonic-gate { 3707c478bd9Sstevel@tonic-gate int error; 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate switch (infocmd) { 3737c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 3747c478bd9Sstevel@tonic-gate if (wc_dip == NULL) { 3757c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 3767c478bd9Sstevel@tonic-gate } else { 3777c478bd9Sstevel@tonic-gate *result = (void *) wc_dip; 3787c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate break; 3817c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 3827c478bd9Sstevel@tonic-gate *result = (void *)0; 3837c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 3847c478bd9Sstevel@tonic-gate break; 3857c478bd9Sstevel@tonic-gate default: 3867c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate return (error); 3897c478bd9Sstevel@tonic-gate } 3907c478bd9Sstevel@tonic-gate 391fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 3927c478bd9Sstevel@tonic-gate /* 3937c478bd9Sstevel@tonic-gate * Output buffer. Protected by the per-module inner perimeter. 3947c478bd9Sstevel@tonic-gate */ 3957c478bd9Sstevel@tonic-gate #define MAXHIWAT 2000 3967c478bd9Sstevel@tonic-gate static char obuf[MAXHIWAT]; 397fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 3987c478bd9Sstevel@tonic-gate 399aecfc01dSrui zang - Sun Microsystems - Beijing China static void 400aecfc01dSrui zang - Sun Microsystems - Beijing China wc_init_polledio(void) 4017c478bd9Sstevel@tonic-gate { 402fea9cb91Slq150181 static boolean_t polledio_inited = B_FALSE; 403aecfc01dSrui zang - Sun Microsystems - Beijing China _NOTE(SCHEME_PROTECTS_DATA("D_MTPERMOD protected data", 404aecfc01dSrui zang - Sun Microsystems - Beijing China polledio_inited)) 4057c478bd9Sstevel@tonic-gate 406aecfc01dSrui zang - Sun Microsystems - Beijing China if (polledio_inited) 407aecfc01dSrui zang - Sun Microsystems - Beijing China return; 4087c478bd9Sstevel@tonic-gate 409fea9cb91Slq150181 polledio_inited = B_TRUE; 410fea9cb91Slq150181 411fea9cb91Slq150181 /* 412fea9cb91Slq150181 * Initialize the parts of the polled I/O struct that 413fea9cb91Slq150181 * are common to both input and output modes, but which 414fea9cb91Slq150181 * don't flag to the upper layers, which if any of the 415fea9cb91Slq150181 * two modes are available. We don't know at this point 416fea9cb91Slq150181 * if system is configured CONS_KFB, but we will when 417fea9cb91Slq150181 * consconfig_dacf asks us with CONSOPENPOLLED I/O. 418fea9cb91Slq150181 */ 419aecfc01dSrui zang - Sun Microsystems - Beijing China bzero(&(wscons.wc_polledio), sizeof (wscons.wc_polledio)); 420fea9cb91Slq150181 wscons.wc_polledio.cons_polledio_version = 421fea9cb91Slq150181 CONSPOLLEDIO_V0; 4227c478bd9Sstevel@tonic-gate wscons.wc_polledio.cons_polledio_argument = 423281f0747Slt200341 (cons_polledio_arg_t)&wscons; 424fea9cb91Slq150181 wscons.wc_polledio.cons_polledio_enter = 425fea9cb91Slq150181 wc_polled_enter; 426fea9cb91Slq150181 wscons.wc_polledio.cons_polledio_exit = 427fea9cb91Slq150181 wc_polled_exit; 4287c478bd9Sstevel@tonic-gate 429fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 4307c478bd9Sstevel@tonic-gate /* 4317c478bd9Sstevel@tonic-gate * If we're talking directly to a framebuffer, we assume 432fea9cb91Slq150181 * that it's a "slow" device, so that rendering should 433fea9cb91Slq150181 * be deferred to a timeout or softcall so that we write 4347c478bd9Sstevel@tonic-gate * a bunch of characters at once. 4357c478bd9Sstevel@tonic-gate */ 4367c478bd9Sstevel@tonic-gate wscons.wc_defer_output = prom_stdout_is_framebuffer(); 437fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 438fea9cb91Slq150181 } 4397c478bd9Sstevel@tonic-gate 440aecfc01dSrui zang - Sun Microsystems - Beijing China /*ARGSUSED*/ 441aecfc01dSrui zang - Sun Microsystems - Beijing China static int 442aecfc01dSrui zang - Sun Microsystems - Beijing China wcopen(queue_t *q, dev_t *devp, int flag, int sflag, cred_t *crp) 443aecfc01dSrui zang - Sun Microsystems - Beijing China { 444aecfc01dSrui zang - Sun Microsystems - Beijing China int minor; 445aecfc01dSrui zang - Sun Microsystems - Beijing China 446aecfc01dSrui zang - Sun Microsystems - Beijing China wc_init_polledio(); 447aecfc01dSrui zang - Sun Microsystems - Beijing China minor = (int)getminor(*devp); 448aecfc01dSrui zang - Sun Microsystems - Beijing China return (vt_open(minor, q, crp)); 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4527c478bd9Sstevel@tonic-gate static int 4537c478bd9Sstevel@tonic-gate wcclose(queue_t *q, int flag, cred_t *crp) 4547c478bd9Sstevel@tonic-gate { 455aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)q->q_ptr; 456aecfc01dSrui zang - Sun Microsystems - Beijing China 4577c478bd9Sstevel@tonic-gate qprocsoff(q); 458aecfc01dSrui zang - Sun Microsystems - Beijing China 459aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 460aecfc01dSrui zang - Sun Microsystems - Beijing China 461*ceeba6f9Srui zang - Sun Microsystems - Beijing China /* 462*ceeba6f9Srui zang - Sun Microsystems - Beijing China * If we are closing the VT node which 463*ceeba6f9Srui zang - Sun Microsystems - Beijing China * /dev/vt/console_user points to, revert 464*ceeba6f9Srui zang - Sun Microsystems - Beijing China * /dev/vt/console to /dev/console 465*ceeba6f9Srui zang - Sun Microsystems - Beijing China */ 466*ceeba6f9Srui zang - Sun Microsystems - Beijing China if (vc_cons_user == pvc->vc_minor) 467*ceeba6f9Srui zang - Sun Microsystems - Beijing China vc_cons_user = VT_MINOR_INVALID; 468*ceeba6f9Srui zang - Sun Microsystems - Beijing China 469aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_minor == 0 || pvc->vc_minor == vc_active_console) { 470aecfc01dSrui zang - Sun Microsystems - Beijing China 471aecfc01dSrui zang - Sun Microsystems - Beijing China /* 472aecfc01dSrui zang - Sun Microsystems - Beijing China * If we lose the system console, 473aecfc01dSrui zang - Sun Microsystems - Beijing China * no any other active consoles. 474aecfc01dSrui zang - Sun Microsystems - Beijing China */ 475aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_minor == 0 && pvc->vc_minor == vc_active_console) { 476aecfc01dSrui zang - Sun Microsystems - Beijing China vc_active_console = VT_MINOR_INVALID; 477aecfc01dSrui zang - Sun Microsystems - Beijing China vc_last_console = VT_MINOR_INVALID; 4787c478bd9Sstevel@tonic-gate } 479aecfc01dSrui zang - Sun Microsystems - Beijing China 480aecfc01dSrui zang - Sun Microsystems - Beijing China /* 481aecfc01dSrui zang - Sun Microsystems - Beijing China * just clean for our primary console 482aecfc01dSrui zang - Sun Microsystems - Beijing China * and active console 483aecfc01dSrui zang - Sun Microsystems - Beijing China */ 484aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 485aecfc01dSrui zang - Sun Microsystems - Beijing China vt_clean(q, pvc); 486aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 487aecfc01dSrui zang - Sun Microsystems - Beijing China 488aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 489aecfc01dSrui zang - Sun Microsystems - Beijing China 490aecfc01dSrui zang - Sun Microsystems - Beijing China return (0); 4917c478bd9Sstevel@tonic-gate } 492aecfc01dSrui zang - Sun Microsystems - Beijing China vt_close(q, pvc, crp); 493aecfc01dSrui zang - Sun Microsystems - Beijing China 494aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 495aecfc01dSrui zang - Sun Microsystems - Beijing China 4967c478bd9Sstevel@tonic-gate return (0); 4977c478bd9Sstevel@tonic-gate } 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate /* 5007c478bd9Sstevel@tonic-gate * Put procedure for upper write queue. 5017c478bd9Sstevel@tonic-gate * Respond to M_STOP, M_START, M_IOCTL, and M_FLUSH messages here; 5027c478bd9Sstevel@tonic-gate * queue up M_BREAK, M_DELAY, and M_DATA messages for processing by 5037c478bd9Sstevel@tonic-gate * the start routine, and then call the start routine; discard 5047c478bd9Sstevel@tonic-gate * everything else. 5057c478bd9Sstevel@tonic-gate */ 5067c478bd9Sstevel@tonic-gate static int 5077c478bd9Sstevel@tonic-gate wcuwput(queue_t *q, mblk_t *mp) 5087c478bd9Sstevel@tonic-gate { 509aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)q->q_ptr; 510aecfc01dSrui zang - Sun Microsystems - Beijing China 5117c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) { 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate case M_STOP: 514aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 515aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags |= WCS_STOPPED; 516aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 517aecfc01dSrui zang - Sun Microsystems - Beijing China 5187c478bd9Sstevel@tonic-gate freemsg(mp); 5197c478bd9Sstevel@tonic-gate break; 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate case M_START: 522aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 523aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags &= ~WCS_STOPPED; 524aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 525aecfc01dSrui zang - Sun Microsystems - Beijing China 526aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 5277c478bd9Sstevel@tonic-gate freemsg(mp); 5287c478bd9Sstevel@tonic-gate break; 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate case M_IOCTL: { 5317c478bd9Sstevel@tonic-gate struct iocblk *iocp; 5327c478bd9Sstevel@tonic-gate struct linkblk *linkp; 5337c478bd9Sstevel@tonic-gate 534aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 5357c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) { 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate case I_LINK: /* stupid, but permitted */ 5387c478bd9Sstevel@tonic-gate case I_PLINK: 5397c478bd9Sstevel@tonic-gate if (wscons.wc_kbdqueue != NULL) { 5407c478bd9Sstevel@tonic-gate /* somebody already linked */ 5417c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL); 5427c478bd9Sstevel@tonic-gate return (0); 5437c478bd9Sstevel@tonic-gate } 544aecfc01dSrui zang - Sun Microsystems - Beijing China linkp = (struct linkblk *)(void *)mp->b_cont->b_rptr; 5457c478bd9Sstevel@tonic-gate wscons.wc_kbdqueue = WR(linkp->l_qbot); 5467c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 5477c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; 5487c478bd9Sstevel@tonic-gate wc_open_kb_polledio(&wscons, q, mp); 5497c478bd9Sstevel@tonic-gate break; 5507c478bd9Sstevel@tonic-gate 5517c478bd9Sstevel@tonic-gate case I_UNLINK: /* stupid, but permitted */ 5527c478bd9Sstevel@tonic-gate case I_PUNLINK: 553aecfc01dSrui zang - Sun Microsystems - Beijing China linkp = (struct linkblk *)(void *)mp->b_cont->b_rptr; 5547c478bd9Sstevel@tonic-gate if (wscons.wc_kbdqueue != WR(linkp->l_qbot)) { 5557c478bd9Sstevel@tonic-gate /* not us */ 5567c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, EINVAL); 5577c478bd9Sstevel@tonic-gate return (0); 5587c478bd9Sstevel@tonic-gate } 5597c478bd9Sstevel@tonic-gate 5607c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 5617c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; 5627c478bd9Sstevel@tonic-gate wc_close_kb_polledio(&wscons, q, mp); 5637c478bd9Sstevel@tonic-gate break; 5647c478bd9Sstevel@tonic-gate 5657c478bd9Sstevel@tonic-gate case TCSETSW: 5667c478bd9Sstevel@tonic-gate case TCSETSF: 5677c478bd9Sstevel@tonic-gate case TCSETAW: 5687c478bd9Sstevel@tonic-gate case TCSETAF: 5697c478bd9Sstevel@tonic-gate case TCSBRK: 5707c478bd9Sstevel@tonic-gate /* 5717c478bd9Sstevel@tonic-gate * The changes do not take effect until all 5727c478bd9Sstevel@tonic-gate * output queued before them is drained. 5737c478bd9Sstevel@tonic-gate * Put this message on the queue, so that 5747c478bd9Sstevel@tonic-gate * "wcstart" will see it when it's done 5757c478bd9Sstevel@tonic-gate * with the output before it. Poke the 5767c478bd9Sstevel@tonic-gate * start routine, just in case. 5777c478bd9Sstevel@tonic-gate */ 5787c478bd9Sstevel@tonic-gate (void) putq(q, mp); 579aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 5807c478bd9Sstevel@tonic-gate break; 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate case CONSSETABORTENABLE: 5837c478bd9Sstevel@tonic-gate case CONSGETABORTENABLE: 5847c478bd9Sstevel@tonic-gate case KIOCSDIRECT: 5857c478bd9Sstevel@tonic-gate if (wscons.wc_kbdqueue != NULL) { 586aecfc01dSrui zang - Sun Microsystems - Beijing China wscons.wc_pending_wq = q; 5877c478bd9Sstevel@tonic-gate (void) putnext(wscons.wc_kbdqueue, mp); 5887c478bd9Sstevel@tonic-gate break; 5897c478bd9Sstevel@tonic-gate } 5907c478bd9Sstevel@tonic-gate /* fall through */ 5917c478bd9Sstevel@tonic-gate 5927c478bd9Sstevel@tonic-gate default: 5937c478bd9Sstevel@tonic-gate /* 5947c478bd9Sstevel@tonic-gate * Do it now. 5957c478bd9Sstevel@tonic-gate */ 5967c478bd9Sstevel@tonic-gate wcioctl(q, mp); 5977c478bd9Sstevel@tonic-gate break; 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate break; 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate case M_FLUSH: 6037c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) { 6047c478bd9Sstevel@tonic-gate /* 6057c478bd9Sstevel@tonic-gate * Flush our write queue. 6067c478bd9Sstevel@tonic-gate */ 6077c478bd9Sstevel@tonic-gate flushq(q, FLUSHDATA); /* XXX doesn't flush M_DELAY */ 6087c478bd9Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHW; /* it has been flushed */ 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) { 6117c478bd9Sstevel@tonic-gate flushq(RD(q), FLUSHDATA); 6127c478bd9Sstevel@tonic-gate qreply(q, mp); /* give the read queues a crack at it */ 6137c478bd9Sstevel@tonic-gate } else 6147c478bd9Sstevel@tonic-gate freemsg(mp); 6157c478bd9Sstevel@tonic-gate break; 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate case M_BREAK: 6187c478bd9Sstevel@tonic-gate /* 6197c478bd9Sstevel@tonic-gate * Ignore these, as they make no sense. 6207c478bd9Sstevel@tonic-gate */ 6217c478bd9Sstevel@tonic-gate freemsg(mp); 6227c478bd9Sstevel@tonic-gate break; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate case M_DELAY: 6257c478bd9Sstevel@tonic-gate case M_DATA: 6267c478bd9Sstevel@tonic-gate /* 6277c478bd9Sstevel@tonic-gate * Queue the message up to be transmitted, 6287c478bd9Sstevel@tonic-gate * and poke the start routine. 6297c478bd9Sstevel@tonic-gate */ 6307c478bd9Sstevel@tonic-gate (void) putq(q, mp); 631aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 632aecfc01dSrui zang - Sun Microsystems - Beijing China break; 633aecfc01dSrui zang - Sun Microsystems - Beijing China 634aecfc01dSrui zang - Sun Microsystems - Beijing China case M_IOCDATA: 635aecfc01dSrui zang - Sun Microsystems - Beijing China vt_miocdata(q, mp); 6367c478bd9Sstevel@tonic-gate break; 6377c478bd9Sstevel@tonic-gate 6387c478bd9Sstevel@tonic-gate default: 6397c478bd9Sstevel@tonic-gate /* 6407c478bd9Sstevel@tonic-gate * "No, I don't want a subscription to Chain Store Age, 6417c478bd9Sstevel@tonic-gate * thank you anyway." 6427c478bd9Sstevel@tonic-gate */ 6437c478bd9Sstevel@tonic-gate freemsg(mp); 6447c478bd9Sstevel@tonic-gate break; 6457c478bd9Sstevel@tonic-gate } 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate return (0); 6487c478bd9Sstevel@tonic-gate } 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate /* 6517c478bd9Sstevel@tonic-gate * Retry an "ioctl", now that "qbufcall" claims we may be able to allocate 6527c478bd9Sstevel@tonic-gate * the buffer we need. 6537c478bd9Sstevel@tonic-gate */ 6547c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6557c478bd9Sstevel@tonic-gate static void 6567c478bd9Sstevel@tonic-gate wcreioctl(void *arg) 6577c478bd9Sstevel@tonic-gate { 658aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 6597c478bd9Sstevel@tonic-gate queue_t *q; 6607c478bd9Sstevel@tonic-gate mblk_t *mp; 6617c478bd9Sstevel@tonic-gate 662aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_bufcallid = 0; 663aecfc01dSrui zang - Sun Microsystems - Beijing China q = pvc->vc_ttycommon.t_writeq; 664aecfc01dSrui zang - Sun Microsystems - Beijing China if ((mp = pvc->vc_ttycommon.t_iocpending) != NULL) { 6657c478bd9Sstevel@tonic-gate /* not pending any more */ 666aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_ttycommon.t_iocpending = NULL; 6677c478bd9Sstevel@tonic-gate wcioctl(q, mp); 6687c478bd9Sstevel@tonic-gate } 6697c478bd9Sstevel@tonic-gate } 6707c478bd9Sstevel@tonic-gate 671fea9cb91Slq150181 static int 672fea9cb91Slq150181 wc_getterm(mblk_t *mp) 673fea9cb91Slq150181 { 674fea9cb91Slq150181 char *term; 675fea9cb91Slq150181 intptr_t arg; 67622eb7cb5Sgd78059 int flag = ((struct iocblk *)(void *)mp->b_rptr)->ioc_flag; 677fea9cb91Slq150181 678fea9cb91Slq150181 STRUCT_DECL(cons_getterm, wcterm); 679fea9cb91Slq150181 STRUCT_INIT(wcterm, flag); 680fea9cb91Slq150181 68122eb7cb5Sgd78059 arg = *((intptr_t *)(void *)mp->b_cont->b_rptr); 682fea9cb91Slq150181 683fea9cb91Slq150181 if (ddi_copyin((void *)arg, STRUCT_BUF(wcterm), 684fea9cb91Slq150181 STRUCT_SIZE(wcterm), flag) != 0) { 685fea9cb91Slq150181 return (EFAULT); 686fea9cb91Slq150181 } 687fea9cb91Slq150181 688fea9cb91Slq150181 if (consmode == CONS_FW) { 689fea9cb91Slq150181 /* PROM terminal emulator */ 690fea9cb91Slq150181 term = "sun"; 691fea9cb91Slq150181 } else { 692fea9cb91Slq150181 /* Kernel terminal emulator */ 693fea9cb91Slq150181 ASSERT(consmode == CONS_KFB); 694fea9cb91Slq150181 term = "sun-color"; 695fea9cb91Slq150181 } 696fea9cb91Slq150181 697fea9cb91Slq150181 if (STRUCT_FGET(wcterm, cn_term_len) < 698fea9cb91Slq150181 strlen(term) + 1) { 699fea9cb91Slq150181 return (EOVERFLOW); 700fea9cb91Slq150181 } 701fea9cb91Slq150181 702fea9cb91Slq150181 if (ddi_copyout(term, 703fea9cb91Slq150181 STRUCT_FGETP(wcterm, cn_term_type), 704fea9cb91Slq150181 strlen(term) + 1, flag) != 0) { 705fea9cb91Slq150181 return (EFAULT); 706fea9cb91Slq150181 } 707fea9cb91Slq150181 708fea9cb91Slq150181 return (0); 709fea9cb91Slq150181 } 710fea9cb91Slq150181 7117c478bd9Sstevel@tonic-gate /* 7127c478bd9Sstevel@tonic-gate * Process an "ioctl" message sent down to us. 7137c478bd9Sstevel@tonic-gate */ 7147c478bd9Sstevel@tonic-gate static void 7157c478bd9Sstevel@tonic-gate wcioctl(queue_t *q, mblk_t *mp) 7167c478bd9Sstevel@tonic-gate { 717aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)q->q_ptr; 7187c478bd9Sstevel@tonic-gate struct iocblk *iocp; 7197c478bd9Sstevel@tonic-gate size_t datasize; 7207c478bd9Sstevel@tonic-gate int error; 721fea9cb91Slq150181 long len; 7227c478bd9Sstevel@tonic-gate 723aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 724aecfc01dSrui zang - Sun Microsystems - Beijing China 725aecfc01dSrui zang - Sun Microsystems - Beijing China if ((iocp->ioc_cmd & VTIOC) == VTIOC || 726aecfc01dSrui zang - Sun Microsystems - Beijing China (iocp->ioc_cmd & KDIOC) == KDIOC) { 727aecfc01dSrui zang - Sun Microsystems - Beijing China vt_ioctl(q, mp); 728aecfc01dSrui zang - Sun Microsystems - Beijing China return; 729aecfc01dSrui zang - Sun Microsystems - Beijing China } 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) { 7327c478bd9Sstevel@tonic-gate case TIOCSWINSZ: 7337c478bd9Sstevel@tonic-gate /* 7347c478bd9Sstevel@tonic-gate * Ignore all attempts to set the screen size; the 7357c478bd9Sstevel@tonic-gate * value in the EEPROM is guaranteed (modulo PROM bugs) 7367c478bd9Sstevel@tonic-gate * to be the value used by the PROM monitor code, so it 7377c478bd9Sstevel@tonic-gate * is by definition correct. Many programs (e.g., 7387c478bd9Sstevel@tonic-gate * "login" and "tset") will attempt to reset the size 7397c478bd9Sstevel@tonic-gate * to (0, 0) or (34, 80), neither of which is 7407c478bd9Sstevel@tonic-gate * necessarily correct. 7417c478bd9Sstevel@tonic-gate * We just ACK the message, so as not to disturb 7427c478bd9Sstevel@tonic-gate * programs that set the sizes. 7437c478bd9Sstevel@tonic-gate */ 7447c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; /* no data returned */ 7457c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7467c478bd9Sstevel@tonic-gate qreply(q, mp); 7477c478bd9Sstevel@tonic-gate return; 7487c478bd9Sstevel@tonic-gate 7497c478bd9Sstevel@tonic-gate case CONSOPENPOLLEDIO: 7507c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 7517c478bd9Sstevel@tonic-gate ("wcioctl: CONSOPENPOLLEDIO\n")); 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate error = miocpullup(mp, sizeof (struct cons_polledio *)); 7547c478bd9Sstevel@tonic-gate if (error != 0) { 7557c478bd9Sstevel@tonic-gate miocnak(q, mp, 0, error); 7567c478bd9Sstevel@tonic-gate return; 7577c478bd9Sstevel@tonic-gate } 7587c478bd9Sstevel@tonic-gate 7597c478bd9Sstevel@tonic-gate /* 7607c478bd9Sstevel@tonic-gate * We are given an appropriate-sized data block, 7617c478bd9Sstevel@tonic-gate * and return a pointer to our structure in it. 7627c478bd9Sstevel@tonic-gate */ 763fea9cb91Slq150181 if (consmode == CONS_KFB) 764fea9cb91Slq150181 wscons.wc_polledio.cons_polledio_putchar = 765fea9cb91Slq150181 wc_polled_putchar; 76622eb7cb5Sgd78059 *(struct cons_polledio **)(void *)mp->b_cont->b_rptr = 7677c478bd9Sstevel@tonic-gate &wscons.wc_polledio; 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate qreply(q, mp); 7727c478bd9Sstevel@tonic-gate break; 7737c478bd9Sstevel@tonic-gate 774fea9cb91Slq150181 case CONS_GETTERM: 775fea9cb91Slq150181 if ((error = wc_getterm(mp)) != 0) 776fea9cb91Slq150181 miocnak(q, mp, 0, error); 777fea9cb91Slq150181 else 778fea9cb91Slq150181 miocack(q, mp, 0, 0); 779fea9cb91Slq150181 return; 780fea9cb91Slq150181 7817c478bd9Sstevel@tonic-gate case WC_OPEN_FB: 7827c478bd9Sstevel@tonic-gate /* 7837c478bd9Sstevel@tonic-gate * Start out pessimistic, so that we can just jump to 7847c478bd9Sstevel@tonic-gate * the reply to bail out. 7857c478bd9Sstevel@tonic-gate */ 7867c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 7877c478bd9Sstevel@tonic-gate 7887c478bd9Sstevel@tonic-gate /* 7897c478bd9Sstevel@tonic-gate * First test: really, this should be done only from 7907c478bd9Sstevel@tonic-gate * inside the kernel. Unfortunately, that information 7917c478bd9Sstevel@tonic-gate * doesn't seem to be available in a streams ioctl, 7927c478bd9Sstevel@tonic-gate * so restrict it to root only. (Perhaps we could check 7937c478bd9Sstevel@tonic-gate * for ioc_cr == kcred.) 7947c478bd9Sstevel@tonic-gate */ 7957c478bd9Sstevel@tonic-gate if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0) 7967c478bd9Sstevel@tonic-gate goto open_fail; 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate /* 7997c478bd9Sstevel@tonic-gate * Some miscellaneous checks... 8007c478bd9Sstevel@tonic-gate */ 8017c478bd9Sstevel@tonic-gate iocp->ioc_error = EINVAL; 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate /* 8047c478bd9Sstevel@tonic-gate * If we don't have exactly one continuation block, fail. 8057c478bd9Sstevel@tonic-gate */ 806aecfc01dSrui zang - Sun Microsystems - Beijing China if (mp->b_cont == NULL || 807aecfc01dSrui zang - Sun Microsystems - Beijing China mp->b_cont->b_cont != NULL) 8087c478bd9Sstevel@tonic-gate goto open_fail; 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate /* 8117c478bd9Sstevel@tonic-gate * If there's no null terminator in the string, fail. 8127c478bd9Sstevel@tonic-gate */ 813aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED E_PTRDIFF_OVERFLOW */ 814aecfc01dSrui zang - Sun Microsystems - Beijing China len = mp->b_cont->b_wptr - mp->b_cont->b_rptr; 8157c478bd9Sstevel@tonic-gate if (memchr(mp->b_cont->b_rptr, 0, len) == NULL) 8167c478bd9Sstevel@tonic-gate goto open_fail; 8177c478bd9Sstevel@tonic-gate 8187c478bd9Sstevel@tonic-gate /* 8197c478bd9Sstevel@tonic-gate * NOTE: should eventually get default 8207c478bd9Sstevel@tonic-gate * dimensions from a property, e.g. screen-#rows. 8217c478bd9Sstevel@tonic-gate */ 822aecfc01dSrui zang - Sun Microsystems - Beijing China iocp->ioc_error = tem_info_init((char *)mp->b_cont->b_rptr, 823aecfc01dSrui zang - Sun Microsystems - Beijing China iocp->ioc_cr); 8247c478bd9Sstevel@tonic-gate /* 8257c478bd9Sstevel@tonic-gate * Of course, if the terminal emulator initialization 8267c478bd9Sstevel@tonic-gate * failed, fail. 8277c478bd9Sstevel@tonic-gate */ 8287c478bd9Sstevel@tonic-gate if (iocp->ioc_error != 0) 8297c478bd9Sstevel@tonic-gate goto open_fail; 8307c478bd9Sstevel@tonic-gate 831aecfc01dSrui zang - Sun Microsystems - Beijing China #ifdef _HAVE_TEM_FIRMWARE 832aecfc01dSrui zang - Sun Microsystems - Beijing China if (prom_stdout_is_framebuffer()) { 8337c478bd9Sstevel@tonic-gate /* 834aecfc01dSrui zang - Sun Microsystems - Beijing China * Drivers in the console stream may emit additional 835aecfc01dSrui zang - Sun Microsystems - Beijing China * messages before we are ready. This causes text 836aecfc01dSrui zang - Sun Microsystems - Beijing China * overwrite on the screen. So we set the redirection 837aecfc01dSrui zang - Sun Microsystems - Beijing China * here. It is safe because the ioctl in consconfig_dacf 838aecfc01dSrui zang - Sun Microsystems - Beijing China * will succeed and consmode will be set to CONS_KFB. 8397c478bd9Sstevel@tonic-gate */ 840aecfc01dSrui zang - Sun Microsystems - Beijing China prom_set_stdout_redirect(wc_cons_wrtvec, 841aecfc01dSrui zang - Sun Microsystems - Beijing China (promif_redir_arg_t)NULL); 842aecfc01dSrui zang - Sun Microsystems - Beijing China 843aecfc01dSrui zang - Sun Microsystems - Beijing China } 844aecfc01dSrui zang - Sun Microsystems - Beijing China #endif /* _HAVE_TEM_FIRMWARE */ 845aecfc01dSrui zang - Sun Microsystems - Beijing China 846aecfc01dSrui zang - Sun Microsystems - Beijing China tem_register_modechg_cb(wc_modechg_cb, 847aecfc01dSrui zang - Sun Microsystems - Beijing China (tem_modechg_cb_arg_t)&wscons); 8487c478bd9Sstevel@tonic-gate 8497c478bd9Sstevel@tonic-gate /* 8507c478bd9Sstevel@tonic-gate * ... and succeed. 8517c478bd9Sstevel@tonic-gate */ 8527c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 8537c478bd9Sstevel@tonic-gate 8547c478bd9Sstevel@tonic-gate open_fail: 8557c478bd9Sstevel@tonic-gate qreply(q, mp); 8567c478bd9Sstevel@tonic-gate break; 8577c478bd9Sstevel@tonic-gate 8587c478bd9Sstevel@tonic-gate case WC_CLOSE_FB: 8597c478bd9Sstevel@tonic-gate /* 8607c478bd9Sstevel@tonic-gate * There's nothing that can call this, so it's not 8617c478bd9Sstevel@tonic-gate * really implemented. 8627c478bd9Sstevel@tonic-gate */ 8637c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 8647c478bd9Sstevel@tonic-gate /* 8657c478bd9Sstevel@tonic-gate * However, if it were implemented, it would clearly 8667c478bd9Sstevel@tonic-gate * be root-only. 8677c478bd9Sstevel@tonic-gate */ 8687c478bd9Sstevel@tonic-gate if ((iocp->ioc_error = secpolicy_console(iocp->ioc_cr)) != 0) 8697c478bd9Sstevel@tonic-gate goto close_fail; 8707c478bd9Sstevel@tonic-gate 8717c478bd9Sstevel@tonic-gate iocp->ioc_error = EINVAL; 8727c478bd9Sstevel@tonic-gate 8737c478bd9Sstevel@tonic-gate close_fail: 8747c478bd9Sstevel@tonic-gate qreply(q, mp); 8757c478bd9Sstevel@tonic-gate break; 8767c478bd9Sstevel@tonic-gate 8777c478bd9Sstevel@tonic-gate default: 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate /* 8807c478bd9Sstevel@tonic-gate * The only way in which "ttycommon_ioctl" can fail is 8817c478bd9Sstevel@tonic-gate * if the "ioctl" requires a response containing data 8827c478bd9Sstevel@tonic-gate * to be returned to the user, and no mblk could be 8837c478bd9Sstevel@tonic-gate * allocated for the data. No such "ioctl" alters our 8847c478bd9Sstevel@tonic-gate * state. Thus, we always go ahead and do any 8857c478bd9Sstevel@tonic-gate * state-changes the "ioctl" calls for. If we couldn't 8867c478bd9Sstevel@tonic-gate * allocate the data, "ttycommon_ioctl" has stashed the 8877c478bd9Sstevel@tonic-gate * "ioctl" away safely, so we just call "qbufcall" to 8887c478bd9Sstevel@tonic-gate * request that we be called back when we stand a 8897c478bd9Sstevel@tonic-gate * better chance of allocating the data. 8907c478bd9Sstevel@tonic-gate */ 891aecfc01dSrui zang - Sun Microsystems - Beijing China datasize = ttycommon_ioctl(&pvc->vc_ttycommon, q, mp, &error); 8927c478bd9Sstevel@tonic-gate if (datasize != 0) { 893aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_bufcallid != 0) 894aecfc01dSrui zang - Sun Microsystems - Beijing China qunbufcall(q, pvc->vc_bufcallid); 895aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_bufcallid = qbufcall(q, datasize, BPRI_HI, 896aecfc01dSrui zang - Sun Microsystems - Beijing China wcreioctl, pvc); 8977c478bd9Sstevel@tonic-gate return; 8987c478bd9Sstevel@tonic-gate } 8997c478bd9Sstevel@tonic-gate 9007c478bd9Sstevel@tonic-gate if (error < 0) { 9017c478bd9Sstevel@tonic-gate if (iocp->ioc_cmd == TCSBRK) 9027c478bd9Sstevel@tonic-gate error = 0; 9037c478bd9Sstevel@tonic-gate else 9047c478bd9Sstevel@tonic-gate error = EINVAL; 9057c478bd9Sstevel@tonic-gate } 9067c478bd9Sstevel@tonic-gate if (error != 0) { 9077c478bd9Sstevel@tonic-gate iocp->ioc_error = error; 9087c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 9097c478bd9Sstevel@tonic-gate } 9107c478bd9Sstevel@tonic-gate qreply(q, mp); 9117c478bd9Sstevel@tonic-gate break; 9127c478bd9Sstevel@tonic-gate } 9137c478bd9Sstevel@tonic-gate } 9147c478bd9Sstevel@tonic-gate 9157c478bd9Sstevel@tonic-gate /* 9167c478bd9Sstevel@tonic-gate * This function gets the polled I/O structures from the lower 9177c478bd9Sstevel@tonic-gate * keyboard driver. If any initialization or resource allocation 9187c478bd9Sstevel@tonic-gate * needs to be done by the lower driver, it will be done when 9197c478bd9Sstevel@tonic-gate * the lower driver services this message. 9207c478bd9Sstevel@tonic-gate */ 9217c478bd9Sstevel@tonic-gate static void 922aecfc01dSrui zang - Sun Microsystems - Beijing China wc_open_kb_polledio(struct wscons_state *wscons, queue_t *q, mblk_t *mp) 9237c478bd9Sstevel@tonic-gate { 9247c478bd9Sstevel@tonic-gate mblk_t *mp2; 9257c478bd9Sstevel@tonic-gate struct iocblk *iocp; 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 9287c478bd9Sstevel@tonic-gate ("wc_open_kb_polledio: sending CONSOPENPOLLEDIO\n")); 9297c478bd9Sstevel@tonic-gate 9307c478bd9Sstevel@tonic-gate mp2 = mkiocb(CONSOPENPOLLEDIO); 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate if (mp2 == NULL) { 9337c478bd9Sstevel@tonic-gate /* 9347c478bd9Sstevel@tonic-gate * If we can't get an mblk, then wait for it. 9357c478bd9Sstevel@tonic-gate */ 9367c478bd9Sstevel@tonic-gate goto nomem; 9377c478bd9Sstevel@tonic-gate } 9387c478bd9Sstevel@tonic-gate 9397c478bd9Sstevel@tonic-gate mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI); 9407c478bd9Sstevel@tonic-gate 9417c478bd9Sstevel@tonic-gate if (mp2->b_cont == NULL) { 9427c478bd9Sstevel@tonic-gate /* 9437c478bd9Sstevel@tonic-gate * If we can't get an mblk, then wait for it, and release 9447c478bd9Sstevel@tonic-gate * the mblk that we have already allocated. 9457c478bd9Sstevel@tonic-gate */ 9467c478bd9Sstevel@tonic-gate freemsg(mp2); 9477c478bd9Sstevel@tonic-gate goto nomem; 9487c478bd9Sstevel@tonic-gate } 9497c478bd9Sstevel@tonic-gate 950aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp2->b_rptr; 9517c478bd9Sstevel@tonic-gate 9527c478bd9Sstevel@tonic-gate iocp->ioc_count = sizeof (struct cons_polledio *); 9537c478bd9Sstevel@tonic-gate mp2->b_cont->b_wptr = mp2->b_cont->b_rptr + 9547c478bd9Sstevel@tonic-gate sizeof (struct cons_polledio *); 9557c478bd9Sstevel@tonic-gate 956aecfc01dSrui zang - Sun Microsystems - Beijing China wscons->wc_pending_wq = q; 9577c478bd9Sstevel@tonic-gate wscons->wc_pending_link = mp; 9587c478bd9Sstevel@tonic-gate wscons->wc_kb_getpolledio_id = iocp->ioc_id; 9597c478bd9Sstevel@tonic-gate 9607c478bd9Sstevel@tonic-gate putnext(wscons->wc_kbdqueue, mp2); 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate return; 9637c478bd9Sstevel@tonic-gate 9647c478bd9Sstevel@tonic-gate nomem: 965aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 9667c478bd9Sstevel@tonic-gate iocp->ioc_error = ENOMEM; 9677c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 9687c478bd9Sstevel@tonic-gate qreply(q, mp); 9697c478bd9Sstevel@tonic-gate } 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate /* 9727c478bd9Sstevel@tonic-gate * This function releases the polled I/O structures from the lower 9737c478bd9Sstevel@tonic-gate * keyboard driver. If any de-initialization needs to be done, or 9747c478bd9Sstevel@tonic-gate * any resources need to be released, it will be done when the lower 9757c478bd9Sstevel@tonic-gate * driver services this message. 9767c478bd9Sstevel@tonic-gate */ 9777c478bd9Sstevel@tonic-gate static void 978aecfc01dSrui zang - Sun Microsystems - Beijing China wc_close_kb_polledio(struct wscons_state *wscons, queue_t *q, mblk_t *mp) 9797c478bd9Sstevel@tonic-gate { 9807c478bd9Sstevel@tonic-gate mblk_t *mp2; 9817c478bd9Sstevel@tonic-gate struct iocblk *iocp; 9827c478bd9Sstevel@tonic-gate 9837c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 9847c478bd9Sstevel@tonic-gate ("wc_close_kb_polledio: sending CONSCLOSEPOLLEDIO\n")); 9857c478bd9Sstevel@tonic-gate 9867c478bd9Sstevel@tonic-gate mp2 = mkiocb(CONSCLOSEPOLLEDIO); 9877c478bd9Sstevel@tonic-gate 9887c478bd9Sstevel@tonic-gate if (mp2 == NULL) { 9897c478bd9Sstevel@tonic-gate /* 9907c478bd9Sstevel@tonic-gate * If we can't get an mblk, then wait for it. 9917c478bd9Sstevel@tonic-gate */ 9927c478bd9Sstevel@tonic-gate goto nomem; 9937c478bd9Sstevel@tonic-gate } 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate mp2->b_cont = allocb(sizeof (struct cons_polledio *), BPRI_HI); 9967c478bd9Sstevel@tonic-gate 9977c478bd9Sstevel@tonic-gate if (mp2->b_cont == NULL) { 9987c478bd9Sstevel@tonic-gate /* 9997c478bd9Sstevel@tonic-gate * If we can't get an mblk, then wait for it, and release 10007c478bd9Sstevel@tonic-gate * the mblk that we have already allocated. 10017c478bd9Sstevel@tonic-gate */ 10027c478bd9Sstevel@tonic-gate freemsg(mp2); 10037c478bd9Sstevel@tonic-gate 10047c478bd9Sstevel@tonic-gate goto nomem; 10057c478bd9Sstevel@tonic-gate } 10067c478bd9Sstevel@tonic-gate 1007aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp2->b_rptr; 10087c478bd9Sstevel@tonic-gate 10097c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; 10107c478bd9Sstevel@tonic-gate 1011aecfc01dSrui zang - Sun Microsystems - Beijing China wscons->wc_pending_wq = q; 10127c478bd9Sstevel@tonic-gate wscons->wc_pending_link = mp; 10137c478bd9Sstevel@tonic-gate wscons->wc_kb_getpolledio_id = iocp->ioc_id; 10147c478bd9Sstevel@tonic-gate 10157c478bd9Sstevel@tonic-gate putnext(wscons->wc_kbdqueue, mp2); 10167c478bd9Sstevel@tonic-gate 10177c478bd9Sstevel@tonic-gate return; 10187c478bd9Sstevel@tonic-gate 10197c478bd9Sstevel@tonic-gate nomem: 1020aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 10217c478bd9Sstevel@tonic-gate iocp->ioc_error = ENOMEM; 10227c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 10237c478bd9Sstevel@tonic-gate qreply(q, mp); 10247c478bd9Sstevel@tonic-gate } 10257c478bd9Sstevel@tonic-gate 1026fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 10277c478bd9Sstevel@tonic-gate /* ARGSUSED */ 10287c478bd9Sstevel@tonic-gate static void 10297c478bd9Sstevel@tonic-gate wcopoll(void *arg) 10307c478bd9Sstevel@tonic-gate { 1031aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 10327c478bd9Sstevel@tonic-gate queue_t *q; 10337c478bd9Sstevel@tonic-gate 1034aecfc01dSrui zang - Sun Microsystems - Beijing China q = pvc->vc_ttycommon.t_writeq; 1035aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = 0; 1036aecfc01dSrui zang - Sun Microsystems - Beijing China 1037aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1038aecfc01dSrui zang - Sun Microsystems - Beijing China 10397c478bd9Sstevel@tonic-gate /* See if we can continue output */ 1040aecfc01dSrui zang - Sun Microsystems - Beijing China if ((pvc->vc_flags & WCS_BUSY) && pvc->vc_pendc != -1) { 1041aecfc01dSrui zang - Sun Microsystems - Beijing China if (prom_mayput((char)pvc->vc_pendc) == 0) { 1042aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_pendc = -1; 1043aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags &= ~WCS_BUSY; 1044aecfc01dSrui zang - Sun Microsystems - Beijing China if (!(pvc->vc_flags&(WCS_DELAY|WCS_STOPPED))) 1045aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 10467c478bd9Sstevel@tonic-gate } else 1047aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = qtimeout(q, wcopoll, pvc, 1); 10487c478bd9Sstevel@tonic-gate } 1049aecfc01dSrui zang - Sun Microsystems - Beijing China 1050aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 10517c478bd9Sstevel@tonic-gate } 1052fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate /* 10557c478bd9Sstevel@tonic-gate * Restart output on the console after a timeout. 10567c478bd9Sstevel@tonic-gate */ 10577c478bd9Sstevel@tonic-gate /* ARGSUSED */ 10587c478bd9Sstevel@tonic-gate static void 10597c478bd9Sstevel@tonic-gate wcrstrt(void *arg) 10607c478bd9Sstevel@tonic-gate { 1061aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 1062aecfc01dSrui zang - Sun Microsystems - Beijing China 1063aecfc01dSrui zang - Sun Microsystems - Beijing China ASSERT(pvc->vc_ttycommon.t_writeq != NULL); 1064aecfc01dSrui zang - Sun Microsystems - Beijing China 1065aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1066aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags &= ~WCS_DELAY; 1067aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1068aecfc01dSrui zang - Sun Microsystems - Beijing China 1069aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 1070aecfc01dSrui zang - Sun Microsystems - Beijing China } 1071aecfc01dSrui zang - Sun Microsystems - Beijing China 1072aecfc01dSrui zang - Sun Microsystems - Beijing China /* 1073aecfc01dSrui zang - Sun Microsystems - Beijing China * get screen terminal for current output 1074aecfc01dSrui zang - Sun Microsystems - Beijing China */ 1075aecfc01dSrui zang - Sun Microsystems - Beijing China static tem_vt_state_t 1076aecfc01dSrui zang - Sun Microsystems - Beijing China wc_get_screen_tem(vc_state_t *pvc) 1077aecfc01dSrui zang - Sun Microsystems - Beijing China { 1078aecfc01dSrui zang - Sun Microsystems - Beijing China if (!tem_initialized(pvc->vc_tem) || 1079aecfc01dSrui zang - Sun Microsystems - Beijing China tem_get_fbmode(pvc->vc_tem) != KD_TEXT) 1080aecfc01dSrui zang - Sun Microsystems - Beijing China return (NULL); 1081aecfc01dSrui zang - Sun Microsystems - Beijing China 1082aecfc01dSrui zang - Sun Microsystems - Beijing China return (pvc->vc_tem); 10837c478bd9Sstevel@tonic-gate } 10847c478bd9Sstevel@tonic-gate 10857c478bd9Sstevel@tonic-gate /* 10867c478bd9Sstevel@tonic-gate * Start console output 10877c478bd9Sstevel@tonic-gate */ 10887c478bd9Sstevel@tonic-gate static void 1089aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(void *arg) 10907c478bd9Sstevel@tonic-gate { 1091aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 1092aecfc01dSrui zang - Sun Microsystems - Beijing China tem_vt_state_t ptem = NULL; 1093fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 10947c478bd9Sstevel@tonic-gate int c; 10957c478bd9Sstevel@tonic-gate ssize_t cc; 1096fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 10977c478bd9Sstevel@tonic-gate queue_t *q; 10987c478bd9Sstevel@tonic-gate mblk_t *bp; 10997c478bd9Sstevel@tonic-gate mblk_t *nbp; 11007c478bd9Sstevel@tonic-gate 11017c478bd9Sstevel@tonic-gate /* 11027c478bd9Sstevel@tonic-gate * If we're waiting for something to happen (delay timeout to 11037c478bd9Sstevel@tonic-gate * expire, current transmission to finish, output to be 11047c478bd9Sstevel@tonic-gate * restarted, output to finish draining), don't grab anything 11057c478bd9Sstevel@tonic-gate * new. 11067c478bd9Sstevel@tonic-gate */ 1107aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_flags & (WCS_DELAY|WCS_BUSY|WCS_STOPPED)) 1108fea9cb91Slq150181 return; 11097c478bd9Sstevel@tonic-gate 1110aecfc01dSrui zang - Sun Microsystems - Beijing China q = pvc->vc_ttycommon.t_writeq; 11117c478bd9Sstevel@tonic-gate /* 11127c478bd9Sstevel@tonic-gate * assumes that we have been called by whoever holds the 11137c478bd9Sstevel@tonic-gate * exclusionary lock on the write-side queue (protects 1114aecfc01dSrui zang - Sun Microsystems - Beijing China * vc_flags and vc_pendc). 11157c478bd9Sstevel@tonic-gate */ 11167c478bd9Sstevel@tonic-gate for (;;) { 11177c478bd9Sstevel@tonic-gate if ((bp = getq(q)) == NULL) 1118fea9cb91Slq150181 return; /* nothing to transmit */ 11197c478bd9Sstevel@tonic-gate 11207c478bd9Sstevel@tonic-gate /* 11217c478bd9Sstevel@tonic-gate * We have a new message to work on. 11227c478bd9Sstevel@tonic-gate * Check whether it's a delay or an ioctl (the latter 11237c478bd9Sstevel@tonic-gate * occurs if the ioctl in question was waiting for the output 11247c478bd9Sstevel@tonic-gate * to drain). If it's one of those, process it immediately. 11257c478bd9Sstevel@tonic-gate */ 11267c478bd9Sstevel@tonic-gate switch (bp->b_datap->db_type) { 11277c478bd9Sstevel@tonic-gate 11287c478bd9Sstevel@tonic-gate case M_DELAY: 11297c478bd9Sstevel@tonic-gate /* 11307c478bd9Sstevel@tonic-gate * Arrange for "wcrstrt" to be called when the 11317c478bd9Sstevel@tonic-gate * delay expires; it will turn WCS_DELAY off, 11327c478bd9Sstevel@tonic-gate * and call "wcstart" to grab the next message. 11337c478bd9Sstevel@tonic-gate */ 1134aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_timeoutid != 0) 1135aecfc01dSrui zang - Sun Microsystems - Beijing China (void) quntimeout(q, pvc->vc_timeoutid); 1136aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = qtimeout(q, wcrstrt, pvc, 11377c478bd9Sstevel@tonic-gate (clock_t)(*(unsigned char *)bp->b_rptr + 6)); 1138aecfc01dSrui zang - Sun Microsystems - Beijing China 1139aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1140aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags |= WCS_DELAY; 1141aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1142aecfc01dSrui zang - Sun Microsystems - Beijing China 11437c478bd9Sstevel@tonic-gate freemsg(bp); 1144fea9cb91Slq150181 return; /* wait for this to finish */ 11457c478bd9Sstevel@tonic-gate 11467c478bd9Sstevel@tonic-gate case M_IOCTL: 11477c478bd9Sstevel@tonic-gate /* 11487c478bd9Sstevel@tonic-gate * This ioctl was waiting for the output ahead of 11497c478bd9Sstevel@tonic-gate * it to drain; obviously, it has. Do it, and 11507c478bd9Sstevel@tonic-gate * then grab the next message after it. 11517c478bd9Sstevel@tonic-gate */ 11527c478bd9Sstevel@tonic-gate wcioctl(q, bp); 11537c478bd9Sstevel@tonic-gate continue; 11547c478bd9Sstevel@tonic-gate } 11557c478bd9Sstevel@tonic-gate 1156fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 1157fea9cb91Slq150181 if (consmode == CONS_KFB) { 1158fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 1159aecfc01dSrui zang - Sun Microsystems - Beijing China if ((ptem = wc_get_screen_tem(pvc)) != NULL) { 1160aecfc01dSrui zang - Sun Microsystems - Beijing China 11617c478bd9Sstevel@tonic-gate for (nbp = bp; nbp != NULL; nbp = nbp->b_cont) { 11627c478bd9Sstevel@tonic-gate if (nbp->b_wptr > nbp->b_rptr) { 1163aecfc01dSrui zang - Sun Microsystems - Beijing China (void) tem_write(ptem, 1164fea9cb91Slq150181 nbp->b_rptr, 1165aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED */ 1166aecfc01dSrui zang - Sun Microsystems - Beijing China nbp->b_wptr - nbp->b_rptr, 11677c478bd9Sstevel@tonic-gate kcred); 11687c478bd9Sstevel@tonic-gate } 11697c478bd9Sstevel@tonic-gate } 1170aecfc01dSrui zang - Sun Microsystems - Beijing China 1171fea9cb91Slq150181 } 1172aecfc01dSrui zang - Sun Microsystems - Beijing China 1173aecfc01dSrui zang - Sun Microsystems - Beijing China freemsg(bp); 1174aecfc01dSrui zang - Sun Microsystems - Beijing China 1175fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 1176fea9cb91Slq150181 continue; 1177fea9cb91Slq150181 } 1178fea9cb91Slq150181 1179fea9cb91Slq150181 /* consmode = CONS_FW */ 1180aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_minor != 0) { 1181aecfc01dSrui zang - Sun Microsystems - Beijing China freemsg(bp); 1182aecfc01dSrui zang - Sun Microsystems - Beijing China continue; 1183aecfc01dSrui zang - Sun Microsystems - Beijing China } 1184aecfc01dSrui zang - Sun Microsystems - Beijing China 1185aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED E_PTRDIFF_OVERFLOW */ 1186aecfc01dSrui zang - Sun Microsystems - Beijing China if ((cc = bp->b_wptr - bp->b_rptr) == 0) { 11877c478bd9Sstevel@tonic-gate freemsg(bp); 11887c478bd9Sstevel@tonic-gate continue; 11897c478bd9Sstevel@tonic-gate } 11907c478bd9Sstevel@tonic-gate /* 11917c478bd9Sstevel@tonic-gate * Direct output to the frame buffer if this device 11927c478bd9Sstevel@tonic-gate * is not the "hardware" console. 11937c478bd9Sstevel@tonic-gate */ 11947c478bd9Sstevel@tonic-gate if (wscons.wc_defer_output) { 11957c478bd9Sstevel@tonic-gate /* 11967c478bd9Sstevel@tonic-gate * Never do output here; 11977c478bd9Sstevel@tonic-gate * it takes forever. 11987c478bd9Sstevel@tonic-gate */ 1199aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1200aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags |= WCS_BUSY; 1201aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1202aecfc01dSrui zang - Sun Microsystems - Beijing China 1203aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_pendc = -1; 12047c478bd9Sstevel@tonic-gate (void) putbq(q, bp); 12057c478bd9Sstevel@tonic-gate if (q->q_count > 128) { /* do it soon */ 1206aecfc01dSrui zang - Sun Microsystems - Beijing China softcall(wconsout, pvc); 12077c478bd9Sstevel@tonic-gate } else { /* wait a bit */ 1208aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_timeoutid != 0) 12097c478bd9Sstevel@tonic-gate (void) quntimeout(q, 1210aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid); 1211aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = qtimeout(q, wconsout, 1212aecfc01dSrui zang - Sun Microsystems - Beijing China pvc, hz / 30); 12137c478bd9Sstevel@tonic-gate } 1214fea9cb91Slq150181 return; 12157c478bd9Sstevel@tonic-gate } 12167c478bd9Sstevel@tonic-gate for (;;) { 12177c478bd9Sstevel@tonic-gate c = *bp->b_rptr++; 12187c478bd9Sstevel@tonic-gate cc--; 12197c478bd9Sstevel@tonic-gate if (prom_mayput((char)c) != 0) { 1220aecfc01dSrui zang - Sun Microsystems - Beijing China 1221aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1222aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags |= WCS_BUSY; 1223aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1224aecfc01dSrui zang - Sun Microsystems - Beijing China 1225aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_pendc = c; 1226aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_timeoutid != 0) 12277c478bd9Sstevel@tonic-gate (void) quntimeout(q, 1228aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid); 1229aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_timeoutid = qtimeout(q, wcopoll, 1230aecfc01dSrui zang - Sun Microsystems - Beijing China pvc, 1); 12317c478bd9Sstevel@tonic-gate if (bp != NULL) 12327c478bd9Sstevel@tonic-gate /* not done with this message yet */ 12337c478bd9Sstevel@tonic-gate (void) putbq(q, bp); 1234fea9cb91Slq150181 return; 12357c478bd9Sstevel@tonic-gate } 12367c478bd9Sstevel@tonic-gate while (cc <= 0) { 12377c478bd9Sstevel@tonic-gate nbp = bp; 12387c478bd9Sstevel@tonic-gate bp = bp->b_cont; 12397c478bd9Sstevel@tonic-gate freeb(nbp); 12407c478bd9Sstevel@tonic-gate if (bp == NULL) 1241fea9cb91Slq150181 return; 1242aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED E_PTRDIFF_OVERFLOW */ 1243aecfc01dSrui zang - Sun Microsystems - Beijing China cc = bp->b_wptr - bp->b_rptr; 12447c478bd9Sstevel@tonic-gate } 12457c478bd9Sstevel@tonic-gate } 1246fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 12477c478bd9Sstevel@tonic-gate } 12487c478bd9Sstevel@tonic-gate } 12497c478bd9Sstevel@tonic-gate 1250fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 12517c478bd9Sstevel@tonic-gate /* 12527c478bd9Sstevel@tonic-gate * Output to frame buffer console. 12537c478bd9Sstevel@tonic-gate * It takes a long time to scroll. 12547c478bd9Sstevel@tonic-gate */ 12557c478bd9Sstevel@tonic-gate /* ARGSUSED */ 12567c478bd9Sstevel@tonic-gate static void 1257aecfc01dSrui zang - Sun Microsystems - Beijing China wconsout(void *arg) 12587c478bd9Sstevel@tonic-gate { 1259aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc = (vc_state_t *)arg; 12607c478bd9Sstevel@tonic-gate uchar_t *cp; 12617c478bd9Sstevel@tonic-gate ssize_t cc; 12627c478bd9Sstevel@tonic-gate queue_t *q; 12637c478bd9Sstevel@tonic-gate mblk_t *bp; 12647c478bd9Sstevel@tonic-gate mblk_t *nbp; 12657c478bd9Sstevel@tonic-gate char *current_position; 12667c478bd9Sstevel@tonic-gate ssize_t bytes_left; 12677c478bd9Sstevel@tonic-gate 1268aecfc01dSrui zang - Sun Microsystems - Beijing China if ((q = pvc->vc_ttycommon.t_writeq) == NULL) { 12697c478bd9Sstevel@tonic-gate return; /* not attached to a stream */ 12707c478bd9Sstevel@tonic-gate } 12717c478bd9Sstevel@tonic-gate 12727c478bd9Sstevel@tonic-gate /* 12737c478bd9Sstevel@tonic-gate * Set up to copy up to MAXHIWAT bytes. 12747c478bd9Sstevel@tonic-gate */ 12757c478bd9Sstevel@tonic-gate current_position = &obuf[0]; 12767c478bd9Sstevel@tonic-gate bytes_left = MAXHIWAT; 12777c478bd9Sstevel@tonic-gate while ((bp = getq(q)) != NULL) { 12787c478bd9Sstevel@tonic-gate if (bp->b_datap->db_type == M_IOCTL) { 12797c478bd9Sstevel@tonic-gate /* 12807c478bd9Sstevel@tonic-gate * This ioctl was waiting for the output ahead of 12817c478bd9Sstevel@tonic-gate * it to drain; obviously, it has. Put it back 12827c478bd9Sstevel@tonic-gate * so that "wcstart" can handle it, and transmit 12837c478bd9Sstevel@tonic-gate * what we've got. 12847c478bd9Sstevel@tonic-gate */ 12857c478bd9Sstevel@tonic-gate (void) putbq(q, bp); 12867c478bd9Sstevel@tonic-gate goto transmit; 12877c478bd9Sstevel@tonic-gate } 12887c478bd9Sstevel@tonic-gate 12897c478bd9Sstevel@tonic-gate do { 12907c478bd9Sstevel@tonic-gate cp = bp->b_rptr; 1291aecfc01dSrui zang - Sun Microsystems - Beijing China /* LINTED E_PTRDIFF_OVERFLOW */ 1292aecfc01dSrui zang - Sun Microsystems - Beijing China cc = bp->b_wptr - cp; 12937c478bd9Sstevel@tonic-gate while (cc != 0) { 12947c478bd9Sstevel@tonic-gate if (bytes_left == 0) { 12957c478bd9Sstevel@tonic-gate /* 12967c478bd9Sstevel@tonic-gate * Out of buffer space; put this 12977c478bd9Sstevel@tonic-gate * buffer back on the queue, and 12987c478bd9Sstevel@tonic-gate * transmit what we have. 12997c478bd9Sstevel@tonic-gate */ 13007c478bd9Sstevel@tonic-gate bp->b_rptr = cp; 13017c478bd9Sstevel@tonic-gate (void) putbq(q, bp); 13027c478bd9Sstevel@tonic-gate goto transmit; 13037c478bd9Sstevel@tonic-gate } 13047c478bd9Sstevel@tonic-gate *current_position++ = *cp++; 13057c478bd9Sstevel@tonic-gate cc--; 13067c478bd9Sstevel@tonic-gate bytes_left--; 13077c478bd9Sstevel@tonic-gate } 13087c478bd9Sstevel@tonic-gate nbp = bp; 13097c478bd9Sstevel@tonic-gate bp = bp->b_cont; 13107c478bd9Sstevel@tonic-gate freeb(nbp); 13117c478bd9Sstevel@tonic-gate } while (bp != NULL); 13127c478bd9Sstevel@tonic-gate } 13137c478bd9Sstevel@tonic-gate 13147c478bd9Sstevel@tonic-gate transmit: 13157c478bd9Sstevel@tonic-gate if ((cc = MAXHIWAT - bytes_left) != 0) 13167c478bd9Sstevel@tonic-gate console_puts(obuf, cc); 13177c478bd9Sstevel@tonic-gate 1318aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1319aecfc01dSrui zang - Sun Microsystems - Beijing China pvc->vc_flags &= ~WCS_BUSY; 1320aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1321aecfc01dSrui zang - Sun Microsystems - Beijing China 1322aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 13237c478bd9Sstevel@tonic-gate } 1324fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 13257c478bd9Sstevel@tonic-gate 13267c478bd9Sstevel@tonic-gate /* 13277c478bd9Sstevel@tonic-gate * Put procedure for lower read queue. 13287c478bd9Sstevel@tonic-gate * Pass everything up to queue above "upper half". 13297c478bd9Sstevel@tonic-gate */ 13307c478bd9Sstevel@tonic-gate static int 13317c478bd9Sstevel@tonic-gate wclrput(queue_t *q, mblk_t *mp) 13327c478bd9Sstevel@tonic-gate { 1333aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc; 13347c478bd9Sstevel@tonic-gate queue_t *upq; 13357c478bd9Sstevel@tonic-gate struct iocblk *iocp; 13367c478bd9Sstevel@tonic-gate 1337aecfc01dSrui zang - Sun Microsystems - Beijing China pvc = vt_minor2vc(VT_ACTIVE); 1338aecfc01dSrui zang - Sun Microsystems - Beijing China 13397c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 13407c478bd9Sstevel@tonic-gate ("wclrput: wclrput type = 0x%x\n", mp->b_datap->db_type)); 13417c478bd9Sstevel@tonic-gate 13427c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) { 13437c478bd9Sstevel@tonic-gate 13447c478bd9Sstevel@tonic-gate case M_FLUSH: 13457c478bd9Sstevel@tonic-gate if (*mp->b_rptr == FLUSHW || *mp->b_rptr == FLUSHRW) { 13467c478bd9Sstevel@tonic-gate /* 13477c478bd9Sstevel@tonic-gate * Flush our write queue. 13487c478bd9Sstevel@tonic-gate */ 13497c478bd9Sstevel@tonic-gate /* XXX doesn't flush M_DELAY */ 13507c478bd9Sstevel@tonic-gate flushq(WR(q), FLUSHDATA); 13517c478bd9Sstevel@tonic-gate *mp->b_rptr = FLUSHR; /* it has been flushed */ 13527c478bd9Sstevel@tonic-gate } 13537c478bd9Sstevel@tonic-gate if (*mp->b_rptr == FLUSHR || *mp->b_rptr == FLUSHRW) { 13547c478bd9Sstevel@tonic-gate flushq(q, FLUSHDATA); 13557c478bd9Sstevel@tonic-gate *mp->b_rptr = FLUSHW; /* it has been flushed */ 13567c478bd9Sstevel@tonic-gate qreply(q, mp); /* give the read queues a crack at it */ 13577c478bd9Sstevel@tonic-gate } else 13587c478bd9Sstevel@tonic-gate freemsg(mp); 13597c478bd9Sstevel@tonic-gate break; 13607c478bd9Sstevel@tonic-gate 13617c478bd9Sstevel@tonic-gate case M_DATA: 1362aecfc01dSrui zang - Sun Microsystems - Beijing China if (consmode == CONS_KFB && vt_check_hotkeys(mp)) { 13637c478bd9Sstevel@tonic-gate freemsg(mp); 1364aecfc01dSrui zang - Sun Microsystems - Beijing China break; 1365aecfc01dSrui zang - Sun Microsystems - Beijing China } 1366aecfc01dSrui zang - Sun Microsystems - Beijing China 1367aecfc01dSrui zang - Sun Microsystems - Beijing China if ((upq = pvc->vc_ttycommon.t_readq) != NULL) { 1368aecfc01dSrui zang - Sun Microsystems - Beijing China if (!canput(upq->q_next)) { 1369aecfc01dSrui zang - Sun Microsystems - Beijing China ttycommon_qfull(&pvc->vc_ttycommon, upq); 1370aecfc01dSrui zang - Sun Microsystems - Beijing China wcstart(pvc); 1371aecfc01dSrui zang - Sun Microsystems - Beijing China freemsg(mp); 1372aecfc01dSrui zang - Sun Microsystems - Beijing China } else { 13737c478bd9Sstevel@tonic-gate putnext(upq, mp); 1374aecfc01dSrui zang - Sun Microsystems - Beijing China } 13757c478bd9Sstevel@tonic-gate } else 13767c478bd9Sstevel@tonic-gate freemsg(mp); 13777c478bd9Sstevel@tonic-gate break; 13787c478bd9Sstevel@tonic-gate 13797c478bd9Sstevel@tonic-gate case M_IOCACK: 13807c478bd9Sstevel@tonic-gate case M_IOCNAK: 1381aecfc01dSrui zang - Sun Microsystems - Beijing China iocp = (struct iocblk *)(void *)mp->b_rptr; 13827c478bd9Sstevel@tonic-gate if (wscons.wc_pending_link != NULL && 13837c478bd9Sstevel@tonic-gate iocp->ioc_id == wscons.wc_kb_getpolledio_id) { 13847c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) { 13857c478bd9Sstevel@tonic-gate 13867c478bd9Sstevel@tonic-gate case M_IOCACK: 13877c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) { 13887c478bd9Sstevel@tonic-gate 13897c478bd9Sstevel@tonic-gate case CONSOPENPOLLEDIO: 13907c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 13917c478bd9Sstevel@tonic-gate ("wclrput: " 13927c478bd9Sstevel@tonic-gate "ACK CONSOPENPOLLEDIO\n")); 13937c478bd9Sstevel@tonic-gate wscons.wc_kb_polledio = 1394aecfc01dSrui zang - Sun Microsystems - Beijing China *(struct cons_polledio **) 1395aecfc01dSrui zang - Sun Microsystems - Beijing China (void *)mp->b_cont->b_rptr; 1396fea9cb91Slq150181 wscons.wc_polledio. 1397fea9cb91Slq150181 cons_polledio_getchar = 1398fea9cb91Slq150181 wc_polled_getchar; 1399fea9cb91Slq150181 wscons.wc_polledio. 1400fea9cb91Slq150181 cons_polledio_ischar = 1401fea9cb91Slq150181 wc_polled_ischar; 14027c478bd9Sstevel@tonic-gate break; 14037c478bd9Sstevel@tonic-gate 14047c478bd9Sstevel@tonic-gate case CONSCLOSEPOLLEDIO: 14057c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 14067c478bd9Sstevel@tonic-gate ("wclrput: " 14077c478bd9Sstevel@tonic-gate "ACK CONSCLOSEPOLLEDIO\n")); 14087c478bd9Sstevel@tonic-gate wscons.wc_kb_polledio = NULL; 14097c478bd9Sstevel@tonic-gate wscons.wc_kbdqueue = NULL; 1410fea9cb91Slq150181 wscons.wc_polledio. 1411fea9cb91Slq150181 cons_polledio_getchar = NULL; 1412fea9cb91Slq150181 wscons.wc_polledio. 1413fea9cb91Slq150181 cons_polledio_ischar = NULL; 14147c478bd9Sstevel@tonic-gate break; 14157c478bd9Sstevel@tonic-gate default: 14167c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 1417aecfc01dSrui zang - Sun Microsystems - Beijing China ("wclrput: " 1418aecfc01dSrui zang - Sun Microsystems - Beijing China "ACK UNKNOWN\n")); 14197c478bd9Sstevel@tonic-gate } 14207c478bd9Sstevel@tonic-gate 14217c478bd9Sstevel@tonic-gate break; 14227c478bd9Sstevel@tonic-gate case M_IOCNAK: 14237c478bd9Sstevel@tonic-gate /* 14247c478bd9Sstevel@tonic-gate * Keyboard may or may not support polled I/O. 14257c478bd9Sstevel@tonic-gate * This ioctl may have been rejected because 14267c478bd9Sstevel@tonic-gate * we only have the wc->conskbd chain built, 14277c478bd9Sstevel@tonic-gate * and the keyboard driver has not been linked 14287c478bd9Sstevel@tonic-gate * underneath conskbd yet. 14297c478bd9Sstevel@tonic-gate */ 14307c478bd9Sstevel@tonic-gate DPRINTF(PRINT_L1, PRINT_MASK_ALL, 14317c478bd9Sstevel@tonic-gate ("wclrput: NAK\n")); 14327c478bd9Sstevel@tonic-gate 14337c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) { 14347c478bd9Sstevel@tonic-gate 14357c478bd9Sstevel@tonic-gate case CONSCLOSEPOLLEDIO: 14367c478bd9Sstevel@tonic-gate wscons.wc_kb_polledio = NULL; 14377c478bd9Sstevel@tonic-gate wscons.wc_kbdqueue = NULL; 1438fea9cb91Slq150181 wscons.wc_polledio. 1439fea9cb91Slq150181 cons_polledio_getchar = NULL; 1440fea9cb91Slq150181 wscons.wc_polledio. 1441fea9cb91Slq150181 cons_polledio_ischar = NULL; 14427c478bd9Sstevel@tonic-gate break; 14437c478bd9Sstevel@tonic-gate } 14447c478bd9Sstevel@tonic-gate break; 14457c478bd9Sstevel@tonic-gate } 14467c478bd9Sstevel@tonic-gate 14477c478bd9Sstevel@tonic-gate /* 14487c478bd9Sstevel@tonic-gate * Discard the response, replace it with the 14497c478bd9Sstevel@tonic-gate * pending response to the I_PLINK, then let it 14507c478bd9Sstevel@tonic-gate * flow upward. 14517c478bd9Sstevel@tonic-gate */ 14527c478bd9Sstevel@tonic-gate freemsg(mp); 14537c478bd9Sstevel@tonic-gate mp = wscons.wc_pending_link; 14547c478bd9Sstevel@tonic-gate wscons.wc_pending_link = NULL; 14557c478bd9Sstevel@tonic-gate wscons.wc_kb_getpolledio_id = 0; 14567c478bd9Sstevel@tonic-gate } 14577c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate default: /* inc M_ERROR, M_HANGUP, M_IOCACK, M_IOCNAK, ... */ 1460aecfc01dSrui zang - Sun Microsystems - Beijing China if (wscons.wc_pending_wq != NULL) { 1461aecfc01dSrui zang - Sun Microsystems - Beijing China qreply(wscons.wc_pending_wq, mp); 1462aecfc01dSrui zang - Sun Microsystems - Beijing China wscons.wc_pending_wq = NULL; 1463aecfc01dSrui zang - Sun Microsystems - Beijing China break; 1464aecfc01dSrui zang - Sun Microsystems - Beijing China } 1465aecfc01dSrui zang - Sun Microsystems - Beijing China 1466aecfc01dSrui zang - Sun Microsystems - Beijing China if ((upq = pvc->vc_ttycommon.t_readq) != NULL) { 14677c478bd9Sstevel@tonic-gate putnext(upq, mp); 14687c478bd9Sstevel@tonic-gate } else { 1469aecfc01dSrui zang - Sun Microsystems - Beijing China DPRINTF(PRINT_L1, PRINT_MASK_ALL, 1470aecfc01dSrui zang - Sun Microsystems - Beijing China ("wclrput: Message DISCARDED\n")); 14717c478bd9Sstevel@tonic-gate freemsg(mp); 14727c478bd9Sstevel@tonic-gate } 14737c478bd9Sstevel@tonic-gate break; 14747c478bd9Sstevel@tonic-gate } 14757c478bd9Sstevel@tonic-gate 14767c478bd9Sstevel@tonic-gate return (0); 14777c478bd9Sstevel@tonic-gate } 14787c478bd9Sstevel@tonic-gate 1479aecfc01dSrui zang - Sun Microsystems - Beijing China #ifdef _HAVE_TEM_FIRMWARE 1480aecfc01dSrui zang - Sun Microsystems - Beijing China /* 1481aecfc01dSrui zang - Sun Microsystems - Beijing China * This routine exists so that prom_write() can redirect writes 1482aecfc01dSrui zang - Sun Microsystems - Beijing China * to the framebuffer through the kernel terminal emulator, if 1483aecfc01dSrui zang - Sun Microsystems - Beijing China * that configuration is selected during consconfig. 1484aecfc01dSrui zang - Sun Microsystems - Beijing China * When the kernel terminal emulator is enabled, consconfig_dacf 1485aecfc01dSrui zang - Sun Microsystems - Beijing China * sets up the PROM output redirect vector to enter this function. 1486aecfc01dSrui zang - Sun Microsystems - Beijing China * During panic the console will already be powered up as part of 1487aecfc01dSrui zang - Sun Microsystems - Beijing China * calling into the prom_*() layer. 1488aecfc01dSrui zang - Sun Microsystems - Beijing China */ 1489aecfc01dSrui zang - Sun Microsystems - Beijing China /* ARGSUSED */ 1490aecfc01dSrui zang - Sun Microsystems - Beijing China ssize_t 1491aecfc01dSrui zang - Sun Microsystems - Beijing China wc_cons_wrtvec(promif_redir_arg_t arg, uchar_t *s, size_t n) 1492aecfc01dSrui zang - Sun Microsystems - Beijing China { 1493aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc; 1494aecfc01dSrui zang - Sun Microsystems - Beijing China 1495aecfc01dSrui zang - Sun Microsystems - Beijing China pvc = vt_minor2vc(VT_ACTIVE); 1496aecfc01dSrui zang - Sun Microsystems - Beijing China 1497aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_tem == NULL) 1498aecfc01dSrui zang - Sun Microsystems - Beijing China return (0); 1499aecfc01dSrui zang - Sun Microsystems - Beijing China 1500aecfc01dSrui zang - Sun Microsystems - Beijing China ASSERT(consmode == CONS_KFB); 1501aecfc01dSrui zang - Sun Microsystems - Beijing China 1502aecfc01dSrui zang - Sun Microsystems - Beijing China if (panicstr) 1503aecfc01dSrui zang - Sun Microsystems - Beijing China polled_io_cons_write(s, n); 1504aecfc01dSrui zang - Sun Microsystems - Beijing China else 1505aecfc01dSrui zang - Sun Microsystems - Beijing China (void) tem_write(pvc->vc_tem, s, n, kcred); 1506aecfc01dSrui zang - Sun Microsystems - Beijing China 1507aecfc01dSrui zang - Sun Microsystems - Beijing China return (n); 1508aecfc01dSrui zang - Sun Microsystems - Beijing China } 1509aecfc01dSrui zang - Sun Microsystems - Beijing China #endif /* _HAVE_TEM_FIRMWARE */ 1510aecfc01dSrui zang - Sun Microsystems - Beijing China 15117c478bd9Sstevel@tonic-gate /* 1512fea9cb91Slq150181 * These are for systems without OBP, and for devices that cannot be 1513fea9cb91Slq150181 * shared between Solaris and the OBP. 15147c478bd9Sstevel@tonic-gate */ 15157c478bd9Sstevel@tonic-gate static void 1516281f0747Slt200341 wc_polled_putchar(cons_polledio_arg_t arg, unsigned char c) 15177c478bd9Sstevel@tonic-gate { 1518aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc; 1519aecfc01dSrui zang - Sun Microsystems - Beijing China 1520aecfc01dSrui zang - Sun Microsystems - Beijing China pvc = vt_minor2vc(VT_ACTIVE); 1521aecfc01dSrui zang - Sun Microsystems - Beijing China 15227c478bd9Sstevel@tonic-gate if (c == '\n') 1523fea9cb91Slq150181 wc_polled_putchar(arg, '\r'); 15247c478bd9Sstevel@tonic-gate 1525aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_tem == NULL) { 15267c478bd9Sstevel@tonic-gate /* 15277c478bd9Sstevel@tonic-gate * We have no terminal emulator configured. We have no 15287c478bd9Sstevel@tonic-gate * recourse but to drop the output on the floor. 15297c478bd9Sstevel@tonic-gate */ 15307c478bd9Sstevel@tonic-gate return; 15317c478bd9Sstevel@tonic-gate } 15327c478bd9Sstevel@tonic-gate 1533aecfc01dSrui zang - Sun Microsystems - Beijing China tem_safe_polled_write(pvc->vc_tem, &c, 1); 15347c478bd9Sstevel@tonic-gate } 15357c478bd9Sstevel@tonic-gate 15367c478bd9Sstevel@tonic-gate /* 15377c478bd9Sstevel@tonic-gate * These are for systems without OBP, and for devices that cannot be 15387c478bd9Sstevel@tonic-gate * shared between Solaris and the OBP. 15397c478bd9Sstevel@tonic-gate */ 15407c478bd9Sstevel@tonic-gate static int 1541281f0747Slt200341 wc_polled_getchar(cons_polledio_arg_t arg) 15427c478bd9Sstevel@tonic-gate { 1543aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state *wscons = (struct wscons_state *)arg; 15447c478bd9Sstevel@tonic-gate 15457c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) { 15467c478bd9Sstevel@tonic-gate prom_printf("wscons: getchar with no keyboard support"); 15477c478bd9Sstevel@tonic-gate prom_printf("Halted..."); 15487c478bd9Sstevel@tonic-gate for (;;) 15497c478bd9Sstevel@tonic-gate /* HANG FOREVER */; 15507c478bd9Sstevel@tonic-gate } 15517c478bd9Sstevel@tonic-gate 15527c478bd9Sstevel@tonic-gate return (wscons->wc_kb_polledio->cons_polledio_getchar( 15537c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_argument)); 15547c478bd9Sstevel@tonic-gate } 15557c478bd9Sstevel@tonic-gate 15567c478bd9Sstevel@tonic-gate static boolean_t 1557281f0747Slt200341 wc_polled_ischar(cons_polledio_arg_t arg) 15587c478bd9Sstevel@tonic-gate { 1559aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state *wscons = (struct wscons_state *)arg; 15607c478bd9Sstevel@tonic-gate 15617c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) 15627c478bd9Sstevel@tonic-gate return (B_FALSE); 15637c478bd9Sstevel@tonic-gate 15647c478bd9Sstevel@tonic-gate return (wscons->wc_kb_polledio->cons_polledio_ischar( 15657c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_argument)); 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate static void 1569281f0747Slt200341 wc_polled_enter(cons_polledio_arg_t arg) 15707c478bd9Sstevel@tonic-gate { 1571aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state *wscons = (struct wscons_state *)arg; 15727c478bd9Sstevel@tonic-gate 15737c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) 15747c478bd9Sstevel@tonic-gate return; 15757c478bd9Sstevel@tonic-gate 15767c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio->cons_polledio_enter != NULL) { 15777c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_enter( 15787c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_argument); 15797c478bd9Sstevel@tonic-gate } 15807c478bd9Sstevel@tonic-gate } 15817c478bd9Sstevel@tonic-gate 15827c478bd9Sstevel@tonic-gate static void 1583281f0747Slt200341 wc_polled_exit(cons_polledio_arg_t arg) 15847c478bd9Sstevel@tonic-gate { 1585aecfc01dSrui zang - Sun Microsystems - Beijing China struct wscons_state *wscons = (struct wscons_state *)arg; 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio == NULL) 15887c478bd9Sstevel@tonic-gate return; 15897c478bd9Sstevel@tonic-gate 15907c478bd9Sstevel@tonic-gate if (wscons->wc_kb_polledio->cons_polledio_exit != NULL) { 15917c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_exit( 15927c478bd9Sstevel@tonic-gate wscons->wc_kb_polledio->cons_polledio_argument); 15937c478bd9Sstevel@tonic-gate } 15947c478bd9Sstevel@tonic-gate } 15957c478bd9Sstevel@tonic-gate 15967c478bd9Sstevel@tonic-gate 15977c478bd9Sstevel@tonic-gate #ifdef DEBUG 15987c478bd9Sstevel@tonic-gate static void 15997c478bd9Sstevel@tonic-gate wc_dprintf(const char *fmt, ...) 16007c478bd9Sstevel@tonic-gate { 16017c478bd9Sstevel@tonic-gate char buf[256]; 16027c478bd9Sstevel@tonic-gate va_list ap; 16037c478bd9Sstevel@tonic-gate 16047c478bd9Sstevel@tonic-gate va_start(ap, fmt); 16057c478bd9Sstevel@tonic-gate (void) vsprintf(buf, fmt, ap); 16067c478bd9Sstevel@tonic-gate va_end(ap); 16077c478bd9Sstevel@tonic-gate 1608fea9cb91Slq150181 cmn_err(CE_WARN, "wc: %s", buf); 16097c478bd9Sstevel@tonic-gate } 16107c478bd9Sstevel@tonic-gate #endif 16117c478bd9Sstevel@tonic-gate 1612aecfc01dSrui zang - Sun Microsystems - Beijing China /*ARGSUSED*/ 1613fea9cb91Slq150181 static void 1614aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(vc_state_t *pvc, char *name, ushort_t value) 16157c478bd9Sstevel@tonic-gate { 1616fea9cb91Slq150181 char data[8]; 16177c478bd9Sstevel@tonic-gate 1618fea9cb91Slq150181 (void) snprintf(data, sizeof (data), "%u", value); 1619aecfc01dSrui zang - Sun Microsystems - Beijing China 1620aecfc01dSrui zang - Sun Microsystems - Beijing China (void) ddi_prop_update_string(wscons.wc_dev, wc_dip, name, data); 16217c478bd9Sstevel@tonic-gate } 16227c478bd9Sstevel@tonic-gate 16237c478bd9Sstevel@tonic-gate /* 16247c478bd9Sstevel@tonic-gate * Gets the number of text rows and columns and the 16257c478bd9Sstevel@tonic-gate * width and height (in pixels) of the console. 16267c478bd9Sstevel@tonic-gate */ 1627aecfc01dSrui zang - Sun Microsystems - Beijing China void 1628aecfc01dSrui zang - Sun Microsystems - Beijing China wc_get_size(vc_state_t *pvc) 16297c478bd9Sstevel@tonic-gate { 1630aecfc01dSrui zang - Sun Microsystems - Beijing China struct winsize *t = &pvc->vc_ttycommon.t_size; 1631fea9cb91Slq150181 ushort_t r = LOSCREENLINES, c = LOSCREENCOLS, x = 0, y = 0; 16327c478bd9Sstevel@tonic-gate 1633aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_tem != NULL) 1634aecfc01dSrui zang - Sun Microsystems - Beijing China tem_get_size(&r, &c, &x, &y); 1635fea9cb91Slq150181 #ifdef _HAVE_TEM_FIRMWARE 1636aecfc01dSrui zang - Sun Microsystems - Beijing China else 1637fea9cb91Slq150181 console_get_size(&r, &c, &x, &y); 1638fea9cb91Slq150181 #endif /* _HAVE_TEM_FIRMWARE */ 1639fea9cb91Slq150181 1640aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_ttycommon.t_excl); 1641aecfc01dSrui zang - Sun Microsystems - Beijing China t->ws_col = c; 1642aecfc01dSrui zang - Sun Microsystems - Beijing China t->ws_row = r; 1643aecfc01dSrui zang - Sun Microsystems - Beijing China t->ws_xpixel = x; 1644aecfc01dSrui zang - Sun Microsystems - Beijing China t->ws_ypixel = y; 1645aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_ttycommon.t_excl); 1646aecfc01dSrui zang - Sun Microsystems - Beijing China 1647aecfc01dSrui zang - Sun Microsystems - Beijing China if (pvc->vc_minor != 0) 1648aecfc01dSrui zang - Sun Microsystems - Beijing China return; 1649aecfc01dSrui zang - Sun Microsystems - Beijing China 1650aecfc01dSrui zang - Sun Microsystems - Beijing China /* only for the wscons:0 */ 1651aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(pvc, "screen-#cols", c); 1652aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(pvc, "screen-#rows", r); 1653aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(pvc, "screen-width", x); 1654aecfc01dSrui zang - Sun Microsystems - Beijing China update_property(pvc, "screen-height", y); 1655fea9cb91Slq150181 } 1656fea9cb91Slq150181 1657aecfc01dSrui zang - Sun Microsystems - Beijing China /*ARGSUSED*/ 1658fea9cb91Slq150181 static void 1659fea9cb91Slq150181 wc_modechg_cb(tem_modechg_cb_arg_t arg) 1660fea9cb91Slq150181 { 1661aecfc01dSrui zang - Sun Microsystems - Beijing China minor_t index; 1662aecfc01dSrui zang - Sun Microsystems - Beijing China vc_state_t *pvc; 1663aecfc01dSrui zang - Sun Microsystems - Beijing China 1664aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 1665aecfc01dSrui zang - Sun Microsystems - Beijing China for (index = 0; index < VC_INSTANCES_COUNT; index++) { 1666aecfc01dSrui zang - Sun Microsystems - Beijing China pvc = vt_minor2vc(index); 1667aecfc01dSrui zang - Sun Microsystems - Beijing China 1668aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&pvc->vc_state_lock); 1669aecfc01dSrui zang - Sun Microsystems - Beijing China 1670aecfc01dSrui zang - Sun Microsystems - Beijing China if ((pvc->vc_flags & WCS_ISOPEN) && 1671aecfc01dSrui zang - Sun Microsystems - Beijing China (pvc->vc_flags & WCS_INIT)) 1672aecfc01dSrui zang - Sun Microsystems - Beijing China wc_get_size(pvc); 1673aecfc01dSrui zang - Sun Microsystems - Beijing China 1674aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&pvc->vc_state_lock); 1675aecfc01dSrui zang - Sun Microsystems - Beijing China } 1676aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 16777c478bd9Sstevel@tonic-gate } 1678