1 #ifndef _LINUX_TTY_H
2 #define _LINUX_TTY_H
3
4
5
6
7
8 #include <linux/termios.h>
9
10 #include <asm/system.h>
11
12 #define NR_CONSOLES 8
13 #define NR_LDISCS 16
14
15
16
17
18
19 struct screen_info {
20 unsigned char orig_x;
21 unsigned char orig_y;
22 unsigned char unused1[2];
23 unsigned short orig_video_page;
24 unsigned char orig_video_mode;
25 unsigned char orig_video_cols;
26 unsigned short orig_video_ega_ax;
27 unsigned short orig_video_ega_bx;
28 unsigned short orig_video_ega_cx;
29 unsigned char orig_video_lines;
30 };
31
32 extern struct screen_info screen_info;
33
34 #define ORIG_X (screen_info.orig_x)
35 #define ORIG_Y (screen_info.orig_y)
36 #define ORIG_VIDEO_PAGE (screen_info.orig_video_page)
37 #define ORIG_VIDEO_MODE (screen_info.orig_video_mode)
38 #define ORIG_VIDEO_COLS (screen_info.orig_video_cols)
39 #define ORIG_VIDEO_EGA_AX (screen_info.orig_video_ega_ax)
40 #define ORIG_VIDEO_EGA_BX (screen_info.orig_video_ega_bx)
41 #define ORIG_VIDEO_EGA_CX (screen_info.orig_video_ega_cx)
42 #define ORIG_VIDEO_LINES (screen_info.orig_video_lines)
43
44 #define VIDEO_TYPE_MDA 0x10
45 #define VIDEO_TYPE_CGA 0x11
46 #define VIDEO_TYPE_EGAM 0x20
47 #define VIDEO_TYPE_EGAC 0x21
48
49
50
51
52
53
54 #define __DISABLED_CHAR '\0'
55
56
57
58
59
60
61
62 #define TTY_BUF_SIZE 1024
63
64 struct tty_queue {
65 unsigned long data;
66 unsigned long head;
67 unsigned long tail;
68 struct wait_queue * proc_list;
69 unsigned char buf[TTY_BUF_SIZE];
70 };
71
72 struct serial_struct {
73 int type;
74 int line;
75 int port;
76 int irq;
77 int flags;
78 int xmit_fifo_size;
79 int custom_divisor;
80 int baud_base;
81 char close_delay;
82 char reserved_char[3];
83 int hub6;
84 int reserved[5];
85 };
86
87
88
89
90 #define PORT_UNKNOWN 0
91 #define PORT_8250 1
92 #define PORT_16450 2
93 #define PORT_16550 3
94 #define PORT_16550A 4
95 #define PORT_MAX 4
96
97
98
99
100 #define ASYNC_FOURPORT 0x0002
101 #define ASYNC_SAK 0x0004
102 #define ASYNC_SPLIT_TERMIOS 0x0008
103
104 #define ASYNC_SPD_MASK 0x0030
105 #define ASYNC_SPD_HI 0x0010
106 #define ASYNC_SPD_VHI 0x0020
107 #define ASYNC_SPD_CUST 0x0030
108
109 #define ASYNC_SKIP_TEST 0x0040
110 #define ASYNC_AUTO_IRQ 0x0080
111 #define ASYNC_SESSION_LOCKOUT 0x0100
112 #define ASYNC_PGRP_LOCKOUT 0x0200
113 #define ASYNC_CALLOUT_NOHUP 0x0400
114
115 #define ASYNC_FLAGS 0x0FFF
116 #define ASYNC_USR_MASK 0x0430
117
118
119
120 #define ASYNC_INITIALIZED 0x80000000
121 #define ASYNC_CALLOUT_ACTIVE 0x40000000
122 #define ASYNC_NORMAL_ACTIVE 0x20000000
123 #define ASYNC_BOOT_AUTOCONF 0x10000000
124 #define ASYNC_CLOSING 0x08000000
125
126 #define IS_A_CONSOLE(min) (((min) & 0xC0) == 0x00)
127 #define IS_A_SERIAL(min) (((min) & 0xC0) == 0x40)
128 #define IS_A_PTY(min) ((min) & 0x80)
129 #define IS_A_PTY_MASTER(min) (((min) & 0xC0) == 0x80)
130 #define IS_A_PTY_SLAVE(min) (((min) & 0xC0) == 0xC0)
131 #define PTY_OTHER(min) ((min) ^ 0x40)
132
133 #define SL_TO_DEV(line) ((line) | 0x40)
134 #define DEV_TO_SL(min) ((min) & 0x3F)
135
136 #define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))
137 #define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))
138 #define EMPTY(a) ((a)->head == (a)->tail)
139 #define LEFT(a) (((a)->tail-(a)->head-1)&(TTY_BUF_SIZE-1))
140 #define LAST(a) ((a)->buf[(TTY_BUF_SIZE-1)&((a)->head-1)])
141 #define FULL(a) (!LEFT(a))
142 #define CHARS(a) (((a)->head-(a)->tail)&(TTY_BUF_SIZE-1))
143
144 extern void put_tty_queue(char c, struct tty_queue * queue);
145 extern int get_tty_queue(struct tty_queue * queue);
146
147 #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
148 #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
149 #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
150 #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
151 #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE])
152 #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
153 #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
154 #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
155 #define SUSPEND_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
156 #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT])
157
158 #define _L_FLAG(tty,f) ((tty)->termios->c_lflag & f)
159 #define _I_FLAG(tty,f) ((tty)->termios->c_iflag & f)
160 #define _O_FLAG(tty,f) ((tty)->termios->c_oflag & f)
161 #define _C_FLAG(tty,f) ((tty)->termios->c_cflag & f)
162
163 #define L_CANON(tty) _L_FLAG((tty),ICANON)
164 #define L_ISIG(tty) _L_FLAG((tty),ISIG)
165 #define L_ECHO(tty) _L_FLAG((tty),ECHO)
166 #define L_ECHOE(tty) _L_FLAG((tty),ECHOE)
167 #define L_ECHOK(tty) _L_FLAG((tty),ECHOK)
168 #define L_ECHONL(tty) _L_FLAG((tty),ECHONL)
169 #define L_ECHOCTL(tty) _L_FLAG((tty),ECHOCTL)
170 #define L_ECHOKE(tty) _L_FLAG((tty),ECHOKE)
171 #define L_TOSTOP(tty) _L_FLAG((tty),TOSTOP)
172
173 #define I_IGNBRK(tty) _I_FLAG((tty),IGNBRK)
174 #define I_BRKINT(tty) _I_FLAG((tty),BRKINT)
175 #define I_IGNPAR(tty) _I_FLAG((tty),IGNPAR)
176 #define I_PARMRK(tty) _I_FLAG((tty),PARMRK)
177 #define I_INPCK(tty) _I_FLAG((tty),INPCK)
178 #define I_UCLC(tty) _I_FLAG((tty),IUCLC)
179 #define I_NLCR(tty) _I_FLAG((tty),INLCR)
180 #define I_CRNL(tty) _I_FLAG((tty),ICRNL)
181 #define I_NOCR(tty) _I_FLAG((tty),IGNCR)
182 #define I_IXON(tty) _I_FLAG((tty),IXON)
183 #define I_IXANY(tty) _I_FLAG((tty),IXANY)
184 #define I_STRP(tty) _I_FLAG((tty),ISTRIP)
185
186 #define O_POST(tty) _O_FLAG((tty),OPOST)
187 #define O_LCUC(tty) _O_FLAG((tty),OLCUC)
188 #define O_NLCR(tty) _O_FLAG((tty),ONLCR)
189 #define O_CRNL(tty) _O_FLAG((tty),OCRNL)
190 #define O_NOCR(tty) _O_FLAG((tty),ONOCR)
191 #define O_NLRET(tty) _O_FLAG((tty),ONLRET)
192 #define O_TABDLY(tty) _O_FLAG((tty),TABDLY)
193
194 #define C_LOCAL(tty) _C_FLAG((tty),CLOCAL)
195 #define C_RTSCTS(tty) _C_FLAG((tty),CRTSCTS)
196 #define C_SPEED(tty) ((tty)->termios->c_cflag & CBAUD)
197 #define C_HUP(tty) (C_SPEED((tty)) == B0)
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213 struct tty_struct {
214 struct termios *termios;
215 int pgrp;
216 int session;
217 unsigned char stopped:1, hw_stopped:1, packet:1, lnext:1;
218 unsigned char char_error:3;
219 unsigned char ctrl_status;
220 short line;
221 int disc;
222 int flags;
223 int count;
224 int column;
225 struct winsize winsize;
226 int (*open)(struct tty_struct * tty, struct file * filp);
227 void (*close)(struct tty_struct * tty, struct file * filp);
228 void (*write)(struct tty_struct * tty);
229 int (*ioctl)(struct tty_struct *tty, struct file * file,
230 unsigned int cmd, unsigned long arg);
231 void (*throttle)(struct tty_struct * tty, int status);
232 void (*set_termios)(struct tty_struct *tty, struct termios * old);
233 void (*stop)(struct tty_struct *tty);
234 void (*start)(struct tty_struct *tty);
235 void (*hangup)(struct tty_struct *tty);
236 struct tty_struct *link;
237 unsigned char *write_data_ptr;
238 int write_data_cnt;
239 void (*write_data_callback)(void * data);
240 void * write_data_arg;
241 int readq_flags[TTY_BUF_SIZE/32];
242 struct tty_queue read_q;
243 struct tty_queue write_q;
244 struct tty_queue secondary;
245 struct wait_queue * except_q;
246 void *disc_data;
247 };
248
249 struct tty_ldisc {
250 int flags;
251
252
253
254 int (*open)(struct tty_struct *);
255 void (*close)(struct tty_struct *);
256 int (*read)(struct tty_struct * tty, struct file * file,
257 char * buf, int nr);
258 int (*write)(struct tty_struct * tty, struct file * file,
259 char * buf, int nr);
260 int (*ioctl)(struct tty_struct * tty, struct file * file,
261 unsigned int cmd, unsigned long arg);
262
263
264
265 void (*handler)(struct tty_struct *);
266 };
267
268 #define LDISC_FLAG_DEFINED 0x00000001
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286 #define TTY_THROTTLE_SQ_FULL 1
287 #define TTY_THROTTLE_SQ_AVAIL 2
288 #define TTY_THROTTLE_RQ_FULL 3
289 #define TTY_THROTTLE_RQ_AVAIL 4
290
291
292
293
294
295
296 #define SQ_THRESHOLD_LW 16
297 #define SQ_THRESHOLD_HW 768
298 #define RQ_THRESHOLD_LW 16
299 #define RQ_THRESHOLD_HW 768
300
301
302
303
304
305
306
307
308
309 #define TTY_WRITE_BUSY 0
310 #define TTY_READ_BUSY 1
311 #define TTY_CR_PENDING 2
312 #define TTY_SQ_THROTTLED 3
313 #define TTY_RQ_THROTTLED 4
314 #define TTY_IO_ERROR 5
315 #define TTY_SLAVE_OPENED 6
316 #define TTY_EXCLUSIVE 7
317
318
319
320
321
322
323 #define TTY_BREAK 1
324 #define TTY_FRAME 2
325 #define TTY_PARITY 3
326 #define TTY_OVERRUN 4
327
328 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
329 #define TTY_READ_FLUSH(tty) tty_read_flush((tty))
330
331 extern void tty_write_flush(struct tty_struct *);
332 extern void tty_read_flush(struct tty_struct *);
333
334 extern struct tty_struct *tty_table[];
335 extern struct termios *tty_termios[];
336 extern struct termios *termios_locked[];
337 extern int tty_check_write[];
338 extern struct tty_struct * redirect;
339 extern struct tty_ldisc ldiscs[];
340 extern int fg_console;
341 extern unsigned long video_num_columns;
342 extern unsigned long video_num_lines;
343 extern struct wait_queue * keypress_wait;
344
345 #define TTY_TABLE_IDX(nr) ((nr) ? (nr) : (fg_console+1))
346 #define TTY_TABLE(nr) (tty_table[TTY_TABLE_IDX(nr)])
347
348
349
350
351
352
353
354 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
355
356 extern long rs_init(long);
357 extern long lp_init(long);
358 extern long con_init(long);
359 extern long tty_init(long);
360
361 extern void flush_input(struct tty_struct * tty);
362 extern void flush_output(struct tty_struct * tty);
363 extern void wait_until_sent(struct tty_struct * tty);
364 extern void copy_to_cooked(struct tty_struct * tty);
365 extern int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc);
366 extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp,
367 int buflen);
368 extern int tty_write_data(struct tty_struct *tty, char *bufp, int buflen,
369 void (*callback)(void * data), void * callarg);
370
371 extern int tty_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
372 extern int is_orphaned_pgrp(int pgrp);
373 extern int is_ignored(int sig);
374 extern int tty_signal(int sig, struct tty_struct *tty);
375 extern void tty_hangup(struct tty_struct * tty);
376 extern void tty_vhangup(struct tty_struct * tty);
377 extern void tty_unhangup(struct file *filp);
378 extern int tty_hung_up_p(struct file * filp);
379 extern void do_SAK(struct tty_struct *tty);
380 extern void disassociate_ctty(int priv);
381
382
383
384 extern void rs_write(struct tty_struct * tty);
385 extern void con_write(struct tty_struct * tty);
386
387
388
389 extern int rs_open(struct tty_struct * tty, struct file * filp);
390
391
392
393 extern int pty_open(struct tty_struct * tty, struct file * filp);
394
395
396
397 extern int con_open(struct tty_struct * tty, struct file * filp);
398 extern void update_screen(int new_console);
399 extern void blank_screen(void);
400 extern void unblank_screen(void);
401
402
403
404 extern int vt_ioctl(struct tty_struct *tty, struct file * file,
405 unsigned int cmd, unsigned long arg);
406
407 #endif