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