tty: add kernel-doc for tty_ldisc_ops
[linux-2.6-block.git] / include / linux / tty_ldisc.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef _LINUX_TTY_LDISC_H
3#define _LINUX_TTY_LDISC_H
4
a24bc667
JS
5struct tty_struct;
6
1da177e4
LT
7#include <linux/fs.h>
8#include <linux/wait.h>
5fd691af 9#include <linux/atomic.h>
abca9901
JS
10#include <linux/list.h>
11#include <linux/lockdep.h>
a24bc667 12#include <linux/seq_file.h>
4898e640
PH
13
14/*
15 * the semaphore definition
16 */
17struct ld_semaphore {
5fd691af 18 atomic_long_t count;
4898e640
PH
19 raw_spinlock_t wait_lock;
20 unsigned int wait_readers;
21 struct list_head read_wait;
22 struct list_head write_wait;
23#ifdef CONFIG_DEBUG_LOCK_ALLOC
24 struct lockdep_map dep_map;
25#endif
26};
27
78941934 28void __init_ldsem(struct ld_semaphore *sem, const char *name,
4898e640
PH
29 struct lock_class_key *key);
30
31#define init_ldsem(sem) \
32do { \
33 static struct lock_class_key __key; \
34 \
35 __init_ldsem((sem), #sem, &__key); \
36} while (0)
37
38
78941934
JS
39int ldsem_down_read(struct ld_semaphore *sem, long timeout);
40int ldsem_down_read_trylock(struct ld_semaphore *sem);
41int ldsem_down_write(struct ld_semaphore *sem, long timeout);
42int ldsem_down_write_trylock(struct ld_semaphore *sem);
43void ldsem_up_read(struct ld_semaphore *sem);
44void ldsem_up_write(struct ld_semaphore *sem);
4898e640
PH
45
46#ifdef CONFIG_DEBUG_LOCK_ALLOC
78941934
JS
47int ldsem_down_read_nested(struct ld_semaphore *sem, int subclass,
48 long timeout);
49int ldsem_down_write_nested(struct ld_semaphore *sem, int subclass,
50 long timeout);
4898e640
PH
51#else
52# define ldsem_down_read_nested(sem, subclass, timeout) \
53 ldsem_down_read(sem, timeout)
54# define ldsem_down_write_nested(sem, subclass, timeout) \
55 ldsem_down_write(sem, timeout)
56#endif
57
0c6119f9
JS
58/**
59 * struct tty_ldisc_ops - ldisc operations
60 *
61 * @name: name of this ldisc rendered in /proc/tty/ldiscs
62 * @num: ``N_*`` number (%N_TTY, %N_HDLC, ...) reserved to this ldisc
63 *
64 * @open: ``int ()(struct tty_struct *tty)``
65 *
66 * This function is called when the line discipline is associated with the
67 * @tty. The line discipline can use this as an opportunity to initialize
68 * any state needed by the ldisc routines.
69 *
70 * @close: ``void ()(struct tty_struct *tty)``
71 *
72 * This function is called when the line discipline is being shutdown,
73 * either because the @tty is being closed or because the @tty is being
74 * changed to use a new line discipline
75 *
76 * @flush_buffer: ``void ()(struct tty_struct *tty)``
77 *
78 * This function instructs the line discipline to clear its buffers of any
79 * input characters it may have queued to be delivered to the user mode
80 * process.
81 *
82 * @read: ``ssize_t ()(struct tty_struct *tty, struct file *file,
83 * unsigned char *buf, size_t nr)``
84 *
85 * This function is called when the user requests to read from the @tty.
86 * The line discipline will return whatever characters it has buffered up
87 * for the user. If this function is not defined, the user will receive
88 * an %EIO error.
89 *
90 * @write: ``ssize_t ()(struct tty_struct *tty, struct file *file,
91 * const unsigned char *buf, size_t nr)``
92 *
93 * This function is called when the user requests to write to the @tty.
94 * The line discipline will deliver the characters to the low-level tty
95 * device for transmission, optionally performing some processing on the
96 * characters first. If this function is not defined, the user will
97 * receive an %EIO error.
98 *
99 * @ioctl: ``int ()(struct tty_struct *tty, unsigned int cmd,
100 * unsigned long arg)``
101 *
102 * This function is called when the user requests an ioctl which is not
103 * handled by the tty layer or the low-level tty driver. It is intended
104 * for ioctls which affect line discpline operation. Note that the search
105 * order for ioctls is (1) tty layer, (2) tty low-level driver, (3) line
106 * discpline. So a low-level driver can "grab" an ioctl request before
107 * the line discpline has a chance to see it.
108 *
109 * @compat_ioctl: ``int ()(struct tty_struct *tty, unsigned int cmd,
110 * unsigned long arg)``
111 *
112 * Process ioctl calls from 32-bit process on 64-bit system.
113 *
114 * Note that only ioctls that are neither "pointer to compatible
115 * structure" nor tty-generic. Something private that takes an integer or
116 * a pointer to wordsize-sensitive structure belongs here, but most of
117 * ldiscs will happily leave it %NULL.
118 *
119 * @set_termios: ``void ()(struct tty_struct *tty, struct ktermios *old)``
120 *
121 * This function notifies the line discpline that a change has been made
122 * to the termios structure.
123 *
124 * @poll: ``int ()(struct tty_struct *tty, struct file *file,
125 * struct poll_table_struct *wait)``
126 *
127 * This function is called when a user attempts to select/poll on a @tty
128 * device. It is solely the responsibility of the line discipline to
129 * handle poll requests.
130 *
131 * @hangup: ``void ()(struct tty_struct *tty)``
132 *
133 * Called on a hangup. Tells the discipline that it should cease I/O to
134 * the tty driver. Can sleep. The driver should seek to perform this
135 * action quickly but should wait until any pending driver I/O is
136 * completed.
137 *
138 * @receive_buf: ``void ()(struct tty_struct *tty, const unsigned char *cp,
139 * const char *fp, int count)``
140 *
141 * This function is called by the low-level tty driver to send characters
142 * received by the hardware to the line discpline for processing. @cp is
143 * a pointer to the buffer of input character received by the device. @fp
144 * is a pointer to an array of flag bytes which indicate whether a
145 * character was received with a parity error, etc. @fp may be %NULL to
146 * indicate all data received is %TTY_NORMAL.
147 *
148 * @write_wakeup: ``void ()(struct tty_struct *tty)``
149 *
150 * This function is called by the low-level tty driver to signal that line
151 * discpline should try to send more characters to the low-level driver
152 * for transmission. If the line discpline does not have any more data to
153 * send, it can just return. If the line discipline does have some data to
154 * send, please arise a tasklet or workqueue to do the real data transfer.
155 * Do not send data in this hook, it may lead to a deadlock.
156 *
157 * @dcd_change: ``void ()(struct tty_struct *tty, unsigned int status)``
158 *
159 * Tells the discipline that the DCD pin has changed its status. Used
160 * exclusively by the %N_PPS (Pulse-Per-Second) line discipline.
161 *
162 * @receive_buf2: ``int ()(struct tty_struct *tty, const unsigned char *cp,
163 * const char *fp, int count)``
164 *
165 * This function is called by the low-level tty driver to send characters
166 * received by the hardware to the line discpline for processing. @cp is a
167 * pointer to the buffer of input character received by the device. @fp
168 * is a pointer to an array of flag bytes which indicate whether a
169 * character was received with a parity error, etc. @fp may be %NULL to
170 * indicate all data received is %TTY_NORMAL. If assigned, prefer this
171 * function for automatic flow control.
172 *
173 * @owner: module containting this ldisc (for reference counting)
174 *
175 * This structure defines the interface between the tty line discipline
176 * implementation and the tty routines. The above routines can be defined.
177 * Unless noted otherwise, they are optional, and can be filled in with a %NULL
178 * pointer.
179 */
a352def2 180struct tty_ldisc_ops {
1da177e4
LT
181 char *name;
182 int num;
6be06e72 183
1da177e4
LT
184 /*
185 * The following routines are called from above.
186 */
0c6119f9
JS
187 int (*open)(struct tty_struct *tty);
188 void (*close)(struct tty_struct *tty);
1da177e4 189 void (*flush_buffer)(struct tty_struct *tty);
6be06e72 190 ssize_t (*read)(struct tty_struct *tty, struct file *file,
3b830a9c
LT
191 unsigned char *buf, size_t nr,
192 void **cookie, unsigned long offset);
6be06e72
PH
193 ssize_t (*write)(struct tty_struct *tty, struct file *file,
194 const unsigned char *buf, size_t nr);
d78328bc
JS
195 int (*ioctl)(struct tty_struct *tty, unsigned int cmd,
196 unsigned long arg);
197 int (*compat_ioctl)(struct tty_struct *tty, unsigned int cmd,
198 unsigned long arg);
6be06e72 199 void (*set_termios)(struct tty_struct *tty, struct ktermios *old);
0c6119f9
JS
200 __poll_t (*poll)(struct tty_struct *tty, struct file *file,
201 struct poll_table_struct *wait);
28f194da 202 void (*hangup)(struct tty_struct *tty);
6be06e72 203
1da177e4
LT
204 /*
205 * The following routines are called from below.
206 */
0c6119f9 207 void (*receive_buf)(struct tty_struct *tty, const unsigned char *cp,
0f3dcf3b 208 const char *fp, int count);
0c6119f9
JS
209 void (*write_wakeup)(struct tty_struct *tty);
210 void (*dcd_change)(struct tty_struct *tty, unsigned int status);
211 int (*receive_buf2)(struct tty_struct *tty, const unsigned char *cp,
0f3dcf3b 212 const char *fp, int count);
1da177e4
LT
213
214 struct module *owner;
1da177e4
LT
215};
216
a352def2
AC
217struct tty_ldisc {
218 struct tty_ldisc_ops *ops;
36697529 219 struct tty_struct *tty;
a352def2
AC
220};
221
1da177e4
LT
222#define MODULE_ALIAS_LDISC(ldisc) \
223 MODULE_ALIAS("tty-ldisc-" __stringify(ldisc))
224
a24bc667
JS
225extern const struct seq_operations tty_ldiscs_seq_ops;
226
227struct tty_ldisc *tty_ldisc_ref(struct tty_struct *);
228void tty_ldisc_deref(struct tty_ldisc *);
229struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *);
230
231void tty_ldisc_flush(struct tty_struct *tty);
232
233int tty_register_ldisc(struct tty_ldisc_ops *new_ldisc);
234void tty_unregister_ldisc(struct tty_ldisc_ops *ldisc);
235int tty_set_ldisc(struct tty_struct *tty, int disc);
236
1da177e4 237#endif /* _LINUX_TTY_LDISC_H */