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 
  14 /*
  15  * These are set up by the setup-routine at boot-time:
  16  */
  17 
  18 struct screen_info {
  19         unsigned char  orig_x;
  20         unsigned char  orig_y;
  21         unsigned char  unused1[2];
  22         unsigned short orig_video_page;
  23         unsigned char  orig_video_mode;
  24         unsigned char  orig_video_cols;
  25         unsigned short orig_video_ega_ax;
  26         unsigned short orig_video_ega_bx;
  27         unsigned short orig_video_ega_cx;
  28         unsigned char  orig_video_lines;
  29 };
  30 
  31 extern struct screen_info screen_info;
  32 
  33 #define ORIG_X                  (screen_info.orig_x)
  34 #define ORIG_Y                  (screen_info.orig_y)
  35 #define ORIG_VIDEO_PAGE         (screen_info.orig_video_page)
  36 #define ORIG_VIDEO_MODE         (screen_info.orig_video_mode)
  37 #define ORIG_VIDEO_COLS         (screen_info.orig_video_cols)
  38 #define ORIG_VIDEO_EGA_AX       (screen_info.orig_video_ega_ax)
  39 #define ORIG_VIDEO_EGA_BX       (screen_info.orig_video_ega_bx)
  40 #define ORIG_VIDEO_EGA_CX       (screen_info.orig_video_ega_cx)
  41 #define ORIG_VIDEO_LINES        (screen_info.orig_video_lines)
  42 
  43 #define VIDEO_TYPE_MDA          0x10    /* Monochrome Text Display      */
  44 #define VIDEO_TYPE_CGA          0x11    /* CGA Display                  */
  45 #define VIDEO_TYPE_EGAM         0x20    /* EGA/VGA in Monochrome Mode   */
  46 #define VIDEO_TYPE_EGAC         0x21    /* EGA/VGA in Color Mode        */
  47 
  48 /*
  49  * This character is the same as _POSIX_VDISABLE: it cannot be used as
  50  * a c_cc[] character, but indicates that a particular special character
  51  * isn't in use (eg VINTR ahs no character etc)
  52  */
  53 #define __DISABLED_CHAR '\0'
  54 
  55 /*
  56  * See comment for the tty_struct structure before changing
  57  * TTY_BUF_SIZE.  Actually, there should be different sized tty_queue
  58  * structures for different purposes.  1024 bytes for the transmit
  59  * queue is way overkill.  TYT, 9/14/92
  60  */
  61 #define TTY_BUF_SIZE 1024       /* Must be a power of 2 */
  62 
  63 struct tty_queue {
  64         unsigned long data;
  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     reserved[8];
  80 };
  81 
  82 /*
  83  * These are the supported serial types.
  84  */
  85 #define PORT_UNKNOWN    0
  86 #define PORT_8250       1
  87 #define PORT_16450      2
  88 #define PORT_16550      3
  89 #define PORT_16550A     4
  90 
  91 /*
  92  * Definitions for async_struct (and serial_struct) flags field
  93  */
  94 #define ASYNC_NOSCRATCH 0x0001  /* 16XXX UART with no scratch register */
  95 #define ASYNC_FOURPORT  0x0002  /* Set OU1, OUT2 per AST Fourport settings */
  96 #define ASYNC_SAK       0x0004  /* Secure Attention Key (Orange book) */
  97 
  98 #define ASYNC_SPD_MASK  0x0030
  99 #define ASYNC_SPD_HI    0x0010  /* Use 56000 instead of 38400 bps */
 100 #define ASYNC_SPD_VHI   0x0020  /* Use 115200 instead of 38400 bps */
 101 #define ASYNC_SPD_CUST  0x0030  /* Use user-specified divisor */
 102 
 103 #define IS_A_CONSOLE(min)       (((min) & 0xC0) == 0x00)
 104 #define IS_A_SERIAL(min)        (((min) & 0xC0) == 0x40)
 105 #define IS_A_PTY(min)           ((min) & 0x80)
 106 #define IS_A_PTY_MASTER(min)    (((min) & 0xC0) == 0x80)
 107 #define IS_A_PTY_SLAVE(min)     (((min) & 0xC0) == 0xC0)
 108 #define PTY_OTHER(min)          ((min) ^ 0x40)
 109 
 110 #define SL_TO_DEV(line)         ((line) | 0x40)
 111 #define DEV_TO_SL(min)          ((min) & 0x3F)
 112 
 113 #define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))
 114 #define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))
 115 #define EMPTY(a) ((a)->head == (a)->tail)
 116 #define LEFT(a) (((a)->tail-(a)->head-1)&(TTY_BUF_SIZE-1))
 117 #define LAST(a) ((a)->buf[(TTY_BUF_SIZE-1)&((a)->head-1)])
 118 #define FULL(a) (!LEFT(a))
 119 #define CHARS(a) (((a)->head-(a)->tail)&(TTY_BUF_SIZE-1))
 120 
 121 extern void put_tty_queue(char c, struct tty_queue * queue);
 122 extern int get_tty_queue(struct tty_queue * queue);
 123 
 124 #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
 125 #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
 126 #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
 127 #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
 128 #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
 129 #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
 130 #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
 131 #define SUSPEND_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
 132 
 133 #define _L_FLAG(tty,f)  ((tty)->termios->c_lflag & f)
 134 #define _I_FLAG(tty,f)  ((tty)->termios->c_iflag & f)
 135 #define _O_FLAG(tty,f)  ((tty)->termios->c_oflag & f)
 136 
 137 #define L_CANON(tty)    _L_FLAG((tty),ICANON)
 138 #define L_ISIG(tty)     _L_FLAG((tty),ISIG)
 139 #define L_ECHO(tty)     _L_FLAG((tty),ECHO)
 140 #define L_ECHOE(tty)    _L_FLAG((tty),ECHOE)
 141 #define L_ECHOK(tty)    _L_FLAG((tty),ECHOK)
 142 #define L_ECHONL(tty)   _L_FLAG((tty),ECHONL)
 143 #define L_ECHOCTL(tty)  _L_FLAG((tty),ECHOCTL)
 144 #define L_ECHOKE(tty)   _L_FLAG((tty),ECHOKE)
 145 #define L_TOSTOP(tty)   _L_FLAG((tty),TOSTOP)
 146 
 147 #define I_UCLC(tty)     _I_FLAG((tty),IUCLC)
 148 #define I_NLCR(tty)     _I_FLAG((tty),INLCR)
 149 #define I_CRNL(tty)     _I_FLAG((tty),ICRNL)
 150 #define I_NOCR(tty)     _I_FLAG((tty),IGNCR)
 151 #define I_IXON(tty)     _I_FLAG((tty),IXON)
 152 #define I_IXANY(tty)    _I_FLAG((tty),IXANY)
 153 #define I_STRP(tty)     _I_FLAG((tty),ISTRIP)
 154 
 155 #define O_POST(tty)     _O_FLAG((tty),OPOST)
 156 #define O_NLCR(tty)     _O_FLAG((tty),ONLCR)
 157 #define O_CRNL(tty)     _O_FLAG((tty),OCRNL)
 158 #define O_NLRET(tty)    _O_FLAG((tty),ONLRET)
 159 #define O_LCUC(tty)     _O_FLAG((tty),OLCUC)
 160 
 161 #define C_SPEED(tty)    ((tty)->termios->c_cflag & CBAUD)
 162 #define C_HUP(tty)      (C_SPEED((tty)) == B0)
 163 
 164 /*
 165  * Where all of the state associated with a tty is kept while the tty
 166  * is open.  Since the termios state should be kept even if the tty
 167  * has been closed --- for things like the baud rate, etc --- it is
 168  * not stored here, but rather a pointer to the real state is stored
 169  * here.  Possible the winsize structure should have the same
 170  * treatment, but (1) the default 80x24 is usually right and (2) it's
 171  * most often used by a windowing system, which will set the correct
 172  * size each time the window is created or resized anyway.
 173  * IMPORTANT: since this structure is dynamically allocated, it must
 174  * be no larger than 4096 bytes.  Changing TTY_BUF_SIZE will change
 175  * the size of this structure, and it needs to be done with care.
 176  *                                              - TYT, 9/14/92
 177  */
 178 struct tty_struct {
 179         struct termios *termios;
 180         int pgrp;
 181         int session;
 182         unsigned char stopped:1, status_changed:1, packet:1;
 183         unsigned char ctrl_status;
 184         short line;
 185         int flags;
 186         int count;
 187         struct winsize winsize;
 188         int  (*open)(struct tty_struct * tty, struct file * filp);
 189         void (*close)(struct tty_struct * tty, struct file * filp);
 190         void (*write)(struct tty_struct * tty);
 191         int  (*ioctl)(struct tty_struct *tty, struct file * file,
 192                     unsigned int cmd, unsigned int arg);
 193         void (*throttle)(struct tty_struct * tty, int status);
 194         struct tty_struct *link;
 195         struct tty_queue read_q;
 196         struct tty_queue write_q;
 197         struct tty_queue secondary;
 198         };
 199 
 200 /*
 201  * These are the different types of thottle status which can be sent
 202  * to the low-level tty driver.  The tty_io.c layer is responsible for
 203  * notifying the low-level tty driver of the following conditions:
 204  * secondary queue full, secondary queue available, and read queue
 205  * available.  The low-level driver must send the read queue full
 206  * command to itself, if it is interested in that condition.
 207  *
 208  * Note that the low-level tty driver may elect to ignore one or both
 209  * of these conditions; normally, however, it will use ^S/^Q or some
 210  * sort of hardware flow control to regulate the input to try to avoid
 211  * overflow.  While the low-level driver is responsible for all
 212  * receiving flow control, note that the ^S/^Q handling (but not
 213  * hardware flow control) is handled by the upper layer, in
 214  * copy_to_cooked.  
 215  */
 216 #define TTY_THROTTLE_SQ_FULL    1
 217 #define TTY_THROTTLE_SQ_AVAIL   2
 218 #define TTY_THROTTLE_RQ_FULL    3
 219 #define TTY_THROTTLE_RQ_AVAIL   4
 220 
 221 /*
 222  * This defines the low- and high-watermarks for the various conditions.
 223  * Again, the low-level driver is free to ignore any of these, and has
 224  * to implement RQ_THREHOLD_LW for itself if it wants it.
 225  */
 226 #define SQ_THRESHOLD_LW 16
 227 #define SQ_THRESHOLD_HW 768
 228 #define RQ_THRESHOLD_LW 16
 229 #define RQ_THRESHOLD_HW 768
 230 
 231 /*
 232  * These bits are used in the flags field of the tty structure.
 233  * 
 234  * So that interrupts won't be able to mess up the queues,
 235  * copy_to_cooked must be atomic with repect to itself, as must
 236  * tty->write.  Thus, you must use the inline functions set_bit() and
 237  * clear_bit() to make things atomic.
 238  */
 239 #define TTY_WRITE_BUSY 0
 240 #define TTY_READ_BUSY 1
 241 #define TTY_CR_PENDING 2
 242 #define TTY_SQ_THROTTLED 3
 243 #define TTY_RQ_THROTTLED 4
 244 
 245 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
 246 #define TTY_READ_FLUSH(tty) tty_read_flush((tty))
 247 
 248 extern void tty_write_flush(struct tty_struct *);
 249 extern void tty_read_flush(struct tty_struct *);
 250 
 251 extern struct tty_struct *tty_table[];
 252 extern struct tty_struct * redirect;
 253 extern int fg_console;
 254 extern unsigned long video_num_columns;
 255 extern unsigned long video_num_lines;
 256 extern struct wait_queue * keypress_wait;
 257 
 258 #define TTY_TABLE_IDX(nr)       ((nr) ? (nr) : (fg_console+1))
 259 #define TTY_TABLE(nr)           (tty_table[TTY_TABLE_IDX(nr)])
 260 
 261 /*      intr=^C         quit=^|         erase=del       kill=^U
 262         eof=^D          vtime=\0        vmin=\1         sxtc=\0
 263         start=^Q        stop=^S         susp=^Z         eol=\0
 264         reprint=^R      discard=^U      werase=^W       lnext=^V
 265         eol2=\0
 266 */
 267 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
 268 
 269 extern long rs_init(long);
 270 extern long lp_init(long);
 271 extern long con_init(long);
 272 extern long tty_init(long);
 273 
 274 extern void flush_input(struct tty_struct * tty);
 275 extern void flush_output(struct tty_struct * tty);
 276 extern void wait_until_sent(struct tty_struct * tty);
 277 extern void copy_to_cooked(struct tty_struct * tty);
 278 
 279 extern int tty_ioctl(struct inode *, struct file *, unsigned int, unsigned int);
 280 extern int is_orphaned_pgrp(int pgrp);
 281 extern int is_ignored(int sig);
 282 extern int tty_signal(int sig, struct tty_struct *tty);
 283 extern int kill_pg(int pgrp, int sig, int priv);
 284 extern void do_SAK(struct tty_struct *tty);
 285 
 286 /* tty write functions */
 287 
 288 extern void rs_write(struct tty_struct * tty);
 289 extern void con_write(struct tty_struct * tty);
 290 
 291 /* serial.c */
 292 
 293 extern int  rs_open(struct tty_struct * tty, struct file * filp);
 294 extern void change_speed(unsigned int line);
 295 
 296 /* pty.c */
 297 
 298 extern int  pty_open(struct tty_struct * tty, struct file * filp);
 299 
 300 /* console.c */
 301 
 302 extern int con_open(struct tty_struct * tty, struct file * filp);
 303 extern void update_screen(int new_console);
 304 extern void blank_screen(void);
 305 extern void unblank_screen(void);
 306 
 307 /* vt.c */
 308 
 309 extern int vt_ioctl(struct tty_struct *tty, struct file * file,
 310                     unsigned int cmd, unsigned int arg);
 311 
 312 #endif

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