nrelease - fix/improve livecd
[dragonfly.git] / sys / sys / tty.h
... / ...
CommitLineData
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 * 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.
21 *
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.
33 *
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 */
37
38#ifndef _SYS_TTY_H_
39#define _SYS_TTY_H_
40
41/*
42 * Clists are character lists, which is a variable length linked list
43 * of cblocks, with a count of the number of characters in the list.
44 */
45struct clist {
46 int c_cc; /* Number of characters in the clist. */
47 int c_ccmax; /* Max # chars for this clist. */
48 int c_cchead; /* First char */
49 int c_unused01;
50 short *c_data; /* linear data buffer (no longer chained) */
51};
52
53#if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
54
55#include <sys/_termios.h>
56#include <sys/event.h>
57#include <sys/queue.h>
58#include <sys/ttycom.h>
59#ifdef _KERNEL
60#include <sys/device.h>
61#endif
62#ifndef _SYS_THREAD_H_
63#include <sys/thread.h>
64#endif
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 */
73struct tty {
74 struct lwkt_token t_token;
75 struct clist t_rawq; /* Device raw input queue. */
76 long t_rawcc; /* Raw input queue statistics. */
77 struct clist t_canq; /* Device canonical queue. */
78 long t_cancc; /* Canonical queue statistics. */
79 struct clist t_outq; /* Device output queue. */
80 long t_outcc; /* Output queue statistics. */
81 int t_line; /* Interface to device drivers. */
82 struct cdev *t_dev; /* Device. */
83 int t_state; /* Device and driver (TS*) state. */
84 int t_flags; /* Tty flags. */
85 int t_timeout; /* Timeout for ttywait() */
86 struct pgrp *t_pgrp; /* Foreground process group. */
87 struct session *t_session; /* Enclosing session. */
88 struct sigio *t_sigio; /* Information for async I/O. */
89 struct kqinfo t_rkq; /* Tty read/oob kq. */
90 struct kqinfo t_wkq; /* Tty write kq. */
91 struct termios t_termios; /* Termios state. */
92 struct winsize t_winsize; /* Window size. */
93 /* Start output. */
94 void (*t_oproc) (struct tty *);
95 /* Stop output. */
96 void (*t_stop) (struct tty *, int);
97 /* Set hardware state. */
98 int (*t_param) (struct tty *, struct termios *);
99 void (*t_unhold) (struct tty *); /* callback to pty after unhold */
100 void *t_sc; /* generic driver (u4b com) */
101 void *t_slsc; /* if_sl.c, ppp_tty.c (disc) */
102 int t_column; /* Tty output column. */
103 int t_rocount, t_rocol; /* Tty. */
104 int t_ififosize; /* Total size of upstream fifos. */
105 int t_ihiwat; /* High water mark for input. */
106 int t_ilowat; /* Low water mark for input. */
107 speed_t t_ispeedwat; /* t_ispeed override for watermarks. */
108 int t_ohiwat; /* High water mark for output. */
109 int t_olowat; /* Low water mark for output. */
110 speed_t t_ospeedwat; /* t_ospeed override for watermarks. */
111 int t_gen; /* Generation number. */
112 TAILQ_ENTRY(tty) t_list; /* Global chain of ttys for pstat(8) */
113 int t_refs; /* Reference count. */
114};
115
116#define t_cc t_termios.c_cc
117#define t_cflag t_termios.c_cflag
118#define t_iflag t_termios.c_iflag
119#define t_ispeed t_termios.c_ispeed
120#define t_lflag t_termios.c_lflag
121#define t_min t_termios.c_min
122#define t_oflag t_termios.c_oflag
123#define t_ospeed t_termios.c_ospeed
124#define t_time t_termios.c_time
125
126#endif
127
128/*
129 * User data unfortunately has to be copied through buffers on the way to
130 * and from clists. The buffers are on the stack so their sizes must be
131 * fairly small.
132 */
133#define IBUFSIZ 384 /* Should be >= max value of MIN. */
134#define OBUFSIZ 100
135
136#ifndef TTYHOG
137#define TTYHOG 1024
138#endif
139
140#ifdef _KERNEL
141#define TTMAXHIWAT 2048
142#define TTMINHIWAT 100
143#define TTMAXLOWAT 256
144#define TTMINLOWAT 32
145#endif
146
147/* These flags are kept in t_state. */
148#define TS_SO_OLOWAT 0x00001 /* Wake up when output <= low water. */
149#define TS_ASYNC 0x00002 /* Tty in async I/O mode. */
150#define TS_BUSY 0x00004 /* Draining output. */
151#define TS_CARR_ON 0x00008 /* Carrier is present. */
152#define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */
153#define TS_ISOPEN 0x00020 /* Open has completed. */
154#define TS_TBLOCK 0x00040 /* Further input blocked. */
155#define TS_TIMEOUT 0x00080 /* Wait for output char processing. */
156#define TS_TTSTOP 0x00100 /* Output paused. */
157#ifdef notyet
158#define TS_WOPEN 0x00200 /* Open in progress. */
159#endif
160#define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */
161
162/* State for intra-line fancy editing work. */
163#define TS_BKSL 0x00800 /* State for lowercase \ work. */
164#define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */
165#define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */
166#define TS_LNCH 0x04000 /* Next character is literal. */
167#define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */
168#define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
169
170/* Extras. */
171#define TS_CAN_BYPASS_L_RINT 0x010000 /* Device in "raw" mode. */
172#define TS_CONNECTED 0x020000 /* Connection open. */
173#define TS_SNOOP 0x040000 /* Device is being snooped on. */
174#define TS_SO_OCOMPLETE 0x080000 /* Wake up when output completes. */
175#define TS_ZOMBIE 0x100000 /* Connection lost. */
176
177/* Hardware flow-control-invoked bits. */
178#define TS_CAR_OFLOW 0x200000 /* For MDMBUF (XXX handle in driver). */
179#ifdef notyet
180#define TS_CTS_OFLOW 0x400000 /* For CCTS_OFLOW. */
181#define TS_DSR_OFLOW 0x800000 /* For CDSR_OFLOW. */
182#endif
183#define TS_REGISTERED 0x1000000 /* ttyregister sanity check */
184#define TS_MARKER 0x2000000 /* sysctl iteration marker */
185
186/* Character type information. */
187#define ORDINARY 0
188#define CONTROL 1
189#define BACKSPACE 2
190#define NEWLINE 3
191#define TAB 4
192#define VTAB 5
193#define RETURN 6
194
195struct speedtab {
196 int sp_speed; /* Speed. */
197 int sp_code; /* Code. */
198};
199
200/* Modem control commands (driver). */
201#define DMSET 0
202#define DMBIS 1
203#define DMBIC 2
204#define DMGET 3
205
206/* Flags on a character passed to ttyinput. */
207#define TTY_CHARMASK 0x00ff /* Character mask */
208#define TTY_QUOTE 0x0100 /* Character quoted */
209#define TTY_ERRORMASK 0xff000000 /* Error mask */
210#define TTY_FE 0x01000000 /* Framing error */
211#define TTY_PE 0x02000000 /* Parity error */
212#define TTY_OE 0x04000000 /* Overrun error */
213#define TTY_BI 0x08000000 /* Break condition */
214
215/* Is tp controlling terminal for p? */
216#define isctty(p, tp) \
217 ((p)->p_session == (tp)->t_session && ((p)->p_flags & P_CONTROLT))
218
219/* Is p in background of tp? */
220#define isbackground(p, tp) \
221 (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
222
223/* Unique sleep addresses. */
224#define TSA_CARR_ON(tp) ((void *)&(tp)->t_rawq)
225#define TSA_HUP_OR_INPUT(tp) ((void *)&(tp)->t_rawq.c_cchead)
226#define TSA_OCOMPLETE(tp) ((void *)&(tp)->t_outq.c_ccmax)
227#define TSA_OLOWAT(tp) ((void *)&(tp)->t_outq)
228#define TSA_PTC_READ(tp) ((void *)&(tp)->t_outq.c_cchead)
229#define TSA_PTC_WRITE(tp) ((void *)&(tp)->t_rawq.c_ccmax)
230#define TSA_PTS_READ(tp) ((void *)&(tp)->t_canq)
231
232#ifdef _KERNEL
233
234#ifdef MALLOC_DECLARE
235MALLOC_DECLARE(M_TTYS);
236#endif
237
238extern struct tty *constty; /* Temporary virtual console. */
239
240int clist_btoq (char *cp, int cc, struct clist *q);
241void clist_catq (struct clist *from, struct clist *to);
242void clist_alloc_cblocks (struct clist *q, int ccmax);
243void clist_free_cblocks (struct clist *q);
244int clist_getc (struct clist *q);
245int clist_unputc (struct clist *q);
246void ndflush (struct clist *q, int cc);
247void *clist_nextc (struct clist *q, void *cp, int *c);
248void nottystop (struct tty *tp, int rw);
249int clist_putc (int c, struct clist *q);
250int clist_qtob (struct clist *q, char *cp, int cc);
251void termioschars (struct termios *t);
252int tputchar (int c, struct tty *tp);
253int ttcompat (struct tty *tp, u_long com, caddr_t data, int flag);
254int ttioctl (struct tty *tp, u_long com, void *data, int flag);
255int ttread (struct tty *tp, struct uio *uio, int flag);
256int ttsetcompat (struct tty *tp, u_long *com, caddr_t data,
257 struct termios *term);
258void ttsetwater (struct tty *tp);
259int ttspeedtab (int speed, struct speedtab *table);
260int ttstart (struct tty *tp);
261void ttwakeup (struct tty *tp);
262int ttwrite (struct tty *tp, struct uio *uio, int flag);
263void ttwwakeup (struct tty *tp);
264void ttyblock (struct tty *tp);
265void ttychars (struct tty *tp);
266int ttycheckoutq (struct tty *tp, int wait);
267int ttyclose (struct tty *tp);
268void ttyclearsession (struct tty *tp);
269void ttyclosesession (struct session *, int);
270void ttyflush (struct tty *tp, int rw);
271void ttyhold (struct tty *tp);
272void ttyunhold (struct tty *tp);
273void ttyinfo (struct tty *tp);
274int ttyinput (int c, struct tty *tp);
275int ttylclose (struct tty *tp, int flag);
276struct tty *ttymalloc (struct tty **tpp);
277int ttymodem (struct tty *tp, int flag);
278int ttyopen (cdev_t device, struct tty *tp);
279int ttykqfilter (struct dev_kqfilter_args *);
280int ttyread (struct dev_read_args *);
281void ttyregister (struct tty *tp);
282void ttyinit (struct tty *tp);
283void ttyunregister (struct tty *tp);
284int ttysleep (struct tty *tp, void *chan, int slpflags, char *wmesg,
285 int timeout);
286int ttyrevoke (struct dev_revoke_args *);
287int ttywait (struct tty *tp);
288int ttywrite (struct dev_write_args *);
289
290#endif /* _KERNEL */
291
292#endif /* !_SYS_TTY_H_ */