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/drivers/char/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         int             retval;
 991 
 992         if (!(info->flags & ASYNC_INITIALIZED))
 993                 return;
 994 
 995 #ifdef SERIAL_DEBUG_OPEN
 996         printk("Shutting down serial port %d (irq %d)....", info->line,
 997                info->irq);
 998 #endif
 999         
1000         save_flags(flags); cli(); /* Disable interrupts */
1001         
1002         /*
1003          * First unlink the serial port from the IRQ chain...
1004          */
1005         if (info->next_port)
1006                 info->next_port->prev_port = info->prev_port;
1007         if (info->prev_port)
1008                 info->prev_port->next_port = info->next_port;
1009         else
1010                 IRQ_ports[info->irq] = info->next_port;
1011         figure_IRQ_timeout(info->irq);
1012         
1013         /*
1014          * Free the IRQ, if necessary
1015          */
1016         if (info->irq && (!IRQ_ports[info->irq] ||
1017                           !IRQ_ports[info->irq]->next_port)) {
1018                 if (IRQ_ports[info->irq]) {
1019                         free_irq(info->irq);
1020                         retval = request_irq(info->irq, rs_interrupt_single, SA_INTERRUPT, "serial");
1021                         
1022                         if (retval)
1023                                 printk("serial shutdown: request_irq: error %d"
1024                                        "  Couldn't reacquire IRQ.\n", retval);
1025                 } else
1026                         free_irq(info->irq);
1027         }
1028 
1029         if (info->xmit_buf) {
1030                 free_page((unsigned long) info->xmit_buf);
1031                 info->xmit_buf = 0;
1032         }
1033 
1034         info->IER = 0;
1035         serial_outp(info, UART_IER, 0x00);      /* disable all intrs */
1036         if (info->flags & ASYNC_FOURPORT) {
1037                 /* reset interrupts on the AST Fourport board */
1038                 (void) inb((info->port & 0xFE0) | 0x01F);
1039         }
1040         
1041         if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
1042                 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1043                 info->MCR_noint &= ~(UART_MCR_DTR|UART_MCR_RTS);
1044         }
1045         serial_outp(info, UART_MCR, info->MCR_noint);
1046 
1047         /* disable FIFO's */    
1048         serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
1049                                      UART_FCR_CLEAR_XMIT));
1050         (void)serial_in(info, UART_RX);    /* read data port to reset things */
1051         
1052         if (info->tty)
1053                 set_bit(TTY_IO_ERROR, &info->tty->flags);
1054         
1055         info->flags &= ~ASYNC_INITIALIZED;
1056         restore_flags(flags);
1057 }
1058 
1059 /*
1060  * This routine is called to set the UART divisor registers to match
1061  * the specified baud rate for a serial port.
1062  */
1063 static void change_speed(struct async_struct *info)
     /* [previous][next][first][last][top][bottom][index][help] */
1064 {
1065         unsigned short port;
1066         int     quot = 0;
1067         unsigned cflag,cval,fcr;
1068         int     i;
1069 
1070         if (!info->tty || !info->tty->termios)
1071                 return;
1072         cflag = info->tty->termios->c_cflag;
1073         if (!(port = info->port))
1074                 return;
1075         i = cflag & CBAUD;
1076         if (i == 15) {
1077                 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1078                         i += 1;
1079                 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1080                         i += 2;
1081                 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
1082                         quot = info->custom_divisor;
1083         }
1084         if (quot) {
1085                 info->timeout = ((info->xmit_fifo_size*HZ*15*quot) /
1086                                  info->baud_base) + 2;
1087         } else if (baud_table[i] == 134) {
1088                 quot = (2*info->baud_base / 269);
1089                 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
1090         } else if (baud_table[i]) {
1091                 quot = info->baud_base / baud_table[i];
1092                 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
1093         } else {
1094                 quot = 0;
1095                 info->timeout = 0;
1096         }
1097         if (quot) {
1098                 info->MCR |= UART_MCR_DTR;
1099                 info->MCR_noint |= UART_MCR_DTR;
1100                 cli();
1101                 serial_out(info, UART_MCR, info->MCR);
1102                 sti();
1103         } else {
1104                 info->MCR &= ~UART_MCR_DTR;
1105                 info->MCR_noint &= ~UART_MCR_DTR;
1106                 cli();
1107                 serial_out(info, UART_MCR, info->MCR);
1108                 sti();
1109                 return;
1110         }
1111         /* byte size and parity */
1112         cval = cflag & (CSIZE | CSTOPB);
1113         cval >>= 4;
1114         if (cflag & PARENB)
1115                 cval |= UART_LCR_PARITY;
1116         if (!(cflag & PARODD))
1117                 cval |= UART_LCR_EPAR;
1118         if (info->type == PORT_16550A) {
1119                 if ((info->baud_base / quot) < 2400)
1120                         fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
1121                 else
1122                         fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;
1123         } else
1124                 fcr = 0;
1125         
1126         /* CTS flow control flag and modem status interrupts */
1127         info->IER &= ~UART_IER_MSI;
1128         if (cflag & CRTSCTS) {
1129                 info->flags |= ASYNC_CTS_FLOW;
1130                 info->IER |= UART_IER_MSI;
1131         } else
1132                 info->flags &= ~ASYNC_CTS_FLOW;
1133         if (cflag & CLOCAL)
1134                 info->flags &= ~ASYNC_CHECK_CD;
1135         else {
1136                 info->flags |= ASYNC_CHECK_CD;
1137                 info->IER |= UART_IER_MSI;
1138         }
1139         serial_out(info, UART_IER, info->IER);
1140 
1141         /*
1142          * Set up parity check flag
1143          */
1144         info->read_status_mask = UART_LSR_OE;
1145         if (I_INPCK(info->tty))
1146                 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1147         if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
1148                 info->read_status_mask |= UART_LSR_BI;
1149         
1150         info->ignore_status_mask = 0;
1151         if (I_IGNPAR(info->tty))
1152                 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
1153         if (I_IGNBRK(info->tty)) {
1154                 info->ignore_status_mask |= UART_LSR_BI;
1155                 /*
1156                  * If we're ignore parity and break indicators, ignore 
1157                  * overruns too.  (For real raw support).
1158                  */
1159                 if (I_IGNPAR(info->tty))
1160                         info->ignore_status_mask |= UART_LSR_OE;
1161         }
1162         
1163         cli();
1164         serial_outp(info, UART_LCR, cval | UART_LCR_DLAB);      /* set DLAB */
1165         serial_outp(info, UART_DLL, quot & 0xff);       /* LS of divisor */
1166         serial_outp(info, UART_DLM, quot >> 8);         /* MS of divisor */
1167         serial_outp(info, UART_LCR, cval);              /* reset DLAB */
1168         serial_outp(info, UART_FCR, fcr);       /* set fcr */
1169         sti();
1170 }
1171 
1172 static void rs_put_char(struct tty_struct *tty, unsigned char ch)
     /* [previous][next][first][last][top][bottom][index][help] */
