xref: /illumos-gate/usr/src/uts/common/xen/io/xencons.h (revision e2a8479967f5e2ae9ba0aa265cfa175d7874b057)
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 (c) 1990, 1991 UNIX System Laboratories, Inc.	*/
23 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T	*/
24 /*	  All Rights Reserved 	*/
25 
26 /*
27  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef	_SYS_XENCONS_H
32 #define	_SYS_XENCONS_H
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 #include <sys/tty.h>
39 #include <sys/ksynch.h>
40 #include <sys/dditypes.h>
41 #include <xen/public/io/console.h>
42 
43 
44 /*
45  * Xencons tracing macros.  These are a similar to some macros in sys/vtrace.h.
46  *
47  * XXX - Needs review:  would it be better to use the macros in sys/vtrace.h ?
48  */
49 #ifdef DEBUG
50 #define	DEBUGWARN0(fac, format) \
51 	if (debug & (fac)) \
52 		cmn_err(CE_WARN, format)
53 #define	DEBUGNOTE0(fac, format) \
54 	if (debug & (fac)) \
55 		cmn_err(CE_NOTE, format)
56 #define	DEBUGNOTE1(fac, format, arg1) \
57 	if (debug & (fac)) \
58 		cmn_err(CE_NOTE, format, arg1)
59 #define	DEBUGNOTE2(fac, format, arg1, arg2) \
60 	if (debug & (fac)) \
61 		cmn_err(CE_NOTE, format, arg1, arg2)
62 #define	DEBUGNOTE3(fac, format, arg1, arg2, arg3) \
63 	if (debug & (fac)) \
64 		cmn_err(CE_NOTE, format, arg1, arg2, arg3)
65 #define	DEBUGCONT0(fac, format) \
66 	if (debug & (fac)) \
67 		cmn_err(CE_CONT, format)
68 #define	DEBUGCONT1(fac, format, arg1) \
69 	if (debug & (fac)) \
70 		cmn_err(CE_CONT, format, arg1)
71 #define	DEBUGCONT2(fac, format, arg1, arg2) \
72 	if (debug & (fac)) \
73 		cmn_err(CE_CONT, format, arg1, arg2)
74 #define	DEBUGCONT3(fac, format, arg1, arg2, arg3) \
75 	if (debug & (fac)) \
76 		cmn_err(CE_CONT, format, arg1, arg2, arg3)
77 #define	DEBUGCONT4(fac, format, arg1, arg2, arg3, arg4) \
78 	if (debug & (fac)) \
79 		cmn_err(CE_CONT, format, arg1, arg2, arg3, arg4)
80 #define	DEBUGCONT10(fac, format, \
81 	arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10) \
82 	if (debug & (fac)) \
83 		cmn_err(CE_CONT, format, \
84 		arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
85 #else
86 #define	DEBUGWARN0(fac, format)
87 #define	DEBUGNOTE0(fac, format)
88 #define	DEBUGNOTE1(fac, format, arg1)
89 #define	DEBUGNOTE2(fac, format, arg1, arg2)
90 #define	DEBUGNOTE3(fac, format, arg1, arg2, arg3)
91 #define	DEBUGCONT0(fac, format)
92 #define	DEBUGCONT1(fac, format, arg1)
93 #define	DEBUGCONT2(fac, format, arg1, arg2)
94 #define	DEBUGCONT3(fac, format, arg1, arg2, arg3)
95 #define	DEBUGCONT4(fac, format, arg1, arg2, arg3, arg4)
96 #define	DEBUGCONT10(fac, format, \
97 	arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10)
98 #endif
99 
100 /* enum value for sw and hw flow control action */
101 typedef enum {
102 	FLOW_CHECK,
103 	FLOW_STOP,
104 	FLOW_START
105 } async_flowc_action;
106 
107 #define	async_stopc	async_ttycommon.t_stopc
108 #define	async_startc	async_ttycommon.t_startc
109 
110 /*
111  * Console instance data.
112  * Each of the fields in this structure is required to be protected by a
113  * mutex lock at the highest priority at which it can be altered.
114  */
115 
116 struct xencons {
117 	int		flags;	/* random flags  */
118 	struct asyncline *priv;	/* protocol private data -- asyncline */
119 	dev_info_t	*dip;	/* dev_info */
120 	int		unit;	/* which port */
121 	kmutex_t	excl;	/* adaptive mutex */
122 	kcondvar_t	excl_cv;	/* condition variable */
123 	struct cons_polledio polledio;	/* polled I/O functions */
124 	unsigned char	pollbuf[60];	/* polled I/O data */
125 	int		polldix;	/* polled data buffer index */
126 	int		polllen;	/* polled data buffer length */
127 	volatile struct xencons_interface *ifp;	/* console ring buffers */
128 	int		console_irq;	/* dom0 console interrupt */
129 	int		evtchn;		/* console event channel */
130 };
131 
132 /*
133  * Asychronous protocol private data structure for ASY.
134  * Each of the fields in the structure is required to be protected by
135  * the lower priority lock except the fields that are set only at
136  * base level but cleared (with out lock) at interrupt level.
137  */
138 
139 struct asyncline {
140 	int		async_flags;	/* random flags */
141 	kcondvar_t	async_flags_cv; /* condition variable for flags */
142 	dev_t		async_dev;	/* device major/minor numbers */
143 	mblk_t		*async_xmitblk;	/* transmit: active msg block */
144 	struct xencons	*async_common;	/* device common data */
145 	tty_common_t 	async_ttycommon; /* tty driver common data */
146 	bufcall_id_t	async_wbufcid;	/* id for pending write-side bufcall */
147 	timeout_id_t	async_polltid;	/* softint poll timeout id */
148 	timeout_id_t    async_dtrtid;   /* delaying DTR turn on */
149 	timeout_id_t    async_utbrktid; /* hold minimum untimed break time id */
150 
151 	/*
152 	 * The following fields are protected by the excl_hi lock.
153 	 * Some, such as async_flowc, are set only at the base level and
154 	 * cleared (without the lock) only by the interrupt level.
155 	 */
156 	uchar_t		*async_optr;	/* output pointer */
157 	int		async_ocnt;	/* output count */
158 	ushort_t	async_rput;	/* producing pointer for input */
159 	ushort_t	async_rget;	/* consuming pointer for input */
160 	int		async_inflow_source; /* input flow control type */
161 
162 	union {
163 		struct {
164 			uchar_t _hw;	/* overrun (hw) */
165 			uchar_t _sw;	/* overrun (sw) */
166 		} _a;
167 		ushort_t uover_overrun;
168 	} async_uover;
169 #define	async_overrun		async_uover._a.uover_overrun
170 #define	async_hw_overrun	async_uover._a._hw
171 #define	async_sw_overrun	async_uover._a._sw
172 	short		async_ext;	/* modem status change count */
173 	short		async_work;	/* work to do flag */
174 };
175 
176 /* definitions for async_flags field */
177 #define	ASYNC_EXCL_OPEN	 0x10000000	/* exclusive open */
178 #define	ASYNC_WOPEN	 0x00000001	/* waiting for open to complete */
179 #define	ASYNC_ISOPEN	 0x00000002	/* open is complete */
180 #define	ASYNC_STOPPED	 0x00000010	/* output is stopped */
181 #define	ASYNC_PROGRESS	 0x00001000	/* made progress on output effort */
182 #define	ASYNC_CLOSING	 0x00002000	/* processing close on stream */
183 #define	ASYNC_SW_IN_FLOW 0x00020000	/* sw input flow control in effect */
184 #define	ASYNC_SW_OUT_FLW 0x00040000	/* sw output flow control in effect */
185 #define	ASYNC_SW_IN_NEEDED 0x00080000	/* sw input flow control char is */
186 					/* needed to be sent */
187 #define	ASYNC_OUT_FLW_RESUME 0x00100000 /* output need to be resumed */
188 					/* because of transition of flow */
189 					/* control from stop to start */
190 
191 
192 /* definitions for asy_flags field */
193 #define	ASY_CONSOLE	0x00000080
194 
195 /* definitions for async_inflow_source field in struct asyncline */
196 #define	IN_FLOW_NULL	0x00000000
197 #define	IN_FLOW_STREAMS	0x00000002
198 #define	IN_FLOW_USER	0x00000004
199 
200 #define	XENCONS_BURST	128	/* burst size for console writes */
201 
202 #ifdef __cplusplus
203 }
204 #endif
205 
206 #endif	/* _SYS_XENCONS_H */
207