Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

dz.h

Go to the documentation of this file.
00001 /*
00002  * dz.h: Serial port driver for DECStations equiped 
00003  *       with the DZ chipset.
00004  *
00005  * Copyright (C) 1998 Olivier A. D. Lebaillif 
00006  *             
00007  * Email: olivier.lebaillif@ifrsys.com
00008  *
00009  */
00010 #ifndef DZ_SERIAL_H
00011 #define DZ_SERIAL_H
00012 
00013 /*
00014  * Definitions for the Control and Status Received.
00015  */
00016 #define DZ_TRDY        0x8000                 /* Transmitter empty */
00017 #define DZ_TIE         0x4000                 /* Transmitter Interrupt Enable */
00018 #define DZ_RDONE       0x0080                 /* Receiver data ready */
00019 #define DZ_RIE         0x0040                 /* Receive Interrupt Enable */
00020 #define DZ_MSE         0x0020                 /* Master Scan Enable */
00021 #define DZ_CLR         0x0010                 /* Master reset */
00022 #define DZ_MAINT       0x0008                 /* Loop Back Mode */
00023 
00024 /*
00025  * Definitions for the Received buffer. 
00026  */
00027 #define DZ_RBUF_MASK   0x00FF                 /* Data Mask in the Receive Buffer */
00028 #define DZ_LINE_MASK   0x0300                 /* Line Mask in the Receive Buffer */
00029 #define DZ_DVAL        0x8000                 /* Valid Data indicator */
00030 #define DZ_OERR        0x4000                 /* Overrun error indicator */
00031 #define DZ_FERR        0x2000                 /* Frame error indicator */
00032 #define DZ_PERR        0x1000                 /* Parity error indicator */
00033 
00034 #define LINE(x) (x & DZ_LINE_MASK) >> 8       /* Get the line number from the input buffer */
00035 #define UCHAR(x) (unsigned char)(x & DZ_RBUF_MASK)
00036 
00037 /*
00038  * Definitions for the Transmit Register.
00039  */
00040 #define DZ_LINE_KEYBOARD 0x0001
00041 #define DZ_LINE_MOUSE    0x0002
00042 #define DZ_LINE_MODEM    0x0004
00043 #define DZ_LINE_PRINTER  0x0008
00044 
00045 #define DZ_MODEM_DTR     0x0400               /* DTR for the modem line (2) */
00046 
00047 /*
00048  * Definitions for the Modem Status Register.
00049  */
00050 #define DZ_MODEM_DSR     0x0200               /* DSR for the modem line (2) */
00051 
00052 /*
00053  * Definitions for the Transmit Data Register.
00054  */
00055 #define DZ_BRK0          0x0100               /* Break assertion for line 0 */
00056 #define DZ_BRK1          0x0200               /* Break assertion for line 1 */
00057 #define DZ_BRK2          0x0400               /* Break assertion for line 2 */
00058 #define DZ_BRK3          0x0800               /* Break assertion for line 3 */
00059 
00060 /*
00061  * Definitions for the Line Parameter Register.
00062  */
00063 #define DZ_KEYBOARD      0x0000               /* line 0 = keyboard */
00064 #define DZ_MOUSE         0x0001               /* line 1 = mouse */
00065 #define DZ_MODEM         0x0002               /* line 2 = modem */
00066 #define DZ_PRINTER       0x0003               /* line 3 = printer */
00067 
00068 #define DZ_CSIZE         0x0018               /* Number of bits per byte (mask) */
00069 #define DZ_CS5           0x0000               /* 5 bits per byte */
00070 #define DZ_CS6           0x0008               /* 6 bits per byte */
00071 #define DZ_CS7           0x0010               /* 7 bits per byte */
00072 #define DZ_CS8           0x0018               /* 8 bits per byte */
00073 
00074 #define DZ_CSTOPB        0x0020               /* 2 stop bits instead of one */ 
00075 
00076 #define DZ_PARENB        0x0040               /* Parity enable */
00077 #define DZ_PARODD        0x0080               /* Odd parity instead of even */
00078 
00079 #define DZ_CBAUD         0x0E00               /* Baud Rate (mask) */
00080 #define DZ_B50           0x0000
00081 #define DZ_B75           0x0100
00082 #define DZ_B110          0x0200
00083 #define DZ_B134          0x0300
00084 #define DZ_B150          0x0400
00085 #define DZ_B300          0x0500
00086 #define DZ_B600          0x0600
00087 #define DZ_B1200         0x0700 
00088 #define DZ_B1800         0x0800
00089 #define DZ_B2000         0x0900
00090 #define DZ_B2400         0x0A00
00091 #define DZ_B3600         0x0B00
00092 #define DZ_B4800         0x0C00
00093 #define DZ_B7200         0x0D00
00094 #define DZ_B9600         0x0E00
00095 
00096 #define DZ_CREAD         0x1000               /* Enable receiver */
00097 #define DZ_RXENAB        0x1000               /* enable receive char */
00098 /*
00099  * Addresses for the DZ registers
00100  */
00101 #define DZ_CSR       0x00            /* Control and Status Register */
00102 #define DZ_RBUF      0x08            /* Receive Buffer */
00103 #define DZ_LPR       0x08            /* Line Parameters Register */
00104 #define DZ_TCR       0x10            /* Transmitter Control Register */
00105 #define DZ_MSR       0x18            /* Modem Status Register */
00106 #define DZ_TDR       0x18            /* Transmit Data Register */
00107 
00108 
00109 #define DZ_NB_PORT 4
00110 
00111 #define DZ_XMIT_SIZE   4096                 /* buffer size */
00112 #define WAKEUP_CHARS   DZ_XMIT_SIZE/4
00113 
00114 #define DZ_EVENT_WRITE_WAKEUP   0
00115 
00116 #ifndef MIN
00117 #define MIN(a,b)        ((a) < (b) ? (a) : (b))
00118 
00119 #define DZ_INITIALIZED       0x80000000 /* Serial port was initialized */
00120 #define DZ_CALLOUT_ACTIVE    0x40000000 /* Call out device is active */
00121 #define DZ_NORMAL_ACTIVE     0x20000000 /* Normal device is active */
00122 #define DZ_BOOT_AUTOCONF     0x10000000 /* Autoconfigure port on bootup */
00123 #define DZ_CLOSING           0x08000000 /* Serial port is closing */
00124 #define DZ_CTS_FLOW          0x04000000 /* Do CTS flow control */
00125 #define DZ_CHECK_CD          0x02000000 /* i.e., CLOCAL */
00126 
00127 #define DZ_CLOSING_WAIT_INF  0
00128 #define DZ_CLOSING_WAIT_NONE 65535
00129 
00130 #define DZ_SPLIT_TERMIOS   0x0008 /* Separate termios for dialin/callout */
00131 #define DZ_SESSION_LOCKOUT 0x0100 /* Lock out cua opens based on session */
00132 #define DZ_PGRP_LOCKOUT    0x0200 /* Lock out cua opens based on pgrp */
00133 
00134 struct dz_serial {
00135   unsigned                port;                /* base address for the port */
00136   int                     type;
00137   int                     flags; 
00138   int                     baud_base;
00139   int                     blocked_open;
00140   unsigned short          close_delay;
00141   unsigned short          closing_wait;
00142   unsigned short          line;                /* port/line number */
00143   unsigned short          cflags;              /* line configuration flag */
00144   unsigned short          x_char;              /* xon/xoff character */
00145   unsigned short          read_status_mask;    /* mask for read condition */
00146   unsigned short          ignore_status_mask;  /* mask for ignore condition */
00147   unsigned long           event;               /* mask used in BH */
00148   unsigned char           *xmit_buf;           /* Transmit buffer */
00149   int                     xmit_head;           /* Position of the head */
00150   int                     xmit_tail;           /* Position of the tail */
00151   int                     xmit_cnt;            /* Count of the chars in the buffer */
00152   int                     count;               /* indicates how many times it has been opened */
00153   int                     magic;
00154 
00155   struct async_icount     icount;              /* keep track of things ... */
00156   struct tty_struct       *tty;                /* tty associated */
00157   struct tq_struct        tqueue;              /* Queue for BH */
00158   struct tq_struct        tqueue_hangup;
00159   struct termios          normal_termios;
00160   struct termios          callout_termios;
00161   struct wait_queue       *open_wait;
00162   struct wait_queue       *close_wait;
00163 
00164   long                    session;             /* Session of opening process */
00165   long                    pgrp;                /* pgrp of opening process */
00166 
00167   unsigned char           is_console;          /* flag indicating a serial console */
00168   unsigned char           is_initialized;
00169 };
00170 
00171 static struct dz_serial multi[DZ_NB_PORT];    /* Four serial lines in the DZ chip */
00172 static struct dz_serial *dz_console;
00173 static struct tty_driver serial_driver, callout_driver;
00174 
00175 static struct tty_struct *serial_table[DZ_NB_PORT];
00176 static struct termios *serial_termios[DZ_NB_PORT];
00177 static struct termios *serial_termios_locked[DZ_NB_PORT];
00178 
00179 static int serial_refcount;
00180 
00181 /*
00182  * tmp_buf is used as a temporary buffer by serial_write.  We need to
00183  * lock it in case the copy_from_user blocks while swapping in a page,
00184  * and some other program tries to do a serial write at the same time.
00185  * Since the lock will only come under contention when the system is
00186  * swapping and available memory is low, it makes sense to share one
00187  * buffer across all the serial ports, since it significantly saves
00188  * memory if large numbers of serial ports are open.
00189  */
00190 static unsigned char *tmp_buf;
00191 static struct semaphore tmp_buf_sem = MUTEX;
00192 
00193 static char *dz_name = "DECstation DZ serial driver version ";
00194 static char *dz_version = "1.02";
00195 
00196 static inline unsigned short dz_in (struct dz_serial *, unsigned);
00197 static inline void dz_out (struct dz_serial *, unsigned, unsigned short);
00198 
00199 static inline void dz_sched_event (struct dz_serial *, int);
00200 static inline void receive_chars (struct dz_serial *);
00201 static inline void transmit_chars (struct dz_serial *);
00202 static inline void check_modem_status (struct dz_serial *);
00203 
00204 static void dz_stop (struct tty_struct *);
00205 static void dz_start (struct tty_struct *);
00206 static void dz_interrupt (int, void *, struct pt_regs *);
00207 static void do_serial_bh (void);
00208 static void do_softint (void *);
00209 static void do_serial_hangup (void *);
00210 static void change_speed (struct dz_serial *);
00211 static void dz_flush_chars (struct tty_struct *);
00212 static void dz_console_print (struct console *, const char *, unsigned int);
00213 static void dz_flush_buffer (struct tty_struct *);
00214 static void dz_throttle (struct tty_struct *);
00215 static void dz_unthrottle (struct tty_struct *);
00216 static void dz_send_xchar (struct tty_struct *, char);
00217 static void shutdown (struct dz_serial *);
00218 static void send_break (struct dz_serial *, int);
00219 static void dz_set_termios (struct tty_struct *, struct termios *);
00220 static void dz_close (struct tty_struct *, struct file *);
00221 static void dz_hangup (struct tty_struct *);
00222 static void show_serial_version (void);
00223 
00224 static int dz_write (struct tty_struct *, int, const unsigned char *, int);
00225 static int dz_write_room (struct tty_struct *);
00226 static int dz_chars_in_buffer (struct tty_struct *);
00227 static int startup (struct dz_serial *);
00228 static int get_serial_info (struct dz_serial *, struct serial_struct *);
00229 static int set_serial_info (struct dz_serial *, struct serial_struct *);
00230 static int get_lsr_info (struct dz_serial *, unsigned int *);
00231 static int dz_ioctl (struct tty_struct *, struct file *, unsigned int, unsigned long);
00232 static int block_til_ready (struct tty_struct *, struct file *, struct dz_serial *);
00233 static int dz_open (struct tty_struct *, struct file *);
00234 
00235 #ifdef MODULE
00236 int init_module (void)
00237 void cleanup_module (void)
00238 #endif
00239 
00240 #endif
00241 
00242 #endif /* DZ_SERIAL_H */