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