5 * 'tty.h' defines some structures used by tty_io.c and some defines.
9 * These constants are also useful for user-level apps (e.g., VC
12 #define MIN_NR_CONSOLES 1 /* must be at least 1 */
13 #define MAX_NR_CONSOLES 63 /* serial lines start at 64 */
14 #define MAX_NR_USER_CONSOLES 63 /* must be root to allocate above this */
15 /* Note: the ioctl VT_GETSTATE does not work for
16 consoles 16 and higher (since it returns a short) */
20 #include <linux/termios.h>
21 #include <linux/tqueue.h>
22 #include <linux/tty_driver.h>
23 #include <linux/tty_ldisc.h>
24 #include <linux/serialP.h>
26 #include <asm/system.h>
30 * Note: don't mess with NR_PTYS until you understand the tty minor
31 * number allocation game...
32 * (Note: the *_driver.minor_start values 1, 64, 128, 192 are
33 * hardcoded at present.)
39 * These are set up by the setup-routine at boot-time:
45 unsigned char unused1
[2];
46 unsigned short orig_video_page
;
47 unsigned char orig_video_mode
;
48 unsigned char orig_video_cols
;
49 unsigned short unused2
;
50 unsigned short orig_video_ega_bx
;
51 unsigned short unused3
;
52 unsigned char orig_video_lines
;
53 unsigned char orig_video_isVGA
;
54 unsigned short orig_video_points
;
57 extern struct screen_info screen_info
;
59 #define ORIG_X (screen_info.orig_x)
60 #define ORIG_Y (screen_info.orig_y)
61 #define ORIG_VIDEO_MODE (screen_info.orig_video_mode)
62 #define ORIG_VIDEO_COLS (screen_info.orig_video_cols)
63 #define ORIG_VIDEO_EGA_BX (screen_info.orig_video_ega_bx)
64 #define ORIG_VIDEO_LINES (screen_info.orig_video_lines)
65 #define ORIG_VIDEO_ISVGA (screen_info.orig_video_isVGA)
66 #define ORIG_VIDEO_POINTS (screen_info.orig_video_points)
68 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
69 #define VIDEO_TYPE_CGA 0x11 /* CGA Display */
70 #define VIDEO_TYPE_EGAM 0x20 /* EGA/VGA in Monochrome Mode */
71 #define VIDEO_TYPE_EGAC 0x21 /* EGA in Color Mode */
72 #define VIDEO_TYPE_VGAC 0x22 /* VGA+ in Color Mode */
74 #define VIDEO_TYPE_TGAC 0x40 /* DEC TGA */
76 #define VIDEO_TYPE_SUN 0x50 /* Sun frame buffer. */
77 #define VIDEO_TYPE_SUNPCI 0x51 /* Sun PCI based frame buffer. */
79 #define VIDEO_TYPE_PMAC 0x60 /* PowerMacintosh frame buffer. */
82 * This character is the same as _POSIX_VDISABLE: it cannot be used as
83 * a c_cc[] character, but indicates that a particular special character
84 * isn't in use (eg VINTR has no character etc)
86 #define __DISABLED_CHAR '\0'
89 * This is the flip buffer used for the tty driver. The buffer is
90 * located in the tty structure, and is used as a high speed interface
91 * between the tty driver and the tty line discipline.
93 #define TTY_FLIPBUF_SIZE 512
95 struct tty_flip_buffer
{
96 struct tq_struct tqueue
;
97 struct semaphore pty_sem
;
99 unsigned char *flag_buf_ptr
;
102 unsigned char char_buf
[2*TTY_FLIPBUF_SIZE
];
103 char flag_buf
[2*TTY_FLIPBUF_SIZE
];
104 unsigned char slop
[4]; /* N.B. bug overwrites buffer by 1 */
107 * The pty uses char_buf and flag_buf as a contiguous buffer
109 #define PTY_BUF_SIZE 4*TTY_FLIPBUF_SIZE
112 * When a break, frame error, or parity error happens, these codes are
113 * stuffed into the flags buffer.
119 #define TTY_OVERRUN 4
121 #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
122 #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
123 #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
124 #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
125 #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
126 #define TIME_CHAR(tty) ((tty)->termios->c_cc[VTIME])
127 #define MIN_CHAR(tty) ((tty)->termios->c_cc[VMIN])
128 #define SWTC_CHAR(tty) ((tty)->termios->c_cc[VSWTC])
129 #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
130 #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
131 #define SUSP_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
132 #define EOL_CHAR(tty) ((tty)->termios->c_cc[VEOL])
133 #define REPRINT_CHAR(tty) ((tty)->termios->c_cc[VREPRINT])
134 #define DISCARD_CHAR(tty) ((tty)->termios->c_cc[VDISCARD])
135 #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE])
136 #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT])
137 #define EOL2_CHAR(tty) ((tty)->termios->c_cc[VEOL2])
139 #define _I_FLAG(tty,f) ((tty)->termios->c_iflag & (f))
140 #define _O_FLAG(tty,f) ((tty)->termios->c_oflag & (f))
141 #define _C_FLAG(tty,f) ((tty)->termios->c_cflag & (f))
142 #define _L_FLAG(tty,f) ((tty)->termios->c_lflag & (f))
144 #define I_IGNBRK(tty) _I_FLAG((tty),IGNBRK)
145 #define I_BRKINT(tty) _I_FLAG((tty),BRKINT)
146 #define I_IGNPAR(tty) _I_FLAG((tty),IGNPAR)
147 #define I_PARMRK(tty) _I_FLAG((tty),PARMRK)
148 #define I_INPCK(tty) _I_FLAG((tty),INPCK)
149 #define I_ISTRIP(tty) _I_FLAG((tty),ISTRIP)
150 #define I_INLCR(tty) _I_FLAG((tty),INLCR)
151 #define I_IGNCR(tty) _I_FLAG((tty),IGNCR)
152 #define I_ICRNL(tty) _I_FLAG((tty),ICRNL)
153 #define I_IUCLC(tty) _I_FLAG((tty),IUCLC)
154 #define I_IXON(tty) _I_FLAG((tty),IXON)
155 #define I_IXANY(tty) _I_FLAG((tty),IXANY)
156 #define I_IXOFF(tty) _I_FLAG((tty),IXOFF)
157 #define I_IMAXBEL(tty) _I_FLAG((tty),IMAXBEL)
159 #define O_OPOST(tty) _O_FLAG((tty),OPOST)
160 #define O_OLCUC(tty) _O_FLAG((tty),OLCUC)
161 #define O_ONLCR(tty) _O_FLAG((tty),ONLCR)
162 #define O_OCRNL(tty) _O_FLAG((tty),OCRNL)
163 #define O_ONOCR(tty) _O_FLAG((tty),ONOCR)
164 #define O_ONLRET(tty) _O_FLAG((tty),ONLRET)
165 #define O_OFILL(tty) _O_FLAG((tty),OFILL)
166 #define O_OFDEL(tty) _O_FLAG((tty),OFDEL)
167 #define O_NLDLY(tty) _O_FLAG((tty),NLDLY)
168 #define O_CRDLY(tty) _O_FLAG((tty),CRDLY)
169 #define O_TABDLY(tty) _O_FLAG((tty),TABDLY)
170 #define O_BSDLY(tty) _O_FLAG((tty),BSDLY)
171 #define O_VTDLY(tty) _O_FLAG((tty),VTDLY)
172 #define O_FFDLY(tty) _O_FLAG((tty),FFDLY)
174 #define C_BAUD(tty) _C_FLAG((tty),CBAUD)
175 #define C_CSIZE(tty) _C_FLAG((tty),CSIZE)
176 #define C_CSTOPB(tty) _C_FLAG((tty),CSTOPB)
177 #define C_CREAD(tty) _C_FLAG((tty),CREAD)
178 #define C_PARENB(tty) _C_FLAG((tty),PARENB)
179 #define C_PARODD(tty) _C_FLAG((tty),PARODD)
180 #define C_HUPCL(tty) _C_FLAG((tty),HUPCL)
181 #define C_CLOCAL(tty) _C_FLAG((tty),CLOCAL)
182 #define C_CIBAUD(tty) _C_FLAG((tty),CIBAUD)
183 #define C_CRTSCTS(tty) _C_FLAG((tty),CRTSCTS)
185 #define L_ISIG(tty) _L_FLAG((tty),ISIG)
186 #define L_ICANON(tty) _L_FLAG((tty),ICANON)
187 #define L_XCASE(tty) _L_FLAG((tty),XCASE)
188 #define L_ECHO(tty) _L_FLAG((tty),ECHO)
189 #define L_ECHOE(tty) _L_FLAG((tty),ECHOE)
190 #define L_ECHOK(tty) _L_FLAG((tty),ECHOK)
191 #define L_ECHONL(tty) _L_FLAG((tty),ECHONL)
192 #define L_NOFLSH(tty) _L_FLAG((tty),NOFLSH)
193 #define L_TOSTOP(tty) _L_FLAG((tty),TOSTOP)
194 #define L_ECHOCTL(tty) _L_FLAG((tty),ECHOCTL)
195 #define L_ECHOPRT(tty) _L_FLAG((tty),ECHOPRT)
196 #define L_ECHOKE(tty) _L_FLAG((tty),ECHOKE)
197 #define L_FLUSHO(tty) _L_FLAG((tty),FLUSHO)
198 #define L_PENDIN(tty) _L_FLAG((tty),PENDIN)
199 #define L_IEXTEN(tty) _L_FLAG((tty),IEXTEN)
202 * Where all of the state associated with a tty is kept while the tty
203 * is open. Since the termios state should be kept even if the tty
204 * has been closed --- for things like the baud rate, etc --- it is
205 * not stored here, but rather a pointer to the real state is stored
206 * here. Possible the winsize structure should have the same
207 * treatment, but (1) the default 80x24 is usually right and (2) it's
208 * most often used by a windowing system, which will set the correct
209 * size each time the window is created or resized anyway.
210 * IMPORTANT: since this structure is dynamically allocated, it must
211 * be no larger than 4096 bytes. Changing TTY_FLIPBUF_SIZE will change
212 * the size of this structure, and it needs to be done with care.
217 struct tty_driver driver
;
218 struct tty_ldisc ldisc
;
219 struct termios
*termios
, *termios_locked
;
225 struct winsize winsize
;
226 unsigned char stopped
:1, hw_stopped
:1, flow_stopped
:1, packet
:1;
227 unsigned char low_latency
:1, warned
:1;
228 unsigned char ctrl_status
;
230 struct tty_struct
*link
;
231 struct fasync_struct
*fasync
;
232 struct tty_flip_buffer flip
;
234 int alt_speed
; /* For magic substitution of 38400 bps */
235 struct wait_queue
*write_wait
;
236 struct wait_queue
*read_wait
;
237 struct tq_struct tq_hangup
;
241 #define N_TTY_BUF_SIZE 4096
244 * The following is data for the N_TTY line discipline. For
245 * historical reasons, this is included in the tty structure.
248 unsigned char lnext
:1, erasing
:1, raw
:1, real_raw
:1, icanon
:1;
249 unsigned char closing
:1;
250 unsigned short minimum_to_wake
;
251 unsigned overrun_time
;
253 unsigned long process_char_map
[256/(8*sizeof(unsigned long))];
258 unsigned long read_flags
[N_TTY_BUF_SIZE
/(8*sizeof(unsigned long))];
260 unsigned long canon_head
;
261 unsigned int canon_column
;
264 /* tty magic number */
265 #define TTY_MAGIC 0x5401
268 * These bits are used in the flags field of the tty structure.
270 * So that interrupts won't be able to mess up the queues,
271 * copy_to_cooked must be atomic with respect to itself, as must
272 * tty->write. Thus, you must use the inline functions set_bit() and
273 * clear_bit() to make things atomic.
275 #define TTY_THROTTLED 0
276 #define TTY_IO_ERROR 1
277 #define TTY_OTHER_CLOSED 2
278 #define TTY_EXCLUSIVE 3
280 #define TTY_DO_WRITE_WAKEUP 5
282 #define TTY_CLOSING 7
283 #define TTY_HW_COOK_OUT 14
284 #define TTY_HW_COOK_IN 15
286 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
288 extern void tty_write_flush(struct tty_struct
*);
290 extern struct termios tty_std_termios
;
291 extern struct tty_struct
* redirect
;
292 extern struct tty_ldisc ldiscs
[];
293 extern int fg_console
, last_console
, want_console
;
295 extern int kmsg_redirect
;
297 extern unsigned long con_init(unsigned long);
299 extern int rs_init(void);
300 extern int lp_init(void);
301 extern int pty_init(void);
302 extern int tty_init(void);
303 extern int pcxe_init(void);
304 extern int pc_init(void);
305 extern int vcs_init(void);
306 extern int rp_init(void);
307 extern int cy_init(void);
308 extern int stl_init(void);
309 extern int stli_init(void);
310 extern int riscom8_init(void);
311 extern int specialix_init(void);
312 extern int espserial_init(void);
314 extern int tty_paranoia_check(struct tty_struct
*tty
, kdev_t device
,
315 const char *routine
);
316 extern char *_tty_name(struct tty_struct
*tty
, char *buf
);
317 extern char *tty_name(struct tty_struct
*tty
);
318 extern void tty_wait_until_sent(struct tty_struct
* tty
, int timeout
);
319 extern int tty_check_change(struct tty_struct
* tty
);
320 extern void stop_tty(struct tty_struct
* tty
);
321 extern void start_tty(struct tty_struct
* tty
);
322 extern int tty_register_ldisc(int disc
, struct tty_ldisc
*new_ldisc
);
323 extern int tty_register_driver(struct tty_driver
*driver
);
324 extern int tty_unregister_driver(struct tty_driver
*driver
);
325 extern int tty_read_raw_data(struct tty_struct
*tty
, unsigned char *bufp
,
327 extern void tty_write_message(struct tty_struct
*tty
, char *msg
);
329 extern int is_orphaned_pgrp(int pgrp
);
330 extern int is_ignored(int sig
);
331 extern int tty_signal(int sig
, struct tty_struct
*tty
);
332 extern void tty_hangup(struct tty_struct
* tty
);
333 extern void tty_vhangup(struct tty_struct
* tty
);
334 extern void tty_unhangup(struct file
*filp
);
335 extern int tty_hung_up_p(struct file
* filp
);
336 extern void do_SAK(struct tty_struct
*tty
);
337 extern void disassociate_ctty(int priv
);
338 extern void tty_flip_buffer_push(struct tty_struct
*tty
);
339 extern int tty_get_baud_rate(struct tty_struct
*tty
);
342 extern struct tty_ldisc tty_ldisc_N_TTY
;
345 extern int n_tty_ioctl(struct tty_struct
* tty
, struct file
* file
,
346 unsigned int cmd
, unsigned long arg
);
350 extern long serial_console_init(long kmem_start
, long kmem_end
);
354 extern int pcxe_open(struct tty_struct
*tty
, struct file
*filp
);
358 extern void update_screen(int new_console
);
362 extern void console_print(const char *);
366 extern int vt_ioctl(struct tty_struct
*tty
, struct file
* file
,
367 unsigned int cmd
, unsigned long arg
);
369 #endif /* __KERNEL__ */