tty_driver.h 12.3 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#ifndef _LINUX_TTY_DRIVER_H
#define _LINUX_TTY_DRIVER_H

/*
 * This structure defines the interface between the low-level tty
 * driver and the tty routines.  The following routines can be
 * defined; unless noted otherwise, they are optional, and can be
 * filled in with a null pointer.
 *
 * int  (*open)(struct tty_struct * tty, struct file * filp);
 *
 * 	This routine is called when a particular tty device is opened.
 * 	This routine is mandatory; if this routine is not filled in,
 * 	the attempted open will fail with ENODEV.
A
Alan Cox 已提交
15 16
 *
 *	Required method.
L
Linus Torvalds 已提交
17 18 19 20 21
 *     
 * void (*close)(struct tty_struct * tty, struct file * filp);
 *
 * 	This routine is called when a particular tty device is closed.
 *
A
Alan Cox 已提交
22 23
 *	Required method.
 *
A
Alan Cox 已提交
24 25 26 27 28
 * void (*shutdown)(struct tty_struct * tty);
 *
 * 	This routine is called when a particular tty device is closed for
 *	the last time freeing up the resources.
 *
L
Linus Torvalds 已提交
29 30 31 32 33 34
 * int (*write)(struct tty_struct * tty,
 * 		 const unsigned char *buf, int count);
 *
 * 	This routine is called by the kernel to write a series of
 * 	characters to the tty device.  The characters may come from
 * 	user space or kernel space.  This routine will return the
35
 *	number of characters actually accepted for writing.
L
Linus Torvalds 已提交
36
 *
A
Alan Cox 已提交
37 38 39
 *	Optional: Required for writable devices.
 *
 * int (*put_char)(struct tty_struct *tty, unsigned char ch);
L
Linus Torvalds 已提交
40 41 42 43 44 45 46
 *
 * 	This routine is called by the kernel to write a single
 * 	character to the tty device.  If the kernel uses this routine,
 * 	it must call the flush_chars() routine (if defined) when it is
 * 	done stuffing characters into the driver.  If there is no room
 * 	in the queue, the character is ignored.
 *
A
Alan Cox 已提交
47 48 49 50
 *	Optional: Kernel will use the write method if not provided.
 *
 *	Note: Do not call this function directly, call tty_put_char
 *
L
Linus Torvalds 已提交
51 52 53 54
 * void (*flush_chars)(struct tty_struct *tty);
 *
 * 	This routine is called by the kernel after it has written a
 * 	series of characters to the tty device using put_char().  
A
Alan Cox 已提交
55 56 57 58
 *
 *	Optional:
 *
 *	Note: Do not call this function directly, call tty_driver_flush_chars
L
Linus Torvalds 已提交
59 60 61 62 63 64 65
 * 
 * int  (*write_room)(struct tty_struct *tty);
 *
 * 	This routine returns the numbers of characters the tty driver
 * 	will accept for queuing to be written.  This number is subject
 * 	to change as output buffers get emptied, or if the output flow
 *	control is acted.
A
Alan Cox 已提交
66 67 68 69
 *
 *	Required if write method is provided else not needed.
 *
 *	Note: Do not call this function directly, call tty_write_room
L
Linus Torvalds 已提交
70 71 72 73 74 75 76
 * 
 * int  (*ioctl)(struct tty_struct *tty, struct file * file,
 * 	    unsigned int cmd, unsigned long arg);
 *
 * 	This routine allows the tty driver to implement
 *	device-specific ioctl's.  If the ioctl number passed in cmd
 * 	is not recognized by the driver, it should return ENOIOCTLCMD.
P
Paul Fulghum 已提交
77
 *
A
Alan Cox 已提交
78 79
 *	Optional
 *
P
Paul Fulghum 已提交
80 81 82 83
 * long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
 * 	                unsigned int cmd, unsigned long arg);
 *
 * 	implement ioctl processing for 32 bit process on 64 bit system
A
Alan Cox 已提交
84 85
 *
 *	Optional
L
Linus Torvalds 已提交
86
 * 
87
 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
L
Linus Torvalds 已提交
88 89
 *
 * 	This routine allows the tty driver to be notified when
A
Alan Cox 已提交
90 91 92 93
 * 	device's termios settings have changed.
 *
 *	Optional: Called under the termios lock
 *
L
Linus Torvalds 已提交
94 95 96 97 98
 *
 * void (*set_ldisc)(struct tty_struct *tty);
 *
 * 	This routine allows the tty driver to be notified when the
 * 	device's termios settings have changed.
A
Alan Cox 已提交
99 100
 *
 *	Optional: Called under BKL (currently)
L
Linus Torvalds 已提交
101 102 103 104 105 106
 * 
 * void (*throttle)(struct tty_struct * tty);
 *
 * 	This routine notifies the tty driver that input buffers for
 * 	the line discipline are close to full, and it should somehow
 * 	signal that no more characters should be sent to the tty.
A
Alan Cox 已提交
107 108
 *
 *	Optional: Always invoke via tty_throttle();
L
Linus Torvalds 已提交
109 110 111 112 113 114 115
 * 
 * void (*unthrottle)(struct tty_struct * tty);
 *
 * 	This routine notifies the tty drivers that it should signals
 * 	that characters can now be sent to the tty without fear of
 * 	overrunning the input buffers of the line disciplines.
 * 
A
Alan Cox 已提交
116 117
 *	Optional: Always invoke via tty_unthrottle();
 *
L
Linus Torvalds 已提交
118 119 120 121
 * void (*stop)(struct tty_struct *tty);
 *
 * 	This routine notifies the tty driver that it should stop
 * 	outputting characters to the tty device.  
A
Alan Cox 已提交
122 123 124 125
 *
 *	Optional:
 *
 *	Note: Call stop_tty not this method.
L
Linus Torvalds 已提交
126 127 128 129 130
 * 
 * void (*start)(struct tty_struct *tty);
 *
 * 	This routine notifies the tty driver that it resume sending
 *	characters to the tty device.
A
Alan Cox 已提交
131 132 133 134
 *
 *	Optional:
 *
 *	Note: Call start_tty not this method.
L
Linus Torvalds 已提交
135 136 137 138 139 140
 * 
 * void (*hangup)(struct tty_struct *tty);
 *
 * 	This routine notifies the tty driver that it should hangup the
 * 	tty device.
 *
141
 *	Optional:
A
Alan Cox 已提交
142
 *
A
Alan Cox 已提交
143
 * int (*break_ctl)(struct tty_stuct *tty, int state);
L
Linus Torvalds 已提交
144 145 146 147 148 149 150 151
 *
 * 	This optional routine requests the tty driver to turn on or
 * 	off BREAK status on the RS-232 port.  If state is -1,
 * 	then the BREAK status should be turned on; if state is 0, then
 * 	BREAK should be turned off.
 *
 * 	If this routine is implemented, the high-level tty driver will
 * 	handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
A
Alan Cox 已提交
152 153
 * 	TIOCCBRK.
 *
A
Alan Cox 已提交
154 155 156 157
 *	If the driver sets TTY_DRIVER_HARDWARE_BREAK then the interface
 *	will also be called with actual times and the hardware is expected
 *	to do the delay work itself. 0 and -1 are still used for on/off.
 *
A
Alan Cox 已提交
158
 *	Optional: Required for TCSBRK/BRKP/etc handling.
L
Linus Torvalds 已提交
159 160 161 162 163 164
 *
 * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
 * 
 * 	This routine waits until the device has written out all of the
 * 	characters in its transmitter FIFO.
 *
A
Alan Cox 已提交
165 166 167 168
 *	Optional: If not provided the device is assumed to have no FIFO
 *
 *	Note: Usually correct to call tty_wait_until_sent
 *
L
Linus Torvalds 已提交
169 170 171 172
 * void (*send_xchar)(struct tty_struct *tty, char ch);
 *
 * 	This routine is used to send a high-priority XON/XOFF
 * 	character to the device.
A
Alan Cox 已提交
173 174 175
 *
 *	Optional: If not provided then the write method is called under
 *	the atomic write lock to keep it serialized with the ldisc.
176 177 178 179 180 181 182 183 184 185 186 187
 *
 * int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty,
 *				unsigned int rows, unsigned int cols);
 *
 *	Called when a termios request is issued which changes the
 *	requested terminal geometry.
 *
 *	Optional: the default action is to update the termios structure
 *	without error. This is usually the correct behaviour. Drivers should
 *	not force errors here if they are not resizable objects (eg a serial
 *	line). See tty_do_resize() if you need to wrap the standard method
 *	in your own logic - the usual case.
A
Alan Cox 已提交
188 189 190 191 192 193 194 195
 *
 * void (*set_termiox)(struct tty_struct *tty, struct termiox *new);
 *
 *	Called when the device receives a termiox based ioctl. Passes down
 *	the requested data from user space. This method will not be invoked
 *	unless the tty also has a valid tty->termiox pointer.
 *
 *	Optional: Called under the termios lock
L
Linus Torvalds 已提交
196 197 198 199 200 201 202
 */

