xref: /illumos-gate/usr/src/uts/common/sys/vt_impl.h (revision ceeba6f9)
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 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef _SYS_VT_IMPL_H
27 #define	_SYS_VT_IMPL_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/types.h>
34 #include <sys/stream.h>
35 #include <sys/vt.h>
36 #include <sys/kd.h>
37 #include <sys/tem.h>
38 #include <sys/tty.h>
39 #include <sys/cred.h>
40 #include <sys/list.h>
41 #include <sys/avl.h>
42 #include <sys/note.h>
43 
44 #define	WCS_INIT	0x00000001	/* tty is init */
45 #define	WCS_ISOPEN	0x00000002	/* open is complete */
46 #define	WCS_STOPPED	0x00000004	/* output is stopped */
47 #define	WCS_DELAY	0x00000008	/* waiting for delay to finish */
48 #define	WCS_BUSY	0x00000010	/* waiting for transmission to finish */
49 
50 typedef struct vc_waitactive_msg {
51 	list_node_t	wa_list_node;
52 	int	wa_msg_minor;		/* minor number from which msg comes */
53 	int	wa_wait_minor;		/* which node we are waiting for */
54 	mblk_t *wa_mp;
55 } vc_waitactive_msg_t;
56 
57 /* virtual console soft state associated with each vt */
58 typedef struct vc_state {
59 	minor_t	vc_minor;
60 	avl_node_t vc_avl_node;
61 	uchar_t	vc_switch_mode;		/* VT_AUTO or VT_PROCESS */
62 	char	vc_waitv;
63 	int	vc_relsig;
64 	int	vc_acqsig;
65 	pid_t	vc_pid;
66 	minor_t	vc_switchto;
67 	int	vc_flags;
68 
69 	int	vc_dispnum;
70 	int	vc_login;
71 
72 	tem_vt_state_t vc_tem;		/* Terminal emulator state */
73 	tty_common_t vc_ttycommon;	/* data common to all tty drivers */
74 	bufcall_id_t vc_bufcallid;	/* id returned by qbufcall */
75 	timeout_id_t vc_timeoutid;	/* id returned by qtimeout */
76 
77 	queue_t	*vc_wq;			/* write queue */
78 
79 #ifdef _HAVE_TEM_FIRMWARE
80 	int	vc_pendc;		/* pending output character */
81 #endif /* _HAVE_TEM_FIRMWARE */
82 
83 	/*
84 	 * vc_state_lock is currently only used to protect vc_flags,
85 	 * more precisely, the state change of vc_state_t.
86 	 * The existence of this lock is because wc_modechg_cb().
87 	 * wc_modechg_cb() is a callback function which may result in
88 	 * multiple threads accessing vc_flags regardless the STREAMS
89 	 * periemters of wc module.
90 	 * Since wc_modechg_cb() only conducts read access to vc_flags,
91 	 * we only need to hold this lock when writing to vc_flags in
92 	 * wc module (except wc_modechg_cb()).
93 	 * See locking policy in wscons.c for more info.
94 	 */
95 	kmutex_t vc_state_lock;
96 } vc_state_t;
97 _NOTE(MUTEX_PROTECTS_DATA(vc_state_t::vc_state_lock, vc_state_t::vc_flags))
98 
99 #define	VC_DEFAULT_COUNT	16
100 
101 /* Invalid VT minor number */
102 #define	VT_MINOR_INVALID	((minor_t)-1)
103 /* Argument to vt_minor2vc to get the softstate of the active VT */
104 #define	VT_ACTIVE		VT_MINOR_INVALID
105 
106 /*
107  * VC_INSTANCES_COUNT should be regarded as reading access to vc_avl_root
108  */
109 #define	VC_INSTANCES_COUNT	(avl_numnodes(&vc_avl_root))
110 
111 void vt_ioctl(queue_t *q, mblk_t *mp);
112 void vt_miocdata(queue_t *qp, mblk_t *mp);
113 void vt_clean(queue_t *q, vc_state_t *pvc);
114 void vt_close(queue_t *q, vc_state_t *pvc, cred_t *crp);
115 int vt_open(minor_t minor, queue_t *rq, cred_t *crp);
116 int vt_check_hotkeys(mblk_t *mp);
117 vc_state_t *vt_minor2vc(minor_t);
118 
119 extern dev_info_t *wc_dip;
120 extern avl_tree_t vc_avl_root;
121 extern minor_t	vc_active_console;
122 extern minor_t	vc_cons_user;
123 extern kmutex_t vc_lock;
124 extern minor_t vc_last_console;
125 
126 major_t vt_wc_attached(void);
127 void vt_getactive(char *, int);
128 void vt_getconsuser(char *, int);
129 boolean_t vt_minor_valid(minor_t minor);
130 void vt_resize(uint_t);
131 void vt_attach(void);
132 void vt_init(void);
133 
134 #ifdef __cplusplus
135 }
136 #endif
137 
138 #endif /* _SYS_VT_IMPL_H */
139