tty_driver.h 12 KB

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