tty_driver.h 13 KB

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