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