tty.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Mach Operating System
  3. * Copyright (c) 1993-1990 Carnegie Mellon University
  4. * All Rights Reserved.
  5. *
  6. * Permission to use, copy, modify and distribute this software and its
  7. * documentation is hereby granted, provided that both the copyright
  8. * notice and this permission notice appear in all copies of the
  9. * software, derivative works or modified versions, and any portions
  10. * thereof, and that both notices appear in supporting documentation.
  11. *
  12. * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13. * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14. * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15. *
  16. * Carnegie Mellon requests users of this software to return to
  17. *
  18. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  19. * School of Computer Science
  20. * Carnegie Mellon University
  21. * Pittsburgh PA 15213-3890
  22. *
  23. * any improvements or extensions that they make and grant Carnegie Mellon
  24. * the rights to redistribute these changes.
  25. */
  26. /*
  27. * Author: David B. Golub, Carnegie Mellon University
  28. * Date: 7/90
  29. *
  30. * Compatibility TTY structure for existing TTY device drivers.
  31. */
  32. #ifndef _DEVICE_TTY_H_
  33. #define _DEVICE_TTY_H_
  34. #include <kern/lock.h>
  35. #include <kern/queue.h>
  36. #include <mach/port.h>
  37. #include <device/device_types.h>
  38. #include <device/tty_status.h>
  39. #include <device/cirbuf.h>
  40. #include <device/io_req.h>
  41. struct tty {
  42. decl_simple_lock_data(,t_lock)
  43. struct cirbuf t_inq; /* input buffer */
  44. struct cirbuf t_outq; /* output buffer */
  45. char * t_addr; /* device pointer */
  46. int t_dev; /* device number */
  47. void (*t_start)(struct tty *);
  48. /* routine to start output */
  49. #define t_oproc t_start
  50. void (*t_stop)(struct tty *, int);
  51. /* routine to stop output */
  52. int (*t_mctl)(struct tty *, int, int);
  53. /* (optional) routine to control
  54. modem signals */
  55. unsigned char t_ispeed; /* input speed */
  56. unsigned char t_ospeed; /* output speed */
  57. char t_breakc; /* character to deliver when 'break'
  58. condition received */
  59. int t_flags; /* mode flags */
  60. int t_state; /* current state */
  61. int t_line; /* fake line discipline number,
  62. for old drivers - always 0 */
  63. queue_head_t t_delayed_read; /* pending read requests */
  64. queue_head_t t_delayed_write;/* pending write requests */
  65. queue_head_t t_delayed_open; /* pending open requests */
  66. /*
  67. * Items beyond this point should be removed to device-specific
  68. * extension structures.
  69. */
  70. io_return_t (*t_getstat)(dev_t, int, int *, natural_t *); /* routine to get status */
  71. io_return_t (*t_setstat)(dev_t, int, int *, natural_t); /* routine to set status */
  72. dev_ops_t t_tops; /* another device to possibly
  73. push through */
  74. };
  75. typedef struct tty *tty_t;
  76. /*
  77. * Common TTY service routines
  78. */
  79. extern io_return_t char_open(
  80. int dev,
  81. struct tty * tp,
  82. dev_mode_t mode,
  83. io_req_t ior);
  84. extern io_return_t char_read(
  85. struct tty * tp,
  86. io_req_t ior);
  87. extern io_return_t char_write(
  88. struct tty * tp,
  89. io_req_t ior);
  90. extern void ttyinput(
  91. unsigned int c,
  92. struct tty * tp);
  93. extern void ttyinput_many(
  94. struct tty * tp,
  95. char * chars,
  96. int count);
  97. extern boolean_t ttymodem(
  98. struct tty * tp,
  99. boolean_t carrier_up);
  100. extern void tty_cts(
  101. struct tty * tp,
  102. boolean_t cts_up);
  103. extern void tty_queue_completion(
  104. queue_t queue);
  105. #define tt_open_wakeup(tp) \
  106. (tty_queue_completion(&(tp)->t_delayed_open))
  107. #define tt_write_wakeup(tp) \
  108. (tty_queue_completion(&(tp)->t_delayed_write))
  109. extern void ttychars(
  110. struct tty * tp);
  111. #define TTMINBUF 90
  112. short tthiwat[NSPEEDS], ttlowat[NSPEEDS];
  113. #define TTHIWAT(tp) tthiwat[(tp)->t_ospeed]
  114. #define TTLOWAT(tp) ttlowat[(tp)->t_ospeed]
  115. extern io_return_t tty_get_status(
  116. struct tty * tp,
  117. dev_flavor_t flavor,
  118. int * data,
  119. natural_t * count);
  120. extern io_return_t tty_set_status(
  121. struct tty * tp,
  122. dev_flavor_t flavor,
  123. int * data,
  124. natural_t count);
  125. extern void tty_flush(
  126. struct tty * tp,
  127. int rw);
  128. extern void ttrstrt(
  129. struct tty * tp);
  130. extern void ttstart(
  131. struct tty * tp);
  132. extern void ttyclose(
  133. struct tty * tp);
  134. extern boolean_t tty_portdeath(
  135. struct tty * tp,
  136. ipc_port_t port);
  137. /* internal state bits */
  138. #define TS_INIT 0x00000001 /* tty structure initialized */
  139. #define TS_TIMEOUT 0x00000002 /* delay timeout in progress */
  140. #define TS_WOPEN 0x00000004 /* waiting for open to complete */
  141. #define TS_ISOPEN 0x00000008 /* device is open */
  142. #define TS_FLUSH 0x00000010 /* outq has been flushed during DMA */
  143. #define TS_CARR_ON 0x00000020 /* software copy of carrier-present */
  144. #define TS_BUSY 0x00000040 /* output in progress */
  145. #define TS_ASLEEP 0x00000080 /* wakeup when output done */
  146. #define TS_TTSTOP 0x00000100 /* output stopped by ctl-s */
  147. #define TS_HUPCLS 0x00000200 /* hang up upon last close */
  148. #define TS_TBLOCK 0x00000400 /* tandem queue blocked */
  149. #define TS_NBIO 0x00001000 /* tty in non-blocking mode */
  150. #define TS_ONDELAY 0x00002000 /* device is open; software copy of
  151. * carrier is not present */
  152. #define TS_MIN 0x00004000 /* buffer input chars, if possible */
  153. #define TS_MIN_TO 0x00008000 /* timeout for the above is active */
  154. #define TS_OUT 0x00010000 /* tty in use for dialout only */
  155. #define TS_RTS_DOWN 0x00020000 /* modem pls stop */
  156. #define TS_TRANSLATE 0x00100000 /* translation device enabled */
  157. #define TS_KDB 0x00200000 /* should enter kdb on ALT */
  158. #define TS_MIN_TO_RCV 0x00400000 /* character received during
  159. receive timeout interval */
  160. /* flags - old names defined in terms of new ones */
  161. #define TANDEM TF_TANDEM
  162. #define ODDP TF_ODDP
  163. #define EVENP TF_EVENP
  164. #define ANYP (ODDP|EVENP)
  165. #define MDMBUF TF_MDMBUF
  166. #define LITOUT TF_LITOUT
  167. #define NOHANG TF_NOHANG
  168. #define ECHO TF_ECHO
  169. #define CRMOD TF_CRMOD
  170. #define XTABS TF_XTABS
  171. /* these are here only to let old code compile - they are never set */
  172. #define RAW LITOUT
  173. #define PASS8 LITOUT
  174. /*
  175. * Hardware bits.
  176. * SHOULD NOT BE HERE.
  177. */
  178. #define DONE 0200
  179. #define IENABLE 0100
  180. /*
  181. * Modem control commands.
  182. */
  183. #define DMSET 0
  184. #define DMBIS 1
  185. #define DMBIC 2
  186. #define DMGET 3
  187. /*
  188. * Fake 'line discipline' switch, for the benefit of old code
  189. * that wants to call through it.
  190. */
  191. struct ldisc_switch {
  192. int (*l_read) (struct tty *, io_req_t); /* read */
  193. int (*l_write)(struct tty *, io_req_t); /* write */
  194. void (*l_rint) (unsigned int, struct tty *); /* character input */
  195. boolean_t (*l_modem)(struct tty *, boolean_t); /* modem change */
  196. void (*l_start)(struct tty *); /* start output */
  197. };
  198. extern struct ldisc_switch linesw[];
  199. #endif /* _DEVICE_TTY_H_ */