root/drivers/char/serial.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. serial_paranoia_check
  2. serial_in
  3. serial_inp
  4. serial_out
  5. serial_outp
  6. rs_stop
  7. rs_start
  8. rs_probe
  9. rs_sched_event
  10. receive_chars
  11. transmit_chars
  12. check_modem_status
  13. rs_interrupt
  14. rs_interrupt_single
  15. rs_interrupt
  16. rs_interrupt_single
  17. do_serial_bh
  18. do_softint
  19. rs_timer
  20. grab_all_interrupts
  21. free_all_interrupts
  22. figure_IRQ_timeout
  23. startup
  24. shutdown
  25. change_speed
  26. rs_put_char
  27. rs_flush_chars
  28. rs_write
  29. rs_write_room
  30. rs_chars_in_buffer
  31. rs_flush_buffer
  32. rs_throttle
  33. rs_unthrottle
  34. get_serial_info
  35. set_serial_info
  36. get_modem_info
  37. set_modem_info
  38. do_autoconfig
  39. send_break
  40. check_wild_interrupts
  41. rs_ioctl
  42. rs_set_termios
  43. rs_close
  44. rs_hangup
  45. block_til_ready
  46. rs_open
  47. show_serial_version
  48. get_auto_irq
  49. do_auto_irq
  50. autoconfig
  51. rs_init
  52. register_serial
  53. unregister_serial

   1 /*
   2  *  linux/kernel/serial.c
   3  *
   4  *  Copyright (C) 1991, 1992  Linus Torvalds
   5  *
   6  *  Extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92.  Now
   7  *  much more extensible to support other serial cards based on the
   8  *  16450/16550A UART's.  Added support for the AST FourPort and the
   9  *  Accent Async board.  
  10  *
  11  *  set_serial_info fixed to set the flags, custom divisor, and uart
  12  *      type fields.  Fix suggested by Michael K. Johnson 12/12/92.
  13  *
  14  * This module exports the following rs232 io functions:
  15  *
  16  *      long rs_init(long);
  17  *      int  rs_open(struct tty_struct * tty, struct file * filp)
  18  */
  19 
  20 #include <linux/errno.h>
  21 #include <linux/signal.h>
  22 #include <linux/sched.h>
  23 #include <linux/timer.h>
  24 #include <linux/interrupt.h>
  25 #include <linux/tty.h>
  26 #include <linux/tty_flip.h>
  27 #include <linux/serial.h>
  28 #include <linux/serial_reg.h>
  29 #include <linux/config.h>
  30 #include <linux/major.h>
  31 #include <linux/string.h>
  32 #include <linux/fcntl.h>
  33 #include <linux/ptrace.h>
  34 #include <linux/major.h>
  35 
  36 #include <asm/system.h>
  37 #include <asm/io.h>
  38 #include <asm/segment.h>
  39 #include <asm/bitops.h>
  40 
  41 DECLARE_TASK_QUEUE(tq_serial);
  42 
  43 struct tty_driver serial_driver, callout_driver;
  44 static int serial_refcount;
  45 
  46 /* serial subtype definitions */
  47 #define SERIAL_TYPE_NORMAL      1
  48 #define SERIAL_TYPE_CALLOUT     2
  49 
  50 /* number of characters left in xmit buffer before we ask for more */
  51 #define WAKEUP_CHARS 256
  52 
  53 /*
  54  * Serial driver configuration section.  Here are the various options:
  55  *
  56  * CONFIG_HUB6
  57  *              Enables support for the venerable Bell Technologies
  58  *              HUB6 card.
  59  *
  60  * SERIAL_PARANOIA_CHECK
  61  *              Check the magic number for the async_structure where
  62  *              ever possible.
  63  */
  64 
  65 #define SERIAL_PARANOIA_CHECK
  66 #define CONFIG_SERIAL_NOPAUSE_IO
  67 #define SERIAL_DO_RESTART
  68 #define CONFIG_SERIAL_NEW_ISR
  69 
  70 #undef SERIAL_DEBUG_INTR
  71 #undef SERIAL_DEBUG_OPEN
  72 #undef SERIAL_DEBUG_FLOW
  73 
  74 #define _INLINE_ inline
  75   
  76 /*
  77  * IRQ_timeout          - How long the timeout should be for each IRQ
  78  *                              should be after the IRQ has been active.
  79  */
  80 
  81 static struct async_struct *IRQ_ports[16];
  82 static int IRQ_timeout[16];
  83 static volatile int rs_irq_triggered;
  84 static volatile int rs_triggered;
  85 static int rs_wild_int_mask;
  86 
  87 static void autoconfig(struct async_struct * info);
  88 static void change_speed(struct async_struct *info);
  89         
  90 /*
  91  * This assumes you have a 1.8432 MHz clock for your UART.
  92  *
  93  * It'd be nice if someone built a serial card with a 24.576 MHz
  94  * clock, since the 16550A is capable of handling a top speed of 1.5
  95  * megabits/second; but this requires the faster clock.
  96  */
  97 #define BASE_BAUD ( 1843200 / 16 )
  98 
  99 /* Standard COM flags (except for COM4, because of the 8514 problem) */
 100 #define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST )
 101 #define STD_COM4_FLAGS ASYNC_BOOT_AUTOCONF
 102 
 103 #define FOURPORT_FLAGS ASYNC_FOURPORT
 104 #define ACCENT_FLAGS 0
 105 #define BOCA_FLAGS 0
 106 #define HUB6_FLAGS 0
 107         
 108 /*
 109  * The following define the access methods for the HUB6 card. All
 110  * access is through two ports for all 24 possible chips. The card is
 111  * selected through the high 2 bits, the port on that card with the
 112  * "middle" 3 bits, and the register on that port with the bottom
 113  * 3 bits.
 114  *
 115  * While the access port and interrupt is configurable, the default
 116  * port locations are 0x302 for the port control register, and 0x303
 117  * for the data read/write register. Normally, the interrupt is at irq3
 118  * but can be anything from 3 to 7 inclusive. Note that using 3 will
 119  * require disabling com2.
 120  */
 121 
 122 #define C_P(card,port) (((card)<<6|(port)<<3) + 1)
 123 
 124 struct async_struct rs_table[] = {
 125         /* UART CLK   PORT IRQ     FLAGS        */
 126         { 0, BASE_BAUD, 0x3F8, 4, STD_COM_FLAGS },      /* ttyS0 */
 127         { 0, BASE_BAUD, 0x2F8, 3, STD_COM_FLAGS },      /* ttyS1 */
 128         { 0, BASE_BAUD, 0x3E8, 4, STD_COM_FLAGS },      /* ttyS2 */
 129         { 0, BASE_BAUD, 0x2E8, 3, STD_COM4_FLAGS },     /* ttyS3 */
 130 
 131         { 0, BASE_BAUD, 0x1A0, 9, FOURPORT_FLAGS },     /* ttyS4 */
 132         { 0, BASE_BAUD, 0x1A8, 9, FOURPORT_FLAGS },     /* ttyS5 */
 133         { 0, BASE_BAUD, 0x1B0, 9, FOURPORT_FLAGS },     /* ttyS6 */
 134         { 0, BASE_BAUD, 0x1B8, 9, FOURPORT_FLAGS },     /* ttyS7 */
 135 
 136         { 0, BASE_BAUD, 0x2A0, 5, FOURPORT_FLAGS },     /* ttyS8 */
 137         { 0, BASE_BAUD, 0x2A8, 5, FOURPORT_FLAGS },     /* ttyS9 */
 138         { 0, BASE_BAUD, 0x2B0, 5, FOURPORT_FLAGS },     /* ttyS10 */
 139         { 0, BASE_BAUD, 0x2B8, 5, FOURPORT_FLAGS },     /* ttyS11 */
 140         
 141         { 0, BASE_BAUD, 0x330, 4, ACCENT_FLAGS },       /* ttyS12 */
 142         { 0, BASE_BAUD, 0x338, 4, ACCENT_FLAGS },       /* ttyS13 */
 143         { 0, BASE_BAUD, 0x000, 0, 0 },  /* ttyS14 (spare; user configurable) */
 144         { 0, BASE_BAUD, 0x000, 0, 0 },  /* ttyS15 (spare; user configurable) */
 145 
 146         { 0, BASE_BAUD, 0x100, 12, BOCA_FLAGS },        /* ttyS16 */
 147         { 0, BASE_BAUD, 0x108, 12, BOCA_FLAGS },        /* ttyS17 */
 148         { 0, BASE_BAUD, 0x110, 12, BOCA_FLAGS },        /* ttyS18 */
 149         { 0, BASE_BAUD, 0x118, 12, BOCA_FLAGS },        /* ttyS19 */
 150         { 0, BASE_BAUD, 0x120, 12, BOCA_FLAGS },        /* ttyS20 */
 151         { 0, BASE_BAUD, 0x128, 12, BOCA_FLAGS },        /* ttyS21 */
 152         { 0, BASE_BAUD, 0x130, 12, BOCA_FLAGS },        /* ttyS22 */
 153         { 0, BASE_BAUD, 0x138, 12, BOCA_FLAGS },        /* ttyS23 */
 154         { 0, BASE_BAUD, 0x140, 12, BOCA_FLAGS },        /* ttyS24 */
 155         { 0, BASE_BAUD, 0x148, 12, BOCA_FLAGS },        /* ttyS25 */
 156         { 0, BASE_BAUD, 0x150, 12, BOCA_FLAGS },        /* ttyS26 */
 157         { 0, BASE_BAUD, 0x158, 12, BOCA_FLAGS },        /* ttyS27 */
 158         { 0, BASE_BAUD, 0x160, 12, BOCA_FLAGS },        /* ttyS28 */
 159         { 0, BASE_BAUD, 0x168, 12, BOCA_FLAGS },        /* ttyS29 */
 160         { 0, BASE_BAUD, 0x170, 12, BOCA_FLAGS },        /* ttyS30 */
 161         { 0, BASE_BAUD, 0x178, 12, BOCA_FLAGS },        /* ttyS31 */
 162 
 163 /* You can have up to four HUB6's in the system, but I've only
 164  * included two cards here for a total of twelve ports.
 165  */
 166         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,0) },       /* ttyS32 */
 167         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,1) },       /* ttyS33 */
 168         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,2) },       /* ttyS34 */
 169         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,3) },       /* ttyS35 */
 170         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,4) },       /* ttyS36 */
 171         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(0,5) },       /* ttyS37 */
 172         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,0) },       /* ttyS32 */
 173         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,1) },       /* ttyS33 */
 174         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,2) },       /* ttyS34 */
 175         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,3) },       /* ttyS35 */
 176         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,4) },       /* ttyS36 */
 177         { 0, BASE_BAUD, 0x302, 3, HUB6_FLAGS, C_P(1,5) },       /* ttyS37 */
 178 };
 179 
 180 #define NR_PORTS        (sizeof(rs_table)/sizeof(struct async_struct))
 181 
 182 static struct tty_struct *serial_table[NR_PORTS];
 183 static struct termios *serial_termios[NR_PORTS];
 184 static struct termios *serial_termios_locked[NR_PORTS];
 185 
 186 #ifndef MIN
 187 #define MIN(a,b)        ((a) < (b) ? (a) : (b))
 188 #endif
 189 
 190 /*
 191  * tmp_buf is used as a temporary buffer by serial_write.  We need to
 192  * lock it in case the memcpy_fromfs blocks while swapping in a page,
 193  * and some other program tries to do a serial write at the same time.
 194  * Since the lock will only come under contention when the system is
 195  * swapping and available memory is low, it makes sense to share one
 196  * buffer across all the serial ports, since it significantly saves
 197  * memory if large numbers of serial ports are open.
 198  */
 199 static unsigned char *tmp_buf = 0;
 200 static struct semaphore tmp_buf_sem = MUTEX;
 201 
 202 static inline int serial_paranoia_check(struct async_struct *info,
     /* [previous][next][first][last][top][bottom][index][help] */
 203                                         dev_t device, const char *routine)
 204 {
 205 #ifdef SERIAL_PARANOIA_CHECK
 206         static const char *badmagic =
 207                 "Warning: bad magic number for serial struct (%d, %d) in %s\n";
 208         static const char *badinfo =
 209                 "Warning: null async_struct for (%d, %d) in %s\n";
 210 
 211         if (!info) {
 212                 printk(badinfo, MAJOR(device), MINOR(device), routine);
 213                 return 1;
 214         }
 215         if (info->magic != SERIAL_MAGIC) {
 216                 printk(badmagic, MAJOR(device), MINOR(device), routine);
 217                 return 1;
 218         }
 219 #endif
 220         return 0;
 221 }
 222 
 223 /*
 224  * This is used to figure out the divisor speeds and the timeouts
 225  */
 226 static int baud_table[] = {
 227         0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
 228         9600, 19200, 38400, 57600, 115200, 0 };
 229 
 230 static inline unsigned int serial_in(struct async_struct *info, int offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 231 {
 232 #ifdef CONFIG_HUB6
 233     if (info->hub6) {
 234         outb(info->hub6 - 1 + offset, info->port);
 235         return inb(info->port+1);
 236     } else
 237 #endif
 238         return inb(info->port + offset);
 239 }
 240 
 241 static inline unsigned int serial_inp(struct async_struct *info, int offset)
     /* [previous][next][first][last][top][bottom][index][help] */
 242 {
 243 #ifdef CONFIG_HUB6
 244     if (info->hub6) {
 245         outb(info->hub6 - 1 + offset, info->port);
 246         return inb_p(info->port+1);
 247     } else
 248 #endif
 249 #ifdef CONFIG_SERIAL_NOPAUSE_IO
 250         return inb(info->port + offset);
 251 #else
 252         return inb_p(info->port + offset);
 253 #endif
 254 }
 255 
 256 static inline void serial_out(struct async_struct *info, int offset, int value)
     /* [previous][next][first][last][top][bottom][index][help] */
 257 {
 258 #ifdef CONFIG_HUB6
 259     if (info->hub6) {
 260         outb(info->hub6 - 1 + offset, info->port);
 261         outb(value, info->port+1);
 262     } else
 263 #endif
 264         outb(value, info->port+offset);
 265 }
 266 
 267 static inline void serial_outp(struct async_struct *info, int offset,
     /* [previous][next][first][last][top][bottom][index][help] */
 268                                int value)
 269 {
 270 #ifdef CONFIG_HUB6
 271     if (info->hub6) {
 272         outb(info->hub6 - 1 + offset, info->port);
 273         outb_p(value, info->port+1);
 274     } else
 275 #endif
 276 #ifdef CONFIG_SERIAL_NOPAUSE_IO
 277         outb(value, info->port+offset);
 278 #else
 279         outb_p(value, info->port+offset);
 280 #endif
 281 }
 282 
 283 /*
 284  * ------------------------------------------------------------
 285  * rs_stop() and rs_start()
 286  *
 287  * This routines are called before setting or resetting tty->stopped.
 288  * They enable or disable transmitter interrupts, as necessary.
 289  * ------------------------------------------------------------
 290  */
 291 static void rs_stop(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
 292 {
 293         struct async_struct *info = (struct async_struct *)tty->driver_data;
 294         unsigned long flags;
 295 
 296         if (serial_paranoia_check(info, tty->device, "rs_stop"))
 297                 return;
 298         
 299         save_flags(flags); cli();
 300         if (info->IER & UART_IER_THRI) {
 301                 info->IER &= ~UART_IER_THRI;
 302                 serial_out(info, UART_IER, info->IER);
 303         }
 304         restore_flags(flags);
 305 }
 306 
 307 static void rs_start(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
 308 {
 309         struct async_struct *info = (struct async_struct *)tty->driver_data;
 310         unsigned long flags;
 311         
 312         if (serial_paranoia_check(info, tty->device, "rs_start"))
 313                 return;
 314         
 315         save_flags(flags); cli();
 316         if (info->xmit_cnt && !info->xmit_buf &&
 317             !(info->IER & UART_IER_THRI)) {
 318                 info->IER |= UART_IER_THRI;
 319                 serial_out(info, UART_IER, info->IER);
 320         }
 321         restore_flags(flags);
 322 }
 323 
 324 /*
 325  * ----------------------------------------------------------------------
 326  *
 327  * Here starts the interrupt handling routines.  All of the following
 328  * subroutines are declared as inline and are folded into
 329  * rs_interrupt().  They were separated out for readability's sake.
 330  *
 331  * Note: rs_interrupt() is a "fast" interrupt, which means that it
 332  * runs with interrupts turned off.  People who may want to modify
 333  * rs_interrupt() should try to keep the interrupt handler as fast as
 334  * possible.  After you are done making modifications, it is not a bad
 335  * idea to do:
 336  * 
 337  * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
 338  *
 339  * and look at the resulting assemble code in serial.s.
 340  *
 341  *                              - Ted Ts'o (tytso@mit.edu), 7-Mar-93
 342  * -----------------------------------------------------------------------
 343  */
 344 
 345 /*
 346  * This is the serial driver's interrupt routine while we are probing
 347  * for submarines.
 348  */
 349 static void rs_probe(int irq)
     /* [previous][next][first][last][top][bottom][index][help] */
 350 {
 351         rs_irq_triggered = irq;
 352         rs_triggered |= 1 << irq;
 353         return;
 354 }
 355 
 356 /*
 357  * This routine is used by the interrupt handler to schedule
 358  * processing in the software interrupt portion of the driver.
 359  */
 360 static _INLINE_ void rs_sched_event(struct async_struct *info,
     /* [previous][next][first][last][top][bottom][index][help] */
 361                                   int event)
 362 {
 363         info->event |= 1 << event;
 364         queue_task_irq_off(&info->tqueue, &tq_serial);
 365         mark_bh(SERIAL_BH);
 366 }
 367 
 368 static _INLINE_ void receive_chars(struct async_struct *info,
     /* [previous][next][first][last][top][bottom][index][help] */
 369                                  int *status)
 370 {
 371         struct tty_struct *tty = info->tty;
 372         unsigned char ch;
 373 
 374         do {
 375                 ch = serial_inp(info, UART_RX);
 376                 if (*status & info->ignore_status_mask)
 377                         continue;
 378                 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
 379                         break;
 380                 tty->flip.count++;
 381                 if (*status & info->read_status_mask) {
 382                         if (*status & (UART_LSR_BI)) {
 383                                 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
 384                                 if (info->flags & ASYNC_SAK)
 385                                         do_SAK(tty);
 386                         } else if (*status & UART_LSR_PE)
 387                                 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
 388                         else if (*status & UART_LSR_FE)
 389                                 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
 390                         else if (*status & UART_LSR_OE) 
 391                                 *tty->flip.flag_buf_ptr++ = TTY_OVERRUN;
 392                         else
 393                                 *tty->flip.flag_buf_ptr++ = 0;
 394                 } else
 395                         *tty->flip.flag_buf_ptr++ = 0;
 396                 *tty->flip.char_buf_ptr++ = ch;
 397         } while ((*status = serial_inp(info, UART_LSR)) & UART_LSR_DR);
 398         queue_task_irq_off(&tty->flip.tqueue, &tq_timer);
 399 #ifdef SERIAL_DEBUG_INTR
 400         printk("DR...");
 401 #endif
 402 }
 403 
 404 static _INLINE_ void transmit_chars(struct async_struct *info, int *intr_done)
     /* [previous][next][first][last][top][bottom][index][help] */
 405 {
 406         int count;
 407         
 408         if (info->x_char) {
 409                 serial_outp(info, UART_TX, info->x_char);
 410                 info->x_char = 0;
 411                 if (intr_done)
 412                         *intr_done = 0;
 413                 return;
 414         }
 415         if ((info->xmit_cnt <= 0) || info->tty->stopped ||
 416             info->tty->hw_stopped) {
 417                 info->IER &= ~UART_IER_THRI;
 418 #ifdef CONFIG_SERIAL_NEW_ISR
 419                 serial_out(info, UART_IER, info->IER);
 420 #endif
 421                 return;
 422         }
 423         
 424         count = info->xmit_fifo_size;
 425         do {
 426                 serial_out(info, UART_TX, info->xmit_buf[info->xmit_tail++]);
 427                 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
 428                 if (--info->xmit_cnt <= 0)
 429                         break;
 430         } while (--count > 0);
 431         
 432         if (info->xmit_cnt < WAKEUP_CHARS)
 433                 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
 434 
 435 #ifdef SERIAL_DEBUG_INTR
 436         printk("THRE...");
 437 #endif
 438         if (intr_done)
 439                 *intr_done = 0;
 440 
 441         if (info->xmit_cnt <= 0) {
 442                 info->IER &= ~UART_IER_THRI;
 443 #ifdef CONFIG_SERIAL_NEW_ISR
 444                 serial_out(info, UART_IER, info->IER);
 445 #endif
 446         }
 447 }
 448 
 449 static _INLINE_ void check_modem_status(struct async_struct *info)
     /* [previous][next][first][last][top][bottom][index][help] */
 450 {
 451         int     status;
 452         
 453         status = serial_in(info, UART_MSR);
 454 
 455         if ((info->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
 456 #if (defined(SERIAL_DEBUG_OPEN) || defined(SERIAL_DEBUG_INTR))
 457                 printk("ttys%d CD now %s...", info->line,
 458                        (status & UART_MSR_DCD) ? "on" : "off");
 459 #endif          
 460                 if (status & UART_MSR_DCD)
 461                         wake_up_interruptible(&info->open_wait);
 462                 else if (!((info->flags & ASYNC_CALLOUT_ACTIVE) &&
 463                            (info->flags & ASYNC_CALLOUT_NOHUP))) {
 464 #ifdef SERIAL_DEBUG_OPEN
 465                         printk("scheduling hangup...");
 466 #endif
 467                         rs_sched_event(info, RS_EVENT_HANGUP);
 468                 }
 469         }
 470         if (info->flags & ASYNC_CTS_FLOW) {
 471                 if (info->tty->hw_stopped) {
 472                         if (status & UART_MSR_CTS) {
 473 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
 474                                 printk("CTS tx start...");
 475 #endif
 476                                 info->tty->hw_stopped = 0;
 477                                 info->IER |= UART_IER_THRI;
 478 #ifdef CONFIG_SERIAL_NEW_ISR
 479                                 serial_out(info, UART_IER, info->IER);
 480 #endif
 481                                 rs_sched_event(info, RS_EVENT_WRITE_WAKEUP);
 482                                 return;
 483                         }
 484                 } else {
 485                         if (!(status & UART_MSR_CTS)) {
 486 #if (defined(SERIAL_DEBUG_INTR) || defined(SERIAL_DEBUG_FLOW))
 487                                 printk("CTS tx stop...");
 488 #endif
 489                                 info->tty->hw_stopped = 1;
 490                                 info->IER &= ~UART_IER_THRI;
 491 #ifdef CONFIG_SERIAL_NEW_ISR
 492                                 serial_out(info, UART_IER, info->IER);
 493 #endif
 494                         }
 495                 }
 496         }
 497 }
 498 
 499 #ifdef CONFIG_SERIAL_NEW_ISR
 500 /*
 501  * This is the serial driver's generic interrupt routine
 502  */
 503 static void rs_interrupt(int irq)
     /* [previous][next][first][last][top][bottom][index][help] */
 504 {
 505         int status;
 506         struct async_struct * info;
 507         int pass_counter = 0;
 508         struct async_struct *end_mark = 0;
 509 
 510 #ifdef SERIAL_DEBUG_INTR
 511         printk("rs_interrupt(%d)...", irq);
 512 #endif
 513         
 514         info = IRQ_ports[irq];
 515         if (!info)
 516                 return;
 517         
 518         do {
 519                 if (!info->tty ||
 520                     (serial_in(info, UART_IIR) & UART_IIR_NO_INT)) {
 521                         if (!end_mark)
 522                                 end_mark = info;
 523                         goto next;
 524                 }
 525                 end_mark = 0;
 526 
 527                 info->last_active = jiffies;
 528 
 529                 status = serial_inp(info, UART_LSR);
 530                 if (status & UART_LSR_DR)
 531                         receive_chars(info, &status);
 532                 check_modem_status(info);
 533                 if (status & UART_LSR_THRE)
 534                         transmit_chars(info, 0);
 535 
 536         next:
 537                 info = info->next_port;
 538                 if (!info) {
 539                         info = IRQ_ports[irq];
 540                         if (pass_counter++ > 64) {
 541 #if 0
 542                                 printk("rs loop break\n");
 543 #endif
 544                                 break;  /* Prevent infinite loops */
 545                         }
 546                         continue;
 547                 }
 548         } while (end_mark != info);
 549 }
 550 
 551 /*
 552  * This is the serial driver's interrupt routine for a single port
 553  */
 554 static void rs_interrupt_single(int irq)
     /* [previous][next][first][last][top][bottom][index][help] */
 555 {
 556         int status;
 557         int pass_counter = 0;
 558         struct async_struct * info;
 559         
 560 #ifdef SERIAL_DEBUG_INTR
 561         printk("rs_interrupt_single(%d)...", irq);
 562 #endif
 563         
 564         info = IRQ_ports[irq];
 565         if (!info || !info->tty)
 566                 return;
 567 
 568         do {
 569                 status = serial_inp(info, UART_LSR);
 570                 if (status & UART_LSR_DR)
 571                         receive_chars(info, &status);
 572                 check_modem_status(info);
 573                 if (status & UART_LSR_THRE)
 574                         transmit_chars(info, 0);
 575                 if (pass_counter++ > 64) {
 576 #if 0
 577                         printk("rs_single loop break.\n");
 578 #endif
 579                         break;
 580                 }
 581         } while (!(serial_in(info, UART_IIR) & UART_IIR_NO_INT));
 582         info->last_active = jiffies;
 583 }
 584 
 585 #else /* CONFIG_SERIAL_NEW_ISR */
 586 
 587 /*
 588  * This is the serial driver's generic interrupt routine
 589  */
 590 static void rs_interrupt(int irq)
     /* [previous][next][first][last][top][bottom][index][help] */
 591 {
 592         int status;
 593         struct async_struct * info;
 594         int done = 1, pass_counter = 0;
 595 
 596         
 597 #ifdef SERIAL_DEBUG_INTR
 598         printk("rs_interrupt(%d)...", irq);
 599 #endif
 600         
 601         info = IRQ_ports[irq];
 602         if (!info)
 603                 return;
 604         
 605         while (1) {
 606                 if (!info->tty)
 607                         goto next;
 608 
 609                 serial_outp(info, UART_IER, 0);
 610                 status = serial_inp(info, UART_LSR);
 611                 if (status & UART_LSR_DR) {
 612                         receive_chars(info, &status);
 613                         done = 0;
 614                 }
 615                 check_modem_status(info);
 616                 if (status & UART_LSR_THRE)
 617                         transmit_chars(info, &done);
 618 
 619         next:
 620                 info = info->next_port;         
 621                 if (!info) {
 622                         info = IRQ_ports[irq];
 623                         if (done)
 624                                 break;
 625                         done = 1;
 626                         if (pass_counter++ > 64) {
 627 #if 0
 628                                 printk("rs loop break\n");
 629 #endif
 630                                 break;  /* Prevent infinite loops */
 631                         }
 632                 }
 633         }
 634 
 635         /*
 636          * Reset the IER registers; info is already set up from the
 637          * above while loop.
 638          */
 639         do
 640                 serial_outp(info, UART_IER, info->IER);
 641         while ((info = info->next_port) != NULL);
 642 }
 643 
 644 /*
 645  * This is the serial driver's interrupt routine for a single port
 646  */
 647 static void rs_interrupt_single(int irq)
     /* [previous][next][first][last][top][bottom][index][help] */
 648 {
 649         int status;
 650         struct async_struct * info;
 651 
 652         
 653 #ifdef SERIAL_DEBUG_INTR
 654         printk("rs_interrupt_single(%d)...", irq);
 655 #endif
 656         
 657         info = IRQ_ports[irq];
 658         if (!info || !info->tty)
 659                 return;
 660 
 661         serial_outp(info, UART_IER, 0);
 662         status = serial_inp(info, UART_LSR);
 663         if (status & UART_LSR_DR)
 664                 receive_chars(info, &status);
 665         check_modem_status(info);
 666         if (status & UART_LSR_THRE)
 667                 transmit_chars(info, 0);
 668 
 669         /*
 670          * Reset the IER register
 671          */
 672         serial_outp(info, UART_IER, info->IER);
 673 }
 674 
 675 #endif /* CONFIG_SERIAL_NEW_ISR */
 676 
 677 /*
 678  * -------------------------------------------------------------------
 679  * Here ends the serial interrupt routines.
 680  * -------------------------------------------------------------------
 681  */
 682 
 683 /*
 684  * This routine is used to handle the "bottom half" processing for the
 685  * serial driver, known also the "software interrupt" processing.
 686  * This processing is done at the kernel interrupt level, after the
 687  * rs_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON.  This
 688  * is where time-consuming activities which can not be done in the
 689  * interrupt driver proper are done; the interrupt driver schedules
 690  * them using rs_sched_event(), and they get done here.
 691  */
 692 static void do_serial_bh(void *unused)
     /* [previous][next][first][last][top][bottom][index][help] */
 693 {
 694         run_task_queue(&tq_serial);
 695 }
 696 
 697 static void do_softint(void *private_)
     /* [previous][next][first][last][top][bottom][index][help] */
 698 {
 699         struct async_struct     *info = (struct async_struct *) private_;
 700         struct tty_struct       *tty;
 701         
 702         tty = info->tty;
 703         if (!tty)
 704                 return;
 705 
 706         if (clear_bit(RS_EVENT_HANGUP, &info->event)) {
 707                 tty_hangup(tty);
 708                 wake_up_interruptible(&info->open_wait);
 709                 info->flags &= ~(ASYNC_NORMAL_ACTIVE|
 710                                  ASYNC_CALLOUT_ACTIVE);
 711         }
 712         if (clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) {
 713                 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
 714                     tty->ldisc.write_wakeup)
 715                         (tty->ldisc.write_wakeup)(tty);
 716                 wake_up_interruptible(&tty->write_wait);
 717         }
 718 }
 719 
 720 /*
 721  * This subroutine is called when the RS_TIMER goes off.  It is used
 722  * by the serial driver to handle ports that do not have an interrupt
 723  * (irq=0).  This doesn't work very well for 16450's, but gives barely
 724  * passable results for a 16550A.  (Although at the expense of much
 725  * CPU overhead).
 726  */
 727 static void rs_timer(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 728 {
 729         static unsigned long last_strobe = 0;
 730         struct async_struct *info;
 731         unsigned int    i;
 732 
 733         if ((jiffies - last_strobe) >= 60*HZ) {
 734                 for (i=1; i < 16; i++) {
 735                         info = IRQ_ports[i];
 736                         if (!info)
 737                                 continue;
 738                         cli();
 739                         if (info->next_port) {
 740                                 do {
 741                                         serial_out(info, UART_IER, 0);
 742                                         info->IER |= UART_IER_THRI;
 743                                         serial_out(info, UART_IER, info->IER);
 744                                         info = info->next_port;
 745                                 } while (info);
 746                                 rs_interrupt(i);
 747                         } else
 748                                 rs_interrupt_single(i);
 749                         sti();
 750                 }
 751         }
 752         last_strobe = jiffies;
 753         timer_table[RS_TIMER].expires = jiffies + 60 * HZ;
 754         timer_active |= 1 << RS_TIMER;
 755 
 756         if (IRQ_ports[0]) {
 757                 cli();
 758                 rs_interrupt(0);
 759                 sti();
 760 
 761                 timer_table[RS_TIMER].expires = jiffies + IRQ_timeout[0] - 2;
 762         }
 763 }
 764 
 765 /*
 766  * ---------------------------------------------------------------
 767  * Low level utility subroutines for the serial driver:  routines to
 768  * figure out the appropriate timeout for an interrupt chain, routines
 769  * to initialize and startup a serial port, and routines to shutdown a
 770  * serial port.  Useful stuff like that.
 771  * ---------------------------------------------------------------
 772  */
 773 
 774 /*
 775  * Grab all interrupts in preparation for doing an automatic irq
 776  * detection.  dontgrab is a mask of irq's _not_ to grab.  Returns a
 777  * mask of irq's which were grabbed and should therefore be freed
 778  * using free_all_interrupts().
 779  */
 780 static int grab_all_interrupts(int dontgrab)
     /* [previous][next][first][last][top][bottom][index][help] */
 781 {
 782         int                     irq_lines = 0;
 783         int                     i, mask;
 784         
 785         for (i = 0, mask = 1; i < 16; i++, mask <<= 1) {
 786                 if (!(mask & dontgrab) && !request_irq(i, rs_probe, SA_INTERRUPT, "serial probe")) {
 787                         irq_lines |= mask;
 788                 }
 789         }
 790         return irq_lines;
 791 }
 792 
 793 /*
 794  * Release all interrupts grabbed by grab_all_interrupts
 795  */
 796 static void free_all_interrupts(int irq_lines)
     /* [previous][next][first][last][top][bottom][index][help] */
 797 {
 798         int     i;
 799         
 800         for (i = 0; i < 16; i++) {
 801                 if (irq_lines & (1 << i))
 802                         free_irq(i);
 803         }
 804 }
 805 
 806 /*
 807  * This routine figures out the correct timeout for a particular IRQ.
 808  * It uses the smallest timeout of all of the serial ports in a
 809  * particular interrupt chain.  Now only used for IRQ 0....
 810  */
 811 static void figure_IRQ_timeout(int irq)
     /* [previous][next][first][last][top][bottom][index][help] */
 812 {
 813         struct  async_struct    *info;
 814         int     timeout = 6000; /* 60 seconds === a long time :-) */
 815 
 816         info = IRQ_ports[irq];
 817         if (!info) {
 818                 IRQ_timeout[irq] = 6000;
 819                 return;
 820         }
 821         while (info) {
 822                 if (info->timeout < timeout)
 823                         timeout = info->timeout;
 824                 info = info->next_port;
 825         }
 826         if (!irq)
 827                 timeout = timeout / 2;
 828         IRQ_timeout[irq] = timeout ? timeout : 1;
 829 }
 830 
 831 static int startup(struct async_struct * info)
     /* [previous][next][first][last][top][bottom][index][help] */
 832 {
 833         unsigned short ICP;
 834         unsigned long flags;
 835         int     retval;
 836         void (*handler)(int);
 837 
 838         if (info->flags & ASYNC_INITIALIZED)
 839                 return 0;
 840 
 841         if (!info->port || !info->type) {
 842                 if (info->tty)
 843                         set_bit(TTY_IO_ERROR, &info->tty->flags);
 844                 return 0;
 845         }
 846 
 847         if (!info->xmit_buf) {
 848                 info->xmit_buf = (unsigned char *) get_free_page(GFP_KERNEL);
 849                 if (!info->xmit_buf)
 850                         return -ENOMEM;
 851         }
 852 
 853         save_flags(flags); cli();
 854 
 855 #ifdef SERIAL_DEBUG_OPEN
 856         printk("starting up ttys%d (irq %d)...", info->line, info->irq);
 857 #endif
 858 
 859         /*
 860          * Clear the FIFO buffers and disable them
 861          * (they will be reenabled in change_speed())
 862          */
 863         if (info->type == PORT_16550A) {
 864                 serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
 865                                              UART_FCR_CLEAR_XMIT));
 866                 info->xmit_fifo_size = 16;
 867         } else
 868                 info->xmit_fifo_size = 1;
 869 
 870         /*
 871          * At this point there's no way the LSR could still be 0xFF;
 872          * if it is, then bail out, because there's likely no UART
 873          * here.
 874          */
 875         if (serial_inp(info, UART_LSR) == 0xff) {
 876                 restore_flags(flags);
 877                 if (suser()) {
 878                         if (info->tty)
 879                                 set_bit(TTY_IO_ERROR, &info->tty->flags);
 880                         return 0;
 881                 } else
 882                         return -ENODEV;
 883         }
 884         
 885         /*
 886          * Allocate the IRQ if necessary
 887          */
 888         if (info->irq && (!IRQ_ports[info->irq] ||
 889                           !IRQ_ports[info->irq]->next_port)) {
 890                 if (IRQ_ports[info->irq]) {
 891                         free_irq(info->irq);
 892                         handler = rs_interrupt;
 893                 } else 
 894                         handler = rs_interrupt_single;
 895 
 896                 retval = request_irq(info->irq, handler, SA_INTERRUPT, "serial");
 897                 if (retval) {
 898                         restore_flags(flags);
 899                         if (suser()) {
 900                                 if (info->tty)
 901                                         set_bit(TTY_IO_ERROR,
 902                                                 &info->tty->flags);
 903                                 return 0;
 904                         } else
 905                                 return retval;
 906                 }
 907         }
 908 
 909         /*
 910          * Clear the interrupt registers.
 911          */
 912      /* (void) serial_inp(info, UART_LSR); */   /* (see above) */
 913         (void) serial_inp(info, UART_RX);
 914         (void) serial_inp(info, UART_IIR);
 915         (void) serial_inp(info, UART_MSR);
 916 
 917         /*
 918          * Now, initialize the UART 
 919          */
 920         serial_outp(info, UART_LCR, UART_LCR_WLEN8);    /* reset DLAB */
 921         if (info->flags & ASYNC_FOURPORT) {
 922                 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
 923                 info->MCR_noint = UART_MCR_DTR | UART_MCR_OUT1;
 924         } else {
 925                 info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
 926                 info->MCR_noint = UART_MCR_DTR | UART_MCR_RTS;
 927         }
 928         if (info->irq == 0)
 929                 info->MCR = info->MCR_noint;
 930         serial_outp(info, UART_MCR, info->MCR);
 931         
 932         /*
 933          * Finally, enable interrupts
 934          */
 935         info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
 936         serial_outp(info, UART_IER, info->IER); /* enable interrupts */
 937         
 938         if (info->flags & ASYNC_FOURPORT) {
 939                 /* Enable interrupts on the AST Fourport board */
 940                 ICP = (info->port & 0xFE0) | 0x01F;
 941                 outb_p(0x80, ICP);
 942                 (void) inb_p(ICP);
 943         }
 944 
 945         /*
 946          * And clear the interrupt registers again for luck.
 947          */
 948         (void)serial_inp(info, UART_LSR);
 949         (void)serial_inp(info, UART_RX);
 950         (void)serial_inp(info, UART_IIR);
 951         (void)serial_inp(info, UART_MSR);
 952 
 953         if (info->tty)
 954                 clear_bit(TTY_IO_ERROR, &info->tty->flags);
 955         info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
 956 
 957         /*
 958          * Insert serial port into IRQ chain.
 959          */
 960         info->prev_port = 0;
 961         info->next_port = IRQ_ports[info->irq];
 962         if (info->next_port)
 963                 info->next_port->prev_port = info;
 964         IRQ_ports[info->irq] = info;
 965         figure_IRQ_timeout(info->irq);
 966 
 967         /*
 968          * Set up serial timers...
 969          */
 970         timer_table[RS_TIMER].expires = jiffies + 2;
 971         timer_active |= 1 << RS_TIMER;
 972 
 973         /*
 974          * and set the speed of the serial port
 975          */
 976         change_speed(info);
 977 
 978         info->flags |= ASYNC_INITIALIZED;
 979         restore_flags(flags);
 980         return 0;
 981 }
 982 
 983 /*
 984  * This routine will shutdown a serial port; interrupts are disabled, and
 985  * DTR is dropped if the hangup on close termio flag is on.
 986  */
 987 static void shutdown(struct async_struct * info)
     /* [previous][next][first][last][top][bottom][index][help] */
 988 {
 989         unsigned long   flags;
 990         unsigned long timeout;
 991         int             retval;
 992 
 993         if (!(info->flags & ASYNC_INITIALIZED))
 994                 return;
 995 
 996 #ifdef SERIAL_DEBUG_OPEN
 997         printk("Shutting down serial port %d (irq %d)....", info->line,
 998                info->irq);
 999 #endif
1000         
1001         save_flags(flags); cli(); /* Disable interrupts */
1002         
1003         /*
1004          * First unlink the serial port from the IRQ chain...
1005          */
1006         if (info->next_port)
1007                 info->next_port->prev_port = info->prev_port;
1008         if (info->prev_port)
1009                 info->prev_port->next_port = info->next_port;
1010         else
1011                 IRQ_ports[info->irq] = info->next_port;
1012         figure_IRQ_timeout(info->irq);
1013         
1014         /*
1015          * Free the IRQ, if necessary
1016          */
1017         if (info->irq && (!IRQ_ports[info->irq] ||
1018                           !IRQ_ports[info->irq]->next_port)) {
1019                 if (IRQ_ports[info->irq]) {
1020                         free_irq(info->irq);
1021                         retval = request_irq(info->irq, rs_interrupt_single, SA_INTERRUPT, "serial");
1022                         
1023                         if (retval)
1024                                 printk("serial shutdown: request_irq: error %d"
1025                                        "  Couldn't reacquire IRQ.\n", retval);
1026                 } else
1027                         free_irq(info->irq);
1028         }
1029 
1030         if (info->xmit_buf) {
1031                 free_page((unsigned long) info->xmit_buf);
1032                 info->xmit_buf = 0;
1033         }
1034 
1035         info->IER = 0;
1036         serial_outp(info, UART_IER, 0x00);      /* disable all intrs */
1037         if (info->flags & ASYNC_FOURPORT) {
1038                 /* reset interrupts on the AST Fourport board */
1039                 (void) inb((info->port & 0xFE0) | 0x01F);
1040         }
1041         
1042         /*
1043          * Before we drop DTR, make sure the UART transmitter has
1044          * completely drained; this is especially important if there
1045          * is a transmit FIFO!
1046          * 
1047          * We busy loop here, which is not great; unfortunately the
1048          * UART does not provide an interrupt for TEMT, and putting it
1049          * in the interrupt handler would slow down normal accesses
1050          * anyway.
1051          */
1052         sti();
1053         timeout = jiffies + info->timeout;
1054         while (!(serial_inp(info, UART_LSR) & UART_LSR_TEMT)) {
1055                 if (jiffies > timeout)
1056                         break;
1057         }
1058         cli();
1059         
1060         if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
1061                 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1062                 info->MCR_noint &= ~(UART_MCR_DTR|UART_MCR_RTS);
1063         }
1064         serial_outp(info, UART_MCR, info->MCR_noint);
1065 
1066         /* disable FIFO's */    
1067         serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
1068                                      UART_FCR_CLEAR_XMIT));
1069         (void)serial_in(info, UART_RX);    /* read data port to reset things */
1070         
1071         if (info->tty)
1072                 set_bit(TTY_IO_ERROR, &info->tty->flags);
1073         
1074         info->flags &= ~ASYNC_INITIALIZED;
1075         restore_flags(flags);
1076 }
1077 
1078 /*
1079  * This routine is called to set the UART divisor registers to match
1080  * the specified baud rate for a serial port.
1081  */
1082 static void change_speed(struct async_struct *info)
     /* [previous][next][first][last][top][bottom][index][help] */
