kernel: scheduling fix for ARM
[minix.git] / drivers / tty / tty.h
blob9bf4147de447dcd60e03528c0f19cc847327a1e4
1 /* tty.h - Terminals */
3 #include <timers.h>
5 #undef lock
6 #undef unlock
8 #define TTY_REVIVE 6767
10 /* First minor numbers for the various classes of TTY devices. */
11 #define CONS_MINOR 0
12 #define LOG_MINOR 15
13 #define RS232_MINOR 16
14 #define KBD_MINOR 127
15 #define KBDAUX_MINOR 126
16 #define VIDEO_MINOR 125
17 #define TTYPX_MINOR 128
18 #define PTYPX_MINOR 192
20 #define CONS_ARG 30 /* console= boot param length (incl. nul) */
21 #define LINEWRAP 1 /* console.c - wrap lines at column 80 */
23 #define TTY_IN_BYTES 256 /* tty input queue size */
24 #define TAB_SIZE 8 /* distance between tab stops */
25 #define TAB_MASK 7 /* mask to compute a tab stop position */
27 #define ESC '\33' /* escape */
29 #define O_NOCTTY 00400 /* from <fcntl.h>, or cc will choke */
30 #define O_NONBLOCK 04000
32 struct tty;
33 typedef int(*devfun_t) (struct tty *tp, int try_only);
34 typedef void(*devfunarg_t) (struct tty *tp, int c);
36 typedef struct tty {
37 int tty_events; /* set when TTY should inspect this line */
38 int tty_index; /* index into TTY table */
39 int tty_minor; /* device minor number */
41 /* Input queue. Typed characters are stored here until read by a program. */
42 u16_t *tty_inhead; /* pointer to place where next char goes */
43 u16_t *tty_intail; /* pointer to next char to be given to prog */
44 int tty_incount; /* # chars in the input queue */
45 int tty_eotct; /* number of "line breaks" in input queue */
46 devfun_t tty_devread; /* routine to read from low level buffers */
47 devfun_t tty_icancel; /* cancel any device input */
48 int tty_min; /* minimum requested #chars in input queue */
49 timer_t tty_tmr; /* the timer for this tty */
51 /* Output section. */
52 devfun_t tty_devwrite; /* routine to start actual device output */
53 devfunarg_t tty_echo; /* routine to echo characters input */
54 devfun_t tty_ocancel; /* cancel any ongoing device output */
55 devfun_t tty_break; /* let the device send a break */
57 /* Terminal parameters and status. */
58 int tty_position; /* current position on the screen for echoing */
59 char tty_reprint; /* 1 when echoed input messed up, else 0 */
60 char tty_escaped; /* 1 when LNEXT (^V) just seen, else 0 */
61 char tty_inhibited; /* 1 when STOP (^S) just seen (stops output) */
62 endpoint_t tty_pgrp; /* endpoint of controlling process */
63 char tty_openct; /* count of number of opens of this tty */
65 /* Information about incomplete I/O requests is stored here. */
66 int tty_inrepcode; /* reply code, TASK_REPLY or REVIVE */
67 char tty_inrevived; /* set to 1 if revive callback is pending */
68 endpoint_t tty_incaller; /* process that made the call (usually VFS) */
69 endpoint_t tty_inproc; /* process that wants to read from tty */
70 cp_grant_id_t tty_ingrant; /* grant where data is to go */
71 vir_bytes tty_inoffset; /* offset into grant */
72 int tty_inleft; /* how many chars are still needed */
73 int tty_incum; /* # chars input so far */
74 int tty_outrepcode; /* reply code, TASK_REPLY or REVIVE */
75 int tty_outrevived; /* set to 1 if revive callback is pending */
76 endpoint_t tty_outcaller; /* process that made the call (usually VFS) */
77 endpoint_t tty_outproc; /* process that wants to write to tty */
78 cp_grant_id_t tty_outgrant; /* grant where data comes from */
79 vir_bytes tty_outoffset; /* offset into grant */
80 int tty_outleft; /* # chars yet to be output */
81 int tty_outcum; /* # chars output so far */
82 endpoint_t tty_iocaller; /* process that made the call (usually VFS) */
83 int tty_iorevived; /* set to 1 if revive callback is pending */
84 endpoint_t tty_ioproc; /* process that wants to do an ioctl */
85 int tty_iostatus; /* result */
86 int tty_ioreq; /* ioctl request code */
87 cp_grant_id_t tty_iogrant; /* virtual address of ioctl buffer or grant */
89 /* select() data */
90 int tty_select_ops; /* which operations are interesting */
91 endpoint_t tty_select_proc; /* which process wants notification */
93 /* Miscellaneous. */
94 devfun_t tty_ioctl; /* set line speed, etc. at the device level */
95 devfun_t tty_open; /* tell the device that the tty is opened */
96 devfun_t tty_close; /* tell the device that the tty is closed */
97 void *tty_priv; /* pointer to per device private data */
98 struct termios tty_termios; /* terminal attributes */
99 struct winsize tty_winsize; /* window size (#lines and #columns) */
101 u16_t tty_inbuf[TTY_IN_BYTES];/* tty input buffer */
103 } tty_t;
105 /* Memory allocated in tty.c, so extern here. */
106 extern tty_t tty_table[NR_CONS+NR_RS_LINES+NR_PTYS];
107 extern int ccurrent; /* currently visible console */
108 extern u32_t system_hz; /* system clock frequency */
110 extern unsigned long kbd_irq_set;
111 extern unsigned long rs_irq_set;
113 /* Values for the fields. */
114 #define NOT_ESCAPED 0 /* previous character is not LNEXT (^V) */
115 #define ESCAPED 1 /* previous character was LNEXT (^V) */
116 #define RUNNING 0 /* no STOP (^S) has been typed to stop output */
117 #define STOPPED 1 /* STOP (^S) has been typed to stop output */
119 /* Fields and flags on characters in the input queue. */
120 #define IN_CHAR 0x00FF /* low 8 bits are the character itself */
121 #define IN_LEN 0x0F00 /* length of char if it has been echoed */
122 #define IN_LSHIFT 8 /* length = (c & IN_LEN) >> IN_LSHIFT */
123 #define IN_EOT 0x1000 /* char is a line break (^D, LF) */
124 #define IN_EOF 0x2000 /* char is EOF (^D), do not return to user */
125 #define IN_ESC 0x4000 /* escaped by LNEXT (^V), no interpretation */
127 /* Times and timeouts. */
128 #define force_timeout() ((void) (0))
130 /* Number of elements and limit of a buffer. */
131 #define buflen(buf) (sizeof(buf) / sizeof((buf)[0]))
132 #define bufend(buf) ((buf) + buflen(buf))
134 /* Memory allocated in tty.c, so extern here. */
135 extern struct machine machine; /* machine information (a.o.: pc_at, ega) */
137 /* The tty outputs diagnostic messages in a circular buffer. */
138 extern struct kmessages kmess;
140 /* Function prototypes for TTY driver. */
141 /* tty.c */
142 void handle_events(struct tty *tp);
143 void sigchar(struct tty *tp, int sig, int mayflush);
144 void tty_task(void);
145 int in_process(struct tty *tp, char *buf, int count, int scode);
146 void out_process(struct tty *tp, char *bstart, char *bpos, char *bend,
147 int *icount, int *ocount);
148 void tty_wakeup(clock_t now);
149 #define tty_reply(c, r, p, s) tty_reply_f(__FILE__, __LINE__, (c), (r), (p), (s))
150 void tty_reply_f(char *f, int l, int code, int replyee, int proc_nr, int
151 status);
152 int select_try(struct tty *tp, int ops);
153 int select_retry(struct tty *tp);
155 /* rs232.c */
156 void rs_init(struct tty *tp);
157 void rs_interrupt(message *m);
159 /* console.c */
160 void kputc(int c);
161 void cons_stop(void);
162 void scr_init(struct tty *tp);
163 void toggle_scroll(void);
164 int con_loadfont(message *m);
165 void select_console(int cons_line);
166 void beep_x( unsigned freq, clock_t dur);
167 void do_video(message *m);
169 /* keyboard.c */
170 void kb_init(struct tty *tp);
171 void kb_init_once(void);
172 int kbd_loadmap(message *m);
173 void do_fkey_ctl(message *m);
174 void kbd_interrupt(message *m);
175 void do_kbd(message *m);
176 void do_kb_inject(message *m);
177 void do_kbdaux(message *m);
178 int kbd_status(message *m_ptr);
180 /* pty.c */
181 void do_pty(struct tty *tp, message *m_ptr);
182 void pty_init(struct tty *tp);
183 void select_retry_pty(struct tty *tp);
184 int pty_status(message *m_ptr);