The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/sys/tty.h

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    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  * Copyright (c) 2002 Networks Associates Technologies, Inc.
   11  * All rights reserved.
   12  *
   13  * Portions of this software were developed for the FreeBSD Project by
   14  * ThinkSec AS and NAI Labs, the Security Research Division of Network
   15  * Associates, Inc.  under DARPA/SPAWAR contract N66001-01-C-8035
   16  * ("CBOSS"), as part of the DARPA CHATS research program.
   17  *
   18  * Redistribution and use in source and binary forms, with or without
   19  * modification, are permitted provided that the following conditions
   20  * are met:
   21  * 1. Redistributions of source code must retain the above copyright
   22  *    notice, this list of conditions and the following disclaimer.
   23  * 2. Redistributions in binary form must reproduce the above copyright
   24  *    notice, this list of conditions and the following disclaimer in the
   25  *    documentation and/or other materials provided with the distribution.
   26  * 4. Neither the name of the University nor the names of its contributors
   27  *    may be used to endorse or promote products derived from this software
   28  *    without specific prior written permission.
   29  *
   30  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   31  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   34  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   35  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   36  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   37  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   38  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   39  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   40  * SUCH DAMAGE.
   41  *
   42  *      @(#)tty.h       8.6 (Berkeley) 1/21/94
   43  * $FreeBSD$
   44  */
   45 
   46 #ifndef _SYS_TTY_H_
   47 #define _SYS_TTY_H_
   48 
   49 #include <sys/termios.h>
   50 #include <sys/queue.h>
   51 #include <sys/selinfo.h>
   52 #include <sys/_lock.h>
   53 #include <sys/_mutex.h>
   54 
   55 /*
   56  * Clists are character lists, which is a variable length linked list
   57  * of cblocks, with a count of the number of characters in the list.
   58  */
   59 struct clist {
   60         int     c_cc;           /* Number of characters in the clist. */
   61         int     c_cbcount;      /* Number of cblocks. */
   62         int     c_cbmax;        /* Max # cblocks allowed for this clist. */
   63         int     c_cbreserved;   /* # cblocks reserved for this clist. */
   64         char    *c_cf;          /* Pointer to the first cblock. */
   65         char    *c_cl;          /* Pointer to the last cblock. */
   66 };
   67 
   68 struct tty;
   69 struct pps_state;
   70 struct cdev;
   71 struct cdevsw;
   72 
   73 typedef int t_open_t(struct tty *, struct cdev *);
   74 typedef void t_close_t(struct tty *);
   75 typedef void t_oproc_t(struct tty *);
   76 typedef void t_purge_t(struct tty *);
   77 typedef void t_stop_t(struct tty *, int);
   78 typedef int t_param_t(struct tty *, struct termios *);
   79 typedef int t_modem_t(struct tty *, int, int);
   80 typedef void t_break_t(struct tty *, int);
   81 typedef int t_ioctl_t(struct tty *, u_long cmd, void * data,
   82                       int fflag, struct thread *td);
   83 /* XXX: same as d_ioctl_t in sys/conf.h to avoid #include polution */
   84 typedef int __d_ioctl_t(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread *td);
   85 
   86 
   87 
   88 /*
   89  * Per-tty structure.
   90  *
   91  * Should be split in two, into device and tty drivers.
   92  * Glue could be masks of what to echo and circular buffer
   93  * (low, high, timeout).
   94  */
   95 struct tty {
   96         struct  clist t_rawq;           /* Device raw input queue. */
   97         long    t_rawcc;                /* Raw input queue statistics. */
   98         struct  clist t_canq;           /* Device canonical queue. */
   99         long    t_cancc;                /* Canonical queue statistics. */
  100         struct  clist t_outq;           /* Device output queue. */
  101         long    t_outcc;                /* Output queue statistics. */
  102         int     t_line;                 /* Interface to device drivers. */
  103         struct cdev *t_dev;             /* Device. */
  104         struct cdev *t_mdev;            /* Device. */
  105         u_int   t_devunit;              /* Cdev unit number */
  106         int     t_state;                /* Device and driver (TS*) state. */
  107         int     t_flags;                /* Tty flags. */
  108         int     t_timeout;              /* Timeout for ttywait() */
  109         struct  pgrp *t_pgrp;           /* Foreground process group. */
  110         struct  session *t_session;     /* Enclosing session. */
  111         struct  sigio *t_sigio;         /* Information for async I/O. */
  112         struct  selinfo t_rsel;         /* Tty read/oob select. */
  113         struct  selinfo t_wsel;         /* Tty write select. */
  114         struct  termios t_termios;      /* Termios state. */
  115         struct  termios t_init_in;      /* ... init ingoing */
  116         struct  termios t_init_out;     /* ... outgoing */
  117         struct  termios t_lock_in;      /* ... lock ingoing */
  118         struct  termios t_lock_out;     /* ... outgoing */
  119         struct  winsize t_winsize;      /* Window size. */
  120         void    *t_sc;                  /* driver private softc pointer. */
  121         void    *t_lsc;                 /* linedisc private softc pointer. */
  122         int     t_column;               /* Tty output column. */
  123         int     t_rocount, t_rocol;     /* Tty. */
  124         int     t_ififosize;            /* Total size of upstream fifos. */
  125         int     t_ihiwat;               /* High water mark for input. */
  126         int     t_ilowat;               /* Low water mark for input. */
  127         speed_t t_ispeedwat;            /* t_ispeed override for watermarks. */
  128         int     t_ohiwat;               /* High water mark for output. */
  129         int     t_olowat;               /* Low water mark for output. */
  130         speed_t t_ospeedwat;            /* t_ospeed override for watermarks. */
  131         int     t_gen;                  /* Generation number. */
  132         TAILQ_ENTRY(tty) t_list;        /* Global chain of ttys for pstat(8) */
  133         int     t_actout;               /* Outbound device open */
  134         int     t_wopeners;             /* #threads waiting for DCD in open */
  135 
  136         struct mtx t_mtx;
  137         int     t_refcnt;
  138         int     t_hotchar;              /* linedisc preferred hot char */
  139         int     t_dtr_wait;             /* Inter-session DTR holddown [hz] */
  140         int     t_do_timestamp;         /* flag instead ? */
  141         struct  timeval t_timestamp;    /* char timestamp */
  142         struct  pps_state *t_pps;       /* PPS-API stuff */
  143 
  144         /* Driver supplied methods */
  145         t_oproc_t *t_oproc;             /* Start output. */
  146         t_stop_t *t_stop;               /* Stop output. */
  147         t_param_t *t_param;             /* Set parameters. */
  148         t_modem_t *t_modem;             /* Set modem state (optional). */
  149         t_break_t *t_break;             /* Set break state (optional). */
  150         t_ioctl_t *t_ioctl;             /* Set ioctl handling (optional). */
  151         t_open_t *t_open;               /* First open */
  152         t_purge_t *t_purge;             /* Purge threads */
  153         t_close_t *t_close;             /* Last close */
  154         __d_ioctl_t *t_cioctl;          /* Ioctl on control devices */
  155 };
  156 
  157 #define t_cc            t_termios.c_cc
  158 #define t_cflag         t_termios.c_cflag
  159 #define t_iflag         t_termios.c_iflag
  160 #define t_ispeed        t_termios.c_ispeed
  161 #define t_lflag         t_termios.c_lflag
  162 #define t_min           t_termios.c_min
  163 #define t_oflag         t_termios.c_oflag
  164 #define t_ospeed        t_termios.c_ospeed
  165 #define t_time          t_termios.c_time
  166 
  167 #define TTIPRI          (PSOCK + 1)     /* Sleep priority for tty reads. */
  168 #define TTOPRI          (PSOCK + 2)     /* Sleep priority for tty writes. */
  169 
  170 /*
  171  * Userland version of struct tty, for sysctl.
  172  */
  173 struct xtty {
  174         size_t  xt_size;                /* Structure size. */
  175         long    xt_rawcc;               /* Raw input queue statistics. */
  176         long    xt_cancc;               /* Canonical queue statistics. */
  177         long    xt_outcc;               /* Output queue statistics. */
  178         int     xt_line;                /* Interface to device drivers. */
  179         dev_t   xt_dev;                 /* Userland (sysctl) instance. */
  180         int     xt_state;               /* Device and driver (TS*) state. */
  181         int     xt_flags;               /* Tty flags. */
  182         int     xt_timeout;             /* Timeout for ttywait(). */
  183         pid_t   xt_pgid;                /* Process group ID. */
  184         pid_t   xt_sid;                 /* Session ID. */
  185         struct  termios xt_termios;     /* Termios state. */
  186         struct  winsize xt_winsize;     /* Window size. */
  187         int     xt_column;              /* Tty output column. */
  188         int     xt_rocount, xt_rocol;   /* Tty. */
  189         int     xt_ififosize;           /* Total size of upstream fifos. */
  190         int     xt_ihiwat;              /* High water mark for input. */
  191         int     xt_ilowat;              /* Low water mark for input. */
  192         speed_t xt_ispeedwat;           /* t_ispeed override for watermarks. */
  193         int     xt_ohiwat;              /* High water mark for output. */
  194         int     xt_olowat;              /* Low water mark for output. */
  195         speed_t xt_ospeedwat;           /* t_ospeed override for watermarks. */
  196 };
  197 
  198 /*
  199  * User data unfortunately has to be copied through buffers on the way to
  200  * and from clists.  The buffers are on the stack so their sizes must be
  201  * fairly small.
  202  */
  203 #define IBUFSIZ 384                     /* Should be >= max value of MIN. */
  204 #define OBUFSIZ 100
  205 
  206 #ifndef TTYHOG
  207 #define TTYHOG  8192
  208 #endif
  209 
  210 #ifdef _KERNEL
  211 #define TTMAXHIWAT      roundup(2048, CBSIZE)
  212 #define TTMINHIWAT      roundup(100, CBSIZE)
  213 #define TTMAXLOWAT      256
  214 #define TTMINLOWAT      32
  215 #endif
  216 
  217 /* These flags are kept in t_state. */
  218 #define TS_SO_OLOWAT    0x00001         /* Wake up when output <= low water. */
  219 #define TS_ASYNC        0x00002         /* Tty in async I/O mode. */
  220 #define TS_BUSY         0x00004         /* Draining output. */
  221 #define TS_CARR_ON      0x00008         /* Carrier is present. */
  222 #define TS_FLUSH        0x00010         /* Outq has been flushed during DMA. */
  223 #define TS_ISOPEN       0x00020         /* Open has completed. */
  224 #define TS_TBLOCK       0x00040         /* Further input blocked. */
  225 #define TS_TIMEOUT      0x00080         /* Wait for output char processing. */
  226 #define TS_TTSTOP       0x00100         /* Output paused. */
  227 #ifdef notyet
  228 #define TS_WOPEN        0x00200         /* Open in progress. */
  229 #endif
  230 #define TS_XCLUDE       0x00400         /* Tty requires exclusivity. */
  231 
  232 /* State for intra-line fancy editing work. */
  233 #define TS_BKSL         0x00800         /* State for lowercase \ work. */
  234 #define TS_CNTTB        0x01000         /* Counting tab width, ignore FLUSHO. */
  235 #define TS_ERASE        0x02000         /* Within a \.../ for PRTRUB. */
  236 #define TS_LNCH         0x04000         /* Next character is literal. */
  237 #define TS_TYPEN        0x08000         /* Retyping suspended input (PENDIN). */
  238 #define TS_LOCAL        (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
  239 
  240 /* Extras. */
  241 #define TS_CAN_BYPASS_L_RINT 0x010000   /* Device in "raw" mode. */
  242 #define TS_CONNECTED    0x020000        /* Connection open. */
  243 #define TS_SNOOP        0x040000        /* Device is being snooped on. */
  244 #define TS_SO_OCOMPLETE 0x080000        /* Wake up when output completes. */
  245 #define TS_ZOMBIE       0x100000        /* Connection lost. */
  246 
  247 /* Hardware flow-control-invoked bits. */
  248 #define TS_CAR_OFLOW    0x200000        /* For MDMBUF (XXX handle in driver). */
  249 #ifdef notyet
  250 #define TS_CTS_OFLOW    0x400000        /* For CCTS_OFLOW. */
  251 #define TS_DSR_OFLOW    0x800000        /* For CDSR_OFLOW. */
  252 #endif
  253 
  254 #define TS_DTR_WAIT     0x1000000       /* DTR hold-down between sessions */
  255 #define TS_GONE         0x2000000       /* Hardware detached */
  256 
  257 /* Character type information. */
  258 #define ORDINARY        0
  259 #define CONTROL         1
  260 #define BACKSPACE       2
  261 #define NEWLINE         3
  262 #define TAB             4
  263 #define VTAB            5
  264 #define RETURN          6
  265 
  266 struct speedtab {
  267         int sp_speed;                   /* Speed. */
  268         int sp_code;                    /* Code. */
  269 };
  270 
  271 /* Modem control commands (driver). */
  272 #define DMSET           0
  273 #define DMBIS           1
  274 #define DMBIC           2
  275 #define DMGET           3
  276 
  277 /* Flags on a character passed to ttyinput. */
  278 #define TTY_CHARMASK    0x000000ff      /* Character mask */
  279 #define TTY_QUOTE       0x00000100      /* Character quoted */
  280 #define TTY_ERRORMASK   0xff000000      /* Error mask */
  281 #define TTY_FE          0x01000000      /* Framing error */
  282 #define TTY_PE          0x02000000      /* Parity error */
  283 #define TTY_OE          0x04000000      /* Overrun error */
  284 #define TTY_BI          0x08000000      /* Break condition */
  285 
  286 /* Is tp controlling terminal for p? */
  287 #define isctty(p, tp)                                                   \
  288         ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT)
  289 
  290 /* Is p in background of tp? */
  291 #define isbackground(p, tp)                                             \
  292         (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp)
  293 
  294 /* Unique sleep addresses. */
  295 #define TSA_CARR_ON(tp)         ((void *)&(tp)->t_rawq)
  296 #define TSA_HUP_OR_INPUT(tp)    ((void *)&(tp)->t_rawq.c_cf)
  297 #define TSA_OCOMPLETE(tp)       ((void *)&(tp)->t_outq.c_cl)
  298 #define TSA_OLOWAT(tp)          ((void *)&(tp)->t_outq)
  299 
  300 #ifdef _KERNEL
  301 #ifdef MALLOC_DECLARE
  302 MALLOC_DECLARE(M_TTYS);
  303 #endif
  304 
  305 /* Minor number flag bits */
  306 #define MINOR_CALLOUT   0x80000000
  307 #define MINOR_INIT      0x40000000
  308 #define MINOR_LOCK      0x20000000
  309 
  310 #define ISCALLOUT(dev)  (minor(dev) & MINOR_CALLOUT)
  311 #define ISINIT(dev)     (minor(dev) & MINOR_INIT)
  312 #define ISLOCK(dev)     (minor(dev) & MINOR_LOCK)
  313 
  314 extern  struct msgbuf consmsgbuf; /* Message buffer for constty. */
  315 extern  struct tty *constty;    /* Temporary virtual console. */
  316 extern long tk_cancc;
  317 extern long tk_nin;
  318 extern long tk_nout;
  319 extern long tk_rawcc;
  320 
  321 int      b_to_q(char *cp, int cc, struct clist *q);
  322 void     catq(struct clist *from, struct clist *to);
  323 void     clist_alloc_cblocks(struct clist *q, int ccmax, int ccres);
  324 void     clist_free_cblocks(struct clist *q);
  325 void     constty_set(struct tty *tp);
  326 void     constty_clear(void);
  327 int      getc(struct clist *q);
  328 void     ndflush(struct clist *q, int cc);
  329 char    *nextc(struct clist *q, char *cp, int *c);
  330 void     nottystop(struct tty *tp, int rw);
  331 int      putc(int c, struct clist *q);
  332 int      q_to_b(struct clist *q, char *cp, int cc);
  333 void     termioschars(struct termios *t);
  334 int      tputchar(int c, struct tty *tp);
  335 int      ttcompat(struct tty *tp, u_long com, caddr_t data, int flag);
  336 int      ttioctl(struct tty *tp, u_long com, void *data, int flag);
  337 int      ttread(struct tty *tp, struct uio *uio, int flag);
  338 void     ttrstrt(void *tp);
  339 int      ttsetcompat(struct tty *tp, u_long *com, caddr_t data,
  340             struct termios *term);
  341 void     ttsetwater(struct tty *tp);
  342 int      ttspeedtab(int speed, struct speedtab *table);
  343 int      ttstart(struct tty *tp);
  344 void     ttwakeup(struct tty *tp);
  345 int      ttwrite(struct tty *tp, struct uio *uio, int flag);
  346 void     ttwwakeup(struct tty *tp);
  347 struct tty *ttyalloc(void);
  348 void     ttyblock(struct tty *tp);
  349 void     ttychars(struct tty *tp);
  350 int      ttycheckoutq(struct tty *tp, int wait);
  351 void     ttyconsolemode(struct tty *tp, int speed);
  352 int      tty_close(struct tty *tp);
  353 int      ttycreate(struct tty *tp, struct cdevsw *, int unit, int flags, const char *fmt, ...) __printflike(5, 6);
  354 int      ttydtrwaitsleep(struct tty *tp);
  355 void     ttydtrwaitstart(struct tty *tp);
  356 void     ttyflush(struct tty *tp, int rw);
  357 void     ttyfree(struct tty *tp);
  358 void     ttygone(struct tty *tp);
  359 void     ttyinfo(struct tty *tp);
  360 void     ttyinitmode(struct tty *tp, int echo, int speed);
  361 int      ttyinput(int c, struct tty *tp);
  362 int      ttylclose(struct tty *tp, int flag);
  363 void     ttyldoptim(struct tty *tp);
  364 struct tty *ttymalloc(struct tty *tp);
  365 int      ttymodem(struct tty *tp, int flag);
  366 int      tty_open(struct cdev *device, struct tty *tp);
  367 int      ttyref(struct tty *tp);
  368 int      ttyrel(struct tty *tp);
  369 int      ttysleep(struct tty *tp, void *chan, int pri, char *wmesg, int timo);
  370 int      ttywait(struct tty *tp);
  371 int      unputc(struct clist *q);
  372 
  373 /*
  374  * XXX: temporary
  375  */
  376 #include <sys/linedisc.h>
  377 
  378 #endif /* _KERNEL */
  379 
  380 #endif /* !_SYS_TTY_H_ */

Cache object: e93cdfc90406fe6b48674231bcce0ec0


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.