1083 {
1084         unsigned short port;
1085         int     quot = 0;
1086         unsigned cflag,cval,fcr;
1087         int     i;
1088 
1089         if (!info->tty || !info->tty->termios)
1090                 return;
1091         cflag = info->tty->termios->c_cflag;
1092         if (!(port = info->port))
1093                 return;
1094         i = cflag & CBAUD;
1095         if (i == 15) {
1096                 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1097                         i += 1;
1098                 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1099                         i += 2;
1100                 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
1101                         quot = info->custom_divisor;
1102         }
1103         if (quot) {
1104                 info->timeout = ((info->xmit_fifo_size*HZ*15*quot) /
1105                                  info->baud_base) + 2;
1106         } else if (baud_table[i] == 134) {
1107                 quot = (2*info->baud_base / 269);
1108                 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
1109         } else if (baud_table[i]) {
1110                 quot = info->baud_base / baud_table[i];
1111                 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
1112         } else {
1113                 quot = 0;
1114                 info->timeout = 0;
1115         }
1116         if (quot) {
1117                 info->MCR |= UART_MCR_DTR;
1118                 info->MCR_noint |= UART_MCR_DTR;
1119                 cli();
1120                 serial_out(info, UART_MCR, info->MCR);
1121                 sti();
1122         } else {
1123                 info->MCR &= ~UART_MCR_DTR;
1124                 info->MCR_noint &= ~UART_MCR_DTR;
1125                 cli();
1126                 serial_out(info, UART_MCR, info->MCR);
1127                 sti();
1128                 return;
1129         }
1130         /* byte size and parity */
1131         cval = cflag & (CSIZE | CSTOPB);
1132         cval >>= 4;
1133         if (cflag & PARENB)
1134                 cval |= UART_LCR_PARITY;
1135         if (!(cflag & PARODD))
1136                 cval |= UART_LCR_EPAR;
1137         if (info->type == PORT_16550A) {
1138                 if ((info->baud_base / quot) < 2400)
1139                         fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
1140                 else
1141                         fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;
1142         } else
1143                 fcr = 0;
1144         
1145         /* CTS flow control flag */
1146         if (cflag & CRTSCTS)
1147                 info->flags |= ASYNC_CTS_FLOW;
1148         else
1149                 info->flags &= ~ASYNC_CTS_FLOW;
1150         if (cflag & CLOCAL)
1151                 info->flags &= ~ASYNC_CHECK_CD;
1152         else
1153                 info->flags |= ASYNC_CHECK_CD;
1154 
1155         /*
1156          * Set up parity check flag
1157          */
1158         info->read_status_mask = UART_LSR_OE;
1159         if (I_INPCK(info->tty))
1160                 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1161         if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
1162                 info->read_status_mask |= UART_LSR_BI;
1163         
1164         info->ignore_status_mask = 0;
1165         if (I_IGNPAR(info->tty))
1166                 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
1167         if (I_IGNBRK(info->tty)) {
1168                 info->ignore_status_mask |= UART_LSR_BI;
1169                 /*
1170                  * If we're ignore parity and break indicators, ignore 
1171                  * overruns too.  (For real raw support).
1172                  */
1173                 if (I_IGNPAR(info->tty))
1174                         info->ignore_status_mask |= UART_LSR_OE;
1175         }
1176         
1177         cli();
1178         serial_outp(info, UART_LCR, cval | UART_LCR_DLAB);      /* set DLAB */
1179         serial_outp(info, UART_DLL, quot & 0xff);       /* LS of divisor */
1180         serial_outp(info, UART_DLM, quot >> 8);         /* MS of divisor */
1181         serial_outp(info, UART_LCR, cval);              /* reset DLAB */
1182         serial_outp(info, UART_FCR, fcr);       /* set fcr */
1183         sti();
1184 }
1185 
1186 static void rs_put_char(struct tty_struct *tty, unsigned char ch)
     /* [previous][next][first][last][top][bottom][index][help] */
