tty.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. #ifndef _LINUX_TTY_H
  2. #define _LINUX_TTY_H
  3. /*
  4. * 'tty.h' defines some structures used by tty_io.c and some defines.
  5. */
  6. #ifdef __KERNEL__
  7. #include <linux/fs.h>
  8. #include <linux/major.h>
  9. #include <linux/termios.h>
  10. #include <linux/workqueue.h>
  11. #include <linux/tty_driver.h>
  12. #include <linux/tty_ldisc.h>
  13. #include <linux/mutex.h>
  14. #include <asm/system.h>
  15. /*
  16. * (Note: the *_driver.minor_start values 1, 64, 128, 192 are
  17. * hardcoded at present.)
  18. */
  19. #define NR_PTYS CONFIG_LEGACY_PTY_COUNT /* Number of legacy ptys */
  20. #define NR_UNIX98_PTY_DEFAULT 4096 /* Default maximum for Unix98 ptys */
  21. #define NR_UNIX98_PTY_MAX (1 << MINORBITS) /* Absolute limit */
  22. #define NR_LDISCS 16
  23. /*
  24. * This character is the same as _POSIX_VDISABLE: it cannot be used as
  25. * a c_cc[] character, but indicates that a particular special character
  26. * isn't in use (eg VINTR has no character etc)
  27. */
  28. #define __DISABLED_CHAR '\0'
  29. /*
  30. * This is the flip buffer used for the tty driver. The buffer is
  31. * located in the tty structure, and is used as a high speed interface
  32. * between the tty driver and the tty line discipline.
  33. */
  34. #define TTY_FLIPBUF_SIZE 512
  35. struct tty_buffer {
  36. struct tty_buffer *next;
  37. char *char_buf_ptr;
  38. unsigned char *flag_buf_ptr;
  39. int used;
  40. int size;
  41. int commit;
  42. int read;
  43. /* Data points here */
  44. unsigned long data[0];
  45. };
  46. struct tty_bufhead {
  47. struct work_struct work;
  48. struct semaphore pty_sem;
  49. spinlock_t lock;
  50. struct tty_buffer *head; /* Queue head */
  51. struct tty_buffer *tail; /* Active buffer */
  52. struct tty_buffer *free; /* Free queue head */
  53. };
  54. /*
  55. * The pty uses char_buf and flag_buf as a contiguous buffer
  56. */
  57. #define PTY_BUF_SIZE 4*TTY_FLIPBUF_SIZE
  58. /*
  59. * When a break, frame error, or parity error happens, these codes are
  60. * stuffed into the flags buffer.
  61. */
  62. #define TTY_NORMAL 0
  63. #define TTY_BREAK 1
  64. #define TTY_FRAME 2
  65. #define TTY_PARITY 3
  66. #define TTY_OVERRUN 4
  67. #define INTR_CHAR(tty) ((tty)->termios->c_cc[VINTR])
  68. #define QUIT_CHAR(tty) ((tty)->termios->c_cc[VQUIT])
  69. #define ERASE_CHAR(tty) ((tty)->termios->c_cc[VERASE])
  70. #define KILL_CHAR(tty) ((tty)->termios->c_cc[VKILL])
  71. #define EOF_CHAR(tty) ((tty)->termios->c_cc[VEOF])
  72. #define TIME_CHAR(tty) ((tty)->termios->c_cc[VTIME])
  73. #define MIN_CHAR(tty) ((tty)->termios->c_cc[VMIN])
  74. #define SWTC_CHAR(tty) ((tty)->termios->c_cc[VSWTC])
  75. #define START_CHAR(tty) ((tty)->termios->c_cc[VSTART])
  76. #define STOP_CHAR(tty) ((tty)->termios->c_cc[VSTOP])
  77. #define SUSP_CHAR(tty) ((tty)->termios->c_cc[VSUSP])
  78. #define EOL_CHAR(tty) ((tty)->termios->c_cc[VEOL])
  79. #define REPRINT_CHAR(tty) ((tty)->termios->c_cc[VREPRINT])
  80. #define DISCARD_CHAR(tty) ((tty)->termios->c_cc[VDISCARD])
  81. #define WERASE_CHAR(tty) ((tty)->termios->c_cc[VWERASE])
  82. #define LNEXT_CHAR(tty) ((tty)->termios->c_cc[VLNEXT])
  83. #define EOL2_CHAR(tty) ((tty)->termios->c_cc[VEOL2])
  84. #define _I_FLAG(tty,f) ((tty)->termios->c_iflag & (f))
  85. #define _O_FLAG(tty,f) ((tty)->termios->c_oflag & (f))
  86. #define _C_FLAG(tty,f) ((tty)->termios->c_cflag & (f))
  87. #define _L_FLAG(tty,f) ((tty)->termios->c_lflag & (f))
  88. #define I_IGNBRK(tty) _I_FLAG((tty),IGNBRK)
  89. #define I_BRKINT(tty) _I_FLAG((tty),BRKINT)
  90. #define I_IGNPAR(tty) _I_FLAG((tty),IGNPAR)
  91. #define I_PARMRK(tty) _I_FLAG((tty),PARMRK)
  92. #define I_INPCK(tty) _I_FLAG((tty),INPCK)
  93. #define I_ISTRIP(tty) _I_FLAG((tty),ISTRIP)
  94. #define I_INLCR(tty) _I_FLAG((tty),INLCR)
  95. #define I_IGNCR(tty) _I_FLAG((tty),IGNCR)
  96. #define I_ICRNL(tty) _I_FLAG((tty),ICRNL)
  97. #define I_IUCLC(tty) _I_FLAG((tty),IUCLC)
  98. #define I_IXON(tty) _I_FLAG((tty),IXON)
  99. #define I_IXANY(tty) _I_FLAG((tty),IXANY)
  100. #define I_IXOFF(tty) _I_FLAG((tty),IXOFF)
  101. #define I_IMAXBEL(tty) _I_FLAG((tty),IMAXBEL)
  102. #define I_IUTF8(tty) _I_FLAG((tty),IUTF8)
  103. #define O_OPOST(tty) _O_FLAG((tty),OPOST)
  104. #define O_OLCUC(tty) _O_FLAG((tty),OLCUC)
  105. #define O_ONLCR(tty) _O_FLAG((tty),ONLCR)
  106. #define O_OCRNL(tty) _O_FLAG((tty),OCRNL)
  107. #define O_ONOCR(tty) _O_FLAG((tty),ONOCR)
  108. #define O_ONLRET(tty) _O_FLAG((tty),ONLRET)
  109. #define O_OFILL(tty) _O_FLAG((tty),OFILL)
  110. #define O_OFDEL(tty) _O_FLAG((tty),OFDEL)
  111. #define O_NLDLY(tty) _O_FLAG((tty),NLDLY)
  112. #define O_CRDLY(tty) _O_FLAG((tty),CRDLY)
  113. #define O_TABDLY(tty) _O_FLAG((tty),TABDLY)
  114. #define O_BSDLY(tty) _O_FLAG((tty),BSDLY)
  115. #define O_VTDLY(tty) _O_FLAG((tty),VTDLY)
  116. #define O_FFDLY(tty) _O_FLAG((tty),FFDLY)
  117. #define C_BAUD(tty) _C_FLAG((tty),CBAUD)
  118. #define C_CSIZE(tty) _C_FLAG((tty),CSIZE)
  119. #define C_CSTOPB(tty) _C_FLAG((tty),CSTOPB)
  120. #define C_CREAD(tty) _C_FLAG((tty),CREAD)
  121. #define C_PARENB(tty) _C_FLAG((tty),PARENB)
  122. #define C_PARODD(tty) _C_FLAG((tty),PARODD)
  123. #define C_HUPCL(tty) _C_FLAG((tty),HUPCL)
  124. #define C_CLOCAL(tty) _C_FLAG((tty),CLOCAL)
  125. #define C_CIBAUD(tty) _C_FLAG((tty),CIBAUD)
  126. #define C_CRTSCTS(tty) _C_FLAG((tty),CRTSCTS)
  127. #define L_ISIG(tty) _L_FLAG((tty),ISIG)
  128. #define L_ICANON(tty) _L_FLAG((tty),ICANON)
  129. #define L_XCASE(tty) _L_FLAG((tty),XCASE)
  130. #define L_ECHO(tty) _L_FLAG((tty),ECHO)
  131. #define L_ECHOE(tty) _L_FLAG((tty),ECHOE)
  132. #define L_ECHOK(tty) _L_FLAG((tty),ECHOK)
  133. #define L_ECHONL(tty) _L_FLAG((tty),ECHONL)
  134. #define L_NOFLSH(tty) _L_FLAG((tty),NOFLSH)
  135. #define L_TOSTOP(tty) _L_FLAG((tty),TOSTOP)
  136. #define L_ECHOCTL(tty) _L_FLAG((tty),ECHOCTL)
  137. #define L_ECHOPRT(tty) _L_FLAG((tty),ECHOPRT)
  138. #define L_ECHOKE(tty) _L_FLAG((tty),ECHOKE)
  139. #define L_FLUSHO(tty) _L_FLAG((tty),FLUSHO)
  140. #define L_PENDIN(tty) _L_FLAG((tty),PENDIN)
  141. #define L_IEXTEN(tty) _L_FLAG((tty),IEXTEN)
  142. struct device;
  143. /*
  144. * Where all of the state associated with a tty is kept while the tty
  145. * is open. Since the termios state should be kept even if the tty
  146. * has been closed --- for things like the baud rate, etc --- it is
  147. * not stored here, but rather a pointer to the real state is stored
  148. * here. Possible the winsize structure should have the same
  149. * treatment, but (1) the default 80x24 is usually right and (2) it's
  150. * most often used by a windowing system, which will set the correct
  151. * size each time the window is created or resized anyway.
  152. * - TYT, 9/14/92
  153. */
  154. struct tty_struct {
  155. int magic;
  156. struct tty_driver *driver;
  157. int index;
  158. struct tty_ldisc ldisc;
  159. struct semaphore termios_sem;
  160. struct termios *termios, *termios_locked;
  161. char name[64];
  162. int pgrp;
  163. int session;
  164. unsigned long flags;
  165. int count;
  166. struct winsize winsize;
  167. unsigned char stopped:1, hw_stopped:1, flow_stopped:1, packet:1;
  168. unsigned char low_latency:1, warned:1;
  169. unsigned char ctrl_status;
  170. unsigned int receive_room; /* Bytes free for queue */
  171. struct tty_struct *link;
  172. struct fasync_struct *fasync;
  173. struct tty_bufhead buf;
  174. int max_flip_cnt;
  175. int alt_speed; /* For magic substitution of 38400 bps */
  176. wait_queue_head_t write_wait;
  177. wait_queue_head_t read_wait;
  178. struct work_struct hangup_work;
  179. void *disc_data;
  180. void *driver_data;
  181. struct list_head tty_files;
  182. #define N_TTY_BUF_SIZE 4096
  183. /*
  184. * The following is data for the N_TTY line discipline. For
  185. * historical reasons, this is included in the tty structure.
  186. */
  187. unsigned int column;
  188. unsigned char lnext:1, erasing:1, raw:1, real_raw:1, icanon:1;
  189. unsigned char closing:1;
  190. unsigned short minimum_to_wake;
  191. unsigned long overrun_time;
  192. int num_overrun;
  193. unsigned long process_char_map[256/(8*sizeof(unsigned long))];
  194. char *read_buf;
  195. int read_head;
  196. int read_tail;
  197. int read_cnt;
  198. unsigned long read_flags[N_TTY_BUF_SIZE/(8*sizeof(unsigned long))];
  199. int canon_data;
  200. unsigned long canon_head;
  201. unsigned int canon_column;
  202. struct mutex atomic_read_lock;
  203. struct mutex atomic_write_lock;
  204. unsigned char *write_buf;
  205. int write_cnt;
  206. spinlock_t read_lock;
  207. /* If the tty has a pending do_SAK, queue it here - akpm */
  208. struct work_struct SAK_work;
  209. };
  210. /* tty magic number */
  211. #define TTY_MAGIC 0x5401
  212. /*
  213. * These bits are used in the flags field of the tty structure.
  214. *
  215. * So that interrupts won't be able to mess up the queues,
  216. * copy_to_cooked must be atomic with respect to itself, as must
  217. * tty->write. Thus, you must use the inline functions set_bit() and
  218. * clear_bit() to make things atomic.
  219. */
  220. #define TTY_THROTTLED 0 /* Call unthrottle() at threshold min */
  221. #define TTY_IO_ERROR 1 /* Canse an I/O error (may be no ldisc too) */
  222. #define TTY_OTHER_CLOSED 2 /* Other side (if any) has closed */
  223. #define TTY_EXCLUSIVE 3 /* Exclusive open mode */
  224. #define TTY_DEBUG 4 /* Debugging */
  225. #define TTY_DO_WRITE_WAKEUP 5 /* Call write_wakeup after queuing new */
  226. #define TTY_PUSH 6 /* n_tty private */
  227. #define TTY_CLOSING 7 /* ->close() in progress */
  228. #define TTY_LDISC 9 /* Line discipline attached */
  229. #define TTY_HW_COOK_OUT 14 /* Hardware can do output cooking */
  230. #define TTY_HW_COOK_IN 15 /* Hardware can do input cooking */
  231. #define TTY_PTY_LOCK 16 /* pty private */
  232. #define TTY_NO_WRITE_SPLIT 17 /* Preserve write boundaries to driver */
  233. #define TTY_HUPPED 18 /* Post driver->hangup() */
  234. #define TTY_WRITE_FLUSH(tty) tty_write_flush((tty))
  235. extern void tty_write_flush(struct tty_struct *);
  236. extern struct termios tty_std_termios;
  237. extern int kmsg_redirect;
  238. extern void console_init(void);
  239. extern int vcs_init(void);
  240. extern int tty_paranoia_check(struct tty_struct *tty, struct inode *inode,
  241. const char *routine);
  242. extern char *tty_name(struct tty_struct *tty, char *buf);
  243. extern void tty_wait_until_sent(struct tty_struct * tty, long timeout);
  244. extern int tty_check_change(struct tty_struct * tty);
  245. extern void stop_tty(struct tty_struct * tty);
  246. extern void start_tty(struct tty_struct * tty);
  247. extern int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc);
  248. extern int tty_unregister_ldisc(int disc);
  249. extern int tty_register_driver(struct tty_driver *driver);
  250. extern int tty_unregister_driver(struct tty_driver *driver);
  251. extern struct class_device *tty_register_device(struct tty_driver *driver,
  252. unsigned index,
  253. struct device *dev);
  254. extern void tty_unregister_device(struct tty_driver *driver, unsigned index);
  255. extern int tty_read_raw_data(struct tty_struct *tty, unsigned char *bufp,
  256. int buflen);
  257. extern void tty_write_message(struct tty_struct *tty, char *msg);
  258. extern int is_orphaned_pgrp(int pgrp);
  259. extern int is_ignored(int sig);
  260. extern int tty_signal(int sig, struct tty_struct *tty);
  261. extern void tty_hangup(struct tty_struct * tty);
  262. extern void tty_vhangup(struct tty_struct * tty);
  263. extern void tty_unhangup(struct file *filp);
  264. extern int tty_hung_up_p(struct file * filp);
  265. extern void do_SAK(struct tty_struct *tty);
  266. extern void disassociate_ctty(int priv);
  267. extern void tty_flip_buffer_push(struct tty_struct *tty);
  268. extern int tty_get_baud_rate(struct tty_struct *tty);
  269. extern int tty_termios_baud_rate(struct termios *termios);
  270. extern struct tty_ldisc *tty_ldisc_ref(struct tty_struct *);
  271. extern void tty_ldisc_deref(struct tty_ldisc *);
  272. extern struct tty_ldisc *tty_ldisc_ref_wait(struct tty_struct *);
  273. extern struct tty_ldisc *tty_ldisc_get(int);
  274. extern void tty_ldisc_put(int);
  275. extern void tty_wakeup(struct tty_struct *tty);
  276. extern void tty_ldisc_flush(struct tty_struct *tty);
  277. extern struct mutex tty_mutex;
  278. /* n_tty.c */
  279. extern struct tty_ldisc tty_ldisc_N_TTY;
  280. /* tty_ioctl.c */
  281. extern int n_tty_ioctl(struct tty_struct * tty, struct file * file,
  282. unsigned int cmd, unsigned long arg);
  283. /* serial.c */
  284. extern void serial_console_init(void);
  285. /* pcxx.c */
  286. extern int pcxe_open(struct tty_struct *tty, struct file *filp);
  287. /* printk.c */
  288. extern void console_print(const char *);
  289. /* vt.c */
  290. extern int vt_ioctl(struct tty_struct *tty, struct file * file,
  291. unsigned int cmd, unsigned long arg);
  292. static inline dev_t tty_devnum(struct tty_struct *tty)
  293. {
  294. return MKDEV(tty->driver->major, tty->driver->minor_start) + tty->index;
  295. }
  296. #endif /* __KERNEL__ */
  297. #endif