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