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