1173 {
1174         struct async_struct *info = (struct async_struct *)tty->driver_data;
1175         unsigned long flags;
1176 
1177         if (serial_paranoia_check(info, tty->device, "rs_put_char"))
1178                 return;
1179 
1180         if (!tty || !info->xmit_buf)
1181                 return;
1182 
1183         save_flags(flags); cli();
1184         if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1185                 restore_flags(flags);
1186                 return;
1187         }
1188 
1189         info->xmit_buf[info->xmit_head++] = ch;
1190         info->xmit_head &= SERIAL_XMIT_SIZE-1;
1191         info->xmit_cnt++;
1192         restore_flags(flags);
1193 }
1194 
1195 static void rs_flush_chars(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1196 {
1197         struct async_struct *info = (struct async_struct *)tty->driver_data;
1198         unsigned long flags;
1199                                 
1200         if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))
1201                 return;
1202 
1203         if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1204             !info->xmit_buf)
1205                 return;
1206 
1207         save_flags(flags); cli();
1208         info->IER |= UART_IER_THRI;
1209         serial_out(info, UART_IER, info->IER);
1210         restore_flags(flags);
1211 }
1212 
1213 static int rs_write(struct tty_struct * tty, int from_user,
     /* [previous][next][first][last][top][bottom][index][help] */
1214                     unsigned char *buf, int count)
1215 {
1216         int     c, total = 0;
1217         struct async_struct *info = (struct async_struct *)tty->driver_data;
1218         unsigned long flags;
1219                                 
1220         if (serial_paranoia_check(info, tty->device, "rs_write"))
1221                 return 0;
1222 
1223         if (!tty || !info->xmit_buf || !tmp_buf)
1224                 return 0;
1225             
1226         save_flags(flags);
1227         while (1) {
1228                 cli();          
1229                 c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1230                                    SERIAL_XMIT_SIZE - info->xmit_head));
1231                 if (c <= 0)
1232                         break;
1233 
1234                 if (from_user) {
1235                         down(&tmp_buf_sem);
1236                         memcpy_fromfs(tmp_buf, buf, c);
1237                         c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1238                                        SERIAL_XMIT_SIZE - info->xmit_head));
1239                         memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
1240                         up(&tmp_buf_sem);
1241                 } else
1242                         memcpy(info->xmit_buf + info->xmit_head, buf, c);
1243                 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1244                 info->xmit_cnt += c;
1245                 restore_flags(flags);
1246                 buf += c;
1247                 count -= c;
1248                 total += c;
1249         }
1250         if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1251             !(info->IER & UART_IER_THRI)) {
1252                 info->IER |= UART_IER_THRI;
1253                 serial_out(info, UART_IER, info->IER);
1254         }
1255         restore_flags(flags);
1256         return total;
1257 }
1258 
1259 static int rs_write_room(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1260 {
1261         struct async_struct *info = (struct async_struct *)tty->driver_data;
1262         int     ret;
1263                                 
1264         if (serial_paranoia_check(info, tty->device, "rs_write_room"))
1265                 return 0;
1266         ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1267         if (ret < 0)
1268                 ret = 0;
1269         return ret;
1270 }
1271 
1272 static int rs_chars_in_buffer(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1273 {
1274         struct async_struct *info = (struct async_struct *)tty->driver_data;
1275                                 
1276         if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
1277                 return 0;
1278         return info->xmit_cnt;
1279 }
1280 
1281 static void rs_flush_buffer(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1282 {
1283         struct async_struct *info = (struct async_struct *)tty->driver_data;
1284                                 
1285         if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
1286                 return;
1287         cli();
1288         info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1289         sti();
1290         wake_up_interruptible(&tty->write_wait);
1291         if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1292             tty->ldisc.write_wakeup)
1293                 (tty->ldisc.write_wakeup)(tty);
1294 }
1295 
1296 /*
1297  * ------------------------------------------------------------
1298  * rs_throttle()
1299  * 
1300  * This routine is called by the upper-layer tty layer to signal that
1301  * incoming characters should be throttled.
1302  * ------------------------------------------------------------
1303  */
1304 static void rs_throttle(struct tty_struct * tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1305 {
1306         struct async_struct *info = (struct async_struct *)tty->driver_data;
1307 #ifdef SERIAL_DEBUG_THROTTLE
1308         char    buf[64];
1309         
1310         printk("throttle %s: %d....\n", _tty_name(tty, buf),
1311                tty->ldisc.chars_in_buffer(tty));
1312 #endif
1313 
1314         if (serial_paranoia_check(info, tty->device, "rs_throttle"))
1315                 return;
1316         
1317         if (I_IXOFF(tty))
1318                 info->x_char = STOP_CHAR(tty);
1319 
1320         info->MCR &= ~UART_MCR_RTS;
1321         info->MCR_noint &= ~UART_MCR_RTS;
1322         cli();
1323         serial_out(info, UART_MCR, info->MCR);
1324         sti();
1325 }
1326 
1327 static void rs_unthrottle(struct tty_struct * tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1328 {
1329         struct async_struct *info = (struct async_struct *)tty->driver_data;
1330 #ifdef SERIAL_DEBUG_THROTTLE
1331         char    buf[64];
1332         
1333         printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1334                tty->ldisc.chars_in_buffer(tty));
1335 #endif
1336 
1337         if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
1338                 return;
1339         
1340         if (I_IXOFF(tty)) {
1341                 if (info->x_char)
1342                         info->x_char = 0;
1343                 else
1344                         info->x_char = START_CHAR(tty);
1345         }
1346         info->MCR |= UART_MCR_RTS;
1347         info->MCR_noint |= UART_MCR_RTS;
1348         cli();
1349         serial_out(info, UART_MCR, info->MCR);
1350         sti();
1351 }
1352 
1353 /*
1354  * ------------------------------------------------------------
1355  * rs_ioctl() and friends
1356  * ------------------------------------------------------------
1357  */
1358 
1359 static int get_serial_info(struct async_struct * info,
     /* [previous][next][first][last][top][bottom][index][help] */
1360                            struct serial_struct * retinfo)
1361 {
1362         struct serial_struct tmp;
1363   
1364         if (!retinfo)
1365                 return -EFAULT;
1366         memset(&tmp, 0, sizeof(tmp));
1367         tmp.type = info->type;
1368         tmp.line = info->line;
1369         tmp.port = info->port;
1370         tmp.irq = info->irq;
1371         tmp.flags = info->flags;
1372         tmp.baud_base = info->baud_base;
1373         tmp.close_delay = info->close_delay;
1374         tmp.custom_divisor = info->custom_divisor;
1375         tmp.hub6 = info->hub6;
1376         memcpy_tofs(retinfo,&tmp,sizeof(*retinfo));
1377         return 0;
1378 }
1379 
1380 static int set_serial_info(struct async_struct * info,
     /* [previous][next][first][last][top][bottom][index][help] */
1381                            struct serial_struct * new_info)
1382 {
1383         struct serial_struct new_serial;
1384         struct async_struct old_info;
1385         unsigned int            i,change_irq,change_port;
1386         int                     retval = 0;
1387 
1388         if (!new_info)
1389                 return -EFAULT;
1390         memcpy_fromfs(&new_serial,new_info,sizeof(new_serial));
1391         old_info = *info;
1392 
1393         change_irq = new_serial.irq != info->irq;
1394         change_port = (new_serial.port != info->port) || (new_serial.hub6 != info->hub6);
1395 
1396         if (!suser()) {
1397                 if (change_irq || change_port ||
1398                     (new_serial.baud_base != info->baud_base) ||
1399                     (new_serial.type != info->type) ||
1400                     (new_serial.close_delay != info->close_delay) ||
1401                     ((new_serial.flags & ~ASYNC_USR_MASK) !=
1402                      (info->flags & ~ASYNC_USR_MASK)))
1403                         return -EPERM;
1404                 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1405                                (new_serial.flags & ASYNC_USR_MASK));
1406                 info->custom_divisor = new_serial.custom_divisor;
1407                 goto check_and_exit;
1408         }
1409 
1410         if (new_serial.irq == 2)
1411                 new_serial.irq = 9;
1412 
1413         if ((new_serial.irq > 15) || (new_serial.port > 0xffff) ||
1414             (new_serial.type < PORT_UNKNOWN) || (new_serial.type > PORT_MAX)) {
1415                 return -EINVAL;
1416         }
1417 
1418         /* Make sure address is not already in use */
1419         if (new_serial.type) {
1420                 for (i = 0 ; i < NR_PORTS; i++)
1421                         if ((info != &rs_table[i]) &&
1422                             (rs_table[i].port == new_serial.port) &&
1423                             rs_table[i].type)
1424                                 return -EADDRINUSE;
1425         }
1426 
1427         if ((change_port || change_irq) && (info->count > 1))
1428                 return -EBUSY;
1429 
1430         /*
1431          * OK, past this point, all the error checking has been done.
1432          * At this point, we start making changes.....
1433          */
1434 
1435         info->baud_base = new_serial.baud_base;
1436         info->flags = ((info->flags & ~ASYNC_FLAGS) |
1437                         (new_serial.flags & ASYNC_FLAGS));
1438         info->custom_divisor = new_serial.custom_divisor;
1439         info->type = new_serial.type;
1440         info->close_delay = new_serial.close_delay;
1441 
1442         if (change_port || change_irq) {
1443                 /*
1444                  * We need to shutdown the serial port at the old
1445                  * port/irq combination.
1446                  */
1447                 shutdown(info);
1448                 info->irq = new_serial.irq;
1449                 info->port = new_serial.port;
1450                 info->hub6 = new_serial.hub6;
1451         }
1452         
1453 check_and_exit:
1454         if (!info->port || !info->type)
1455                 return 0;
1456         if (info->flags & ASYNC_INITIALIZED) {
1457                 if (((old_info.flags & ASYNC_SPD_MASK) !=
1458                      (info->flags & ASYNC_SPD_MASK)) ||
1459                     (old_info.custom_divisor != info->custom_divisor))
1460                         change_speed(info);
1461         } else
1462                 retval = startup(info);
1463         return retval;
1464 }
1465 
1466 static int get_modem_info(struct async_struct * info, unsigned int *value)
     /* [previous][next][first][last][top][bottom][index][help] */
1467 {
1468         unsigned char control, status;
1469         unsigned int result;
1470 
1471         control = info->MCR;
1472         cli();
1473         status = serial_in(info, UART_MSR);
1474         sti();
1475         result =  ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1476                 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1477                 | ((status  & UART_MSR_DCD) ? TIOCM_CAR : 0)
1478                 | ((status  & UART_MSR_RI) ? TIOCM_RNG : 0)
1479                 | ((status  & UART_MSR_DSR) ? TIOCM_DSR : 0)
1480                 | ((status  & UART_MSR_CTS) ? TIOCM_CTS : 0);
1481         put_fs_long(result,(unsigned long *) value);
1482         return 0;
1483 }
1484 
1485 static int set_modem_info(struct async_struct * info, unsigned int cmd,
     /* [previous][next][first][last][top][bottom][index][help] */
1486                           unsigned int *value)
1487 {
1488         unsigned int arg = get_fs_long((unsigned long *) value);
1489 
1490         switch (cmd) {
1491         case TIOCMBIS: 
1492                 if (arg & TIOCM_RTS) {
1493                         info->MCR |= UART_MCR_RTS;
1494                         info->MCR_noint |= UART_MCR_RTS;
1495                 }
1496                 if (arg & TIOCM_DTR) {
1497                         info->MCR |= UART_MCR_DTR;
1498                         info->MCR_noint |= UART_MCR_DTR;
1499                 }
1500                 break;
1501         case TIOCMBIC:
1502                 if (arg & TIOCM_RTS) {
1503                         info->MCR &= ~UART_MCR_RTS;
1504                         info->MCR_noint &= ~UART_MCR_RTS;
1505                 }
1506                 if (arg & TIOCM_DTR) {
1507                         info->MCR &= ~UART_MCR_DTR;
1508                         info->MCR_noint &= ~UART_MCR_DTR;
1509                 }
1510                 break;
1511         case TIOCMSET:
1512                 info->MCR = ((info->MCR & ~(UART_MCR_RTS | UART_MCR_DTR))
1513                              | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1514                              | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1515                 info->MCR_noint = ((info->MCR_noint
1516                                     & ~(UART_MCR_RTS | UART_MCR_DTR))
1517                                    | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1518                                    | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1519                 break;
1520         default:
1521                 return -EINVAL;
1522         }
1523         cli();
1524         serial_out(info, UART_MCR, info->MCR);
1525         sti();
1526         return 0;
1527 }
1528 
1529 static int do_autoconfig(struct async_struct * info)
     /* [previous][next][first][last][top][bottom][index][help] */
1530 {
1531         int                     retval;
1532         
1533         if (!suser())
1534                 return -EPERM;
1535         
1536         if (info->count > 1)
1537                 return -EBUSY;
1538         
1539         shutdown(info);
1540 
1541         cli();
1542         autoconfig(info);
1543         sti();
1544 
1545         retval = startup(info);
1546         if (retval)
1547                 return retval;
1548         return 0;
1549 }
1550 
1551 
1552 /*
1553  * This routine sends a break character out the serial port.
1554  */
1555 static void send_break( struct async_struct * info, int duration)
     /* [previous][next][first][last][top][bottom][index][help] */
1556 {
1557         if (!info->port)
1558                 return;
1559         current->state = TASK_INTERRUPTIBLE;
1560         current->timeout = jiffies + duration;
1561         cli();
1562         serial_out(info, UART_LCR, serial_inp(info, UART_LCR) | UART_LCR_SBC);
1563         schedule();
1564         serial_out(info, UART_LCR, serial_inp(info, UART_LCR) & ~UART_LCR_SBC);
1565         sti();
1566 }
1567 
1568 /*
1569  * This routine returns a bitfield of "wild interrupts".  Basically,
1570  * any unclaimed interrupts which is flapping around.
1571  */
1572 static int check_wild_interrupts(int doprint)
     /* [previous][next][first][last][top][bottom][index][help] */
1573 {
1574         int     i, mask;
1575         int     wild_interrupts = 0;
1576         int     irq_lines;
1577         unsigned long timeout;
1578         unsigned long flags;
1579         
1580         /* Turn on interrupts (they may be off) */
1581         save_flags(flags); sti();
1582 
1583         irq_lines = grab_all_interrupts(0);
1584         
1585         /*
1586          * Delay for 0.1 seconds -- we use a busy loop since this may 
1587          * occur during the bootup sequence
1588          */
1589         timeout = jiffies+10;
1590         while (timeout >= jiffies)
1591                 ;
1592         
1593         rs_triggered = 0;       /* Reset after letting things settle */
1594 
1595         timeout = jiffies+10;
1596         while (timeout >= jiffies)
1597                 ;
1598         
1599         for (i = 0, mask = 1; i < 16; i++, mask <<= 1) {
1600                 if ((rs_triggered & (1 << i)) &&
1601                     (irq_lines & (1 << i))) {
1602                         wild_interrupts |= mask;
1603                         if (doprint)
1604                                 printk("Wild interrupt?  (IRQ %d)\n", i);
1605                 }
1606         }
1607         free_all_interrupts(irq_lines);
1608         restore_flags(flags);
1609         return wild_interrupts;
1610 }
1611 
1612 static int rs_ioctl(struct tty_struct *tty, struct file * file,
     /* [previous][next][first][last][top][bottom][index][help] */
1613                     unsigned int cmd, unsigned long arg)
1614 {
1615         int error;
1616         struct async_struct * info = (struct async_struct *)tty->driver_data;
1617         int retval;
1618 
1619         if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
1620                 return -ENODEV;
1621         
1622         switch (cmd) {
1623                 case TCSBRK:    /* SVID version: non-zero arg --> no break */
1624                         retval = tty_check_change(tty);
1625                         if (retval)
1626                                 return retval;
1627                         wait_until_sent(tty, 0);
1628                         if (!arg)
1629                                 send_break(info, HZ/4); /* 1/4 second */
1630                         return 0;
1631                 case TCSBRKP:   /* support for POSIX tcsendbreak() */
1632                         retval = tty_check_change(tty);
1633                         if (retval)
1634                                 return retval;
1635                         wait_until_sent(tty, 0);
1636                         send_break(info, arg ? arg*(HZ/10) : HZ/4);
1637                         return 0;
1638                 case TIOCGSOFTCAR:
1639                         error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
1640                         if (error)
1641                                 return error;
1642                         put_fs_long(C_CLOCAL(tty) ? 1 : 0,
1643                                     (unsigned long *) arg);
1644                         return 0;
1645                 case TIOCSSOFTCAR:
1646                         arg = get_fs_long((unsigned long *) arg);
1647                         tty->termios->c_cflag =
1648                                 ((tty->termios->c_cflag & ~CLOCAL) |
1649                                  (arg ? CLOCAL : 0));
1650                         return 0;
1651                 case TIOCMGET:
1652                         error = verify_area(VERIFY_WRITE, (void *) arg,
1653                                 sizeof(unsigned int));
1654                         if (error)
1655                                 return error;
1656                         return get_modem_info(info, (unsigned int *) arg);
1657                 case TIOCMBIS:
1658                 case TIOCMBIC:
1659                 case TIOCMSET:
1660                         return set_modem_info(info, cmd, (unsigned int *) arg);
1661                 case TIOCGSERIAL:
1662                         error = verify_area(VERIFY_WRITE, (void *) arg,
1663                                                 sizeof(struct serial_struct));
1664                         if (error)
1665                                 return error;
1666                         return get_serial_info(info,
1667                                                (struct serial_struct *) arg);
1668                 case TIOCSSERIAL:
1669                         return set_serial_info(info,
1670                                                (struct serial_struct *) arg);
1671                 case TIOCSERCONFIG:
1672                         return do_autoconfig(info);
1673 
1674                 case TIOCSERGWILD:
1675                         error = verify_area(VERIFY_WRITE, (void *) arg,
1676                                             sizeof(int));
1677                         if (error)
1678                                 return error;
1679                         put_fs_long(rs_wild_int_mask, (unsigned long *) arg);
1680                         return 0;
1681 
1682                 case TIOCSERSWILD:
1683                         if (!suser())
1684                                 return -EPERM;
1685                         rs_wild_int_mask = get_fs_long((unsigned long *) arg);
1686                         if (rs_wild_int_mask < 0)
1687                                 rs_wild_int_mask = check_wild_interrupts(0);
1688                         return 0;
1689 
1690                 case TIOCSERGSTRUCT:
1691                         error = verify_area(VERIFY_WRITE, (void *) arg,
1692                                                 sizeof(struct async_struct));
1693                         if (error)
1694                                 return error;
1695                         memcpy_tofs((struct async_struct *) arg,
1696                                     info, sizeof(struct async_struct));
1697                         return 0;
1698                         
1699                 default:
1700                         return -ENOIOCTLCMD;
1701                 }
1702         return 0;
1703 }
1704 
1705 static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
     /* [previous][next][first][last][top][bottom][index][help] */
1706 {
1707         struct async_struct *info = (struct async_struct *)tty->driver_data;
1708 
1709         if (tty->termios->c_cflag == old_termios->c_cflag)
1710                 return;
1711 
1712         change_speed(info);
1713 
1714         if ((old_termios->c_cflag & CRTSCTS) &&
1715             !(tty->termios->c_cflag & CRTSCTS)) {
1716                 tty->hw_stopped = 0;
1717                 rs_start(tty);
1718         }
1719 
1720         if (!(old_termios->c_cflag & CLOCAL) &&
1721             (tty->termios->c_cflag & CLOCAL))
1722                 wake_up_interruptible(&info->open_wait);
1723 }
1724 
1725 /*
1726  * ------------------------------------------------------------
1727  * rs_close()
1728  * 
1729  * This routine is called when the serial port gets closed.  First, we
1730  * wait for the last remaining data to be sent.  Then, we unlink its
1731  * async structure from the interrupt chain if necessary, and we free
1732  * that IRQ if nothing is left in the chain.
1733  * ------------------------------------------------------------
1734  */
1735 static void rs_close(struct tty_struct *tty, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
1736 {
1737         struct async_struct * info = (struct async_struct *)tty->driver_data;
1738         unsigned long flags;
1739 
1740         if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
1741                 return;
1742         
1743         save_flags(flags); cli();
1744         
1745         if (tty_hung_up_p(filp)) {
1746                 restore_flags(flags);
1747                 return;
1748         }
1749         
1750 #ifdef SERIAL_DEBUG_OPEN
1751         printk("rs_close ttys%d, count = %d\n", info->line, info->count);
1752 #endif
1753         if ((tty->count == 1) && (info->count != 1)) {
1754                 /*
1755                  * Uh, oh.  tty->count is 1, which means that the tty
1756                  * structure will be freed.  Info->count should always
1757                  * be one in these conditions.  If it's greater than
1758                  * one, we've got real problems, since it means the
1759                  * serial port won't be shutdown.
1760                  */
1761                 printk("rs_close: bad serial port count; tty->count is 1, "
1762                        "info->count is %d\n", info->count);
1763                 info->count = 1;
1764         }
1765         if (--info->count < 0) {
1766                 printk("rs_close: bad serial port count for ttys%d: %d\n",
1767                        info->line, info->count);
1768                 info->count = 0;
1769         }
1770         if (info->count) {
1771                 restore_flags(flags);
1772                 return;
1773         }
1774         info->flags |= ASYNC_CLOSING;
1775         /*
1776          * Save the termios structure, since this port may have
1777          * separate termios for callout and dialin.
1778          */
1779         if (info->flags & ASYNC_NORMAL_ACTIVE)
1780                 info->normal_termios = *tty->termios;
1781         if (info->flags & ASYNC_CALLOUT_ACTIVE)
1782                 info->callout_termios = *tty->termios;
1783         if (info->flags & ASYNC_INITIALIZED) {
1784                 wait_until_sent(tty, 3000); /* 30 seconds timeout */
1785                 /*
1786                  * Before we drop DTR, make sure the UART transmitter
1787                  * has completely drained; this is especially
1788                  * important if there is a transmit FIFO!
1789                  */
1790                 while (!(serial_inp(info, UART_LSR) & UART_LSR_TEMT)) {
1791                         current->state = TASK_INTERRUPTIBLE;
1792                         current->timeout = jiffies + info->timeout;
1793                         schedule();
1794                 }
1795         }
1796         shutdown(info);
1797         if (tty->driver.flush_buffer)
1798                 tty->driver.flush_buffer(tty);
1799         if (tty->ldisc.flush_buffer)
1800                 tty->ldisc.flush_buffer(tty);
1801         info->event = 0;
1802         info->tty = 0;
1803         if (tty->ldisc.num != ldiscs[N_TTY].num) {
1804                 if (tty->ldisc.close)
1805                         (tty->ldisc.close)(tty);
1806                 tty->ldisc = ldiscs[N_TTY];
1807                 tty->termios->c_line = N_TTY;
1808                 if (tty->ldisc.open)
1809                         (tty->ldisc.open)(tty);
1810         }
1811         if (info->blocked_open) {
1812                 if (info->close_delay) {
1813                         current->state = TASK_INTERRUPTIBLE;
1814                         current->timeout = jiffies + info->close_delay;
1815                         schedule();
1816                 }
1817                 wake_up_interruptible(&info->open_wait);
1818         }
1819         info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
1820                          ASYNC_CLOSING);
1821         wake_up_interruptible(&info->close_wait);
1822         restore_flags(flags);
1823 }
1824 
1825 /*
1826  * rs_hangup() --- called by tty_hangup() when a hangup is signaled.
1827  */
1828 void rs_hangup(struct tty_struct *tty)
     /* [previous][next][first][last][top][bottom][index][help] */
1829 {
1830         struct async_struct * info = (struct async_struct *)tty->driver_data;
1831         
1832         if (serial_paranoia_check(info, tty->device, "rs_hangup"))
1833                 return;
1834         
1835         shutdown(info);
1836         info->event = 0;
1837         info->count = 0;
1838         info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
1839         info->tty = 0;
1840         wake_up_interruptible(&info->open_wait);
1841 }
1842 
1843 /*
1844  * ------------------------------------------------------------
1845  * rs_open() and friends
1846  * ------------------------------------------------------------
1847  */
1848 static int block_til_ready(struct tty_struct *tty, struct file * filp,
     /* [previous][next][first][last][top][bottom][index][help] */
1849                            struct async_struct *info)
1850 {
1851         struct wait_queue wait = { current, NULL };
1852         int             retval;
1853         int             do_clocal = 0;
1854 
1855         /*
1856          * If the device is in the middle of being closed, then block
1857          * until it's done, and then try again.
1858          */
1859         if (info->flags & ASYNC_CLOSING) {
1860                 interruptible_sleep_on(&info->close_wait);
1861 #ifdef SERIAL_DO_RESTART
1862                 if (info->flags & ASYNC_HUP_NOTIFY)
1863                         return -EAGAIN;
1864                 else
1865                         return -ERESTARTSYS;
1866 #else
1867                 return -EAGAIN;
1868 #endif
1869         }
1870 
1871         /*
1872          * If this is a callout device, then just make sure the normal
1873          * device isn't being used.
1874          */
1875         if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
1876                 if (info->flags & ASYNC_NORMAL_ACTIVE)
1877                         return -EBUSY;
1878                 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1879                     (info->flags & ASYNC_SESSION_LOCKOUT) &&
1880                     (info->session != current->session))
1881                     return -EBUSY;
1882                 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1883                     (info->flags & ASYNC_PGRP_LOCKOUT) &&
1884                     (info->pgrp != current->pgrp))
1885                     return -EBUSY;
1886                 info->flags |= ASYNC_CALLOUT_ACTIVE;
1887                 return 0;
1888         }
1889         
1890         /*
1891          * If non-blocking mode is set, then make the check up front
1892          * and then exit.
1893          */
1894         if (filp->f_flags & O_NONBLOCK) {
1895                 if (info->flags & ASYNC_CALLOUT_ACTIVE)
1896                         return -EBUSY;
1897                 info->flags |= ASYNC_NORMAL_ACTIVE;
1898                 return 0;
1899         }
1900 
1901         if (info->normal_termios.c_cflag & CLOCAL)
1902                 do_clocal = 1;
1903 
1904         /*
1905          * Block waiting for the carrier detect and the line to become
1906          * free (i.e., not in use by the callout).  While we are in
1907          * this loop, info->count is dropped by one, so that
1908          * rs_close() knows when to free things.  We restore it upon
1909          * exit, either normal or abnormal.
1910          */
1911         retval = 0;
1912         add_wait_queue(&info->open_wait, &wait);
1913 #ifdef SERIAL_DEBUG_OPEN
1914         printk("block_til_ready before block: ttys%d, count = %d\n",
1915                info->line, info->count);
1916 #endif
1917         info->count--;
1918         info->blocked_open++;
1919         while (1) {
1920                 cli();
1921                 if (!(info->flags & ASYNC_CALLOUT_ACTIVE))
1922                         serial_out(info, UART_MCR,
1923                                    serial_inp(info, UART_MCR) |
1924                                    (UART_MCR_DTR | UART_MCR_RTS));
1925                 sti();
1926                 current->state = TASK_INTERRUPTIBLE;
1927                 if (tty_hung_up_p(filp) ||
1928                     !(info->flags & ASYNC_INITIALIZED)) {
1929 #ifdef SERIAL_DO_RESTART
1930                         if (info->flags & ASYNC_HUP_NOTIFY)
1931                                 retval = -EAGAIN;
1932                         else
1933                                 retval = -ERESTARTSYS;  
1934 #else
1935                         retval = -EAGAIN;
1936 #endif
1937                         break;
1938                 }
1939                 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
1940                     !(info->flags & ASYNC_CLOSING) &&
1941                     (do_clocal || (serial_in(info, UART_MSR) &
1942                                    UART_MSR_DCD)))
1943                         break;
1944                 if (current->signal & ~current->blocked) {
1945                         retval = -ERESTARTSYS;
1946                         break;
1947                 }
1948 #ifdef SERIAL_DEBUG_OPEN
1949                 printk("block_til_ready blocking: ttys%d, count = %d\n",
1950                        info->line, info->count);
1951 #endif
1952                 schedule();
1953         }
1954         current->state = TASK_RUNNING;
1955         remove_wait_queue(&info->open_wait, &wait);
1956         if (!tty_hung_up_p(filp))
1957                 info->count++;
1958         info->blocked_open--;
1959 #ifdef SERIAL_DEBUG_OPEN
1960         printk("block_til_ready after blocking: ttys%d, count = %d\n",
1961                info->line, info->count);
1962 #endif
1963         if (retval)
1964                 return retval;
1965         info->flags |= ASYNC_NORMAL_ACTIVE;
1966         return 0;
1967 }       
1968 
1969 /*
1970  * This routine is called whenever a serial port is opened.  It
1971  * enables interrupts for a serial port, linking in its async structure into
1972  * the IRQ chain.   It also performs the serial-specific
1973  * initialization for the tty structure.
1974  */
1975 int rs_open(struct tty_struct *tty, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
1976 {
1977         struct async_struct     *info;
1978         int                     retval, line;
1979 
1980         line = MINOR(tty->device) - tty->driver.minor_start;
1981         if ((line < 0) || (line >= NR_PORTS))
1982                 return -ENODEV;
1983         info = rs_table + line;
1984         if (serial_paranoia_check(info, tty->device, "rs_open"))
1985                 return -ENODEV;
1986 
1987 #ifdef SERIAL_DEBUG_OPEN
1988         printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
1989                info->count);
1990 #endif
1991         info->count++;
1992         tty->driver_data = info;
1993         info->tty = tty;
1994 
1995         if (!tmp_buf) {
1996                 tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
1997                 if (!tmp_buf)
1998                         return -ENOMEM;
1999         }
2000         
2001         /*
2002          * Start up serial port
2003          */
2004         retval = startup(info);
2005         if (retval)
2006                 return retval;
2007 
2008         retval = block_til_ready(tty, filp, info);
2009         if (retval) {
2010 #ifdef SERIAL_DEBUG_OPEN
2011                 printk("rs_open returning after block_til_ready with %d\n",
2012                        retval);
2013 #endif
2014                 return retval;
2015         }
2016 
2017         if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
2018                 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
2019                         *tty->termios = info->normal_termios;
2020                 else 
2021                         *tty->termios = info->callout_termios;
2022                 change_speed(info);
2023         }
2024 
2025         info->session = current->session;
2026         info->pgrp = current->pgrp;
2027 
2028 #ifdef SERIAL_DEBUG_OPEN
2029         printk("rs_open ttys%d successful...", info->line);
2030 #endif
2031         return 0;
2032 }
2033 
2034 /*
2035  * ---------------------------------------------------------------------
2036  * rs_init() and friends
2037  *
2038  * rs_init() is called at boot-time to initialize the serial driver.
2039  * ---------------------------------------------------------------------
2040  */
2041 
2042 /*
2043  * This routine prints out the appropriate serial driver version
2044  * number, and identifies which options were configured into this
2045  * driver.
2046  */
2047 static void show_serial_version(void)
     /* [previous][next][first][last][top][bottom][index][help] */