1187 {
1188         struct async_struct *info = (struct async_struct *)tty->driver_data;
1189         unsigned long flags;
1190 
1191         if (serial_paranoia_check(info, tty->device, "rs_put_char"))
1192                 return;
1193 
1194         if (!tty || !info->xmit_buf)
1195                 return;
1196 
1197         save_flags(flags); cli();
1198         if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1199                 restore_flags(flags);
1200                 return;
1201         }
1202 
1203         info->xmit_buf[info->xmit_head++] = ch;
1204         info->xmit_head &= SERIAL_XMIT_SIZE-1;
1205         info->xmit_cnt++;
1206         restore_flags(flags);
1207 }
1208 
1209 static void rs_flush_chars(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1210 {
1211         struct async_struct *info = (struct async_struct *)tty->driver_data;
1212         unsigned long flags;
1213                                 
1214         if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))
1215                 return;
1216 
1217         if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1218             !info->xmit_buf)
1219                 return;
1220 
1221         save_flags(flags); cli();
1222         info->IER |= UART_IER_THRI;
1223         serial_out(info, UART_IER, info->IER);
1224         restore_flags(flags);
1225 }
1226 
1227 static int rs_write(struct tty_struct * tty, int from_user,
     /* [previous][next][first][last][top][bottom][index][help] */
1228                     unsigned char *buf, int count)
1229 {
1230         int     c, total = 0;
1231         struct async_struct *info = (struct async_struct *)tty->driver_data;
1232         unsigned long flags;
1233                                 
1234         if (serial_paranoia_check(info, tty->device, "rs_write"))
1235                 return 0;
1236 
1237         if (!tty || !info->xmit_buf || !tmp_buf)
1238                 return 0;
1239             
1240         save_flags(flags);
1241         while (1) {
1242                 cli();          
1243                 c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1244                                    SERIAL_XMIT_SIZE - info->xmit_head));
1245                 if (c <= 0)
1246                         break;
1247 
1248                 if (from_user) {
1249                         down(&tmp_buf_sem);
1250                         memcpy_fromfs(tmp_buf, buf, c);
1251                         c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1252                                        SERIAL_XMIT_SIZE - info->xmit_head));
1253                         memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
1254                         up(&tmp_buf_sem);
1255                 } else
1256                         memcpy(info->xmit_buf + info->xmit_head, buf, c);
1257                 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1258                 info->xmit_cnt += c;
1259                 restore_flags(flags);
1260                 buf += c;
1261                 count -= c;
1262                 total += c;
1263         }
1264         if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1265             !(info->IER & UART_IER_THRI)) {
1266                 info->IER |= UART_IER_THRI;
1267                 serial_out(info, UART_IER, info->IER);
1268         }
1269         restore_flags(flags);
1270         return total;
1271 }
1272 
1273 static int rs_write_room(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1274 {
1275         struct async_struct *info = (struct async_struct *)tty->driver_data;
1276         int     ret;
1277                                 
1278         if (serial_paranoia_check(info, tty->device, "rs_write_room"))
1279                 return 0;
1280         ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1281         if (ret < 0)
1282                 ret = 0;
1283         return ret;
1284 }
1285 
1286 static int rs_chars_in_buffer(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1287 {
1288         struct async_struct *info = (struct async_struct *)tty->driver_data;
1289                                 
1290         if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
1291                 return 0;
1292         return info->xmit_cnt;
1293 }
1294 
1295 static void rs_flush_buffer(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1296 {
1297         struct async_struct *info = (struct async_struct *)tty->driver_data;
1298                                 
1299         if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
1300                 return;
1301         cli();
1302         info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1303         sti();
1304         wake_up_interruptible(&tty->write_wait);
1305         if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1306             tty->ldisc.write_wakeup)
1307                 (tty->ldisc.write_wakeup)(tty);
1308 }
1309 
1310 /*
1311  * ------------------------------------------------------------
1312  * rs_throttle()
1313  * 
1314  * This routine is called by the upper-layer tty layer to signal that
1315  * incoming characters should be throttled.
1316  * ------------------------------------------------------------
1317  */
1318 static void rs_throttle(struct tty_struct * tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1319 {
1320         struct async_struct *info = (struct async_struct *)tty->driver_data;
1321 #ifdef SERIAL_DEBUG_THROTTLE
1322         char    buf[64];
1323         
1324         printk("throttle %s: %d....\n", _tty_name(tty, buf),
1325                tty->ldisc.chars_in_buffer(tty));
1326 #endif
1327 
1328         if (serial_paranoia_check(info, tty->device, "rs_throttle"))
1329                 return;
1330         
1331         if (I_IXOFF(tty))
1332                 info->x_char = STOP_CHAR(tty);
1333 
1334         info->MCR &= ~UART_MCR_RTS;
1335         info->MCR_noint &= ~UART_MCR_RTS;
1336         cli();
1337         serial_out(info, UART_MCR, info->MCR);
1338         sti();
1339 }
1340 
1341 static void rs_unthrottle(struct tty_struct * tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1342 {
1343         struct async_struct *info = (struct async_struct *)tty->driver_data;
1344 #ifdef SERIAL_DEBUG_THROTTLE
1345         char    buf[64];
1346         
1347         printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1348                tty->ldisc.chars_in_buffer(tty));
1349 #endif
1350 
1351         if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
1352                 return;
1353         
1354         if (I_IXOFF(tty)) {
1355                 if (info->x_char)
1356                         info->x_char = 0;
1357                 else
1358                         info->x_char = START_CHAR(tty);
1359         }
1360         info->MCR |= UART_MCR_RTS;
1361         info->MCR_noint |= UART_MCR_RTS;
1362         cli();
1363         serial_out(info, UART_MCR, info->MCR);
1364         sti();
1365 }
1366 
1367 /*
1368  * ------------------------------------------------------------
1369  * rs_ioctl() and friends
1370  * ------------------------------------------------------------
1371  */
1372 
1373 static int get_serial_info(struct async_struct * info,
     /* [previous][next][first][last][top][bottom][index][help] */
1374                            struct serial_struct * retinfo)
1375 {
1376         struct serial_struct tmp;
1377   
1378         if (!retinfo)
1379                 return -EFAULT;
1380         memset(&tmp, 0, sizeof(tmp));
1381         tmp.type = info->type;
1382         tmp.line = info->line;
1383         tmp.port = info->port;
1384         tmp.irq = info->irq;
1385         tmp.flags = info->flags;
1386         tmp.baud_base = info->baud_base;
1387         tmp.close_delay = info->close_delay;
1388         tmp.custom_divisor = info->custom_divisor;
1389         tmp.hub6 = info->hub6;
1390         memcpy_tofs(retinfo,&tmp,sizeof(*retinfo));
1391         return 0;
1392 }
1393 
1394 static int set_serial_info(struct async_struct * info,
     /* [previous][next][first][last][top][bottom][index][help] */
1395                            struct serial_struct * new_info)
1396 {
1397         struct serial_struct new_serial;
1398         struct async_struct old_info;
1399         unsigned int            i,change_irq,change_port;
1400         int                     retval = 0;
1401 
1402         if (!new_info)
1403                 return -EFAULT;
1404         memcpy_fromfs(&new_serial,new_info,sizeof(new_serial));
1405         old_info = *info;
1406 
1407         change_irq = new_serial.irq != info->irq;
1408         change_port = (new_serial.port != info->port) || (new_serial.hub6 != info->hub6);
1409 
1410         if (!suser()) {
1411                 if (change_irq || change_port ||
1412                     (new_serial.baud_base != info->baud_base) ||
1413                     (new_serial.type != info->type) ||
1414                     (new_serial.close_delay != info->close_delay) ||
1415                     ((new_serial.flags & ~ASYNC_USR_MASK) !=
1416                      (info->flags & ~ASYNC_USR_MASK)))
1417                         return -EPERM;
1418                 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1419                                (new_serial.flags & ASYNC_USR_MASK));
1420                 info->custom_divisor = new_serial.custom_divisor;
1421                 goto check_and_exit;
1422         }
1423 
1424         if (new_serial.irq == 2)
1425                 new_serial.irq = 9;
1426 
1427         if ((new_serial.irq > 15) || (new_serial.port > 0xffff) ||
1428             (new_serial.type < PORT_UNKNOWN) || (new_serial.type > PORT_MAX)) {
1429                 return -EINVAL;
1430         }
1431 
1432         /* Make sure address is not already in use */
1433         if (new_serial.type) {
1434                 for (i = 0 ; i < NR_PORTS; i++)
1435                         if ((info != &rs_table[i]) &&
1436                             (rs_table[i].port == new_serial.port) &&
1437                             rs_table[i].type)
1438                                 return -EADDRINUSE;
1439         }
1440 
1441         if ((change_port || change_irq) && (info->count > 1))
1442                 return -EBUSY;
1443 
1444         /*
1445          * OK, past this point, all the error checking has been done.
1446          * At this point, we start making changes.....
1447          */
1448 
1449         info->baud_base = new_serial.baud_base;
1450         info->flags = ((info->flags & ~ASYNC_FLAGS) |
1451                         (new_serial.flags & ASYNC_FLAGS));
1452         info->custom_divisor = new_serial.custom_divisor;
1453         info->type = new_serial.type;
1454         info->close_delay = new_serial.close_delay;
1455 
1456         if (change_port || change_irq) {
1457                 /*
1458                  * We need to shutdown the serial port at the old
1459                  * port/irq combination.
1460                  */
1461                 shutdown(info);
1462                 info->irq = new_serial.irq;
1463                 info->port = new_serial.port;
1464                 info->hub6 = new_serial.hub6;
1465         }
1466         
1467 check_and_exit:
1468         if (!info->port || !info->type)
1469                 return 0;
1470         if (info->flags & ASYNC_INITIALIZED) {
1471                 if (((old_info.flags & ASYNC_SPD_MASK) !=
1472                      (info->flags & ASYNC_SPD_MASK)) ||
1473                     (old_info.custom_divisor != info->custom_divisor))
1474                         change_speed(info);
1475         } else
1476                 retval = startup(info);
1477         return retval;
1478 }
1479 
1480 static int get_modem_info(struct async_struct * info, unsigned int *value)
     /* [previous][next][first][last][top][bottom][index][help] */
1481 {
1482         unsigned char control, status;
1483         unsigned int result;
1484 
1485         control = info->MCR;
1486         cli();
1487         status = serial_in(info, UART_MSR);
1488         sti();
1489         result =  ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1490                 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1491                 | ((status  & UART_MSR_DCD) ? TIOCM_CAR : 0)
1492                 | ((status  & UART_MSR_RI) ? TIOCM_RNG : 0)
1493                 | ((status  & UART_MSR_DSR) ? TIOCM_DSR : 0)
1494                 | ((status  & UART_MSR_CTS) ? TIOCM_CTS : 0);
1495         put_fs_long(result,(unsigned long *) value);
1496         return 0;
1497 }
1498 
1499 static int set_modem_info(struct async_struct * info, unsigned int cmd,
     /* [previous][next][first][last][top][bottom][index][help] */
1500                           unsigned int *value)
1501 {
1502         unsigned int arg = get_fs_long((unsigned long *) value);
1503 
1504         switch (cmd) {
1505         case TIOCMBIS: 
1506                 if (arg & TIOCM_RTS) {
1507                         info->MCR |= UART_MCR_RTS;
1508                         info->MCR_noint |= UART_MCR_RTS;
1509                 }
1510                 if (arg & TIOCM_DTR) {
1511                         info->MCR |= UART_MCR_DTR;
1512                         info->MCR_noint |= UART_MCR_DTR;
1513                 }
1514                 break;
1515         case TIOCMBIC:
1516                 if (arg & TIOCM_RTS) {
1517                         info->MCR &= ~UART_MCR_RTS;
1518                         info->MCR_noint &= ~UART_MCR_RTS;
1519                 }
1520                 if (arg & TIOCM_DTR) {
1521                         info->MCR &= ~UART_MCR_DTR;
1522                         info->MCR_noint &= ~UART_MCR_DTR;
1523                 }
1524                 break;
1525         case TIOCMSET:
1526                 info->MCR = ((info->MCR & ~(UART_MCR_RTS | UART_MCR_DTR))
1527                              | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1528                              | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1529                 info->MCR_noint = ((info->MCR_noint
1530                                     & ~(UART_MCR_RTS | UART_MCR_DTR))
1531                                    | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1532                                    | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1533                 break;
1534         default:
1535                 return -EINVAL;
1536         }
1537         cli();
1538         serial_out(info, UART_MCR, info->MCR);
1539         sti();
1540         return 0;
1541 }
1542 
1543 static int do_autoconfig(struct async_struct * info)
     /* [previous][next][first][last][top][bottom][index][help] */
1544 {
1545         int                     retval;
1546         
1547         if (!suser())
1548                 return -EPERM;
1549         
1550         if (info->count > 1)
1551                 return -EBUSY;
1552         
1553         shutdown(info);
1554 
1555         cli();
1556         autoconfig(info);
1557         sti();
1558 
1559         retval = startup(info);
1560         if (retval)
1561                 return retval;
1562         return 0;
1563 }
1564 
1565 
1566 /*
1567  * This routine sends a break character out the serial port.
1568  */
1569 static void send_break( struct async_struct * info, int duration)
     /* [previous][next][first][last][top][bottom][index][help] */
1570 {
1571         if (!info->port)
1572                 return;
1573         current->state = TASK_INTERRUPTIBLE;
1574         current->timeout = jiffies + duration;
1575         cli();
1576         serial_out(info, UART_LCR, serial_inp(info, UART_LCR) | UART_LCR_SBC);
1577         schedule();
1578         serial_out(info, UART_LCR, serial_inp(info, UART_LCR) & ~UART_LCR_SBC);
1579         sti();
1580 }
1581 
1582 /*
1583  * This routine returns a bitfield of "wild interrupts".  Basically,
1584  * any unclaimed interrupts which is flapping around.
1585  */
1586 static int check_wild_interrupts(int doprint)
     /* [previous][next][first][last][top][bottom][index][help] */
1587 {
1588         int     i, mask;
1589         int     wild_interrupts = 0;
1590         int     irq_lines;
1591         unsigned long timeout;
1592         unsigned long flags;
1593         
1594         /* Turn on interrupts (they may be off) */
1595         save_flags(flags); sti();
1596 
1597         irq_lines = grab_all_interrupts(0);
1598         
1599         /*
1600          * Delay for 0.1 seconds -- we use a busy loop since this may 
1601          * occur during the bootup sequence
1602          */
1603         timeout = jiffies+10;
1604         while (timeout >= jiffies)
1605                 ;
1606         
1607         rs_triggered = 0;       /* Reset after letting things settle */
1608 
1609         timeout = jiffies+10;
1610         while (timeout >= jiffies)
1611                 ;
1612         
1613         for (i = 0, mask = 1; i < 16; i++, mask <<= 1) {
1614                 if ((rs_triggered & (1 << i)) &&
1615                     (irq_lines & (1 << i))) {
1616                         wild_interrupts |= mask;
1617                         if (doprint)
1618                                 printk("Wild interrupt?  (IRQ %d)\n", i);
1619                 }
1620         }
1621         free_all_interrupts(irq_lines);
1622         restore_flags(flags);
1623         return wild_interrupts;
1624 }
1625 
1626 static int rs_ioctl(struct tty_struct *tty, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
1627                     unsigned int cmd, unsigned long arg)
1628 {
1629         int error;
1630         struct async_struct * info = (struct async_struct *)tty->driver_data;
1631         int retval;
1632 
1633         if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
1634                 return -ENODEV;
1635         
1636         switch (cmd) {
1637                 case TCSBRK:    /* SVID version: non-zero arg --> no break */
1638                         retval = tty_check_change(tty);
1639                         if (retval)
1640                                 return retval;
1641                         wait_until_sent(tty, 0);
1642                         if (!arg)
1643                                 send_break(info, HZ/4); /* 1/4 second */
1644                         return 0;
1645                 case TCSBRKP:   /* support for POSIX tcsendbreak() */
1646                         retval = tty_check_change(tty);
1647                         if (retval)
1648                                 return retval;
1649                         wait_until_sent(tty, 0);
1650                         send_break(info, arg ? arg*(HZ/10) : HZ/4);
1651                         return 0;
1652                 case TIOCGSOFTCAR:
1653                         error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
1654                         if (error)
1655                                 return error;
1656                         put_fs_long(C_CLOCAL(tty) ? 1 : 0,
1657                                     (unsigned long *) arg);
1658                         return 0;
1659                 case TIOCSSOFTCAR:
1660                         arg = get_fs_long((unsigned long *) arg);
1661                         tty->termios->c_cflag =
1662                                 ((tty->termios->c_cflag & ~CLOCAL) |
1663                                  (arg ? CLOCAL : 0));
1664                         return 0;
1665                 case TIOCMGET:
1666                         error = verify_area(VERIFY_WRITE, (void *) arg,
1667                                 sizeof(unsigned int));
1668                         if (error)
1669                                 return error;
1670                         return get_modem_info(info, (unsigned int *) arg);
1671                 case TIOCMBIS:
1672                 case TIOCMBIC:
1673                 case TIOCMSET:
1674                         return set_modem_info(info, cmd, (unsigned int *) arg);
1675                 case TIOCGSERIAL:
1676                         error = verify_area(VERIFY_WRITE, (void *) arg,
1677                                                 sizeof(struct serial_struct));
1678                         if (error)
1679                                 return error;
1680                         return get_serial_info(info,
1681                                                (struct serial_struct *) arg);
1682                 case TIOCSSERIAL:
1683                         return set_serial_info(info,
1684                                                (struct serial_struct *) arg);
1685                 case TIOCSERCONFIG:
1686                         return do_autoconfig(info);
1687 
1688                 case TIOCSERGWILD:
1689                         error = verify_area(VERIFY_WRITE, (void *) arg,
1690                                             sizeof(int));
1691                         if (error)
1692                                 return error;
1693                         put_fs_long(rs_wild_int_mask, (unsigned long *) arg);
1694                         return 0;
1695 
1696                 case TIOCSERSWILD:
1697                         if (!suser())
1698                                 return -EPERM;
1699                         rs_wild_int_mask = get_fs_long((unsigned long *) arg);
1700                         if (rs_wild_int_mask < 0)
1701                                 rs_wild_int_mask = check_wild_interrupts(0);
1702                         return 0;
1703 
1704                 case TIOCSERGSTRUCT:
1705                         error = verify_area(VERIFY_WRITE, (void *) arg,
1706                                                 sizeof(struct async_struct));
1707                         if (error)
1708                                 return error;
1709                         memcpy_tofs((struct async_struct *) arg,
1710                                     info, sizeof(struct async_struct));
1711                         return 0;
1712                         
1713                 default:
1714                         return -ENOIOCTLCMD;
1715                 }
1716         return 0;
1717 }
1718 
1719 static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
     /* [previous][next][first][last][top][bottom][index][help] */
1720 {
1721         struct async_struct *info = (struct async_struct *)tty->driver_data;
1722 
1723         if (tty->termios->c_cflag == old_termios->c_cflag)
1724                 return;
1725 
1726         change_speed(info);
1727 
1728         if ((old_termios->c_cflag & CRTSCTS) &&
1729             !(tty->termios->c_cflag & CRTSCTS)) {
1730                 tty->hw_stopped = 0;
1731                 rs_start(tty);
1732         }
1733 
1734         if (!(old_termios->c_cflag & CLOCAL) &&
1735             (tty->termios->c_cflag & CLOCAL))
1736                 wake_up_interruptible(&info->open_wait);
1737 }
1738 
1739 /*
1740  * ------------------------------------------------------------
1741  * rs_close()
1742  * 
1743  * This routine is called when the serial port gets closed.  First, we
1744  * wait for the last remaining data to be sent.  Then, we unlink its
1745  * async structure from the interrupt chain if necessary, and we free
1746  * that IRQ if nothing is left in the chain.
1747  * ------------------------------------------------------------
1748  */
1749 static void rs_close(struct tty_struct *tty, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
1750 {
1751         struct async_struct * info = (struct async_struct *)tty->driver_data;
1752 
1753         if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
1754                 return;
1755         
1756         if (tty_hung_up_p(filp))
1757                 return;
1758         
1759 #ifdef SERIAL_DEBUG_OPEN
1760         printk("rs_close ttys%d, count = %d\n", info->line, info->count);
1761 #endif
1762         if ((tty->count == 1) && (info->count != 1)) {
1763                 /*
1764                  * Uh, oh.  tty->count is 1, which means that the tty
1765                  * structure will be freed.  Info->count should always
1766                  * be one in these conditions.  If it's greater than
1767                  * one, we've got real problems, since it means the
1768                  * serial port won't be shutdown.
1769                  */
1770                 printk("rs_close: bad serial port count; tty->count is 1, "
1771                        "info->count is %d\n", info->count);
1772                 info->count = 1;
1773         }
1774         if (--info->count < 0) {
1775                 printk("rs_close: bad serial port count for ttys%d: %d\n",
1776                        info->line, info->count);
1777                 info->count = 0;
1778         }
1779         if (info->count)
1780                 return;
1781         info->flags |= ASYNC_CLOSING;
1782         /*
1783          * Save the termios structure, since this port may have
1784          * separate termios for callout and dialin.
1785          */
1786         if (info->flags & ASYNC_NORMAL_ACTIVE)
1787                 info->normal_termios = *tty->termios;
1788         if (info->flags & ASYNC_CALLOUT_ACTIVE)
1789                 info->callout_termios = *tty->termios;
1790         if (info->flags & ASYNC_INITIALIZED)
1791                 wait_until_sent(tty, 3000); /* 30 seconds timeout */
1792         shutdown(info);
1793         if (tty->driver.flush_buffer)
1794                 tty->driver.flush_buffer(tty);
1795         if (tty->ldisc.flush_buffer)
1796                 tty->ldisc.flush_buffer(tty);
1797         info->event = 0;
1798         info->tty = 0;
1799         if (tty->ldisc.num != ldiscs[N_TTY].num) {
1800                 if (tty->ldisc.close)
1801                         (tty->ldisc.close)(tty);
1802                 tty->ldisc = ldiscs[N_TTY];
1803                 tty->termios->c_line = N_TTY;
1804                 if (tty->ldisc.open)
1805                         (tty->ldisc.open)(tty);
1806         }
1807         if (info->blocked_open) {
1808                 if (info->close_delay) {
1809                         current->state = TASK_INTERRUPTIBLE;
1810                         current->timeout = jiffies + info->close_delay;
1811                         schedule();
1812                 }
1813                 wake_up_interruptible(&info->open_wait);
1814         }
1815         info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
1816                          ASYNC_CLOSING);
1817         wake_up_interruptible(&info->close_wait);
1818 }
1819 
1820 /*
1821  * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1822  */
1823 void rs_hangup(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1824 {
1825         struct async_struct * info = (struct async_struct *)tty->driver_data;
1826         
1827         if (serial_paranoia_check(info, tty->device, "rs_hangup"))
1828                 return;
1829         
1830         shutdown(info);
1831         info->event = 0;
1832         info->count = 0;
1833         info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
1834         info->tty = 0;
1835         wake_up_interruptible(&info->open_wait);
1836 }
1837 
1838 /*
1839  * ------------------------------------------------------------
1840  * rs_open() and friends
1841  * ------------------------------------------------------------
1842  */
1843 static int block_til_ready(struct tty_struct *tty, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
1844                            struct async_struct *info)
1845 {
1846         struct wait_queue wait = { current, NULL };
1847         int             retval;
1848         int             do_clocal = C_CLOCAL(tty);
1849 
1850         /*
1851          * If the device is in the middle of being closed, then block
1852          * until it's done, and then try again.
1853          */
1854         if (info->flags & ASYNC_CLOSING) {
1855                 interruptible_sleep_on(&info->close_wait);
1856 #ifdef SERIAL_DO_RESTART
1857                 if (info->flags & ASYNC_HUP_NOTIFY)
1858                         return -EAGAIN;
1859                 else
1860                         return -ERESTARTSYS;
1861 #else
1862                 return -EAGAIN;
1863 #endif
1864         }
1865 
1866         /*
1867          * If this is a callout device, then just make sure the normal
1868          * device isn't being used.
1869          */
1870         if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
1871                 if (info->flags & ASYNC_NORMAL_ACTIVE)
1872                         return -EBUSY;
1873                 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1874                     (info->flags & ASYNC_SESSION_LOCKOUT) &&
1875                     (info->session != current->session))
1876                     return -EBUSY;
1877                 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1878                     (info->flags & ASYNC_PGRP_LOCKOUT) &&
1879                     (info->pgrp != current->pgrp))
1880                     return -EBUSY;
1881                 info->flags |= ASYNC_CALLOUT_ACTIVE;
1882                 return 0;
1883         }
1884         
1885         /*
1886          * If non-blocking mode is set, then make the check up front
1887          * and then exit.
1888          */
1889         if (filp->f_flags & O_NONBLOCK) {
1890                 if (info->flags & ASYNC_CALLOUT_ACTIVE)
1891                         return -EBUSY;
1892                 info->flags |= ASYNC_NORMAL_ACTIVE;
1893                 return 0;
1894         }
1895 
1896         /*
1897          * Block waiting for the carrier detect and the line to become
1898          * free (i.e., not in use by the callout).  While we are in
1899          * this loop, info->count is dropped by one, so that
1900          * rs_close() knows when to free things.  We restore it upon
1901          * exit, either normal or abnormal.
1902          */
1903         retval = 0;
1904         add_wait_queue(&info->open_wait, &wait);
1905 #ifdef SERIAL_DEBUG_OPEN
1906         printk("block_til_ready before block: ttys%d, count = %d\n",
1907                info->line, info->count);
1908 #endif
1909         info->count--;
1910         info->blocked_open++;
1911         while (1) {
1912                 cli();
1913                 if (!(info->flags & ASYNC_CALLOUT_ACTIVE))
1914                         serial_out(info, UART_MCR,
1915                                    serial_inp(info, UART_MCR) |
1916                                    (UART_MCR_DTR | UART_MCR_RTS));
1917                 sti();
1918                 current->state = TASK_INTERRUPTIBLE;
1919                 if (tty_hung_up_p(filp) ||
1920                     !(info->flags & ASYNC_INITIALIZED)) {
1921 #ifdef SERIAL_DO_RESTART
1922                         if (info->flags & ASYNC_HUP_NOTIFY)
1923                                 retval = -EAGAIN;
1924                         else
1925                                 retval = -ERESTARTSYS;  
1926 #else
1927                         retval = -EAGAIN;
1928 #endif
1929                         break;
1930                 }
1931                 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
1932                     !(info->flags & ASYNC_CLOSING) &&
1933                     (do_clocal || (serial_in(info, UART_MSR) &
1934                                    UART_MSR_DCD)))
1935                         break;
1936                 if (current->signal & ~current->blocked) {
1937                         retval = -ERESTARTSYS;
1938                         break;
1939                 }
1940 #ifdef SERIAL_DEBUG_OPEN
1941                 printk("block_til_ready blocking: ttys%d, count = %d\n",
1942                        info->line, info->count);
1943 #endif
1944                 schedule();
1945         }
1946         current->state = TASK_RUNNING;
1947         remove_wait_queue(&info->open_wait, &wait);
1948         if (!tty_hung_up_p(filp))
1949                 info->count++;
1950         info->blocked_open--;
1951 #ifdef SERIAL_DEBUG_OPEN
1952         printk("block_til_ready after blocking: ttys%d, count = %d\n",
1953                info->line, info->count);
1954 #endif
1955         if (retval)
1956                 return retval;
1957         info->flags |= ASYNC_NORMAL_ACTIVE;
1958         return 0;
1959 }       
1960 
1961 /*
1962  * This routine is called whenever a serial port is opened.  It
1963  * enables interrupts for a serial port, linking in its async structure into
1964  * the IRQ chain.   It also performs the serial-specific
1965  * initialization for the tty structure.
1966  */
1967 int rs_open(struct tty_struct *tty, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
1968 {
1969         struct async_struct     *info;
1970         int                     retval, line;
1971 
1972         line = MINOR(tty->device) - tty->driver.minor_start;
1973         if ((line < 0) || (line >= NR_PORTS))
1974                 return -ENODEV;
1975         info = rs_table + line;
1976         if (serial_paranoia_check(info, tty->device, "rs_open"))
1977                 return -ENODEV;
1978 
1979 #ifdef SERIAL_DEBUG_OPEN
1980         printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
1981                info->count);
1982 #endif
1983         info->count++;
1984         tty->driver_data = info;
1985         info->tty = tty;
1986 
1987         if (!tmp_buf) {
1988                 tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
1989                 if (!tmp_buf)
1990                         return -ENOMEM;
1991         }
1992         
1993         if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
1994                 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
1995                         *tty->termios = info->normal_termios;
1996                 else 
1997                         *tty->termios = info->callout_termios;
1998         }
1999         /*
2000          * Start up serial port
2001          */
2002         retval = startup(info);
2003         if (retval)
2004                 return retval;
2005 
2006         retval = block_til_ready(tty, filp, info);
2007         if (retval) {
2008 #ifdef SERIAL_DEBUG_OPEN
2009                 printk("rs_open returning after block_til_ready with %d\n",
2010                        retval);
2011 #endif
2012                 return retval;
2013         }
2014 
2015         info->session = current->session;
2016         info->pgrp = current->pgrp;
2017 
2018 #ifdef SERIAL_DEBUG_OPEN
2019         printk("rs_open ttys%d successful...", info->line);
2020 #endif
2021         return 0;
2022 }
2023 
2024 /*
2025  * ---------------------------------------------------------------------
2026  * rs_init() and friends
2027  *
2028  * rs_init() is called at boot-time to initialize the serial driver.
2029  * ---------------------------------------------------------------------
2030  */
2031 
2032 /*
2033  * This routine prints out the appropriate serial driver version
2034  * number, and identifies which options were configured into this
2035  * driver.
2036  */
2037 static void show_serial_version(void)
     /* [previous][next][first][last][top][bottom][index][help] */
