| 1 | /*- |
| 2 | * Copyright (c) 1982, 1986 The Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. All advertising materials mentioning features or use of this software |
| 14 | * must display the following acknowledgement: |
| 15 | * This product includes software developed by the University of |
| 16 | * California, Berkeley and its contributors. |
| 17 | * 4. Neither the name of the University nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this software |
| 19 | * without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | * |
| 33 | * from: @(#)tty.h 7.10 (Berkeley) 6/26/91 |
| 34 | * $Id$ |
| 35 | */ |
| 36 | |
| 37 | #ifndef _SYS_TTY_H_ |
| 38 | #define _SYS_TTY_H_ |
| 39 | |
| 40 | #include <sys/termios.h> |
| 41 | |
| 42 | /* |
| 43 | * Ring buffers provide a contiguous, dense storage for |
| 44 | * character data used by the tty driver. |
| 45 | */ |
| 46 | #define RBSZ 1024 |
| 47 | |
| 48 | struct ringb { |
| 49 | char *rb_hd; /* head of buffer segment to be read */ |
| 50 | char *rb_tl; /* tail of buffer segment to be written */ |
| 51 | char rb_buf[RBSZ]; /* segment contents */ |
| 52 | }; |
| 53 | |
| 54 | #define RB_SUCC(rbp, p) \ |
| 55 | ((p) >= (rbp)->rb_buf + RBSZ - 1 ? (rbp)->rb_buf : (p) + 1) |
| 56 | |
| 57 | #define RB_ROLLOVER(rbp, p) \ |
| 58 | ((p) > (rbp)->rb_buf + RBSZ - 1 ? (rbp)->rb_buf : (p)) |
| 59 | |
| 60 | #define RB_PRED(rbp, p) \ |
| 61 | ((p) <= (rbp)->rb_buf ? (rbp)->rb_buf + RBSZ - 1 : (p) - 1) |
| 62 | |
| 63 | #define RB_LEN(rp) \ |
| 64 | ((rp)->rb_hd <= (rp)->rb_tl ? (rp)->rb_tl - (rp)->rb_hd : \ |
| 65 | RBSZ - ((rp)->rb_hd - (rp)->rb_tl)) |
| 66 | |
| 67 | #define RB_CONTIGPUT(rp) \ |
| 68 | (RB_PRED(rp, (rp)->rb_hd) < (rp)->rb_tl ? \ |
| 69 | (rp)->rb_buf + RBSZ - (rp)->rb_tl : \ |
| 70 | RB_PRED(rp, (rp)->rb_hd) - (rp)->rb_tl) |
| 71 | |
| 72 | #define RB_CONTIGGET(rp) \ |
| 73 | ((rp)->rb_hd <= (rp)->rb_tl ? (rp)->rb_tl - (rp)->rb_hd : \ |
| 74 | (rp)->rb_buf + RBSZ - (rp)->rb_hd) |
| 75 | |
| 76 | /* |
| 77 | * Per-tty structure. |
| 78 | * |
| 79 | * Should be split in two, into device and tty drivers. |
| 80 | * Glue could be masks of what to echo and circular buffer |
| 81 | * (low, high, timeout). |
| 82 | */ |
| 83 | struct tty { |
| 84 | int (*t_oproc)(); /* device */ |
| 85 | int (*t_param)(); /* device */ |
| 86 | pid_t t_rsel; /* tty */ |
| 87 | pid_t t_wsel; |
| 88 | caddr_t T_LINEP; /* XXX */ |
| 89 | caddr_t t_addr; /* ??? */ |
| 90 | dev_t t_dev; /* device */ |
| 91 | int t_flags; /* (compat) some of both */ |
| 92 | int t_state; /* some of both */ |
| 93 | struct session *t_session; /* tty */ |
| 94 | struct pgrp *t_pgrp; /* foreground process group */ |
| 95 | char t_line; /* glue */ |
| 96 | short t_col; /* tty */ |
| 97 | short t_rocount, t_rocol; /* tty */ |
| 98 | short t_hiwat; /* hi water mark */ |
| 99 | short t_lowat; /* low water mark */ |
| 100 | struct winsize t_winsize; /* window size */ |
| 101 | struct termios t_termios; /* termios state */ |
| 102 | #define t_iflag t_termios.c_iflag |
| 103 | #define t_oflag t_termios.c_oflag |
| 104 | #define t_cflag t_termios.c_cflag |
| 105 | #define t_lflag t_termios.c_lflag |
| 106 | #define t_min t_termios.c_min |
| 107 | #define t_time t_termios.c_time |
| 108 | #define t_cc t_termios.c_cc |
| 109 | #define t_ispeed t_termios.c_ispeed |
| 110 | #define t_ospeed t_termios.c_ospeed |
| 111 | long t_cancc; /* stats */ |
| 112 | long t_rawcc; |
| 113 | long t_outcc; |
| 114 | short t_gen; /* generation number */ |
| 115 | short t_mask; /* interrupt mask */ |
| 116 | struct ringb t_raw; /* ring buffers */ |
| 117 | struct ringb t_can; |
| 118 | struct ringb t_out; |
| 119 | }; |
| 120 | |
| 121 | #define TTIPRI 25 /* sleep priority for tty reads */ |
| 122 | #define TTOPRI 26 /* sleep priority for tty writes */ |
| 123 | |
| 124 | #define TTMASK 15 |
| 125 | #define OBUFSIZ 100 |
| 126 | #define TTYHOG 1024 |
| 127 | |
| 128 | #ifdef KERNEL |
| 129 | #define TTMAXHIWAT (RBSZ/2) /* XXX */ |
| 130 | #define TTMINHIWAT 128 |
| 131 | #define TTMAXLOWAT 256 |
| 132 | #define TTMINLOWAT 32 |
| 133 | extern struct ttychars ttydefaults; |
| 134 | #endif /* KERNEL */ |
| 135 | |
| 136 | /* internal state bits */ |
| 137 | #define TS_TIMEOUT 0x000001 /* delay timeout in progress */ |
| 138 | #define TS_WOPEN 0x000002 /* waiting for open to complete */ |
| 139 | #define TS_ISOPEN 0x000004 /* device is open */ |
| 140 | #define TS_FLUSH 0x000008 /* outq has been flushed during DMA */ |
| 141 | #define TS_CARR_ON 0x000010 /* software copy of carrier-present */ |
| 142 | #define TS_BUSY 0x000020 /* output in progress */ |
| 143 | #define TS_ASLEEP 0x000040 /* wakeup when output done */ |
| 144 | #define TS_XCLUDE 0x000080 /* exclusive-use flag against open */ |
| 145 | #define TS_TTSTOP 0x000100 /* output stopped by ctl-s */ |
| 146 | /* was TS_HUPCLS 0x000200 * hang up upon last close */ |
| 147 | #define TS_TBLOCK 0x000400 /* tandem queue blocked */ |
| 148 | #define TS_RCOLL 0x000800 /* collision in read select */ |
| 149 | #define TS_WCOLL 0x001000 /* collision in write select */ |
| 150 | #define TS_ASYNC 0x004000 /* tty in async i/o mode */ |
| 151 | /* state for intra-line fancy editing work */ |
| 152 | #define TS_BKSL 0x010000 /* state for lowercase \ work */ |
| 153 | #define TS_ERASE 0x040000 /* within a \.../ for PRTRUB */ |
| 154 | #define TS_LNCH 0x080000 /* next character is literal */ |
| 155 | #define TS_TYPEN 0x100000 /* retyping suspended input (PENDIN) */ |
| 156 | #define TS_CNTTB 0x200000 /* counting tab width, ignore FLUSHO */ |
| 157 | |
| 158 | #define TS_LOCAL (TS_BKSL|TS_ERASE|TS_LNCH|TS_TYPEN|TS_CNTTB) |
| 159 | |
| 160 | /* define partab character types */ |
| 161 | #define ORDINARY 0 |
| 162 | #define CONTROL 1 |
| 163 | #define BACKSPACE 2 |
| 164 | #define NEWLINE 3 |
| 165 | #define TAB 4 |
| 166 | #define VTAB 5 |
| 167 | #define RETURN 6 |
| 168 | |
| 169 | struct speedtab { |
| 170 | int sp_speed; |
| 171 | int sp_code; |
| 172 | }; |
| 173 | /* |
| 174 | * Flags on character passed to ttyinput |
| 175 | */ |
| 176 | #define TTY_CHARMASK 0x000000ff /* Character mask */ |
| 177 | #define TTY_QUOTE 0x00000100 /* Character quoted */ |
| 178 | #define TTY_ERRORMASK 0xff000000 /* Error mask */ |
| 179 | #define TTY_FE 0x01000000 /* Framing error or BREAK condition */ |
| 180 | #define TTY_PE 0x02000000 /* Parity error */ |
| 181 | |
| 182 | /* |
| 183 | * Is tp controlling terminal for p |
| 184 | */ |
| 185 | #define isctty(p, tp) ((p)->p_session == (tp)->t_session && \ |
| 186 | (p)->p_flag&SCTTY) |
| 187 | /* |
| 188 | * Is p in background of tp |
| 189 | */ |
| 190 | #define isbackground(p, tp) (isctty((p), (tp)) && \ |
| 191 | (p)->p_pgrp != (tp)->t_pgrp) |
| 192 | /* |
| 193 | * Modem control commands (driver). |
| 194 | */ |
| 195 | #define DMSET 0 |
| 196 | #define DMBIS 1 |
| 197 | #define DMBIC 2 |
| 198 | #define DMGET 3 |
| 199 | |
| 200 | #ifdef KERNEL |
| 201 | /* symbolic sleep message strings */ |
| 202 | extern char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[]; |
| 203 | #endif |
| 204 | |
| 205 | #endif /* _SYS_TTY_H_ */ |