blob: b710c5ef89ab2f5939869dacaa73f383628d60e1 [file] [log] [blame]
Greg Kroah-Hartman98602c02021-04-08 14:51:22 +02001/* 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__)
Greg Kroah-Hartman98602c02021-04-08 14:51:22 +020013#define tty_notice(tty, f, ...) tty_msg(pr_notice, tty, f, ##__VA_ARGS__)
14#define tty_warn(tty, f, ...) tty_msg(pr_warn, tty, f, ##__VA_ARGS__)
15#define tty_err(tty, f, ...) tty_msg(pr_err, tty, f, ##__VA_ARGS__)
16
17#define tty_info_ratelimited(tty, f, ...) \
18 tty_msg(pr_info_ratelimited, tty, f, ##__VA_ARGS__)
19
Greg Kroah-Hartman6c80c0b2021-04-08 14:51:30 +020020/*
21 * Lock subclasses for tty locks
22 *
23 * TTY_LOCK_NORMAL is for normal ttys and master ptys.
24 * TTY_LOCK_SLAVE is for slave ptys only.
25 *
26 * Lock subclasses are necessary for handling nested locking with pty pairs.
27 * tty locks which use nested locking:
28 *
29 * legacy_mutex - Nested tty locks are necessary for releasing pty pairs.
30 * The stable lock order is master pty first, then slave pty.
31 * termios_rwsem - The stable lock order is tty_buffer lock->termios_rwsem.
32 * Subclassing this lock enables the slave pty to hold its
33 * termios_rwsem when claiming the master tty_buffer lock.
34 * tty_buffer lock - slave ptys can claim nested buffer lock when handling
35 * signal chars. The stable lock order is slave pty, then
36 * master.
37 */
38enum {
39 TTY_LOCK_NORMAL = 0,
40 TTY_LOCK_SLAVE,
41};
42
Greg Kroah-Hartman9f72cab2021-04-08 14:51:32 +020043/* Values for tty->flow_change */
44#define TTY_THROTTLE_SAFE 1
45#define TTY_UNTHROTTLE_SAFE 2
46
47static inline void __tty_set_flow_change(struct tty_struct *tty, int val)
48{
49 tty->flow_change = val;
50}
51
52static inline void tty_set_flow_change(struct tty_struct *tty, int val)
53{
54 tty->flow_change = val;
55 smp_mb();
56}
57
Greg Kroah-Hartman6c80c0b2021-04-08 14:51:30 +020058int tty_ldisc_lock(struct tty_struct *tty, unsigned long timeout);
59void tty_ldisc_unlock(struct tty_struct *tty);
60
Greg Kroah-Hartman5ffa6e32021-04-08 14:51:34 +020061int __tty_check_change(struct tty_struct *tty, int sig);
62int tty_check_change(struct tty_struct *tty);
63void __stop_tty(struct tty_struct *tty);
64void __start_tty(struct tty_struct *tty);
65void tty_vhangup_session(struct tty_struct *tty);
66void tty_open_proc_set_tty(struct file *filp, struct tty_struct *tty);
67int tty_signal_session_leader(struct tty_struct *tty, int exit_session);
68void session_clear_tty(struct pid *session);
69void tty_buffer_free_all(struct tty_port *port);
70void tty_buffer_flush(struct tty_struct *tty, struct tty_ldisc *ld);
71void tty_buffer_init(struct tty_port *port);
72void tty_buffer_set_lock_subclass(struct tty_port *port);
73bool tty_buffer_restart_work(struct tty_port *port);
74bool tty_buffer_cancel_work(struct tty_port *port);
75void tty_buffer_flush_work(struct tty_port *port);
76speed_t tty_termios_input_baud_rate(struct ktermios *termios);
77void tty_ldisc_hangup(struct tty_struct *tty, bool reset);
78int tty_ldisc_reinit(struct tty_struct *tty, int disc);
79long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
80long tty_jobctrl_ioctl(struct tty_struct *tty, struct tty_struct *real_tty,
81 struct file *file, unsigned int cmd, unsigned long arg);
82void tty_default_fops(struct file_operations *fops);
83struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx);
84int tty_alloc_file(struct file *file);
85void tty_add_file(struct tty_struct *tty, struct file *file);
86void tty_free_file(struct file *file);
87int tty_release(struct inode *inode, struct file *filp);
88
89#define tty_is_writelocked(tty) (mutex_is_locked(&tty->atomic_write_lock))
90
91int tty_ldisc_setup(struct tty_struct *tty, struct tty_struct *o_tty);
92void tty_ldisc_release(struct tty_struct *tty);
93int __must_check tty_ldisc_init(struct tty_struct *tty);
94void tty_ldisc_deinit(struct tty_struct *tty);
95
96void tty_sysctl_init(void);
97
Greg Kroah-Hartmanda5d6692021-04-08 14:51:29 +020098/* tty_audit.c */
99#ifdef CONFIG_AUDIT
100void tty_audit_add_data(struct tty_struct *tty, const void *data, size_t size);
101void tty_audit_tiocsti(struct tty_struct *tty, char ch);
102#else
103static inline void tty_audit_add_data(struct tty_struct *tty, const void *data,
104 size_t size)
105{
106}
107static inline void tty_audit_tiocsti(struct tty_struct *tty, char ch)
108{
109}
110#endif
111
Greg Kroah-Hartman9f72cab2021-04-08 14:51:32 +0200112ssize_t redirected_tty_write(struct kiocb *, struct iov_iter *);
113
Greg Kroah-Hartman98602c02021-04-08 14:51:22 +0200114#endif