xref: /titanic_41/usr/src/uts/common/io/vcons_conf.c (revision cde2885fdf538266ee2a3b08dee2d5075ce8fa2b)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <sys/types.h>
27 #include <sys/param.h>
28 #include <sys/termios.h>
29 #include <sys/stream.h>
30 #include <sys/stropts.h>
31 #include <sys/kmem.h>
32 #include <sys/stat.h>
33 #include <sys/sunddi.h>
34 #include <sys/ddi.h>
35 #include <sys/bitmap.h>
36 #include <sys/sysmacros.h>
37 #include <sys/ddi_impldefs.h>
38 #include <sys/zone.h>
39 #include <sys/thread.h>
40 #ifdef DEBUG
41 #include <sys/strlog.h>
42 #endif
43 
44 #include <sys/consdev.h>
45 #include <sys/console.h>
46 #include <sys/wscons.h>
47 #include <sys/vt_impl.h>
48 #include <sys/note.h>
49 #include <sys/avl.h>
50 
51 /* set if console driver is attached */
52 dev_info_t *wc_dip = NULL;
53 /* active virtual console minor number */
54 minor_t vc_active_console = VT_MINOR_INVALID;
55 /* vc_state_t AVL tree */
56 avl_tree_t vc_avl_root;
57 /* virtual console global lock */
58 kmutex_t vc_lock;
59 
60 _NOTE(MUTEX_PROTECTS_DATA(vc_lock, wc_dip vc_avl_root vc_active_console))
61 
62 /*
63  * Called from vt devname part. Checks if dip is attached. If it is,
64  * return its major number.
65  */
66 major_t
67 vt_wc_attached(void)
68 {
69 	major_t maj = (major_t)-1;
70 
71 	mutex_enter(&vc_lock);
72 
73 	if (wc_dip)
74 		maj = ddi_driver_major(wc_dip);
75 
76 	mutex_exit(&vc_lock);
77 
78 	return (maj);
79 }
80 
81 void
82 vt_getactive(char *buf, int buflen)
83 {
84 	ASSERT(buf);
85 	ASSERT(buflen != 0);
86 
87 	mutex_enter(&vc_lock);
88 
89 	if (vc_active_console == 0 || vc_active_console == VT_MINOR_INVALID)
90 		(void) snprintf(buf, buflen, "/dev/console");
91 	else
92 		(void) snprintf(buf, buflen, "%d", vc_active_console);
93 
94 	mutex_exit(&vc_lock);
95 }
96 
97 boolean_t
98 vt_minor_valid(minor_t minor)
99 {
100 	if (consmode == CONS_FW) {
101 		if (minor == 0)
102 			return (B_TRUE);
103 
104 		return (B_FALSE);
105 	}
106 
107 	mutex_enter(&vc_lock);
108 	if (minor < VC_INSTANCES_COUNT) {
109 		mutex_exit(&vc_lock);
110 		return (B_TRUE);
111 	}
112 
113 	mutex_exit(&vc_lock);
114 	return (B_FALSE);
115 
116 }
117