1aecfc01dSrui zang - Sun Microsystems - Beijing China /* 2aecfc01dSrui zang - Sun Microsystems - Beijing China * CDDL HEADER START 3aecfc01dSrui zang - Sun Microsystems - Beijing China * 4aecfc01dSrui zang - Sun Microsystems - Beijing China * The contents of this file are subject to the terms of the 5aecfc01dSrui zang - Sun Microsystems - Beijing China * Common Development and Distribution License (the "License"). 6aecfc01dSrui zang - Sun Microsystems - Beijing China * You may not use this file except in compliance with the License. 7aecfc01dSrui zang - Sun Microsystems - Beijing China * 8aecfc01dSrui zang - Sun Microsystems - Beijing China * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9aecfc01dSrui zang - Sun Microsystems - Beijing China * or http://www.opensolaris.org/os/licensing. 10aecfc01dSrui zang - Sun Microsystems - Beijing China * See the License for the specific language governing permissions 11aecfc01dSrui zang - Sun Microsystems - Beijing China * and limitations under the License. 12aecfc01dSrui zang - Sun Microsystems - Beijing China * 13aecfc01dSrui zang - Sun Microsystems - Beijing China * When distributing Covered Code, include this CDDL HEADER in each 14aecfc01dSrui zang - Sun Microsystems - Beijing China * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15aecfc01dSrui zang - Sun Microsystems - Beijing China * If applicable, add the following below this CDDL HEADER, with the 16aecfc01dSrui zang - Sun Microsystems - Beijing China * fields enclosed by brackets "[]" replaced with your own identifying 17aecfc01dSrui zang - Sun Microsystems - Beijing China * information: Portions Copyright [yyyy] [name of copyright owner] 18aecfc01dSrui zang - Sun Microsystems - Beijing China * 19aecfc01dSrui zang - Sun Microsystems - Beijing China * CDDL HEADER END 20aecfc01dSrui zang - Sun Microsystems - Beijing China */ 21aecfc01dSrui zang - Sun Microsystems - Beijing China /* 22*ceeba6f9Srui zang - Sun Microsystems - Beijing China * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 23aecfc01dSrui zang - Sun Microsystems - Beijing China */ 24aecfc01dSrui zang - Sun Microsystems - Beijing China 25aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/types.h> 26aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/param.h> 27aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/termios.h> 28aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/stream.h> 29aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/stropts.h> 30aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/kmem.h> 31aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/stat.h> 32aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/sunddi.h> 33aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/ddi.h> 34aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/bitmap.h> 35aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/sysmacros.h> 36aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/ddi_impldefs.h> 37aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/zone.h> 38aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/thread.h> 39aecfc01dSrui zang - Sun Microsystems - Beijing China #ifdef DEBUG 40aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/strlog.h> 41aecfc01dSrui zang - Sun Microsystems - Beijing China #endif 42aecfc01dSrui zang - Sun Microsystems - Beijing China 43aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/consdev.h> 44aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/console.h> 45aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/wscons.h> 46aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/vt_impl.h> 47aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/note.h> 48aecfc01dSrui zang - Sun Microsystems - Beijing China #include <sys/avl.h> 49aecfc01dSrui zang - Sun Microsystems - Beijing China 50aecfc01dSrui zang - Sun Microsystems - Beijing China /* set if console driver is attached */ 51aecfc01dSrui zang - Sun Microsystems - Beijing China dev_info_t *wc_dip = NULL; 52aecfc01dSrui zang - Sun Microsystems - Beijing China /* active virtual console minor number */ 53aecfc01dSrui zang - Sun Microsystems - Beijing China minor_t vc_active_console = VT_MINOR_INVALID; 54*ceeba6f9Srui zang - Sun Microsystems - Beijing China /* 55*ceeba6f9Srui zang - Sun Microsystems - Beijing China * console_user symbol link minor number. 56*ceeba6f9Srui zang - Sun Microsystems - Beijing China * VT_MINOR_INVALID : /dev/console 57*ceeba6f9Srui zang - Sun Microsystems - Beijing China * N : /dev/vt/N 58*ceeba6f9Srui zang - Sun Microsystems - Beijing China */ 59*ceeba6f9Srui zang - Sun Microsystems - Beijing China minor_t vc_cons_user = VT_MINOR_INVALID; 60aecfc01dSrui zang - Sun Microsystems - Beijing China /* vc_state_t AVL tree */ 61aecfc01dSrui zang - Sun Microsystems - Beijing China avl_tree_t vc_avl_root; 62aecfc01dSrui zang - Sun Microsystems - Beijing China /* virtual console global lock */ 63aecfc01dSrui zang - Sun Microsystems - Beijing China kmutex_t vc_lock; 64aecfc01dSrui zang - Sun Microsystems - Beijing China 65*ceeba6f9Srui zang - Sun Microsystems - Beijing China _NOTE(MUTEX_PROTECTS_DATA(vc_lock, wc_dip vc_avl_root vc_active_console 66*ceeba6f9Srui zang - Sun Microsystems - Beijing China vc_cons_user)) 67aecfc01dSrui zang - Sun Microsystems - Beijing China 68aecfc01dSrui zang - Sun Microsystems - Beijing China /* 69aecfc01dSrui zang - Sun Microsystems - Beijing China * Called from vt devname part. Checks if dip is attached. If it is, 70aecfc01dSrui zang - Sun Microsystems - Beijing China * return its major number. 71aecfc01dSrui zang - Sun Microsystems - Beijing China */ 72aecfc01dSrui zang - Sun Microsystems - Beijing China major_t 73aecfc01dSrui zang - Sun Microsystems - Beijing China vt_wc_attached(void) 74aecfc01dSrui zang - Sun Microsystems - Beijing China { 75aecfc01dSrui zang - Sun Microsystems - Beijing China major_t maj = (major_t)-1; 76aecfc01dSrui zang - Sun Microsystems - Beijing China 77aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 78aecfc01dSrui zang - Sun Microsystems - Beijing China 79aecfc01dSrui zang - Sun Microsystems - Beijing China if (wc_dip) 80aecfc01dSrui zang - Sun Microsystems - Beijing China maj = ddi_driver_major(wc_dip); 81aecfc01dSrui zang - Sun Microsystems - Beijing China 82aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 83aecfc01dSrui zang - Sun Microsystems - Beijing China 84aecfc01dSrui zang - Sun Microsystems - Beijing China return (maj); 85aecfc01dSrui zang - Sun Microsystems - Beijing China } 86aecfc01dSrui zang - Sun Microsystems - Beijing China 87aecfc01dSrui zang - Sun Microsystems - Beijing China void 88aecfc01dSrui zang - Sun Microsystems - Beijing China vt_getactive(char *buf, int buflen) 89aecfc01dSrui zang - Sun Microsystems - Beijing China { 90aecfc01dSrui zang - Sun Microsystems - Beijing China ASSERT(buf); 91aecfc01dSrui zang - Sun Microsystems - Beijing China ASSERT(buflen != 0); 92aecfc01dSrui zang - Sun Microsystems - Beijing China 93aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 94aecfc01dSrui zang - Sun Microsystems - Beijing China 95aecfc01dSrui zang - Sun Microsystems - Beijing China if (vc_active_console == 0 || vc_active_console == VT_MINOR_INVALID) 96aecfc01dSrui zang - Sun Microsystems - Beijing China (void) snprintf(buf, buflen, "/dev/console"); 97aecfc01dSrui zang - Sun Microsystems - Beijing China else 98*ceeba6f9Srui zang - Sun Microsystems - Beijing China (void) snprintf(buf, buflen, "%u", vc_active_console); 99aecfc01dSrui zang - Sun Microsystems - Beijing China 100aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 101aecfc01dSrui zang - Sun Microsystems - Beijing China } 102aecfc01dSrui zang - Sun Microsystems - Beijing China 103*ceeba6f9Srui zang - Sun Microsystems - Beijing China void 104*ceeba6f9Srui zang - Sun Microsystems - Beijing China vt_getconsuser(char *buf, int buflen) 105*ceeba6f9Srui zang - Sun Microsystems - Beijing China { 106*ceeba6f9Srui zang - Sun Microsystems - Beijing China ASSERT(buf); 107*ceeba6f9Srui zang - Sun Microsystems - Beijing China ASSERT(buflen != 0); 108*ceeba6f9Srui zang - Sun Microsystems - Beijing China 109*ceeba6f9Srui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 110*ceeba6f9Srui zang - Sun Microsystems - Beijing China 111*ceeba6f9Srui zang - Sun Microsystems - Beijing China if (vc_cons_user == VT_MINOR_INVALID) { 112*ceeba6f9Srui zang - Sun Microsystems - Beijing China (void) snprintf(buf, buflen, "/dev/console"); 113*ceeba6f9Srui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 114*ceeba6f9Srui zang - Sun Microsystems - Beijing China return; 115*ceeba6f9Srui zang - Sun Microsystems - Beijing China } 116*ceeba6f9Srui zang - Sun Microsystems - Beijing China 117*ceeba6f9Srui zang - Sun Microsystems - Beijing China (void) snprintf(buf, buflen, "%u", vc_cons_user); 118*ceeba6f9Srui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 119*ceeba6f9Srui zang - Sun Microsystems - Beijing China } 120*ceeba6f9Srui zang - Sun Microsystems - Beijing China 121aecfc01dSrui zang - Sun Microsystems - Beijing China boolean_t 122aecfc01dSrui zang - Sun Microsystems - Beijing China vt_minor_valid(minor_t minor) 123aecfc01dSrui zang - Sun Microsystems - Beijing China { 124aecfc01dSrui zang - Sun Microsystems - Beijing China if (consmode == CONS_FW) { 125aecfc01dSrui zang - Sun Microsystems - Beijing China if (minor == 0) 126aecfc01dSrui zang - Sun Microsystems - Beijing China return (B_TRUE); 127aecfc01dSrui zang - Sun Microsystems - Beijing China 128aecfc01dSrui zang - Sun Microsystems - Beijing China return (B_FALSE); 129aecfc01dSrui zang - Sun Microsystems - Beijing China } 130aecfc01dSrui zang - Sun Microsystems - Beijing China 131aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_enter(&vc_lock); 132aecfc01dSrui zang - Sun Microsystems - Beijing China if (minor < VC_INSTANCES_COUNT) { 133aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 134aecfc01dSrui zang - Sun Microsystems - Beijing China return (B_TRUE); 135aecfc01dSrui zang - Sun Microsystems - Beijing China } 136aecfc01dSrui zang - Sun Microsystems - Beijing China 137aecfc01dSrui zang - Sun Microsystems - Beijing China mutex_exit(&vc_lock); 138aecfc01dSrui zang - Sun Microsystems - Beijing China return (B_FALSE); 139aecfc01dSrui zang - Sun Microsystems - Beijing China 140aecfc01dSrui zang - Sun Microsystems - Beijing China } 141