kernel - remove mapzone
[dragonfly.git] / sys / sys / tty.h
blob1f85ebc0f3a9b6b96d8ee5eec2e5e8236611a19c
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.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * @(#)tty.h 8.6 (Berkeley) 1/21/94
35 * $FreeBSD: src/sys/sys/tty.h,v 1.53.2.1 2001/02/26 04:23:21 jlemon Exp $
36 * $DragonFly: src/sys/sys/tty.h,v 1.12 2006/09/10 01:26:40 dillon Exp $
39 #ifndef _SYS_TTY_H_
40 #define _SYS_TTY_H_
42 #ifndef _SYS_TERMIOS_H_
43 #include <sys/termios.h>
44 #endif
45 #ifndef _SYS_EVENT_H_
46 #include <sys/event.h>
47 #endif
48 #ifdef _KERNEL
49 #include <sys/device.h>
50 #endif
53 * Clists are character lists, which is a variable length linked list
54 * of cblocks, with a count of the number of characters in the list.
56 struct clist {
57 int c_cc; /* Number of characters in the clist. */
58 int c_cbcount; /* Number of cblocks. */
59 int c_cbmax; /* Max # cblocks allowed for this clist. */
60 int c_cbreserved; /* # cblocks reserved for this clist. */
61 char *c_cf; /* Pointer to the first cblock. */
62 char *c_cl; /* Pointer to the last cblock. */
65 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
67 #ifndef _SYS_QUEUE_H_
68 #include <sys/queue.h>
69 #endif
72 * Per-tty structure.
74 * Should be split in two, into device and tty drivers.
75 * Glue could be masks of what to echo and circular buffer
76 * (low, high, timeout).
78 struct tty {
79 struct clist t_rawq; /* Device raw input queue. */
80 long t_rawcc; /* Raw input queue statistics. */
81 struct clist t_canq; /* Device canonical queue. */
82 long t_cancc; /* Canonical queue statistics. */
83 struct clist t_outq; /* Device output queue. */
84 long t_outcc; /* Output queue statistics. */
85 int t_line; /* Interface to device drivers. */
86 struct cdev *t_dev; /* Device. */
87 int t_state; /* Device and driver (TS*) state. */
88 int t_flags; /* Tty flags. */
89 int t_timeout; /* Timeout for ttywait() */
90 struct pgrp *t_pgrp; /* Foreground process group. */
91 struct session *t_session; /* Enclosing session. */
92 struct sigio *t_sigio; /* Information for async I/O. */
93 struct kqinfo t_rkq; /* Tty read/oob kq. */
94 struct kqinfo t_wkq; /* Tty write kq. */
95 struct termios t_termios; /* Termios state. */
96 struct winsize t_winsize; /* Window size. */
97 /* Start output. */
98 void (*t_oproc) (struct tty *);
99 /* Stop output. */
100 void (*t_stop) (struct tty *, int);
101 /* Set hardware state. */
102 int (*t_param) (struct tty *, struct termios *);
103 void (*t_unhold) (struct tty *); /* callback to pty after unhold */
104 void *t_sc; /* generic driver (u4b com) */
105 void *t_slsc; /* if_sl.c, ppp_tty.c (disc) */
106 int t_column; /* Tty output column. */
107 int t_rocount, t_rocol; /* Tty. */
108 int t_ififosize; /* Total size of upstream fifos. */
109 int t_ihiwat; /* High water mark for input. */
110 int t_ilowat; /* Low water mark for input. */
111 speed_t t_ispeedwat; /* t_ispeed override for watermarks. */
112 int t_ohiwat; /* High water mark for output. */
113 int t_olowat; /* Low water mark for output. */
114 speed_t t_ospeedwat; /* t_ospeed override for watermarks. */
115 int t_gen; /* Generation number. */
116 TAILQ_ENTRY(tty) t_list; /* Global chain of ttys for pstat(8) */
117 int t_refs; /* Reference count. */
120 #define t_cc t_termios.c_cc
121 #define t_cflag t_termios.c_cflag
122 #define t_iflag t_termios.c_iflag
123 #define t_ispeed t_termios.c_ispeed
124 #define t_lflag t_termios.c_lflag
125 #define t_min t_termios.c_min
126 #define t_oflag t_termios.c_oflag
127 #define t_ospeed t_termios.c_ospeed
128 #define t_time t_termios.c_time
130 #endif
133 * User data unfortunately has to be copied through buffers on the way to
134 * and from clists. The buffers are on the stack so their sizes must be
135 * fairly small.
137 #define IBUFSIZ 384 /* Should be >= max value of MIN. */
138 #define OBUFSIZ 100
140 #ifndef TTYHOG
141 #define TTYHOG 1024
142 #endif
144 #ifdef _KERNEL
145 #define TTMAXHIWAT roundup(2048, CBSIZE)
146 #define TTMINHIWAT roundup(100, CBSIZE)
147 #define TTMAXLOWAT 256
148 #define TTMINLOWAT 32
149 #endif
151 /* These flags are kept in t_state. */
152 #define TS_SO_OLOWAT 0x00001 /* Wake up when output <= low water. */
153 #define TS_ASYNC 0x00002 /* Tty in async I/O mode. */
154 #define TS_BUSY 0x00004 /* Draining output. */
155 #define TS_CARR_ON 0x00008 /* Carrier is present. */
156 #define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */
157 #define TS_ISOPEN 0x00020 /* Open has completed. */
158 #define TS_TBLOCK 0x00040 /* Further input blocked. */
159 #define TS_TIMEOUT 0x00080 /* Wait for output char processing. */
160 #define TS_TTSTOP 0x00100 /* Output paused. */
161 #ifdef notyet
162 #define TS_WOPEN 0x00200 /* Open in progress. */
163 #endif
164 #define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */
166 /* State for intra-line fancy editing work. */
167 #define TS_BKSL 0x00800 /* State for lowercase \ work. */
168 #define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */
169 #define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */
170 #define TS_LNCH 0x04000 /* Next character is literal. */
171 #define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */
172 #define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
174 /* Extras. */
175 #define TS_CAN_BYPASS_L_RINT 0x010000 /* Device in "raw" mode. */
176 #define TS_CONNECTED 0x020000 /* Connection open. */
177 #define TS_SNOOP 0x040000 /* Device is being snooped on. */
178 #define TS_SO_OCOMPLETE 0x080000 /* Wake up when output completes. */
179 #define TS_ZOMBIE 0x100000 /* Connection lost. */
181 /* Hardware flow-control-invoked bits. */
182 #define TS_CAR_OFLOW 0x200000 /* For MDMBUF (XXX handle in driver). */
183 #ifdef notyet
184 #define TS_CTS_OFLOW 0x400000 /* For CCTS_OFLOW. */
185 #define TS_DSR_OFLOW 0x800000 /* For CDSR_OFLOW. */
186 #endif
187 #define TS_REGISTERED 0x1000000 /* ttyregister sanity check */
188 #define TS_MARKER 0x2000000 /* sysctl iteration marker */
190 /* Character type information. */
191 #define ORDINARY 0
192 #define CONTROL 1
193 #define BACKSPACE 2
194 #define NEWLINE 3
195 #define TAB 4
196 #define VTAB 5
197 #define RETURN 6
199 struct speedtab {
200 int sp_speed; /* Speed. */
201 int sp_code; /* Code. */
204 /* Modem control commands (driver). */
205 #define DMSET 0
206 #define DMBIS 1
207 #define DMBIC 2
208 #define DMGET 3
210 /* Flags on a character passed to ttyinput. */
211 #define TTY_CHARMASK 0x000000ff /* Character mask */
212 #define TTY_QUOTE 0x00000100 /* Character quoted */
213 #define TTY_ERRORMASK 0xff000000 /* Error mask */
214 #define TTY_FE 0x01000000 /* Framing error */
215 #define TTY_PE 0x02000000 /* Parity error */
216 #define TTY_OE 0x04000000 /* Overrun error */
217 #define TTY_BI 0x08000000 /* Break condition */
219 /* Is tp controlling terminal for p? */
220 #define isctty(p, tp) \
221 ((p)->p_session == (tp)->t_session && ((p)->p_flags & P_CONTROLT))
223 /* Is p in background of tp? */
224 #define isbackground(p, tp) \
225 (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
227 /* Unique sleep addresses. */
228 #define TSA_CARR_ON(tp) ((void *)&(tp)->t_rawq)
229 #define TSA_HUP_OR_INPUT(tp) ((void *)&(tp)->t_rawq.c_cf)
230 #define TSA_OCOMPLETE(tp) ((void *)&(tp)->t_outq.c_cl)
231 #define TSA_OLOWAT(tp) ((void *)&(tp)->t_outq)
232 #define TSA_PTC_READ(tp) ((void *)&(tp)->t_outq.c_cf)
233 #define TSA_PTC_WRITE(tp) ((void *)&(tp)->t_rawq.c_cl)
234 #define TSA_PTS_READ(tp) ((void *)&(tp)->t_canq)
236 #ifdef _KERNEL
238 #ifndef _SYS_MALLOC_H_
239 #include <sys/malloc.h>
240 #endif
242 MALLOC_DECLARE(M_TTYS);
244 extern struct tty *constty; /* Temporary virtual console. */
246 int b_to_q (char *cp, int cc, struct clist *q);
247 void catq (struct clist *from, struct clist *to);
248 void clist_alloc_cblocks (struct clist *q, int ccmax, int ccres);
249 void clist_free_cblocks (struct clist *q);
250 int clist_getc (struct clist *q);
251 int clist_unputc (struct clist *q);
252 void ndflush (struct clist *q, int cc);
253 char *nextc (struct clist *q, char *cp, int *c);
254 void nottystop (struct tty *tp, int rw);
255 int clist_putc (int c, struct clist *q);
256 int q_to_b (struct clist *q, char *cp, int cc);
257 void termioschars (struct termios *t);
258 int tputchar (int c, struct tty *tp);
259 int ttcompat (struct tty *tp, u_long com, caddr_t data, int flag);
260 int ttioctl (struct tty *tp, u_long com, void *data, int flag);
261 int ttread (struct tty *tp, struct uio *uio, int flag);
262 void ttrstrt (void *tp);
263 int ttsetcompat (struct tty *tp, u_long *com, caddr_t data,
264 struct termios *term);
265 void ttsetwater (struct tty *tp);
266 int ttspeedtab (int speed, struct speedtab *table);
267 int ttstart (struct tty *tp);
268 void ttwakeup (struct tty *tp);
269 int ttwrite (struct tty *tp, struct uio *uio, int flag);
270 void ttwwakeup (struct tty *tp);
271 void ttyblock (struct tty *tp);
272 void ttychars (struct tty *tp);
273 int ttycheckoutq (struct tty *tp, int wait);
274 int ttyclose (struct tty *tp);
275 void ttyclearsession (struct tty *tp);
276 void ttyclosesession (struct session *, int);
277 void ttyflush (struct tty *tp, int rw);
278 void ttyhold (struct tty *tp);
279 void ttyunhold (struct tty *tp);
280 void ttyinfo (struct tty *tp);
281 int ttyinput (int c, struct tty *tp);
282 int ttylclose (struct tty *tp, int flag);
283 struct tty *ttymalloc (struct tty *tp);
284 int ttymodem (struct tty *tp, int flag);
285 int ttyopen (cdev_t device, struct tty *tp);
286 int ttykqfilter (struct dev_kqfilter_args *);
287 int ttyread (struct dev_read_args *);
288 void ttyregister (struct tty *tp);
289 void ttyunregister (struct tty *tp);
290 int ttysleep (struct tty *tp, void *chan, int slpflags, char *wmesg,
291 int timeout);
292 int ttyrevoke (struct dev_revoke_args *);
293 int ttywait (struct tty *tp);
294 int ttywrite (struct dev_write_args *);
296 #endif /* _KERNEL */
298 #endif /* !_SYS_TTY_H_ */