xref: /minix/minix/drivers/tty/tty/tty.h (revision d2532d3d)
1 /*	tty.h - Terminals	*/
2 
3 #include <minix/chardriver.h>
4 #include <minix/timers.h>
5 
6 /* First minor numbers for the various classes of TTY devices. */
7 /* CONS_MINOR is defined in minix/dmap.h */
8 #define LOG_MINOR	  15
9 #define RS232_MINOR	  16
10 #define VIDEO_MINOR	 125
11 
12 #define CONS_ARG	  30	/* console= boot param length (incl. nul) */
13 #define LINEWRAP	   1	/* console.c - wrap lines at column 80 */
14 
15 #define TTY_IN_BYTES     256	/* tty input queue size */
16 #define TAB_SIZE           8	/* distance between tab stops */
17 #define TAB_MASK           7	/* mask to compute a tab stop position */
18 
19 #define ESC             '\33'	/* escape */
20 
21 struct tty;
22 typedef int(*devfun_t) (struct tty *tp, int try_only);
23 typedef void(*devfunarg_t) (struct tty *tp, int c);
24 
25 typedef struct tty {
26   int tty_events;		/* set when TTY should inspect this line */
27   int tty_index;		/* index into TTY table */
28   devminor_t tty_minor;		/* device minor number */
29 
30   /* Input queue.  Typed characters are stored here until read by a program. */
31   u16_t *tty_inhead;		/* pointer to place where next char goes */
32   u16_t *tty_intail;		/* pointer to next char to be given to prog */
33   int tty_incount;		/* # chars in the input queue */
34   int tty_eotct;		/* number of "line breaks" in input queue */
35   devfun_t tty_devread;		/* routine to read from low level buffers */
36   devfun_t tty_icancel;		/* cancel any device input */
37   int tty_min;			/* minimum requested #chars in input queue */
38   minix_timer_t tty_tmr;		/* the timer for this tty */
39 
40   /* Output section. */
41   devfun_t tty_devwrite;	/* routine to start actual device output */
42   devfunarg_t tty_echo;		/* routine to echo characters input */
43   devfun_t tty_ocancel;		/* cancel any ongoing device output */
44   devfun_t tty_break_on;	/* let the device assert a break */
45   devfun_t tty_break_off;	/* let the device de-assert a break */
46 
47   /* Terminal parameters and status. */
48   int tty_position;		/* current position on the screen for echoing */
49   char tty_reprint;		/* 1 when echoed input messed up, else 0 */
50   char tty_escaped;		/* 1 when LNEXT (^V) just seen, else 0 */
51   char tty_inhibited;		/* 1 when STOP (^S) just seen (stops output) */
52   endpoint_t tty_pgrp;		/* endpoint of controlling process */
53   char tty_openct;		/* count of number of opens of this tty */
54 
55   /* Information about incomplete I/O requests is stored here. */
56   endpoint_t tty_incaller;	/* process that made the call, or NONE */
57   cdev_id_t tty_inid;		/* ID of suspended read request */
58   cp_grant_id_t tty_ingrant;	/* grant where data is to go */
59   size_t tty_inleft;		/* how many chars are still needed */
60   size_t tty_incum;		/* # chars input so far */
61   endpoint_t tty_outcaller;	/* process that made the call, or NONE */
62   cdev_id_t tty_outid;		/* ID of suspended write request */
63   cp_grant_id_t tty_outgrant;	/* grant where data comes from */
64   size_t tty_outleft;		/* # chars yet to be output */
65   size_t tty_outcum;		/* # chars output so far */
66   endpoint_t tty_iocaller;	/* process that made the call, or NONE */
67   cdev_id_t tty_ioid;		/* ID of suspended ioctl request */
68   unsigned int tty_ioreq;	/* ioctl request code */
69   cp_grant_id_t tty_iogrant;	/* virtual address of ioctl buffer or grant */
70 
71   /* select() data */
72   unsigned int tty_select_ops;	/* which operations are interesting */
73   endpoint_t tty_select_proc;	/* which process wants notification */
74   devminor_t tty_select_minor;	/* minor used to start select query */
75 
76   /* Miscellaneous. */
77   devfun_t tty_ioctl;		/* set line speed, etc. at the device level */
78   devfun_t tty_open;		/* tell the device that the tty is opened */
79   devfun_t tty_close;		/* tell the device that the tty is closed */
80   void *tty_priv;		/* pointer to per device private data */
81   struct termios tty_termios;	/* terminal attributes */
82   struct winsize tty_winsize;	/* window size (#lines and #columns) */
83 
84   u16_t tty_inbuf[TTY_IN_BYTES];/* tty input buffer */
85 
86 } tty_t;
87 
88 /* Memory allocated in tty.c, so extern here. */
89 extern tty_t tty_table[NR_CONS+NR_RS_LINES];
90 extern int ccurrent;		/* currently visible console */
91 extern u32_t system_hz;		/* system clock frequency */
92 
93 extern unsigned long kbd_irq_set;
94 extern unsigned long rs_irq_set;
95 
96 /* Values for the fields. */
97 #define NOT_ESCAPED        0	/* previous character is not LNEXT (^V) */
98 #define ESCAPED            1	/* previous character was LNEXT (^V) */
99 #define RUNNING            0	/* no STOP (^S) has been typed to stop output */
100 #define STOPPED            1	/* STOP (^S) has been typed to stop output */
101 
102 /* Fields and flags on characters in the input queue. */
103 #define IN_CHAR       0x00FF	/* low 8 bits are the character itself */
104 #define IN_LEN        0x0F00	/* length of char if it has been echoed */
105 #define IN_LSHIFT          8	/* length = (c & IN_LEN) >> IN_LSHIFT */
106 #define IN_EOT        0x1000	/* char is a line break (^D, LF) */
107 #define IN_EOF        0x2000	/* char is EOF (^D), do not return to user */
108 #define IN_ESC        0x4000	/* escaped by LNEXT (^V), no interpretation */
109 
110 /* Times and timeouts. */
111 #define force_timeout()	((void) (0))
112 
113 /* Number of elements and limit of a buffer. */
114 #define buflen(buf)	(sizeof(buf) / sizeof((buf)[0]))
115 #define bufend(buf)	((buf) + buflen(buf))
116 
117 /* Memory allocated in tty.c, so extern here. */
118 extern struct machine machine;	/* machine information (a.o.: pc_at, ega) */
119 
120 /* The tty outputs diagnostic messages in a circular buffer. */
121 extern struct kmessages kmess;
122 
123 /* Function prototypes for TTY driver. */
124 /* tty.c */
125 void handle_events(struct tty *tp);
126 void sigchar(struct tty *tp, int sig, int mayflush);
127 void tty_task(void);
128 tty_t *line2tty(devminor_t minor);
129 int in_process(struct tty *tp, char *buf, int count);
130 void out_process(struct tty *tp, char *bstart, char *bpos, char *bend,
131 	int *icount, int *ocount);
132 void tty_wakeup(clock_t now);
133 int select_try(struct tty *tp, int ops);
134 int select_retry(struct tty *tp);
135 
136 /* rs232.c */
137 void rs_init(struct tty *tp);
138 void rs_interrupt(message *m);
139 
140 /* console.c */
141 void kputc(int c);
142 void cons_stop(void);
143 void scr_init(struct tty *tp);
144 void toggle_scroll(void);
145 int con_loadfont(endpoint_t endpt, cp_grant_id_t grant);
146 void select_console(int cons_line);
147 void beep_x( unsigned freq, clock_t dur);
148 void do_video(message *m, int ipc_status);
149 
150 /* keyboard.c */
151 void kb_init(struct tty *tp);
152 void kb_init_once(void);
153 int kbd_loadmap(endpoint_t endpt, cp_grant_id_t grant);
154 void do_fkey_ctl(message *m);
155 void do_input(message *m);
156