blob: 767f62086bd9b5d6b1d3b222d90dd9a8f558f8bc [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_TTY_FLIP_H
3#define _LINUX_TTY_FLIP_H
4
Peter Hurley4d18e6ef2013-11-22 12:09:55 -05005extern int tty_buffer_set_limit(struct tty_port *port, int limit);
Peter Hurley7bfe0b72013-06-15 09:36:08 -04006extern int tty_buffer_space_avail(struct tty_port *port);
Jiri Slaby227434f2013-01-03 15:53:01 +01007extern int tty_buffer_request_room(struct tty_port *port, size_t size);
Jiri Slaby2f693352013-01-03 15:53:02 +01008extern int tty_insert_flip_string_flags(struct tty_port *port,
9 const unsigned char *chars, const char *flags, size_t size);
10extern int tty_insert_flip_string_fixed_flag(struct tty_port *port,
11 const unsigned char *chars, char flag, size_t size);
12extern int tty_prepare_flip_string(struct tty_port *port,
13 unsigned char **chars, size_t size);
Jiri Slaby2e124b42013-01-03 15:53:06 +010014extern void tty_flip_buffer_push(struct tty_port *port);
Jiri Slaby6732c8b2013-01-03 15:53:07 +010015void tty_schedule_flip(struct tty_port *port);
Arnd Bergmann979990c2017-06-20 23:10:41 +020016int __tty_insert_flip_char(struct tty_port *port, unsigned char ch, char flag);
Alan Cox33f0f882006-01-09 20:54:13 -080017
Jiri Slaby92a19f92013-01-03 15:53:03 +010018static inline int tty_insert_flip_char(struct tty_port *port,
Andrew Mortone1a25092006-04-10 22:54:05 -070019 unsigned char ch, char flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
Jiri Slaby92a19f92013-01-03 15:53:03 +010021 struct tty_buffer *tb = port->buf.tail;
Peter Hurleyacc0f672013-12-09 09:23:52 -050022 int change;
23
24 change = (tb->flags & TTYB_NORMAL) && (flag != TTY_NORMAL);
25 if (!change && tb->used < tb->size) {
26 if (~tb->flags & TTYB_NORMAL)
27 *flag_buf_ptr(tb, tb->used) = flag;
Peter Hurley1fc359f2013-06-15 09:36:01 -040028 *char_buf_ptr(tb, tb->used++) = ch;
Alan Cox33f0f882006-01-09 20:54:13 -080029 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 }
Arnd Bergmann979990c2017-06-20 23:10:41 +020031 return __tty_insert_flip_char(port, ch, flag);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032}
33
Jiri Slaby05c7cd32013-01-03 15:53:04 +010034static inline int tty_insert_flip_string(struct tty_port *port,
35 const unsigned char *chars, size_t size)
Alan Cox2832fc12010-02-18 16:43:54 +000036{
Jiri Slaby05c7cd32013-01-03 15:53:04 +010037 return tty_insert_flip_string_fixed_flag(port, chars, TTY_NORMAL, size);
Alan Cox2832fc12010-02-18 16:43:54 +000038}
39
Peter Hurleya7c8d582013-06-15 09:36:15 -040040extern void tty_buffer_lock_exclusive(struct tty_port *port);
41extern void tty_buffer_unlock_exclusive(struct tty_port *port);
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#endif /* _LINUX_TTY_FLIP_H */