xref: /openbmc/linux/drivers/tty/tty.h (revision 3e04ba41)
198602c01SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
298602c01SGreg Kroah-Hartman /*
398602c01SGreg Kroah-Hartman  * TTY core internal functions
498602c01SGreg Kroah-Hartman  */
598602c01SGreg Kroah-Hartman 
698602c01SGreg Kroah-Hartman #ifndef _TTY_INTERNAL_H
798602c01SGreg Kroah-Hartman #define _TTY_INTERNAL_H
898602c01SGreg Kroah-Hartman 
998602c01SGreg Kroah-Hartman #define tty_msg(fn, tty, f, ...) \
1098602c01SGreg Kroah-Hartman 	fn("%s %s: " f, tty_driver_name(tty), tty_name(tty), ##__VA_ARGS__)
1198602c01SGreg Kroah-Hartman 
1298602c01SGreg Kroah-Hartman #define tty_debug(tty, f, ...)	tty_msg(pr_debug, tty, f, ##__VA_ARGS__)
1398602c01SGreg Kroah-Hartman #define tty_notice(tty, f, ...)	tty_msg(pr_notice, tty, f, ##__VA_ARGS__)
1498602c01SGreg Kroah-Hartman #define tty_warn(tty, f, ...)	tty_msg(pr_warn, tty, f, ##__VA_ARGS__)
1598602c01SGreg Kroah-Hartman #define tty_err(tty, f, ...)	tty_msg(pr_err, tty, f, ##__VA_ARGS__)
1698602c01SGreg Kroah-Hartman 
1798602c01SGreg Kroah-Hartman #define tty_info_ratelimited(tty, f, ...) \
1898602c01SGreg Kroah-Hartman 		tty_msg(pr_info_ratelimited, tty, f, ##__VA_ARGS__)
1998602c01SGreg Kroah-Hartman 
206c80c0b9SGreg Kroah-Hartman /*
216c80c0b9SGreg Kroah-Hartman  * Lock subclasses for tty locks
226c80c0b9SGreg Kroah-Hartman  *
236c80c0b9SGreg Kroah-Hartman  * TTY_LOCK_NORMAL is for normal ttys and master ptys.
246c80c0b9SGreg Kroah-Hartman  * TTY_LOCK_SLAVE is for slave ptys only.
256c80c0b9SGreg Kroah-Hartman  *
266c80c0b9SGreg Kroah-Hartman  * Lock subclasses are necessary for handling nested locking with pty pairs.
276c80c0b9SGreg Kroah-Hartman  * tty locks which use nested locking:
286c80c0b9SGreg Kroah-Hartman  *
296c80c0b9SGreg Kroah-Hartman  * legacy_mutex - Nested tty locks are necessary for releasing pty pairs.
306c80c0b9SGreg Kroah-Hartman  *		  The stable lock order is master pty first, then slave pty.
316c80c0b9SGreg Kroah-Hartman  * termios_rwsem - The stable lock order is tty_buffer lock->termios_rwsem.
326c80c0b9SGreg Kroah-Hartman  *		   Subclassing this lock enables the slave pty to hold its
336c80c0b9SGreg Kroah-Hartman  *		   termios_rwsem when claiming the master tty_buffer lock.
346c80c0b9SGreg Kroah-Hartman  * tty_buffer lock - slave ptys can claim nested buffer lock when handling
356c80c0b9SGreg Kroah-Hartman  *		     signal chars. The stable lock order is slave pty, then
366c80c0b9SGreg Kroah-Hartman  *		     master.
376c80c0b9SGreg Kroah-Hartman  */
386c80c0b9SGreg Kroah-Hartman enum {
396c80c0b9SGreg Kroah-Hartman 	TTY_LOCK_NORMAL = 0,
406c80c0b9SGreg Kroah-Hartman 	TTY_LOCK_SLAVE,
416c80c0b9SGreg Kroah-Hartman };
426c80c0b9SGreg Kroah-Hartman 
439f72cab1SGreg Kroah-Hartman /* Values for tty->flow_change */
449f72cab1SGreg Kroah-Hartman #define TTY_THROTTLE_SAFE	1
459f72cab1SGreg Kroah-Hartman #define TTY_UNTHROTTLE_SAFE	2
469f72cab1SGreg Kroah-Hartman 
__tty_set_flow_change(struct tty_struct * tty,int val)479f72cab1SGreg Kroah-Hartman static inline void __tty_set_flow_change(struct tty_struct *tty, int val)
489f72cab1SGreg Kroah-Hartman {
499f72cab1SGreg Kroah-Hartman 	tty->flow_change = val;
509f72cab1SGreg Kroah-Hartman }
519f72cab1SGreg Kroah-Hartman 
tty_set_flow_change(struct tty_struct * tty,int val)529f72cab1SGreg Kroah-Hartman static inline void tty_set_flow_change(struct tty_struct *tty, int val)
539f72cab1SGreg Kroah-Hartman {
549f72cab1SGreg Kroah-Hartman 	tty->flow_change = val;
559f72cab1SGreg Kroah-Hartman 	smp_mb();
569f72cab1SGreg Kroah-Hartman }
579f72cab1SGreg Kroah-Hartman 
586c80c0b9SGreg Kroah-Hartman int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout);
596c80c0b9SGreg Kroah-Hartman void tty_ldisc_unlock(struct tty_struct *tty);
606c80c0b9SGreg Kroah-Hartman 
615ffa6e34SGreg Kroah-Hartman int __tty_check_change(struct tty_struct *tty, int sig);
625ffa6e34SGreg Kroah-Hartman int tty_check_change(struct tty_struct *tty);
635ffa6e34SGreg Kroah-Hartman void __stop_tty(struct tty_struct *tty);
645ffa6e34SGreg Kroah-Hartman void __start_tty(struct tty_struct *tty);
65094fb49aSIlpo Järvinen void tty_write_unlock(struct tty_struct *tty);
66af815336SJiri Slaby (SUSE) int tty_write_lock(struct tty_struct *tty, bool ndelay);
675ffa6e34SGreg Kroah-Hartman void tty_vhangup_session(struct tty_struct *tty);
685ffa6e34SGreg Kroah-Hartman void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty);
695ffa6e34SGreg Kroah-Hartman int tty_signal_session_leader(struct tty_struct *tty, int exit_session);
705ffa6e34SGreg Kroah-Hartman void session_clear_tty(struct pid *session);
715ffa6e34SGreg Kroah-Hartman void tty_buffer_free_all(struct tty_port *port);
725ffa6e34SGreg Kroah-Hartman void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld);
735ffa6e34SGreg Kroah-Hartman void tty_buffer_init(struct tty_port *port);
745ffa6e34SGreg Kroah-Hartman void tty_buffer_set_lock_subclass(struct tty_port *port);
755ffa6e34SGreg Kroah-Hartman bool tty_buffer_restart_work(struct tty_port *port);
765ffa6e34SGreg Kroah-Hartman bool tty_buffer_cancel_work(struct tty_port *port);
775ffa6e34SGreg Kroah-Hartman void tty_buffer_flush_work(struct tty_port *port);
7887888fb9SIlpo Järvinen speed_t tty_termios_input_baud_rate(const struct ktermios *termios);
795ffa6e34SGreg Kroah-Hartman void tty_ldisc_hangup(struct tty_struct *tty, bool reset);
805ffa6e34SGreg Kroah-Hartman int tty_ldisc_reinit(struct tty_struct *tty, int disc);
815ffa6e34SGreg Kroah-Hartman long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
825ffa6e34SGreg Kroah-Hartman long tty_jobctrl_ioctl(struct tty_struct *tty, struct tty_struct *real_tty,
835ffa6e34SGreg Kroah-Hartman 		       struct file *file, unsigned int cmd, unsigned long arg);
845ffa6e34SGreg Kroah-Hartman void tty_default_fops(struct file_operations *fops);
855ffa6e34SGreg Kroah-Hartman struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx);
865ffa6e34SGreg Kroah-Hartman int tty_alloc_file(struct file *file);
875ffa6e34SGreg Kroah-Hartman void tty_add_file(struct tty_struct *tty, struct file *file);
885ffa6e34SGreg Kroah-Hartman void tty_free_file(struct file *file);
895ffa6e34SGreg Kroah-Hartman int tty_release(struct inode *inode, struct file *filp);
905ffa6e34SGreg Kroah-Hartman 
915ffa6e34SGreg Kroah-Hartman #define tty_is_writelocked(tty)  (mutex_is_locked(&tty->atomic_write_lock))
925ffa6e34SGreg Kroah-Hartman 
935ffa6e34SGreg Kroah-Hartman int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);
945ffa6e34SGreg Kroah-Hartman void tty_ldisc_release(struct tty_struct *tty);
955ffa6e34SGreg Kroah-Hartman int __must_check tty_ldisc_init(struct tty_struct *tty);
965ffa6e34SGreg Kroah-Hartman void tty_ldisc_deinit(struct tty_struct *tty);
975ffa6e34SGreg Kroah-Hartman 
985fd8c2d3SKees Cook extern int tty_ldisc_autoload;
995ffa6e34SGreg Kroah-Hartman 
100da5d669eSGreg Kroah-Hartman /* tty_audit.c */
101da5d669eSGreg Kroah-Hartman #ifdef CONFIG_AUDIT
102e64ed44bSJiri Slaby void tty_audit_add_data(const struct tty_struct *tty, const void *data,
103e64ed44bSJiri Slaby 			size_t size);
104*3e04ba41SJiri Slaby (SUSE) void tty_audit_tiocsti(const struct tty_struct *tty, u8 ch);
105da5d669eSGreg Kroah-Hartman #else
tty_audit_add_data(const struct tty_struct * tty,const void * data,size_t size)106e64ed44bSJiri Slaby static inline void tty_audit_add_data(const struct tty_struct *tty,
107e64ed44bSJiri Slaby 				      const void *data, size_t size)
108da5d669eSGreg Kroah-Hartman {
109da5d669eSGreg Kroah-Hartman }
tty_audit_tiocsti(const struct tty_struct * tty,u8 ch)110*3e04ba41SJiri Slaby (SUSE) static inline void tty_audit_tiocsti(const struct tty_struct *tty, u8 ch)
111da5d669eSGreg Kroah-Hartman {
112da5d669eSGreg Kroah-Hartman }
113da5d669eSGreg Kroah-Hartman #endif
114da5d669eSGreg Kroah-Hartman 
1159f72cab1SGreg Kroah-Hartman ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *);
1169f72cab1SGreg Kroah-Hartman 
117a501ab75SJiri Slaby int tty_insert_flip_string_and_push_buffer(struct tty_port *port,
118a8d9cd23SJiri Slaby (SUSE) 					   const u8 *chars, size_t cnt);
119a501ab75SJiri Slaby 
12098602c01SGreg Kroah-Hartman #endif
121