xref: /openbmc/linux/include/linux/tty.h (revision ebf05c7d)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _LINUX_TTY_H
31da177e4SLinus Torvalds #define _LINUX_TTY_H
41da177e4SLinus Torvalds 
5ae92c1f5SFlorian Fainelli #include <linux/fs.h>
6ae92c1f5SFlorian Fainelli #include <linux/major.h>
7ae92c1f5SFlorian Fainelli #include <linux/termios.h>
8ae92c1f5SFlorian Fainelli #include <linux/workqueue.h>
98d29e002SJiri Slaby #include <linux/tty_buffer.h>
10ae92c1f5SFlorian Fainelli #include <linux/tty_driver.h>
11ae92c1f5SFlorian Fainelli #include <linux/tty_ldisc.h>
1267b94be4SJiri Slaby #include <linux/tty_port.h>
13ae92c1f5SFlorian Fainelli #include <linux/mutex.h>
14ba3fe7abSAlan Cox #include <linux/tty_flags.h>
15607ca46eSDavid Howells #include <uapi/linux/tty.h>
166a1c0680SPeter Hurley #include <linux/rwsem.h>
17809850b7SPeter Hurley #include <linux/llist.h>
18ae92c1f5SFlorian Fainelli 
19ae92c1f5SFlorian Fainelli 
203abf87cdSPeter Hurley /*
21ae92c1f5SFlorian Fainelli  * (Note: the *_driver.minor_start values 1, 64, 128, 192 are
22ae92c1f5SFlorian Fainelli  * hardcoded at present.)
23ae92c1f5SFlorian Fainelli  */
24ae92c1f5SFlorian Fainelli #define NR_UNIX98_PTY_DEFAULT	4096      /* Default maximum for Unix98 ptys */
25e9aba515SKonstantin Khlebnikov #define NR_UNIX98_PTY_RESERVE	1024	  /* Default reserve for main devpts */
26ae92c1f5SFlorian Fainelli #define NR_UNIX98_PTY_MAX	(1 << MINORBITS) /* Absolute limit */
27ae92c1f5SFlorian Fainelli 
281da177e4SLinus Torvalds /*
291da177e4SLinus Torvalds  * This character is the same as _POSIX_VDISABLE: it cannot be used as
301da177e4SLinus Torvalds  * a c_cc[] character, but indicates that a particular special character
311da177e4SLinus Torvalds  * isn't in use (eg VINTR has no character etc)
321da177e4SLinus Torvalds  */
331da177e4SLinus Torvalds #define __DISABLED_CHAR '\0'
341da177e4SLinus Torvalds 
35adc8d746SAlan Cox #define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR])
36adc8d746SAlan Cox #define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT])
37adc8d746SAlan Cox #define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE])
38adc8d746SAlan Cox #define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL])
39adc8d746SAlan Cox #define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF])
40adc8d746SAlan Cox #define TIME_CHAR(tty) ((tty)->termios.c_cc[VTIME])
41adc8d746SAlan Cox #define MIN_CHAR(tty) ((tty)->termios.c_cc[VMIN])
42adc8d746SAlan Cox #define SWTC_CHAR(tty) ((tty)->termios.c_cc[VSWTC])
43adc8d746SAlan Cox #define START_CHAR(tty) ((tty)->termios.c_cc[VSTART])
44adc8d746SAlan Cox #define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP])
45adc8d746SAlan Cox #define SUSP_CHAR(tty) ((tty)->termios.c_cc[VSUSP])
46adc8d746SAlan Cox #define EOL_CHAR(tty) ((tty)->termios.c_cc[VEOL])
47adc8d746SAlan Cox #define REPRINT_CHAR(tty) ((tty)->termios.c_cc[VREPRINT])
48adc8d746SAlan Cox #define DISCARD_CHAR(tty) ((tty)->termios.c_cc[VDISCARD])
49adc8d746SAlan Cox #define WERASE_CHAR(tty) ((tty)->termios.c_cc[VWERASE])
50adc8d746SAlan Cox #define LNEXT_CHAR(tty)	((tty)->termios.c_cc[VLNEXT])
51adc8d746SAlan Cox #define EOL2_CHAR(tty) ((tty)->termios.c_cc[VEOL2])
521da177e4SLinus Torvalds 
53adc8d746SAlan Cox #define _I_FLAG(tty, f)	((tty)->termios.c_iflag & (f))
54adc8d746SAlan Cox #define _O_FLAG(tty, f)	((tty)->termios.c_oflag & (f))
55adc8d746SAlan Cox #define _C_FLAG(tty, f)	((tty)->termios.c_cflag & (f))
56adc8d746SAlan Cox #define _L_FLAG(tty, f)	((tty)->termios.c_lflag & (f))
571da177e4SLinus Torvalds 
581da177e4SLinus Torvalds #define I_IGNBRK(tty)	_I_FLAG((tty), IGNBRK)
591da177e4SLinus Torvalds #define I_BRKINT(tty)	_I_FLAG((tty), BRKINT)
601da177e4SLinus Torvalds #define I_IGNPAR(tty)	_I_FLAG((tty), IGNPAR)
611da177e4SLinus Torvalds #define I_PARMRK(tty)	_I_FLAG((tty), PARMRK)
621da177e4SLinus Torvalds #define I_INPCK(tty)	_I_FLAG((tty), INPCK)
631da177e4SLinus Torvalds #define I_ISTRIP(tty)	_I_FLAG((tty), ISTRIP)
641da177e4SLinus Torvalds #define I_INLCR(tty)	_I_FLAG((tty), INLCR)
651da177e4SLinus Torvalds #define I_IGNCR(tty)	_I_FLAG((tty), IGNCR)
661da177e4SLinus Torvalds #define I_ICRNL(tty)	_I_FLAG((tty), ICRNL)
671da177e4SLinus Torvalds #define I_IUCLC(tty)	_I_FLAG((tty), IUCLC)
681da177e4SLinus Torvalds #define I_IXON(tty)	_I_FLAG((tty), IXON)
691da177e4SLinus Torvalds #define I_IXANY(tty)	_I_FLAG((tty), IXANY)
701da177e4SLinus Torvalds #define I_IXOFF(tty)	_I_FLAG((tty), IXOFF)
711da177e4SLinus Torvalds #define I_IMAXBEL(tty)	_I_FLAG((tty), IMAXBEL)
721da177e4SLinus Torvalds #define I_IUTF8(tty)	_I_FLAG((tty), IUTF8)
731da177e4SLinus Torvalds 
741da177e4SLinus Torvalds #define O_OPOST(tty)	_O_FLAG((tty), OPOST)
751da177e4SLinus Torvalds #define O_OLCUC(tty)	_O_FLAG((tty), OLCUC)
761da177e4SLinus Torvalds #define O_ONLCR(tty)	_O_FLAG((tty), ONLCR)
771da177e4SLinus Torvalds #define O_OCRNL(tty)	_O_FLAG((tty), OCRNL)
781da177e4SLinus Torvalds #define O_ONOCR(tty)	_O_FLAG((tty), ONOCR)
791da177e4SLinus Torvalds #define O_ONLRET(tty)	_O_FLAG((tty), ONLRET)
801da177e4SLinus Torvalds #define O_OFILL(tty)	_O_FLAG((tty), OFILL)
811da177e4SLinus Torvalds #define O_OFDEL(tty)	_O_FLAG((tty), OFDEL)
821da177e4SLinus Torvalds #define O_NLDLY(tty)	_O_FLAG((tty), NLDLY)
831da177e4SLinus Torvalds #define O_CRDLY(tty)	_O_FLAG((tty), CRDLY)
841da177e4SLinus Torvalds #define O_TABDLY(tty)	_O_FLAG((tty), TABDLY)
851da177e4SLinus Torvalds #define O_BSDLY(tty)	_O_FLAG((tty), BSDLY)
861da177e4SLinus Torvalds #define O_VTDLY(tty)	_O_FLAG((tty), VTDLY)
871da177e4SLinus Torvalds #define O_FFDLY(tty)	_O_FLAG((tty), FFDLY)
881da177e4SLinus Torvalds 
891da177e4SLinus Torvalds #define C_BAUD(tty)	_C_FLAG((tty), CBAUD)
901da177e4SLinus Torvalds #define C_CSIZE(tty)	_C_FLAG((tty), CSIZE)
911da177e4SLinus Torvalds #define C_CSTOPB(tty)	_C_FLAG((tty), CSTOPB)
921da177e4SLinus Torvalds #define C_CREAD(tty)	_C_FLAG((tty), CREAD)
931da177e4SLinus Torvalds #define C_PARENB(tty)	_C_FLAG((tty), PARENB)
941da177e4SLinus Torvalds #define C_PARODD(tty)	_C_FLAG((tty), PARODD)
951da177e4SLinus Torvalds #define C_HUPCL(tty)	_C_FLAG((tty), HUPCL)
961da177e4SLinus Torvalds #define C_CLOCAL(tty)	_C_FLAG((tty), CLOCAL)
971da177e4SLinus Torvalds #define C_CIBAUD(tty)	_C_FLAG((tty), CIBAUD)
981da177e4SLinus Torvalds #define C_CRTSCTS(tty)	_C_FLAG((tty), CRTSCTS)
99e58b57a3SAndrew Lunn #define C_CMSPAR(tty)	_C_FLAG((tty), CMSPAR)
1001da177e4SLinus Torvalds 
1011da177e4SLinus Torvalds #define L_ISIG(tty)	_L_FLAG((tty), ISIG)
1021da177e4SLinus Torvalds #define L_ICANON(tty)	_L_FLAG((tty), ICANON)
1031da177e4SLinus Torvalds #define L_XCASE(tty)	_L_FLAG((tty), XCASE)
1041da177e4SLinus Torvalds #define L_ECHO(tty)	_L_FLAG((tty), ECHO)
1051da177e4SLinus Torvalds #define L_ECHOE(tty)	_L_FLAG((tty), ECHOE)
1061da177e4SLinus Torvalds #define L_ECHOK(tty)	_L_FLAG((tty), ECHOK)
1071da177e4SLinus Torvalds #define L_ECHONL(tty)	_L_FLAG((tty), ECHONL)
1081da177e4SLinus Torvalds #define L_NOFLSH(tty)	_L_FLAG((tty), NOFLSH)
1091da177e4SLinus Torvalds #define L_TOSTOP(tty)	_L_FLAG((tty), TOSTOP)
1101da177e4SLinus Torvalds #define L_ECHOCTL(tty)	_L_FLAG((tty), ECHOCTL)
1111da177e4SLinus Torvalds #define L_ECHOPRT(tty)	_L_FLAG((tty), ECHOPRT)
1121da177e4SLinus Torvalds #define L_ECHOKE(tty)	_L_FLAG((tty), ECHOKE)
1131da177e4SLinus Torvalds #define L_FLUSHO(tty)	_L_FLAG((tty), FLUSHO)
1141da177e4SLinus Torvalds #define L_PENDIN(tty)	_L_FLAG((tty), PENDIN)
1151da177e4SLinus Torvalds #define L_IEXTEN(tty)	_L_FLAG((tty), IEXTEN)
11626df6d13Shyc@symas.com #define L_EXTPROC(tty)	_L_FLAG((tty), EXTPROC)
1171da177e4SLinus Torvalds 
1181da177e4SLinus Torvalds struct device;
119522ed776SMiloslav Trmac struct signal_struct;
120f34d7a5bSAlan Cox struct tty_operations;
121f34d7a5bSAlan Cox 
1226e94dbc7SJiri Slaby /**
1236e94dbc7SJiri Slaby  * struct tty_struct - state associated with a tty while open
1246e94dbc7SJiri Slaby  *
12518e6c075SJiri Slaby  * @kref: reference counting by tty_kref_get() and tty_kref_put(), reaching zero
12618e6c075SJiri Slaby  *	  frees the structure
12718e6c075SJiri Slaby  * @dev: class device or %NULL (e.g. ptys, serdev)
12818e6c075SJiri Slaby  * @driver: &struct tty_driver operating this tty
12918e6c075SJiri Slaby  * @ops: &struct tty_operations of @driver for this tty (open, close, etc.)
13018e6c075SJiri Slaby  * @index: index of this tty (e.g. to construct @name like tty12)
13118e6c075SJiri Slaby  * @ldisc_sem: protects line discipline changes (@ldisc) -- lock tty not pty
13218e6c075SJiri Slaby  * @ldisc: the current line discipline for this tty (n_tty by default)
13318e6c075SJiri Slaby  * @atomic_write_lock: protects against concurrent writers, i.e. locks
13418e6c075SJiri Slaby  *		       @write_cnt, @write_buf and similar
13518e6c075SJiri Slaby  * @legacy_mutex: leftover from history (BKL -> BTM -> @legacy_mutex),
13618e6c075SJiri Slaby  *		  protecting several operations on this tty
13718e6c075SJiri Slaby  * @throttle_mutex: protects against concurrent tty_throttle_safe() and
13818e6c075SJiri Slaby  *		    tty_unthrottle_safe() (but not tty_unthrottle())
13918e6c075SJiri Slaby  * @termios_rwsem: protects @termios and @termios_locked
14018e6c075SJiri Slaby  * @winsize_mutex: protects @winsize
14118e6c075SJiri Slaby  * @termios: termios for the current tty, copied from/to @driver.termios
14218e6c075SJiri Slaby  * @termios_locked: locked termios (by %TIOCGLCKTRMIOS and %TIOCSLCKTRMIOS
14318e6c075SJiri Slaby  *		    ioctls)
14418e6c075SJiri Slaby  * @name: name of the tty constructed by tty_line_name() (e.g. ttyS3)
14518e6c075SJiri Slaby  * @flags: bitwise OR of %TTY_THROTTLED, %TTY_IO_ERROR, ...
14618e6c075SJiri Slaby  * @count: count of open processes, reaching zero cancels all the work for
14718e6c075SJiri Slaby  *	   this tty and drops a @kref too (but does not free this tty)
14818e6c075SJiri Slaby  * @winsize: size of the terminal "window" (cf. @winsize_mutex)
14918e6c075SJiri Slaby  * @flow: flow settings grouped together, see also @flow.unused
15018e6c075SJiri Slaby  * @flow.lock: lock for @flow members
15118e6c075SJiri Slaby  * @flow.stopped: tty stopped/started by stop_tty()/start_tty()
15218e6c075SJiri Slaby  * @flow.tco_stopped: tty stopped/started by %TCOOFF/%TCOON ioctls (it has
15318e6c075SJiri Slaby  *		      precedence over @flow.stopped)
1546e94dbc7SJiri Slaby  * @flow.unused: alignment for Alpha, so that no members other than @flow.* are
1556e94dbc7SJiri Slaby  *		 modified by the same 64b word store. The @flow's __aligned is
1566e94dbc7SJiri Slaby  *		 there for the very same reason.
15718e6c075SJiri Slaby  * @ctrl: control settings grouped together, see also @ctrl.unused
15818e6c075SJiri Slaby  * @ctrl.lock: lock for @ctrl members
15964d608dbSJiri Slaby  * @ctrl.pgrp: process group of this tty (setpgrp(2))
16064d608dbSJiri Slaby  * @ctrl.session: session of this tty (setsid(2)). Writes are protected by both
16118e6c075SJiri Slaby  *		  @ctrl.lock and @legacy_mutex, readers must use at least one of
16264d608dbSJiri Slaby  *		  them.
16318e6c075SJiri Slaby  * @ctrl.pktstatus: packet mode status (bitwise OR of %TIOCPKT_ constants)
16464d608dbSJiri Slaby  * @ctrl.packet: packet mode enabled
16518e6c075SJiri Slaby  * @ctrl.unused: alignment for Alpha, see @flow.unused for explanation
16618e6c075SJiri Slaby  * @hw_stopped: not controlled by the tty layer, under @driver's control for CTS
16718e6c075SJiri Slaby  *		handling
16818e6c075SJiri Slaby  * @receive_room: bytes permitted to feed to @ldisc without any being lost
16918e6c075SJiri Slaby  * @flow_change: controls behavior of throttling, see tty_throttle_safe() and
17018e6c075SJiri Slaby  *		 tty_unthrottle_safe()
17118e6c075SJiri Slaby  * @link: link to another pty (master -> slave and vice versa)
17218e6c075SJiri Slaby  * @fasync: state for %O_ASYNC (for %SIGIO); managed by fasync_helper()
17318e6c075SJiri Slaby  * @write_wait: concurrent writers are waiting in this queue until they are
17418e6c075SJiri Slaby  *		allowed to write
17518e6c075SJiri Slaby  * @read_wait: readers wait for data in this queue
17618e6c075SJiri Slaby  * @hangup_work: normally a work to perform a hangup (do_tty_hangup()); while
17718e6c075SJiri Slaby  *		 freeing the tty, (re)used to release_one_tty()
17818e6c075SJiri Slaby  * @disc_data: pointer to @ldisc's private data (e.g. to &struct n_tty_data)
17918e6c075SJiri Slaby  * @driver_data: pointer to @driver's private data (e.g. &struct uart_state)
18018e6c075SJiri Slaby  * @files_lock:	protects @tty_files list
18118e6c075SJiri Slaby  * @tty_files: list of (re)openers of this tty (i.e. linked &struct
18218e6c075SJiri Slaby  *	       tty_file_private)
18318e6c075SJiri Slaby  * @closing: when set during close, n_tty processes only START & STOP chars
18418e6c075SJiri Slaby  * @write_buf: temporary buffer used during tty_write() to copy user data to
18518e6c075SJiri Slaby  * @write_cnt: count of bytes written in tty_write() to @write_buf
18618e6c075SJiri Slaby  * @SAK_work: if the tty has a pending do_SAK, it is queued here
18718e6c075SJiri Slaby  * @port: persistent storage for this device (i.e. &struct tty_port)
1886e94dbc7SJiri Slaby  *
1896e94dbc7SJiri Slaby  * All of the state associated with a tty while the tty is open. Persistent
19018e6c075SJiri Slaby  * storage for tty devices is referenced here as @port and is documented in
19118e6c075SJiri Slaby  * &struct tty_port.
1926e94dbc7SJiri Slaby  */
1931da177e4SLinus Torvalds struct tty_struct {
1949c9f4dedSAlan Cox 	struct kref kref;
195*ebf05c7dSGreg Kroah-Hartman 	int index;
19618e6c075SJiri Slaby 	struct device *dev;
1971da177e4SLinus Torvalds 	struct tty_driver *driver;
198*ebf05c7dSGreg Kroah-Hartman 	struct tty_port *port;
199f34d7a5bSAlan Cox 	const struct tty_operations *ops;
200c65c9bc3SAlan Cox 
201c65c9bc3SAlan Cox 	struct tty_ldisc *ldisc;
202*ebf05c7dSGreg Kroah-Hartman 	struct ld_semaphore ldisc_sem;
203c65c9bc3SAlan Cox 
204bddc7152SJiri Slaby 	struct mutex atomic_write_lock;
20589c8d91eSAlan Cox 	struct mutex legacy_mutex;
206d8c1f929SPeter Hurley 	struct mutex throttle_mutex;
2076a1c0680SPeter Hurley 	struct rw_semaphore termios_rwsem;
208dee4a0beSPeter Hurley 	struct mutex winsize_mutex;
209adc8d746SAlan Cox 	struct ktermios termios, termios_locked;
2101da177e4SLinus Torvalds 	char name[64];
2111da177e4SLinus Torvalds 	unsigned long flags;
2121da177e4SLinus Torvalds 	int count;
213*ebf05c7dSGreg Kroah-Hartman 	unsigned int receive_room;
21418e6c075SJiri Slaby 	struct winsize winsize;
2156e94dbc7SJiri Slaby 
2166e94dbc7SJiri Slaby 	struct {
2176e94dbc7SJiri Slaby 		spinlock_t lock;
2186e94dbc7SJiri Slaby 		bool stopped;
2196e94dbc7SJiri Slaby 		bool tco_stopped;
2206e94dbc7SJiri Slaby 		unsigned long unused[0];
2216e94dbc7SJiri Slaby 	} __aligned(sizeof(unsigned long)) flow;
2226e94dbc7SJiri Slaby 
22364d608dbSJiri Slaby 	struct {
22464d608dbSJiri Slaby 		struct pid *pgrp;
22564d608dbSJiri Slaby 		struct pid *session;
226*ebf05c7dSGreg Kroah-Hartman 		spinlock_t lock;
22764d608dbSJiri Slaby 		unsigned char pktstatus;
22864d608dbSJiri Slaby 		bool packet;
22964d608dbSJiri Slaby 		unsigned long unused[0];
23064d608dbSJiri Slaby 	} __aligned(sizeof(unsigned long)) ctrl;
23164d608dbSJiri Slaby 
232035173c9SIlpo Järvinen 	bool hw_stopped;
233*ebf05c7dSGreg Kroah-Hartman 	bool closing;
23470bc1264SPeter Hurley 	int flow_change;
2351da177e4SLinus Torvalds 
2361da177e4SLinus Torvalds 	struct tty_struct *link;
2371da177e4SLinus Torvalds 	struct fasync_struct *fasync;
2381da177e4SLinus Torvalds 	wait_queue_head_t write_wait;
2391da177e4SLinus Torvalds 	wait_queue_head_t read_wait;
2401da177e4SLinus Torvalds 	struct work_struct hangup_work;
2411da177e4SLinus Torvalds 	void *disc_data;
2421da177e4SLinus Torvalds 	void *driver_data;
24318e6c075SJiri Slaby 	spinlock_t files_lock;
244*ebf05c7dSGreg Kroah-Hartman 	int write_cnt;
245*ebf05c7dSGreg Kroah-Hartman 	unsigned char *write_buf;
246*ebf05c7dSGreg Kroah-Hartman 
2471da177e4SLinus Torvalds 	struct list_head tty_files;
2481da177e4SLinus Torvalds 
2491da177e4SLinus Torvalds #define N_TTY_BUF_SIZE 4096
2501da177e4SLinus Torvalds 	struct work_struct SAK_work;
2513859a271SKees Cook } __randomize_layout;
2521da177e4SLinus Torvalds 
253d996b62aSNick Piggin /* Each of a tty's open files has private_data pointing to tty_file_private */
254d996b62aSNick Piggin struct tty_file_private {
255d996b62aSNick Piggin 	struct tty_struct *tty;
256d996b62aSNick Piggin 	struct file *file;
257d996b62aSNick Piggin 	struct list_head list;
258d996b62aSNick Piggin };
259d996b62aSNick Piggin 
2604072254fSJiri Slaby /**
2614072254fSJiri Slaby  * DOC: TTY Struct Flags
2624072254fSJiri Slaby  *
2634072254fSJiri Slaby  * These bits are used in the :c:member:`tty_struct.flags` field.
2641da177e4SLinus Torvalds  *
2651da177e4SLinus Torvalds  * So that interrupts won't be able to mess up the queues,
2661da177e4SLinus Torvalds  * copy_to_cooked must be atomic with respect to itself, as must
2671da177e4SLinus Torvalds  * tty->write.  Thus, you must use the inline functions set_bit() and
2681da177e4SLinus Torvalds  * clear_bit() to make things atomic.
2694072254fSJiri Slaby  *
2704072254fSJiri Slaby  * TTY_THROTTLED
2714072254fSJiri Slaby  *	Driver input is throttled. The ldisc should call
2724072254fSJiri Slaby  *	:c:member:`tty_driver.unthrottle()` in order to resume reception when
2734072254fSJiri Slaby  *	it is ready to process more data (at threshold min).
2744072254fSJiri Slaby  *
2754072254fSJiri Slaby  * TTY_IO_ERROR
2764072254fSJiri Slaby  *	If set, causes all subsequent userspace read/write calls on the tty to
2774072254fSJiri Slaby  *	fail, returning -%EIO. (May be no ldisc too.)
2784072254fSJiri Slaby  *
2794072254fSJiri Slaby  * TTY_OTHER_CLOSED
2804072254fSJiri Slaby  *	Device is a pty and the other side has closed.
2814072254fSJiri Slaby  *
2824072254fSJiri Slaby  * TTY_EXCLUSIVE
2834072254fSJiri Slaby  *	Exclusive open mode (a single opener).
2844072254fSJiri Slaby  *
2854072254fSJiri Slaby  * TTY_DO_WRITE_WAKEUP
2864072254fSJiri Slaby  *	If set, causes the driver to call the
2874072254fSJiri Slaby  *	:c:member:`tty_ldisc_ops.write_wakeup()` method in order to resume
2884072254fSJiri Slaby  *	transmission when it can accept more data to transmit.
2894072254fSJiri Slaby  *
2904072254fSJiri Slaby  * TTY_LDISC_OPEN
2914072254fSJiri Slaby  *	Indicates that a line discipline is open. For debugging purposes only.
2924072254fSJiri Slaby  *
2934072254fSJiri Slaby  * TTY_PTY_LOCK
2944072254fSJiri Slaby  *	A flag private to pty code to implement %TIOCSPTLCK/%TIOCGPTLCK logic.
2954072254fSJiri Slaby  *
2964072254fSJiri Slaby  * TTY_NO_WRITE_SPLIT
2974072254fSJiri Slaby  *	Prevent driver from splitting up writes into smaller chunks (preserve
2984072254fSJiri Slaby  *	write boundaries to driver).
2994072254fSJiri Slaby  *
3004072254fSJiri Slaby  * TTY_HUPPED
3014072254fSJiri Slaby  *	The TTY was hung up. This is set post :c:member:`tty_driver.hangup()`.
3024072254fSJiri Slaby  *
3034072254fSJiri Slaby  * TTY_HUPPING
3044072254fSJiri Slaby  *	The TTY is in the process of hanging up to abort potential readers.
3054072254fSJiri Slaby  *
3064072254fSJiri Slaby  * TTY_LDISC_CHANGING
3074072254fSJiri Slaby  *	Line discipline for this TTY is being changed. I/O should not block
3084072254fSJiri Slaby  *	when this is set. Use tty_io_nonblock() to check.
3094072254fSJiri Slaby  *
3104072254fSJiri Slaby  * TTY_LDISC_HALTED
3114072254fSJiri Slaby  *	Line discipline for this TTY was stopped. No work should be queued to
3124072254fSJiri Slaby  *	this ldisc.
3131da177e4SLinus Torvalds  */
3144072254fSJiri Slaby #define TTY_THROTTLED		0
3154072254fSJiri Slaby #define TTY_IO_ERROR		1
3164072254fSJiri Slaby #define TTY_OTHER_CLOSED	2
3174072254fSJiri Slaby #define TTY_EXCLUSIVE		3
3184072254fSJiri Slaby #define TTY_DO_WRITE_WAKEUP	5
3194072254fSJiri Slaby #define TTY_LDISC_OPEN		11
3204072254fSJiri Slaby #define TTY_PTY_LOCK		16
3214072254fSJiri Slaby #define TTY_NO_WRITE_SPLIT	17
3224072254fSJiri Slaby #define TTY_HUPPED		18
3234072254fSJiri Slaby #define TTY_HUPPING		19
3244072254fSJiri Slaby #define TTY_LDISC_CHANGING	20
3254072254fSJiri Slaby #define TTY_LDISC_HALTED	22
3261da177e4SLinus Torvalds 
tty_io_nonblock(struct tty_struct * tty,struct file * file)327c96cf923SDmitry Safonov static inline bool tty_io_nonblock(struct tty_struct *tty, struct file *file)
328c96cf923SDmitry Safonov {
329c96cf923SDmitry Safonov 	return file->f_flags & O_NONBLOCK ||
330c96cf923SDmitry Safonov 		test_bit(TTY_LDISC_CHANGING, &tty->flags);
331c96cf923SDmitry Safonov }
332c96cf923SDmitry Safonov 
tty_io_error(struct tty_struct * tty)33318900ca6SPeter Hurley static inline bool tty_io_error(struct tty_struct *tty)
33418900ca6SPeter Hurley {
33518900ca6SPeter Hurley 	return test_bit(TTY_IO_ERROR, &tty->flags);
33618900ca6SPeter Hurley }
33718900ca6SPeter Hurley 
tty_throttled(struct tty_struct * tty)33897ef38b8SPeter Hurley static inline bool tty_throttled(struct tty_struct *tty)
33997ef38b8SPeter Hurley {
34097ef38b8SPeter Hurley 	return test_bit(TTY_THROTTLED, &tty->flags);
34197ef38b8SPeter Hurley }
34297ef38b8SPeter Hurley 
3434f73bc4dSJoe Millenbach #ifdef CONFIG_TTY
34478941934SJiri Slaby void tty_kref_put(struct tty_struct *tty);
34578941934SJiri Slaby struct pid *tty_get_pgrp(struct tty_struct *tty);
34678941934SJiri Slaby void tty_vhangup_self(void);
34778941934SJiri Slaby void disassociate_ctty(int priv);
34878941934SJiri Slaby dev_t tty_devnum(struct tty_struct *tty);
34978941934SJiri Slaby void proc_clear_tty(struct task_struct *p);
35078941934SJiri Slaby struct tty_struct *get_current_tty(void);
3514f73bc4dSJoe Millenbach /* tty_io.c */
35278941934SJiri Slaby int __init tty_init(void);
35378941934SJiri Slaby const char *tty_name(const struct tty_struct *tty);
35478941934SJiri Slaby struct tty_struct *tty_kopen_exclusive(dev_t device);
35578941934SJiri Slaby struct tty_struct *tty_kopen_shared(dev_t device);
35678941934SJiri Slaby void tty_kclose(struct tty_struct *tty);
35778941934SJiri Slaby int tty_dev_name_to_number(const char *name, dev_t *number);
3584f73bc4dSJoe Millenbach #else
tty_kref_put(struct tty_struct * tty)3594f73bc4dSJoe Millenbach static inline void tty_kref_put(struct tty_struct *tty)
3604f73bc4dSJoe Millenbach { }
tty_get_pgrp(struct tty_struct * tty)3614f73bc4dSJoe Millenbach static inline struct pid *tty_get_pgrp(struct tty_struct *tty)
3624f73bc4dSJoe Millenbach { return NULL; }
tty_vhangup_self(void)3634f73bc4dSJoe Millenbach static inline void tty_vhangup_self(void)
3644f73bc4dSJoe Millenbach { }
disassociate_ctty(int priv)3654f73bc4dSJoe Millenbach static inline void disassociate_ctty(int priv)
3664f73bc4dSJoe Millenbach { }
tty_devnum(struct tty_struct * tty)3674f73bc4dSJoe Millenbach static inline dev_t tty_devnum(struct tty_struct *tty)
3684f73bc4dSJoe Millenbach { return 0; }
proc_clear_tty(struct task_struct * p)3694f73bc4dSJoe Millenbach static inline void proc_clear_tty(struct task_struct *p)
3704f73bc4dSJoe Millenbach { }
get_current_tty(void)3714f73bc4dSJoe Millenbach static inline struct tty_struct *get_current_tty(void)
3724f73bc4dSJoe Millenbach { return NULL; }
3734f73bc4dSJoe Millenbach /* tty_io.c */
tty_init(void)3744f73bc4dSJoe Millenbach static inline int __init tty_init(void)
3754f73bc4dSJoe Millenbach { return 0; }
tty_name(const struct tty_struct * tty)376188e3c5cSArnd Bergmann static inline const char *tty_name(const struct tty_struct *tty)
377188e3c5cSArnd Bergmann { return "(none)"; }
tty_kopen_exclusive(dev_t device)3784ea3cd65SUwe Kleine-König static inline struct tty_struct *tty_kopen_exclusive(dev_t device)
379a09ac397SOkash Khawaja { return ERR_PTR(-ENODEV); }
tty_kclose(struct tty_struct * tty)380a09ac397SOkash Khawaja static inline void tty_kclose(struct tty_struct *tty)
381a09ac397SOkash Khawaja { }
tty_dev_name_to_number(const char * name,dev_t * number)382fc61ed51SOkash Khawaja static inline int tty_dev_name_to_number(const char *name, dev_t *number)
383fc61ed51SOkash Khawaja { return -ENOTSUPP; }
3844f73bc4dSJoe Millenbach #endif
3854f73bc4dSJoe Millenbach 
386edc6afc5SAlan Cox extern struct ktermios tty_std_termios;
3871da177e4SLinus Torvalds 
38878941934SJiri Slaby int vcs_init(void);
3891da177e4SLinus Torvalds 
390862d8312SGreg Kroah-Hartman extern const struct class tty_class;
391d81ed103SAlan Cox 
3929c9f4dedSAlan Cox /**
3939c9f4dedSAlan Cox  *	tty_kref_get		-	get a tty reference
3949c9f4dedSAlan Cox  *	@tty: tty device
3959c9f4dedSAlan Cox  *
3969c9f4dedSAlan Cox  *	Return a new reference to a tty object. The caller must hold
3979c9f4dedSAlan Cox  *	sufficient locks/counts to ensure that their existing reference cannot
3989c9f4dedSAlan Cox  *	go away
3999c9f4dedSAlan Cox  */
4009c9f4dedSAlan Cox 
tty_kref_get(struct tty_struct * tty)40114bfc987SIngo Molnar static inline struct tty_struct *tty_kref_get(struct tty_struct *tty)
4029c9f4dedSAlan Cox {
4039c9f4dedSAlan Cox 	if (tty)
4049c9f4dedSAlan Cox 		kref_get(&tty->kref);
4059c9f4dedSAlan Cox 	return tty;
4069c9f4dedSAlan Cox }
4079c9f4dedSAlan Cox 
40878941934SJiri Slaby const char *tty_driver_name(const struct tty_struct *tty);
40978941934SJiri Slaby void tty_wait_until_sent(struct tty_struct *tty, long timeout);
41078941934SJiri Slaby void stop_tty(struct tty_struct *tty);
41178941934SJiri Slaby void start_tty(struct tty_struct *tty);
41278941934SJiri Slaby void tty_write_message(struct tty_struct *tty, char *msg);
41378941934SJiri Slaby int tty_send_xchar(struct tty_struct *tty, char ch);
41478941934SJiri Slaby int tty_put_char(struct tty_struct *tty, unsigned char c);
41578941934SJiri Slaby unsigned int tty_chars_in_buffer(struct tty_struct *tty);
41678941934SJiri Slaby unsigned int tty_write_room(struct tty_struct *tty);
41778941934SJiri Slaby void tty_driver_flush_buffer(struct tty_struct *tty);
41878941934SJiri Slaby void tty_unthrottle(struct tty_struct *tty);
41978941934SJiri Slaby int tty_throttle_safe(struct tty_struct *tty);
42078941934SJiri Slaby int tty_unthrottle_safe(struct tty_struct *tty);
42178941934SJiri Slaby int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
42278941934SJiri Slaby int tty_get_icount(struct tty_struct *tty,
423d20c219cSUwe Kleine-König 		struct serial_icounter_struct *icount);
42478941934SJiri Slaby int is_current_pgrp_orphaned(void);
42578941934SJiri Slaby void tty_hangup(struct tty_struct *tty);
42678941934SJiri Slaby void tty_vhangup(struct tty_struct *tty);
42778941934SJiri Slaby int tty_hung_up_p(struct file *filp);
42878941934SJiri Slaby void do_SAK(struct tty_struct *tty);
42978941934SJiri Slaby void __do_SAK(struct tty_struct *tty);
43078941934SJiri Slaby void no_tty(void);
43187888fb9SIlpo Järvinen speed_t tty_termios_baud_rate(const struct ktermios *termios);
43278941934SJiri Slaby void tty_termios_encode_baud_rate(struct ktermios *termios, speed_t ibaud,
43378941934SJiri Slaby 		speed_t obaud);
43478941934SJiri Slaby void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud,
43578941934SJiri Slaby 		speed_t obaud);
4366865ff22SJiri Slaby 
4376865ff22SJiri Slaby /**
4386865ff22SJiri Slaby  *	tty_get_baud_rate	-	get tty bit rates
4396865ff22SJiri Slaby  *	@tty: tty to query
4406865ff22SJiri Slaby  *
4416865ff22SJiri Slaby  *	Returns the baud rate as an integer for this terminal. The
4426865ff22SJiri Slaby  *	termios lock must be held by the caller and the terminal bit
4436865ff22SJiri Slaby  *	flags may be updated.
4446865ff22SJiri Slaby  *
4456865ff22SJiri Slaby  *	Locking: none
4466865ff22SJiri Slaby  */
tty_get_baud_rate(struct tty_struct * tty)4476865ff22SJiri Slaby static inline speed_t tty_get_baud_rate(struct tty_struct *tty)
4486865ff22SJiri Slaby {
4496865ff22SJiri Slaby 	return tty_termios_baud_rate(&tty->termios);
4506865ff22SJiri Slaby }
4516865ff22SJiri Slaby 
452654ee49bSJiri Slaby unsigned char tty_get_char_size(unsigned int cflag);
453654ee49bSJiri Slaby unsigned char tty_get_frame_size(unsigned int cflag);
454654ee49bSJiri Slaby 
455d15f89d9SIlpo Järvinen void tty_termios_copy_hw(struct ktermios *new, const struct ktermios *old);
45687f22db4SIlpo Järvinen bool tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
45778941934SJiri Slaby int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
4581da177e4SLinus Torvalds 
45978941934SJiri Slaby void tty_wakeup(struct tty_struct *tty);
4601da177e4SLinus Torvalds 
461dcc223e8SJiri Slaby int tty_mode_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
46278941934SJiri Slaby int tty_perform_flush(struct tty_struct *tty, unsigned long arg);
46378941934SJiri Slaby struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
46478941934SJiri Slaby void tty_release_struct(struct tty_struct *tty, int idx);
46578941934SJiri Slaby void tty_init_termios(struct tty_struct *tty);
46678941934SJiri Slaby void tty_save_termios(struct tty_struct *tty);
46778941934SJiri Slaby int tty_standard_install(struct tty_driver *driver,
46866d450e8SJiri Slaby 		struct tty_struct *tty);
46924ec839cSPeter Zijlstra 
47070522e12SIngo Molnar extern struct mutex tty_mutex;
4711da177e4SLinus Torvalds 
4721da177e4SLinus Torvalds /* n_tty.c */
47378941934SJiri Slaby void n_tty_inherit_ops(struct tty_ldisc_ops *ops);
4740c688614SNicolas Pitre #ifdef CONFIG_TTY
47578941934SJiri Slaby void __init n_tty_init(void);
4760c688614SNicolas Pitre #else
n_tty_init(void)4770c688614SNicolas Pitre static inline void n_tty_init(void) { }
4780c688614SNicolas Pitre #endif
4791da177e4SLinus Torvalds 
480522ed776SMiloslav Trmac /* tty_audit.c */
481522ed776SMiloslav Trmac #ifdef CONFIG_AUDIT
48278941934SJiri Slaby void tty_audit_exit(void);
48378941934SJiri Slaby void tty_audit_fork(struct signal_struct *sig);
48478941934SJiri Slaby int tty_audit_push(void);
485522ed776SMiloslav Trmac #else
tty_audit_exit(void)486522ed776SMiloslav Trmac static inline void tty_audit_exit(void)
487522ed776SMiloslav Trmac {
488522ed776SMiloslav Trmac }
tty_audit_fork(struct signal_struct * sig)489522ed776SMiloslav Trmac static inline void tty_audit_fork(struct signal_struct *sig)
490522ed776SMiloslav Trmac {
491522ed776SMiloslav Trmac }
tty_audit_push(void)49237282a77SPeter Hurley static inline int tty_audit_push(void)
493522ed776SMiloslav Trmac {
4943c80fe4aSThomas Gleixner 	return 0;
495522ed776SMiloslav Trmac }
496522ed776SMiloslav Trmac #endif
497522ed776SMiloslav Trmac 
4981da177e4SLinus Torvalds /* tty_ioctl.c */
4997c783601SJiri Slaby int n_tty_ioctl_helper(struct tty_struct *tty, unsigned int cmd,
5007c783601SJiri Slaby 		unsigned long arg);
5011da177e4SLinus Torvalds 
5021da177e4SLinus Torvalds /* vt.c */
5031da177e4SLinus Torvalds 
50478941934SJiri Slaby int vt_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
5051da177e4SLinus Torvalds 
50678941934SJiri Slaby long vt_compat_ioctl(struct tty_struct *tty, unsigned int cmd,
50778941934SJiri Slaby 		unsigned long arg);
508e9216651SArnd Bergmann 
509b07471faSArnd Bergmann /* tty_mutex.c */
510ec79d605SArnd Bergmann /* functions for preparation of BKL removal */
51178941934SJiri Slaby void tty_lock(struct tty_struct *tty);
51278941934SJiri Slaby int  tty_lock_interruptible(struct tty_struct *tty);
51378941934SJiri Slaby void tty_unlock(struct tty_struct *tty);
51478941934SJiri Slaby void tty_lock_slave(struct tty_struct *tty);
51578941934SJiri Slaby void tty_unlock_slave(struct tty_struct *tty);
51678941934SJiri Slaby void tty_set_lock_subclass(struct tty_struct *tty);
517be1bc288SArnd Bergmann 
5181da177e4SLinus Torvalds #endif
519