tty_driver.h
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:8k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  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, int from_user,
  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 termios * 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. struct tty_driver {
  118. int magic; /* magic number for this structure */
  119. const char *driver_name;
  120. const char *name;
  121. int name_base; /* offset of printed name */
  122. short major; /* major device number */
  123. short minor_start; /* start of minor device number*/
  124. short num; /* number of devices */
  125. short type; /* type of tty driver */
  126. short subtype; /* subtype of tty driver */
  127. struct termios init_termios; /* Initial termios */
  128. int flags; /* tty driver flags */
  129. int *refcount; /* for loadable tty drivers */
  130. struct proc_dir_entry *proc_entry; /* /proc fs entry */
  131. struct tty_driver *other; /* only used for the PTY driver */
  132. /*
  133.  * Pointer to the tty data structures
  134.  */
  135. struct tty_struct **table;
  136. struct termios **termios;
  137. struct termios **termios_locked;
  138. void *driver_state; /* only used for the PTY driver */
  139. /*
  140.  * Interface routines from the upper tty layer to the tty
  141.  * driver.
  142.  */
  143. int  (*open)(struct tty_struct * tty, struct file * filp);
  144. void (*close)(struct tty_struct * tty, struct file * filp);
  145. int  (*write)(struct tty_struct * tty, int from_user,
  146.       const unsigned char *buf, int count);
  147. void (*put_char)(struct tty_struct *tty, unsigned char ch);
  148. void (*flush_chars)(struct tty_struct *tty);
  149. int  (*write_room)(struct tty_struct *tty);
  150. int  (*chars_in_buffer)(struct tty_struct *tty);
  151. int  (*ioctl)(struct tty_struct *tty, struct file * file,
  152.     unsigned int cmd, unsigned long arg);
  153. void (*set_termios)(struct tty_struct *tty, struct termios * old);
  154. void (*throttle)(struct tty_struct * tty);
  155. void (*unthrottle)(struct tty_struct * tty);
  156. void (*stop)(struct tty_struct *tty);
  157. void (*start)(struct tty_struct *tty);
  158. void (*hangup)(struct tty_struct *tty);
  159. void (*break_ctl)(struct tty_struct *tty, int state);
  160. void (*flush_buffer)(struct tty_struct *tty);
  161. void (*set_ldisc)(struct tty_struct *tty);
  162. void (*wait_until_sent)(struct tty_struct *tty, int timeout);
  163. void (*send_xchar)(struct tty_struct *tty, char ch);
  164. int (*read_proc)(char *page, char **start, off_t off,
  165.   int count, int *eof, void *data);
  166. int (*write_proc)(struct file *file, const char *buffer,
  167.   unsigned long count, void *data);
  168. /*
  169.  * linked list pointers
  170.  */
  171. struct tty_driver *next;
  172. struct tty_driver *prev;
  173. };
  174. /* tty driver magic number */
  175. #define TTY_DRIVER_MAGIC 0x5402
  176. /*
  177.  * tty driver flags
  178.  * 
  179.  * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the
  180.  *  termios setting when the last process has closed the device.
  181.  *  Used for PTY's, in particular.
  182.  * 
  183.  * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will
  184.  *  guarantee never not to set any special character handling
  185.  *  flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR ||
  186.  *  !INPCK)).  That is, if there is no reason for the driver to
  187.  *  send notifications of parity and break characters up to the
  188.  *  line driver, it won't do so.  This allows the line driver to
  189.  * optimize for this case if this flag is set.  (Note that there
  190.  *  is also a promise, if the above case is true, not to signal
  191.  *  overruns, either.)
  192.  *
  193.  * TTY_DRIVER_NO_DEVFS --- if set, do not create devfs entries. This
  194.  * is only used by tty_register_driver().
  195.  *
  196.  */
  197. #define TTY_DRIVER_INSTALLED 0x0001
  198. #define TTY_DRIVER_RESET_TERMIOS 0x0002
  199. #define TTY_DRIVER_REAL_RAW 0x0004
  200. #define TTY_DRIVER_NO_DEVFS 0x0008
  201. /* tty driver types */
  202. #define TTY_DRIVER_TYPE_SYSTEM 0x0001
  203. #define TTY_DRIVER_TYPE_CONSOLE 0x0002
  204. #define TTY_DRIVER_TYPE_SERIAL 0x0003
  205. #define TTY_DRIVER_TYPE_PTY 0x0004
  206. #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */
  207. #define TTY_DRIVER_TYPE_SYSCONS 0x0006
  208. /* system subtypes (magic, used by tty_io.c) */
  209. #define SYSTEM_TYPE_TTY 0x0001
  210. #define SYSTEM_TYPE_CONSOLE 0x0002
  211. #define SYSTEM_TYPE_SYSCONS 0x0003
  212. #define SYSTEM_TYPE_SYSPTMX 0x0004
  213. /* pty subtypes (magic, used by tty_io.c) */
  214. #define PTY_TYPE_MASTER 0x0001
  215. #define PTY_TYPE_SLAVE 0x0002
  216. /* serial subtype definitions */
  217. #define SERIAL_TYPE_NORMAL 1
  218. #define SERIAL_TYPE_CALLOUT 2
  219. #endif /* #ifdef _LINUX_TTY_DRIVER_H */