2048 {
2049         printk("Serial driver version 4.00 with");
2050 #ifdef CONFIG_HUB6
2051         printk(" HUB-6");
2052 #define SERIAL_OPT
2053 #endif
2054 #ifdef SERIAL_OPT
2055         printk(" enabled\n");
2056 #else
2057         printk(" no serial options enabled\n");
2058 #endif
2059 #undef SERIAL_OPT
2060 }
2061 
2062 /*
2063  * This routine is called by do_auto_irq(); it attempts to determine
2064  * which interrupt a serial port is configured to use.  It is not
2065  * fool-proof, but it works a large part of the time.
2066  */
2067 static int get_auto_irq(struct async_struct *info)
     /* [previous][next][first][last][top][bottom][index][help] */
2068 {
2069         unsigned char save_MCR, save_IER, save_ICP=0;
2070         unsigned short ICP=0, port = info->port;
2071         unsigned long timeout;
2072         
2073         /*
2074          * Enable interrupts and see who answers
2075          */
2076         rs_irq_triggered = 0;
2077         cli();
2078         save_IER = serial_inp(info, UART_IER);
2079         save_MCR = serial_inp(info, UART_MCR);
2080         if (info->flags & ASYNC_FOURPORT)  {
2081                 serial_outp(info, UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
2082                 serial_outp(info, UART_IER, 0x0f);      /* enable all intrs */
2083                 ICP = (port & 0xFE0) | 0x01F;
2084                 save_ICP = inb_p(ICP);
2085                 outb_p(0x80, ICP);
2086                 (void) inb_p(ICP);
2087         } else {
2088                 serial_outp(info, UART_MCR,
2089                             UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
2090                 serial_outp(info, UART_IER, 0x0f);      /* enable all intrs */
2091         }
2092         sti();
2093         /*
2094          * Next, clear the interrupt registers.
2095          */
2096         (void)serial_inp(info, UART_LSR);
2097         (void)serial_inp(info, UART_RX);
2098         (void)serial_inp(info, UART_IIR);
2099         (void)serial_inp(info, UART_MSR);
2100         
2101         timeout = jiffies+2;
2102         while (timeout >= jiffies) {
2103                 if (rs_irq_triggered)
2104                         break;
2105         }
2106         /*
2107          * Now check to see if we got any business, and clean up.
2108          */
2109         cli();
2110         serial_outp(info, UART_IER, save_IER);
2111         serial_outp(info, UART_MCR, save_MCR);
2112         if (info->flags & ASYNC_FOURPORT)
2113                 outb_p(save_ICP, ICP);
2114         sti();
2115         return(rs_irq_triggered);
2116 }
2117 
2118 /*
2119  * Calls get_auto_irq() multiple times, to make sure we don't get
2120  * faked out by random interrupts
2121  */
2122 static int do_auto_irq(struct async_struct * info)
     /* [previous][next][first][last][top][bottom][index][help] */
2123 {
2124         unsigned                port = info->port;
2125         int                     irq_lines = 0;
2126         int                     irq_try_1 = 0, irq_try_2 = 0;
2127         int                     retries;
2128         unsigned long flags;
2129 
2130         if (!port)
2131                 return 0;
2132 
2133         /* Turn on interrupts (they may be off) */
2134         save_flags(flags); sti();
2135 
2136         irq_lines = grab_all_interrupts(rs_wild_int_mask);
2137         
2138         for (retries = 0; retries < 5; retries++) {
2139                 if (!irq_try_1)
2140                         irq_try_1 = get_auto_irq(info);
2141                 if (!irq_try_2)
2142                         irq_try_2 = get_auto_irq(info);
2143                 if (irq_try_1 && irq_try_2) {
2144                         if (irq_try_1 == irq_try_2)
2145                                 break;
2146                         irq_try_1 = irq_try_2 = 0;
2147                 }
2148         }
2149         restore_flags(flags);
2150         free_all_interrupts(irq_lines);
2151         return (irq_try_1 == irq_try_2) ? irq_try_1 : 0;
2152 }
2153 
2154 /*
2155  * This routine is called by rs_init() to initialize a specific serial
2156  * port.  It determines what type of UART ship this serial port is
2157  * using: 8250, 16450, 16550, 16550A.  The important question is
2158  * whether or not this UART is a 16550A or not, since this will
2159  * determine whether or not we can use its FIFO features or not.
2160  */
2161 static void autoconfig(struct async_struct * info)
     /* [previous][next][first][last][top][bottom][index][help] */
2162 {
2163         unsigned char status1, status2, scratch, scratch2;
2164         unsigned port = info->port;
2165         unsigned long flags;
2166 
2167         info->type = PORT_UNKNOWN;
2168         
2169         if (!port)
2170                 return;
2171 
2172         save_flags(flags); cli();
2173         
2174         /*
2175          * Do a simple existence test first; if we fail this, there's
2176          * no point trying anything else.
2177          *
2178          * 0x80 is used as a nonsense port to prevent against false
2179          * positives due to ISA bus float.  The assumption is that
2180          * 0x80 is a non-existent port; which should be safe since
2181          * include/asm/io.h also makes this assumption.
2182          */
2183         scratch = serial_inp(info, UART_IER);
2184         serial_outp(info, UART_IER, 0);
2185         outb(0xff, 0x080);
2186         scratch2 = serial_inp(info, UART_IER);
2187         serial_outp(info, UART_IER, scratch);
2188         if (scratch2) {
2189                 restore_flags(flags);
2190                 return;         /* We failed; there's nothing here */
2191         }
2192 
2193         /* 
2194          * Check to see if a UART is really there.  Certain broken
2195          * internal modems based on the Rockwell chipset fail this
2196          * test, because they apparently don't implement the loopback
2197          * test mode.  So this test is skipped on the COM 1 through
2198          * COM 4 ports.  This *should* be safe, since no board
2199          * manufacturer would be stupid enough to design a board
2200          * that conflicts with COM 1-4 --- we hope!
2201          */
2202         if (!(info->flags & ASYNC_SKIP_TEST)) {
2203                 scratch = serial_inp(info, UART_MCR);
2204                 serial_outp(info, UART_MCR, UART_MCR_LOOP | scratch);
2205                 scratch2 = serial_inp(info, UART_MSR);
2206                 serial_outp(info, UART_MCR, UART_MCR_LOOP | 0x0A);
2207                 status1 = serial_inp(info, UART_MSR) & 0xF0;
2208                 serial_outp(info, UART_MCR, scratch);
2209                 serial_outp(info, UART_MSR, scratch2);
2210                 if (status1 != 0x90) {
2211                         restore_flags(flags);
2212                         return;
2213                 }
2214         } 
2215         
2216         /*
2217          * If the AUTO_IRQ flag is set, try to do the automatic IRQ
2218          * detection.
2219          */
2220         if (info->flags & ASYNC_AUTO_IRQ)
2221                 info->irq = do_auto_irq(info);
2222                 
2223         serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
2224         scratch = serial_in(info, UART_IIR) >> 6;
2225         info->xmit_fifo_size = 1;
2226         switch (scratch) {
2227                 case 0:
2228                         info->type = PORT_16450;
2229                         break;
2230                 case 1:
2231                         info->type = PORT_UNKNOWN;
2232                         break;
2233                 case 2:
2234                         info->type = PORT_16550;
2235                         break;
2236                 case 3:
2237                         info->type = PORT_16550A;
2238                         info->xmit_fifo_size = 16;
2239                         break;
2240         }
2241         if (info->type == PORT_16450) {
2242                 scratch = serial_in(info, UART_SCR);
2243                 serial_outp(info, UART_SCR, 0xa5);
2244                 status1 = serial_in(info, UART_SCR);
2245                 serial_outp(info, UART_SCR, 0x5a);
2246                 status2 = serial_in(info, UART_SCR);
2247                 serial_outp(info, UART_SCR, scratch);
2248 
2249                 if ((status1 != 0xa5) || (status2 != 0x5a))
2250                         info->type = PORT_8250;
2251         }
2252 
2253         /*
2254          * Reset the UART.
2255          */
2256         serial_outp(info, UART_MCR, 0x00);
2257         serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
2258                                      UART_FCR_CLEAR_XMIT));
2259         (void)serial_in(info, UART_RX);
2260         
2261         restore_flags(flags);
2262 }
2263 
2264 /*
2265  * The serial driver boot-time initialization code!
2266  */
2267 long rs_init(long kmem_start)
     /* [previous][next][first][last][top][bottom][index][help] */
