tty_driver.h 11 KB

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