FreeBSD/Linux Kernel Cross Reference
sys/sys/tty.h
1 /* $NetBSD: tty.h,v 1.66 2005/02/03 19:20:02 perry Exp $ */
2
3 /*-
4 * Copyright (c) 1982, 1986, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)tty.h 8.7 (Berkeley) 1/9/95
37 */
38
39 #include <sys/termios.h>
40 #include <sys/select.h> /* For struct selinfo. */
41 #include <sys/lock.h>
42 #include <sys/queue.h>
43 #include <sys/callout.h>
44
45 #ifndef _SYS_TTY_H_
46 #define _SYS_TTY_H_
47
48 /*
49 * Clists are actually ring buffers. The c_cc, c_cf, c_cl fields have
50 * exactly the same behaviour as in true clists.
51 * if c_cq is NULL, the ring buffer has no TTY_QUOTE functionality
52 * (but, saves memory and CPU time)
53 *
54 * *DON'T* play with c_cs, c_ce, c_cq, or c_cl outside tty_subr.c!!!
55 */
56 struct clist {
57 int c_cc; /* count of characters in queue */
58 int c_cn; /* total ring buffer length */
59 u_char *c_cf; /* points to first character */
60 u_char *c_cl; /* points to next open character */
61 u_char *c_cs; /* start of ring buffer */
62 u_char *c_ce; /* c_ce + c_len */
63 u_char *c_cq; /* N bits/bytes long, see tty_subr.c */
64 };
65
66 /*
67 * Per-tty structure.
68 *
69 * Should be split in two, into device and tty drivers.
70 * Glue could be masks of what to echo and circular buffer
71 * (low, high, timeout).
72 */
73 struct tty {
74 TAILQ_ENTRY(tty) tty_link; /* Link in global tty list. */
75 struct simplelock t_slock; /* mutex for all access to this tty */
76 struct clist t_rawq; /* Device raw input queue. */
77 long t_rawcc; /* Raw input queue statistics. */
78 struct clist t_canq; /* Device canonical queue. */
79 long t_cancc; /* Canonical queue statistics. */
80 struct clist t_outq; /* Device output queue. */
81 struct callout t_rstrt_ch; /* for delayed output start */
82 long t_outcc; /* Output queue statistics. */
83 struct linesw *t_linesw; /* Interface to device drivers. */
84 dev_t t_dev; /* Device. */
85 int t_state; /* Device and driver (TS*) state. */
86 int t_wopen; /* Processes waiting for open. */
87 int t_flags; /* Tty flags. */
88 struct pgrp *t_pgrp; /* Foreground process group. */
89 struct session *t_session; /* Enclosing session. */
90 struct selinfo t_rsel; /* Tty read/oob select. */
91 struct selinfo t_wsel; /* Tty write select. */
92 struct termios t_termios; /* Termios state. */
93 struct winsize t_winsize; /* Window size. */
94 /* Start output. */
95 void (*t_oproc)(struct tty *);
96 /* Set hardware state. */
97 int (*t_param)(struct tty *, struct termios *);
98 /* Set hardware flow control. */
99 int (*t_hwiflow)(struct tty *, int);
100 void *t_sc; /* XXX: net/if_sl.c:sl_softc. */
101 short t_column; /* Tty output column. */
102 short t_rocount, t_rocol; /* Tty. */
103 short t_hiwat; /* High water mark. */
104 short t_lowat; /* Low water mark. */
105 short t_gen; /* Generation number. */
106 };
107
108 #define __TTY_ENABLE_SLOCK
109 #ifdef __TTY_ENABLE_SLOCK
110 #define TTY_LOCK(tp) simple_lock(&(tp)->t_slock)
111 #define TTY_UNLOCK(tp) simple_unlock(&(tp)->t_slock)
112 #else /* __TTY_ENABLE_SLOCK */
113 #define TTY_LOCK(tp) /**/
114 #define TTY_UNLOCK(tp) /**/
115 #endif /* __TTY_ENABLE_SLOCK */
116
117 #define t_cc t_termios.c_cc
118 #define t_cflag t_termios.c_cflag
119 #define t_iflag t_termios.c_iflag
120 #define t_ispeed t_termios.c_ispeed
121 #define t_lflag t_termios.c_lflag
122 #define t_oflag t_termios.c_oflag
123 #define t_ospeed t_termios.c_ospeed
124
125 #define TTIPRI 25 /* Sleep priority for tty reads. */
126 #define TTOPRI 26 /* Sleep priority for tty writes. */
127
128 #define TTMASK 15
129 #define OBUFSIZ 100
130 #define TTYHOG 1024
131
132 #ifdef _KERNEL
133 #define TTMAXHIWAT roundup(2048, CBSIZE)
134 #define TTMINHIWAT roundup(100, CBSIZE)
135 #define TTMAXLOWAT 256
136 #define TTMINLOWAT 32
137 #endif /* _KERNEL */
138
139 /* These flags are kept in t_state. */
140 #define TS_ASLEEP 0x00001 /* Process waiting for tty. */
141 #define TS_ASYNC 0x00002 /* Tty in async I/O mode. */
142 #define TS_BUSY 0x00004 /* Draining output. */
143 #define TS_CARR_ON 0x00008 /* Carrier is present. */
144 #define TS_DIALOUT 0x00010 /* Tty used for dialout. */
145 #define TS_FLUSH 0x00020 /* Outq has been flushed during DMA. */
146 #define TS_ISOPEN 0x00040 /* Open has completed. */
147 #define TS_TBLOCK 0x00080 /* Further input blocked. */
148 #define TS_TIMEOUT 0x00100 /* Wait for output char processing. */
149 #define TS_TTSTOP 0x00200 /* Output paused. */
150 #define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */
151
152 /* State for intra-line fancy editing work. */
153 #define TS_BKSL 0x00800 /* State for lowercase \ work. */
154 #define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */
155 #define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */
156 #define TS_LNCH 0x04000 /* Next character is literal. */
157 #define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */
158 #define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
159
160 /* Character type information. */
161 #define ORDINARY 0
162 #define CONTROL 1
163 #define BACKSPACE 2
164 #define NEWLINE 3
165 #define TAB 4
166 #define VTAB 5
167 #define RETURN 6
168
169 struct speedtab {
170 int sp_speed; /* Speed. */
171 int sp_code; /* Code. */
172 };
173
174 /* Modem control commands (driver). */
175 #define DMSET 0
176 #define DMBIS 1
177 #define DMBIC 2
178 #define DMGET 3
179
180 /* Flags on a character passed to ttyinput. */
181 #define TTY_CHARMASK 0x000000ff /* Character mask */
182 #define TTY_QUOTE 0x00000100 /* Character quoted */
183 #define TTY_ERRORMASK 0xff000000 /* Error mask */
184 #define TTY_FE 0x01000000 /* Framing error or BREAK condition */
185 #define TTY_PE 0x02000000 /* Parity error */
186
187 /* Is tp controlling terminal for p? */
188 #define isctty(p, tp) \
189 ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
190
191 /* Is p in background of tp? */
192 #define isbackground(p, tp) \
193 (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
194
195 /*
196 * ttylist_head is defined here so that user-land has access to it.
197 */
198 TAILQ_HEAD(ttylist_head, tty); /* the ttylist is a TAILQ */
199
200 #ifdef _KERNEL
201 #include <sys/mallocvar.h>
202
203 MALLOC_DECLARE(M_TTYS);
204
205 extern int tty_count; /* number of ttys in global ttylist */
206 extern struct ttychars ttydefaults;
207
208 /* Symbolic sleep message strings. */
209 extern const char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[];
210
211 int b_to_q(const u_char *, int, struct clist *);
212 void catq(struct clist *, struct clist *);
213 void clist_init(void);
214 int getc(struct clist *);
215 void ndflush(struct clist *, int);
216 int ndqb(struct clist *, int);
217 u_char *nextc(struct clist *, u_char *, int *);
218 int putc(int, struct clist *);
219 int q_to_b(struct clist *, u_char *, int);
220 int unputc(struct clist *);
221
222 int nullmodem(struct tty *, int);
223 int tputchar(int, int, struct tty *);
224 int ttioctl(struct tty *, u_long, caddr_t, int, struct proc *);
225 int ttread(struct tty *, struct uio *, int);
226 void ttrstrt(void *);
227 int ttpoll(struct tty *, int, struct proc *);
228 void ttsetwater(struct tty *);
229 int ttspeedtab(int, const struct speedtab *);
230 int ttstart(struct tty *);
231 void ttwakeup(struct tty *);
232 int ttwrite(struct tty *, struct uio *, int);
233 void ttychars(struct tty *);
234 int ttycheckoutq(struct tty *, int);
235 int ttyclose(struct tty *);
236 void ttyflush(struct tty *, int);
237 void ttyinfo(struct tty *);
238 int ttyinput(int, struct tty *);
239 int ttylclose(struct tty *, int);
240 int ttylopen(dev_t, struct tty *);
241 int ttykqfilter(dev_t, struct knote *);
242 int ttymodem(struct tty *, int);
243 int ttyopen(struct tty *, int, int);
244 int ttyoutput(int, struct tty *);
245 void ttypend(struct tty *);
246 void ttyretype(struct tty *);
247 void ttyrub(int, struct tty *);
248 int ttysleep(struct tty *, void *, int, const char *, int);
249 int ttywait(struct tty *);
250 int ttywflush(struct tty *);
251
252 void tty_init(void);
253 void tty_attach(struct tty *);
254 void tty_detach(struct tty *);
255 struct tty
256 *ttymalloc(void);
257 void ttyfree(struct tty *);
258 u_char *firstc(struct clist *, int *);
259
260 int clalloc(struct clist *, int, int);
261 void clfree(struct clist *);
262
263 #if defined(_KERNEL_OPT)
264 #include "opt_compat_freebsd.h"
265 #include "opt_compat_sunos.h"
266 #include "opt_compat_svr4.h"
267 #include "opt_compat_43.h"
268 #include "opt_compat_osf1.h"
269 #endif
270
271 #if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_SVR4) || \
272 defined(COMPAT_FREEBSD) || defined(COMPAT_OSF1) || defined(LKM)
273 # define COMPAT_OLDTTY
274 int ttcompat(struct tty *, u_long, caddr_t, int, struct proc *);
275 #endif
276
277 #endif /* _KERNEL */
278
279 #endif /* !_SYS_TTY_H_ */
Cache object: 3ce82b6c4756393bc99243dc1b9e8a43
|