Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_TTY_DRIVER_H |
3 | #define _LINUX_TTY_DRIVER_H | |
4 | ||
1fe18309 JS |
5 | #include <linux/export.h> |
6 | #include <linux/fs.h> | |
7 | #include <linux/kref.h> | |
8 | #include <linux/list.h> | |
9 | #include <linux/cdev.h> | |
89bbeb7e | 10 | #include <linux/uaccess.h> |
1fe18309 JS |
11 | #include <linux/termios.h> |
12 | #include <linux/seq_file.h> | |
13 | ||
14 | struct tty_struct; | |
15 | struct tty_driver; | |
16 | struct serial_icounter_struct; | |
17 | struct serial_struct; | |
18 | ||
19 | /** | |
20 | * struct tty_operations -- interface between driver and tty | |
1da177e4 | 21 | * |
1fe18309 JS |
22 | * @lookup: ``struct tty_struct *()(struct tty_driver *self, struct file *, |
23 | * int idx)`` | |
99f1fe18 | 24 | * |
1fe18309 JS |
25 | * Return the tty device corresponding to @idx, %NULL if there is not |
26 | * one currently in use and an %ERR_PTR value on error. Called under | |
27 | * %tty_mutex (for now!) | |
99f1fe18 | 28 | * |
1fe18309 | 29 | * Optional method. Default behaviour is to use the @self->ttys array. |
99f1fe18 | 30 | * |
1fe18309 | 31 | * @install: ``int ()(struct tty_driver *self, struct tty_struct *tty)`` |
8b0a88d5 | 32 | * |
1fe18309 JS |
33 | * Install a new @tty into the @self's internal tables. Used in |
34 | * conjunction with @lookup and @remove methods. | |
8b0a88d5 | 35 | * |
1fe18309 | 36 | * Optional method. Default behaviour is to use the @self->ttys array. |
8b0a88d5 | 37 | * |
1fe18309 | 38 | * @remove: ``void ()(struct tty_driver *self, struct tty_struct *tty)`` |
8b0a88d5 | 39 | * |
1fe18309 JS |
40 | * Remove a closed @tty from the @self's internal tables. Used in |
41 | * conjunction with @lookup and @remove methods. | |
8b0a88d5 | 42 | * |
1fe18309 | 43 | * Optional method. Default behaviour is to use the @self->ttys array. |
8b0a88d5 | 44 | * |
1fe18309 | 45 | * @open: ``int ()(struct tty_struct *tty, struct file *)`` |
1da177e4 | 46 | * |
1fe18309 JS |
47 | * This routine is called when a particular @tty device is opened. This |
48 | * routine is mandatory; if this routine is not filled in, the attempted | |
49 | * open will fail with %ENODEV. | |
f34d7a5b | 50 | * |
29d5ef68 | 51 | * Required method. Called with tty lock held. May sleep. |
ed617e44 | 52 | * |
1fe18309 JS |
53 | * @close: ``void ()(struct tty_struct *tty, struct file *)`` |
54 | * | |
29d5ef68 JS |
55 | * This routine is called when a particular @tty device is closed. At the |
56 | * point of return from this call the driver must make no further ldisc | |
57 | * calls of any kind. | |
1da177e4 | 58 | * |
1fe18309 | 59 | * Remark: called even if the corresponding @open() failed. |
1da177e4 | 60 | * |
29d5ef68 | 61 | * Required method. Called with tty lock held. May sleep. |
f34d7a5b | 62 | * |
1fe18309 | 63 | * @shutdown: ``void ()(struct tty_struct *tty)`` |
feebed65 | 64 | * |
1fe18309 JS |
65 | * This routine is called under the tty lock when a particular @tty device |
66 | * is closed for the last time. It executes before the @tty resources | |
67 | * are freed so may execute while another function holds a @tty kref. | |
f278a2f7 | 68 | * |
1fe18309 | 69 | * @cleanup: ``void ()(struct tty_struct *tty)`` |
f278a2f7 | 70 | * |
1fe18309 | 71 | * This routine is called asynchronously when a particular @tty device |
f278a2f7 DY |
72 | * is closed for the last time freeing up the resources. This is |
73 | * actually the second part of shutdown for routines that might sleep. | |
74 | * | |
1fe18309 JS |
75 | * @write: ``int ()(struct tty_struct *tty, const unsigned char *buf, |
76 | * int count)`` | |
feebed65 | 77 | * |
1fe18309 JS |
78 | * This routine is called by the kernel to write a series (@count) of |
79 | * characters (@buf) to the @tty device. The characters may come from | |
80 | * user space or kernel space. This routine will return the | |
36c7343b | 81 | * number of characters actually accepted for writing. |
1da177e4 | 82 | * |
29d5ef68 JS |
83 | * May occur in parallel in special cases. Because this includes panic |
84 | * paths drivers generally shouldn't try and do clever locking here. | |
85 | * | |
86 | * Optional: Required for writable devices. May not sleep. | |
f34d7a5b | 87 | * |
1fe18309 | 88 | * @put_char: ``int ()(struct tty_struct *tty, unsigned char ch)`` |
1da177e4 | 89 | * |
1fe18309 JS |
90 | * This routine is called by the kernel to write a single character @ch to |
91 | * the @tty device. If the kernel uses this routine, it must call the | |
92 | * @flush_chars() routine (if defined) when it is done stuffing characters | |
93 | * into the driver. If there is no room in the queue, the character is | |
94 | * ignored. | |
f34d7a5b | 95 | * |
1fe18309 JS |
96 | * Optional: Kernel will use the @write method if not provided. Do not |
97 | * call this function directly, call tty_put_char(). | |
f34d7a5b | 98 | * |
1fe18309 | 99 | * @flush_chars: ``void ()(struct tty_struct *tty)`` |
1da177e4 | 100 | * |
1fe18309 JS |
101 | * This routine is called by the kernel after it has written a |
102 | * series of characters to the tty device using @put_char(). | |
f34d7a5b | 103 | * |
1fe18309 JS |
104 | * Optional. Do not call this function directly, call |
105 | * tty_driver_flush_chars(). | |
f34d7a5b | 106 | * |
1fe18309 | 107 | * @write_room: ``unsigned int ()(struct tty_struct *tty)`` |
1da177e4 | 108 | * |
1fe18309 JS |
109 | * This routine returns the numbers of characters the @tty driver |
110 | * will accept for queuing to be written. This number is subject | |
111 | * to change as output buffers get emptied, or if the output flow | |
1da177e4 | 112 | * control is acted. |
f34d7a5b | 113 | * |
29d5ef68 JS |
114 | * The ldisc is responsible for being intelligent about multi-threading of |
115 | * write_room/write calls | |
116 | * | |
1fe18309 JS |
117 | * Required if @write method is provided else not needed. Do not call this |
118 | * function directly, call tty_write_room() | |
f34d7a5b | 119 | * |
1fe18309 | 120 | * @chars_in_buffer: ``unsigned int ()(struct tty_struct *tty)`` |
1da177e4 | 121 | * |
1fe18309 JS |
122 | * This routine returns the number of characters in the device private |
123 | * output queue. Used in tty_wait_until_sent() and for poll() | |
124 | * implementation. | |
e10cc1df | 125 | * |
1fe18309 JS |
126 | * Optional: if not provided, it is assumed there is no queue on the |
127 | * device. Do not call this function directly, call tty_chars_in_buffer(). | |
f34d7a5b | 128 | * |
1fe18309 JS |
129 | * @ioctl: ``int ()(struct tty_struct *tty, unsigned int cmd, |
130 | * unsigned long arg)`` | |
e10cc1df | 131 | * |
1fe18309 JS |
132 | * This routine allows the @tty driver to implement device-specific |
133 | * ioctls. If the ioctl number passed in @cmd is not recognized by the | |
134 | * driver, it should return %ENOIOCTLCMD. | |
f34d7a5b | 135 | * |
1fe18309 | 136 | * Optional. |
1da177e4 | 137 | * |
1fe18309 JS |
138 | * @compat_ioctl: ``long ()(struct tty_struct *tty, unsigned int cmd, |
139 | * unsigned long arg)`` | |
f34d7a5b | 140 | * |
1fe18309 | 141 | * Implement ioctl processing for 32 bit process on 64 bit system. |
f34d7a5b | 142 | * |
1fe18309 | 143 | * Optional. |
1da177e4 | 144 | * |
a8c11c15 | 145 | * @set_termios: ``void ()(struct tty_struct *tty, const struct ktermios *old)`` |
1da177e4 | 146 | * |
1fe18309 | 147 | * This routine allows the @tty driver to be notified when device's |
29d5ef68 JS |
148 | * termios settings have changed. New settings are in @tty->termios. |
149 | * Previous settings are passed in the @old argument. | |
f34d7a5b | 150 | * |
29d5ef68 JS |
151 | * The API is defined such that the driver should return the actual modes |
152 | * selected. This means that the driver is responsible for modifying any | |
153 | * bits in @tty->termios it cannot fulfill to indicate the actual modes | |
154 | * being used. | |
155 | * | |
156 | * Optional. Called under the @tty->termios_rwsem. May sleep. | |
1da177e4 | 157 | * |
1fe18309 | 158 | * @set_ldisc: ``void ()(struct tty_struct *tty)`` |
39c2e60f | 159 | * |
1fe18309 | 160 | * This routine allows the @tty driver to be notified when the device's |
29d5ef68 JS |
161 | * line discipline is being changed. At the point this is done the |
162 | * discipline is not yet usable. | |
1da177e4 | 163 | * |
1fe18309 | 164 | * Optional. Called under the @tty->ldisc_sem and @tty->termios_rwsem. |
39c2e60f | 165 | * |
1fe18309 | 166 | * @throttle: ``void ()(struct tty_struct *tty)`` |
1da177e4 | 167 | * |
1fe18309 JS |
168 | * This routine notifies the @tty driver that input buffers for the line |
169 | * discipline are close to full, and it should somehow signal that no more | |
170 | * characters should be sent to the @tty. | |
f34d7a5b | 171 | * |
29d5ef68 JS |
172 | * Serialization including with @unthrottle() is the job of the ldisc |
173 | * layer. | |
174 | * | |
1fe18309 JS |
175 | * Optional: Always invoke via tty_throttle_safe(). Called under the |
176 | * @tty->termios_rwsem. | |
f9e053dc | 177 | * |
1fe18309 | 178 | * @unthrottle: ``void ()(struct tty_struct *tty)`` |
f34d7a5b | 179 | * |
1fe18309 JS |
180 | * This routine notifies the @tty driver that it should signal that |
181 | * characters can now be sent to the @tty without fear of overrunning the | |
182 | * input buffers of the line disciplines. | |
1da177e4 | 183 | * |
1fe18309 JS |
184 | * Optional. Always invoke via tty_unthrottle(). Called under the |
185 | * @tty->termios_rwsem. | |
186 | * | |
187 | * @stop: ``void ()(struct tty_struct *tty)`` | |
188 | * | |
189 | * This routine notifies the @tty driver that it should stop outputting | |
1da177e4 | 190 | * characters to the tty device. |
f34d7a5b | 191 | * |
1fe18309 JS |
192 | * Called with @tty->flow.lock held. Serialized with @start() method. |
193 | * | |
194 | * Optional. Always invoke via stop_tty(). | |
195 | * | |
196 | * @start: ``void ()(struct tty_struct *tty)`` | |
197 | * | |
198 | * This routine notifies the @tty driver that it resumed sending | |
199 | * characters to the @tty device. | |
200 | * | |
201 | * Called with @tty->flow.lock held. Serialized with stop() method. | |
202 | * | |
203 | * Optional. Always invoke via start_tty(). | |
204 | * | |
205 | * @hangup: ``void ()(struct tty_struct *tty)`` | |
206 | * | |
207 | * This routine notifies the @tty driver that it should hang up the @tty | |
208 | * device. | |
f9e053dc | 209 | * |
1fe18309 | 210 | * Optional. Called with tty lock held. |
f34d7a5b | 211 | * |
1fe18309 | 212 | * @break_ctl: ``int ()(struct tty_struct *tty, int state)`` |
1da177e4 | 213 | * |
1fe18309 JS |
214 | * This optional routine requests the @tty driver to turn on or off BREAK |
215 | * status on the RS-232 port. If @state is -1, then the BREAK status | |
216 | * should be turned on; if @state is 0, then BREAK should be turned off. | |
1da177e4 | 217 | * |
1fe18309 JS |
218 | * If this routine is implemented, the high-level tty driver will handle |
219 | * the following ioctls: %TCSBRK, %TCSBRKP, %TIOCSBRK, %TIOCCBRK. | |
f34d7a5b | 220 | * |
1fe18309 JS |
221 | * If the driver sets %TTY_DRIVER_HARDWARE_BREAK in tty_alloc_driver(), |
222 | * then the interface will also be called with actual times and the | |
223 | * hardware is expected to do the delay work itself. 0 and -1 are still | |
224 | * used for on/off. | |
ed617e44 | 225 | * |
29d5ef68 | 226 | * Optional: Required for %TCSBRK/%BRKP/etc. handling. May sleep. |
1da177e4 | 227 | * |
1fe18309 | 228 | * @flush_buffer: ``void ()(struct tty_struct *tty)`` |
1da177e4 | 229 | * |
1fe18309 JS |
230 | * This routine discards device private output buffer. Invoked on close, |
231 | * hangup, to implement %TCOFLUSH ioctl and similar. | |
f34d7a5b | 232 | * |
1fe18309 JS |
233 | * Optional: if not provided, it is assumed there is no queue on the |
234 | * device. Do not call this function directly, call | |
235 | * tty_driver_flush_buffer(). | |
9e98966c | 236 | * |
1fe18309 | 237 | * @wait_until_sent: ``void ()(struct tty_struct *tty, int timeout)`` |
1da177e4 | 238 | * |
1fe18309 JS |
239 | * This routine waits until the device has written out all of the |
240 | * characters in its transmitter FIFO. Or until @timeout (in jiffies) is | |
241 | * reached. | |
1da177e4 | 242 | * |
1fe18309 | 243 | * Optional: If not provided, the device is assumed to have no FIFO. |
29d5ef68 | 244 | * Usually correct to invoke via tty_wait_until_sent(). May sleep. |
f34d7a5b | 245 | * |
1fe18309 | 246 | * @send_xchar: ``void ()(struct tty_struct *tty, char ch)`` |
f34d7a5b | 247 | * |
1fe18309 JS |
248 | * This routine is used to send a high-priority XON/XOFF character (@ch) |
249 | * to the @tty device. | |
1da177e4 | 250 | * |
1fe18309 JS |
251 | * Optional: If not provided, then the @write method is called under |
252 | * the @tty->atomic_write_lock to keep it serialized with the ldisc. | |
f34d7a5b | 253 | * |
1fe18309 | 254 | * @tiocmget: ``int ()(struct tty_struct *tty)`` |
8c9a9dd0 | 255 | * |
1fe18309 JS |
256 | * This routine is used to obtain the modem status bits from the @tty |
257 | * driver. | |
8c9a9dd0 | 258 | * |
1fe18309 JS |
259 | * Optional: If not provided, then %ENOTTY is returned from the %TIOCMGET |
260 | * ioctl. Do not call this function directly, call tty_tiocmget(). | |
261 | * | |
262 | * @tiocmset: ``int ()(struct tty_struct *tty, | |
263 | * unsigned int set, unsigned int clear)`` | |
264 | * | |
265 | * This routine is used to set the modem status bits to the @tty driver. | |
266 | * First, @clear bits should be cleared, then @set bits set. | |
267 | * | |
268 | * Optional: If not provided, then %ENOTTY is returned from the %TIOCMSET | |
269 | * ioctl. Do not call this function directly, call tty_tiocmset(). | |
270 | * | |
271 | * @resize: ``int ()(struct tty_struct *tty, struct winsize *ws)`` | |
272 | * | |
273 | * Called when a termios request is issued which changes the requested | |
274 | * terminal geometry to @ws. | |
8c9a9dd0 AC |
275 | * |
276 | * Optional: the default action is to update the termios structure | |
277 | * without error. This is usually the correct behaviour. Drivers should | |
1fe18309 | 278 | * not force errors here if they are not resizable objects (e.g. a serial |
8c9a9dd0 | 279 | * line). See tty_do_resize() if you need to wrap the standard method |
1fe18309 JS |
280 | * in your own logic -- the usual case. |
281 | * | |
282 | * @get_icount: ``int ()(struct tty_struct *tty, | |
283 | * struct serial_icounter *icount)`` | |
284 | * | |
285 | * Called when the @tty device receives a %TIOCGICOUNT ioctl. Passed a | |
286 | * kernel structure @icount to complete. | |
287 | * | |
288 | * Optional: called only if provided, otherwise %ENOTTY will be returned. | |
1d65b4a0 | 289 | * |
1fe18309 | 290 | * @get_serial: ``int ()(struct tty_struct *tty, struct serial_struct *p)`` |
d281da7f | 291 | * |
1fe18309 JS |
292 | * Called when the @tty device receives a %TIOCGSERIAL ioctl. Passed a |
293 | * kernel structure @p (&struct serial_struct) to complete. | |
294 | * | |
295 | * Optional: called only if provided, otherwise %ENOTTY will be returned. | |
296 | * Do not call this function directly, call tty_tiocgserial(). | |
297 | * | |
298 | * @set_serial: ``int ()(struct tty_struct *tty, struct serial_struct *p)`` | |
299 | * | |
300 | * Called when the @tty device receives a %TIOCSSERIAL ioctl. Passed a | |
301 | * kernel structure @p (&struct serial_struct) to set the values from. | |
302 | * | |
303 | * Optional: called only if provided, otherwise %ENOTTY will be returned. | |
304 | * Do not call this function directly, call tty_tiocsserial(). | |
305 | * | |
306 | * @show_fdinfo: ``void ()(struct tty_struct *tty, struct seq_file *m)`` | |
307 | * | |
308 | * Called when the @tty device file descriptor receives a fdinfo request | |
309 | * from VFS (to show in /proc/<pid>/fdinfo/). @m should be filled with | |
310 | * information. | |
311 | * | |
312 | * Optional: called only if provided, otherwise nothing is written to @m. | |
313 | * Do not call this function directly, call tty_show_fdinfo(). | |
314 | * | |
315 | * @poll_init: ``int ()(struct tty_driver *driver, int line, char *options)`` | |
316 | * | |
317 | * kgdboc support (Documentation/dev-tools/kgdb.rst). This routine is | |
318 | * called to initialize the HW for later use by calling @poll_get_char or | |
319 | * @poll_put_char. | |
320 | * | |
321 | * Optional: called only if provided, otherwise skipped as a non-polling | |
322 | * driver. | |
323 | * | |
324 | * @poll_get_char: ``int ()(struct tty_driver *driver, int line)`` | |
325 | * | |
326 | * kgdboc support (see @poll_init). @driver should read a character from a | |
327 | * tty identified by @line and return it. | |
328 | * | |
329 | * Optional: called only if @poll_init provided. | |
330 | * | |
331 | * @poll_put_char: ``void ()(struct tty_driver *driver, int line, char ch)`` | |
332 | * | |
333 | * kgdboc support (see @poll_init). @driver should write character @ch to | |
334 | * a tty identified by @line. | |
335 | * | |
336 | * Optional: called only if @poll_init provided. | |
337 | * | |
338 | * @proc_show: ``int ()(struct seq_file *m, void *driver)`` | |
339 | * | |
340 | * Driver @driver (cast to &struct tty_driver) can show additional info in | |
341 | * /proc/tty/driver/<driver_name>. It is enough to fill in the information | |
342 | * into @m. | |
343 | * | |
344 | * Optional: called only if provided, otherwise no /proc entry created. | |
345 | * | |
346 | * This structure defines the interface between the low-level tty driver and | |
347 | * the tty routines. These routines can be defined. Unless noted otherwise, | |
348 | * they are optional, and can be filled in with a %NULL pointer. | |
1da177e4 | 349 | */ |
1da177e4 | 350 | struct tty_operations { |
15f1a633 | 351 | struct tty_struct * (*lookup)(struct tty_driver *driver, |
8ead9dd5 | 352 | struct file *filp, int idx); |
8b0a88d5 AC |
353 | int (*install)(struct tty_driver *driver, struct tty_struct *tty); |
354 | void (*remove)(struct tty_driver *driver, struct tty_struct *tty); | |
1da177e4 LT |
355 | int (*open)(struct tty_struct * tty, struct file * filp); |
356 | void (*close)(struct tty_struct * tty, struct file * filp); | |
feebed65 | 357 | void (*shutdown)(struct tty_struct *tty); |
f278a2f7 | 358 | void (*cleanup)(struct tty_struct *tty); |
1da177e4 LT |
359 | int (*write)(struct tty_struct * tty, |
360 | const unsigned char *buf, int count); | |
f34d7a5b | 361 | int (*put_char)(struct tty_struct *tty, unsigned char ch); |
1da177e4 | 362 | void (*flush_chars)(struct tty_struct *tty); |
03b3b1a2 | 363 | unsigned int (*write_room)(struct tty_struct *tty); |
fff4ef17 | 364 | unsigned int (*chars_in_buffer)(struct tty_struct *tty); |
6caa76b7 | 365 | int (*ioctl)(struct tty_struct *tty, |
1da177e4 | 366 | unsigned int cmd, unsigned long arg); |
6caa76b7 | 367 | long (*compat_ioctl)(struct tty_struct *tty, |
e10cc1df | 368 | unsigned int cmd, unsigned long arg); |
a8c11c15 | 369 | void (*set_termios)(struct tty_struct *tty, const struct ktermios *old); |
1da177e4 LT |
370 | void (*throttle)(struct tty_struct * tty); |
371 | void (*unthrottle)(struct tty_struct * tty); | |
372 | void (*stop)(struct tty_struct *tty); | |
373 | void (*start)(struct tty_struct *tty); | |
374 | void (*hangup)(struct tty_struct *tty); | |
9e98966c | 375 | int (*break_ctl)(struct tty_struct *tty, int state); |
1da177e4 LT |
376 | void (*flush_buffer)(struct tty_struct *tty); |
377 | void (*set_ldisc)(struct tty_struct *tty); | |
378 | void (*wait_until_sent)(struct tty_struct *tty, int timeout); | |
379 | void (*send_xchar)(struct tty_struct *tty, char ch); | |
60b33c13 | 380 | int (*tiocmget)(struct tty_struct *tty); |
20b9d177 | 381 | int (*tiocmset)(struct tty_struct *tty, |
1da177e4 | 382 | unsigned int set, unsigned int clear); |
fc6f6238 | 383 | int (*resize)(struct tty_struct *tty, struct winsize *ws); |
d281da7f AC |
384 | int (*get_icount)(struct tty_struct *tty, |
385 | struct serial_icounter_struct *icount); | |
2f46a2c1 AV |
386 | int (*get_serial)(struct tty_struct *tty, struct serial_struct *p); |
387 | int (*set_serial)(struct tty_struct *tty, struct serial_struct *p); | |
d01c3289 | 388 | void (*show_fdinfo)(struct tty_struct *tty, struct seq_file *m); |
f2d937f3 JW |
389 | #ifdef CONFIG_CONSOLE_POLL |
390 | int (*poll_init)(struct tty_driver *driver, int line, char *options); | |
391 | int (*poll_get_char)(struct tty_driver *driver, int line); | |
392 | void (*poll_put_char)(struct tty_driver *driver, int line, char ch); | |
393 | #endif | |
1fe18309 | 394 | int (*proc_show)(struct seq_file *m, void *driver); |
3859a271 | 395 | } __randomize_layout; |
1da177e4 | 396 | |
a6563830 JS |
397 | /** |
398 | * struct tty_driver -- driver for TTY devices | |
399 | * | |
a6563830 JS |
400 | * @kref: reference counting. Reaching zero frees all the internals and the |
401 | * driver. | |
402 | * @cdevs: allocated/registered character /dev devices | |
403 | * @owner: modules owning this driver. Used drivers cannot be rmmod'ed. | |
404 | * Automatically set by tty_alloc_driver(). | |
405 | * @driver_name: name of the driver used in /proc/tty | |
406 | * @name: used for constructing /dev node name | |
407 | * @name_base: used as a number base for constructing /dev node name | |
408 | * @major: major /dev device number (zero for autoassignment) | |
409 | * @minor_start: the first minor /dev device number | |
410 | * @num: number of devices allocated | |
411 | * @type: type of tty driver (%TTY_DRIVER_TYPE_) | |
412 | * @subtype: subtype of tty driver (%SYSTEM_TYPE_, %PTY_TYPE_, %SERIAL_TYPE_) | |
413 | * @init_termios: termios to set to each tty initially (e.g. %tty_std_termios) | |
414 | * @flags: tty driver flags (%TTY_DRIVER_) | |
415 | * @proc_entry: proc fs entry, used internally | |
416 | * @other: driver of the linked tty; only used for the PTY driver | |
417 | * @ttys: array of active &struct tty_struct, set by tty_standard_install() | |
418 | * @ports: array of &struct tty_port; can be set during initialization by | |
419 | * tty_port_link_device() and similar | |
420 | * @termios: storage for termios at each TTY close for the next open | |
421 | * @driver_state: pointer to driver's arbitrary data | |
422 | * @ops: driver hooks for TTYs. Set them using tty_set_operations(). Use &struct | |
423 | * tty_port helpers in them as much as possible. | |
424 | * @tty_drivers: used internally to link tty_drivers together | |
425 | * | |
426 | * The usual handling of &struct tty_driver is to allocate it by | |
427 | * tty_alloc_driver(), set up all the necessary members, and register it by | |
428 | * tty_register_driver(). At last, the driver is torn down by calling | |
429 | * tty_unregister_driver() followed by tty_driver_kref_put(). | |
430 | * | |
431 | * The fields required to be set before calling tty_register_driver() include | |
432 | * @driver_name, @name, @type, @subtype, @init_termios, and @ops. | |
433 | */ | |
1da177e4 | 434 | struct tty_driver { |
a6563830 | 435 | struct kref kref; |
a3a10ce3 | 436 | struct cdev **cdevs; |
1da177e4 LT |
437 | struct module *owner; |
438 | const char *driver_name; | |
1da177e4 | 439 | const char *name; |
a6563830 JS |
440 | int name_base; |
441 | int major; | |
442 | int minor_start; | |
443 | unsigned int num; | |
444 | short type; | |
445 | short subtype; | |
446 | struct ktermios init_termios; | |
447 | unsigned long flags; | |
448 | struct proc_dir_entry *proc_entry; | |
449 | struct tty_driver *other; | |
1da177e4 LT |
450 | |
451 | /* | |
452 | * Pointer to the tty data structures | |
453 | */ | |
454 | struct tty_struct **ttys; | |
04831dc1 | 455 | struct tty_port **ports; |
edc6afc5 | 456 | struct ktermios **termios; |
f34d7a5b AC |
457 | void *driver_state; |
458 | ||
1da177e4 | 459 | /* |
f34d7a5b | 460 | * Driver methods |
1da177e4 | 461 | */ |
1da177e4 | 462 | |
f34d7a5b | 463 | const struct tty_operations *ops; |
1da177e4 | 464 | struct list_head tty_drivers; |
3859a271 | 465 | } __randomize_layout; |
1da177e4 LT |
466 | |
467 | extern struct list_head tty_drivers; | |
468 | ||
78941934 JS |
469 | struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner, |
470 | unsigned long flags); | |
471 | struct tty_driver *tty_find_polling_driver(char *name, int *line); | |
1da177e4 | 472 | |
78941934 | 473 | void tty_driver_kref_put(struct tty_driver *driver); |
f786ddd2 | 474 | |
7f0bc6a6 JS |
475 | /* Use TTY_DRIVER_* flags below */ |
476 | #define tty_alloc_driver(lines, flags) \ | |
477 | __tty_alloc_driver(lines, THIS_MODULE, flags) | |
478 | ||
f786ddd2 | 479 | static inline struct tty_driver *tty_driver_kref_get(struct tty_driver *d) |
7d7b93c1 AC |
480 | { |
481 | kref_get(&d->kref); | |
482 | return d; | |
483 | } | |
484 | ||
cb9ea618 JS |
485 | static inline void tty_set_operations(struct tty_driver *driver, |
486 | const struct tty_operations *op) | |
487 | { | |
488 | driver->ops = op; | |
489 | } | |
490 | ||
34d809f8 JS |
491 | /** |
492 | * DOC: TTY Driver Flags | |
493 | * | |
494 | * TTY_DRIVER_RESET_TERMIOS | |
495 | * Requests the tty layer to reset the termios setting when the last | |
496 | * process has closed the device. Used for PTYs, in particular. | |
497 | * | |
498 | * TTY_DRIVER_REAL_RAW | |
499 | * Indicates that the driver will guarantee not to set any special | |
500 | * character handling flags if this is set for the tty: | |
501 | * | |
502 | * ``(IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR || !INPCK)`` | |
503 | * | |
504 | * That is, if there is no reason for the driver to | |
505 | * send notifications of parity and break characters up to the line | |
506 | * driver, it won't do so. This allows the line driver to optimize for | |
507 | * this case if this flag is set. (Note that there is also a promise, if | |
508 | * the above case is true, not to signal overruns, either.) | |
509 | * | |
510 | * TTY_DRIVER_DYNAMIC_DEV | |
511 | * The individual tty devices need to be registered with a call to | |
512 | * tty_register_device() when the device is found in the system and | |
513 | * unregistered with a call to tty_unregister_device() so the devices will | |
514 | * be show up properly in sysfs. If not set, all &tty_driver.num entries | |
515 | * will be created by the tty core in sysfs when tty_register_driver() is | |
516 | * called. This is to be used by drivers that have tty devices that can | |
517 | * appear and disappear while the main tty driver is registered with the | |
518 | * tty core. | |
519 | * | |
520 | * TTY_DRIVER_DEVPTS_MEM | |
521 | * Don't use the standard arrays (&tty_driver.ttys and | |
522 | * &tty_driver.termios), instead use dynamic memory keyed through the | |
523 | * devpts filesystem. This is only applicable to the PTY driver. | |
524 | * | |
525 | * TTY_DRIVER_HARDWARE_BREAK | |
526 | * Hardware handles break signals. Pass the requested timeout to the | |
527 | * &tty_operations.break_ctl instead of using a simple on/off interface. | |
528 | * | |
529 | * TTY_DRIVER_DYNAMIC_ALLOC | |
530 | * Do not allocate structures which are needed per line for this driver | |
531 | * (&tty_driver.ports) as it would waste memory. The driver will take | |
532 | * care. This is only applicable to the PTY driver. | |
533 | * | |
534 | * TTY_DRIVER_UNNUMBERED_NODE | |
535 | * Do not create numbered ``/dev`` nodes. For example, create | |
536 | * ``/dev/ttyprintk`` and not ``/dev/ttyprintk0``. Applicable only when a | |
537 | * driver for a single tty device is being allocated. | |
1da177e4 LT |
538 | */ |
539 | #define TTY_DRIVER_INSTALLED 0x0001 | |
540 | #define TTY_DRIVER_RESET_TERMIOS 0x0002 | |
541 | #define TTY_DRIVER_REAL_RAW 0x0004 | |
331b8319 | 542 | #define TTY_DRIVER_DYNAMIC_DEV 0x0008 |
1da177e4 | 543 | #define TTY_DRIVER_DEVPTS_MEM 0x0010 |
9e98966c | 544 | #define TTY_DRIVER_HARDWARE_BREAK 0x0020 |
21aca2fa | 545 | #define TTY_DRIVER_DYNAMIC_ALLOC 0x0040 |
0019b408 | 546 | #define TTY_DRIVER_UNNUMBERED_NODE 0x0080 |
1da177e4 LT |
547 | |
548 | /* tty driver types */ | |
549 | #define TTY_DRIVER_TYPE_SYSTEM 0x0001 | |
550 | #define TTY_DRIVER_TYPE_CONSOLE 0x0002 | |
551 | #define TTY_DRIVER_TYPE_SERIAL 0x0003 | |
552 | #define TTY_DRIVER_TYPE_PTY 0x0004 | |
553 | #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */ | |
554 | #define TTY_DRIVER_TYPE_SYSCONS 0x0006 | |
555 | ||
556 | /* system subtypes (magic, used by tty_io.c) */ | |
557 | #define SYSTEM_TYPE_TTY 0x0001 | |
558 | #define SYSTEM_TYPE_CONSOLE 0x0002 | |
559 | #define SYSTEM_TYPE_SYSCONS 0x0003 | |
560 | #define SYSTEM_TYPE_SYSPTMX 0x0004 | |
561 | ||
562 | /* pty subtypes (magic, used by tty_io.c) */ | |
563 | #define PTY_TYPE_MASTER 0x0001 | |
564 | #define PTY_TYPE_SLAVE 0x0002 | |
565 | ||
566 | /* serial subtype definitions */ | |
567 | #define SERIAL_TYPE_NORMAL 1 | |
568 | ||
4d3d9478 JS |
569 | int tty_register_driver(struct tty_driver *driver); |
570 | void tty_unregister_driver(struct tty_driver *driver); | |
571 | struct device *tty_register_device(struct tty_driver *driver, unsigned index, | |
572 | struct device *dev); | |
573 | struct device *tty_register_device_attr(struct tty_driver *driver, | |
574 | unsigned index, struct device *device, void *drvdata, | |
575 | const struct attribute_group **attr_grp); | |
576 | void tty_unregister_device(struct tty_driver *driver, unsigned index); | |
577 | ||
578 | #ifdef CONFIG_PROC_FS | |
579 | void proc_tty_register_driver(struct tty_driver *); | |
580 | void proc_tty_unregister_driver(struct tty_driver *); | |
581 | #else | |
582 | static inline void proc_tty_register_driver(struct tty_driver *d) {} | |
583 | static inline void proc_tty_unregister_driver(struct tty_driver *d) {} | |
584 | #endif | |
585 | ||
1da177e4 | 586 | #endif /* #ifdef _LINUX_TTY_DRIVER_H */ |