#include <linux/fs.h>
#include <linux/list.h>
#include <linux/cdev.h>

struct tty_struct;
J
Jason Wessel 已提交
203
struct tty_driver;
L
Linus Torvalds 已提交
204 205 206 207

struct tty_operations {
	int  (*open)(struct tty_struct * tty, struct file * filp);
	void (*close)(struct tty_struct * tty, struct file * filp);
A
Alan Cox 已提交
208
	void (*shutdown)(struct tty_struct *tty);
L
Linus Torvalds 已提交
209 210
	int  (*write)(struct tty_struct * tty,
		      const unsigned char *buf, int count);
A
Alan Cox 已提交
211
	int  (*put_char)(struct tty_struct *tty, unsigned char ch);
L
Linus Torvalds 已提交
212 213 214 215 216
	void (*flush_chars)(struct tty_struct *tty);
	int  (*write_room)(struct tty_struct *tty);
	int  (*chars_in_buffer)(struct tty_struct *tty);
	int  (*ioctl)(struct tty_struct *tty, struct file * file,
		    unsigned int cmd, unsigned long arg);
P
Paul Fulghum 已提交
217 218
	long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
			     unsigned int cmd, unsigned long arg);
219
	void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
L
Linus Torvalds 已提交
220 221 222 223 224
	void (*throttle)(struct tty_struct * tty);
	void (*unthrottle)(struct tty_struct * tty);
	void (*stop)(struct tty_struct *tty);
	void (*start)(struct tty_struct *tty);
	void (*hangup)(struct tty_struct *tty);
