xref: /original-bsd/sys/sys/tty.h (revision f43778ea)
1 /*-
2  * Copyright (c) 1982, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * %sccs.include.redist.c%
11  *
12  *	@(#)tty.h	8.7 (Berkeley) 01/09/95
13  */
14 
15 #include <sys/termios.h>
16 #include <sys/select.h>		/* For struct selinfo. */
17 
18 /*
19  * Clists are character lists, which is a variable length linked list
20  * of cblocks, with a count of the number of characters in the list.
21  */
22 struct clist {
23 	int	c_cc;		/* Number of characters in the clist. */
24 	char	*c_cf;		/* Pointer to the first cblock. */
25 	char	*c_cl;		/* Pointer to the last cblock. */
26 };
27 
28 /*
29  * Per-tty structure.
30  *
31  * Should be split in two, into device and tty drivers.
32  * Glue could be masks of what to echo and circular buffer
33  * (low, high, timeout).
34  */
35 struct tty {
36 	struct	clist t_rawq;		/* Device raw input queue. */
37 	long	t_rawcc;		/* Raw input queue statistics. */
38 	struct	clist t_canq;		/* Device canonical queue. */
39 	long	t_cancc;		/* Canonical queue statistics. */
40 	struct	clist t_outq;		/* Device output queue. */
41 	long	t_outcc;		/* Output queue statistics. */
42 	u_char	t_line;			/* Interface to device drivers. */
43 	dev_t	t_dev;			/* Device. */
44 	int	t_state;		/* Device and driver (TS*) state. */
45 	int	t_flags;		/* Tty flags. */
46 	struct	pgrp *t_pgrp;		/* Foreground process group. */
47 	struct	session *t_session;	/* Enclosing session. */
48 	struct	selinfo t_rsel;		/* Tty read/oob select. */
49 	struct	selinfo t_wsel;		/* Tty write select. */
50 	struct	termios t_termios;	/* Termios state. */
51 	struct	winsize t_winsize;	/* Window size. */
52 					/* Start output. */
53 	void	(*t_oproc) __P((struct tty *));
54 					/* Stop output. */
55 	void	(*t_stop) __P((struct tty *, int));
56 					/* Set hardware state. */
57 	int	(*t_param) __P((struct tty *, struct termios *));
58 	void	*t_sc;			/* XXX: net/if_sl.c:sl_softc. */
59 	short	t_column;		/* Tty output column. */
60 	short	t_rocount, t_rocol;	/* Tty. */
61 	short	t_hiwat;		/* High water mark. */
62 	short	t_lowat;		/* Low water mark. */
63 	short	t_gen;			/* Generation number. */
64 };
65 
66 #define	t_cc		t_termios.c_cc
67 #define	t_cflag		t_termios.c_cflag
68 #define	t_iflag		t_termios.c_iflag
69 #define	t_ispeed	t_termios.c_ispeed
70 #define	t_lflag		t_termios.c_lflag
71 #define	t_min		t_termios.c_min
72 #define	t_oflag		t_termios.c_oflag
73 #define	t_ospeed	t_termios.c_ospeed
74 #define	t_time		t_termios.c_time
75 
76 #define	TTIPRI	25			/* Sleep priority for tty reads. */
77 #define	TTOPRI	26			/* Sleep priority for tty writes. */
78 
79 #define	TTMASK	15
80 #define	OBUFSIZ	100
81 #define	TTYHOG	1024
82 
83 #ifdef KERNEL
84 #define	TTMAXHIWAT	roundup(2048, CBSIZE)
85 #define	TTMINHIWAT	roundup(100, CBSIZE)
86 #define	TTMAXLOWAT	256
87 #define	TTMINLOWAT	32
88 #endif
89 
90 /* These flags are kept in t_state. */
91 #define	TS_ASLEEP	0x00001		/* Process waiting for tty. */
92 #define	TS_ASYNC	0x00002		/* Tty in async I/O mode. */
93 #define	TS_BUSY		0x00004		/* Draining output. */
94 #define	TS_CARR_ON	0x00008		/* Carrier is present. */
95 #define	TS_FLUSH	0x00010		/* Outq has been flushed during DMA. */
96 #define	TS_ISOPEN	0x00020		/* Open has completed. */
97 #define	TS_TBLOCK	0x00040		/* Further input blocked. */
98 #define	TS_TIMEOUT	0x00080		/* Wait for output char processing. */
99 #define	TS_TTSTOP	0x00100		/* Output paused. */
100 #define	TS_WOPEN	0x00200		/* Open in progress. */
101 #define	TS_XCLUDE	0x00400		/* Tty requires exclusivity. */
102 
103 /* State for intra-line fancy editing work. */
104 #define	TS_BKSL		0x00800		/* State for lowercase \ work. */
105 #define	TS_CNTTB	0x01000		/* Counting tab width, ignore FLUSHO. */
106 #define	TS_ERASE	0x02000		/* Within a \.../ for PRTRUB. */
107 #define	TS_LNCH		0x04000		/* Next character is literal. */
108 #define	TS_TYPEN	0x08000		/* Retyping suspended input (PENDIN). */
109 #define	TS_LOCAL	(TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
110 
111 /* Character type information. */
112 #define	ORDINARY	0
113 #define	CONTROL		1
114 #define	BACKSPACE	2
115 #define	NEWLINE		3
116 #define	TAB		4
117 #define	VTAB		5
118 #define	RETURN		6
119 
120 struct speedtab {
121 	int sp_speed;			/* Speed. */
122 	int sp_code;			/* Code. */
123 };
124 
125 /* Modem control commands (driver). */
126 #define	DMSET		0
127 #define	DMBIS		1
128 #define	DMBIC		2
129 #define	DMGET		3
130 
131 /* Flags on a character passed to ttyinput. */
132 #define	TTY_CHARMASK	0x000000ff	/* Character mask */
133 #define	TTY_QUOTE	0x00000100	/* Character quoted */
134 #define	TTY_ERRORMASK	0xff000000	/* Error mask */
135 #define	TTY_FE		0x01000000	/* Framing error or BREAK condition */
136 #define	TTY_PE		0x02000000	/* Parity error */
137 
138 /* Is tp controlling terminal for p? */
139 #define	isctty(p, tp)							\
140 	((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
141 
142 /* Is p in background of tp? */
143 #define	isbackground(p, tp)						\
144 	(isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
145 
146 #ifdef KERNEL
147 extern	struct ttychars ttydefaults;
148 
149 /* Symbolic sleep message strings. */
150 extern	 char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[];
151 
152 int	 b_to_q __P((char *cp, int cc, struct clist *q));
153 void	 catq __P((struct clist *from, struct clist *to));
154 void	 clist_init __P((void));
155 int	 getc __P((struct clist *q));
156 void	 ndflush __P((struct clist *q, int cc));
157 int	 ndqb __P((struct clist *q, int flag));
158 char	*nextc __P((struct clist *q, char *cp, int *c));
159 int	 putc __P((int c, struct clist *q));
160 int	 q_to_b __P((struct clist *q, char *cp, int cc));
161 int	 unputc __P((struct clist *q));
162 
163 int	 nullmodem __P((struct tty *tp, int flag));
164 int	 tputchar __P((int c, struct tty *tp));
165 int	 ttioctl __P((struct tty *tp, u_long com, void *data, int flag));
166 int	 ttread __P((struct tty *tp, struct uio *uio, int flag));
167 void	 ttrstrt __P((void *tp));
168 int	 ttselect __P((dev_t device, int rw, struct proc *p));
169 void	 ttsetwater __P((struct tty *tp));
170 int	 ttspeedtab __P((int speed, struct speedtab *table));
171 int	 ttstart __P((struct tty *tp));
172 void	 ttwakeup __P((struct tty *tp));
173 int	 ttwrite __P((struct tty *tp, struct uio *uio, int flag));
174 void	 ttychars __P((struct tty *tp));
175 int	 ttycheckoutq __P((struct tty *tp, int wait));
176 int	 ttyclose __P((struct tty *tp));
177 void	 ttyflush __P((struct tty *tp, int rw));
178 void	 ttyinfo __P((struct tty *tp));
179 int	 ttyinput __P((int c, struct tty *tp));
180 int	 ttylclose __P((struct tty *tp, int flag));
181 int	 ttymodem __P((struct tty *tp, int flag));
182 int	 ttyopen __P((dev_t device, struct tty *tp));
183 int	 ttyoutput __P((int c, struct tty *tp));
184 void	 ttypend __P((struct tty *tp));
185 void	 ttyretype __P((struct tty *tp));
186 void	 ttyrub __P((int c, struct tty *tp));
187 int	 ttysleep __P((struct tty *tp,
188 	    void *chan, int pri, char *wmesg, int timeout));
189 int	 ttywait __P((struct tty *tp));
190 int	 ttywflush __P((struct tty *tp));
191 #endif
192