XenevaOS
Loading...
Searching...
No Matches
tty_driver.h
Go to the documentation of this file.
1#ifndef _LINUX_TTY_DRIVER_H
2#define _LINUX_TTY_DRIVER_H
3
4/*
5 * DCL <linux/tty_driver.h> -- struct tty_driver and struct tty_operations.
6 *
7 * Ported from mainline v7.2, with two classes of change:
8 *
9 * - __randomize_layout dropped from both structs. It is a GCC plugin that
10 * shuffles field order per build to defeat struct-prediction attacks; DCL
11 * has no plugin and no adversary, and a struct whose layout differs between
12 * translation units would be a correctness bug, not a hardening feature.
13 *
14 * - The CONFIG_PROC_FS and CONFIG_CONSOLE_POLL blocks are written out in the
15 * "present" direction (proc registration is declared, the poll ops are
16 * not). proc_tty_register_driver() is one of the calls tty_register_driver()
17 * makes, so it needs a symbol; poll_* is a console-polling hook nothing in
18 * the staged set installs.
19 *
20 * `struct cdev **cdevs` is the field that makes /dev/ttyS0 possible at all:
21 * tty_io.c's cdev bridge looks the driver up through it, and serial_core.c's
22 * uart_add_one_port() eventually lands here. It is an array -- one cdev per
23 * line -- because a serial driver can have as many ports as minors.
24 */
25
26#include <linux/export.h>
27#include <linux/fs.h>
28#include <linux/kref.h>
29#include <linux/list.h>
30#include <linux/bitops.h> /* BIT() for the tty_driver_flag enum */
31#include <linux/termios.h>
32#include <linux/seq_file.h>
33#include <linux/module.h> /* THIS_MODULE for tty_alloc_driver() */
34
35struct tty_struct;
36struct tty_driver;
37struct tty_port;
39struct serial_struct;
40struct cdev;
41struct proc_dir_entry;
42struct device;
43struct module;
44struct workqueue_struct;
45struct attribute_group;
46
58
67
79
81 struct tty_struct* (*lookup)(struct tty_driver* driver,
82 struct file* filp, int idx);
83 int (*install)(struct tty_driver* driver, struct tty_struct* tty);
84 void (*remove)(struct tty_driver* driver, struct tty_struct* tty);
85 int (*open)(struct tty_struct* tty, struct file* filp);
86 void (*close)(struct tty_struct* tty, struct file* filp);
87 void (*shutdown)(struct tty_struct* tty);
88 void (*cleanup)(struct tty_struct* tty);
89 ssize_t (*write)(struct tty_struct* tty, const u8* buf, size_t count);
90 int (*put_char)(struct tty_struct* tty, u8 ch);
91 void (*flush_chars)(struct tty_struct* tty);
92 unsigned int (*write_room)(struct tty_struct* tty);
93 unsigned int (*chars_in_buffer)(struct tty_struct* tty);
94 int (*ioctl)(struct tty_struct* tty,
95 unsigned int cmd, unsigned long arg);
96 long (*compat_ioctl)(struct tty_struct* tty,
97 unsigned int cmd, unsigned long arg);
98 void (*set_termios)(struct tty_struct* tty, const struct ktermios* old);
99 void (*throttle)(struct tty_struct* tty);
100 void (*unthrottle)(struct tty_struct* tty);
101 void (*stop)(struct tty_struct* tty);
102 void (*start)(struct tty_struct* tty);
103 void (*hangup)(struct tty_struct* tty);
104 int (*break_ctl)(struct tty_struct* tty, int state);
105 void (*flush_buffer)(struct tty_struct* tty);
106 int (*ldisc_ok)(struct tty_struct* tty, int ldisc);
107 void (*set_ldisc)(struct tty_struct* tty);
108 void (*wait_until_sent)(struct tty_struct* tty, int timeout);
109 void (*send_xchar)(struct tty_struct* tty, u8 ch);
110 int (*tiocmget)(struct tty_struct* tty);
111 int (*tiocmset)(struct tty_struct* tty,
112 unsigned int set, unsigned int clear);
113 int (*resize)(struct tty_struct* tty, struct winsize* ws);
114 int (*get_icount)(struct tty_struct* tty,
115 struct serial_icounter_struct* icount);
116 int (*get_serial)(struct tty_struct* tty, struct serial_struct* p);
117 int (*set_serial)(struct tty_struct* tty, struct serial_struct* p);
118 void (*show_fdinfo)(struct tty_struct* tty, struct seq_file* m);
119 int (*proc_show)(struct seq_file* m, void* driver);
120};
121
123 struct kref kref;
124 struct cdev** cdevs;
125 struct module* owner;
126 const char* driver_name;
127 const char* name;
129 int major;
131 unsigned int num;
135 unsigned long flags;
136 struct proc_dir_entry* proc_entry;
139
140 /*
141 * Pointer to the tty data structures
142 */
143 struct tty_struct** ttys;
144 struct tty_port** ports;
147
148 /*
149 * Driver methods
150 */
151 const struct tty_operations* ops;
153};
154
155extern struct list_head tty_drivers;
156
158 struct module* owner, unsigned long flags);
159struct tty_driver* tty_find_polling_driver(char* name, int* line);
160
161void tty_driver_kref_put(struct tty_driver* driver);
162
163/*
164 * tty_alloc_driver -- allocate tty driver. Returns a PTR-encoded error (use
165 * IS_ERR() and friends), which is why the macro exists rather than a plain
166 * function: THIS_MODULE is (void*)0 in DCL, so the wrapper costs nothing but
167 * keeps the call sites byte-identical to mainline.
168 */
169#define tty_alloc_driver(lines, flags) \
170 __tty_alloc_driver(lines, THIS_MODULE, flags)
171
172static inline struct tty_driver* tty_driver_kref_get(struct tty_driver* d)
173{
174 kref_get(&d->kref);
175 return d;
176}
177
178static inline void tty_set_operations(struct tty_driver* driver,
179 const struct tty_operations* op)
180{
181 driver->ops = op;
182}
183
184int tty_register_driver(struct tty_driver* driver);
186struct device* tty_register_device(struct tty_driver* driver, unsigned index,
187 struct device* dev);
189 unsigned index, struct device* device, void* drvdata,
190 const struct attribute_group** attr_grp);
191void tty_unregister_device(struct tty_driver* driver, unsigned index);
192
195
196#endif /* _LINUX_TTY_DRIVER_H */
int64_t ssize_t
Definition stddef.h:38
uint8_t flags
Definition virtio.h:0
#define index(str, chr)
Definition string.h:66
#define BIT(nr)
Definition bitops.h:112
struct drm_crtc struct drm_plane struct drm_plane const struct drm_crtc_funcs const char * name
Definition drm_crtc.h:1242
const struct device * dev
Definition drm_print.h:519
#define d
Definition libunicode.c:1833
uint8_t u8
Definition kernel.h:14
AuProcess * owner
Definition netproxy.c:38
line_t * lines
Definition p_setup.c:67
Definition sysfs.h:33
Definition fs.h:210
Definition fs.h:255
Definition fs.h:142
Definition kref.h:44
Definition termios.h:250
Definition list.h:11
Definition seq_file.h:47
Definition serial.h:139
Definition serial.h:56
Definition tty_driver.h:122
struct ktermios init_termios
Definition tty_driver.h:134
const struct tty_operations * ops
Definition tty_driver.h:151
unsigned long flags
Definition tty_driver.h:135
struct tty_port ** ports
Definition tty_driver.h:144
struct module * owner
Definition tty_driver.h:125
struct workqueue_struct * flip_wq
Definition tty_driver.h:138
void * driver_state
Definition tty_driver.h:146
enum tty_driver_subtype subtype
Definition tty_driver.h:133
struct proc_dir_entry * proc_entry
Definition tty_driver.h:136
struct list_head tty_drivers
Definition tty_driver.h:152
int name_base
Definition tty_driver.h:128
struct cdev ** cdevs
Definition tty_driver.h:124
struct tty_driver * other
Definition tty_driver.h:137
int minor_start
Definition tty_driver.h:130
struct tty_struct ** ttys
Definition tty_driver.h:143
int major
Definition tty_driver.h:129
unsigned int num
Definition tty_driver.h:131
enum tty_driver_type type
Definition tty_driver.h:132
struct ktermios ** termios
Definition tty_driver.h:145
const char * name
Definition tty_driver.h:127
const char * driver_name
Definition tty_driver.h:126
Definition tty_driver.h:80
void(* hangup)(struct tty_struct *tty)
Definition tty_driver.h:103
unsigned int(* write_room)(struct tty_struct *tty)
Definition tty_driver.h:92
void(* throttle)(struct tty_struct *tty)
Definition tty_driver.h:99
void(* flush_chars)(struct tty_struct *tty)
Definition tty_driver.h:91
void(* stop)(struct tty_struct *tty)
Definition tty_driver.h:101
void(* set_termios)(struct tty_struct *tty, const struct ktermios *old)
Definition tty_driver.h:98
void(* cleanup)(struct tty_struct *tty)
Definition tty_driver.h:88
int(* ldisc_ok)(struct tty_struct *tty, int ldisc)
Definition tty_driver.h:106
int(* set_serial)(struct tty_struct *tty, struct serial_struct *p)
Definition tty_driver.h:117
void(* set_ldisc)(struct tty_struct *tty)
Definition tty_driver.h:107
void(* start)(struct tty_struct *tty)
Definition tty_driver.h:102
ssize_t(* write)(struct tty_struct *tty, const u8 *buf, size_t count)
Definition tty_driver.h:89
long(* compat_ioctl)(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
Definition tty_driver.h:96
void(* remove)(struct tty_driver *driver, struct tty_struct *tty)
Definition tty_driver.h:84
void(* unthrottle)(struct tty_struct *tty)
Definition tty_driver.h:100
void(* close)(struct tty_struct *tty, struct file *filp)
Definition tty_driver.h:86
int(* break_ctl)(struct tty_struct *tty, int state)
Definition tty_driver.h:104
int(* install)(struct tty_driver *driver, struct tty_struct *tty)
Definition tty_driver.h:83
int(* open)(struct tty_struct *tty, struct file *filp)
Definition tty_driver.h:85
int(* resize)(struct tty_struct *tty, struct winsize *ws)
Definition tty_driver.h:113
int(* tiocmset)(struct tty_struct *tty, unsigned int set, unsigned int clear)
Definition tty_driver.h:111
int(* ioctl)(struct tty_struct *tty, unsigned int cmd, unsigned long arg)
Definition tty_driver.h:94
int(* tiocmget)(struct tty_struct *tty)
Definition tty_driver.h:110
int(* proc_show)(struct seq_file *m, void *driver)
Definition tty_driver.h:119
int(* get_serial)(struct tty_struct *tty, struct serial_struct *p)
Definition tty_driver.h:116
void(* flush_buffer)(struct tty_struct *tty)
Definition tty_driver.h:105
void(* shutdown)(struct tty_struct *tty)
Definition tty_driver.h:87
void(* send_xchar)(struct tty_struct *tty, u8 ch)
Definition tty_driver.h:109
unsigned int(* chars_in_buffer)(struct tty_struct *tty)
Definition tty_driver.h:93
int(* get_icount)(struct tty_struct *tty, struct serial_icounter_struct *icount)
Definition tty_driver.h:114
int(* put_char)(struct tty_struct *tty, u8 ch)
Definition tty_driver.h:90
void(* wait_until_sent)(struct tty_struct *tty, int timeout)
Definition tty_driver.h:108
void(* show_fdinfo)(struct tty_struct *tty, struct seq_file *m)
Definition tty_driver.h:118
Definition tty_port.h:79
Definition tty.h:203
Definition termios.h:281
Definition workqueue.h:50
#define state(x)
struct tty_driver * tty_find_polling_driver(char *name, int *line)
int tty_register_driver(struct tty_driver *driver)
void tty_unregister_driver(struct tty_driver *driver)
struct tty_driver * __tty_alloc_driver(unsigned int lines, struct module *owner, unsigned long flags)
tty_driver_flag
Definition tty_driver.h:47
@ TTY_DRIVER_HARDWARE_BREAK
Definition tty_driver.h:53
@ TTY_DRIVER_DEVPTS_MEM
Definition tty_driver.h:52
@ TTY_DRIVER_INSTALLED
Definition tty_driver.h:48
@ TTY_DRIVER_NO_WORKQUEUE
Definition tty_driver.h:56
@ TTY_DRIVER_REAL_RAW
Definition tty_driver.h:50
@ TTY_DRIVER_DYNAMIC_DEV
Definition tty_driver.h:51
@ TTY_DRIVER_DYNAMIC_ALLOC
Definition tty_driver.h:54
@ TTY_DRIVER_UNNUMBERED_NODE
Definition tty_driver.h:55
@ TTY_DRIVER_RESET_TERMIOS
Definition tty_driver.h:49
struct device * tty_register_device(struct tty_driver *driver, unsigned index, struct device *dev)
struct list_head tty_drivers
tty_driver_type
Definition tty_driver.h:59
@ TTY_DRIVER_TYPE_SERIAL
Definition tty_driver.h:62
@ TTY_DRIVER_TYPE_SCC
Definition tty_driver.h:64
@ TTY_DRIVER_TYPE_SYSTEM
Definition tty_driver.h:60
@ TTY_DRIVER_TYPE_PTY
Definition tty_driver.h:63
@ TTY_DRIVER_TYPE_CONSOLE
Definition tty_driver.h:61
@ TTY_DRIVER_TYPE_SYSCONS
Definition tty_driver.h:65
void tty_driver_kref_put(struct tty_driver *driver)
void tty_unregister_device(struct tty_driver *driver, unsigned index)
struct device * tty_register_device_attr(struct tty_driver *driver, unsigned index, struct device *device, void *drvdata, const struct attribute_group **attr_grp)
void proc_tty_unregister_driver(struct tty_driver *)
void proc_tty_register_driver(struct tty_driver *)
tty_driver_subtype
Definition tty_driver.h:68
@ SYSTEM_TYPE_TTY
Definition tty_driver.h:69
@ SYSTEM_TYPE_SYSCONS
Definition tty_driver.h:71
@ SYSTEM_TYPE_CONSOLE
Definition tty_driver.h:70
@ SERIAL_TYPE_NORMAL
Definition tty_driver.h:77
@ PTY_TYPE_SLAVE
Definition tty_driver.h:75
@ PTY_TYPE_MASTER
Definition tty_driver.h:74
@ SYSTEM_TYPE_SYSPTMX
Definition tty_driver.h:72