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