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