tty_driver.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. #ifndef _LINUX_TTY_DRIVER_H
  2. #define _LINUX_TTY_DRIVER_H
  3. /*
  4. * This structure defines the interface between the low-level tty
  5. * driver and the tty routines. The following routines can be
  6. * defined; unless noted otherwise, they are optional, and can be
  7. * filled in with a null pointer.
  8. *
  9. * int (*open)(struct tty_struct * tty, struct file * filp);
  10. *
  11. * This routine is called when a particular tty device is opened.
  12. * This routine is mandatory; if this routine is not filled in,
  13. * the attempted open will fail with ENODEV.
  14. *
  15. * Required method.
  16. *
  17. * void (*close)(struct tty_struct * tty, struct file * filp);
  18. *
  19. * This routine is called when a particular tty device is closed.
  20. *
  21. * Required method.
  22. *
  23. * void (*shutdown)(struct tty_struct * tty);
  24. *
  25. * This routine is called when a particular tty device is closed for
  26. * the last time freeing up the resources.
  27. *
  28. * int (*write)(struct tty_struct * tty,
  29. * const unsigned char *buf, int count);
  30. *
  31. * This routine is called by the kernel to write a series of
  32. * characters to the tty device. The characters may come from
  33. * user space or kernel space. This routine will return the
  34. * number of characters actually accepted for writing.
  35. *
  36. * Optional: Required for writable devices.
  37. *
  38. * int (*put_char)(struct tty_struct *tty, unsigned char ch);
  39. *
  40. * This routine is called by the kernel to write a single
  41. * character to the tty device. If the kernel uses this routine,
  42. * it must call the flush_chars() routine (if defined) when it is
  43. * done stuffing characters into the driver. If there is no room
  44. * in the queue, the character is ignored.
  45. *
  46. * Optional: Kernel will use the write method if not provided.
  47. *
  48. * Note: Do not call this function directly, call tty_put_char
  49. *
  50. * void (*flush_chars)(struct tty_struct *tty);
  51. *
  52. * This routine is called by the kernel after it has written a
  53. * series of characters to the tty device using put_char().
  54. *
  55. * Optional:
  56. *
  57. * Note: Do not call this function directly, call tty_driver_flush_chars
  58. *
  59. * int (*write_room)(struct tty_struct *tty);
  60. *
  61. * This routine returns the numbers of characters the tty driver
  62. * will accept for queuing to be written. This number is subject
  63. * to change as output buffers get emptied, or if the output flow
  64. * control is acted.
  65. *
  66. * Required if write method is provided else not needed.
  67. *
  68. * Note: Do not call this function directly, call tty_write_room
  69. *
  70. * int (*ioctl)(struct tty_struct *tty, struct file * file,
  71. * unsigned int cmd, unsigned long arg);
  72. *
  73. * This routine allows the tty driver to implement
  74. * device-specific ioctl's. If the ioctl number passed in cmd
  75. * is not recognized by the driver, it should return ENOIOCTLCMD.
  76. *
  77. * Optional
  78. *
  79. * long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
  80. * unsigned int cmd, unsigned long arg);
  81. *
  82. * implement ioctl processing for 32 bit process on 64 bit system
  83. *
  84. * Optional
  85. *
  86. * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
  87. *
  88. * This routine allows the tty driver to be notified when
  89. * device's termios settings have changed.
  90. *
  91. * Optional: Called under the termios lock
  92. *
  93. *
  94. * void (*set_ldisc)(struct tty_struct *tty);
  95. *
  96. * This routine allows the tty driver to be notified when the
  97. * device's termios settings have changed.
  98. *
  99. * Optional: Called under BKL (currently)
  100. *
  101. * void (*throttle)(struct tty_struct * tty);
  102. *
  103. * This routine notifies the tty driver that input buffers for
  104. * the line discipline are close to full, and it should somehow
  105. * signal that no more characters should be sent to the tty.
  106. *
  107. * Optional: Always invoke via tty_throttle();
  108. *
  109. * void (*unthrottle)(struct tty_struct * tty);
  110. *
  111. * This routine notifies the tty drivers that it should signals
  112. * that characters can now be sent to the tty without fear of
  113. * overrunning the input buffers of the line disciplines.
  114. *
  115. * Optional: Always invoke via tty_unthrottle();
  116. *
  117. * void (*stop)(struct tty_struct *tty);
  118. *
  119. * This routine notifies the tty driver that it should stop
  120. * outputting characters to the tty device.
  121. *
  122. * Optional:
  123. *
  124. * Note: Call stop_tty not this method.
  125. *
  126. * void (*start)(struct tty_struct *tty);
  127. *
  128. * This routine notifies the tty driver that it resume sending
  129. * characters to the tty device.
  130. *
  131. * Optional:
  132. *
  133. * Note: Call start_tty not this method.
  134. *
  135. * void (*hangup)(struct tty_struct *tty);
  136. *
  137. * This routine notifies the tty driver that it should hangup the
  138. * tty device.
  139. *
  140. * Optional:
  141. *
  142. * int (*break_ctl)(struct tty_stuct *tty, int state);
  143. *
  144. * This optional routine requests the tty driver to turn on or
  145. * off BREAK status on the RS-232 port. If state is -1,
  146. * then the BREAK status should be turned on; if state is 0, then
  147. * BREAK should be turned off.
  148. *
  149. * If this routine is implemented, the high-level tty driver will
  150. * handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
  151. * TIOCCBRK.
  152. *
  153. * If the driver sets TTY_DRIVER_HARDWARE_BREAK then the interface
  154. * will also be called with actual times and the hardware is expected
  155. * to do the delay work itself. 0 and -1 are still used for on/off.
  156. *
  157. * Optional: Required for TCSBRK/BRKP/etc handling.
  158. *
  159. * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
  160. *
  161. * This routine waits until the device has written out all of the
  162. * characters in its transmitter FIFO.
  163. *
  164. * Optional: If not provided the device is assumed to have no FIFO
  165. *
  166. * Note: Usually correct to call tty_wait_until_sent
  167. *
  168. * void (*send_xchar)(struct tty_struct *tty, char ch);
  169. *
  170. * This routine is used to send a high-priority XON/XOFF
  171. * character to the device.
  172. *
  173. * Optional: If not provided then the write method is called under
  174. * the atomic write lock to keep it serialized with the ldisc.
  175. *
  176. * int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty,
  177. * unsigned int rows, unsigned int cols);
  178. *
  179. * Called when a termios request is issued which changes the
  180. * requested terminal geometry.
  181. *
  182. * Optional: the default action is to update the termios structure
  183. * without error. This is usually the correct behaviour. Drivers should
  184. * not force errors here if they are not resizable objects (eg a serial
  185. * line). See tty_do_resize() if you need to wrap the standard method
  186. * in your own logic - the usual case.
  187. *
  188. * void (*set_termiox)(struct tty_struct *tty, struct termiox *new);
  189. *
  190. * Called when the device receives a termiox based ioctl. Passes down
  191. * the requested data from user space. This method will not be invoked
  192. * unless the tty also has a valid tty->termiox pointer.
  193. *
  194. * Optional: Called under the termios lock
  195. */
  196. #include <linux/fs.h>
  197. #include <linux/list.h>
  198. #include <linux/cdev.h>
  199. struct tty_struct;
  200. struct tty_driver;
  201. struct tty_operations {
  202. int (*open)(struct tty_struct * tty, struct file * filp);
  203. void (*close)(struct tty_struct * tty, struct file * filp);
  204. void (*shutdown)(struct tty_struct *tty);
  205. int (*write)(struct tty_struct * tty,
  206. const unsigned char *buf, int count);
  207. int (*put_char)(struct tty_struct *tty, unsigned char ch);
  208. void (*flush_chars)(struct tty_struct *tty);
  209. int (*write_room)(struct tty_struct *tty);
  210. int (*chars_in_buffer)(struct tty_struct *tty);
  211. int (*ioctl)(struct tty_struct *tty, struct file * file,
  212. unsigned int cmd, unsigned long arg);
  213. long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
  214. unsigned int cmd, unsigned long arg);
  215. void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
  216. void (*throttle)(struct tty_struct * tty);
  217. void (*unthrottle)(struct tty_struct * tty);
  218. void (*stop)(struct tty_struct *tty);
  219. void (*start)(struct tty_struct *tty);
  220. void (*hangup)(struct tty_struct *tty);
  221. int (*break_ctl)(struct tty_struct *tty, int state);
  222. void (*flush_buffer)(struct tty_struct *tty);
  223. void (*set_ldisc)(struct tty_struct *tty);
  224. void (*wait_until_sent)(struct tty_struct *tty, int timeout);
  225. void (*send_xchar)(struct tty_struct *tty, char ch);
  226. int (*read_proc)(char *page, char **start, off_t off,
  227. int count, int *eof, void *data);
  228. int (*tiocmget)(struct tty_struct *tty, struct file *file);
  229. int (*tiocmset)(struct tty_struct *tty, struct file *file,
  230. unsigned int set, unsigned int clear);
  231. int (*resize)(struct tty_struct *tty, struct tty_struct *real_tty,
  232. struct winsize *ws);
  233. int (*set_termiox)(struct tty_struct *tty, struct termiox *tnew);
  234. #ifdef CONFIG_CONSOLE_POLL
  235. int (*poll_init)(struct tty_driver *driver, int line, char *options);
  236. int (*poll_get_char)(struct tty_driver *driver, int line);
  237. void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
  238. #endif
  239. };
  240. struct tty_driver {
  241. int magic; /* magic number for this structure */
  242. struct cdev cdev;
  243. struct module *owner;
  244. const char *driver_name;
  245. const char *name;
  246. int name_base; /* offset of printed name */
  247. int major; /* major device number */
  248. int minor_start; /* start of minor device number */
  249. int minor_num; /* number of *possible* devices */
  250. int num; /* number of devices allocated */
  251. short type; /* type of tty driver */
  252. short subtype; /* subtype of tty driver */
  253. struct ktermios init_termios; /* Initial termios */
  254. int flags; /* tty driver flags */
  255. int refcount; /* for loadable tty drivers */
  256. struct proc_dir_entry *proc_entry; /* /proc fs entry */
  257. struct tty_driver *other; /* only used for the PTY driver */
  258. /*
  259. * Pointer to the tty data structures
  260. */
  261. struct tty_struct **ttys;
  262. struct ktermios **termios;
  263. struct ktermios **termios_locked;
  264. void *driver_state;
  265. /*
  266. * Driver methods
  267. */
  268. const struct tty_operations *ops;
  269. struct list_head tty_drivers;
  270. };
  271. extern struct list_head tty_drivers;
  272. struct tty_driver *alloc_tty_driver(int lines);
  273. void put_tty_driver(struct tty_driver *driver);
  274. void tty_set_operations(struct tty_driver *driver,
  275. const struct tty_operations *op);
  276. extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
  277. /* tty driver magic number */
  278. #define TTY_DRIVER_MAGIC 0x5402
  279. /*
  280. * tty driver flags
  281. *
  282. * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the
  283. * termios setting when the last process has closed the device.
  284. * Used for PTY's, in particular.
  285. *
  286. * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will
  287. * guarantee never not to set any special character handling
  288. * flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR ||
  289. * !INPCK)). That is, if there is no reason for the driver to
  290. * send notifications of parity and break characters up to the
  291. * line driver, it won't do so. This allows the line driver to
  292. * optimize for this case if this flag is set. (Note that there
  293. * is also a promise, if the above case is true, not to signal
  294. * overruns, either.)
  295. *
  296. * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need
  297. * to be registered with a call to tty_register_driver() when the
  298. * device is found in the system and unregistered with a call to
  299. * tty_unregister_device() so the devices will be show up
  300. * properly in sysfs. If not set, driver->num entries will be
  301. * created by the tty core in sysfs when tty_register_driver() is
  302. * called. This is to be used by drivers that have tty devices
  303. * that can appear and disappear while the main tty driver is
  304. * registered with the tty core.
  305. *
  306. * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
  307. * use dynamic memory keyed through the devpts filesystem. This
  308. * is only applicable to the pty driver.
  309. *
  310. * TTY_DRIVER_HARDWARE_BREAK -- hardware handles break signals. Pass
  311. * the requested timeout to the caller instead of using a simple
  312. * on/off interface.
  313. *
  314. */
  315. #define TTY_DRIVER_INSTALLED 0x0001
  316. #define TTY_DRIVER_RESET_TERMIOS 0x0002
  317. #define TTY_DRIVER_REAL_RAW 0x0004
  318. #define TTY_DRIVER_DYNAMIC_DEV 0x0008
  319. #define TTY_DRIVER_DEVPTS_MEM 0x0010
  320. #define TTY_DRIVER_HARDWARE_BREAK 0x0020
  321. /* tty driver types */
  322. #define TTY_DRIVER_TYPE_SYSTEM 0x0001
  323. #define TTY_DRIVER_TYPE_CONSOLE 0x0002
  324. #define TTY_DRIVER_TYPE_SERIAL 0x0003
  325. #define TTY_DRIVER_TYPE_PTY 0x0004
  326. #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */
  327. #define TTY_DRIVER_TYPE_SYSCONS 0x0006
  328. /* system subtypes (magic, used by tty_io.c) */
  329. #define SYSTEM_TYPE_TTY 0x0001
  330. #define SYSTEM_TYPE_CONSOLE 0x0002
  331. #define SYSTEM_TYPE_SYSCONS 0x0003
  332. #define SYSTEM_TYPE_SYSPTMX 0x0004
  333. /* pty subtypes (magic, used by tty_io.c) */
  334. #define PTY_TYPE_MASTER 0x0001
  335. #define PTY_TYPE_SLAVE 0x0002
  336. /* serial subtype definitions */
  337. #define SERIAL_TYPE_NORMAL 1
  338. #endif /* #ifdef _LINUX_TTY_DRIVER_H */