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 #ifdef __KERNEL__
   9 #include <linux/fs.h>
  10 #include <linux/termios.h>
  11 #include <linux/tqueue.h>
  12 #include <linux/tty_driver.h>
  13 #include <linux/tty_ldisc.h>
  14 
  15 #include <asm/system.h>
  16 
  17 
  18 /*
  19  * Note: don't mess with NR_PTYS until you understand the tty minor 
  20  * number allocation game...
  21  * (Note: the *_driver.minor_start values 1, 64, 128, 192 are
  22  * hardcoded at present.)
  23  */
  24 #define MIN_NR_CONSOLES 1       /* must be at least 1 */
  25 #define MAX_NR_CONSOLES 63      /* serial lines start at 64 */
  26 #define MAX_NR_USER_CONSOLES 63 /* must be root to allocate above this */
  27                 /* Note: the ioctl VT_GETSTATE does not work for
  28                    consoles 16 and higher (since it returns a short) */
  29 #define NR_PTYS         256
  30 #define NR_LDISCS       16
  31 
  32 /*
  33  * These are set up by the setup-routine at boot-time:
  34  */
  35 
  36 struct screen_info {
  37         unsigned char  orig_x;
  38         unsigned char  orig_y;
  39         unsigned char  unused1[2];
  40         unsigned short orig_video_page;
  41         unsigned char  orig_video_mode;
  42         unsigned char  orig_video_cols;
  43         unsigned short unused2;
  44         unsigned short orig_video_ega_bx;
  45         unsigned short unused3;
  46         unsigned char  orig_video_lines;
  47         unsigned char  orig_video_isVGA;
  48         unsigned short orig_video_points;
  49 };
  50 
  51 extern struct screen_info screen_info;
  52 
  53 #define ORIG_X                  (screen_info.orig_x)
  54 #define ORIG_Y                  (screen_info.orig_y)
  55 #define ORIG_VIDEO_PAGE         (screen_info.orig_video_page)
  56 #define ORIG_VIDEO_MODE         (screen_info.orig_video_mode)
  57 #define ORIG_VIDEO_COLS         (screen_info.orig_video_cols)
  58 #define ORIG_VIDEO_EGA_BX       (screen_info.orig_video_ega_bx)
  59 #define ORIG_VIDEO_LINES        (screen_info.orig_video_lines)
  60 #define ORIG_VIDEO_ISVGA        (screen_info.orig_video_isVGA)
  61 #define ORIG_VIDEO_POINTS       (screen_info.orig_video_points)
  62 
  63 #define VIDEO_TYPE_MDA          0x10    /* Monochrome Text Display      */
  64 #define VIDEO_TYPE_CGA          0x11    /* CGA Display                  */
  65 #define VIDEO_TYPE_EGAM         0x20    /* EGA/VGA in Monochrome Mode   */
  66 #define VIDEO_TYPE_EGAC         0x21    /* EGA in Color Mode            */
  67 #define VIDEO_TYPE_VGAC         0x22    /* VGA+ in Color Mode           */
  68 
  69 #define VIDEO_TYPE_TGAC         0x40    /* DEC TGA */
  70 
  71 /*
  72  * This character is the same as _POSIX_VDISABLE: it cannot be used as
  73  * a c_cc[] character, but indicates that a particular special character
  74  * isn't in use (eg VINTR has no character etc)
  75  */
  76 #define __DISABLED_CHAR '\0'
  77 
  78 /*
  79  * This is the flip buffer used for the tty driver.  The buffer is
  80  * located in the tty structure, and is used as a high speed interface
  81  * between the tty driver and the tty line discipline.
  82  */
  83 #define TTY_FLIPBUF_SIZE 512
  84 
  85 struct tty_flip_buffer {
  86         struct tq_struct tqueue;
  87         unsigned char   char_buf[2*TTY_FLIPBUF_SIZE];
  88         char            flag_buf[2*TTY_FLIPBUF_SIZE];
  89         char            *char_buf_ptr;
  90         unsigned char   *flag_buf_ptr;
  91         int             count;
  92         int             buf_num;
  93 };
  94 
  95 /*
  96  * When a break, frame error, or parity error happens, these codes are
  97  * stuffed into the flags buffer.
  98  */
  99 #define TTY_NORMAL      0
 100 #define TTY_BREAK       1
 101 #define TTY_FRAME       2
 102 #define TTY_PARITY      3
 103 #define TTY_OVERRUN     4
 104 
 105 #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
 106 #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
 107 #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
 108 #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
 109 #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
 110 #define TIME_CHAR(tty) ((tty)->termios->c_cc[VTIME])
 111 #define MIN_CHAR(tty) ((tty)->termios->c_cc[VMIN])
 112 #define SWTC_CHAR(tty) ((tty)->termios->c_cc[VSWTC])
 113 #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
 114 #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
 115 #define SUSP_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
 116 #define EOL_CHAR(tty) ((tty)->termios->c_cc[VEOL])
 117 #define REPRINT_CHAR(tty) ((tty)->termios->c_cc[VREPRINT])
 118 #define DISCARD_CHAR(tty) ((tty)->termios->c_cc[VDISCARD])
 119 #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE])
 120 #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT])
 121 #define EOL2_CHAR(tty) ((tty)->termios->c_cc[VEOL2])
 122 
 123 #define _I_FLAG(tty,f)  ((tty)->termios->c_iflag & (f))
 124 #define _O_FLAG(tty,f)  ((tty)->termios->c_oflag & (f))
 125 #define _C_FLAG(tty,f)  ((tty)->termios->c_cflag & (f))
 126 #define _L_FLAG(tty,f)  ((tty)->termios->c_lflag & (f))
 127 
 128 #define I_IGNBRK(tty)   _I_FLAG((tty),IGNBRK)
 129 #define I_BRKINT(tty)   _I_FLAG((tty),BRKINT)
 130 #define I_IGNPAR(tty)   _I_FLAG((tty),IGNPAR)
 131 #define I_PARMRK(tty)   _I_FLAG((tty),PARMRK)
 132 #define I_INPCK(tty)    _I_FLAG((tty),INPCK)
 133 #define I_ISTRIP(tty)   _I_FLAG((tty),ISTRIP)
 134 #define I_INLCR(tty)    _I_FLAG((tty),INLCR)
 135 #define I_IGNCR(tty)    _I_FLAG((tty),IGNCR)
 136 #define I_ICRNL(tty)    _I_FLAG((tty),ICRNL)
 137 #define I_IUCLC(tty)    _I_FLAG((tty),IUCLC)
 138 #define I_IXON(tty)     _I_FLAG((tty),IXON)
 139 #define I_IXANY(tty)    _I_FLAG((tty),IXANY)
 140 #define I_IXOFF(tty)    _I_FLAG((tty),IXOFF)
 141 #define I_IMAXBEL(tty)  _I_FLAG((tty),IMAXBEL)
 142 
 143 #define O_OPOST(tty)    _O_FLAG((tty),OPOST)
 144 #define O_OLCUC(tty)    _O_FLAG((tty),OLCUC)
 145 #define O_ONLCR(tty)    _O_FLAG((tty),ONLCR)
 146 #define O_OCRNL(tty)    _O_FLAG((tty),OCRNL)
 147 #define O_ONOCR(tty)    _O_FLAG((tty),ONOCR)
 148 #define O_ONLRET(tty)   _O_FLAG((tty),ONLRET)
 149 #define O_OFILL(tty)    _O_FLAG((tty),OFILL)
 150 #define O_OFDEL(tty)    _O_FLAG((tty),OFDEL)
 151 #define O_NLDLY(tty)    _O_FLAG((tty),NLDLY)
 152 #define O_CRDLY(tty)    _O_FLAG((tty),CRDLY)
 153 #define O_TABDLY(tty)   _O_FLAG((tty),TABDLY)
 154 #define O_BSDLY(tty)    _O_FLAG((tty),BSDLY)
 155 #define O_VTDLY(tty)    _O_FLAG((tty),VTDLY)
 156 #define O_FFDLY(tty)    _O_FLAG((tty),FFDLY)
 157 
 158 #define C_BAUD(tty)     _C_FLAG((tty),CBAUD)
 159 #define C_CSIZE(tty)    _C_FLAG((tty),CSIZE)
 160 #define C_CSTOPB(tty)   _C_FLAG((tty),CSTOPB)
 161 #define C_CREAD(tty)    _C_FLAG((tty),CREAD)
 162 #define C_PARENB(tty)   _C_FLAG((tty),PARENB)
 163 #define C_PARODD(tty)   _C_FLAG((tty),PARODD)
 164 #define C_HUPCL(tty)    _C_FLAG((tty),HUPCL)
 165 #define C_CLOCAL(tty)   _C_FLAG((tty),CLOCAL)
 166 #define C_CIBAUD(tty)   _C_FLAG((tty),CIBAUD)
 167 #define C_CRTSCTS(tty)  _C_FLAG((tty),CRTSCTS)
 168 
 169 #define L_ISIG(tty)     _L_FLAG((tty),ISIG)
 170 #define L_ICANON(tty)   _L_FLAG((tty),ICANON)
 171 #define L_XCASE(tty)    _L_FLAG((tty),XCASE)
 172 #define L_ECHO(tty)     _L_FLAG((tty),ECHO)
 173 #define L_ECHOE(tty)    _L_FLAG((tty),ECHOE)
 174 #define L_ECHOK(tty)    _L_FLAG((tty),ECHOK)
 175 #define L_ECHONL(tty)   _L_FLAG((tty),ECHONL)
 176 #define L_NOFLSH(tty)   _L_FLAG((tty),NOFLSH)
 177 #define L_TOSTOP(tty)   _L_FLAG((tty),TOSTOP)
 178 #define L_ECHOCTL(tty)  _L_FLAG((tty),ECHOCTL)
 179 #define L_ECHOPRT(tty)  _L_FLAG((tty),ECHOPRT)
 180 #define L_ECHOKE(tty)   _L_FLAG((tty),ECHOKE)
 181 #define L_FLUSHO(tty)   _L_FLAG((tty),FLUSHO)
 182 #define L_PENDIN(tty)   _L_FLAG((tty),PENDIN)
 183 #define L_IEXTEN(tty)   _L_FLAG((tty),IEXTEN)
 184 
 185 /*
 186  * Where all of the state associated with a tty is kept while the tty
 187  * is open.  Since the termios state should be kept even if the tty
 188  * has been closed --- for things like the baud rate, etc --- it is
 189  * not stored here, but rather a pointer to the real state is stored
 190  * here.  Possible the winsize structure should have the same
 191  * treatment, but (1) the default 80x24 is usually right and (2) it's
 192  * most often used by a windowing system, which will set the correct
 193  * size each time the window is created or resized anyway.
 194  * IMPORTANT: since this structure is dynamically allocated, it must
 195  * be no larger than 4096 bytes.  Changing TTY_BUF_SIZE will change
 196  * the size of this structure, and it needs to be done with care.
 197  *                                              - TYT, 9/14/92
 198  */
 199 struct tty_struct {
 200         int     magic;
 201         struct tty_driver driver;
 202         struct tty_ldisc ldisc;
 203         struct termios *termios, *termios_locked;
 204         int pgrp;
 205         int session;
 206         kdev_t  device;
 207         unsigned long flags;
 208         int count;
 209         struct winsize winsize;
 210         unsigned char stopped:1, hw_stopped:1, packet:1;
 211         unsigned char ctrl_status;
 212 
 213         struct tty_struct *link;
 214         struct fasync_struct *fasync;
 215         struct tty_flip_buffer flip;
 216         int max_flip_cnt;
 217         struct wait_queue *write_wait;
 218         struct wait_queue *read_wait;
 219         void *disc_data;
 220         void *driver_data;
 221 
 222 #define N_TTY_BUF_SIZE 4096
 223         
 224         /*
 225          * The following is data for the N_TTY line discipline.  For
 226          * historical reasons, this is included in the tty structure.
 227          */
 228         unsigned int column;
 229         unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
 230         unsigned char closing:1;
 231         unsigned short minimum_to_wake;
 232         unsigned overrun_time;
 233         int num_overrun;
 234         unsigned long process_char_map[256/(8*sizeof(unsigned long))];
 235         char *read_buf;
 236         int read_head;
 237         int read_tail;
 238         int read_cnt;
 239         unsigned long read_flags[N_TTY_BUF_SIZE/(8*sizeof(unsigned long))];
 240         int canon_data;
 241         unsigned long canon_head;
 242         unsigned int canon_column;
 243 };
 244 
 245 /* tty magic number */
 246 #define TTY_MAGIC               0x5401
 247 
 248 /*
 249  * These bits are used in the flags field of the tty structure.
 250  * 
 251  * So that interrupts won't be able to mess up the queues,
 252  * copy_to_cooked must be atomic with respect to itself, as must
 253  * tty->write.  Thus, you must use the inline functions set_bit() and
 254  * clear_bit() to make things atomic.
 255  */
 256 #define TTY_THROTTLED 0
 257 #define TTY_IO_ERROR 1
 258 #define TTY_SLAVE_CLOSED 2
 259 #define TTY_EXCLUSIVE 3
 260 #define TTY_DEBUG 4
 261 #define TTY_DO_WRITE_WAKEUP 5
 262 #define TTY_PUSH 6
 263 #define TTY_CLOSING 7
 264 
 265 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
 266 
 267 extern void tty_write_flush(struct tty_struct *);
 268 
 269 extern struct termios tty_std_termios;
 270 extern struct tty_struct * redirect;
 271 extern struct tty_ldisc ldiscs[];
 272 extern int fg_console, last_console, want_console;
 273 
 274 extern int kmsg_redirect;
 275 extern struct wait_queue * keypress_wait;
 276 
 277 extern unsigned long con_init(unsigned long);
 278 
 279 extern int rs_init(void);
 280 extern int lp_init(void);
 281 extern int pty_init(void);
 282 extern int tty_init(void);
 283 extern int vcs_init(void);
 284 extern int cy_init(void);
 285 extern int stl_init(void);
 286 extern int stli_init(void);
 287 
 288 extern int tty_paranoia_check(struct tty_struct *tty, kdev_t device,
 289                               const char *routine);
 290 extern char *_tty_name(struct tty_struct *tty, char *buf);
 291 extern char *tty_name(struct tty_struct *tty);
 292 extern void tty_wait_until_sent(struct tty_struct * tty, int timeout);
 293 extern int tty_check_change(struct tty_struct * tty);
 294 extern void stop_tty(struct tty_struct * tty);
 295 extern void start_tty(struct tty_struct * tty);
 296 extern int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc);
 297 extern int tty_register_driver(struct tty_driver *driver);
 298 extern int tty_unregister_driver(struct tty_driver *driver);
 299 extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp,
 300                              int buflen);
 301 extern void tty_write_message(struct tty_struct *tty, char *msg);
 302 
 303 extern int is_orphaned_pgrp(int pgrp);
 304 extern int is_ignored(int sig);
 305 extern int tty_signal(int sig, struct tty_struct *tty);
 306 extern void tty_hangup(struct tty_struct * tty);
 307 extern void tty_vhangup(struct tty_struct * tty);
 308 extern void tty_unhangup(struct file *filp);
 309 extern int tty_hung_up_p(struct file * filp);
 310 extern void do_SAK(struct tty_struct *tty);
 311 extern void disassociate_ctty(int priv);
 312 
 313 /* n_tty.c */
 314 extern struct tty_ldisc tty_ldisc_N_TTY;
 315 
 316 /* tty_ioctl.c */
 317 extern int n_tty_ioctl(struct tty_struct * tty, struct file * file,
 318                        unsigned int cmd, unsigned long arg);
 319 
 320 /* serial.c */
 321 
 322 extern int  rs_open(struct tty_struct * tty, struct file * filp);
 323 
 324 /* pty.c */
 325 
 326 extern int  pty_open(struct tty_struct * tty, struct file * filp);
 327 
 328 /* console.c */
 329 
 330 extern int con_open(struct tty_struct * tty, struct file * filp);
 331 extern void update_screen(int new_console);
 332 extern void console_print(const char *);
 333 
 334 /* vt.c */
 335 
 336 extern int vt_ioctl(struct tty_struct *tty, struct file * file,
 337                     unsigned int cmd, unsigned long arg);
 338 
 339 #endif /* __KERNEL__ */
 340 #endif

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