2038 {
2039         printk("Serial driver version 4.00 with");
2040 #ifdef CONFIG_HUB6
2041         printk(" HUB-6");
2042 #define SERIAL_OPT
2043 #endif
2044 #ifdef SERIAL_OPT
2045         printk(" enabled\n");
2046 #else
2047         printk(" no serial options enabled\n");
2048 #endif
2049 #undef SERIAL_OPT
2050 }
2051 
2052 /*
2053  * This routine is called by do_auto_irq(); it attempts to determine
2054  * which interrupt a serial port is configured to use.  It is not
2055  * fool-proof, but it works a large part of the time.
2056  */
2057 static int get_auto_irq(struct async_struct *info)
     /* [previous][next][first][last][top][bottom][index][help] */
2058 {
2059         unsigned char save_MCR, save_IER, save_ICP=0;
2060         unsigned short ICP=0, port = info->port;
2061         unsigned long timeout;
2062         
2063         /*
2064          * Enable interrupts and see who answers
2065          */
2066         rs_irq_triggered = 0;
2067         cli();
2068         save_IER = serial_inp(info, UART_IER);
2069         save_MCR = serial_inp(info, UART_MCR);
2070         if (info->flags & ASYNC_FOURPORT)  {
2071                 serial_outp(info, UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
2072                 serial_outp(info, UART_IER, 0x0f);      /* enable all intrs */
2073                 ICP = (port & 0xFE0) | 0x01F;
2074                 save_ICP = inb_p(ICP);
2075                 outb_p(0x80, ICP);
2076                 (void) inb_p(ICP);
2077         } else {
2078                 serial_outp(info, UART_MCR,
2079                             UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
2080                 serial_outp(info, UART_IER, 0x0f);      /* enable all intrs */
2081         }
2082         sti();
2083         /*
2084          * Next, clear the interrupt registers.
2085          */
2086         (void)serial_inp(info, UART_LSR);
2087         (void)serial_inp(info, UART_RX);
2088         (void)serial_inp(info, UART_IIR);
2089         (void)serial_inp(info, UART_MSR);
2090         
2091         timeout = jiffies+2;
2092         while (timeout >= jiffies) {
2093                 if (rs_irq_triggered)
2094                         break;
2095         }
2096         /*
2097          * Now check to see if we got any business, and clean up.
2098          */
2099         cli();
2100         serial_outp(info, UART_IER, save_IER);
2101         serial_outp(info, UART_MCR, save_MCR);
2102         if (info->flags & ASYNC_FOURPORT)
2103                 outb_p(save_ICP, ICP);
2104         sti();
2105         return(rs_irq_triggered);
2106 }
2107 
2108 /*
2109  * Calls get_auto_irq() multiple times, to make sure we don't get
2110  * faked out by random interrupts
2111  */
2112 static int do_auto_irq(struct async_struct * info)
     /* [previous][next][first][last][top][bottom][index][help] */
2113 {
2114         unsigned                port = info->port;
2115         int                     irq_lines = 0;
2116         int                     irq_try_1 = 0, irq_try_2 = 0;
2117         int                     retries;
2118         unsigned long flags;
2119 
2120         if (!port)
2121                 return 0;
2122 
2123         /* Turn on interrupts (they may be off) */
2124         save_flags(flags); sti();
2125 
2126         irq_lines = grab_all_interrupts(rs_wild_int_mask);
2127         
2128         for (retries = 0; retries < 5; retries++) {
2129                 if (!irq_try_1)
2130                         irq_try_1 = get_auto_irq(info);
2131                 if (!irq_try_2)
2132                         irq_try_2 = get_auto_irq(info);
2133                 if (irq_try_1 && irq_try_2) {
2134                         if (irq_try_1 == irq_try_2)
2135                                 break;
2136                         irq_try_1 = irq_try_2 = 0;
2137                 }
2138         }
2139         restore_flags(flags);
2140         free_all_interrupts(irq_lines);
2141         return (irq_try_1 == irq_try_2) ? irq_try_1 : 0;
2142 }
2143 
2144 /*
2145  * This routine is called by rs_init() to initialize a specific serial
2146  * port.  It determines what type of UART ship this serial port is
2147  * using: 8250, 16450, 16550, 16550A.  The important question is
2148  * whether or not this UART is a 16550A or not, since this will
2149  * determine whether or not we can use its FIFO features or not.
2150  */
2151 static void autoconfig(struct async_struct * info)
     /* [previous][next][first][last][top][bottom][index][help] */
2152 {
2153         unsigned char status1, status2, scratch, scratch2;
2154         unsigned port = info->port;
2155         unsigned long flags;
2156 
2157         info->type = PORT_UNKNOWN;
2158         
2159         if (!port)
2160                 return;
2161 
2162         save_flags(flags); cli();
2163         
2164         /*
2165          * Do a simple existence test first; if we fail this, there's
2166          * no point trying anything else.
2167          *
2168          * 0x80 is used as a nonsense port to prevent against false
2169          * positives due to ISA bus float.  The assumption is that
2170          * 0x80 is a non-existent port; which should be safe since
2171          * include/asm/io.h also makes this assumption.
2172          */
2173         scratch = serial_inp(info, UART_IER);
2174         serial_outp(info, UART_IER, 0);
2175         outb(0xff, 0x080);
2176         scratch2 = serial_inp(info, UART_IER);
2177         serial_outp(info, UART_IER, scratch);
2178         if (scratch2) {
2179                 restore_flags(flags);
2180                 return;         /* We failed; there's nothing here */
2181         }
2182 
2183         /* 
2184          * Check to see if a UART is really there.  Certain broken
2185          * internal modems based on the Rockwell chipset fail this
2186          * test, because they apparently don't implement the loopback
2187          * test mode.  So this test is skipped on the COM 1 through
2188          * COM 4 ports.  This *should* be safe, since no board
2189          * manufacturer would be stupid enough to design a board
2190          * that conflicts with COM 1-4 --- we hope!
2191          */
2192         if (!(info->flags & ASYNC_SKIP_TEST)) {
2193                 scratch = serial_inp(info, UART_MCR);
2194                 serial_outp(info, UART_MCR, UART_MCR_LOOP | scratch);
2195                 scratch2 = serial_inp(info, UART_MSR);
2196                 serial_outp(info, UART_MCR, UART_MCR_LOOP | 0x0A);
2197                 status1 = serial_inp(info, UART_MSR) & 0xF0;
2198                 serial_outp(info, UART_MCR, scratch);
2199                 serial_outp(info, UART_MSR, scratch2);
2200                 if (status1 != 0x90) {
2201                         restore_flags(flags);
2202                         return;
2203                 }
2204         } 
2205         
2206         /*
2207          * If the AUTO_IRQ flag is set, try to do the automatic IRQ
2208          * detection.
2209          */
2210         if (info->flags & ASYNC_AUTO_IRQ)
2211                 info->irq = do_auto_irq(info);
2212                 
2213         serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
2214         scratch = serial_in(info, UART_IIR) >> 6;
2215         info->xmit_fifo_size = 1;
2216         switch (scratch) {
2217                 case 0:
2218                         info->type = PORT_16450;
2219                         break;
2220                 case 1:
2221                         info->type = PORT_UNKNOWN;
2222                         break;
2223                 case 2:
2224                         info->type = PORT_16550;
2225                         break;
2226                 case 3:
2227                         info->type = PORT_16550A;
2228                         info->xmit_fifo_size = 16;
2229                         break;
2230         }
2231         if (info->type == PORT_16450) {
2232                 scratch = serial_in(info, UART_SCR);
2233                 serial_outp(info, UART_SCR, 0xa5);
2234                 status1 = serial_in(info, UART_SCR);
2235                 serial_outp(info, UART_SCR, 0x5a);
2236                 status2 = serial_in(info, UART_SCR);
2237                 serial_outp(info, UART_SCR, scratch);
2238 
2239                 if ((status1 != 0xa5) || (status2 != 0x5a))
2240                         info->type = PORT_8250;
2241         }
2242 
2243         /*
2244          * Reset the UART.
2245          */
2246         serial_outp(info, UART_MCR, 0x00);
2247         serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
2248                                      UART_FCR_CLEAR_XMIT));
2249         (void)serial_in(info, UART_RX);
2250         
2251         restore_flags(flags);
2252 }
2253 
2254 /*
2255  * The serial driver boot-time initialization code!
2256  */
2257 long rs_init(long kmem_start)
     /* [previous][next][first][last][top][bottom][index][help] */
