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

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