root/include/linux/tty.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 #ifndef _LINUX_TTY_H
   2 #define _LINUX_TTY_H
   3 
   4 /*
   5  * 'tty.h' defines some structures used by tty_io.c and some defines.
   6  */
   7 
   8 #include <linux/termios.h>
   9 
  10 #include <asm/system.h>
  11 
  12 #define NR_CONSOLES     8
  13 #define NR_LDISCS       16
  14 
  15 /*
  16  * These are set up by the setup-routine at boot-time:
  17  */
  18 
  19 struct screen_info {
  20         unsigned char  orig_x;
  21         unsigned char  orig_y;
  22         unsigned char  unused1[2];
  23         unsigned short orig_video_page;
  24         unsigned char  orig_video_mode;
  25         unsigned char  orig_video_cols;
  26         unsigned short orig_video_ega_ax;
  27         unsigned short orig_video_ega_bx;
  28         unsigned short orig_video_ega_cx;
  29         unsigned char  orig_video_lines;
  30 };
  31 
  32 extern struct screen_info screen_info;
  33 
  34 #define ORIG_X                  (screen_info.orig_x)
  35 #define ORIG_Y                  (screen_info.orig_y)
  36 #define ORIG_VIDEO_PAGE         (screen_info.orig_video_page)
  37 #define ORIG_VIDEO_MODE         (screen_info.orig_video_mode)
  38 #define ORIG_VIDEO_COLS         (screen_info.orig_video_cols)
  39 #define ORIG_VIDEO_EGA_AX       (screen_info.orig_video_ega_ax)
  40 #define ORIG_VIDEO_EGA_BX       (screen_info.orig_video_ega_bx)
  41 #define ORIG_VIDEO_EGA_CX       (screen_info.orig_video_ega_cx)
  42 #define ORIG_VIDEO_LINES        (screen_info.orig_video_lines)
  43 
  44 #define VIDEO_TYPE_MDA          0x10    /* Monochrome Text Display      */
  45 #define VIDEO_TYPE_CGA          0x11    /* CGA Display                  */
  46 #define VIDEO_TYPE_EGAM         0x20    /* EGA/VGA in Monochrome Mode   */
  47 #define VIDEO_TYPE_EGAC         0x21    /* EGA/VGA in Color Mode        */
  48 
  49 /*
  50  * This character is the same as _POSIX_VDISABLE: it cannot be used as
  51  * a c_cc[] character, but indicates that a particular special character
  52  * isn't in use (eg VINTR ahs no character etc)
  53  */
  54 #define __DISABLED_CHAR '\0'
  55 
  56 /*
  57  * See comment for the tty_struct structure before changing
  58  * TTY_BUF_SIZE.  Actually, there should be different sized tty_queue
  59  * structures for different purposes.  1024 bytes for the transmit
  60  * queue is way overkill.  TYT, 9/14/92
  61  */
  62 #define TTY_BUF_SIZE 1024       /* Must be a power of 2 */
  63 
  64 struct tty_queue {
  65         unsigned long head;
  66         unsigned long tail;
  67         struct wait_queue * proc_list;
  68         unsigned char buf[TTY_BUF_SIZE];
  69 };
  70 
  71 struct serial_struct {
  72         int     type;
  73         int     line;
  74         int     port;
  75         int     irq;
  76         int     flags;
  77         int     xmit_fifo_size;
  78         int     custom_divisor;
  79         int     baud_base;
  80         unsigned short  close_delay;
  81         char    reserved_char[2];
  82         int     hub6;
  83         int     reserved[5];
  84 };
  85 
  86 /*
  87  * These are the supported serial types.
  88  */
  89 #define PORT_UNKNOWN    0
  90 #define PORT_8250       1
  91 #define PORT_16450      2
  92 #define PORT_16550      3
  93 #define PORT_16550A     4
  94 #define PORT_MAX        4
  95 
  96 /*
  97  * Definitions for async_struct (and serial_struct) flags field
  98  */
  99 #define ASYNC_HUP_NOTIFY 0x0001 /* Notify getty on hangups and closes 
 100                                    on the callout port */
 101 #define ASYNC_FOURPORT  0x0002  /* Set OU1, OUT2 per AST Fourport settings */
 102 #define ASYNC_SAK       0x0004  /* Secure Attention Key (Orange book) */
 103 #define ASYNC_SPLIT_TERMIOS 0x0008 /* Separate termios for dialin/callout */
 104 
 105 #define ASYNC_SPD_MASK  0x0030
 106 #define ASYNC_SPD_HI    0x0010  /* Use 56000 instead of 38400 bps */
 107 #define ASYNC_SPD_VHI   0x0020  /* Use 115200 instead of 38400 bps */
 108 #define ASYNC_SPD_CUST  0x0030  /* Use user-specified divisor */
 109 
 110 #define ASYNC_SKIP_TEST 0x0040 /* Skip UART test during autoconfiguration */
 111 #define ASYNC_AUTO_IRQ  0x0080 /* Do automatic IRQ during autoconfiguration */
 112 #define ASYNC_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
 113 #define ASYNC_PGRP_LOCKOUT    0x0200 /* Lock out cua opens based on pgrp */
 114 #define ASYNC_CALLOUT_NOHUP   0x0400 /* Don't do hangups for cua device */
 115 
 116 #define ASYNC_FLAGS     0x0FFF  /* Possible legal async flags */
 117 #define ASYNC_USR_MASK 0x0430   /* Legal flags that non-privileged
 118                                  * users can set or reset */
 119 
 120 /* Internal flags used only by kernel/chr_drv/serial.c */
 121 #define ASYNC_INITIALIZED       0x80000000 /* Serial port was initialized */
 122 #define ASYNC_CALLOUT_ACTIVE    0x40000000 /* Call out device is active */
 123 #define ASYNC_NORMAL_ACTIVE     0x20000000 /* Normal device is active */
 124 #define ASYNC_BOOT_AUTOCONF     0x10000000 /* Autoconfigure port on bootup */
 125 #define ASYNC_CLOSING           0x08000000 /* Serial port is closing */
 126 
 127 #define IS_A_CONSOLE(min)       (((min) & 0xC0) == 0x00)
 128 #define IS_A_SERIAL(min)        (((min) & 0xC0) == 0x40)
 129 #define IS_A_PTY(min)           ((min) & 0x80)
 130 #define IS_A_PTY_MASTER(min)    (((min) & 0xC0) == 0x80)
 131 #define IS_A_PTY_SLAVE(min)     (((min) & 0xC0) == 0xC0)
 132 #define PTY_OTHER(min)          ((min) ^ 0x40)
 133 
 134 #define SL_TO_DEV(line)         ((line) | 0x40)
 135 #define DEV_TO_SL(min)          ((min) & 0x3F)
 136 
 137 #define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))
 138 #define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))
 139 #define EMPTY(a) ((a)->head == (a)->tail)
 140 #define LEFT(a) (((a)->tail-(a)->head-1)&(TTY_BUF_SIZE-1))
 141 #define LAST(a) ((a)->buf[(TTY_BUF_SIZE-1)&((a)->head-1)])
 142 #define FULL(a) (!LEFT(a))
 143 #define CHARS(a) (((a)->head-(a)->tail)&(TTY_BUF_SIZE-1))
 144 
 145 extern void put_tty_queue(unsigned char c, struct tty_queue * queue);
 146 extern int get_tty_queue(struct tty_queue * queue);
 147 
 148 #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
 149 #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
 150 #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
 151 #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
 152 #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
 153 #define TIME_CHAR(tty) ((tty)->termios->c_cc[VTIME])
 154 #define MIN_CHAR(tty) ((tty)->termios->c_cc[VMIN])
 155 #define SWTC_CHAR(tty) ((tty)->termios->c_cc[VSWTC])
 156 #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
 157 #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
 158 #define SUSP_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
 159 #define EOL_CHAR(tty) ((tty)->termios->c_cc[VEOL])
 160 #define REPRINT_CHAR(tty) ((tty)->termios->c_cc[VREPRINT])
 161 #define DISCARD_CHAR(tty) ((tty)->termios->c_cc[VDISCARD])
 162 #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE])
 163 #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT])
 164 #define EOL2_CHAR(tty) ((tty)->termios->c_cc[VEOL2])
 165 
 166 #define _I_FLAG(tty,f)  ((tty)->termios->c_iflag & (f))
 167 #define _O_FLAG(tty,f)  ((tty)->termios->c_oflag & (f))
 168 #define _C_FLAG(tty,f)  ((tty)->termios->c_cflag & (f))
 169 #define _L_FLAG(tty,f)  ((tty)->termios->c_lflag & (f))
 170 
 171 #define I_IGNBRK(tty)   _I_FLAG((tty),IGNBRK)
 172 #define I_BRKINT(tty)   _I_FLAG((tty),BRKINT)
 173 #define I_IGNPAR(tty)   _I_FLAG((tty),IGNPAR)
 174 #define I_PARMRK(tty)   _I_FLAG((tty),PARMRK)
 175 #define I_INPCK(tty)    _I_FLAG((tty),INPCK)
 176 #define I_ISTRIP(tty)   _I_FLAG((tty),ISTRIP)
 177 #define I_INLCR(tty)    _I_FLAG((tty),INLCR)
 178 #define I_IGNCR(tty)    _I_FLAG((tty),IGNCR)
 179 #define I_ICRNL(tty)    _I_FLAG((tty),ICRNL)
 180 #define I_IUCLC(tty)    _I_FLAG((tty),IUCLC)
 181 #define I_IXON(tty)     _I_FLAG((tty),IXON)
 182 #define I_IXANY(tty)    _I_FLAG((tty),IXANY)
 183 #define I_IXOFF(tty)    _I_FLAG((tty),IXOFF)
 184 #define I_IMAXBEL(tty)  _I_FLAG((tty),IMAXBEL)
 185 
 186 #define O_OPOST(tty)    _O_FLAG((tty),OPOST)
 187 #define O_OLCUC(tty)    _O_FLAG((tty),OLCUC)
 188 #define O_ONLCR(tty)    _O_FLAG((tty),ONLCR)
 189 #define O_OCRNL(tty)    _O_FLAG((tty),OCRNL)
 190 #define O_ONOCR(tty)    _O_FLAG((tty),ONOCR)
 191 #define O_ONLRET(tty)   _O_FLAG((tty),ONLRET)
 192 #define O_OFILL(tty)    _O_FLAG((tty),OFILL)
 193 #define O_OFDEL(tty)    _O_FLAG((tty),OFDEL)
 194 #define O_NLDLY(tty)    _O_FLAG((tty),NLDLY)
 195 #define O_CRDLY(tty)    _O_FLAG((tty),CRDLY)
 196 #define O_TABDLY(tty)   _O_FLAG((tty),TABDLY)
 197 #define O_BSDLY(tty)    _O_FLAG((tty),BSDLY)
 198 #define O_VTDLY(tty)    _O_FLAG((tty),VTDLY)
 199 #define O_FFDLY(tty)    _O_FLAG((tty),FFDLY)
 200 
 201 #define C_BAUD(tty)     _C_FLAG((tty),CBAUD)
 202 #define C_CSIZE(tty)    _C_FLAG((tty),CSIZE)
 203 #define C_CSTOPB(tty)   _C_FLAG((tty),CSTOPB)
 204 #define C_CREAD(tty)    _C_FLAG((tty),CREAD)
 205 #define C_PARENB(tty)   _C_FLAG((tty),PARENB)
 206 #define C_PARODD(tty)   _C_FLAG((tty),PARODD)
 207 #define C_HUPCL(tty)    _C_FLAG((tty),HUPCL)
 208 #define C_CLOCAL(tty)   _C_FLAG((tty),CLOCAL)
 209 #define C_CIBAUD(tty)   _C_FLAG((tty),CIBAUD)
 210 #define C_CRTSCTS(tty)  _C_FLAG((tty),CRTSCTS)
 211 
 212 #define L_ISIG(tty)     _L_FLAG((tty),ISIG)
 213 #define L_ICANON(tty)   _L_FLAG((tty),ICANON)
 214 #define L_XCASE(tty)    _L_FLAG((tty),XCASE)
 215 #define L_ECHO(tty)     _L_FLAG((tty),ECHO)
 216 #define L_ECHOE(tty)    _L_FLAG((tty),ECHOE)
 217 #define L_ECHOK(tty)    _L_FLAG((tty),ECHOK)
 218 #define L_ECHONL(tty)   _L_FLAG((tty),ECHONL)
 219 #define L_NOFLSH(tty)   _L_FLAG((tty),NOFLSH)
 220 #define L_TOSTOP(tty)   _L_FLAG((tty),TOSTOP)
 221 #define L_ECHOCTL(tty)  _L_FLAG((tty),ECHOCTL)
 222 #define L_ECHOPRT(tty)  _L_FLAG((tty),ECHOPRT)
 223 #define L_ECHOKE(tty)   _L_FLAG((tty),ECHOKE)
 224 #define L_FLUSHO(tty)   _L_FLAG((tty),FLUSHO)
 225 #define L_PENDIN(tty)   _L_FLAG((tty),PENDIN)
 226 #define L_IEXTEN(tty)   _L_FLAG((tty),IEXTEN)
 227 
 228 /*
 229  * Where all of the state associated with a tty is kept while the tty
 230  * is open.  Since the termios state should be kept even if the tty
 231  * has been closed --- for things like the baud rate, etc --- it is
 232  * not stored here, but rather a pointer to the real state is stored
 233  * here.  Possible the winsize structure should have the same
 234  * treatment, but (1) the default 80x24 is usually right and (2) it's
 235  * most often used by a windowing system, which will set the correct
 236  * size each time the window is created or resized anyway.
 237  * IMPORTANT: since this structure is dynamically allocated, it must
 238  * be no larger than 4096 bytes.  Changing TTY_BUF_SIZE will change
 239  * the size of this structure, and it needs to be done with care.
 240  *                                              - TYT, 9/14/92
 241  */
 242 struct tty_struct {
 243         struct termios *termios;
 244         int pgrp;
 245         int session;
 246         unsigned char stopped:1, hw_stopped:1, packet:1, lnext:1;
 247         unsigned char char_error:3;
 248         unsigned char erasing:1;
 249         unsigned char ctrl_status;
 250         short line;
 251         int disc;
 252         int flags;
 253         int count;
 254         unsigned int column;
 255         struct winsize winsize;
 256         int  (*open)(struct tty_struct * tty, struct file * filp);
 257         void (*close)(struct tty_struct * tty, struct file * filp);
 258         void (*write)(struct tty_struct * tty);
 259         int  (*ioctl)(struct tty_struct *tty, struct file * file,
 260                     unsigned int cmd, unsigned long arg);
 261         void (*throttle)(struct tty_struct * tty, int status);
 262         void (*set_termios)(struct tty_struct *tty, struct termios * old);
 263         void (*stop)(struct tty_struct *tty);
 264         void (*start)(struct tty_struct *tty);
 265         void (*hangup)(struct tty_struct *tty);
 266         struct tty_struct *link;
 267         unsigned char *write_data_ptr;
 268         int write_data_cnt;
 269         void (*write_data_callback)(void * data);
 270         void * write_data_arg;
 271         int readq_flags[TTY_BUF_SIZE/32];
 272         int secondary_flags[TTY_BUF_SIZE/32];
 273         int canon_data;
 274         unsigned long canon_head;
 275         unsigned int canon_column;
 276         struct tty_queue read_q;
 277         struct tty_queue write_q;
 278         struct tty_queue secondary;
 279         void *disc_data;
 280 };
 281 
 282 struct tty_ldisc {
 283         int     flags;
 284         /*
 285          * The following routines are called from above.
 286          */
 287         int     (*open)(struct tty_struct *);
 288         void    (*close)(struct tty_struct *);
 289         int     (*read)(struct tty_struct * tty, struct file * file,
 290                         unsigned char * buf, unsigned int nr);
 291         int     (*write)(struct tty_struct * tty, struct file * file,
 292                          unsigned char * buf, unsigned int nr); 
 293         int     (*ioctl)(struct tty_struct * tty, struct file * file,
 294                          unsigned int cmd, unsigned long arg);
 295         int     (*select)(struct tty_struct * tty, struct inode * inode,
 296                           struct file * file, int sel_type,
 297                           struct select_table_struct *wait);
 298         /*
 299          * The following routines are called from below.
 300          */
 301         void    (*handler)(struct tty_struct *);
 302 };
 303 
 304 #define LDISC_FLAG_DEFINED      0x00000001
 305 
 306 /*
 307  * These are the different types of thottle status which can be sent
 308  * to the low-level tty driver.  The tty_io.c layer is responsible for
 309  * notifying the low-level tty driver of the following conditions:
 310  * secondary queue full, secondary queue available, and read queue
 311  * available.  The low-level driver must send the read queue full
 312  * command to itself, if it is interested in that condition.
 313  *
 314  * Note that the low-level tty driver may elect to ignore one or both
 315  * of these conditions; normally, however, it will use ^S/^Q or some
 316  * sort of hardware flow control to regulate the input to try to avoid
 317  * overflow.  While the low-level driver is responsible for all
 318  * receiving flow control, note that the ^S/^Q handling (but not
 319  * hardware flow control) is handled by the upper layer, in
 320  * copy_to_cooked.  
 321  */
 322 #define TTY_THROTTLE_SQ_FULL    1
 323 #define TTY_THROTTLE_SQ_AVAIL   2
 324 #define TTY_THROTTLE_RQ_FULL    3
 325 #define TTY_THROTTLE_RQ_AVAIL   4
 326 
 327 /*
 328  * This defines the low- and high-watermarks for the various conditions.
 329  * Again, the low-level driver is free to ignore any of these, and has
 330  * to implement RQ_THREHOLD_LW for itself if it wants it.
 331  */
 332 #define SQ_THRESHOLD_LW 16
 333 #define SQ_THRESHOLD_HW 768
 334 #define RQ_THRESHOLD_LW 16
 335 #define RQ_THRESHOLD_HW 768
 336 
 337 /*
 338  * These bits are used in the flags field of the tty structure.
 339  * 
 340  * So that interrupts won't be able to mess up the queues,
 341  * copy_to_cooked must be atomic with repect to itself, as must
 342  * tty->write.  Thus, you must use the inline functions set_bit() and
 343  * clear_bit() to make things atomic.
 344  */
 345 #define TTY_WRITE_BUSY 0
 346 #define TTY_READ_BUSY 1
 347 #define TTY_SQ_THROTTLED 2
 348 #define TTY_RQ_THROTTLED 3
 349 #define TTY_IO_ERROR 4
 350 #define TTY_SLAVE_CLOSED 5
 351 #define TTY_EXCLUSIVE 6
 352 
 353 /*
 354  * When a break, frame error, or parity error happens, these codes are
 355  * stuffed into the read queue, and the relevant bit in readq_flag bit
 356  * array is set.
 357  */
 358 #define TTY_BREAK       1
 359 #define TTY_FRAME       2
 360 #define TTY_PARITY      3
 361 #define TTY_OVERRUN     4
 362 
 363 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
 364 #define TTY_READ_FLUSH(tty) tty_read_flush((tty))
 365 
 366 extern void tty_write_flush(struct tty_struct *);
 367 extern void tty_read_flush(struct tty_struct *);
 368 
 369 /* Number of chars that must be available in a write queue before
 370    the queue is awakened. */
 371 #define WAKEUP_CHARS (3*TTY_BUF_SIZE/4)
 372 
 373 extern struct tty_struct *tty_table[];
 374 extern struct termios *tty_termios[];
 375 extern struct termios *termios_locked[];
 376 extern int tty_check_write[];
 377 extern struct tty_struct * redirect;
 378 extern struct tty_ldisc ldiscs[];
 379 extern int fg_console;
 380 extern unsigned long video_num_columns;
 381 extern unsigned long video_num_lines;
 382 extern struct wait_queue * keypress_wait;
 383 
 384 #define TTY_TABLE_IDX(nr)       ((nr) ? (nr) : (fg_console+1))
 385 #define TTY_TABLE(nr)           (tty_table[TTY_TABLE_IDX(nr)])
 386 
 387 /*      intr=^C         quit=^|         erase=del       kill=^U
 388         eof=^D          vtime=\0        vmin=\1         sxtc=\0
 389         start=^Q        stop=^S         susp=^Z         eol=\0
 390         reprint=^R      discard=^U      werase=^W       lnext=^V
 391         eol2=\0
 392 */
 393 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 394 
 395 extern long rs_init(long);
 396 extern long lp_init(long);
 397 extern long con_init(long);
 398 extern long tty_init(long);
 399 
 400 extern void flush_input(struct tty_struct * tty);
 401 extern void flush_output(struct tty_struct * tty);
 402 extern void wait_until_sent(struct tty_struct * tty, int timeout);
 403 extern int check_change(struct tty_struct * tty, int channel);
 404 extern void stop_tty(struct tty_struct * tty);
 405 extern void start_tty(struct tty_struct * tty);
 406 extern int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc);
 407 extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp,
 408                              int buflen);
 409 extern int tty_write_data(struct tty_struct *tty, char *bufp, int buflen,
 410                           void (*callback)(void * data), void * callarg);
 411 
 412 extern int tty_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
 413 extern int is_orphaned_pgrp(int pgrp);
 414 extern int is_ignored(int sig);
 415 extern int tty_signal(int sig, struct tty_struct *tty);
 416 extern void tty_hangup(struct tty_struct * tty);
 417 extern void tty_vhangup(struct tty_struct * tty);
 418 extern void tty_unhangup(struct file *filp);
 419 extern int tty_hung_up_p(struct file * filp);
 420 extern void do_SAK(struct tty_struct *tty);
 421 extern void disassociate_ctty(int priv);
 422 
 423 /* tty write functions */
 424 
 425 extern void rs_write(struct tty_struct * tty);
 426 extern void con_write(struct tty_struct * tty);
 427 
 428 /* serial.c */
 429 
 430 extern int  rs_open(struct tty_struct * tty, struct file * filp);
 431 
 432 /* pty.c */
 433 
 434 extern int  pty_open(struct tty_struct * tty, struct file * filp);
 435 
 436 /* console.c */
 437 
 438 extern int con_open(struct tty_struct * tty, struct file * filp);
 439 extern void update_screen(int new_console);
 440 extern void blank_screen(void);
 441 extern void unblank_screen(void);
 442 
 443 /* vt.c */
 444 
 445 extern int vt_ioctl(struct tty_struct *tty, struct file * file,
 446                     unsigned int cmd, unsigned long arg);
 447 
 448 #endif

/* [previous][next][first][last][top][bottom][index][help] */