linux/include/linux/tty_driver.h
<<
>>
Prefs
   1#ifndef _LINUX_TTY_DRIVER_H
   2#define _LINUX_TTY_DRIVER_H
   3
   4/*
   5 * This structure defines the interface between the low-level tty
   6 * driver and the tty routines.  The following routines can be
   7 * defined; unless noted otherwise, they are optional, and can be
   8 * filled in with a null pointer.
   9 *
  10 * int  (*open)(struct tty_struct * tty, struct file * filp);
  11 *
  12 *      This routine is called when a particular tty device is opened.
  13 *      This routine is mandatory; if this routine is not filled in,
  14 *      the attempted open will fail with ENODEV.
  15 *     
  16 * void (*close)(struct tty_struct * tty, struct file * filp);
  17 *
  18 *      This routine is called when a particular tty device is closed.
  19 *
  20 * int (*write)(struct tty_struct * tty,
  21 *               const unsigned char *buf, int count);
  22 *
  23 *      This routine is called by the kernel to write a series of
  24 *      characters to the tty device.  The characters may come from
  25 *      user space or kernel space.  This routine will return the
  26 *      number of characters actually accepted for writing.  This
  27 *      routine is mandatory.
  28 *
  29 * void (*put_char)(struct tty_struct *tty, unsigned char ch);
  30 *
  31 *      This routine is called by the kernel to write a single
  32 *      character to the tty device.  If the kernel uses this routine,
  33 *      it must call the flush_chars() routine (if defined) when it is
  34 *      done stuffing characters into the driver.  If there is no room
  35 *      in the queue, the character is ignored.
  36 *
  37 * void (*flush_chars)(struct tty_struct *tty);
  38 *
  39 *      This routine is called by the kernel after it has written a
  40 *      series of characters to the tty device using put_char().  
  41 * 
  42 * int  (*write_room)(struct tty_struct *tty);
  43 *
  44 *      This routine returns the numbers of characters the tty driver
  45 *      will accept for queuing to be written.  This number is subject
  46 *      to change as output buffers get emptied, or if the output flow
  47 *      control is acted.
  48 * 
  49 * int  (*ioctl)(struct tty_struct *tty, struct file * file,
  50 *          unsigned int cmd, unsigned long arg);
  51 *
  52 *      This routine allows the tty driver to implement
  53 *      device-specific ioctl's.  If the ioctl number passed in cmd
  54 *      is not recognized by the driver, it should return ENOIOCTLCMD.
  55 *
  56 * long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
  57 *                      unsigned int cmd, unsigned long arg);
  58 *
  59 *      implement ioctl processing for 32 bit process on 64 bit system
  60 * 
  61 * void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
  62 *
  63 *      This routine allows the tty driver to be notified when
  64 *      device's termios settings have changed.  Note that a
  65 *      well-designed tty driver should be prepared to accept the case
  66 *      where old == NULL, and try to do something rational.
  67 *
  68 * void (*set_ldisc)(struct tty_struct *tty);
  69 *
  70 *      This routine allows the tty driver to be notified when the
  71 *      device's termios settings have changed.
  72 * 
  73 * void (*throttle)(struct tty_struct * tty);
  74 *
  75 *      This routine notifies the tty driver that input buffers for
  76 *      the line discipline are close to full, and it should somehow
  77 *      signal that no more characters should be sent to the tty.
  78 * 
  79 * void (*unthrottle)(struct tty_struct * tty);
  80 *
  81 *      This routine notifies the tty drivers that it should signals
  82 *      that characters can now be sent to the tty without fear of
  83 *      overrunning the input buffers of the line disciplines.
  84 * 
  85 * void (*stop)(struct tty_struct *tty);
  86 *
  87 *      This routine notifies the tty driver that it should stop
  88 *      outputting characters to the tty device.  
  89 * 
  90 * void (*start)(struct tty_struct *tty);
  91 *
  92 *      This routine notifies the tty driver that it resume sending
  93 *      characters to the tty device.
  94 * 
  95 * void (*hangup)(struct tty_struct *tty);
  96 *
  97 *      This routine notifies the tty driver that it should hangup the
  98 *      tty device.
  99 *
 100 * void (*break_ctl)(struct tty_stuct *tty, int state);
 101 *
 102 *      This optional routine requests the tty driver to turn on or
 103 *      off BREAK status on the RS-232 port.  If state is -1,
 104 *      then the BREAK status should be turned on; if state is 0, then
 105 *      BREAK should be turned off.
 106 *
 107 *      If this routine is implemented, the high-level tty driver will
 108 *      handle the following ioctls: TCSBRK, TCSBRKP, TIOCSBRK,
 109 *      TIOCCBRK.  Otherwise, these ioctls will be passed down to the
 110 *      driver to handle.
 111 *
 112 * void (*wait_until_sent)(struct tty_struct *tty, int timeout);
 113 * 
 114 *      This routine waits until the device has written out all of the
 115 *      characters in its transmitter FIFO.
 116 *
 117 * void (*send_xchar)(struct tty_struct *tty, char ch);
 118 *
 119 *      This routine is used to send a high-priority XON/XOFF
 120 *      character to the device.
 121 */
 122
 123#include <linux/fs.h>
 124#include <linux/list.h>
 125#include <linux/cdev.h>
 126
 127struct tty_struct;
 128
 129struct tty_operations {
 130        int  (*open)(struct tty_struct * tty, struct file * filp);
 131        void (*close)(struct tty_struct * tty, struct file * filp);
 132        int  (*write)(struct tty_struct * tty,
 133                      const unsigned char *buf, int count);
 134        void (*put_char)(struct tty_struct *tty, unsigned char ch);
 135        void (*flush_chars)(struct tty_struct *tty);
 136        int  (*write_room)(struct tty_struct *tty);
 137        int  (*chars_in_buffer)(struct tty_struct *tty);
 138        int  (*ioctl)(struct tty_struct *tty, struct file * file,
 139                    unsigned int cmd, unsigned long arg);
 140        long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
 141                             unsigned int cmd, unsigned long arg);
 142        void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
 143        void (*throttle)(struct tty_struct * tty);
 144        void (*unthrottle)(struct tty_struct * tty);
 145        void (*stop)(struct tty_struct *tty);
 146        void (*start)(struct tty_struct *tty);
 147        void (*hangup)(struct tty_struct *tty);
 148        void (*break_ctl)(struct tty_struct *tty, int state);
 149        void (*flush_buffer)(struct tty_struct *tty);
 150        void (*set_ldisc)(struct tty_struct *tty);
 151        void (*wait_until_sent)(struct tty_struct *tty, int timeout);
 152        void (*send_xchar)(struct tty_struct *tty, char ch);
 153        int (*read_proc)(char *page, char **start, off_t off,
 154                          int count, int *eof, void *data);
 155        int (*write_proc)(struct file *file, const char __user *buffer,
 156                          unsigned long count, void *data);
 157        int (*tiocmget)(struct tty_struct *tty, struct file *file);
 158        int (*tiocmset)(struct tty_struct *tty, struct file *file,
 159                        unsigned int set, unsigned int clear);
 160};
 161
 162struct tty_driver {
 163        int     magic;          /* magic number for this structure */
 164        struct cdev cdev;
 165        struct module   *owner;
 166        const char      *driver_name;
 167        const char      *name;
 168        int     name_base;      /* offset of printed name */
 169        int     major;          /* major device number */
 170        int     minor_start;    /* start of minor device number */
 171        int     minor_num;      /* number of *possible* devices */
 172        int     num;            /* number of devices allocated */
 173        short   type;           /* type of tty driver */
 174        short   subtype;        /* subtype of tty driver */
 175        struct ktermios init_termios; /* Initial termios */
 176        int     flags;          /* tty driver flags */
 177        int     refcount;       /* for loadable tty drivers */
 178        struct proc_dir_entry *proc_entry; /* /proc fs entry */
 179        struct tty_driver *other; /* only used for the PTY driver */
 180
 181        /*
 182         * Pointer to the tty data structures
 183         */
 184        struct tty_struct **ttys;
 185        struct ktermios **termios;
 186        struct ktermios **termios_locked;
 187        void *driver_state;     /* only used for the PTY driver */
 188        
 189        /*
 190         * Interface routines from the upper tty layer to the tty
 191         * driver.      Will be replaced with struct tty_operations.
 192         */
 193        int  (*open)(struct tty_struct * tty, struct file * filp);
 194        void (*close)(struct tty_struct * tty, struct file * filp);
 195        int  (*write)(struct tty_struct * tty,
 196                      const unsigned char *buf, int count);
 197        void (*put_char)(struct tty_struct *tty, unsigned char ch);
 198        void (*flush_chars)(struct tty_struct *tty);
 199        int  (*write_room)(struct tty_struct *tty);
 200        int  (*chars_in_buffer)(struct tty_struct *tty);
 201        int  (*ioctl)(struct tty_struct *tty, struct file * file,
 202                    unsigned int cmd, unsigned long arg);
 203        long (*compat_ioctl)(struct tty_struct *tty, struct file * file,
 204                             unsigned int cmd, unsigned long arg);
 205        void (*set_termios)(struct tty_struct *tty, struct ktermios * old);
 206        void (*throttle)(struct tty_struct * tty);
 207        void (*unthrottle)(struct tty_struct * tty);
 208        void (*stop)(struct tty_struct *tty);
 209        void (*start)(struct tty_struct *tty);
 210        void (*hangup)(struct tty_struct *tty);
 211        void (*break_ctl)(struct tty_struct *tty, int state);
 212        void (*flush_buffer)(struct tty_struct *tty);
 213        void (*set_ldisc)(struct tty_struct *tty);
 214        void (*wait_until_sent)(struct tty_struct *tty, int timeout);
 215        void (*send_xchar)(struct tty_struct *tty, char ch);
 216        int (*read_proc)(char *page, char **start, off_t off,
 217                          int count, int *eof, void *data);
 218        int (*write_proc)(struct file *file, const char __user *buffer,
 219                          unsigned long count, void *data);
 220        int (*tiocmget)(struct tty_struct *tty, struct file *file);
 221        int (*tiocmset)(struct tty_struct *tty, struct file *file,
 222                        unsigned int set, unsigned int clear);
 223
 224        struct list_head tty_drivers;
 225};
 226
 227extern struct list_head tty_drivers;
 228
 229struct tty_driver *alloc_tty_driver(int lines);
 230void put_tty_driver(struct tty_driver *driver);
 231void tty_set_operations(struct tty_driver *driver,
 232                        const struct tty_operations *op);
 233
 234/* tty driver magic number */
 235#define TTY_DRIVER_MAGIC                0x5402
 236
 237/*
 238 * tty driver flags
 239 * 
 240 * TTY_DRIVER_RESET_TERMIOS --- requests the tty layer to reset the
 241 *      termios setting when the last process has closed the device.
 242 *      Used for PTY's, in particular.
 243 * 
 244 * TTY_DRIVER_REAL_RAW --- if set, indicates that the driver will
 245 *      guarantee never not to set any special character handling
 246 *      flags if ((IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR ||
 247 *      !INPCK)).  That is, if there is no reason for the driver to
 248 *      send notifications of parity and break characters up to the
 249 *      line driver, it won't do so.  This allows the line driver to
 250 *      optimize for this case if this flag is set.  (Note that there
 251 *      is also a promise, if the above case is true, not to signal
 252 *      overruns, either.)
 253 *
 254 * TTY_DRIVER_DYNAMIC_DEV --- if set, the individual tty devices need
 255 *      to be registered with a call to tty_register_driver() when the
 256 *      device is found in the system and unregistered with a call to
 257 *      tty_unregister_device() so the devices will be show up
 258 *      properly in sysfs.  If not set, driver->num entries will be
 259 *      created by the tty core in sysfs when tty_register_driver() is
 260 *      called.  This is to be used by drivers that have tty devices
 261 *      that can appear and disappear while the main tty driver is
 262 *      registered with the tty core.
 263 *
 264 * TTY_DRIVER_DEVPTS_MEM -- don't use the standard arrays, instead
 265 *      use dynamic memory keyed through the devpts filesystem.  This
 266 *      is only applicable to the pty driver.
 267 */
 268#define TTY_DRIVER_INSTALLED            0x0001
 269#define TTY_DRIVER_RESET_TERMIOS        0x0002
 270#define TTY_DRIVER_REAL_RAW             0x0004
 271#define TTY_DRIVER_DYNAMIC_DEV          0x0008
 272#define TTY_DRIVER_DEVPTS_MEM           0x0010
 273
 274/* tty driver types */
 275#define TTY_DRIVER_TYPE_SYSTEM          0x0001
 276#define TTY_DRIVER_TYPE_CONSOLE         0x0002
 277#define TTY_DRIVER_TYPE_SERIAL          0x0003
 278#define TTY_DRIVER_TYPE_PTY             0x0004
 279#define TTY_DRIVER_TYPE_SCC             0x0005  /* scc driver */
 280#define TTY_DRIVER_TYPE_SYSCONS         0x0006
 281
 282/* system subtypes (magic, used by tty_io.c) */
 283#define SYSTEM_TYPE_TTY                 0x0001
 284#define SYSTEM_TYPE_CONSOLE             0x0002
 285#define SYSTEM_TYPE_SYSCONS             0x0003
 286#define SYSTEM_TYPE_SYSPTMX             0x0004
 287
 288/* pty subtypes (magic, used by tty_io.c) */
 289#define PTY_TYPE_MASTER                 0x0001
 290#define PTY_TYPE_SLAVE                  0x0002
 291
 292/* serial subtype definitions */
 293#define SERIAL_TYPE_NORMAL      1
 294
 295#endif /* #ifdef _LINUX_TTY_DRIVER_H */
 296