Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_TTY_DRIVER_H |
2 | #define _LINUX_TTY_DRIVER_H | |
3 | ||
4 | /* | |
5 | * This structure defines the interface between the low-level tty | |
6 | * driver and the tty routines. The following routines can be | |
7 | * defined; unless noted otherwise, they are optional, and can be | |
8 | * filled in with a null pointer. | |
9 | * | |
10 | * int (*open)(struct tty_struct * tty, struct file * filp); | |
11 | * | |
12 | * This routine is called when a particular tty device is opened. | |
13 | * This routine is mandatory; if this routine is not filled in, | |
14 | * the attempted open will fail with ENODEV. | |
f34d7a5b AC |
15 | * |
16 | * Required method. | |
1da177e4 LT |
17 | * |
18 | * void (*close)(struct tty_struct * tty, struct file * filp); | |
19 | * | |
20 | * This routine is called when a particular tty device is closed. | |
21 | * | |
f34d7a5b AC |
22 | * Required method. |
23 | * | |
1da177e4 LT |
24 | * int (*write)(struct tty_struct * tty, |
25 | * const unsigned char *buf, int count); | |
26 | * | |
27 | * This routine is called by the kernel to write a series of | |
28 | * characters to the tty device. The characters may come from | |
29 | * user space or kernel space. This routine will return the | |
30 | * number of characters actually accepted for writing. This | |
31 | * routine is mandatory. | |
32 | * | |
f34d7a5b AC |
33 | * Optional: Required for writable devices. |
34 | * | |
35 | * int (*put_char)(struct tty_struct *tty, unsigned char ch); | |
1da177e4 LT |
36 | * |
37 | * This routine is called by the kernel to write a single | |
38 | * character to the tty device. If the kernel uses this routine, | |
39 | * it must call the flush_chars() routine (if defined) when it is | |
40 | * done stuffing characters into the driver. If there is no room | |
41 | * in the queue, the character is ignored. | |
42 | * | |
f34d7a5b AC |
43 | * Optional: Kernel will use the write method if not provided. |
44 | * | |
45 | * Note: Do not call this function directly, call tty_put_char | |
46 | * | |
1da177e4 LT |
47 | * void (*flush_chars)(struct tty_struct *tty); |
48 | * | |
49 | * This routine is called by the kernel after it has written a | |
50 | * series of characters to the tty device using put_char(). | |
f34d7a5b AC |
51 | * |
52 | * Optional: | |
53 | * | |
54 | * Note: Do not call this function directly, call tty_driver_flush_chars | |
1da177e4 LT |
55 | * |
56 | * int (*write_room)(struct tty_struct *tty); | |
57 | * | |
58 | * This routine returns the numbers of characters the tty driver | |
59 | * will accept for queuing to be written. This number is subject | |
60 | * to change as output buffers get emptied, or if the output flow | |
61 | * control is acted. | |
f34d7a5b AC |
62 | * |
63 | * Required if write method is provided else not needed. | |
64 | * | |
65 | * Note: Do not call this function directly, call tty_write_room | |
1da177e4 LT |
66 | * |
67 | * int (*ioctl)(struct tty_struct *tty, struct file * file, | |
68 | * unsigned int cmd, unsigned long arg); | |
69 | * | |
70 | * This routine allows the tty driver to implement | |
71 | * device-specific ioctl's. If the ioctl number passed in cmd | |
72 | * is not recognized by the driver, it should return ENOIOCTLCMD. | |
e10cc1df | 73 | * |
f34d7a5b AC |
74 | * Optional |
75 | * | |
e10cc1df PF |
76 | * long (*compat_ioctl)(struct tty_struct *tty, struct file * file, |
77 | * unsigned int cmd, unsigned long arg); | |
78 | * | |
79 | * implement ioctl processing for 32 bit process on 64 bit system | |
f34d7a5b AC |
80 | * |
81 | * Optional | |
1da177e4 | 82 | * |
edc6afc5 | 83 | * void (*set_termios)(struct tty_struct *tty, struct ktermios * old); |
1da177e4 LT |
84 | * |
85 | * This routine allows the tty driver to be notified when | |
f34d7a5b AC |
86 | * device's termios settings have changed. |
87 | * | |
88 | * Optional: Called under the termios lock | |
89 | * | |
1da177e4 LT |
90 | * |
91 | * void (*set_ldisc)(struct tty_struct *tty); | |
92 | * | |
93 | * This routine allows the tty driver to be notified when the | |
94 | * device's termios settings have changed. | |
f34d7a5b AC |
95 | * |
96 | * Optional: Called under BKL (currently) | |
1da177e4 LT |
97 | * |
98 | * void (*throttle)(struct tty_struct * tty); | |
99 | * | |
100 | * This routine notifies the tty driver that input buffers for | |
101 | * the line discipline are close to full, and it should somehow | |
102 | * signal that no more characters should be sent to the tty. | |
103 | * | |
104 | * void (*unthrottle)(struct tty_struct * tty); | |
105 | * | |
106 | * This routine notifies the tty drivers that it should signals | |
107 | * that characters can now be sent to the tty without fear of | |
108 | * overrunning the input buffers of the line disciplines. | |
109 | * | |
110 | * void (*stop)(struct tty_struct *tty); | |
111 | * | |
112 | * This routine notifies the tty driver that it should stop | |
113 | * outputting characters to the tty device. | |
f34d7a5b AC |
114 | * |
115 | * Optional: | |
116 | * | |
117 | * Note: Call stop_tty not this method. | |
1da177e4 LT |
118 | * |
119 | * void (*start)(struct tty_struct *tty); | |
120 | * | |
121 | * This routine notifies the tty driver that it resume sending | |
122 | * characters to the tty device. | |
f34d7a5b AC |
123 | * |
124 | * Optional: | |
125 | * | |
126 | * Note: Call start_tty not this method. | |
1da177e4 LT |
127 | * |
128 | * void (*hangup)(struct tty_struct *tty); | |
129 | * | |
130 | * This routine notifies the tty driver that it should hangup the | |
131 | * tty device. | |
132 | * | |
f34d7a5b AC |
133 | * Required: |
134 | * | |
1da177e4 LT |
135 | * void (*break_ctl)(struct tty_stuct *tty, int state); |
136 | * | |
137 | * This optional routine requests the tty driver to turn on or | |
138 | * off BREAK status on the RS-232 port. If state is -1, | |
139 | * then the BREAK status should be turned on; if state is 0, then | |
140 | * BREAK should be turned off. | |
141 | * | |
142 | * If this routine is implemented, the high-level tty driver will | |
143 | * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK, | |
f34d7a5b AC |
144 | * TIOCCBRK. |
145 | * | |
146 | * Optional: Required for TCSBRK/BRKP/etc handling. | |
1da177e4 LT |
147 | * |
148 | * void (*wait_until_sent)(struct tty_struct *tty, int timeout); | |
149 | * | |
150 | * This routine waits until the device has written out all of the | |
151 | * characters in its transmitter FIFO. | |
152 | * | |
f34d7a5b AC |
153 | * Optional: If not provided the device is assumed to have no FIFO |
154 | * | |
155 | * Note: Usually correct to call tty_wait_until_sent | |
156 | * | |
1da177e4 LT |
157 | * void (*send_xchar)(struct tty_struct *tty, char ch); |
158 | * | |
159 | * This routine is used to send a high-priority XON/XOFF | |
160 | * character to the device. | |
f34d7a5b AC |
161 | * |
162 | * Optional: If not provided then the write method is called under | |
163 | * the atomic write lock to keep it serialized with the ldisc. | |
1da177e4 LT |
164 | */ |
165 | ||
166 | #include <linux/fs.h> | |
167 | #include <linux/list.h> | |
168 | #include <linux/cdev.h> | |
169 | ||
170 | struct tty_struct; | |
f2d937f3 | 171 | struct tty_driver; |
1da177e4 LT |
172 | |
173 | struct tty_operations { | |
174 | int (*open)(struct tty_struct * tty, struct file * filp); | |
175 | void (*close)(struct tty_struct * tty, struct file * filp); | |
176 | int (*write)(struct tty_struct * tty, | |
177 | const unsigned char *buf, int count); | |
f34d7a5b | 178 | int (*put_char)(struct tty_struct *tty, unsigned char ch); |
1da177e4 LT |
179 | void (*flush_chars)(struct tty_struct *tty); |
180 | int (*write_room)(struct tty_struct *tty); | |
181 | int (*chars_in_buffer)(struct tty_struct *tty); | |
182 | int (*ioctl)(struct tty_struct *tty, struct file * file, | |
183 | unsigned int cmd, unsigned long arg); | |
e10cc1df PF |
184 | long (*compat_ioctl)(struct tty_struct *tty, struct file * file, |
185 | unsigned int cmd, unsigned long arg); | |
edc6afc5 | 186 | void (*set_termios)(struct tty_struct *tty, struct ktermios * old); |
1da177e4 LT |
187 | void (*throttle)(struct tty_struct * tty); |
188 | void (*unthrottle)(struct tty_struct * tty); | |
189 | void (*stop)(struct tty_struct *tty); | |
190 | void (*start)(struct tty_struct *tty); | |
191 | void (*hangup)(struct tty_struct *tty); | |
192 | void (*break_ctl)(struct tty_struct *tty, int state); | |
193 | void (*flush_buffer)(struct tty_struct *tty); | |
194 | void (*set_ldisc)(struct tty_struct *tty); | |
195 | void (*wait_until_sent)(struct tty_struct *tty, int timeout); | |
196 | void (*send_xchar)(struct tty_struct *tty, char ch); | |
197 | int (*read_proc)(char *page, char **start, off_t off, | |
198 | int count, int *eof, void *data); | |
1da177e4 LT |
199 | int (*tiocmget)(struct tty_struct *tty, struct file *file); |
200 | int (*tiocmset)(struct tty_struct *tty, struct file *file, | |
201 | unsigned int set, unsigned int clear); | |
f2d937f3 JW |
202 | #ifdef CONFIG_CONSOLE_POLL |
203 | int (*poll_init)(struct tty_driver *driver, int line, char *options); | |
204 | int (*poll_get_char)(struct tty_driver *driver, int line); | |
205 | void (*poll_put_char)(struct tty_driver *driver, int line, char ch); | |
206 | #endif | |
1da177e4 LT |
207 | }; |
208 | ||
209 | struct tty_driver { | |
210 | int magic; /* magic number for this structure */ | |
211 | struct cdev cdev; | |
212 | struct module *owner; | |
213 | const char *driver_name; | |
1da177e4 LT |
214 | const char *name; |
215 | int name_base; /* offset of printed name */ | |
216 | int major; /* major device number */ | |
217 | int minor_start; /* start of minor device number */ | |
218 | int minor_num; /* number of *possible* devices */ | |
219 | int num; /* number of devices allocated */ | |
220 | short type; /* type of tty driver */ | |
221 | short subtype; /* subtype of tty driver */ | |
edc6afc5 | 222 | struct ktermios init_termios; /* Initial termios */ |
1da177e4 LT |
223 | int flags; /* tty driver flags */ |
224 | int refcount; /* for loadable tty drivers */ | |
225 | struct proc_dir_entry *proc_entry; /* /proc fs entry */ | |
226 | struct tty_driver *other; /* only used for the PTY driver */ | |
227 | ||
228 | /* | |
229 | * Pointer to the tty data structures | |
230 | */ | |
231 | struct tty_struct **ttys; | |
edc6afc5 AC |
232 | struct ktermios **termios; |
233 | struct ktermios **termios_locked; | |
f34d7a5b AC |
234 | void *driver_state; |
235 | ||
1da177e4 | 236 | /* |
f34d7a5b | 237 | * Driver methods |
1da177e4 | 238 | */ |
1da177e4 | 239 | |
f34d7a5b | 240 | const struct tty_operations *ops; |
1da177e4 LT |
241 | struct list_head tty_drivers; |
242 | }; | |
243 | ||
244 | extern struct list_head tty_drivers; | |
245 | ||
246 | struct tty_driver *alloc_tty_driver(int lines); | |
247 | void put_tty_driver(struct tty_driver *driver); | |
b68e31d0 JD |
248 | void tty_set_operations(struct tty_driver *driver, |
249 | const struct tty_operations *op); | |
f2d937f3 | 250 | extern struct tty_driver *tty_find_polling_driver(char *name, int *line); |
1da177e4 LT |
251 | |
252 | /* tty driver magic number */ | |
253 | #define TTY_DRIVER_MAGIC 0x5402 | |
254 | ||
255 | /* | |
256 | * tty driver flags | |
257 | * | |
258 | * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the | |
259 | * termios setting when the last process has closed the device. | |
260 | * Used for PTY's, in particular. | |
261 | * | |
262 | * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will | |
263 | * guarantee never not to set any special character handling | |
264 | * flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR || | |
265 | * !INPCK)). That is, if there is no reason for the driver to | |
266 | * send notifications of parity and break characters up to the | |
267 | * line driver, it won't do so. This allows the line driver to | |
268 | * optimize for this case if this flag is set. (Note that there | |
269 | * is also a promise, if the above case is true, not to signal | |
270 | * overruns, either.) | |
271 | * | |
331b8319 GKH |
272 | * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need |
273 | * to be registered with a call to tty_register_driver() when the | |
274 | * device is found in the system and unregistered with a call to | |
275 | * tty_unregister_device() so the devices will be show up | |
276 | * properly in sysfs. If not set, driver->num entries will be | |
277 | * created by the tty core in sysfs when tty_register_driver() is | |
278 | * called. This is to be used by drivers that have tty devices | |
279 | * that can appear and disappear while the main tty driver is | |
280 | * registered with the tty core. | |
1da177e4 LT |
281 | * |
282 | * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead | |
283 | * use dynamic memory keyed through the devpts filesystem. This | |
284 | * is only applicable to the pty driver. | |
285 | */ | |
286 | #define TTY_DRIVER_INSTALLED 0x0001 | |
287 | #define TTY_DRIVER_RESET_TERMIOS 0x0002 | |
288 | #define TTY_DRIVER_REAL_RAW 0x0004 | |
331b8319 | 289 | #define TTY_DRIVER_DYNAMIC_DEV 0x0008 |
1da177e4 LT |
290 | #define TTY_DRIVER_DEVPTS_MEM 0x0010 |
291 | ||
292 | /* tty driver types */ | |
293 | #define TTY_DRIVER_TYPE_SYSTEM 0x0001 | |
294 | #define TTY_DRIVER_TYPE_CONSOLE 0x0002 | |
295 | #define TTY_DRIVER_TYPE_SERIAL 0x0003 | |
296 | #define TTY_DRIVER_TYPE_PTY 0x0004 | |
297 | #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */ | |
298 | #define TTY_DRIVER_TYPE_SYSCONS 0x0006 | |
299 | ||
300 | /* system subtypes (magic, used by tty_io.c) */ | |
301 | #define SYSTEM_TYPE_TTY 0x0001 | |
302 | #define SYSTEM_TYPE_CONSOLE 0x0002 | |
303 | #define SYSTEM_TYPE_SYSCONS 0x0003 | |
304 | #define SYSTEM_TYPE_SYSPTMX 0x0004 | |
305 | ||
306 | /* pty subtypes (magic, used by tty_io.c) */ | |
307 | #define PTY_TYPE_MASTER 0x0001 | |
308 | #define PTY_TYPE_SLAVE 0x0002 | |
309 | ||
310 | /* serial subtype definitions */ | |
311 | #define SERIAL_TYPE_NORMAL 1 | |
312 | ||
313 | #endif /* #ifdef _LINUX_TTY_DRIVER_H */ |