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 int reserved[7];
82 };
83
84
85
86
87 #define PORT_UNKNOWN 0
88 #define PORT_8250 1
89 #define PORT_16450 2
90 #define PORT_16550 3
91 #define PORT_16550A 4
92 #define PORT_MAX 4
93
94
95
96
97 #define ASYNC_FOURPORT 0x0002
98 #define ASYNC_SAK 0x0004
99
100 #define ASYNC_SPD_MASK 0x0030
101 #define ASYNC_SPD_HI 0x0010
102 #define ASYNC_SPD_VHI 0x0020
103 #define ASYNC_SPD_CUST 0x0030
104
105 #define ASYNC_FLAGS 0x0036
106
107
108 #define ASYNC_INITIALIZED 0x80000000
109 #define ASYNC_CALLOUT_ACTIVE 0x40000000
110 #define ASYNC_NORMAL_ACTIVE 0x20000000
111
112 #define IS_A_CONSOLE(min) (((min) & 0xC0) == 0x00)
113 #define IS_A_SERIAL(min) (((min) & 0xC0) == 0x40)
114 #define IS_A_PTY(min) ((min) & 0x80)
115 #define IS_A_PTY_MASTER(min) (((min) & 0xC0) == 0x80)
116 #define IS_A_PTY_SLAVE(min) (((min) & 0xC0) == 0xC0)
117 #define PTY_OTHER(min) ((min) ^ 0x40)
118
119 #define SL_TO_DEV(line) ((line) | 0x40)
120 #define DEV_TO_SL(min) ((min) & 0x3F)
121
122 #define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))
123 #define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))
124 #define EMPTY(a) ((a)->head == (a)->tail)
125 #define LEFT(a) (((a)->tail-(a)->head-1)&(TTY_BUF_SIZE-1))
126 #define LAST(a) ((a)->buf[(TTY_BUF_SIZE-1)&((a)->head-1)])
127 #define FULL(a) (!LEFT(a))
128 #define CHARS(a) (((a)->head-(a)->tail)&(TTY_BUF_SIZE-1))
129
130 extern void put_tty_queue(char c, struct tty_queue * queue);
131 extern int get_tty_queue(struct tty_queue * queue);
132
133 #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
134 #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
135 #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
136 #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
137 #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
138 #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
139 #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
140 #define SUSPEND_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
141 #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT])
142
143 #define _L_FLAG(tty,f) ((tty)->termios->c_lflag & f)
144 #define _I_FLAG(tty,f) ((tty)->termios->c_iflag & f)
145 #define _O_FLAG(tty,f) ((tty)->termios->c_oflag & f)
146
147 #define L_CANON(tty) _L_FLAG((tty),ICANON)
148 #define L_ISIG(tty) _L_FLAG((tty),ISIG)
149 #define L_ECHO(tty) _L_FLAG((tty),ECHO)
150 #define L_ECHOE(tty) _L_FLAG((tty),ECHOE)
151 #define L_ECHOK(tty) _L_FLAG((tty),ECHOK)
152 #define L_ECHONL(tty) _L_FLAG((tty),ECHONL)
153 #define L_ECHOCTL(tty) _L_FLAG((tty),ECHOCTL)
154 #define L_ECHOKE(tty) _L_FLAG((tty),ECHOKE)
155 #define L_TOSTOP(tty) _L_FLAG((tty),TOSTOP)
156
157 #define I_UCLC(tty) _I_FLAG((tty),IUCLC)
158 #define I_NLCR(tty) _I_FLAG((tty),INLCR)
159 #define I_CRNL(tty) _I_FLAG((tty),ICRNL)
160 #define I_NOCR(tty) _I_FLAG((tty),IGNCR)
161 #define I_IXON(tty) _I_FLAG((tty),IXON)
162 #define I_IXANY(tty) _I_FLAG((tty),IXANY)
163 #define I_STRP(tty) _I_FLAG((tty),ISTRIP)
164
165 #define O_POST(tty) _O_FLAG((tty),OPOST)
166 #define O_NLCR(tty) _O_FLAG((tty),ONLCR)
167 #define O_CRNL(tty) _O_FLAG((tty),OCRNL)
168 #define O_NLRET(tty) _O_FLAG((tty),ONLRET)
169 #define O_LCUC(tty) _O_FLAG((tty),OLCUC)
170
171 #define C_SPEED(tty) ((tty)->termios->c_cflag & CBAUD)
172 #define C_HUP(tty) (C_SPEED((tty)) == B0)
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188 struct tty_struct {
189 struct termios *termios;
190 int pgrp;
191 int session;
192 unsigned char stopped:1, status_changed:1, packet:1, lnext:1;
193 unsigned char ctrl_status;
194 short line;
195 int disc;
196 int flags;
197 int count;
198 struct winsize winsize;
199 int (*open)(struct tty_struct * tty, struct file * filp);
200 void (*close)(struct tty_struct * tty, struct file * filp);
201 void (*write)(struct tty_struct * tty);
202 int (*ioctl)(struct tty_struct *tty, struct file * file,
203 unsigned int cmd, unsigned int arg);
204 void (*throttle)(struct tty_struct * tty, int status);
205 void (*set_termios)(struct tty_struct *tty, struct termios * old);
206 struct tty_struct *link;
207 unsigned char *write_data_ptr;
208 int write_data_cnt;
209 void (*write_data_callback)(void * data);
210 void * write_data_arg;
211 struct tty_queue read_q;
212 struct tty_queue write_q;
213 struct tty_queue secondary;
214 };
215
216 struct tty_ldisc {
217 int flags;
218
219
220
221 int (*open)(struct tty_struct *);
222 void (*close)(struct tty_struct *);
223 int (*read)(struct tty_struct * tty, struct file * file,
224 char * buf, int nr);
225 int (*write)(struct tty_struct * tty, struct file * file,
226 char * buf, int nr);
227 int (*ioctl)(struct tty_struct * tty, struct file * file,
228 unsigned int cmd, unsigned int arg);
229
230
231
232 void (*handler)(struct tty_struct *);
233 };
234
235 #define LDISC_FLAG_DEFINED 0x00000001
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253 #define TTY_THROTTLE_SQ_FULL 1
254 #define TTY_THROTTLE_SQ_AVAIL 2
255 #define TTY_THROTTLE_RQ_FULL 3
256 #define TTY_THROTTLE_RQ_AVAIL 4
257
258
259
260
261
262
263 #define SQ_THRESHOLD_LW 16
264 #define SQ_THRESHOLD_HW 768
265 #define RQ_THRESHOLD_LW 16
266 #define RQ_THRESHOLD_HW 768
267
268
269
270
271
272
273
274
275
276 #define TTY_WRITE_BUSY 0
277 #define TTY_READ_BUSY 1
278 #define TTY_CR_PENDING 2
279 #define TTY_SQ_THROTTLED 3
280 #define TTY_RQ_THROTTLED 4
281 #define TTY_IO_ERROR 5
282
283 #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
284 #define TTY_READ_FLUSH(tty) tty_read_flush((tty))
285
286 extern void tty_write_flush(struct tty_struct *);
287 extern void tty_read_flush(struct tty_struct *);
288
289 extern struct tty_struct *tty_table[];
290 extern int tty_check_write[];
291 extern struct tty_struct * redirect;
292 extern struct tty_ldisc ldiscs[];
293 extern int fg_console;
294 extern unsigned long video_num_columns;
295 extern unsigned long video_num_lines;
296 extern struct wait_queue * keypress_wait;
297
298 #define TTY_TABLE_IDX(nr) ((nr) ? (nr) : (fg_console+1))
299 #define TTY_TABLE(nr) (tty_table[TTY_TABLE_IDX(nr)])
300
301
302
303
304
305
306
307 #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
308
309 extern long rs_init(long);
310 extern long lp_init(long);
311 extern long con_init(long);
312 extern long tty_init(long);
313
314 extern void flush_input(struct tty_struct * tty);
315 extern void flush_output(struct tty_struct * tty);
316 extern void wait_until_sent(struct tty_struct * tty);
317 extern void copy_to_cooked(struct tty_struct * tty);
318 extern int tty_register_ldisc(int disc, struct tty_ldisc *new);
319
320 extern int tty_ioctl(struct inode *, struct file *, unsigned int, unsigned int);
321 extern int is_orphaned_pgrp(int pgrp);
322 extern int is_ignored(int sig);
323 extern int tty_signal(int sig, struct tty_struct *tty);
324 extern int kill_pg(int pgrp, int sig, int priv);
325 extern int kill_sl(int sess, int sig, int priv);
326 extern void tty_hangup(struct tty_struct * tty);
327 extern void tty_unhangup(struct file *filp);
328 extern void do_SAK(struct tty_struct *tty);
329
330
331
332 extern void rs_write(struct tty_struct * tty);
333 extern void con_write(struct tty_struct * tty);
334
335
336
337 extern int rs_open(struct tty_struct * tty, struct file * filp);
338
339
340
341 extern int pty_open(struct tty_struct * tty, struct file * filp);
342
343
344
345 extern int con_open(struct tty_struct * tty, struct file * filp);
346 extern void update_screen(int new_console);
347 extern void blank_screen(void);
348 extern void unblank_screen(void);
349
350
351
352 extern int vt_ioctl(struct tty_struct *tty, struct file * file,
353 unsigned int cmd, unsigned int arg);
354
355 #endif