Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef _LINUX_TTY_DRIVER_H |
2 | #define _LINUX_TTY_DRIVER_H | |
3 | ||
4 | /* | |
5 | * This structure defines the interface between the low-level tty | |
6 | * driver and the tty routines. The following routines can be | |
7 | * defined; unless noted otherwise, they are optional, and can be | |
8 | * filled in with a null pointer. | |
9 | * | |
10 | * int (*open)(struct tty_struct * tty, struct file * filp); | |
11 | * | |
12 | * This routine is called when a particular tty device is opened. | |
13 | * This routine is mandatory; if this routine is not filled in, | |
14 | * the attempted open will fail with ENODEV. | |
15 | * | |
16 | * void (*close)(struct tty_struct * tty, struct file * filp); | |
17 | * | |
18 | * This routine is called when a particular tty device is closed. | |
19 | * | |
20 | * int (*write)(struct tty_struct * tty, | |
21 | * const unsigned char *buf, int count); | |
22 | * | |
23 | * This routine is called by the kernel to write a series of | |
24 | * characters to the tty device. The characters may come from | |
25 | * user space or kernel space. This routine will return the | |
26 | * number of characters actually accepted for writing. This | |
27 | * routine is mandatory. | |
28 | * | |
29 | * void (*put_char)(struct tty_struct *tty, unsigned char ch); | |
30 | * | |
31 | * This routine is called by the kernel to write a single | |
32 | * character to the tty device. If the kernel uses this routine, | |
33 | * it must call the flush_chars() routine (if defined) when it is | |
34 | * done stuffing characters into the driver. If there is no room | |
35 | * in the queue, the character is ignored. | |
36 | * | |
37 | * void (*flush_chars)(struct tty_struct *tty); | |
38 | * | |
39 | * This routine is called by the kernel after it has written a | |
40 | * series of characters to the tty device using put_char(). | |
41 | * | |
42 | * int (*write_room)(struct tty_struct *tty); | |
43 | * | |
44 | * This routine returns the numbers of characters the tty driver | |
45 | * will accept for queuing to be written. This number is subject | |
46 | * to change as output buffers get emptied, or if the output flow | |
47 | * control is acted. | |
48 | * | |
49 | * int (*ioctl)(struct tty_struct *tty, struct file * file, | |
50 | * unsigned int cmd, unsigned long arg); | |
51 | * | |
52 | * This routine allows the tty driver to implement | |
53 | * device-specific ioctl's. If the ioctl number passed in cmd | |
54 | * is not recognized by the driver, it should return ENOIOCTLCMD. | |
55 | * | |
56 | * void (*set_termios)(struct tty_struct *tty, struct termios * old); | |
57 | * | |
58 | * This routine allows the tty driver to be notified when | |
59 | * device's termios settings have changed. Note that a | |
60 | * well-designed tty driver should be prepared to accept the case | |
61 | * where old == NULL, and try to do something rational. | |
62 | * | |
63 | * void (*set_ldisc)(struct tty_struct *tty); | |
64 | * | |
65 | * This routine allows the tty driver to be notified when the | |
66 | * device's termios settings have changed. | |
67 | * | |
68 | * void (*throttle)(struct tty_struct * tty); | |
69 | * | |
70 | * This routine notifies the tty driver that input buffers for | |
71 | * the line discipline are close to full, and it should somehow | |
72 | * signal that no more characters should be sent to the tty. | |
73 | * | |
74 | * void (*unthrottle)(struct tty_struct * tty); | |
75 | * | |
76 | * This routine notifies the tty drivers that it should signals | |
77 | * that characters can now be sent to the tty without fear of | |
78 | * overrunning the input buffers of the line disciplines. | |
79 | * | |
80 | * void (*stop)(struct tty_struct *tty); | |
81 | * | |
82 | * This routine notifies the tty driver that it should stop | |
83 | * outputting characters to the tty device. | |
84 | * | |
85 | * void (*start)(struct tty_struct *tty); | |
86 | * | |
87 | * This routine notifies the tty driver that it resume sending | |
88 | * characters to the tty device. | |
89 | * | |
90 | * void (*hangup)(struct tty_struct *tty); | |
91 | * | |
92 | * This routine notifies the tty driver that it should hangup the | |
93 | * tty device. | |
94 | * | |
95 | * void (*break_ctl)(struct tty_stuct *tty, int state); | |
96 | * | |
97 | * This optional routine requests the tty driver to turn on or | |
98 | * off BREAK status on the RS-232 port. If state is -1, | |
99 | * then the BREAK status should be turned on; if state is 0, then | |
100 | * BREAK should be turned off. | |
101 | * | |
102 | * If this routine is implemented, the high-level tty driver will | |
103 | * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK, | |
104 | * TIOCCBRK. Otherwise, these ioctls will be passed down to the | |
105 | * driver to handle. | |
106 | * | |
107 | * void (*wait_until_sent)(struct tty_struct *tty, int timeout); | |
108 | * | |
109 | * This routine waits until the device has written out all of the | |
110 | * characters in its transmitter FIFO. | |
111 | * | |
112 | * void (*send_xchar)(struct tty_struct *tty, char ch); | |
113 | * | |
114 | * This routine is used to send a high-priority XON/XOFF | |
115 | * character to the device. | |
116 | */ | |
117 | ||
118 | #include <linux/fs.h> | |
119 | #include <linux/list.h> | |
120 | #include <linux/cdev.h> | |
121 | ||
122 | struct tty_struct; | |
123 | ||
124 | struct tty_operations { | |
125 | int (*open)(struct tty_struct * tty, struct file * filp); | |
126 | void (*close)(struct tty_struct * tty, struct file * filp); | |
127 | int (*write)(struct tty_struct * tty, | |
128 | const unsigned char *buf, int count); | |
129 | void (*put_char)(struct tty_struct *tty, unsigned char ch); | |
130 | void (*flush_chars)(struct tty_struct *tty); | |
131 | int (*write_room)(struct tty_struct *tty); | |
132 | int (*chars_in_buffer)(struct tty_struct *tty); | |
133 | int (*ioctl)(struct tty_struct *tty, struct file * file, | |
134 | unsigned int cmd, unsigned long arg); | |
135 | void (*set_termios)(struct tty_struct *tty, struct termios * old); | |
136 | void (*throttle)(struct tty_struct * tty); | |
137 | void (*unthrottle)(struct tty_struct * tty); | |
138 | void (*stop)(struct tty_struct *tty); | |
139 | void (*start)(struct tty_struct *tty); | |
140 | void (*hangup)(struct tty_struct *tty); | |
141 | void (*break_ctl)(struct tty_struct *tty, int state); | |
142 | void (*flush_buffer)(struct tty_struct *tty); | |
143 | void (*set_ldisc)(struct tty_struct *tty); | |
144 | void (*wait_until_sent)(struct tty_struct *tty, int timeout); | |
145 | void (*send_xchar)(struct tty_struct *tty, char ch); | |
146 | int (*read_proc)(char *page, char **start, off_t off, | |
147 | int count, int *eof, void *data); | |
148 | int (*write_proc)(struct file *file, const char __user *buffer, | |
149 | unsigned long count, void *data); | |
150 | int (*tiocmget)(struct tty_struct *tty, struct file *file); | |
151 | int (*tiocmset)(struct tty_struct *tty, struct file *file, | |
152 | unsigned int set, unsigned int clear); | |
153 | }; | |
154 | ||
155 | struct tty_driver { | |
156 | int magic; /* magic number for this structure */ | |
157 | struct cdev cdev; | |
158 | struct module *owner; | |
159 | const char *driver_name; | |
1da177e4 LT |
160 | const char *name; |
161 | int name_base; /* offset of printed name */ | |
162 | int major; /* major device number */ | |
163 | int minor_start; /* start of minor device number */ | |
164 | int minor_num; /* number of *possible* devices */ | |
165 | int num; /* number of devices allocated */ | |
166 | short type; /* type of tty driver */ | |
167 | short subtype; /* subtype of tty driver */ | |
168 | struct termios init_termios; /* Initial termios */ | |
169 | int flags; /* tty driver flags */ | |
170 | int refcount; /* for loadable tty drivers */ | |
171 | struct proc_dir_entry *proc_entry; /* /proc fs entry */ | |
172 | struct tty_driver *other; /* only used for the PTY driver */ | |
173 | ||
174 | /* | |
175 | * Pointer to the tty data structures | |
176 | */ | |
177 | struct tty_struct **ttys; | |
178 | struct termios **termios; | |
179 | struct termios **termios_locked; | |
180 | void *driver_state; /* only used for the PTY driver */ | |
181 | ||
182 | /* | |
183 | * Interface routines from the upper tty layer to the tty | |
184 | * driver. Will be replaced with struct tty_operations. | |
185 | */ | |
186 | int (*open)(struct tty_struct * tty, struct file * filp); | |
187 | void (*close)(struct tty_struct * tty, struct file * filp); | |
188 | int (*write)(struct tty_struct * tty, | |
189 | const unsigned char *buf, int count); | |
190 | void (*put_char)(struct tty_struct *tty, unsigned char ch); | |
191 | void (*flush_chars)(struct tty_struct *tty); | |
192 | int (*write_room)(struct tty_struct *tty); | |
193 | int (*chars_in_buffer)(struct tty_struct *tty); | |
194 | int (*ioctl)(struct tty_struct *tty, struct file * file, | |
195 | unsigned int cmd, unsigned long arg); | |
196 | void (*set_termios)(struct tty_struct *tty, struct termios * old); | |
197 | void (*throttle)(struct tty_struct * tty); | |
198 | void (*unthrottle)(struct tty_struct * tty); | |
199 | void (*stop)(struct tty_struct *tty); | |
200 | void (*start)(struct tty_struct *tty); | |
201 | void (*hangup)(struct tty_struct *tty); | |
202 | void (*break_ctl)(struct tty_struct *tty, int state); | |
203 | void (*flush_buffer)(struct tty_struct *tty); | |
204 | void (*set_ldisc)(struct tty_struct *tty); | |
205 | void (*wait_until_sent)(struct tty_struct *tty, int timeout); | |
206 | void (*send_xchar)(struct tty_struct *tty, char ch); | |
207 | int (*read_proc)(char *page, char **start, off_t off, | |
208 | int count, int *eof, void *data); | |
209 | int (*write_proc)(struct file *file, const char __user *buffer, | |
210 | unsigned long count, void *data); | |
211 | int (*tiocmget)(struct tty_struct *tty, struct file *file); | |
212 | int (*tiocmset)(struct tty_struct *tty, struct file *file, | |
213 | unsigned int set, unsigned int clear); | |
214 | ||
215 | struct list_head tty_drivers; | |
216 | }; | |
217 | ||
218 | extern struct list_head tty_drivers; | |
219 | ||
220 | struct tty_driver *alloc_tty_driver(int lines); | |
221 | void put_tty_driver(struct tty_driver *driver); | |
b68e31d0 JD |
222 | void tty_set_operations(struct tty_driver *driver, |
223 | const struct tty_operations *op); | |
1da177e4 LT |
224 | |
225 | /* tty driver magic number */ | |
226 | #define TTY_DRIVER_MAGIC 0x5402 | |
227 | ||
228 | /* | |
229 | * tty driver flags | |
230 | * | |
231 | * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the | |
232 | * termios setting when the last process has closed the device. | |
233 | * Used for PTY's, in particular. | |
234 | * | |
235 | * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will | |
236 | * guarantee never not to set any special character handling | |
237 | * flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR || | |
238 | * !INPCK)). That is, if there is no reason for the driver to | |
239 | * send notifications of parity and break characters up to the | |
240 | * line driver, it won't do so. This allows the line driver to | |
241 | * optimize for this case if this flag is set. (Note that there | |
242 | * is also a promise, if the above case is true, not to signal | |
243 | * overruns, either.) | |
244 | * | |
331b8319 GKH |
245 | * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need |
246 | * to be registered with a call to tty_register_driver() when the | |
247 | * device is found in the system and unregistered with a call to | |
248 | * tty_unregister_device() so the devices will be show up | |
249 | * properly in sysfs. If not set, driver->num entries will be | |
250 | * created by the tty core in sysfs when tty_register_driver() is | |
251 | * called. This is to be used by drivers that have tty devices | |
252 | * that can appear and disappear while the main tty driver is | |
253 | * registered with the tty core. | |
1da177e4 LT |
254 | * |
255 | * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead | |
256 | * use dynamic memory keyed through the devpts filesystem. This | |
257 | * is only applicable to the pty driver. | |
258 | */ | |
259 | #define TTY_DRIVER_INSTALLED 0x0001 | |
260 | #define TTY_DRIVER_RESET_TERMIOS 0x0002 | |
261 | #define TTY_DRIVER_REAL_RAW 0x0004 | |
331b8319 | 262 | #define TTY_DRIVER_DYNAMIC_DEV 0x0008 |
1da177e4 LT |
263 | #define TTY_DRIVER_DEVPTS_MEM 0x0010 |
264 | ||
265 | /* tty driver types */ | |
266 | #define TTY_DRIVER_TYPE_SYSTEM 0x0001 | |
267 | #define TTY_DRIVER_TYPE_CONSOLE 0x0002 | |
268 | #define TTY_DRIVER_TYPE_SERIAL 0x0003 | |
269 | #define TTY_DRIVER_TYPE_PTY 0x0004 | |
270 | #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */ | |
271 | #define TTY_DRIVER_TYPE_SYSCONS 0x0006 | |
272 | ||
273 | /* system subtypes (magic, used by tty_io.c) */ | |
274 | #define SYSTEM_TYPE_TTY 0x0001 | |
275 | #define SYSTEM_TYPE_CONSOLE 0x0002 | |
276 | #define SYSTEM_TYPE_SYSCONS 0x0003 | |
277 | #define SYSTEM_TYPE_SYSPTMX 0x0004 | |
278 | ||
279 | /* pty subtypes (magic, used by tty_io.c) */ | |
280 | #define PTY_TYPE_MASTER 0x0001 | |
281 | #define PTY_TYPE_SLAVE 0x0002 | |
282 | ||
283 | /* serial subtype definitions */ | |
284 | #define SERIAL_TYPE_NORMAL 1 | |
285 | ||
286 | #endif /* #ifdef _LINUX_TTY_DRIVER_H */ |