FreeBSD/Linux Kernel Cross Reference
sys/sys/tty.h
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 * Copyright (c) 2002 Networks Associates Technologies, Inc.
11 * All rights reserved.
12 *
13 * Portions of this software were developed for the FreeBSD Project by
14 * ThinkSec AS and NAI Labs, the Security Research Division of Network
15 * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035
16 * ("CBOSS"), as part of the DARPA CHATS research program.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the
25 * documentation and/or other materials provided with the distribution.
26 * 4. Neither the name of the University nor the names of its contributors
27 * may be used to endorse or promote products derived from this software
28 * without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * SUCH DAMAGE.
41 *
42 * @(#)tty.h 8.6 (Berkeley) 1/21/94
43 * $FreeBSD: releng/5.4/sys/sys/tty.h 145335 2005-04-20 19:11:07Z cvs2svn $
44 */
45
46 #ifndef _SYS_TTY_H_
47 #define _SYS_TTY_H_
48
49 #include <sys/termios.h>
50 #include <sys/queue.h>
51 #include <sys/selinfo.h>
52 #include <sys/_lock.h>
53 #include <sys/_mutex.h>
54
55 /*
56 * Clists are character lists, which is a variable length linked list
57 * of cblocks, with a count of the number of characters in the list.
58 */
59 struct clist {
60 int c_cc; /* Number of characters in the clist. */
61 int c_cbcount; /* Number of cblocks. */
62 int c_cbmax; /* Max # cblocks allowed for this clist. */
63 int c_cbreserved; /* # cblocks reserved for this clist. */
64 char *c_cf; /* Pointer to the first cblock. */
65 char *c_cl; /* Pointer to the last cblock. */
66 };
67
68 struct tty;
69
70 typedef void t_oproc_t(struct tty *);
71 typedef void t_stop_t(struct tty *, int);
72 typedef int t_param_t(struct tty *, struct termios *);
73 typedef int t_modem_t(struct tty *, int, int);
74 typedef void t_break_t(struct tty *, int);
75 typedef int t_ioctl_t(struct tty *, u_long cmd, void * data,
76 int fflag, struct thread *td);
77
78 /*
79 * Per-tty structure.
80 *
81 * Should be split in two, into device and tty drivers.
82 * Glue could be masks of what to echo and circular buffer
83 * (low, high, timeout).
84 */
85 struct tty {
86 struct clist t_rawq; /* Device raw input queue. */
87 long t_rawcc; /* Raw input queue statistics. */
88 struct clist t_canq; /* Device canonical queue. */
89 long t_cancc; /* Canonical queue statistics. */
90 struct clist t_outq; /* Device output queue. */
91 long t_outcc; /* Output queue statistics. */
92 int t_line; /* Interface to device drivers. */
93 struct cdev *t_dev; /* Device. */
94 int t_state; /* Device and driver (TS*) state. */
95 int t_flags; /* Tty flags. */
96 int t_timeout; /* Timeout for ttywait() */
97 struct pgrp *t_pgrp; /* Foreground process group. */
98 struct session *t_session; /* Enclosing session. */
99 struct sigio *t_sigio; /* Information for async I/O. */
100 struct selinfo t_rsel; /* Tty read/oob select. */
101 struct selinfo t_wsel; /* Tty write select. */
102 struct termios t_termios; /* Termios state. */
103 struct winsize t_winsize; /* Window size. */
104 void *t_sc; /* driver private softc pointer. */
105 int t_column; /* Tty output column. */
106 int t_rocount, t_rocol; /* Tty. */
107 int t_ififosize; /* Total size of upstream fifos. */
108 int t_ihiwat; /* High water mark for input. */
109 int t_ilowat; /* Low water mark for input. */
110 speed_t t_ispeedwat; /* t_ispeed override for watermarks. */
111 int t_ohiwat; /* High water mark for output. */
112 int t_olowat; /* Low water mark for output. */
113 speed_t t_ospeedwat; /* t_ospeed override for watermarks. */
114 int t_gen; /* Generation number. */
115 TAILQ_ENTRY(tty) t_list; /* Global chain of ttys for pstat(8) */
116
117 struct mtx t_mtx;
118 int t_refcnt;
119 int t_hotchar; /* linedisc preferred hot char */
120 int t_dtr_wait; /* Inter-session DTR holddown [hz] */
121
122 /* Driver supplied methods */
123 t_oproc_t *t_oproc; /* Start output. */
124 t_stop_t *t_stop; /* Stop output. */
125 t_param_t *t_param; /* Set parameters. */
126 t_modem_t *t_modem; /* Set modem state (optional). */
127 t_break_t *t_break; /* Set break state (optional). */
128 t_ioctl_t *t_ioctl; /* Set ioctl handling (optional). */
129 };
130
131 #define t_cc t_termios.c_cc
132 #define t_cflag t_termios.c_cflag
133 #define t_iflag t_termios.c_iflag
134 #define t_ispeed t_termios.c_ispeed
135 #define t_lflag t_termios.c_lflag
136 #define t_min t_termios.c_min
137 #define t_oflag t_termios.c_oflag
138 #define t_ospeed t_termios.c_ospeed
139 #define t_time t_termios.c_time
140
141 #define TTIPRI (PSOCK + 1) /* Sleep priority for tty reads. */
142 #define TTOPRI (PSOCK + 2) /* Sleep priority for tty writes. */
143
144 /*
145 * Userland version of struct tty, for sysctl.
146 */
147 struct xtty {
148 size_t xt_size; /* Structure size. */
149 long xt_rawcc; /* Raw input queue statistics. */
150 long xt_cancc; /* Canonical queue statistics. */
151 long xt_outcc; /* Output queue statistics. */
152 int xt_line; /* Interface to device drivers. */
153 dev_t xt_dev; /* Userland (sysctl) instance. */
154 int xt_state; /* Device and driver (TS*) state. */
155 int xt_flags; /* Tty flags. */
156 int xt_timeout; /* Timeout for ttywait(). */
157 pid_t xt_pgid; /* Process group ID. */
158 pid_t xt_sid; /* Session ID. */
159 struct termios xt_termios; /* Termios state. */
160 struct winsize xt_winsize; /* Window size. */
161 int xt_column; /* Tty output column. */
162 int xt_rocount, xt_rocol; /* Tty. */
163 int xt_ififosize; /* Total size of upstream fifos. */
164 int xt_ihiwat; /* High water mark for input. */
165 int xt_ilowat; /* Low water mark for input. */
166 speed_t xt_ispeedwat; /* t_ispeed override for watermarks. */
167 int xt_ohiwat; /* High water mark for output. */
168 int xt_olowat; /* Low water mark for output. */
169 speed_t xt_ospeedwat; /* t_ospeed override for watermarks. */
170 };
171
172 /*
173 * User data unfortunately has to be copied through buffers on the way to
174 * and from clists. The buffers are on the stack so their sizes must be
175 * fairly small.
176 */
177 #define IBUFSIZ 384 /* Should be >= max value of MIN. */
178 #define OBUFSIZ 100
179
180 #ifndef TTYHOG
181 #define TTYHOG 8192
182 #endif
183
184 #ifdef _KERNEL
185 #define TTMAXHIWAT roundup(2048, CBSIZE)
186 #define TTMINHIWAT roundup(100, CBSIZE)
187 #define TTMAXLOWAT 256
188 #define TTMINLOWAT 32
189 #endif
190
191 /* These flags are kept in t_state. */
192 #define TS_SO_OLOWAT 0x00001 /* Wake up when output <= low water. */
193 #define TS_ASYNC 0x00002 /* Tty in async I/O mode. */
194 #define TS_BUSY 0x00004 /* Draining output. */
195 #define TS_CARR_ON 0x00008 /* Carrier is present. */
196 #define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */
197 #define TS_ISOPEN 0x00020 /* Open has completed. */
198 #define TS_TBLOCK 0x00040 /* Further input blocked. */
199 #define TS_TIMEOUT 0x00080 /* Wait for output char processing. */
200 #define TS_TTSTOP 0x00100 /* Output paused. */
201 #ifdef notyet
202 #define TS_WOPEN 0x00200 /* Open in progress. */
203 #endif
204 #define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */
205
206 /* State for intra-line fancy editing work. */
207 #define TS_BKSL 0x00800 /* State for lowercase \ work. */
208 #define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */
209 #define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */
210 #define TS_LNCH 0x04000 /* Next character is literal. */
211 #define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */
212 #define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
213
214 /* Extras. */
215 #define TS_CAN_BYPASS_L_RINT 0x010000 /* Device in "raw" mode. */
216 #define TS_CONNECTED 0x020000 /* Connection open. */
217 #define TS_SNOOP 0x040000 /* Device is being snooped on. */
218 #define TS_SO_OCOMPLETE 0x080000 /* Wake up when output completes. */
219 #define TS_ZOMBIE 0x100000 /* Connection lost. */
220
221 /* Hardware flow-control-invoked bits. */
222 #define TS_CAR_OFLOW 0x200000 /* For MDMBUF (XXX handle in driver). */
223 #ifdef notyet
224 #define TS_CTS_OFLOW 0x400000 /* For CCTS_OFLOW. */
225 #define TS_DSR_OFLOW 0x800000 /* For CDSR_OFLOW. */
226 #endif
227
228 #define TS_DTR_WAIT 0x1000000 /* DTR hold-down between sessions */
229 #define TS_GONE 0x2000000 /* Hardware detached */
230
231 /* Character type information. */
232 #define ORDINARY 0
233 #define CONTROL 1
234 #define BACKSPACE 2
235 #define NEWLINE 3
236 #define TAB 4
237 #define VTAB 5
238 #define RETURN 6
239
240 struct speedtab {
241 int sp_speed; /* Speed. */
242 int sp_code; /* Code. */
243 };
244
245 /* Modem control commands (driver). */
246 #define DMSET 0
247 #define DMBIS 1
248 #define DMBIC 2
249 #define DMGET 3
250
251 /* Flags on a character passed to ttyinput. */
252 #define TTY_CHARMASK 0x000000ff /* Character mask */
253 #define TTY_QUOTE 0x00000100 /* Character quoted */
254 #define TTY_ERRORMASK 0xff000000 /* Error mask */
255 #define TTY_FE 0x01000000 /* Framing error */
256 #define TTY_PE 0x02000000 /* Parity error */
257 #define TTY_OE 0x04000000 /* Overrun error */
258 #define TTY_BI 0x08000000 /* Break condition */
259
260 /* Is tp controlling terminal for p? */
261 #define isctty(p, tp) \
262 ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
263
264 /* Is p in background of tp? */
265 #define isbackground(p, tp) \
266 (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
267
268 /* Unique sleep addresses. */
269 #define TSA_CARR_ON(tp) ((void *)&(tp)->t_rawq)
270 #define TSA_HUP_OR_INPUT(tp) ((void *)&(tp)->t_rawq.c_cf)
271 #define TSA_OCOMPLETE(tp) ((void *)&(tp)->t_outq.c_cl)
272 #define TSA_OLOWAT(tp) ((void *)&(tp)->t_outq)
273
274 #ifdef _KERNEL
275 #ifdef MALLOC_DECLARE
276 MALLOC_DECLARE(M_TTYS);
277 #endif
278 extern struct msgbuf consmsgbuf; /* Message buffer for constty. */
279 extern struct tty *constty; /* Temporary virtual console. */
280 extern long tk_cancc;
281 extern long tk_nin;
282 extern long tk_nout;
283 extern long tk_rawcc;
284
285 int b_to_q(char *cp, int cc, struct clist *q);
286 void catq(struct clist *from, struct clist *to);
287 void clist_alloc_cblocks(struct clist *q, int ccmax, int ccres);
288 void clist_free_cblocks(struct clist *q);
289 void constty_set(struct tty *tp);
290 void constty_clear(void);
291 int getc(struct clist *q);
292 void ndflush(struct clist *q, int cc);
293 char *nextc(struct clist *q, char *cp, int *c);
294 void nottystop(struct tty *tp, int rw);
295 int putc(int c, struct clist *q);
296 int q_to_b(struct clist *q, char *cp, int cc);
297 void termioschars(struct termios *t);
298 int tputchar(int c, struct tty *tp);
299 int ttcompat(struct tty *tp, u_long com, caddr_t data, int flag);
300 int ttioctl(struct tty *tp, u_long com, void *data, int flag);
301 int ttread(struct tty *tp, struct uio *uio, int flag);
302 void ttrstrt(void *tp);
303 int ttsetcompat(struct tty *tp, u_long *com, caddr_t data,
304 struct termios *term);
305 void ttsetwater(struct tty *tp);
306 int ttspeedtab(int speed, struct speedtab *table);
307 int ttstart(struct tty *tp);
308 void ttwakeup(struct tty *tp);
309 int ttwrite(struct tty *tp, struct uio *uio, int flag);
310 void ttwwakeup(struct tty *tp);
311 void ttyblock(struct tty *tp);
312 void ttychars(struct tty *tp);
313 int ttycheckoutq(struct tty *tp, int wait);
314 int tty_close(struct tty *tp);
315 int ttydtrwaitsleep(struct tty *tp);
316 void ttydtrwaitstart(struct tty *tp);
317 void ttyflush(struct tty *tp, int rw);
318 void ttygone(struct tty *tp);
319 void ttyinfo(struct tty *tp);
320 int ttyinput(int c, struct tty *tp);
321 int ttylclose(struct tty *tp, int flag);
322 void ttyldoptim(struct tty *tp);
323 struct tty *ttymalloc(struct tty *tp);
324 int ttymodem(struct tty *tp, int flag);
325 int tty_open(struct cdev *device, struct tty *tp);
326 int ttyref(struct tty *tp);
327 int ttyrel(struct tty *tp);
328 int ttysleep(struct tty *tp, void *chan, int pri, char *wmesg, int timo);
329 int ttywait(struct tty *tp);
330 int unputc(struct clist *q);
331
332 /*
333 * XXX: temporary
334 */
335 #include <sys/linedisc.h>
336
337 #endif /* _KERNEL */
338
339 #endif /* !_SYS_TTY_H_ */
Cache object: 27e62c25fba83be0ae1a29d3a2fc9383
|