1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * TTY core internal functions 4 */ 5 6#ifndef _TTY_INTERNAL_H 7#define _TTY_INTERNAL_H 8 9#define tty_msg(fn, tty, f, ...) \ 10 fn("%s %s: " f, tty_driver_name(tty), tty_name(tty), ##__VA_ARGS__) 11 12#define tty_debug(tty, f, ...) tty_msg(pr_debug, tty, f, ##__VA_ARGS__) 13#define tty_info(tty, f, ...) tty_msg(pr_info, tty, f, ##__VA_ARGS__) 14#define tty_notice(tty, f, ...) tty_msg(pr_notice, tty, f, ##__VA_ARGS__) 15#define tty_warn(tty, f, ...) tty_msg(pr_warn, tty, f, ##__VA_ARGS__) 16#define tty_err(tty, f, ...) tty_msg(pr_err, tty, f, ##__VA_ARGS__) 17 18#define tty_info_ratelimited(tty, f, ...) \ 19 tty_msg(pr_info_ratelimited, tty, f, ##__VA_ARGS__) 20 21/* 22 * Lock subclasses for tty locks 23 * 24 * TTY_LOCK_NORMAL is for normal ttys and master ptys. 25 * TTY_LOCK_SLAVE is for slave ptys only. 26 * 27 * Lock subclasses are necessary for handling nested locking with pty pairs. 28 * tty locks which use nested locking: 29 * 30 * legacy_mutex - Nested tty locks are necessary for releasing pty pairs. 31 * The stable lock order is master pty first, then slave pty. 32 * termios_rwsem - The stable lock order is tty_buffer lock->termios_rwsem. 33 * Subclassing this lock enables the slave pty to hold its 34 * termios_rwsem when claiming the master tty_buffer lock. 35 * tty_buffer lock - slave ptys can claim nested buffer lock when handling 36 * signal chars. The stable lock order is slave pty, then 37 * master. 38 */ 39enum { 40 TTY_LOCK_NORMAL = 0, 41 TTY_LOCK_SLAVE, 42}; 43 44/* Values for tty->flow_change */ 45#define TTY_THROTTLE_SAFE 1 46#define TTY_UNTHROTTLE_SAFE 2 47 48static inline void __tty_set_flow_change(struct tty_struct *tty, int val) 49{ 50 tty->flow_change = val; 51} 52 53static inline void tty_set_flow_change(struct tty_struct *tty, int val) 54{ 55 tty->flow_change = val; 56 smp_mb(); 57} 58 59int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout); 60void tty_ldisc_unlock(struct tty_struct *tty); 61 62int __tty_check_change(struct tty_struct *tty, int sig); 63int tty_check_change(struct tty_struct *tty); 64void __stop_tty(struct tty_struct *tty); 65void __start_tty(struct tty_struct *tty); 66void tty_write_unlock(struct tty_struct *tty); 67int tty_write_lock(struct tty_struct *tty, bool ndelay); 68void tty_vhangup_session(struct tty_struct *tty); 69void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty); 70int tty_signal_session_leader(struct tty_struct *tty, int exit_session); 71void session_clear_tty(struct pid *session); 72void tty_buffer_free_all(struct tty_port *port); 73void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld); 74void tty_buffer_init(struct tty_port *port); 75void tty_buffer_set_lock_subclass(struct tty_port *port); 76bool tty_buffer_restart_work(struct tty_port *port); 77bool tty_buffer_cancel_work(struct tty_port *port); 78void tty_buffer_flush_work(struct tty_port *port); 79speed_t tty_termios_input_baud_rate(struct ktermios *termios); 80void tty_ldisc_hangup(struct tty_struct *tty, bool reset); 81int tty_ldisc_reinit(struct tty_struct *tty, int disc); 82long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 83long tty_jobctrl_ioctl(struct tty_struct *tty, struct tty_struct *real_tty, 84 struct file *file, unsigned int cmd, unsigned long arg); 85void tty_default_fops(struct file_operations *fops); 86struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx); 87int tty_alloc_file(struct file *file); 88void tty_add_file(struct tty_struct *tty, struct file *file); 89void tty_free_file(struct file *file); 90int tty_release(struct inode *inode, struct file *filp); 91 92#define tty_is_writelocked(tty) (mutex_is_locked(&tty->atomic_write_lock)) 93 94int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty); 95void tty_ldisc_release(struct tty_struct *tty); 96int __must_check tty_ldisc_init(struct tty_struct *tty); 97void tty_ldisc_deinit(struct tty_struct *tty); 98 99void tty_sysctl_init(void); 100 101/* tty_audit.c */ 102#ifdef CONFIG_AUDIT 103void tty_audit_add_data(struct tty_struct *tty, const void *data, size_t size); 104void tty_audit_tiocsti(struct tty_struct *tty, char ch); 105#else 106static inline void tty_audit_add_data(struct tty_struct *tty, const void *data, 107 size_t size) 108{ 109} 110static inline void tty_audit_tiocsti(struct tty_struct *tty, char ch) 111{ 112} 113#endif 114 115ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *); 116 117#endif 118