A
Alan Cox 已提交
225
	int (*break_ctl)(struct tty_struct *tty, int state);
L
Linus Torvalds 已提交
226 227 228 229 230 231 232 233 234
	void (*flush_buffer)(struct tty_struct *tty);
	void (*set_ldisc)(struct tty_struct *tty);
	void (*wait_until_sent)(struct tty_struct *tty, int timeout);
	void (*send_xchar)(struct tty_struct *tty, char ch);
	int (*read_proc)(char *page, char **start, off_t off,
			  int count, int *eof, void *data);
	int (*tiocmget)(struct tty_struct *tty, struct file *file);
	int (*tiocmset)(struct tty_struct *tty, struct file *file,
			unsigned int set, unsigned int clear);
235 236
	int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty,
				struct winsize *ws);
A
Alan Cox 已提交
237
	int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
J
Jason Wessel 已提交
238 239 240 241 242
#ifdef CONFIG_CONSOLE_POLL
	int (*poll_init)(struct tty_driver *driver, int line, char *options);
	int (*poll_get_char)(struct tty_driver *driver, int line);
	void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
#endif
L
Linus Torvalds 已提交
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
};

struct tty_driver {
	int	magic;		/* magic number for this structure */
	struct cdev cdev;
	struct module	*owner;
	const char	*driver_name;
	const char	*name;
	int	name_base;	/* offset of printed name */
	int	major;		/* major device number */
	int	minor_start;	/* start of minor device number */
	int	minor_num;	/* number of *possible* devices */
	int	num;		/* number of devices allocated */
	short	type;		/* type of tty driver */
	short	subtype;	/* subtype of tty driver */
258
	struct ktermios init_termios; /* Initial termios */
L
Linus Torvalds 已提交
259 260 261 262 263 264 265 266 267
	int	flags;		/* tty driver flags */
	int	refcount;	/* for loadable tty drivers */
	struct proc_dir_entry *proc_entry; /* /proc fs entry */
	struct tty_driver *other; /* only used for the PTY driver */

