xref: /openbmc/linux/include/linux/tty_buffer.h (revision 6b342707)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_TTY_BUFFER_H
3 #define _LINUX_TTY_BUFFER_H
4 
5 #include <linux/atomic.h>
6 #include <linux/llist.h>
7 #include <linux/mutex.h>
8 #include <linux/workqueue.h>
9 
10 struct tty_buffer {
11 	union {
12 		struct tty_buffer *next;
13 		struct llist_node free;
14 	};
15 	int used;
16 	int size;
17 	int commit;
18 	int read;
19 	int flags;
20 	/* Data points here */
21 	unsigned long data[];
22 };
23 
24 /* Values for .flags field of tty_buffer */
25 #define TTYB_NORMAL	1	/* buffer has no flags buffer */
26 
27 static inline unsigned char *char_buf_ptr(struct tty_buffer *b, int ofs)
28 {
29 	return ((unsigned char *)b->data) + ofs;
30 }
31 
32 static inline char *flag_buf_ptr(struct tty_buffer *b, int ofs)
33 {
34 	return (char *)char_buf_ptr(b, ofs) + b->size;
35 }
36 
37 struct tty_bufhead {
38 	struct tty_buffer *head;	/* Queue head */
39 	struct work_struct work;
40 	struct mutex	   lock;
41 	atomic_t	   priority;
42 	struct tty_buffer sentinel;
43 	struct llist_head free;		/* Free queue head */
44 	atomic_t	   mem_used;    /* In-use buffers excluding free list */
45 	int		   mem_limit;
46 	struct tty_buffer *tail;	/* Active buffer */
47 };
48 
49 /*
50  * When a break, frame error, or parity error happens, these codes are
51  * stuffed into the flags buffer.
52  */
53 #define TTY_NORMAL	0
54 #define TTY_BREAK	1
55 #define TTY_FRAME	2
56 #define TTY_PARITY	3
57 #define TTY_OVERRUN	4
58 
59 #endif
60