1 #ifndef _LINUX_TTY_H
2 #define _LINUX_TTY_H
3
4
5
6
7
8 #include <linux/fs.h>
9 #include <linux/termios.h>
10 #include <linux/tqueue.h>
11 #include <linux/tty_driver.h>
12 #include <linux/tty_ldisc.h>
13
14 #include <asm/system.h>
15
16
17
18
19
20 #define NR_CONSOLES 8
21 #define NR_PTYS 64
22 #define NR_LDISCS 16
23
24
25
26
27
28 struct screen_info {
29 unsigned char orig_x;
30 unsigned char orig_y;
31 unsigned char unused1[2];
32 unsigned short orig_video_page;
33 unsigned char orig_video_mode;
34 unsigned char orig_video_cols;
35 unsigned short orig_video_ega_ax;
36 unsigned short orig_video_ega_bx;
37 unsigned short orig_video_ega_cx;
38 unsigned char orig_video_lines;
39 };
40
41 extern struct screen_info screen_info;
42
43 #define ORIG_X (screen_info.orig_x)
44 #define ORIG_Y (screen_info.orig_y)
45 #define ORIG_VIDEO_PAGE (screen_info.orig_video_page)
46 #define ORIG_VIDEO_MODE (screen_info.orig_video_mode)
47 #define ORIG_VIDEO_COLS (screen_info.orig_video_cols)
48 #define ORIG_VIDEO_EGA_AX (screen_info.orig_video_ega_ax)
49 #define ORIG_VIDEO_EGA_BX (screen_info.orig_video_ega_bx)
50 #define ORIG_VIDEO_EGA_CX (screen_info.orig_video_ega_cx)
51 #define ORIG_VIDEO_LINES (screen_info.orig_video_lines)
52
53 #define VIDEO_TYPE_MDA 0x10
54 #define VIDEO_TYPE_CGA 0x11
55 #define VIDEO_TYPE_EGAM 0x20
56 #define VIDEO_TYPE_EGAC 0x21
57
58
59
60
61
62
63 #define __DISABLED_CHAR '\0'
64
65
66
67
68
69
70 #define TTY_FLIPBUF_SIZE 512
71
72 struct tty_flip_buffer {
73 struct tq_struct tqueue;
74 unsigned char char_buf[2*TTY_FLIPBUF_SIZE];
75 char flag_buf[2*TTY_FLIPBUF_SIZE];
76 char *char_buf_ptr;
77 unsigned char *flag_buf_ptr;
78 int count;
79 int buf_num;
80 };
81
82
83
84
85
86 #define TTY_NORMAL 0
87 #define TTY_BREAK 1
88 #define TTY_FRAME 2
89 #define TTY_PARITY 3
90 #define TTY_OVERRUN 4
91
92 #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
93 #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
94 #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
95 #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
96 #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
97 #define TIME_CHAR(tty) ((tty)->termios->c_cc[VTIME])
98 #define MIN_CHAR(tty) ((tty)->termios->c_cc[VMIN])
99 #define SWTC_CHAR(tty) ((tty)->termios->c_cc[VSWTC])
100 #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
101 #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
102 #define SUSP_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
103 #define EOL_CHAR(tty) ((tty)->termios->c_cc[VEOL])
104 #define REPRINT_CHAR(tty) ((tty)->termios->c_cc[VREPRINT])
105 #define DISCARD_CHAR(tty) ((tty)->termios->c_cc[VDISCARD])
106 #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE])
107 #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT])
108 #define EOL2_CHAR(tty) ((tty)->termios->c_cc[VEOL2])
109
110 #define _I_FLAG(tty,f) ((tty)->termios->c_iflag & (f))
111 #define _O_FLAG(tty,f) ((tty)->termios->c_oflag & (f))
112 #define _C_FLAG(tty,f) ((tty)->termios->c_cflag & (f))
113 #define _L_FLAG(tty,f) ((tty)->termios->c_lflag & (f))
114
115 #define I_IGNBRK(tty) _I_FLAG((tty),IGNBRK)
116 #define I_BRKINT(tty) _I_FLAG((tty),BRKINT)
117 #define I_IGNPAR(tty) _I_FLAG((tty),IGNPAR)
118 #define I_PARMRK(tty) _I_FLAG((tty),PARMRK)
119 #define I_INPCK(tty) _I_FLAG((tty),INPCK)
120 #define I_ISTRIP(tty) _I_FLAG((tty),ISTRIP)
121 #define I_INLCR(tty) _I_FLAG((tty),INLCR)
122 #define I_IGNCR(tty) _I_FLAG((tty),IGNCR)
123 #define I_ICRNL(tty) _I_FLAG((tty),ICRNL)
124 #define I_IUCLC(tty) _I_FLAG((tty),IUCLC)
125 #define I_IXON(tty) _I_FLAG((tty),IXON)
126 #define I_IXANY(tty) _I_FLAG((tty),IXANY)
127 #define I_IXOFF(tty) _I_FLAG((tty),IXOFF)
128 #define I_IMAXBEL(tty) _I_FLAG((tty),IMAXBEL)
129
130 #define O_OPOST(tty) _O_FLAG((tty),OPOST)
131 #define O_OLCUC(tty) _O_FLAG((tty),OLCUC)
132 #define O_ONLCR(tty) _O_FLAG((tty),ONLCR)
133 #define O_OCRNL(tty) _O_FLAG((tty),OCRNL)
134 #define O_ONOCR(tty) _O_FLAG((tty),ONOCR)
135 #define O_ONLRET(tty) _O_FLAG((tty),ONLRET)
136 #define O_OFILL(tty) _O_FLAG((tty),OFILL)
137 #define O_OFDEL(tty) _O_FLAG((tty),OFDEL)
138 #define O_NLDLY(tty) _O_FLAG((tty),NLDLY)
139 #define O_CRDLY(tty) _O_FLAG((tty),CRDLY)
140 #define O_TABDLY(tty) _O_FLAG((tty),TABDLY)
141 #define O_BSDLY(tty) _O_FLAG((tty),BSDLY)
142 #define O_VTDLY(tty) _O_FLAG((tty),VTDLY)
143 #define O_FFDLY(tty) _O_FLAG((tty),FFDLY)
144
145 #define C_BAUD(tty) _C_FLAG((tty),CBAUD)
146 #define C_CSIZE(tty) _C_FLAG((tty),CSIZE)
147 #define C_CSTOPB(tty) _C_FLAG((tty),CSTOPB)
148 #define C_CREAD(tty) _C_FLAG((tty),CREAD)
149 #define C_PARENB(tty) _C_FLAG((tty),PARENB)
150 #define C_PARODD(tty) _C_FLAG((tty),PARODD)
151 #define C_HUPCL(tty) _C_FLAG((tty),HUPCL)
152 #define C_CLOCAL(tty) _C_FLAG((tty),CLOCAL)
153 #define C_CIBAUD(tty) _C_FLAG((tty),CIBAUD)
154 #define C_CRTSCTS(tty) _C_FLAG((tty),CRTSCTS)
155
156 #define L_ISIG(tty) _L_FLAG((tty),ISIG)
157 #define L_ICANON(tty) _L_FLAG((tty),ICANON)
158 #define L_XCASE(tty) _L_FLAG((tty),XCASE)
159 #define L_ECHO(tty) _L_FLAG((tty),ECHO)
160 #define L_ECHOE(tty) _L_FLAG((tty),ECHOE)
161 #define L_ECHOK(tty) _L_FLAG((tty),ECHOK)
162 #define L_ECHONL(tty) _L_FLAG((tty),ECHONL)
163 #define L_NOFLSH(tty) _L_FLAG((tty),NOFLSH)
164 #define L_TOSTOP(tty) _L_FLAG((tty),TOSTOP)
165 #define L_ECHOCTL(tty) _L_FLAG((tty),ECHOCTL)
166 #define L_ECHOPRT(tty) _L_FLAG((tty),ECHOPRT)
167 #define L_ECHOKE(tty) _L_FLAG((tty),ECHOKE)
168 #define L_FLUSHO(tty) _L_FLAG((tty),FLUSHO)
169 #define L_PENDIN(tty) _L_FLAG((tty),PENDIN)
170 #define L_IEXTEN(tty) _L_FLAG((tty),IEXTEN)
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186 struct tty_struct {
187 int magic;
188 struct tty_driver driver;
189 struct tty_ldisc ldisc;
190 struct termios *termios, *termios_locked;
191 int pgrp;
192 int session;
193 dev_t device;
194 int flags;
195 int count;
196 struct winsize winsize;
197 unsigned char stopped:1, hw_stopped:1, packet:1;
198 unsigned char ctrl_status;
199
200 struct tty_struct *link;
201 struct fasync_struct *fasync;
202 struct tty_flip_buffer flip;
203 int max_flip_cnt;
204 struct wait_queue *write_wait;
205 struct wait_queue *read_wait;
206 void *disc_data;
207 void *driver_data;
208
209 #define N_TTY_BUF_SIZE 4096
210
211
212
213
214
215 unsigned int column;
216 unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
217 unsigned short minimum_to_wake;
218 unsigned overrun_time;
219 int num_overrun;
220 int process_char_map[256/32];
221 char *read_buf;
222 int read_head;
223 int read_tail;
224 int read_cnt;
225 int read_flags[N_TTY_BUF_SIZE/32];
226 int canon_data;
227 unsigned long canon_head;
228 unsigned int canon_column;
229 };
230
231
232 #define TTY_MAGIC 0x5401
233
234
235
236
237
238
239
240
241
242 #define TTY_THROTTLED 0
243 #define TTY_IO_ERROR 1
244 #define TTY_SLAVE_CLOSED 2
245 #define TTY_EXCLUSIVE 3
246 #define TTY_DEBUG 4
247 #define TTY_DO_WRITE_WAKEUP 5
248
249 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
250
251 extern void tty_write_flush(struct tty_struct *);
252
253 extern struct termios tty_std_termios;
254 extern struct tty_struct * redirect;
255 extern struct tty_ldisc ldiscs[];
256 extern int fg_console;
257 extern unsigned long video_num_columns;
258 extern unsigned long video_num_lines;
259 extern struct wait_queue * keypress_wait;
260
261
262
263
264
265
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 pty_init(long);
273 extern long tty_init(long);
274
275 extern int tty_paranoia_check(struct tty_struct *tty, dev_t device,
276 const char *routine);
277 extern char *_tty_name(struct tty_struct *tty, char *buf);
278 extern char *tty_name(struct tty_struct *tty);
279 extern void wait_until_sent(struct tty_struct * tty, int timeout);
280 extern int tty_check_change(struct tty_struct * tty);
281 extern void stop_tty(struct tty_struct * tty);
282 extern void start_tty(struct tty_struct * tty);
283 extern int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc);
284 extern int tty_register_driver(struct tty_driver *driver);
285 extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp,
286 int buflen);
287
288 extern int is_orphaned_pgrp(int pgrp);
289 extern int is_ignored(int sig);
290 extern int tty_signal(int sig, struct tty_struct *tty);
291 extern void tty_hangup(struct tty_struct * tty);
292 extern void tty_vhangup(struct tty_struct * tty);
293 extern void tty_unhangup(struct file *filp);
294 extern int tty_hung_up_p(struct file * filp);
295 extern void do_SAK(struct tty_struct *tty);
296 extern void disassociate_ctty(int priv);
297
298
299 extern struct tty_ldisc tty_ldisc_N_TTY;
300
301
302 extern int n_tty_ioctl(struct tty_struct * tty, struct file * file,
303 unsigned int cmd, unsigned long arg);
304
305
306
307 extern int rs_open(struct tty_struct * tty, struct file * filp);
308
309
310
311 extern int pty_open(struct tty_struct * tty, struct file * filp);
312
313
314
315 extern int con_open(struct tty_struct * tty, struct file * filp);
316 extern void update_screen(int new_console);
317 extern void blank_screen(void);
318 extern void unblank_screen(void);
319
320
321
322 extern int vt_ioctl(struct tty_struct *tty, struct file * file,
323 unsigned int cmd, unsigned long arg);
324
325 #endif