	/*
	 * Pointer to the tty data structures
	 */
	struct tty_struct **ttys;
268 269
	struct ktermios **termios;
	struct ktermios **termios_locked;
A
Alan Cox 已提交
270 271
	void *driver_state;

L
Linus Torvalds 已提交
272
	/*
A
Alan Cox 已提交
273
	 * Driver methods
L
Linus Torvalds 已提交
274 275
	 */

A
Alan Cox 已提交
276
	const struct tty_operations *ops;
L
Linus Torvalds 已提交
277 278 279 280 281 282 283
	struct list_head tty_drivers;
};

extern struct list_head tty_drivers;

struct tty_driver *alloc_tty_driver(int lines);
void put_tty_driver(struct tty_driver *driver);
J
Jeff Dike 已提交
284 285
void tty_set_operations(struct tty_driver *driver,
			const struct tty_operations *op);
J
Jason Wessel 已提交
286
extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
L
Linus Torvalds 已提交
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307

/* tty driver magic number */
#define TTY_DRIVER_MAGIC		0x5402

/*
 * tty driver flags
 * 
 * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the
 * 	termios setting when the last process has closed the device.
 * 	Used for PTY's, in particular.
 * 
 * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will
 * 	guarantee never not to set any special character handling
 * 	flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR ||
 * 	!INPCK)).  That is, if there is no reason for the driver to
 * 	send notifications of parity and break characters up to the
 * 	line driver, it won't do so.  This allows the line driver to
 *	optimize for this case if this flag is set.  (Note that there
 * 	is also a promise, if the above case is true, not to signal
 * 	overruns, either.)
 *
308 309 310 311 312 313 314 315 316
 * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need
 *	to be registered with a call to tty_register_driver() when the
 *	device is found in the system and unregistered with a call to
 *	tty_unregister_device() so the devices will be show up
 *	properly in sysfs.  If not set, driver->num entries will be
 *	created by the tty core in sysfs when tty_register_driver() is
 *	called.  This is to be used by drivers that have tty devices
 *	that can appear and disappear while the main tty driver is
 *	registered with the tty core.
L
Linus Torvalds 已提交
317 318 319 320
 *
 * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
 *	use dynamic memory keyed through the devpts filesystem.  This
 *	is only applicable to the pty driver.
A
Alan Cox 已提交
321 322 323 324 325
 *
 * TTY_DRIVER_HARDWARE_BREAK -- hardware handles break signals. Pass
 *	the requested timeout to the caller instead of using a simple
 *	on/off interface.
 *
L
Linus Torvalds 已提交
326 327 328 329
 */
#define TTY_DRIVER_INSTALLED		0x0001
#define TTY_DRIVER_RESET_TERMIOS	0x0002
#define TTY_DRIVER_REAL_RAW		0x0004
330
#define TTY_DRIVER_DYNAMIC_DEV		0x0008
L
Linus Torvalds 已提交
331
#define TTY_DRIVER_DEVPTS_MEM		0x0010
A
Alan Cox 已提交
332
#define TTY_DRIVER_HARDWARE_BREAK	0x0020
L
Linus Torvalds 已提交
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355

/* tty driver types */
#define TTY_DRIVER_TYPE_SYSTEM		0x0001
#define TTY_DRIVER_TYPE_CONSOLE		0x0002
#define TTY_DRIVER_TYPE_SERIAL		0x0003
#define TTY_DRIVER_TYPE_PTY		0x0004
#define TTY_DRIVER_TYPE_SCC		0x0005	/* scc driver */
#define TTY_DRIVER_TYPE_SYSCONS		0x0006

/* system subtypes (magic, used by tty_io.c) */
#define SYSTEM_TYPE_TTY			0x0001
#define SYSTEM_TYPE_CONSOLE		0x0002
#define SYSTEM_TYPE_SYSCONS		0x0003
#define SYSTEM_TYPE_SYSPTMX		0x0004

/* pty subtypes (magic, used by tty_io.c) */
#define PTY_TYPE_MASTER			0x0001
#define PTY_TYPE_SLAVE			0x0002

/* serial subtype definitions */
#define SERIAL_TYPE_NORMAL	1

#endif /* #ifdef _LINUX_TTY_DRIVER_H */