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 data;
  66         unsigned long head;
  67         unsigned long tail;
  68         struct wait_queue * proc_list;
  69         unsigned char buf[TTY_BUF_SIZE];
  70 };
  71 
  72 struct serial_struct {
  73         int     type;
  74         int     line;
  75         int     port;
  76         int     irq;
  77         int     flags;
  78         int     xmit_fifo_size;
  79         int     custom_divisor;
  80         int     baud_base;
  81         char    close_delay;
  82         char    reserved_char[3];
  83         int     reserved[6];
  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 blocked open on hangups */
 100 #define ASYNC_FOURPORT  0x0002  /* Set OU1, OUT2 per AST Fourport settings */
 101 #define ASYNC_SAK       0x0004  /* Secure Attention Key (Orange book) */
 102 #define ASYNC_SKIP_TEST 0x0008  /* Skip UART test on bootup */
 103 
 104 #define ASYNC_SPD_MASK  0x0030
 105 #define ASYNC_SPD_HI    0x0010  /* Use 56000 instead of 38400 bps */
 106 #define ASYNC_SPD_VHI   0x0020  /* Use 115200 instead of 38400 bps */
 107 #define ASYNC_SPD_CUST  0x0030  /* Use user-specified divisor */
 108 
 109 #define ASYNC_FLAGS     0x0037  /* Possible legal async flags */
 110 
 111 /* Internal flags used only by kernel/chr_drv/serial.c */
 112 #define ASYNC_INITIALIZED       0x80000000 /* Serial port was initialized */
 113 #define ASYNC_CALLOUT_ACTIVE    0x40000000 /* Call out device is active */
 114 #define ASYNC_NORMAL_ACTIVE     0x20000000 /* Normal device is active */
 115 
 116 #define IS_A_CONSOLE(min)       (((min) & 0xC0) == 0x00)
 117 #define IS_A_SERIAL(min)        (((min) & 0xC0) == 0x40)
 118 #define IS_A_PTY(min)           ((min) & 0x80)
 119 #define IS_A_PTY_MASTER(min)    (((min) & 0xC0) == 0x80)
 120 #define IS_A_PTY_SLAVE(min)     (((min) & 0xC0) == 0xC0)
 121 #define PTY_OTHER(min)          ((min) ^ 0x40)
 122 
 123 #define SL_TO_DEV(line)         ((line) | 0x40)
 124 #define DEV_TO_SL(min)          ((min) & 0x3F)
 125 
 126 #define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))
 127 #define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))
 128 #define EMPTY(a) ((a)->head == (a)->tail)
 129 #define LEFT(a) (((a)->tail-(a)->head-1)&(TTY_BUF_SIZE-1))
 130 #define LAST(a) ((a)->buf[(TTY_BUF_SIZE-1)&((a)->head-1)])
 131 #define FULL(a) (!LEFT(a))
 132 #define CHARS(a) (((a)->head-(a)->tail)&(TTY_BUF_SIZE-1))
 133 
 134 extern void put_tty_queue(char c, struct tty_queue * queue);
 135 extern int get_tty_queue(struct tty_queue * queue);
 136 
 137 #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
 138 #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
 139 #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
 140 #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
 141 #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
 142 #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
 143 #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
 144 #define SUSPEND_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
 145 #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT])
 146 
 147 #define _L_FLAG(tty,f)  ((tty)->termios->c_lflag & f)
 148 #define _I_FLAG(tty,f)  ((tty)->termios->c_iflag & f)
 149 #define _O_FLAG(tty,f)  ((tty)->termios->c_oflag & f)
 150 #define _C_FLAG(tty,f)  ((tty)->termios->c_cflag & f)
 151 
 152 #define L_CANON(tty)    _L_FLAG((tty),ICANON)
 153 #define L_ISIG(tty)     _L_FLAG((tty),ISIG)
 154 #define L_ECHO(tty)     _L_FLAG((tty),ECHO)
 155 #define L_ECHOE(tty)    _L_FLAG((tty),ECHOE)
 156 #define L_ECHOK(tty)    _L_FLAG((tty),ECHOK)
 157 #define L_ECHONL(tty)   _L_FLAG((tty),ECHONL)
 158 #define L_ECHOCTL(tty)  _L_FLAG((tty),ECHOCTL)
 159 #define L_ECHOKE(tty)   _L_FLAG((tty),ECHOKE)
 160 #define L_TOSTOP(tty)   _L_FLAG((tty),TOSTOP)
 161 
 162 #define I_IGNBRK(tty)   _I_FLAG((tty),IGNBRK)
 163 #define I_BRKINT(tty)   _I_FLAG((tty),BRKINT)
 164 #define I_IGNPAR(tty)   _I_FLAG((tty),IGNPAR)
 165 #define I_PARMRK(tty)   _I_FLAG((tty),PARMRK)
 166 #define I_INPCK(tty)    _I_FLAG((tty),INPCK)
 167 #define I_UCLC(tty)     _I_FLAG((tty),IUCLC)
 168 #define I_NLCR(tty)     _I_FLAG((tty),INLCR)
 169 #define I_CRNL(tty)     _I_FLAG((tty),ICRNL)
 170 #define I_NOCR(tty)     _I_FLAG((tty),IGNCR)
 171 #define I_IXON(tty)     _I_FLAG((tty),IXON)
 172 #define I_IXANY(tty)    _I_FLAG((tty),IXANY)
 173 #define I_STRP(tty)     _I_FLAG((tty),ISTRIP)
 174 
 175 #define O_POST(tty)     _O_FLAG((tty),OPOST)
 176 #define O_NLCR(tty)     _O_FLAG((tty),ONLCR)
 177 #define O_CRNL(tty)     _O_FLAG((tty),OCRNL)
 178 #define O_NLRET(tty)    _O_FLAG((tty),ONLRET)
 179 #define O_LCUC(tty)     _O_FLAG((tty),OLCUC)
 180 
 181 #define C_LOCAL(tty)    _C_FLAG((tty),CLOCAL)
 182 #define C_RTSCTS(tty)   _C_FLAG((tty),CRTSCTS)
 183 #define C_SPEED(tty)    ((tty)->termios->c_cflag & CBAUD)
 184 #define C_HUP(tty)      (C_SPEED((tty)) == B0)
 185 
 186 /*
 187  * Where all of the state associated with a tty is kept while the tty
 188  * is open.  Since the termios state should be kept even if the tty
 189  * has been closed --- for things like the baud rate, etc --- it is
 190  * not stored here, but rather a pointer to the real state is stored
 191  * here.  Possible the winsize structure should have the same
 192  * treatment, but (1) the default 80x24 is usually right and (2) it's
 193  * most often used by a windowing system, which will set the correct
 194  * size each time the window is created or resized anyway.
 195  * IMPORTANT: since this structure is dynamically allocated, it must
 196  * be no larger than 4096 bytes.  Changing TTY_BUF_SIZE will change
 197  * the size of this structure, and it needs to be done with care.
 198  *                                              - TYT, 9/14/92
 199  */
 200 struct tty_struct {
 201         struct termios *termios;
 202         int pgrp;
 203         int session;
 204         unsigned char stopped:1, status_changed:1, packet:1, lnext:1;
 205         unsigned char char_error:2;
 206         unsigned char ctrl_status;
 207         short line;
 208         int disc;
 209         int flags;
 210         int count;
 211         struct winsize winsize;
 212         int  (*open)(struct tty_struct * tty, struct file * filp);
 213         void (*close)(struct tty_struct * tty, struct file * filp);
 214         void (*write)(struct tty_struct * tty);
 215         int  (*ioctl)(struct tty_struct *tty, struct file * file,
 216                     unsigned int cmd, unsigned int arg);
 217         void (*throttle)(struct tty_struct * tty, int status);
 218         void (*set_termios)(struct tty_struct *tty, struct termios * old);
 219         struct tty_struct *link;
 220         unsigned char *write_data_ptr;
 221         int write_data_cnt;
 222         void (*write_data_callback)(void * data);
 223         void * write_data_arg;
 224         int readq_flags[TTY_BUF_SIZE/32];
 225         struct tty_queue read_q;
 226         struct tty_queue write_q;
 227         struct tty_queue secondary;
 228         };
 229 
 230 struct tty_ldisc {
 231         int     flags;
 232         /*
 233          * The following routines are called from above.
 234          */
 235         int     (*open)(struct tty_struct *);
 236         void    (*close)(struct tty_struct *);
 237         int     (*read)(struct tty_struct * tty, struct file * file,
 238                         char * buf, int nr);
 239         int     (*write)(struct tty_struct * tty, struct file * file,
 240                          char * buf, int nr);   
 241         int     (*ioctl)(struct tty_struct * tty, struct file * file,
 242                          unsigned int cmd, unsigned int arg);
 243         /*
 244          * The following routines are called from below.
 245          */
 246         void    (*handler)(struct tty_struct *);
 247 };
 248 
 249 #define LDISC_FLAG_DEFINED      0x00000001
 250 
 251 /*
 252  * These are the different types of thottle status which can be sent
 253  * to the low-level tty driver.  The tty_io.c layer is responsible for
 254  * notifying the low-level tty driver of the following conditions:
 255  * secondary queue full, secondary queue available, and read queue
 256  * available.  The low-level driver must send the read queue full
 257  * command to itself, if it is interested in that condition.
 258  *
 259  * Note that the low-level tty driver may elect to ignore one or both
 260  * of these conditions; normally, however, it will use ^S/^Q or some
 261  * sort of hardware flow control to regulate the input to try to avoid
 262  * overflow.  While the low-level driver is responsible for all
 263  * receiving flow control, note that the ^S/^Q handling (but not
 264  * hardware flow control) is handled by the upper layer, in
 265  * copy_to_cooked.  
 266  */
 267 #define TTY_THROTTLE_SQ_FULL    1
 268 #define TTY_THROTTLE_SQ_AVAIL   2
 269 #define TTY_THROTTLE_RQ_FULL    3
 270 #define TTY_THROTTLE_RQ_AVAIL   4
 271 
 272 /*
 273  * This defines the low- and high-watermarks for the various conditions.
 274  * Again, the low-level driver is free to ignore any of these, and has
 275  * to implement RQ_THREHOLD_LW for itself if it wants it.
 276  */
 277 #define SQ_THRESHOLD_LW 16
 278 #define SQ_THRESHOLD_HW 768
 279 #define RQ_THRESHOLD_LW 16
 280 #define RQ_THRESHOLD_HW 768
 281 
 282 /*
 283  * These bits are used in the flags field of the tty structure.
 284  * 
 285  * So that interrupts won't be able to mess up the queues,
 286  * copy_to_cooked must be atomic with repect to itself, as must
 287  * tty->write.  Thus, you must use the inline functions set_bit() and
 288  * clear_bit() to make things atomic.
 289  */
 290 #define TTY_WRITE_BUSY 0
 291 #define TTY_READ_BUSY 1
 292 #define TTY_CR_PENDING 2
 293 #define TTY_SQ_THROTTLED 3
 294 #define TTY_RQ_THROTTLED 4
 295 #define TTY_IO_ERROR 5
 296 
 297 /*
 298  * When a break, frame error, or parity error happens, these codes are
 299  * stuffed into the read queue, and the relevant bit in readq_flag bit
 300  * array is set.
 301  */
 302 #define TTY_BREAK       1
 303 #define TTY_FRAME       2
 304 #define TTY_PARITY      3
 305 
 306 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
 307 #define TTY_READ_FLUSH(tty) tty_read_flush((tty))
 308 
 309 extern void tty_write_flush(struct tty_struct *);
 310 extern void tty_read_flush(struct tty_struct *);
 311 
 312 extern struct tty_struct *tty_table[];
 313 extern int tty_check_write[];
 314 extern struct tty_struct * redirect;
 315 extern struct tty_ldisc ldiscs[];
 316 extern int fg_console;
 317 extern unsigned long video_num_columns;
 318 extern unsigned long video_num_lines;
 319 extern struct wait_queue * keypress_wait;
 320 
 321 #define TTY_TABLE_IDX(nr)       ((nr) ? (nr) : (fg_console+1))
 322 #define TTY_TABLE(nr)           (tty_table[TTY_TABLE_IDX(nr)])
 323 
 324 /*      intr=^C         quit=^|         erase=del       kill=^U
 325         eof=^D          vtime=\0        vmin=\1         sxtc=\0
 326         start=^Q        stop=^S         susp=^Z         eol=\0
 327         reprint=^R      discard=^U      werase=^W       lnext=^V
 328         eol2=\0
 329 */
 330 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 331 
 332 extern long rs_init(long);
 333 extern long lp_init(long);
 334 extern long con_init(long);
 335 extern long tty_init(long);
 336 
 337 extern void flush_input(struct tty_struct * tty);
 338 extern void flush_output(struct tty_struct * tty);
 339 extern void wait_until_sent(struct tty_struct * tty);
 340 extern void copy_to_cooked(struct tty_struct * tty);
 341 extern int tty_register_ldisc(int disc, struct tty_ldisc *new);
 342 
 343 extern int tty_ioctl(struct inode *, struct file *, unsigned int, unsigned int);
 344 extern int is_orphaned_pgrp(int pgrp);
 345 extern int is_ignored(int sig);
 346 extern int tty_signal(int sig, struct tty_struct *tty);
 347 extern int kill_pg(int pgrp, int sig, int priv);
 348 extern int kill_sl(int sess, int sig, int priv);
 349 extern void tty_hangup(struct tty_struct * tty);
 350 extern void tty_vhangup(struct tty_struct * tty);
 351 extern void tty_unhangup(struct file *filp);
 352 extern int tty_hung_up_p(struct file * filp);
 353 extern void do_SAK(struct tty_struct *tty);
 354 
 355 /* tty write functions */
 356 
 357 extern void rs_write(struct tty_struct * tty);
 358 extern void con_write(struct tty_struct * tty);
 359 
 360 /* serial.c */
 361 
 362 extern int  rs_open(struct tty_struct * tty, struct file * filp);
 363 
 364 /* pty.c */
 365 
 366 extern int  pty_open(struct tty_struct * tty, struct file * filp);
 367 
 368 /* console.c */
 369 
 370 extern int con_open(struct tty_struct * tty, struct file * filp);
 371 extern void update_screen(int new_console);
 372 extern void blank_screen(void);
 373 extern void unblank_screen(void);
 374 
 375 /* vt.c */
 376 
 377 extern int vt_ioctl(struct tty_struct *tty, struct file * file,
 378                     unsigned int cmd, unsigned int arg);
 379 
 380 #endif

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