1
2#ifndef _LINUX_TTY_PORT_H
3#define _LINUX_TTY_PORT_H
4
5#include <linux/kfifo.h>
6#include <linux/kref.h>
7#include <linux/mutex.h>
8#include <linux/tty_buffer.h>
9#include <linux/wait.h>
10
11struct attribute_group;
12struct tty_driver;
13struct tty_port;
14struct tty_struct;
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33struct tty_port_operations {
34 int (*carrier_raised)(struct tty_port *port);
35 void (*dtr_rts)(struct tty_port *port, int raise);
36 void (*shutdown)(struct tty_port *port);
37 int (*activate)(struct tty_port *port, struct tty_struct *tty);
38 void (*destruct)(struct tty_port *port);
39};
40
41struct tty_port_client_operations {
42 int (*receive_buf)(struct tty_port *port, const unsigned char *, const unsigned char *, size_t);
43 void (*write_wakeup)(struct tty_port *port);
44};
45
46extern const struct tty_port_client_operations tty_port_default_client_ops;
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98struct tty_port {
99 struct tty_bufhead buf;
100 struct tty_struct *tty;
101 struct tty_struct *itty;
102 const struct tty_port_operations *ops;
103 const struct tty_port_client_operations *client_ops;
104 spinlock_t lock;
105 int blocked_open;
106 int count;
107 wait_queue_head_t open_wait;
108 wait_queue_head_t delta_msr_wait;
109 unsigned long flags;
110 unsigned long iflags;
111 unsigned char console:1;
112 struct mutex mutex;
113 struct mutex buf_mutex;
114 unsigned char *xmit_buf;
115 DECLARE_KFIFO_PTR(xmit_fifo, unsigned char);
116 unsigned int close_delay;
117 unsigned int closing_wait;
118 int drain_delay;
119 struct kref kref;
120 void *client_data;
121};
122
123
124#define TTY_PORT_INITIALIZED 0
125#define TTY_PORT_SUSPENDED 1
126#define TTY_PORT_ACTIVE 2
127
128
129
130
131
132#define TTY_PORT_CTS_FLOW 3
133#define TTY_PORT_CHECK_CD 4
134#define TTY_PORT_KOPENED 5
135
136
137void tty_port_init(struct tty_port *port);
138void tty_port_link_device(struct tty_port *port, struct tty_driver *driver,
139 unsigned index);
140struct device *tty_port_register_device(struct tty_port *port,
141 struct tty_driver *driver, unsigned index,
142 struct device *device);
143struct device *tty_port_register_device_attr(struct tty_port *port,
144 struct tty_driver *driver, unsigned index,
145 struct device *device, void *drvdata,
146 const struct attribute_group **attr_grp);
147struct device *tty_port_register_device_serdev(struct tty_port *port,
148 struct tty_driver *driver, unsigned index,
149 struct device *device);
150struct device *tty_port_register_device_attr_serdev(struct tty_port *port,
151 struct tty_driver *driver, unsigned index,
152 struct device *device, void *drvdata,
153 const struct attribute_group **attr_grp);
154void tty_port_unregister_device(struct tty_port *port,
155 struct tty_driver *driver, unsigned index);
156int tty_port_alloc_xmit_buf(struct tty_port *port);
157void tty_port_free_xmit_buf(struct tty_port *port);
158void tty_port_destroy(struct tty_port *port);
159void tty_port_put(struct tty_port *port);
160
161static inline struct tty_port *tty_port_get(struct tty_port *port)
162{
163 if (port && kref_get_unless_zero(&port->kref))
164 return port;
165 return NULL;
166}
167
168
169static inline bool tty_port_cts_enabled(const struct tty_port *port)
170{
171 return test_bit(TTY_PORT_CTS_FLOW, &port->iflags);
172}
173
174static inline void tty_port_set_cts_flow(struct tty_port *port, bool val)
175{
176 assign_bit(TTY_PORT_CTS_FLOW, &port->iflags, val);
177}
178
179static inline bool tty_port_active(const struct tty_port *port)
180{
181 return test_bit(TTY_PORT_ACTIVE, &port->iflags);
182}
183
184static inline void tty_port_set_active(struct tty_port *port, bool val)
185{
186 assign_bit(TTY_PORT_ACTIVE, &port->iflags, val);
187}
188
189static inline bool tty_port_check_carrier(const struct tty_port *port)
190{
191 return test_bit(TTY_PORT_CHECK_CD, &port->iflags);
192}
193
194static inline void tty_port_set_check_carrier(struct tty_port *port, bool val)
195{
196 assign_bit(TTY_PORT_CHECK_CD, &port->iflags, val);
197}
198
199static inline bool tty_port_suspended(const struct tty_port *port)
200{
201 return test_bit(TTY_PORT_SUSPENDED, &port->iflags);
202}
203
204static inline void tty_port_set_suspended(struct tty_port *port, bool val)
205{
206 assign_bit(TTY_PORT_SUSPENDED, &port->iflags, val);
207}
208
209static inline bool tty_port_initialized(const struct tty_port *port)
210{
211 return test_bit(TTY_PORT_INITIALIZED, &port->iflags);
212}
213
214static inline void tty_port_set_initialized(struct tty_port *port, bool val)
215{
216 assign_bit(TTY_PORT_INITIALIZED, &port->iflags, val);
217}
218
219static inline bool tty_port_kopened(const struct tty_port *port)
220{
221 return test_bit(TTY_PORT_KOPENED, &port->iflags);
222}
223
224static inline void tty_port_set_kopened(struct tty_port *port, bool val)
225{
226 assign_bit(TTY_PORT_KOPENED, &port->iflags, val);
227}
228
229struct tty_struct *tty_port_tty_get(struct tty_port *port);
230void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty);
231int tty_port_carrier_raised(struct tty_port *port);
232void tty_port_raise_dtr_rts(struct tty_port *port);
233void tty_port_lower_dtr_rts(struct tty_port *port);
234void tty_port_hangup(struct tty_port *port);
235void tty_port_tty_hangup(struct tty_port *port, bool check_clocal);
236void tty_port_tty_wakeup(struct tty_port *port);
237int tty_port_block_til_ready(struct tty_port *port, struct tty_struct *tty,
238 struct file *filp);
239int tty_port_close_start(struct tty_port *port, struct tty_struct *tty,
240 struct file *filp);
241void tty_port_close_end(struct tty_port *port, struct tty_struct *tty);
242void tty_port_close(struct tty_port *port, struct tty_struct *tty,
243 struct file *filp);
244int tty_port_install(struct tty_port *port, struct tty_driver *driver,
245 struct tty_struct *tty);
246int tty_port_open(struct tty_port *port, struct tty_struct *tty,
247 struct file *filp);
248
249static inline int tty_port_users(struct tty_port *port)
250{
251 return port->count + port->blocked_open;
252}
253
254#endif
255