2268 {
2269         int i;
2270         struct async_struct * info;
2271         
2272         bh_base[SERIAL_BH].routine = do_serial_bh;
2273         timer_table[RS_TIMER].fn = rs_timer;
2274         timer_table[RS_TIMER].expires = 0;
2275 #ifdef CONFIG_AUTO_IRQ
2276         rs_wild_int_mask = check_wild_interrupts(1);
2277 #endif
2278 
2279         for (i = 0; i < 16; i++) {
2280                 IRQ_ports[i] = 0;
2281                 IRQ_timeout[i] = 0;
2282         }
2283         
2284         show_serial_version();
2285 
2286         /* Initialize the tty_driver structure */
2287         
2288         memset(&serial_driver, 0, sizeof(struct tty_driver));
2289         serial_driver.magic = TTY_DRIVER_MAGIC;
2290         serial_driver.name = "ttyS";
2291         serial_driver.major = TTY_MAJOR;
2292         serial_driver.minor_start = 64;
2293         serial_driver.num = NR_PORTS;
2294         serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
2295         serial_driver.subtype = SERIAL_TYPE_NORMAL;
2296         serial_driver.init_termios = tty_std_termios;
2297         serial_driver.init_termios.c_cflag =
2298                 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2299         serial_driver.flags = TTY_DRIVER_REAL_RAW;
2300         serial_driver.refcount = &serial_refcount;
2301         serial_driver.table = serial_table;
2302         serial_driver.termios = serial_termios;
2303         serial_driver.termios_locked = serial_termios_locked;
2304 
2305         serial_driver.open = rs_open;
2306         serial_driver.close = rs_close;
2307         serial_driver.write = rs_write;
2308         serial_driver.put_char = rs_put_char;
2309         serial_driver.flush_chars = rs_flush_chars;
2310         serial_driver.write_room = rs_write_room;
2311         serial_driver.chars_in_buffer = rs_chars_in_buffer;
2312         serial_driver.flush_buffer = rs_flush_buffer;
2313         serial_driver.ioctl = rs_ioctl;
2314         serial_driver.throttle = rs_throttle;
2315         serial_driver.unthrottle = rs_unthrottle;
2316         serial_driver.set_termios = rs_set_termios;
2317         serial_driver.stop = rs_stop;
2318         serial_driver.start = rs_start;
2319         serial_driver.hangup = rs_hangup;
2320 
2321         /*
2322          * The callout device is just like normal device except for
2323          * major number and the subtype code.
2324          */
2325         callout_driver = serial_driver;
2326         callout_driver.name = "cua";
2327         callout_driver.major = TTYAUX_MAJOR;
2328         callout_driver.subtype = SERIAL_TYPE_CALLOUT;
2329 
2330         if (tty_register_driver(&serial_driver))
2331                 panic("Couldn't register serial driver\n");
2332         if (tty_register_driver(&callout_driver))
2333                 panic("Couldn't register callout driver\n");
2334         
2335         for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) {
2336                 info->magic = SERIAL_MAGIC;
2337                 info->line = i;
2338                 info->tty = 0;
2339                 info->type = PORT_UNKNOWN;
2340                 info->custom_divisor = 0;
2341                 info->close_delay = 50;
2342                 info->x_char = 0;
2343                 info->event = 0;
2344                 info->count = 0;
2345                 info->blocked_open = 0;
2346                 info->tqueue.routine = do_softint;
2347                 info->tqueue.data = info;
2348                 info->callout_termios =callout_driver.init_termios;
2349                 info->normal_termios = serial_driver.init_termios;
2350                 info->open_wait = 0;
2351                 info->close_wait = 0;
2352                 info->next_port = 0;
2353                 info->prev_port = 0;
2354                 if (info->irq == 2)
2355                         info->irq = 9;
2356                 if (!(info->flags & ASYNC_BOOT_AUTOCONF))
2357                         continue;
2358                 autoconfig(info);
2359                 if (info->type == PORT_UNKNOWN)
2360                         continue;
2361                 printk("tty%02d%s at 0x%04x (irq = %d)", info->line, 
2362                        (info->flags & ASYNC_FOURPORT) ? " FourPort" : "",
2363                        info->port, info->irq);
2364                 switch (info->type) {
2365                         case PORT_8250:
2366                                 printk(" is a 8250\n");
2367                                 break;
2368                         case PORT_16450:
2369                                 printk(" is a 16450\n");
2370                                 break;
2371                         case PORT_16550:
2372                                 printk(" is a 16550\n");
2373                                 break;
2374                         case PORT_16550A:
2375                                 printk(" is a 16550A\n");
2376                                 break;
2377                         default:
2378                                 printk("\n");
2379                                 break;
2380                 }
2381         }
2382         return kmem_start;
2383 }
2384 
2385 /*
2386  * register_serial and unregister_serial allows for serial ports to be
2387  * configured at run-time, to support PCMCIA modems.
2388  */
2389 int register_serial(struct serial_struct *req)
     /* [previous][next][first][last][top][bottom][index][help] */