2258 {
2259         int i;
2260         struct async_struct * info;
2261         
2262         bh_base[SERIAL_BH].routine = do_serial_bh;
2263         timer_table[RS_TIMER].fn = rs_timer;
2264         timer_table[RS_TIMER].expires = 0;
2265 #ifdef CONFIG_AUTO_IRQ
2266         rs_wild_int_mask = check_wild_interrupts(1);
2267 #endif
2268 
2269         for (i = 0; i < 16; i++) {
2270                 IRQ_ports[i] = 0;
2271                 IRQ_timeout[i] = 0;
2272         }
2273         
2274         show_serial_version();
2275 
2276         /* Initialize the tty_driver structure */
2277         
2278         memset(&serial_driver, 0, sizeof(struct tty_driver));
2279         serial_driver.magic = TTY_DRIVER_MAGIC;
2280         serial_driver.name = "ttyS";
2281         serial_driver.major = TTY_MAJOR;
2282         serial_driver.minor_start = 64;
2283         serial_driver.num = NR_PORTS;
2284         serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
2285         serial_driver.subtype = SERIAL_TYPE_NORMAL;
2286         serial_driver.init_termios = tty_std_termios;
2287         serial_driver.init_termios.c_cflag =
2288                 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2289         serial_driver.flags = TTY_DRIVER_REAL_RAW;
2290         serial_driver.refcount = &serial_refcount;
2291         serial_driver.table = serial_table;
2292         serial_driver.termios = serial_termios;
2293         serial_driver.termios_locked = serial_termios_locked;
2294 
2295         serial_driver.open = rs_open;
2296         serial_driver.close = rs_close;
2297         serial_driver.write = rs_write;
2298         serial_driver.put_char = rs_put_char;
2299         serial_driver.flush_chars = rs_flush_chars;
2300         serial_driver.write_room = rs_write_room;
2301         serial_driver.chars_in_buffer = rs_chars_in_buffer;
2302         serial_driver.flush_buffer = rs_flush_buffer;
2303         serial_driver.ioctl = rs_ioctl;
2304         serial_driver.throttle = rs_throttle;
2305         serial_driver.unthrottle = rs_unthrottle;
2306         serial_driver.set_termios = rs_set_termios;
2307         serial_driver.stop = rs_stop;
2308         serial_driver.start = rs_start;
2309         serial_driver.hangup = rs_hangup;
2310 
2311         /*
2312          * The callout device is just like normal device except for
2313          * major number and the subtype code.
2314          */
2315         callout_driver = serial_driver;
2316         callout_driver.name = "cua";
2317         callout_driver.major = TTYAUX_MAJOR;
2318         callout_driver.subtype = SERIAL_TYPE_CALLOUT;
2319 
2320         if (tty_register_driver(&serial_driver))
2321                 panic("Couldn't register serial driver\n");
2322         if (tty_register_driver(&callout_driver))
2323                 panic("Couldn't register callout driver\n");
2324         
2325         for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) {
2326                 info->magic = SERIAL_MAGIC;
2327                 info->line = i;
2328                 info->tty = 0;
2329                 info->type = PORT_UNKNOWN;
2330                 info->custom_divisor = 0;
2331                 info->close_delay = 50;
2332                 info->x_char = 0;
2333                 info->event = 0;
2334                 info->count = 0;
2335                 info->blocked_open = 0;
2336                 info->tqueue.routine = do_softint;
2337                 info->tqueue.data = info;
2338                 info->callout_termios =callout_driver.init_termios;
2339                 info->normal_termios = serial_driver.init_termios;
2340                 info->open_wait = 0;
2341                 info->close_wait = 0;
2342                 info->next_port = 0;
2343                 info->prev_port = 0;
2344                 if (info->irq == 2)
2345                         info->irq = 9;
2346                 if (!(info->flags & ASYNC_BOOT_AUTOCONF))
2347                         continue;
2348                 autoconfig(info);
2349                 if (info->type == PORT_UNKNOWN)
2350                         continue;
2351                 printk("tty%02d%s at 0x%04x (irq = %d)", info->line, 
2352                        (info->flags & ASYNC_FOURPORT) ? " FourPort" : "",
2353                        info->port, info->irq);
2354                 switch (info->type) {
2355                         case PORT_8250:
2356                                 printk(" is a 8250\n");
2357                                 break;
2358                         case PORT_16450:
2359                                 printk(" is a 16450\n");
2360                                 break;
2361                         case PORT_16550:
2362                                 printk(" is a 16550\n");
2363                                 break;
2364                         case PORT_16550A:
2365                                 printk(" is a 16550A\n");
2366                                 break;
2367                         default:
2368                                 printk("\n");
2369                                 break;
2370                 }
2371         }
2372         return kmem_start;
2373 }
2374 
2375 /*
2376  * register_serial and unregister_serial allows for serial ports to be
2377  * configured at run-time, to support PCMCIA modems.
2378  */
2379 int register_serial(struct serial_struct *req)
     /* [previous][next][first][last][top][bottom][index][help] */
