tty_driver.h 11 KB

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