xref: /linux-6.15/include/linux/tty.h (revision 8d29e002)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_TTY_H
3 #define _LINUX_TTY_H
4 
5 #include <linux/fs.h>
6 #include <linux/major.h>
7 #include <linux/termios.h>
8 #include <linux/workqueue.h>
9 #include <linux/tty_buffer.h>
10 #include <linux/tty_driver.h>
11 #include <linux/tty_ldisc.h>
12 #include <linux/mutex.h>
13 #include <linux/tty_flags.h>
14 #include <uapi/linux/tty.h>
15 #include <linux/rwsem.h>
16 #include <linux/llist.h>
17 
18 
19 /*
20  * (Note: the *_driver.minor_start values 1, 64, 128, 192 are
21  * hardcoded at present.)
22  */
23 #define NR_UNIX98_PTY_DEFAULT	4096      /* Default maximum for Unix98 ptys */
24 #define NR_UNIX98_PTY_RESERVE	1024	  /* Default reserve for main devpts */
25 #define NR_UNIX98_PTY_MAX	(1 << MINORBITS) /* Absolute limit */
26 
27 /*
28  * This character is the same as _POSIX_VDISABLE: it cannot be used as
29  * a c_cc[] character, but indicates that a particular special character
30  * isn't in use (eg VINTR has no character etc)
31  */
32 #define __DISABLED_CHAR '\0'
33 
34 #define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR])
35 #define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT])
36 #define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE])
37 #define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL])
38 #define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF])
39 #define TIME_CHAR(tty) ((tty)->termios.c_cc[VTIME])
40 #define MIN_CHAR(tty) ((tty)->termios.c_cc[VMIN])
41 #define SWTC_CHAR(tty) ((tty)->termios.c_cc[VSWTC])
42 #define START_CHAR(tty) ((tty)->termios.c_cc[VSTART])
43 #define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP])
44 #define SUSP_CHAR(tty) ((tty)->termios.c_cc[VSUSP])
45 #define EOL_CHAR(tty) ((tty)->termios.c_cc[VEOL])
46 #define REPRINT_CHAR(tty) ((tty)->termios.c_cc[VREPRINT])
47 #define DISCARD_CHAR(tty) ((tty)->termios.c_cc[VDISCARD])
48 #define WERASE_CHAR(tty) ((tty)->termios.c_cc[VWERASE])
49 #define LNEXT_CHAR(tty)	((tty)->termios.c_cc[VLNEXT])
50 #define EOL2_CHAR(tty) ((tty)->termios.c_cc[VEOL2])
51 
52 #define _I_FLAG(tty, f)	((tty)->termios.c_iflag & (f))
53 #define _O_FLAG(tty, f)	((tty)->termios.c_oflag & (f))
54 #define _C_FLAG(tty, f)	((tty)->termios.c_cflag & (f))
55 #define _L_FLAG(tty, f)	((tty)->termios.c_lflag & (f))
56 
57 #define I_IGNBRK(tty)	_I_FLAG((tty), IGNBRK)
58 #define I_BRKINT(tty)	_I_FLAG((tty), BRKINT)
59 #define I_IGNPAR(tty)	_I_FLAG((tty), IGNPAR)
60 #define I_PARMRK(tty)	_I_FLAG((tty), PARMRK)
61 #define I_INPCK(tty)	_I_FLAG((tty), INPCK)
62 #define I_ISTRIP(tty)	_I_FLAG((tty), ISTRIP)
63 #define I_INLCR(tty)	_I_FLAG((tty), INLCR)
64 #define I_IGNCR(tty)	_I_FLAG((tty), IGNCR)
65 #define I_ICRNL(tty)	_I_FLAG((tty), ICRNL)
66 #define I_IUCLC(tty)	_I_FLAG((tty), IUCLC)
67 #define I_IXON(tty)	_I_FLAG((tty), IXON)
68 #define I_IXANY(tty)	_I_FLAG((tty), IXANY)
69 #define I_IXOFF(tty)	_I_FLAG((tty), IXOFF)
70 #define I_IMAXBEL(tty)	_I_FLAG((tty), IMAXBEL)
71 #define I_IUTF8(tty)	_I_FLAG((tty), IUTF8)
72 
73 #define O_OPOST(tty)	_O_FLAG((tty), OPOST)
74 #define O_OLCUC(tty)	_O_FLAG((tty), OLCUC)
75 #define O_ONLCR(tty)	_O_FLAG((tty), ONLCR)
76 #define O_OCRNL(tty)	_O_FLAG((tty), OCRNL)
77 #define O_ONOCR(tty)	_O_FLAG((tty), ONOCR)
78 #define O_ONLRET(tty)	_O_FLAG((tty), ONLRET)
79 #define O_OFILL(tty)	_O_FLAG((tty), OFILL)
80 #define O_OFDEL(tty)	_O_FLAG((tty), OFDEL)
81 #define O_NLDLY(tty)	_O_FLAG((tty), NLDLY)
82 #define O_CRDLY(tty)	_O_FLAG((tty), CRDLY)
83 #define O_TABDLY(tty)	_O_FLAG((tty), TABDLY)
84 #define O_BSDLY(tty)	_O_FLAG((tty), BSDLY)
85 #define O_VTDLY(tty)	_O_FLAG((tty), VTDLY)
86 #define O_FFDLY(tty)	_O_FLAG((tty), FFDLY)
87 
88 #define C_BAUD(tty)	_C_FLAG((tty), CBAUD)
89 #define C_CSIZE(tty)	_C_FLAG((tty), CSIZE)
90 #define C_CSTOPB(tty)	_C_FLAG((tty), CSTOPB)
91 #define C_CREAD(tty)	_C_FLAG((tty), CREAD)
92 #define C_PARENB(tty)	_C_FLAG((tty), PARENB)
93 #define C_PARODD(tty)	_C_FLAG((tty), PARODD)
94 #define C_HUPCL(tty)	_C_FLAG((tty), HUPCL)
95 #define C_CLOCAL(tty)	_C_FLAG((tty), CLOCAL)
96 #define C_CIBAUD(tty)	_C_FLAG((tty), CIBAUD)
97 #define C_CRTSCTS(tty)	_C_FLAG((tty), CRTSCTS)
98 #define C_CMSPAR(tty)	_C_FLAG((tty), CMSPAR)
99 
100 #define L_ISIG(tty)	_L_FLAG((tty), ISIG)
101 #define L_ICANON(tty)	_L_FLAG((tty), ICANON)
102 #define L_XCASE(tty)	_L_FLAG((tty), XCASE)
103 #define L_ECHO(tty)	_L_FLAG((tty), ECHO)
104 #define L_ECHOE(tty)	_L_FLAG((tty), ECHOE)
105 #define L_ECHOK(tty)	_L_FLAG((tty), ECHOK)
106 #define L_ECHONL(tty)	_L_FLAG((tty), ECHONL)
107 #define L_NOFLSH(tty)	_L_FLAG((tty), NOFLSH)
108 #define L_TOSTOP(tty)	_L_FLAG((tty), TOSTOP)
109 #define L_ECHOCTL(tty)	_L_FLAG((tty), ECHOCTL)
110 #define L_ECHOPRT(tty)	_L_FLAG((tty), ECHOPRT)
111 #define L_ECHOKE(tty)	_L_FLAG((tty), ECHOKE)
112 #define L_FLUSHO(tty)	_L_FLAG((tty), FLUSHO)
113 #define L_PENDIN(tty)	_L_FLAG((tty), PENDIN)
114 #define L_IEXTEN(tty)	_L_FLAG((tty), IEXTEN)
115 #define L_EXTPROC(tty)	_L_FLAG((tty), EXTPROC)
116 
117 struct device;
118 struct signal_struct;
119 
120 /*
121  * Port level information. Each device keeps its own port level information
122  * so provide a common structure for those ports wanting to use common support
123  * routines.
124  *
125  * The tty port has a different lifetime to the tty so must be kept apart.
126  * In addition be careful as tty -> port mappings are valid for the life
127  * of the tty object but in many cases port -> tty mappings are valid only
128  * until a hangup so don't use the wrong path.
129  */
130 
131 struct tty_port;
132 
133 struct tty_port_operations {
134 	/* Return 1 if the carrier is raised */
135 	int (*carrier_raised)(struct tty_port *port);
136 	/* Control the DTR line */
137 	void (*dtr_rts)(struct tty_port *port, int raise);
138 	/* Called when the last close completes or a hangup finishes
139 	   IFF the port was initialized. Do not use to free resources. Called
140 	   under the port mutex to serialize against activate/shutdowns */
141 	void (*shutdown)(struct tty_port *port);
142 	/* Called under the port mutex from tty_port_open, serialized using
143 	   the port mutex */
144         /* FIXME: long term getting the tty argument *out* of this would be
145            good for consoles */
146 	int (*activate)(struct tty_port *port, struct tty_struct *tty);
147 	/* Called on the final put of a port */
148 	void (*destruct)(struct tty_port *port);
149 };
150 
151 struct tty_port_client_operations {
152 	int (*receive_buf)(struct tty_port *port, const unsigned char *, const unsigned char *, size_t);
153 	void (*write_wakeup)(struct tty_port *port);
154 };
155 
156 extern const struct tty_port_client_operations tty_port_default_client_ops;
157 
158 struct tty_port {
159 	struct tty_bufhead	buf;		/* Locked internally */
160 	struct tty_struct	*tty;		/* Back pointer */
161 	struct tty_struct	*itty;		/* internal back ptr */
162 	const struct tty_port_operations *ops;	/* Port operations */
163 	const struct tty_port_client_operations *client_ops; /* Port client operations */
164 	spinlock_t		lock;		/* Lock protecting tty field */
165 	int			blocked_open;	/* Waiting to open */
166 	int			count;		/* Usage count */
167 	wait_queue_head_t	open_wait;	/* Open waiters */
168 	wait_queue_head_t	delta_msr_wait;	/* Modem status change */
169 	unsigned long		flags;		/* User TTY flags ASYNC_ */
170 	unsigned long		iflags;		/* Internal flags TTY_PORT_ */
171 	unsigned char		console:1;	/* port is a console */
172 	struct mutex		mutex;		/* Locking */
173 	struct mutex		buf_mutex;	/* Buffer alloc lock */
174 	unsigned char		*xmit_buf;	/* Optional buffer */
175 	unsigned int		close_delay;	/* Close port delay */
176 	unsigned int		closing_wait;	/* Delay for output */
177 	int			drain_delay;	/* Set to zero if no pure time
178 						   based drain is needed else
179 						   set to size of fifo */
180 	struct kref		kref;		/* Ref counter */
181 	void 			*client_data;
182 };
183 
184 /* tty_port::iflags bits -- use atomic bit ops */
185 #define TTY_PORT_INITIALIZED	0	/* device is initialized */
186 #define TTY_PORT_SUSPENDED	1	/* device is suspended */
187 #define TTY_PORT_ACTIVE		2	/* device is open */
188 
189 /*
190  * uart drivers: use the uart_port::status field and the UPSTAT_* defines
191  * for s/w-based flow control steering and carrier detection status
192  */
193 #define TTY_PORT_CTS_FLOW	3	/* h/w flow control enabled */
194 #define TTY_PORT_CHECK_CD	4	/* carrier detect enabled */
195 #define TTY_PORT_KOPENED	5	/* device exclusively opened by
196 					   kernel */
197 
198 struct tty_operations;
199 
200 /**
201  * struct tty_struct - state associated with a tty while open
202  *
203  * @flow.lock: lock for flow members
204  * @flow.stopped: tty stopped/started by tty_stop/tty_start
205  * @flow.tco_stopped: tty stopped/started by TCOOFF/TCOON ioctls (it has
206  *		      precedense over @flow.stopped)
207  * @flow.unused: alignment for Alpha, so that no members other than @flow.* are
208  *		 modified by the same 64b word store. The @flow's __aligned is
209  *		 there for the very same reason.
210  * @ctrl.lock: lock for ctrl members
211  * @ctrl.pgrp: process group of this tty (setpgrp(2))
212  * @ctrl.session: session of this tty (setsid(2)). Writes are protected by both
213  *		  @ctrl.lock and legacy mutex, readers must use at least one of
214  *		  them.
215  * @ctrl.pktstatus: packet mode status (bitwise OR of TIOCPKT_* constants)
216  * @ctrl.packet: packet mode enabled
217  *
218  * All of the state associated with a tty while the tty is open. Persistent
219  * storage for tty devices is referenced here as @port in struct tty_port.
220  */
221 struct tty_struct {
222 	int	magic;
223 	struct kref kref;
224 	struct device *dev;	/* class device or NULL (e.g. ptys, serdev) */
225 	struct tty_driver *driver;
226 	const struct tty_operations *ops;
227 	int index;
228 
229 	/* Protects ldisc changes: Lock tty not pty */
230 	struct ld_semaphore ldisc_sem;
231 	struct tty_ldisc *ldisc;
232 
233 	struct mutex atomic_write_lock;
234 	struct mutex legacy_mutex;
235 	struct mutex throttle_mutex;
236 	struct rw_semaphore termios_rwsem;
237 	struct mutex winsize_mutex;
238 	/* Termios values are protected by the termios rwsem */
239 	struct ktermios termios, termios_locked;
240 	char name[64];
241 	unsigned long flags;
242 	int count;
243 	struct winsize winsize;		/* winsize_mutex */
244 
245 	struct {
246 		spinlock_t lock;
247 		bool stopped;
248 		bool tco_stopped;
249 		unsigned long unused[0];
250 	} __aligned(sizeof(unsigned long)) flow;
251 
252 	struct {
253 		spinlock_t lock;
254 		struct pid *pgrp;
255 		struct pid *session;
256 		unsigned char pktstatus;
257 		bool packet;
258 		unsigned long unused[0];
259 	} __aligned(sizeof(unsigned long)) ctrl;
260 
261 	int hw_stopped;
262 	unsigned int receive_room;	/* Bytes free for queue */
263 	int flow_change;
264 
265 	struct tty_struct *link;
266 	struct fasync_struct *fasync;
267 	wait_queue_head_t write_wait;
268 	wait_queue_head_t read_wait;
269 	struct work_struct hangup_work;
270 	void *disc_data;
271 	void *driver_data;
272 	spinlock_t files_lock;		/* protects tty_files list */
273 	struct list_head tty_files;
274 
275 #define N_TTY_BUF_SIZE 4096
276 
277 	int closing;
278 	unsigned char *write_buf;
279 	int write_cnt;
280 	/* If the tty has a pending do_SAK, queue it here - akpm */
281 	struct work_struct SAK_work;
282 	struct tty_port *port;
283 } __randomize_layout;
284 
285 /* Each of a tty's open files has private_data pointing to tty_file_private */
286 struct tty_file_private {
287 	struct tty_struct *tty;
288 	struct file *file;
289 	struct list_head list;
290 };
291 
292 /* tty magic number */
293 #define TTY_MAGIC		0x5401
294 
295 /*
296  * These bits are used in the flags field of the tty structure.
297  *
298  * So that interrupts won't be able to mess up the queues,
299  * copy_to_cooked must be atomic with respect to itself, as must
300  * tty->write.  Thus, you must use the inline functions set_bit() and
301  * clear_bit() to make things atomic.
302  */
303 #define TTY_THROTTLED 		0	/* Call unthrottle() at threshold min */
304 #define TTY_IO_ERROR 		1	/* Cause an I/O error (may be no ldisc too) */
305 #define TTY_OTHER_CLOSED 	2	/* Other side (if any) has closed */
306 #define TTY_EXCLUSIVE 		3	/* Exclusive open mode */
307 #define TTY_DO_WRITE_WAKEUP 	5	/* Call write_wakeup after queuing new */
308 #define TTY_LDISC_OPEN	 	11	/* Line discipline is open */
309 #define TTY_PTY_LOCK 		16	/* pty private */
310 #define TTY_NO_WRITE_SPLIT 	17	/* Preserve write boundaries to driver */
311 #define TTY_HUPPED 		18	/* Post driver->hangup() */
312 #define TTY_HUPPING		19	/* Hangup in progress */
313 #define TTY_LDISC_CHANGING	20	/* Change pending - non-block IO */
314 #define TTY_LDISC_HALTED	22	/* Line discipline is halted */
315 
316 static inline bool tty_io_nonblock(struct tty_struct *tty, struct file *file)
317 {
318 	return file->f_flags & O_NONBLOCK ||
319 		test_bit(TTY_LDISC_CHANGING, &tty->flags);
320 }
321 
322 static inline bool tty_io_error(struct tty_struct *tty)
323 {
324 	return test_bit(TTY_IO_ERROR, &tty->flags);
325 }
326 
327 static inline bool tty_throttled(struct tty_struct *tty)
328 {
329 	return test_bit(TTY_THROTTLED, &tty->flags);
330 }
331 
332 #ifdef CONFIG_TTY
333 extern void tty_kref_put(struct tty_struct *tty);
334 extern struct pid *tty_get_pgrp(struct tty_struct *tty);
335 extern void tty_vhangup_self(void);
336 extern void disassociate_ctty(int priv);
337 extern dev_t tty_devnum(struct tty_struct *tty);
338 extern void proc_clear_tty(struct task_struct *p);
339 extern struct tty_struct *get_current_tty(void);
340 /* tty_io.c */
341 extern int __init tty_init(void);
342 extern const char *tty_name(const struct tty_struct *tty);
343 extern struct tty_struct *tty_kopen_exclusive(dev_t device);
344 extern struct tty_struct *tty_kopen_shared(dev_t device);
345 extern void tty_kclose(struct tty_struct *tty);
346 extern int tty_dev_name_to_number(const char *name, dev_t *number);
347 #else
348 static inline void tty_kref_put(struct tty_struct *tty)
349 { }
350 static inline struct pid *tty_get_pgrp(struct tty_struct *tty)
351 { return NULL; }
352 static inline void tty_vhangup_self(void)
353 { }
354 static inline void disassociate_ctty(int priv)
355 { }
356 static inline dev_t tty_devnum(struct tty_struct *tty)
357 { return 0; }
358 static inline void proc_clear_tty(struct task_struct *p)
359 { }
360 static inline struct tty_struct *get_current_tty(void)
361 { return NULL; }
362 /* tty_io.c */
363 static inline int __init tty_init(void)
364 { return 0; }
365 static inline const char *tty_name(const struct tty_struct *tty)
366 { return "(none)"; }
367 static inline struct tty_struct *tty_kopen_exclusive(dev_t device)
368 { return ERR_PTR(-ENODEV); }
369 static inline void tty_kclose(struct tty_struct *tty)
370 { }
371 static inline int tty_dev_name_to_number(const char *name, dev_t *number)
372 { return -ENOTSUPP; }
373 #endif
374 
375 extern struct ktermios tty_std_termios;
376 
377 extern int vcs_init(void);
378 
379 extern struct class *tty_class;
380 
381 /**
382  *	tty_kref_get		-	get a tty reference
383  *	@tty: tty device
384  *
385  *	Return a new reference to a tty object. The caller must hold
386  *	sufficient locks/counts to ensure that their existing reference cannot
387  *	go away
388  */
389 
390 static inline struct tty_struct *tty_kref_get(struct tty_struct *tty)
391 {
392 	if (tty)
393 		kref_get(&tty->kref);
394 	return tty;
395 }
396 
397 extern const char *tty_driver_name(const struct tty_struct *tty);
398 extern void tty_wait_until_sent(struct tty_struct *tty, long timeout);
399 extern void stop_tty(struct tty_struct *tty);
400 extern void start_tty(struct tty_struct *tty);
401 extern void tty_write_message(struct tty_struct *tty, char *msg);
402 extern int tty_send_xchar(struct tty_struct *tty, char ch);
403 extern int tty_put_char(struct tty_struct *tty, unsigned char c);
404 extern unsigned int tty_chars_in_buffer(struct tty_struct *tty);
405 extern unsigned int tty_write_room(struct tty_struct *tty);
406 extern void tty_driver_flush_buffer(struct tty_struct *tty);
407 extern void tty_unthrottle(struct tty_struct *tty);
408 extern int tty_throttle_safe(struct tty_struct *tty);
409 extern int tty_unthrottle_safe(struct tty_struct *tty);
410 extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
411 extern int tty_get_icount(struct tty_struct *tty,
412 			  struct serial_icounter_struct *icount);
413 extern int is_current_pgrp_orphaned(void);
414 extern void tty_hangup(struct tty_struct *tty);
415 extern void tty_vhangup(struct tty_struct *tty);
416 extern int tty_hung_up_p(struct file *filp);
417 extern void do_SAK(struct tty_struct *tty);
418 extern void __do_SAK(struct tty_struct *tty);
419 extern void no_tty(void);
420 extern speed_t tty_termios_baud_rate(struct ktermios *termios);
421 extern void tty_termios_encode_baud_rate(struct ktermios *termios,
422 						speed_t ibaud, speed_t obaud);
423 extern void tty_encode_baud_rate(struct tty_struct *tty,
424 						speed_t ibaud, speed_t obaud);
425 
426 /**
427  *	tty_get_baud_rate	-	get tty bit rates
428  *	@tty: tty to query
429  *
430  *	Returns the baud rate as an integer for this terminal. The
431  *	termios lock must be held by the caller and the terminal bit
432  *	flags may be updated.
433  *
434  *	Locking: none
435  */
436 static inline speed_t tty_get_baud_rate(struct tty_struct *tty)
437 {
438 	return tty_termios_baud_rate(&tty->termios);
439 }
440 
441 unsigned char tty_get_char_size(unsigned int cflag);
442 unsigned char tty_get_frame_size(unsigned int cflag);
443 
444 extern void tty_termios_copy_hw(struct ktermios *new, struct ktermios *old);
445 extern int tty_termios_hw_change(const struct ktermios *a, const struct ktermios *b);
446 extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt);
447 
448 extern void tty_wakeup(struct tty_struct *tty);
449 
450 extern int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
451 			unsigned int cmd, unsigned long arg);
452 extern int tty_perform_flush(struct tty_struct *tty, unsigned long arg);
453 extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
454 extern void tty_release_struct(struct tty_struct *tty, int idx);
455 extern void tty_init_termios(struct tty_struct *tty);
456 extern void tty_save_termios(struct tty_struct *tty);
457 extern int tty_standard_install(struct tty_driver *driver,
458 		struct tty_struct *tty);
459 
460 extern struct mutex tty_mutex;
461 
462 extern void tty_port_init(struct tty_port *port);
463 extern void tty_port_link_device(struct tty_port *port,
464 		struct tty_driver *driver, unsigned index);
465 extern struct device *tty_port_register_device(struct tty_port *port,
466 		struct tty_driver *driver, unsigned index,
467 		struct device *device);
468 extern struct device *tty_port_register_device_attr(struct tty_port *port,
469 		struct tty_driver *driver, unsigned index,
470 		struct device *device, void *drvdata,
471 		const struct attribute_group **attr_grp);
472 extern struct device *tty_port_register_device_serdev(struct tty_port *port,
473 		struct tty_driver *driver, unsigned index,
474 		struct device *device);
475 extern struct device *tty_port_register_device_attr_serdev(struct tty_port *port,
476 		struct tty_driver *driver, unsigned index,
477 		struct device *device, void *drvdata,
478 		const struct attribute_group **attr_grp);
479 extern void tty_port_unregister_device(struct tty_port *port,
480 		struct tty_driver *driver, unsigned index);
481 extern int tty_port_alloc_xmit_buf(struct tty_port *port);
482 extern void tty_port_free_xmit_buf(struct tty_port *port);
483 extern void tty_port_destroy(struct tty_port *port);
484 extern void tty_port_put(struct tty_port *port);
485 
486 static inline struct tty_port *tty_port_get(struct tty_port *port)
487 {
488 	if (port && kref_get_unless_zero(&port->kref))
489 		return port;
490 	return NULL;
491 }
492 
493 /* If the cts flow control is enabled, return true. */
494 static inline bool tty_port_cts_enabled(const struct tty_port *port)
495 {
496 	return test_bit(TTY_PORT_CTS_FLOW, &port->iflags);
497 }
498 
499 static inline void tty_port_set_cts_flow(struct tty_port *port, bool val)
500 {
501 	assign_bit(TTY_PORT_CTS_FLOW, &port->iflags, val);
502 }
503 
504 static inline bool tty_port_active(const struct tty_port *port)
505 {
506 	return test_bit(TTY_PORT_ACTIVE, &port->iflags);
507 }
508 
509 static inline void tty_port_set_active(struct tty_port *port, bool val)
510 {
511 	assign_bit(TTY_PORT_ACTIVE, &port->iflags, val);
512 }
513 
514 static inline bool tty_port_check_carrier(const struct tty_port *port)
515 {
516 	return test_bit(TTY_PORT_CHECK_CD, &port->iflags);
517 }
518 
519 static inline void tty_port_set_check_carrier(struct tty_port *port, bool val)
520 {
521 	assign_bit(TTY_PORT_CHECK_CD, &port->iflags, val);
522 }
523 
524 static inline bool tty_port_suspended(const struct tty_port *port)
525 {
526 	return test_bit(TTY_PORT_SUSPENDED, &port->iflags);
527 }
528 
529 static inline void tty_port_set_suspended(struct tty_port *port, bool val)
530 {
531 	assign_bit(TTY_PORT_SUSPENDED, &port->iflags, val);
532 }
533 
534 static inline bool tty_port_initialized(const struct tty_port *port)
535 {
536 	return test_bit(TTY_PORT_INITIALIZED, &port->iflags);
537 }
538 
539 static inline void tty_port_set_initialized(struct tty_port *port, bool val)
540 {
541 	assign_bit(TTY_PORT_INITIALIZED, &port->iflags, val);
542 }
543 
544 static inline bool tty_port_kopened(const struct tty_port *port)
545 {
546 	return test_bit(TTY_PORT_KOPENED, &port->iflags);
547 }
548 
549 static inline void tty_port_set_kopened(struct tty_port *port, bool val)
550 {
551 	assign_bit(TTY_PORT_KOPENED, &port->iflags, val);
552 }
553 
554 extern struct tty_struct *tty_port_tty_get(struct tty_port *port);
555 extern void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty);
556 extern int tty_port_carrier_raised(struct tty_port *port);
557 extern void tty_port_raise_dtr_rts(struct tty_port *port);
558 extern void tty_port_lower_dtr_rts(struct tty_port *port);
559 extern void tty_port_hangup(struct tty_port *port);
560 extern void tty_port_tty_hangup(struct tty_port *port, bool check_clocal);
561 extern void tty_port_tty_wakeup(struct tty_port *port);
562 extern int tty_port_block_til_ready(struct tty_port *port,
563 				struct tty_struct *tty, struct file *filp);
564 extern int tty_port_close_start(struct tty_port *port,
565 				struct tty_struct *tty, struct file *filp);
566 extern void tty_port_close_end(struct tty_port *port, struct tty_struct *tty);
567 extern void tty_port_close(struct tty_port *port,
568 				struct tty_struct *tty, struct file *filp);
569 extern int tty_port_install(struct tty_port *port, struct tty_driver *driver,
570 				struct tty_struct *tty);
571 extern int tty_port_open(struct tty_port *port,
572 				struct tty_struct *tty, struct file *filp);
573 static inline int tty_port_users(struct tty_port *port)
574 {
575 	return port->count + port->blocked_open;
576 }
577 
578 /* n_tty.c */
579 extern void n_tty_inherit_ops(struct tty_ldisc_ops *ops);
580 #ifdef CONFIG_TTY
581 extern void __init n_tty_init(void);
582 #else
583 static inline void n_tty_init(void) { }
584 #endif
585 
586 /* tty_audit.c */
587 #ifdef CONFIG_AUDIT
588 extern void tty_audit_exit(void);
589 extern void tty_audit_fork(struct signal_struct *sig);
590 extern int tty_audit_push(void);
591 #else
592 static inline void tty_audit_exit(void)
593 {
594 }
595 static inline void tty_audit_fork(struct signal_struct *sig)
596 {
597 }
598 static inline int tty_audit_push(void)
599 {
600 	return 0;
601 }
602 #endif
603 
604 /* tty_ioctl.c */
605 extern int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
606 		       unsigned int cmd, unsigned long arg);
607 
608 /* vt.c */
609 
610 extern int vt_ioctl(struct tty_struct *tty,
611 		    unsigned int cmd, unsigned long arg);
612 
613 extern long vt_compat_ioctl(struct tty_struct *tty,
614 		     unsigned int cmd, unsigned long arg);
615 
616 /* tty_mutex.c */
617 /* functions for preparation of BKL removal */
618 extern void tty_lock(struct tty_struct *tty);
619 extern int  tty_lock_interruptible(struct tty_struct *tty);
620 extern void tty_unlock(struct tty_struct *tty);
621 extern void tty_lock_slave(struct tty_struct *tty);
622 extern void tty_unlock_slave(struct tty_struct *tty);
623 extern void tty_set_lock_subclass(struct tty_struct *tty);
624 
625 #endif
626