2380 {
2381         int i;
2382         unsigned long flags;
2383         struct async_struct *info;
2384 
2385         save_flags(flags);
2386         cli();
2387         for (i = 0; i < NR_PORTS; i++) {
2388                 if (rs_table[i].port == req->port)
2389                         break;
2390         }
2391         if (i == NR_PORTS) {
2392                 for (i = 0; i < NR_PORTS; i++)
2393                         if ((rs_table[i].type == PORT_UNKNOWN) &&
2394                             (rs_table[i].count == 0))
2395                                 break;
2396         }
2397         if (i == NR_PORTS) {
2398                 restore_flags(flags);
2399                 return -1;
2400         }
2401         info = &rs_table[i];
2402         if (rs_table[i].count) {
2403                 restore_flags(flags);
2404                 printk("Couldn't configure serial #%d (port=%d,irq=%d): "
2405                        "device already open\n", i, req->port, req->irq);
2406                 return -1;
2407         }
2408         info->irq = req->irq;
2409         info->port = req->port;
2410         autoconfig(info);
2411         if (info->type == PORT_UNKNOWN) {
2412                 restore_flags(flags);
2413                 printk("register_serial(): autoconfig failed\n");
2414                 return -1;
2415         }
2416         printk("tty%02d at 0x%04x (irq = %d)", info->line, 
2417                info->port, info->irq);
2418         switch (info->type) {
2419         case PORT_8250:
2420                 printk(" is a 8250\n"); break;
2421         case PORT_16450:
2422                 printk(" is a 16450\n"); break;
2423         case PORT_16550:
2424                 printk(" is a 16550\n"); break;
2425         case PORT_16550A:
2426                 printk(" is a 16550A\n"); break;
2427         default:
2428                 printk("\n"); break;
2429         }
2430         restore_flags(flags);
2431         return info->line;
2432 }
2433 
2434 void unregister_serial(int line)
     /* [previous][next][first][last][top][bottom][index][help] */
2435 {
2436         unsigned long flags;
2437         struct async_struct *info = &rs_table[line];
2438 
2439         save_flags(flags);
2440         cli();
2441         if (info->tty)
2442                 tty_hangup(info->tty);
2443         info->type = PORT_UNKNOWN;
2444         printk("tty%02d unloaded\n", info->line);
2445         restore_flags(flags);
2446 }

/* [previous][next][first][last][top][bottom][index][help] */