XenevaOS
Loading...
Searching...
No Matches
tty_flip.h
Go to the documentation of this file.
1#ifndef _LINUX_TTY_FLIP_H
2#define _LINUX_TTY_FLIP_H
3
4/*
5 * DCL <linux/tty_flip.h> -- the driver-facing side of the flip buffer.
6 *
7 * Ported from mainline v7.2. This is the API a UART interrupt handler calls:
8 * tty_insert_flip_char() puts one byte in, tty_flip_buffer_push() makes it
9 * visible. Everything else in the header is convenience layered on
10 * __tty_insert_flip_string_flags().
11 *
12 * The fast path in tty_insert_flip_char() is worth reading slowly, because
13 * the flag byte is the subtle part:
14 *
15 * change = !tb->flags && (flag != TTY_NORMAL);
16 * if (!change && tb->used < tb->size) { ... store ... return 1; }
17 *
18 * A buffer created without flags (tty_prepare_flip_string(), and every
19 * normal-character allocation) has no flag array at all -- flag_buf_ptr()
20 * would point into the next buffer's memory. So a non-NORMAL flag forces an
21 * allocation for a flags-capable buffer before anything is written; and once
22 * a flags buffer is in use, each byte's flag is written *only if* the buffer
23 * is flagged, which is what the inner `if (tb->flags)` checks. Getting this
24 * wrong does not crash -- it silently records every byte as TTY_NORMAL, and
25 * a break or parity error simply never reaches the ldisc.
26 */
27
28#include <linux/tty_buffer.h>
29#include <linux/tty_port.h>
30
31struct tty_ldisc;
32
33int tty_buffer_set_limit(struct tty_port* port, int limit);
34unsigned int tty_buffer_space_avail(struct tty_port* port);
35int tty_buffer_request_room(struct tty_port* port, size_t size);
36size_t __tty_insert_flip_string_flags(struct tty_port* port, const u8* chars,
37 const u8* flags, bool mutable_flags,
38 size_t size);
39size_t tty_prepare_flip_string(struct tty_port* port, u8** chars, size_t size);
40void tty_flip_buffer_push(struct tty_port* port);
41
50static inline size_t tty_insert_flip_string_fixed_flag(struct tty_port* port,
51 const u8* chars, u8 flag,
52 size_t size)
53{
54 return __tty_insert_flip_string_flags(port, chars, &flag, false, size);
55}
56
65static inline size_t tty_insert_flip_string_flags(struct tty_port* port,
66 const u8* chars,
67 const u8* flags, size_t size)
68{
69 return __tty_insert_flip_string_flags(port, chars, flags, true, size);
70}
71
77static inline size_t tty_insert_flip_char(struct tty_port* port, u8 ch, u8 flag)
78{
79 struct tty_buffer* tb = port->buf.tail;
80 int change;
81
82 change = !tb->flags && (flag != TTY_NORMAL);
83 if (!change && tb->used < tb->size) {
84 if (tb->flags)
85 *flag_buf_ptr(tb, tb->used) = flag;
86 *char_buf_ptr(tb, tb->used++) = ch;
87 return 1;
88 }
89 return __tty_insert_flip_string_flags(port, &ch, &flag, false, 1);
90}
91
92static inline size_t tty_insert_flip_string(struct tty_port* port,
93 const u8* chars, size_t size)
94{
95 return tty_insert_flip_string_fixed_flag(port, chars, TTY_NORMAL, size);
96}
97
98size_t tty_ldisc_receive_buf(struct tty_ldisc* ld, const u8* p, const u8* f,
99 size_t count);
100
103
104#endif /* _LINUX_TTY_FLIP_H */
char * chars
Definition clib.cpp:105
uint8_t flags
Definition virtio.h:0
flag
Definition bytecode.h:29
size_t size
Definition drm_bridge.h:1299
const char * f
Definition drm_print.h:205
uint8_t u8
Definition kernel.h:14
Definition tty_buffer.h:35
unsigned int used
Definition tty_buffer.h:40
bool flags
Definition tty_buffer.h:45
unsigned int size
Definition tty_buffer.h:41
struct tty_buffer * tail
Definition tty_buffer.h:90
Definition tty_ldisc.h:164
Definition tty_port.h:79
struct tty_bufhead buf
Definition tty_port.h:80
#define TTY_NORMAL
Definition tty_buffer.h:100
void tty_buffer_unlock_exclusive(struct tty_port *port)
size_t tty_prepare_flip_string(struct tty_port *port, u8 **chars, size_t size)
unsigned int tty_buffer_space_avail(struct tty_port *port)
size_t __tty_insert_flip_string_flags(struct tty_port *port, const u8 *chars, const u8 *flags, bool mutable_flags, size_t size)
void tty_buffer_lock_exclusive(struct tty_port *port)
size_t tty_ldisc_receive_buf(struct tty_ldisc *ld, const u8 *p, const u8 *f, size_t count)
int tty_buffer_request_room(struct tty_port *port, size_t size)
void tty_flip_buffer_push(struct tty_port *port)
int tty_buffer_set_limit(struct tty_port *port, int limit)