summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/io/vcons_conf.c
blob: 5cdcff2ee620307f3a3ddc684aca458b77e8c9a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
 */

#include <sys/types.h>
#include <sys/param.h>
#include <sys/termios.h>
#include <sys/stream.h>
#include <sys/stropts.h>
#include <sys/kmem.h>
#include <sys/stat.h>
#include <sys/sunddi.h>
#include <sys/ddi.h>
#include <sys/bitmap.h>
#include <sys/sysmacros.h>
#include <sys/ddi_impldefs.h>
#include <sys/zone.h>
#include <sys/thread.h>
#ifdef DEBUG
#include <sys/strlog.h>
#endif

#include <sys/consdev.h>
#include <sys/console.h>
#include <sys/wscons.h>
#include <sys/vt_impl.h>
#include <sys/note.h>
#include <sys/avl.h>

/* set if console driver is attached */
dev_info_t *wc_dip = NULL;
/* active virtual console minor number */
minor_t vc_active_console = VT_MINOR_INVALID;
/*
 * console_user symbol link minor number.
 * VT_MINOR_INVALID	:	/dev/console
 * 	N		: 	/dev/vt/N
 */
minor_t vc_cons_user = VT_MINOR_INVALID;
/* vc_state_t AVL tree */
avl_tree_t vc_avl_root;
/* virtual console global lock */
kmutex_t vc_lock;

_NOTE(MUTEX_PROTECTS_DATA(vc_lock, wc_dip vc_avl_root vc_active_console
vc_cons_user))

/*
 * Called from vt devname part. Checks if dip is attached. If it is,
 * return its major number.
 */
major_t
vt_wc_attached(void)
{
	major_t maj = (major_t)-1;

	mutex_enter(&vc_lock);

	if (wc_dip)
		maj = ddi_driver_major(wc_dip);

	mutex_exit(&vc_lock);

	return (maj);
}

void
vt_getactive(char *buf, int buflen)
{
	ASSERT(buf);
	ASSERT(buflen != 0);

	mutex_enter(&vc_lock);

	if (vc_active_console == 0 || vc_active_console == VT_MINOR_INVALID)
		(void) snprintf(buf, buflen, "/dev/console");
	else
		(void) snprintf(buf, buflen, "%u", vc_active_console);

	mutex_exit(&vc_lock);
}

void
vt_getconsuser(char *buf, int buflen)
{
	ASSERT(buf);
	ASSERT(buflen != 0);

	mutex_enter(&vc_lock);

	if (vc_cons_user == VT_MINOR_INVALID) {
		(void) snprintf(buf, buflen, "/dev/console");
		mutex_exit(&vc_lock);
		return;
	}

	(void) snprintf(buf, buflen, "%u", vc_cons_user);
	mutex_exit(&vc_lock);
}

boolean_t
vt_minor_valid(minor_t minor)
{
	if (consmode == CONS_FW) {
		if (minor == 0)
			return (B_TRUE);

		return (B_FALSE);
	}

	mutex_enter(&vc_lock);
	if (minor < VC_INSTANCES_COUNT) {
		mutex_exit(&vc_lock);
		return (B_TRUE);
	}

	mutex_exit(&vc_lock);
	return (B_FALSE);

}