xref: /OK3568_Linux_fs/kernel/include/linux/tty_driver.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _LINUX_TTY_DRIVER_H
3*4882a593Smuzhiyun #define _LINUX_TTY_DRIVER_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun /*
6*4882a593Smuzhiyun  * This structure defines the interface between the low-level tty
7*4882a593Smuzhiyun  * driver and the tty routines.  The following routines can be
8*4882a593Smuzhiyun  * defined; unless noted otherwise, they are optional, and can be
9*4882a593Smuzhiyun  * filled in with a null pointer.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * struct tty_struct * (*lookup)(struct tty_driver *self, struct file *, int idx)
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  *	Return the tty device corresponding to idx, NULL if there is not
14*4882a593Smuzhiyun  *	one currently in use and an ERR_PTR value on error. Called under
15*4882a593Smuzhiyun  *	tty_mutex (for now!)
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  *	Optional method. Default behaviour is to use the ttys array
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * int (*install)(struct tty_driver *self, struct tty_struct *tty)
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  *	Install a new tty into the tty driver internal tables. Used in
22*4882a593Smuzhiyun  *	conjunction with lookup and remove methods.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  *	Optional method. Default behaviour is to use the ttys array
25*4882a593Smuzhiyun  *
26*4882a593Smuzhiyun  * void (*remove)(struct tty_driver *self, struct tty_struct *tty)
27*4882a593Smuzhiyun  *
28*4882a593Smuzhiyun  *	Remove a closed tty from the tty driver internal tables. Used in
29*4882a593Smuzhiyun  *	conjunction with lookup and remove methods.
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  *	Optional method. Default behaviour is to use the ttys array
32*4882a593Smuzhiyun  *
33*4882a593Smuzhiyun  * int  (*open)(struct tty_struct * tty, struct file * filp);
34*4882a593Smuzhiyun  *
35*4882a593Smuzhiyun  * 	This routine is called when a particular tty device is opened.
36*4882a593Smuzhiyun  * 	This routine is mandatory; if this routine is not filled in,
37*4882a593Smuzhiyun  * 	the attempted open will fail with ENODEV.
38*4882a593Smuzhiyun  *
39*4882a593Smuzhiyun  *	Required method. Called with tty lock held.
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  * void (*close)(struct tty_struct * tty, struct file * filp);
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  * 	This routine is called when a particular tty device is closed.
44*4882a593Smuzhiyun  *	Note: called even if the corresponding open() failed.
45*4882a593Smuzhiyun  *
46*4882a593Smuzhiyun  *	Required method. Called with tty lock held.
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  * void (*shutdown)(struct tty_struct * tty);
49*4882a593Smuzhiyun  *
50*4882a593Smuzhiyun  * 	This routine is called under the tty lock when a particular tty device
51*4882a593Smuzhiyun  *	is closed for the last time. It executes before the tty resources
52*4882a593Smuzhiyun  *	are freed so may execute while another function holds a tty kref.
53*4882a593Smuzhiyun  *
54*4882a593Smuzhiyun  * void (*cleanup)(struct tty_struct * tty);
55*4882a593Smuzhiyun  *
56*4882a593Smuzhiyun  *	This routine is called asynchronously when a particular tty device
57*4882a593Smuzhiyun  *	is closed for the last time freeing up the resources. This is
58*4882a593Smuzhiyun  *	actually the second part of shutdown for routines that might sleep.
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  * int (*write)(struct tty_struct * tty,
62*4882a593Smuzhiyun  * 		 const unsigned char *buf, int count);
63*4882a593Smuzhiyun  *
64*4882a593Smuzhiyun  * 	This routine is called by the kernel to write a series of
65*4882a593Smuzhiyun  * 	characters to the tty device.  The characters may come from
66*4882a593Smuzhiyun  * 	user space or kernel space.  This routine will return the
67*4882a593Smuzhiyun  *	number of characters actually accepted for writing.
68*4882a593Smuzhiyun  *
69*4882a593Smuzhiyun  *	Optional: Required for writable devices.
70*4882a593Smuzhiyun  *
71*4882a593Smuzhiyun  * int (*put_char)(struct tty_struct *tty, unsigned char ch);
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * 	This routine is called by the kernel to write a single
74*4882a593Smuzhiyun  * 	character to the tty device.  If the kernel uses this routine,
75*4882a593Smuzhiyun  * 	it must call the flush_chars() routine (if defined) when it is
76*4882a593Smuzhiyun  * 	done stuffing characters into the driver.  If there is no room
77*4882a593Smuzhiyun  * 	in the queue, the character is ignored.
78*4882a593Smuzhiyun  *
79*4882a593Smuzhiyun  *	Optional: Kernel will use the write method if not provided.
80*4882a593Smuzhiyun  *
81*4882a593Smuzhiyun  *	Note: Do not call this function directly, call tty_put_char
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  * void (*flush_chars)(struct tty_struct *tty);
84*4882a593Smuzhiyun  *
85*4882a593Smuzhiyun  * 	This routine is called by the kernel after it has written a
86*4882a593Smuzhiyun  * 	series of characters to the tty device using put_char().
87*4882a593Smuzhiyun  *
88*4882a593Smuzhiyun  *	Optional:
89*4882a593Smuzhiyun  *
90*4882a593Smuzhiyun  *	Note: Do not call this function directly, call tty_driver_flush_chars
91*4882a593Smuzhiyun  *
92*4882a593Smuzhiyun  * int  (*write_room)(struct tty_struct *tty);
93*4882a593Smuzhiyun  *
94*4882a593Smuzhiyun  * 	This routine returns the numbers of characters the tty driver
95*4882a593Smuzhiyun  * 	will accept for queuing to be written.  This number is subject
96*4882a593Smuzhiyun  * 	to change as output buffers get emptied, or if the output flow
97*4882a593Smuzhiyun  *	control is acted.
98*4882a593Smuzhiyun  *
99*4882a593Smuzhiyun  *	Required if write method is provided else not needed.
100*4882a593Smuzhiyun  *
101*4882a593Smuzhiyun  *	Note: Do not call this function directly, call tty_write_room
102*4882a593Smuzhiyun  *
103*4882a593Smuzhiyun  * int  (*ioctl)(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
104*4882a593Smuzhiyun  *
105*4882a593Smuzhiyun  * 	This routine allows the tty driver to implement
106*4882a593Smuzhiyun  *	device-specific ioctls.  If the ioctl number passed in cmd
107*4882a593Smuzhiyun  * 	is not recognized by the driver, it should return ENOIOCTLCMD.
108*4882a593Smuzhiyun  *
109*4882a593Smuzhiyun  *	Optional
110*4882a593Smuzhiyun  *
111*4882a593Smuzhiyun  * long (*compat_ioctl)(struct tty_struct *tty,,
112*4882a593Smuzhiyun  * 	                unsigned int cmd, unsigned long arg);
113*4882a593Smuzhiyun  *
114*4882a593Smuzhiyun  * 	implement ioctl processing for 32 bit process on 64 bit system
115*4882a593Smuzhiyun  *
116*4882a593Smuzhiyun  *	Optional
117*4882a593Smuzhiyun  *
118*4882a593Smuzhiyun  * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
119*4882a593Smuzhiyun  *
120*4882a593Smuzhiyun  * 	This routine allows the tty driver to be notified when
121*4882a593Smuzhiyun  * 	device's termios settings have changed.
122*4882a593Smuzhiyun  *
123*4882a593Smuzhiyun  *	Optional: Called under the termios lock
124*4882a593Smuzhiyun  *
125*4882a593Smuzhiyun  *
126*4882a593Smuzhiyun  * void (*set_ldisc)(struct tty_struct *tty);
127*4882a593Smuzhiyun  *
128*4882a593Smuzhiyun  * 	This routine allows the tty driver to be notified when the
129*4882a593Smuzhiyun  * 	device's termios settings have changed.
130*4882a593Smuzhiyun  *
131*4882a593Smuzhiyun  *	Optional: Called under BKL (currently)
132*4882a593Smuzhiyun  *
133*4882a593Smuzhiyun  * void (*throttle)(struct tty_struct * tty);
134*4882a593Smuzhiyun  *
135*4882a593Smuzhiyun  * 	This routine notifies the tty driver that input buffers for
136*4882a593Smuzhiyun  * 	the line discipline are close to full, and it should somehow
137*4882a593Smuzhiyun  * 	signal that no more characters should be sent to the tty.
138*4882a593Smuzhiyun  *
139*4882a593Smuzhiyun  *	Optional: Always invoke via tty_throttle(), called under the
140*4882a593Smuzhiyun  *	termios lock.
141*4882a593Smuzhiyun  *
142*4882a593Smuzhiyun  * void (*unthrottle)(struct tty_struct * tty);
143*4882a593Smuzhiyun  *
144*4882a593Smuzhiyun  * 	This routine notifies the tty drivers that it should signals
145*4882a593Smuzhiyun  * 	that characters can now be sent to the tty without fear of
146*4882a593Smuzhiyun  * 	overrunning the input buffers of the line disciplines.
147*4882a593Smuzhiyun  *
148*4882a593Smuzhiyun  *	Optional: Always invoke via tty_unthrottle(), called under the
149*4882a593Smuzhiyun  *	termios lock.
150*4882a593Smuzhiyun  *
151*4882a593Smuzhiyun  * void (*stop)(struct tty_struct *tty);
152*4882a593Smuzhiyun  *
153*4882a593Smuzhiyun  * 	This routine notifies the tty driver that it should stop
154*4882a593Smuzhiyun  * 	outputting characters to the tty device.
155*4882a593Smuzhiyun  *
156*4882a593Smuzhiyun  *	Called with ->flow_lock held. Serialized with start() method.
157*4882a593Smuzhiyun  *
158*4882a593Smuzhiyun  *	Optional:
159*4882a593Smuzhiyun  *
160*4882a593Smuzhiyun  *	Note: Call stop_tty not this method.
161*4882a593Smuzhiyun  *
162*4882a593Smuzhiyun  * void (*start)(struct tty_struct *tty);
163*4882a593Smuzhiyun  *
164*4882a593Smuzhiyun  * 	This routine notifies the tty driver that it resume sending
165*4882a593Smuzhiyun  *	characters to the tty device.
166*4882a593Smuzhiyun  *
167*4882a593Smuzhiyun  *	Called with ->flow_lock held. Serialized with stop() method.
168*4882a593Smuzhiyun  *
169*4882a593Smuzhiyun  *	Optional:
170*4882a593Smuzhiyun  *
171*4882a593Smuzhiyun  *	Note: Call start_tty not this method.
172*4882a593Smuzhiyun  *
173*4882a593Smuzhiyun  * void (*hangup)(struct tty_struct *tty);
174*4882a593Smuzhiyun  *
175*4882a593Smuzhiyun  * 	This routine notifies the tty driver that it should hang up the
176*4882a593Smuzhiyun  * 	tty device.
177*4882a593Smuzhiyun  *
178*4882a593Smuzhiyun  *	Optional:
179*4882a593Smuzhiyun  *
180*4882a593Smuzhiyun  *	Called with tty lock held.
181*4882a593Smuzhiyun  *
182*4882a593Smuzhiyun  * int (*break_ctl)(struct tty_struct *tty, int state);
183*4882a593Smuzhiyun  *
184*4882a593Smuzhiyun  * 	This optional routine requests the tty driver to turn on or
185*4882a593Smuzhiyun  * 	off BREAK status on the RS-232 port.  If state is -1,
186*4882a593Smuzhiyun  * 	then the BREAK status should be turned on; if state is 0, then
187*4882a593Smuzhiyun  * 	BREAK should be turned off.
188*4882a593Smuzhiyun  *
189*4882a593Smuzhiyun  * 	If this routine is implemented, the high-level tty driver will
190*4882a593Smuzhiyun  * 	handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
191*4882a593Smuzhiyun  * 	TIOCCBRK.
192*4882a593Smuzhiyun  *
193*4882a593Smuzhiyun  *	If the driver sets TTY_DRIVER_HARDWARE_BREAK then the interface
194*4882a593Smuzhiyun  *	will also be called with actual times and the hardware is expected
195*4882a593Smuzhiyun  *	to do the delay work itself. 0 and -1 are still used for on/off.
196*4882a593Smuzhiyun  *
197*4882a593Smuzhiyun  *	Optional: Required for TCSBRK/BRKP/etc handling.
198*4882a593Smuzhiyun  *
199*4882a593Smuzhiyun  * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
200*4882a593Smuzhiyun  *
201*4882a593Smuzhiyun  * 	This routine waits until the device has written out all of the
202*4882a593Smuzhiyun  * 	characters in its transmitter FIFO.
203*4882a593Smuzhiyun  *
204*4882a593Smuzhiyun  *	Optional: If not provided the device is assumed to have no FIFO
205*4882a593Smuzhiyun  *
206*4882a593Smuzhiyun  *	Note: Usually correct to call tty_wait_until_sent
207*4882a593Smuzhiyun  *
208*4882a593Smuzhiyun  * void (*send_xchar)(struct tty_struct *tty, char ch);
209*4882a593Smuzhiyun  *
210*4882a593Smuzhiyun  * 	This routine is used to send a high-priority XON/XOFF
211*4882a593Smuzhiyun  * 	character to the device.
212*4882a593Smuzhiyun  *
213*4882a593Smuzhiyun  *	Optional: If not provided then the write method is called under
214*4882a593Smuzhiyun  *	the atomic write lock to keep it serialized with the ldisc.
215*4882a593Smuzhiyun  *
216*4882a593Smuzhiyun  * int (*resize)(struct tty_struct *tty, struct winsize *ws)
217*4882a593Smuzhiyun  *
218*4882a593Smuzhiyun  *	Called when a termios request is issued which changes the
219*4882a593Smuzhiyun  *	requested terminal geometry.
220*4882a593Smuzhiyun  *
221*4882a593Smuzhiyun  *	Optional: the default action is to update the termios structure
222*4882a593Smuzhiyun  *	without error. This is usually the correct behaviour. Drivers should
223*4882a593Smuzhiyun  *	not force errors here if they are not resizable objects (eg a serial
224*4882a593Smuzhiyun  *	line). See tty_do_resize() if you need to wrap the standard method
225*4882a593Smuzhiyun  *	in your own logic - the usual case.
226*4882a593Smuzhiyun  *
227*4882a593Smuzhiyun  * int (*get_icount)(struct tty_struct *tty, struct serial_icounter *icount);
228*4882a593Smuzhiyun  *
229*4882a593Smuzhiyun  *	Called when the device receives a TIOCGICOUNT ioctl. Passed a kernel
230*4882a593Smuzhiyun  *	structure to complete. This method is optional and will only be called
231*4882a593Smuzhiyun  *	if provided (otherwise ENOTTY will be returned).
232*4882a593Smuzhiyun  */
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun #include <linux/export.h>
235*4882a593Smuzhiyun #include <linux/fs.h>
236*4882a593Smuzhiyun #include <linux/list.h>
237*4882a593Smuzhiyun #include <linux/cdev.h>
238*4882a593Smuzhiyun #include <linux/termios.h>
239*4882a593Smuzhiyun #include <linux/seq_file.h>
240*4882a593Smuzhiyun #include <linux/android_kabi.h>
241*4882a593Smuzhiyun 
242*4882a593Smuzhiyun struct tty_struct;
243*4882a593Smuzhiyun struct tty_driver;
244*4882a593Smuzhiyun struct serial_icounter_struct;
245*4882a593Smuzhiyun struct serial_struct;
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun struct tty_operations {
248*4882a593Smuzhiyun 	struct tty_struct * (*lookup)(struct tty_driver *driver,
249*4882a593Smuzhiyun 			struct file *filp, int idx);
250*4882a593Smuzhiyun 	int  (*install)(struct tty_driver *driver, struct tty_struct *tty);
251*4882a593Smuzhiyun 	void (*remove)(struct tty_driver *driver, struct tty_struct *tty);
252*4882a593Smuzhiyun 	int  (*open)(struct tty_struct * tty, struct file * filp);
253*4882a593Smuzhiyun 	void (*close)(struct tty_struct * tty, struct file * filp);
254*4882a593Smuzhiyun 	void (*shutdown)(struct tty_struct *tty);
255*4882a593Smuzhiyun 	void (*cleanup)(struct tty_struct *tty);
256*4882a593Smuzhiyun 	int  (*write)(struct tty_struct * tty,
257*4882a593Smuzhiyun 		      const unsigned char *buf, int count);
258*4882a593Smuzhiyun 	int  (*put_char)(struct tty_struct *tty, unsigned char ch);
259*4882a593Smuzhiyun 	void (*flush_chars)(struct tty_struct *tty);
260*4882a593Smuzhiyun 	int  (*write_room)(struct tty_struct *tty);
261*4882a593Smuzhiyun 	int  (*chars_in_buffer)(struct tty_struct *tty);
262*4882a593Smuzhiyun 	int  (*ioctl)(struct tty_struct *tty,
263*4882a593Smuzhiyun 		    unsigned int cmd, unsigned long arg);
264*4882a593Smuzhiyun 	long (*compat_ioctl)(struct tty_struct *tty,
265*4882a593Smuzhiyun 			     unsigned int cmd, unsigned long arg);
266*4882a593Smuzhiyun 	void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
267*4882a593Smuzhiyun 	void (*throttle)(struct tty_struct * tty);
268*4882a593Smuzhiyun 	void (*unthrottle)(struct tty_struct * tty);
269*4882a593Smuzhiyun 	void (*stop)(struct tty_struct *tty);
270*4882a593Smuzhiyun 	void (*start)(struct tty_struct *tty);
271*4882a593Smuzhiyun 	void (*hangup)(struct tty_struct *tty);
272*4882a593Smuzhiyun 	int (*break_ctl)(struct tty_struct *tty, int state);
273*4882a593Smuzhiyun 	void (*flush_buffer)(struct tty_struct *tty);
274*4882a593Smuzhiyun 	void (*set_ldisc)(struct tty_struct *tty);
275*4882a593Smuzhiyun 	void (*wait_until_sent)(struct tty_struct *tty, int timeout);
276*4882a593Smuzhiyun 	void (*send_xchar)(struct tty_struct *tty, char ch);
277*4882a593Smuzhiyun 	int (*tiocmget)(struct tty_struct *tty);
278*4882a593Smuzhiyun 	int (*tiocmset)(struct tty_struct *tty,
279*4882a593Smuzhiyun 			unsigned int set, unsigned int clear);
280*4882a593Smuzhiyun 	int (*resize)(struct tty_struct *tty, struct winsize *ws);
281*4882a593Smuzhiyun 
282*4882a593Smuzhiyun 	/* only for abi preservation */
283*4882a593Smuzhiyun 	int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun 	int (*get_icount)(struct tty_struct *tty,
286*4882a593Smuzhiyun 				struct serial_icounter_struct *icount);
287*4882a593Smuzhiyun 	int  (*get_serial)(struct tty_struct *tty, struct serial_struct *p);
288*4882a593Smuzhiyun 	int  (*set_serial)(struct tty_struct *tty, struct serial_struct *p);
289*4882a593Smuzhiyun 	void (*show_fdinfo)(struct tty_struct *tty, struct seq_file *m);
290*4882a593Smuzhiyun #ifdef CONFIG_CONSOLE_POLL
291*4882a593Smuzhiyun 	int (*poll_init)(struct tty_driver *driver, int line, char *options);
292*4882a593Smuzhiyun 	int (*poll_get_char)(struct tty_driver *driver, int line);
293*4882a593Smuzhiyun 	void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
294*4882a593Smuzhiyun #endif
295*4882a593Smuzhiyun 	int (*proc_show)(struct seq_file *, void *);
296*4882a593Smuzhiyun 
297*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
298*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(2);
299*4882a593Smuzhiyun } __randomize_layout;
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun struct tty_driver {
302*4882a593Smuzhiyun 	int	magic;		/* magic number for this structure */
303*4882a593Smuzhiyun 	struct kref kref;	/* Reference management */
304*4882a593Smuzhiyun 	struct cdev **cdevs;
305*4882a593Smuzhiyun 	struct module	*owner;
306*4882a593Smuzhiyun 	const char	*driver_name;
307*4882a593Smuzhiyun 	const char	*name;
308*4882a593Smuzhiyun 	int	name_base;	/* offset of printed name */
309*4882a593Smuzhiyun 	int	major;		/* major device number */
310*4882a593Smuzhiyun 	int	minor_start;	/* start of minor device number */
311*4882a593Smuzhiyun 	unsigned int	num;	/* number of devices allocated */
312*4882a593Smuzhiyun 	short	type;		/* type of tty driver */
313*4882a593Smuzhiyun 	short	subtype;	/* subtype of tty driver */
314*4882a593Smuzhiyun 	struct ktermios init_termios; /* Initial termios */
315*4882a593Smuzhiyun 	unsigned long	flags;		/* tty driver flags */
316*4882a593Smuzhiyun 	struct proc_dir_entry *proc_entry; /* /proc fs entry */
317*4882a593Smuzhiyun 	struct tty_driver *other; /* only used for the PTY driver */
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun 	/*
320*4882a593Smuzhiyun 	 * Pointer to the tty data structures
321*4882a593Smuzhiyun 	 */
322*4882a593Smuzhiyun 	struct tty_struct **ttys;
323*4882a593Smuzhiyun 	struct tty_port **ports;
324*4882a593Smuzhiyun 	struct ktermios **termios;
325*4882a593Smuzhiyun 	void *driver_state;
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun 	/*
328*4882a593Smuzhiyun 	 * Driver methods
329*4882a593Smuzhiyun 	 */
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 	const struct tty_operations *ops;
332*4882a593Smuzhiyun 	struct list_head tty_drivers;
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(1);
335*4882a593Smuzhiyun 	ANDROID_KABI_RESERVE(2);
336*4882a593Smuzhiyun } __randomize_layout;
337*4882a593Smuzhiyun 
338*4882a593Smuzhiyun extern struct list_head tty_drivers;
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun extern struct tty_driver *__tty_alloc_driver(unsigned int lines,
341*4882a593Smuzhiyun 		struct module *owner, unsigned long flags);
342*4882a593Smuzhiyun extern void put_tty_driver(struct tty_driver *driver);
343*4882a593Smuzhiyun extern void tty_set_operations(struct tty_driver *driver,
344*4882a593Smuzhiyun 			const struct tty_operations *op);
345*4882a593Smuzhiyun extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
346*4882a593Smuzhiyun 
347*4882a593Smuzhiyun extern void tty_driver_kref_put(struct tty_driver *driver);
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun /* Use TTY_DRIVER_* flags below */
350*4882a593Smuzhiyun #define tty_alloc_driver(lines, flags) \
351*4882a593Smuzhiyun 		__tty_alloc_driver(lines, THIS_MODULE, flags)
352*4882a593Smuzhiyun 
353*4882a593Smuzhiyun /*
354*4882a593Smuzhiyun  * DEPRECATED Do not use this in new code, use tty_alloc_driver instead.
355*4882a593Smuzhiyun  * (And change the return value checks.)
356*4882a593Smuzhiyun  */
alloc_tty_driver(unsigned int lines)357*4882a593Smuzhiyun static inline struct tty_driver *alloc_tty_driver(unsigned int lines)
358*4882a593Smuzhiyun {
359*4882a593Smuzhiyun 	struct tty_driver *ret = tty_alloc_driver(lines, 0);
360*4882a593Smuzhiyun 	if (IS_ERR(ret))
361*4882a593Smuzhiyun 		return NULL;
362*4882a593Smuzhiyun 	return ret;
363*4882a593Smuzhiyun }
364*4882a593Smuzhiyun 
tty_driver_kref_get(struct tty_driver * d)365*4882a593Smuzhiyun static inline struct tty_driver *tty_driver_kref_get(struct tty_driver *d)
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun 	kref_get(&d->kref);
368*4882a593Smuzhiyun 	return d;
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun /* tty driver magic number */
372*4882a593Smuzhiyun #define TTY_DRIVER_MAGIC		0x5402
373*4882a593Smuzhiyun 
374*4882a593Smuzhiyun /*
375*4882a593Smuzhiyun  * tty driver flags
376*4882a593Smuzhiyun  *
377*4882a593Smuzhiyun  * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the
378*4882a593Smuzhiyun  * 	termios setting when the last process has closed the device.
379*4882a593Smuzhiyun  * 	Used for PTY's, in particular.
380*4882a593Smuzhiyun  *
381*4882a593Smuzhiyun  * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will
382*4882a593Smuzhiyun  * 	guarantee never not to set any special character handling
383*4882a593Smuzhiyun  * 	flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR ||
384*4882a593Smuzhiyun  * 	!INPCK)).  That is, if there is no reason for the driver to
385*4882a593Smuzhiyun  * 	send notifications of parity and break characters up to the
386*4882a593Smuzhiyun  * 	line driver, it won't do so.  This allows the line driver to
387*4882a593Smuzhiyun  *	optimize for this case if this flag is set.  (Note that there
388*4882a593Smuzhiyun  * 	is also a promise, if the above case is true, not to signal
389*4882a593Smuzhiyun  * 	overruns, either.)
390*4882a593Smuzhiyun  *
391*4882a593Smuzhiyun  * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need
392*4882a593Smuzhiyun  *	to be registered with a call to tty_register_device() when the
393*4882a593Smuzhiyun  *	device is found in the system and unregistered with a call to
394*4882a593Smuzhiyun  *	tty_unregister_device() so the devices will be show up
395*4882a593Smuzhiyun  *	properly in sysfs.  If not set, driver->num entries will be
396*4882a593Smuzhiyun  *	created by the tty core in sysfs when tty_register_driver() is
397*4882a593Smuzhiyun  *	called.  This is to be used by drivers that have tty devices
398*4882a593Smuzhiyun  *	that can appear and disappear while the main tty driver is
399*4882a593Smuzhiyun  *	registered with the tty core.
400*4882a593Smuzhiyun  *
401*4882a593Smuzhiyun  * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
402*4882a593Smuzhiyun  *	use dynamic memory keyed through the devpts filesystem.  This
403*4882a593Smuzhiyun  *	is only applicable to the pty driver.
404*4882a593Smuzhiyun  *
405*4882a593Smuzhiyun  * TTY_DRIVER_HARDWARE_BREAK -- hardware handles break signals. Pass
406*4882a593Smuzhiyun  *	the requested timeout to the caller instead of using a simple
407*4882a593Smuzhiyun  *	on/off interface.
408*4882a593Smuzhiyun  *
409*4882a593Smuzhiyun  * TTY_DRIVER_DYNAMIC_ALLOC -- do not allocate structures which are
410*4882a593Smuzhiyun  *	needed per line for this driver as it would waste memory.
411*4882a593Smuzhiyun  *	The driver will take care.
412*4882a593Smuzhiyun  *
413*4882a593Smuzhiyun  * TTY_DRIVER_UNNUMBERED_NODE -- do not create numbered /dev nodes. In
414*4882a593Smuzhiyun  *	other words create /dev/ttyprintk and not /dev/ttyprintk0.
415*4882a593Smuzhiyun  *	Applicable only when a driver for a single tty device is
416*4882a593Smuzhiyun  *	being allocated.
417*4882a593Smuzhiyun  */
418*4882a593Smuzhiyun #define TTY_DRIVER_INSTALLED		0x0001
419*4882a593Smuzhiyun #define TTY_DRIVER_RESET_TERMIOS	0x0002
420*4882a593Smuzhiyun #define TTY_DRIVER_REAL_RAW		0x0004
421*4882a593Smuzhiyun #define TTY_DRIVER_DYNAMIC_DEV		0x0008
422*4882a593Smuzhiyun #define TTY_DRIVER_DEVPTS_MEM		0x0010
423*4882a593Smuzhiyun #define TTY_DRIVER_HARDWARE_BREAK	0x0020
424*4882a593Smuzhiyun #define TTY_DRIVER_DYNAMIC_ALLOC	0x0040
425*4882a593Smuzhiyun #define TTY_DRIVER_UNNUMBERED_NODE	0x0080
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun /* tty driver types */
428*4882a593Smuzhiyun #define TTY_DRIVER_TYPE_SYSTEM		0x0001
429*4882a593Smuzhiyun #define TTY_DRIVER_TYPE_CONSOLE		0x0002
430*4882a593Smuzhiyun #define TTY_DRIVER_TYPE_SERIAL		0x0003
431*4882a593Smuzhiyun #define TTY_DRIVER_TYPE_PTY		0x0004
432*4882a593Smuzhiyun #define TTY_DRIVER_TYPE_SCC		0x0005	/* scc driver */
433*4882a593Smuzhiyun #define TTY_DRIVER_TYPE_SYSCONS		0x0006
434*4882a593Smuzhiyun 
435*4882a593Smuzhiyun /* system subtypes (magic, used by tty_io.c) */
436*4882a593Smuzhiyun #define SYSTEM_TYPE_TTY			0x0001
437*4882a593Smuzhiyun #define SYSTEM_TYPE_CONSOLE		0x0002
438*4882a593Smuzhiyun #define SYSTEM_TYPE_SYSCONS		0x0003
439*4882a593Smuzhiyun #define SYSTEM_TYPE_SYSPTMX		0x0004
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun /* pty subtypes (magic, used by tty_io.c) */
442*4882a593Smuzhiyun #define PTY_TYPE_MASTER			0x0001
443*4882a593Smuzhiyun #define PTY_TYPE_SLAVE			0x0002
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun /* serial subtype definitions */
446*4882a593Smuzhiyun #define SERIAL_TYPE_NORMAL	1
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun #endif /* #ifdef _LINUX_TTY_DRIVER_H */
449