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