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