tty_driver.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. * int (*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. * If the driver sets TTY_DRIVER_HARDWARE_BREAK then the interface
  149. * will also be called with actual times and the hardware is expected
  150. * to do the delay work itself. 0 and -1 are still used for on/off.
  151. *
  152. * Optional: Required for TCSBRK/BRKP/etc handling.
  153. *
  154. * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
  155. *
  156. * This routine waits until the device has written out all of the
  157. * characters in its transmitter FIFO.
  158. *
  159. * Optional: If not provided the device is assumed to have no FIFO
  160. *
  161. * Note: Usually correct to call tty_wait_until_sent
  162. *
  163. * void (*send_xchar)(struct tty_struct *tty, char ch);
  164. *
  165. * This routine is used to send a high-priority XON/XOFF
  166. * character to the device.
  167. *
  168. * Optional: If not provided then the write method is called under
  169. * the atomic write lock to keep it serialized with the ldisc.
  170. */
  171. #include <linux/fs.h>
  172. #include <linux/list.h>
  173. #include <linux/cdev.h>
  174. struct tty_struct;
  175. struct tty_driver;
  176. struct tty_operations {
  177. int (*open)(struct tty_struct * tty, struct file * filp);
  178. void (*close)(struct tty_struct * tty, struct file * filp);
  179. int (*write)(struct tty_struct * tty,
  180. const unsigned char *buf, int count);
  181. int (*put_char)(struct tty_struct *tty, unsigned char ch);
  182. void (*flush_chars)(struct tty_struct *tty);
  183. int (*write_room)(struct tty_struct *tty);
  184. int (*chars_in_buffer)(struct tty_struct *tty);
  185. int (*ioctl)(struct tty_struct *tty, struct file * file,
  186. unsigned int cmd, unsigned long arg);
  187. long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
  188. unsigned int cmd, unsigned long arg);
  189. void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
  190. void (*throttle)(struct tty_struct * tty);
  191. void (*unthrottle)(struct tty_struct * tty);
  192. void (*stop)(struct tty_struct *tty);
  193. void (*start)(struct tty_struct *tty);
  194. void (*hangup)(struct tty_struct *tty);
  195. int (*break_ctl)(struct tty_struct *tty, int state);
  196. void (*flush_buffer)(struct tty_struct *tty);
  197. void (*set_ldisc)(struct tty_struct *tty);
  198. void (*wait_until_sent)(struct tty_struct *tty, int timeout);
  199. void (*send_xchar)(struct tty_struct *tty, char ch);
  200. int (*read_proc)(char *page, char **start, off_t off,
  201. int count, int *eof, void *data);
  202. int (*tiocmget)(struct tty_struct *tty, struct file *file);
  203. int (*tiocmset)(struct tty_struct *tty, struct file *file,
  204. unsigned int set, unsigned int clear);
  205. #ifdef CONFIG_CONSOLE_POLL
  206. int (*poll_init)(struct tty_driver *driver, int line, char *options);
  207. int (*poll_get_char)(struct tty_driver *driver, int line);
  208. void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
  209. #endif
  210. };
  211. struct tty_driver {
  212. int magic; /* magic number for this structure */
  213. struct cdev cdev;
  214. struct module *owner;
  215. const char *driver_name;
  216. const char *name;
  217. int name_base; /* offset of printed name */
  218. int major; /* major device number */
  219. int minor_start; /* start of minor device number */
  220. int minor_num; /* number of *possible* devices */
  221. int num; /* number of devices allocated */
  222. short type; /* type of tty driver */
  223. short subtype; /* subtype of tty driver */
  224. struct ktermios init_termios; /* Initial termios */
  225. int flags; /* tty driver flags */
  226. int refcount; /* for loadable tty drivers */
  227. struct proc_dir_entry *proc_entry; /* /proc fs entry */
  228. struct tty_driver *other; /* only used for the PTY driver */
  229. /*
  230. * Pointer to the tty data structures
  231. */
  232. struct tty_struct **ttys;
  233. struct ktermios **termios;
  234. struct ktermios **termios_locked;
  235. void *driver_state;
  236. /*
  237. * Driver methods
  238. */
  239. const struct tty_operations *ops;
  240. struct list_head tty_drivers;
  241. };
  242. extern struct list_head tty_drivers;
  243. struct tty_driver *alloc_tty_driver(int lines);
  244. void put_tty_driver(struct tty_driver *driver);
  245. void tty_set_operations(struct tty_driver *driver,
  246. const struct tty_operations *op);
  247. extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
  248. /* tty driver magic number */
  249. #define TTY_DRIVER_MAGIC 0x5402
  250. /*
  251. * tty driver flags
  252. *
  253. * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the
  254. * termios setting when the last process has closed the device.
  255. * Used for PTY's, in particular.
  256. *
  257. * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will
  258. * guarantee never not to set any special character handling
  259. * flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR ||
  260. * !INPCK)). That is, if there is no reason for the driver to
  261. * send notifications of parity and break characters up to the
  262. * line driver, it won't do so. This allows the line driver to
  263. * optimize for this case if this flag is set. (Note that there
  264. * is also a promise, if the above case is true, not to signal
  265. * overruns, either.)
  266. *
  267. * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need
  268. * to be registered with a call to tty_register_driver() when the
  269. * device is found in the system and unregistered with a call to
  270. * tty_unregister_device() so the devices will be show up
  271. * properly in sysfs. If not set, driver->num entries will be
  272. * created by the tty core in sysfs when tty_register_driver() is
  273. * called. This is to be used by drivers that have tty devices
  274. * that can appear and disappear while the main tty driver is
  275. * registered with the tty core.
  276. *
  277. * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
  278. * use dynamic memory keyed through the devpts filesystem. This
  279. * is only applicable to the pty driver.
  280. *
  281. * TTY_DRIVER_HARDWARE_BREAK -- hardware handles break signals. Pass
  282. * the requested timeout to the caller instead of using a simple
  283. * on/off interface.
  284. *
  285. */
  286. #define TTY_DRIVER_INSTALLED 0x0001
  287. #define TTY_DRIVER_RESET_TERMIOS 0x0002
  288. #define TTY_DRIVER_REAL_RAW 0x0004
  289. #define TTY_DRIVER_DYNAMIC_DEV 0x0008
  290. #define TTY_DRIVER_DEVPTS_MEM 0x0010
  291. #define TTY_DRIVER_HARDWARE_BREAK 0x0020
  292. /* tty driver types */
  293. #define TTY_DRIVER_TYPE_SYSTEM 0x0001
  294. #define TTY_DRIVER_TYPE_CONSOLE 0x0002
  295. #define TTY_DRIVER_TYPE_SERIAL 0x0003
  296. #define TTY_DRIVER_TYPE_PTY 0x0004
  297. #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */
  298. #define TTY_DRIVER_TYPE_SYSCONS 0x0006
  299. /* system subtypes (magic, used by tty_io.c) */
  300. #define SYSTEM_TYPE_TTY 0x0001
  301. #define SYSTEM_TYPE_CONSOLE 0x0002
  302. #define SYSTEM_TYPE_SYSCONS 0x0003
  303. #define SYSTEM_TYPE_SYSPTMX 0x0004
  304. /* pty subtypes (magic, used by tty_io.c) */
  305. #define PTY_TYPE_MASTER 0x0001
  306. #define PTY_TYPE_SLAVE 0x0002
  307. /* serial subtype definitions */
  308. #define SERIAL_TYPE_NORMAL 1
  309. #endif /* #ifdef _LINUX_TTY_DRIVER_H */