2390 {
2391         int i;
2392         unsigned long flags;
2393         struct async_struct *info;
2394 
2395         save_flags(flags);
2396         cli();
2397         for (i = 0; i < NR_PORTS; i++) {
2398                 if (rs_table[i].port == req->port)
2399                         break;
2400         }
2401         if (i == NR_PORTS) {
2402                 for (i = 0; i < NR_PORTS; i++)
2403                         if ((rs_table[i].type == PORT_UNKNOWN) &&
2404                             (rs_table[i].count == 0))
2405                                 break;
2406         }
2407         if (i == NR_PORTS) {
2408                 restore_flags(flags);
2409                 return -1;
2410         }
2411         info = &rs_table[i];
2412         if (rs_table[i].count) {
2413                 restore_flags(flags);
2414                 printk("Couldn't configure serial #%d (port=%d,irq=%d): "
2415                        "device already open\n", i, req->port, req->irq);
2416                 return -1;
2417         }
2418         info->irq = req->irq;
2419         info->port = req->port;
2420         autoconfig(info);
2421         if (info->type == PORT_UNKNOWN) {
2422                 restore_flags(flags);
2423                 printk("register_serial(): autoconfig failed\n");
2424                 return -1;
2425         }
2426         printk("tty%02d at 0x%04x (irq = %d)", info->line, 
2427                info->port, info->irq);
2428         switch (info->type) {
2429         case PORT_8250:
2430                 printk(" is a 8250\n"); break;
2431         case PORT_16450:
2432                 printk(" is a 16450\n"); break;
2433         case PORT_16550:
2434                 printk(" is a 16550\n"); break;
2435         case PORT_16550A:
2436                 printk(" is a 16550A\n"); break;
2437         default:
2438                 printk("\n"); break;
2439         }
2440         restore_flags(flags);
2441         return info->line;
2442 }
2443 
2444 void unregister_serial(int line)
     /* [previous][next][first][last][top][bottom][index][help] */
2445 {
2446         unsigned long flags;
2447         struct async_struct *info = &rs_table[line];
2448 
2449         save_flags(flags);
2450         cli();
2451         if (info->tty)
2452                 tty_hangup(info->tty);
2453         info->type = PORT_UNKNOWN;
2454         printk("tty%02d unloaded\n", info->line);
2455         restore_flags(flags);
2456 }

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