]> git.saurik.com Git - apple/xnu.git/blame_incremental - bsd/sys/tty.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / bsd / sys / tty.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */
24/*-
25 * Copyright (c) 1982, 1986, 1993
26 * The Regents of the University of California. All rights reserved.
27 * (c) UNIX System Laboratories, Inc.
28 * All or some portions of this file are derived from material licensed
29 * to the University of California by American Telephone and Telegraph
30 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
31 * the permission of UNIX System Laboratories, Inc.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)tty.h 8.6 (Berkeley) 1/21/94
62 */
63
64#ifndef _SYS_TTY_H_
65#define _SYS_TTY_H_
66
67#include <sys/appleapiopts.h>
68#include <sys/cdefs.h>
69#include <sys/termios.h>
70#include <sys/select.h> /* For struct selinfo. */
71
72
73#ifdef KERNEL
74/*
75 * NetBSD Clists are actually ring buffers. The c_cc, c_cf, c_cl fields have
76 * exactly the same behaviour as in true clists.
77 * if c_cq is NULL, the ring buffer has no TTY_QUOTE functionality
78 * (but, saves memory and cpu time)
79 *
80 * *DON'T* play with c_cs, c_ce, c_cq, or c_cl outside tty_subr.c!!!
81 */
82struct clist {
83 int c_cc; /* count of characters in queue */
84 int c_cn; /* total ring buffer length */
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 */
90};
91
92#ifndef TTYCLSIZE
93#define TTYCLSIZE 1024
94#endif
95
96
97/*
98 * Per-tty structure.
99 *
100 * Should be split in two, into device and tty drivers.
101 * Glue could be masks of what to echo and circular buffer
102 * (low, high, timeout).
103 */
104struct tty {
105 struct clist t_rawq; /* Device raw input queue. */
106 long t_rawcc; /* Raw input queue statistics. */
107 struct clist t_canq; /* Device canonical queue. */
108 long t_cancc; /* Canonical queue statistics. */
109 struct clist t_outq; /* Device output queue. */
110 long t_outcc; /* Output queue statistics. */
111 int t_line; /* Interface to device drivers. */
112 dev_t t_dev; /* Device. */
113 int t_state; /* Device and driver (TS*) state. */
114 int t_flags; /* Tty flags. */
115 int t_timeout; /* Timeout for ttywait() */
116 struct pgrp *t_pgrp; /* Foreground process group. */
117 struct session *t_session; /* Enclosing session. */
118 struct selinfo t_rsel; /* Tty read/oob select. */
119 struct selinfo t_wsel; /* Tty write select. */
120 struct termios t_termios; /* Termios state. */
121 struct winsize t_winsize; /* Window size. */
122 /* Start output. */
123 void (*t_oproc)(struct tty *);
124 /* Stop output. */
125 void (*t_stop)(struct tty *, int);
126 /* Set hardware state. */
127 int (*t_param)(struct tty *, struct termios *);
128 void *t_sc; /* XXX: net/if_sl.c:sl_softc. */
129 int t_column; /* Tty output column. */
130 int t_rocount, t_rocol; /* Tty. */
131 int t_hiwat; /* High water mark. */
132 int t_lowat; /* Low water mark. */
133 int t_gen; /* Generation number. */
134};
135
136#define t_cc t_termios.c_cc
137#define t_cflag t_termios.c_cflag
138#define t_iflag t_termios.c_iflag
139#define t_ispeed t_termios.c_ispeed
140#define t_lflag t_termios.c_lflag
141#define t_min t_termios.c_min
142#define t_oflag t_termios.c_oflag
143#define t_ospeed t_termios.c_ospeed
144#define t_time t_termios.c_time
145
146
147#define TTIPRI 25 /* Sleep priority for tty reads. */
148#define TTOPRI 26 /* Sleep priority for tty writes. */
149
150/*
151 * User data unfortunately has to be copied through buffers on the way to
152 * and from clists. The buffers are on the stack so their sizes must be
153 * fairly small.
154 */
155#define IBUFSIZ 384 /* Should be >= max value of MIN. */
156#define OBUFSIZ 100
157
158#ifndef TTYHOG
159#define TTYHOG 1024
160#endif
161
162#define TTMAXHIWAT roundup(2048, CBSIZE)
163#define TTMINHIWAT roundup(100, CBSIZE)
164#define TTMAXLOWAT 256
165#define TTMINLOWAT 32
166#else
167struct tty;
168struct clist;
169#endif /* KERNEL */
170
171/* These flags are kept in t_state. */
172#define TS_SO_OLOWAT 0x00001 /* Wake up when output <= low water. */
173#define TS_ASYNC 0x00002 /* Tty in async I/O mode. */
174#define TS_BUSY 0x00004 /* Draining output. */
175#define TS_CARR_ON 0x00008 /* Carrier is present. */
176#define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */
177#define TS_ISOPEN 0x00020 /* Open has completed. */
178#define TS_TBLOCK 0x00040 /* Further input blocked. */
179#define TS_TIMEOUT 0x00080 /* Wait for output char processing. */
180#define TS_TTSTOP 0x00100 /* Output paused. */
181#ifdef notyet
182#define TS_WOPEN 0x00200 /* Open in progress. */
183#endif
184#define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */
185
186/* State for intra-line fancy editing work. */
187#define TS_BKSL 0x00800 /* State for lowercase \ work. */
188#define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */
189#define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */
190#define TS_LNCH 0x04000 /* Next character is literal. */
191#define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */
192#define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
193
194/* Extras. */
195#define TS_CAN_BYPASS_L_RINT 0x010000 /* Device in "raw" mode. */
196#define TS_CONNECTED 0x020000 /* Connection open. */
197#define TS_SNOOP 0x040000 /* Device is being snooped on. */
198#define TS_SO_OCOMPLETE 0x080000 /* Wake up when output completes. */
199#define TS_ZOMBIE 0x100000 /* Connection lost. */
200
201/* Hardware flow-control-invoked bits. */
202#define TS_CAR_OFLOW 0x200000 /* For MDMBUF (XXX handle in driver). */
203#ifdef notyet
204#define TS_CTS_OFLOW 0x400000 /* For CCTS_OFLOW. */
205#define TS_DSR_OFLOW 0x800000 /* For CDSR_OFLOW. */
206#endif
207
208
209/* Character type information. */
210#define ORDINARY 0
211#define CONTROL 1
212#define BACKSPACE 2
213#define NEWLINE 3
214#define TAB 4
215#define VTAB 5
216#define RETURN 6
217
218struct speedtab {
219 int sp_speed; /* Speed. */
220 int sp_code; /* Code. */
221};
222
223/* Modem control commands (driver). */
224#define DMSET 0
225#define DMBIS 1
226#define DMBIC 2
227#define DMGET 3
228
229/* Flags on a character passed to ttyinput. */
230#define TTY_CHARMASK 0x000000ff /* Character mask */
231#define TTY_QUOTE 0x00000100 /* Character quoted */
232#define TTY_ERRORMASK 0xff000000 /* Error mask */
233#define TTY_FE 0x01000000 /* Framing error */
234#define TTY_PE 0x02000000 /* Parity error */
235#define TTY_OE 0x04000000 /* Overrun error */
236#define TTY_BI 0x08000000 /* Break condition */
237
238#ifdef KERNEL
239/* Is tp controlling terminal for p? */
240#define isctty(p, tp) \
241 ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
242
243/* Is p in background of tp? */
244#define isbackground(p, tp) \
245 (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
246
247/* Unique sleep addresses. */
248#define TSA_CARR_ON(tp) ((void *)&(tp)->t_rawq)
249#define TSA_HUP_OR_INPUT(tp) ((void *)&(tp)->t_rawq.c_cf)
250#define TSA_OCOMPLETE(tp) ((void *)&(tp)->t_outq.c_cl)
251#define TSA_OLOWAT(tp) ((void *)&(tp)->t_outq)
252#define TSA_PTC_READ(tp) ((void *)&(tp)->t_outq.c_cf)
253#define TSA_PTC_WRITE(tp) ((void *)&(tp)->t_rawq.c_cl)
254#define TSA_PTS_READ(tp) ((void *)&(tp)->t_canq)
255
256
257__BEGIN_DECLS
258
259int b_to_q(const u_char *cp, int cc, struct clist *q);
260void catq(struct clist *from, struct clist *to);
261void clist_init(void);
262int getc(struct clist *q);
263void ndflush(struct clist *q, int cc);
264int ndqb(struct clist *q, int flag);
265u_char *firstc (struct clist *clp, int *c);
266u_char *nextc(struct clist *q, u_char *cp, int *c);
267int putc(int c, struct clist *q);
268int q_to_b(struct clist *q, u_char *cp, int cc);
269int unputc(struct clist *q);
270int clalloc(struct clist *clp, int size, int quot);
271void clfree(struct clist *clp);
272void cinit(void);
273void clrbits(u_char *cp, int off, int len);
274
275#ifdef KERNEL_PRIVATE
276int ttcompat(struct tty *tp, u_long com, caddr_t data, int flag,
277 struct proc *p);
278int ttsetcompat(struct tty *tp, u_long *com, caddr_t data, struct termios *term);
279#endif /* KERNEL_PRIVATE */
280
281void termioschars(struct termios *t);
282int tputchar(int c, struct tty *tp);
283int ttioctl(struct tty *tp, u_long com, caddr_t data, int flag,
284 struct proc *p);
285int ttread(struct tty *tp, struct uio *uio, int flag);
286void ttrstrt(void *tp);
287int ttyselect(struct tty *tp, int rw, void * wql, struct proc *p);
288int ttselect(dev_t dev, int rw, void * wql, struct proc *p);
289void ttsetwater(struct tty *tp);
290int ttspeedtab(int speed, struct speedtab *table);
291int ttstart(struct tty *tp);
292void ttwakeup(struct tty *tp);
293int ttwrite(struct tty *tp, struct uio *uio, int flag);
294void ttwwakeup(struct tty *tp);
295void ttyblock(struct tty *tp);
296void ttychars(struct tty *tp);
297int ttycheckoutq(struct tty *tp, int wait);
298int ttyclose(struct tty *tp);
299void ttyflush(struct tty *tp, int rw);
300void ttyinfo(struct tty *tp);
301int ttyinput(int c, struct tty *tp);
302int ttylclose(struct tty *tp, int flag);
303int ttymodem(struct tty *tp, int flag);
304int ttyopen(dev_t device, struct tty *tp);
305int ttysleep(struct tty *tp,
306 void *chan, int pri, const char *wmesg, int timeout);
307int ttywait(struct tty *tp);
308struct tty *ttymalloc(void);
309void ttyfree(struct tty *);
310
311__END_DECLS
312
313#endif /* KERNEL */
314
315
316#endif /* !_SYS_TTY_H_ */