tty_driver.h 11 KB

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