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