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