Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

tty.h

Go to the documentation of this file.
00001 #ifndef _LINUX_TTY_H
00002 #define _LINUX_TTY_H
00003 
00004 /*
00005  * 'tty.h' defines some structures used by tty_io.c and some defines.
00006  */
00007 
00008 /*
00009  * These constants are also useful for user-level apps (e.g., VC
00010  * resizing).
00011  */
00012 #define MIN_NR_CONSOLES 1       /* must be at least 1 */
00013 #define MAX_NR_CONSOLES 63      /* serial lines start at 64 */
00014 #define MAX_NR_USER_CONSOLES 63 /* must be root to allocate above this */
00015                 /* Note: the ioctl VT_GETSTATE does not work for
00016                    consoles 16 and higher (since it returns a short) */
00017 
00018 #ifdef __KERNEL__
00019 #include <linux/config.h>
00020 #include <linux/fs.h>
00021 #include <linux/major.h>
00022 #include <linux/termios.h>
00023 #include <linux/tqueue.h>
00024 #include <linux/tty_driver.h>
00025 #include <linux/tty_ldisc.h>
00026 #include <linux/serialP.h>
00027 
00028 #include <asm/system.h>
00029 
00030 
00031 /*
00032  * Note: don't mess with NR_PTYS until you understand the tty minor 
00033  * number allocation game...
00034  * (Note: the *_driver.minor_start values 1, 64, 128, 192 are
00035  * hardcoded at present.)
00036  */
00037 #define NR_PTYS         256     /* ptys/major */
00038 #define NR_LDISCS       16
00039 
00040 /*
00041  * Unix98 PTY's can be defined as any multiple of NR_PTYS up to
00042  * UNIX98_PTY_MAJOR_COUNT; this section defines what we need from the
00043  * config options
00044  */
00045 #ifdef CONFIG_UNIX98_PTYS
00046 # define UNIX98_NR_MAJORS ((CONFIG_UNIX98_PTY_COUNT+NR_PTYS-1)/NR_PTYS)
00047 # if UNIX98_NR_MAJORS <= 0
00048 #  undef CONFIG_UNIX98_PTYS
00049 # elif UNIX98_NR_MAJORS > UNIX98_PTY_MAJOR_COUNT
00050 #  error  Too many Unix98 ptys defined
00051 #  undef  UNIX98_NR_MAJORS
00052 #  define UNIX98_NR_MAJORS UNIX98_PTY_MAJOR_COUNT
00053 # endif
00054 #endif
00055 
00056 /*
00057  * These are set up by the setup-routine at boot-time:
00058  */
00059 
00060 struct screen_info {
00061         unsigned char  orig_x;                  /* 0x00 */
00062         unsigned char  orig_y;                  /* 0x01 */
00063         unsigned short dontuse1;                /* 0x02 -- EXT_MEM_K sits here */
00064         unsigned short orig_video_page;         /* 0x04 */
00065         unsigned char  orig_video_mode;         /* 0x06 */
00066         unsigned char  orig_video_cols;         /* 0x07 */
00067         unsigned short unused2;                 /* 0x08 */
00068         unsigned short orig_video_ega_bx;       /* 0x0a */
00069         unsigned short unused3;                 /* 0x0c */
00070         unsigned char  orig_video_lines;        /* 0x0e */
00071         unsigned char  orig_video_isVGA;        /* 0x0f */
00072         unsigned short orig_video_points;       /* 0x10 */
00073 
00074         /* VESA graphic mode -- linear frame buffer */
00075         unsigned short lfb_width;               /* 0x12 */
00076         unsigned short lfb_height;              /* 0x14 */
00077         unsigned short lfb_depth;               /* 0x16 */
00078         unsigned long  lfb_base;                /* 0x18 */
00079         unsigned long  lfb_size;                /* 0x1c */
00080         unsigned short dontuse2, dontuse3;      /* 0x20 -- CL_MAGIC and CL_OFFSET here */
00081         unsigned short lfb_linelength;          /* 0x24 */
00082         unsigned char  red_size;                /* 0x26 */
00083         unsigned char  red_pos;                 /* 0x27 */
00084         unsigned char  green_size;              /* 0x28 */
00085         unsigned char  green_pos;               /* 0x29 */
00086         unsigned char  blue_size;               /* 0x2a */
00087         unsigned char  blue_pos;                /* 0x2b */
00088         unsigned char  rsvd_size;               /* 0x2c */
00089         unsigned char  rsvd_pos;                /* 0x2d */
00090         unsigned short vesapm_seg;              /* 0x2e */
00091         unsigned short vesapm_off;              /* 0x30 */
00092         unsigned short pages;                   /* 0x32 */
00093                                                 /* 0x34 -- 0x3f reserved for future expansion */
00094 };
00095 
00096 extern struct screen_info screen_info;
00097 
00098 #define ORIG_X                  (screen_info.orig_x)
00099 #define ORIG_Y                  (screen_info.orig_y)
00100 #define ORIG_VIDEO_MODE         (screen_info.orig_video_mode)
00101 #define ORIG_VIDEO_COLS         (screen_info.orig_video_cols)
00102 #define ORIG_VIDEO_EGA_BX       (screen_info.orig_video_ega_bx)
00103 #define ORIG_VIDEO_LINES        (screen_info.orig_video_lines)
00104 #define ORIG_VIDEO_ISVGA        (screen_info.orig_video_isVGA)
00105 #define ORIG_VIDEO_POINTS       (screen_info.orig_video_points)
00106 
00107 #define VIDEO_TYPE_MDA          0x10    /* Monochrome Text Display      */
00108 #define VIDEO_TYPE_CGA          0x11    /* CGA Display                  */
00109 #define VIDEO_TYPE_EGAM         0x20    /* EGA/VGA in Monochrome Mode   */
00110 #define VIDEO_TYPE_EGAC         0x21    /* EGA in Color Mode            */
00111 #define VIDEO_TYPE_VGAC         0x22    /* VGA+ in Color Mode           */
00112 #define VIDEO_TYPE_VLFB         0x23    /* VESA VGA in graphic mode     */
00113 
00114 #define VIDEO_TYPE_TGAC         0x40    /* DEC TGA */
00115 
00116 #define VIDEO_TYPE_SUN          0x50    /* Sun frame buffer. */
00117 #define VIDEO_TYPE_SUNPCI       0x51    /* Sun PCI based frame buffer. */
00118 
00119 #define VIDEO_TYPE_PMAC         0x60    /* PowerMacintosh frame buffer. */
00120 
00121 #define VIDEO_TYPE_SGI          0x70    /* Various SGI graphics hardware */
00122 #define VIDEO_TYPE_MIPS_G364    0x71    /* MIPS Magnum 4000 G364 video  */
00123 
00124 /*
00125  * This character is the same as _POSIX_VDISABLE: it cannot be used as
00126  * a c_cc[] character, but indicates that a particular special character
00127  * isn't in use (eg VINTR has no character etc)
00128  */
00129 #define __DISABLED_CHAR '\0'
00130 
00131 /*
00132  * This is the flip buffer used for the tty driver.  The buffer is
00133  * located in the tty structure, and is used as a high speed interface
00134  * between the tty driver and the tty line discipline.
00135  */
00136 #define TTY_FLIPBUF_SIZE 512
00137 
00138 struct tty_flip_buffer {
00139         struct tq_struct tqueue;
00140         struct semaphore pty_sem;
00141         char            *char_buf_ptr;
00142         unsigned char   *flag_buf_ptr;
00143         int             count;
00144         int             buf_num;
00145         unsigned char   char_buf[2*TTY_FLIPBUF_SIZE];
00146         char            flag_buf[2*TTY_FLIPBUF_SIZE];
00147         unsigned char   slop[4]; /* N.B. bug overwrites buffer by 1 */
00148 };
00149 /*
00150  * The pty uses char_buf and flag_buf as a contiguous buffer
00151  */
00152 #define PTY_BUF_SIZE    4*TTY_FLIPBUF_SIZE
00153 
00154 /*
00155  * When a break, frame error, or parity error happens, these codes are
00156  * stuffed into the flags buffer.
00157  */
00158 #define TTY_NORMAL      0
00159 #define TTY_BREAK       1
00160 #define TTY_FRAME       2
00161 #define TTY_PARITY      3
00162 #define TTY_OVERRUN     4
00163 
00164 #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
00165 #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
00166 #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
00167 #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
00168 #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
00169 #define TIME_CHAR(tty) ((tty)->termios->c_cc[VTIME])
00170 #define MIN_CHAR(tty) ((tty)->termios->c_cc[VMIN])
00171 #define SWTC_CHAR(tty) ((tty)->termios->c_cc[VSWTC])
00172 #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
00173 #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
00174 #define SUSP_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
00175 #define EOL_CHAR(tty) ((tty)->termios->c_cc[VEOL])
00176 #define REPRINT_CHAR(tty) ((tty)->termios->c_cc[VREPRINT])
00177 #define DISCARD_CHAR(tty) ((tty)->termios->c_cc[VDISCARD])
00178 #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE])
00179 #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT])
00180 #define EOL2_CHAR(tty) ((tty)->termios->c_cc[VEOL2])
00181 
00182 #define _I_FLAG(tty,f)  ((tty)->termios->c_iflag & (f))
00183 #define _O_FLAG(tty,f)  ((tty)->termios->c_oflag & (f))
00184 #define _C_FLAG(tty,f)  ((tty)->termios->c_cflag & (f))
00185 #define _L_FLAG(tty,f)  ((tty)->termios->c_lflag & (f))
00186 
00187 #define I_IGNBRK(tty)   _I_FLAG((tty),IGNBRK)
00188 #define I_BRKINT(tty)   _I_FLAG((tty),BRKINT)
00189 #define I_IGNPAR(tty)   _I_FLAG((tty),IGNPAR)
00190 #define I_PARMRK(tty)   _I_FLAG((tty),PARMRK)
00191 #define I_INPCK(tty)    _I_FLAG((tty),INPCK)
00192 #define I_ISTRIP(tty)   _I_FLAG((tty),ISTRIP)
00193 #define I_INLCR(tty)    _I_FLAG((tty),INLCR)
00194 #define I_IGNCR(tty)    _I_FLAG((tty),IGNCR)
00195 #define I_ICRNL(tty)    _I_FLAG((tty),ICRNL)
00196 #define I_IUCLC(tty)    _I_FLAG((tty),IUCLC)
00197 #define I_IXON(tty)     _I_FLAG((tty),IXON)
00198 #define I_IXANY(tty)    _I_FLAG((tty),IXANY)
00199 #define I_IXOFF(tty)    _I_FLAG((tty),IXOFF)
00200 #define I_IMAXBEL(tty)  _I_FLAG((tty),IMAXBEL)
00201 
00202 #define O_OPOST(tty)    _O_FLAG((tty),OPOST)
00203 #define O_OLCUC(tty)    _O_FLAG((tty),OLCUC)
00204 #define O_ONLCR(tty)    _O_FLAG((tty),ONLCR)
00205 #define O_OCRNL(tty)    _O_FLAG((tty),OCRNL)
00206 #define O_ONOCR(tty)    _O_FLAG((tty),ONOCR)
00207 #define O_ONLRET(tty)   _O_FLAG((tty),ONLRET)
00208 #define O_OFILL(tty)    _O_FLAG((tty),OFILL)
00209 #define O_OFDEL(tty)    _O_FLAG((tty),OFDEL)
00210 #define O_NLDLY(tty)    _O_FLAG((tty),NLDLY)
00211 #define O_CRDLY(tty)    _O_FLAG((tty),CRDLY)
00212 #define O_TABDLY(tty)   _O_FLAG((tty),TABDLY)
00213 #define O_BSDLY(tty)    _O_FLAG((tty),BSDLY)
00214 #define O_VTDLY(tty)    _O_FLAG((tty),VTDLY)
00215 #define O_FFDLY(tty)    _O_FLAG((tty),FFDLY)
00216 
00217 #define C_BAUD(tty)     _C_FLAG((tty),CBAUD)
00218 #define C_CSIZE(tty)    _C_FLAG((tty),CSIZE)
00219 #define C_CSTOPB(tty)   _C_FLAG((tty),CSTOPB)
00220 #define C_CREAD(tty)    _C_FLAG((tty),CREAD)
00221 #define C_PARENB(tty)   _C_FLAG((tty),PARENB)
00222 #define C_PARODD(tty)   _C_FLAG((tty),PARODD)
00223 #define C_HUPCL(tty)    _C_FLAG((tty),HUPCL)
00224 #define C_CLOCAL(tty)   _C_FLAG((tty),CLOCAL)
00225 #define C_CIBAUD(tty)   _C_FLAG((tty),CIBAUD)
00226 #define C_CRTSCTS(tty)  _C_FLAG((tty),CRTSCTS)
00227 
00228 #define L_ISIG(tty)     _L_FLAG((tty),ISIG)
00229 #define L_ICANON(tty)   _L_FLAG((tty),ICANON)
00230 #define L_XCASE(tty)    _L_FLAG((tty),XCASE)
00231 #define L_ECHO(tty)     _L_FLAG((tty),ECHO)
00232 #define L_ECHOE(tty)    _L_FLAG((tty),ECHOE)
00233 #define L_ECHOK(tty)    _L_FLAG((tty),ECHOK)
00234 #define L_ECHONL(tty)   _L_FLAG((tty),ECHONL)
00235 #define L_NOFLSH(tty)   _L_FLAG((tty),NOFLSH)
00236 #define L_TOSTOP(tty)   _L_FLAG((tty),TOSTOP)
00237 #define L_ECHOCTL(tty)  _L_FLAG((tty),ECHOCTL)
00238 #define L_ECHOPRT(tty)  _L_FLAG((tty),ECHOPRT)
00239 #define L_ECHOKE(tty)   _L_FLAG((tty),ECHOKE)
00240 #define L_FLUSHO(tty)   _L_FLAG((tty),FLUSHO)
00241 #define L_PENDIN(tty)   _L_FLAG((tty),PENDIN)
00242 #define L_IEXTEN(tty)   _L_FLAG((tty),IEXTEN)
00243 
00244 /*
00245  * Where all of the state associated with a tty is kept while the tty
00246  * is open.  Since the termios state should be kept even if the tty
00247  * has been closed --- for things like the baud rate, etc --- it is
00248  * not stored here, but rather a pointer to the real state is stored
00249  * here.  Possible the winsize structure should have the same
00250  * treatment, but (1) the default 80x24 is usually right and (2) it's
00251  * most often used by a windowing system, which will set the correct
00252  * size each time the window is created or resized anyway.
00253  * IMPORTANT: since this structure is dynamically allocated, it must
00254  * be no larger than 4096 bytes.  Changing TTY_FLIPBUF_SIZE will change
00255  * the size of this structure, and it needs to be done with care.
00256  *                                              - TYT, 9/14/92
00257  */
00258 struct tty_struct {
00259         int     magic;
00260         struct tty_driver driver;
00261         struct tty_ldisc ldisc;
00262         struct termios *termios, *termios_locked;
00263         int pgrp;
00264         int session;
00265         kdev_t  device;
00266         unsigned long flags;
00267         int count;
00268         struct winsize winsize;
00269         unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1;
00270         unsigned char low_latency:1, warned:1;
00271         unsigned char ctrl_status;
00272 
00273         struct tty_struct *link;
00274         struct fasync_struct *fasync;
00275         struct tty_flip_buffer flip;
00276         int max_flip_cnt;
00277         int alt_speed;          /* For magic substitution of 38400 bps */
00278         struct wait_queue *write_wait;
00279         struct wait_queue *read_wait;
00280         struct wait_queue *poll_wait;
00281         struct tq_struct tq_hangup;
00282         void *disc_data;
00283         void *driver_data;
00284 
00285 #define N_TTY_BUF_SIZE 4096
00286         
00287         /*
00288          * The following is data for the N_TTY line discipline.  For
00289          * historical reasons, this is included in the tty structure.
00290          */
00291         unsigned int column;
00292         unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
00293         unsigned char closing:1;
00294         unsigned short minimum_to_wake;
00295         unsigned overrun_time;
00296         int num_overrun;
00297         unsigned long process_char_map[256/(8*sizeof(unsigned long))];
00298         char *read_buf;
00299         int read_head;
00300         int read_tail;
00301         int read_cnt;
00302         unsigned long read_flags[N_TTY_BUF_SIZE/(8*sizeof(unsigned long))];
00303         int canon_data;
00304         unsigned long canon_head;
00305         unsigned int canon_column;
00306         struct semaphore atomic_read;
00307         struct semaphore atomic_write;
00308         spinlock_t read_lock;
00309 };
00310 
00311 /* tty magic number */
00312 #define TTY_MAGIC               0x5401
00313 
00314 /*
00315  * These bits are used in the flags field of the tty structure.
00316  * 
00317  * So that interrupts won't be able to mess up the queues,
00318  * copy_to_cooked must be atomic with respect to itself, as must
00319  * tty->write.  Thus, you must use the inline functions set_bit() and
00320  * clear_bit() to make things atomic.
00321  */
00322 #define TTY_THROTTLED 0
00323 #define TTY_IO_ERROR 1
00324 #define TTY_OTHER_CLOSED 2
00325 #define TTY_EXCLUSIVE 3
00326 #define TTY_DEBUG 4
00327 #define TTY_DO_WRITE_WAKEUP 5
00328 #define TTY_PUSH 6
00329 #define TTY_CLOSING 7
00330 #define TTY_DONT_FLIP 8
00331 #define TTY_HW_COOK_OUT 14
00332 #define TTY_HW_COOK_IN 15
00333 #define TTY_PTY_LOCK 16
00334 #define TTY_NO_WRITE_SPLIT 17
00335 
00336 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
00337 
00338 extern void tty_write_flush(struct tty_struct *);
00339 
00340 extern struct termios tty_std_termios;
00341 extern struct tty_struct * redirect;
00342 extern struct tty_ldisc ldiscs[];
00343 extern int fg_console, last_console, want_console;
00344 
00345 extern int kmsg_redirect;
00346 
00347 extern unsigned long con_init(unsigned long);
00348 
00349 extern int rs_init(void);
00350 extern int lp_init(void);
00351 extern int pty_init(void);
00352 extern int tty_init(void);
00353 extern int mxser_init(void);
00354 extern int moxa_init(void);
00355 extern int ip2_init(void);
00356 extern int pcxe_init(void);
00357 extern int pc_init(void);
00358 extern int vcs_init(void);
00359 extern int rp_init(void);
00360 extern int cy_init(void);
00361 extern int stl_init(void);
00362 extern int stli_init(void);
00363 extern int riscom8_init(void);
00364 extern int specialix_init(void);
00365 extern int espserial_init(void);
00366 extern int macserial_init(void);
00367 extern int mgsl_init(void);
00368 extern int n_hdlc_init(void);
00369 
00370 extern int tty_paranoia_check(struct tty_struct *tty, kdev_t device,
00371                               const char *routine);
00372 extern char *tty_name(struct tty_struct *tty, char *buf);
00373 extern void tty_wait_until_sent(struct tty_struct * tty, long timeout);
00374 extern int tty_check_change(struct tty_struct * tty);
00375 extern void stop_tty(struct tty_struct * tty);
00376 extern void start_tty(struct tty_struct * tty);
00377 extern int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc);
00378 extern int tty_register_driver(struct tty_driver *driver);
00379 extern int tty_unregister_driver(struct tty_driver *driver);
00380 extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp,
00381                              int buflen);
00382 extern void tty_write_message(struct tty_struct *tty, char *msg);
00383 
00384 extern int is_orphaned_pgrp(int pgrp);
00385 extern int is_ignored(int sig);
00386 extern int tty_signal(int sig, struct tty_struct *tty);
00387 extern void tty_hangup(struct tty_struct * tty);
00388 extern void tty_vhangup(struct tty_struct * tty);
00389 extern void tty_unhangup(struct file *filp);
00390 extern int tty_hung_up_p(struct file * filp);
00391 extern void do_SAK(struct tty_struct *tty);
00392 extern void disassociate_ctty(int priv);
00393 extern void tty_flip_buffer_push(struct tty_struct *tty);
00394 extern int tty_get_baud_rate(struct tty_struct *tty);
00395 
00396 /* n_tty.c */
00397 extern struct tty_ldisc tty_ldisc_N_TTY;
00398 
00399 /* tty_ioctl.c */
00400 extern int n_tty_ioctl(struct tty_struct * tty, struct file * file,
00401                        unsigned int cmd, unsigned long arg);
00402 
00403 /* serial.c */
00404 
00405 extern long serial_console_init(long kmem_start, long kmem_end);
00406  
00407 /* pcxx.c */
00408 
00409 extern int pcxe_open(struct tty_struct *tty, struct file *filp);
00410 
00411 /* printk.c */
00412 
00413 extern void console_print(const char *);
00414 
00415 /* vt.c */
00416 
00417 extern int vt_ioctl(struct tty_struct *tty, struct file * file,
00418                     unsigned int cmd, unsigned long arg);
00419 
00420 #endif /* __KERNEL__ */
00421 #endif