xref: /linux-6.15/include/linux/tty_flip.h (revision 2ce2983c)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_TTY_FLIP_H
3 #define _LINUX_TTY_FLIP_H
4 
5 #include <linux/tty_buffer.h>
6 #include <linux/tty_port.h>
7 
8 struct tty_ldisc;
9 
10 int tty_buffer_set_limit(struct tty_port *port, int limit);
11 unsigned int tty_buffer_space_avail(struct tty_port *port);
12 int tty_buffer_request_room(struct tty_port *port, size_t size);
13 size_t __tty_insert_flip_string_flags(struct tty_port *port, const u8 *chars,
14 				      const u8 *flags, bool mutable_flags,
15 				      size_t size);
16 size_t tty_prepare_flip_string(struct tty_port *port, u8 **chars, size_t size);
17 void tty_flip_buffer_push(struct tty_port *port);
18 int __tty_insert_flip_char(struct tty_port *port, u8 ch, u8 flag);
19 
20 /**
21  * tty_insert_flip_string_fixed_flag - add characters to the tty buffer
22  * @port: tty port
23  * @chars: characters
24  * @flag: flag value for each character
25  * @size: size
26  *
27  * Queue a series of bytes to the tty buffering. All the characters passed are
28  * marked with the supplied flag.
29  *
30  * Returns: the number added.
31  */
32 static inline size_t tty_insert_flip_string_fixed_flag(struct tty_port *port,
33 						       const u8 *chars, u8 flag,
34 						       size_t size)
35 {
36 	return __tty_insert_flip_string_flags(port, chars, &flag, false, size);
37 }
38 
39 /**
40  * tty_insert_flip_string_flags - add characters to the tty buffer
41  * @port: tty port
42  * @chars: characters
43  * @flags: flag bytes
44  * @size: size
45  *
46  * Queue a series of bytes to the tty buffering. For each character the flags
47  * array indicates the status of the character.
48  *
49  * Returns: the number added.
50  */
51 static inline size_t tty_insert_flip_string_flags(struct tty_port *port,
52 						  const u8 *chars,
53 						  const u8 *flags, size_t size)
54 {
55 	return __tty_insert_flip_string_flags(port, chars, flags, true, size);
56 }
57 
58 
59 static inline size_t tty_insert_flip_char(struct tty_port *port, u8 ch, u8 flag)
60 {
61 	struct tty_buffer *tb = port->buf.tail;
62 	int change;
63 
64 	change = !tb->flags && (flag != TTY_NORMAL);
65 	if (!change && tb->used < tb->size) {
66 		if (tb->flags)
67 			*flag_buf_ptr(tb, tb->used) = flag;
68 		*char_buf_ptr(tb, tb->used++) = ch;
69 		return 1;
70 	}
71 	return __tty_insert_flip_char(port, ch, flag);
72 }
73 
74 static inline size_t tty_insert_flip_string(struct tty_port *port,
75 					    const u8 *chars, size_t size)
76 {
77 	return tty_insert_flip_string_fixed_flag(port, chars, TTY_NORMAL, size);
78 }
79 
80 size_t tty_ldisc_receive_buf(struct tty_ldisc *ld, const u8 *p, const u8 *f,
81 			     size_t count);
82 
83 void tty_buffer_lock_exclusive(struct tty_port *port);
84 void tty_buffer_unlock_exclusive(struct tty_port *port);
85 
86 #endif /* _LINUX_TTY_FLIP_H */
87