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 = (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)
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348 static void rs_probe(int irq)
349 {
350 rs_irq_triggered = irq;
351 rs_triggered |= 1 << irq;
352 return;
353 }
354
355
356
357
358
359 static _INLINE_ void rs_sched_event(struct async_struct *info,
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,
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)
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)
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
501
502 static void rs_interrupt(int irq)
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;
544 }
545 continue;
546 }
547 } while (end_mark != info);
548 }
549
550
551
552
553 static void rs_interrupt_single(int irq)
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
585
586
587
588
589 static void rs_interrupt(int irq)
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;
630 }
631 }
632 }
633
634
635
636
637
638 do
639 serial_outp(info, UART_IER, info->IER);
640 while ((info = info->next_port) != NULL);
641 }
642
643
644
645
646 static void rs_interrupt_single(int irq)
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
670
671 serial_outp(info, UART_IER, info->IER);
672 }
673
674 #endif
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691 static void do_serial_bh(void *unused)
692 {
693 run_task_queue(&tq_serial);
694 }
695
696 static void do_softint(void *private_)
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
721
722
723
724
725
726 static void rs_timer(void)
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
767
768
769
770
771
772
773
774
775
776
777
778
779 static int grab_all_interrupts(int dontgrab)
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
794
795 static void free_all_interrupts(int irq_lines)
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
807
808
809
810 static void figure_IRQ_timeout(int irq)
811 {
812 struct async_struct *info;
813 int timeout = 6000;
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)
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
860
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
871
872
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
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
910
911
912 (void) serial_inp(info, UART_RX);
913 (void) serial_inp(info, UART_IIR);
914 (void) serial_inp(info, UART_MSR);
915
916
917
918
919 serial_outp(info, UART_LCR, UART_LCR_WLEN8);
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
933
934 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
935 serial_outp(info, UART_IER, info->IER);
936
937 if (info->flags & ASYNC_FOURPORT) {
938
939 ICP = (info->port & 0xFE0) | 0x01F;
940 outb_p(0x80, ICP);
941 (void) inb_p(ICP);
942 }
943
944
945
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
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
968
969 timer_table[RS_TIMER].expires = jiffies + 2;
970 timer_active |= 1 << RS_TIMER;
971
972
973
974
975 change_speed(info);
976
977 info->flags |= ASYNC_INITIALIZED;
978 restore_flags(flags);
979 return 0;
980 }
981
982
983
984
985
986 static void shutdown(struct async_struct * info)
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();
1000
1001
1002
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
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);
1035 if (info->flags & ASYNC_FOURPORT) {
1036
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
1047 serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
1048 UART_FCR_CLEAR_XMIT));
1049 (void)serial_in(info, UART_RX);
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
1060
1061
1062 static void change_speed(struct async_struct *info)
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
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
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
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
1156
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);
1164 serial_outp(info, UART_DLL, quot & 0xff);
1165 serial_outp(info, UART_DLM, quot >> 8);
1166 serial_outp(info, UART_LCR, cval);
1167 serial_outp(info, UART_FCR, fcr);
1168 sti();
1169 }
1170
1171 static void rs_put_char(struct tty_struct *tty, unsigned char ch)
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)
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,
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)
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)
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)
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
1298
1299
1300
1301
1302
1303 static void rs_throttle(struct tty_struct * tty)
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)
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
1355
1356
1357
1358 static int get_serial_info(struct async_struct * info,
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,
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
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
1431
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
1444
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)
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,
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)
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
1553
1554 static void send_break( struct async_struct * info, int duration)
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
1569
1570
1571 static int check_wild_interrupts(int doprint)
1572 {
1573 int i, mask;
1574 int wild_interrupts = 0;
1575 int irq_lines;
1576 unsigned long timeout;
1577 unsigned long flags;
1578
1579
1580 save_flags(flags); sti();
1581
1582 irq_lines = grab_all_interrupts(0);
1583
1584
1585
1586
1587
1588 timeout = jiffies+10;
1589 while (timeout >= jiffies)
1590 ;
1591
1592 rs_triggered = 0;
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,
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:
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);
1629 return 0;
1630 case TCSBRKP:
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)
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
1727
1728
1729
1730
1731
1732
1733
1734 static void rs_close(struct tty_struct *tty, struct file * filp)
1735 {
1736 struct async_struct * info = (struct async_struct *)tty->driver_data;
1737 unsigned long flags;
1738
1739 if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
1740 return;
1741
1742 save_flags(flags); cli();
1743
1744 if (tty_hung_up_p(filp)) {
1745 restore_flags(flags);
1746 return;
1747 }
1748
1749 #ifdef SERIAL_DEBUG_OPEN
1750 printk("rs_close ttys%d, count = %d\n", info->line, info->count);
1751 #endif
1752 if ((tty->count == 1) && (info->count != 1)) {
1753
1754
1755
1756
1757
1758
1759
1760 printk("rs_close: bad serial port count; tty->count is 1, "
1761 "info->count is %d\n", info->count);
1762 info->count = 1;
1763 }
1764 if (--info->count < 0) {
1765 printk("rs_close: bad serial port count for ttys%d: %d\n",
1766 info->line, info->count);
1767 info->count = 0;
1768 }
1769 if (info->count) {
1770 restore_flags(flags);
1771 return;
1772 }
1773 info->flags |= ASYNC_CLOSING;
1774
1775
1776
1777
1778 if (info->flags & ASYNC_NORMAL_ACTIVE)
1779 info->normal_termios = *tty->termios;
1780 if (info->flags & ASYNC_CALLOUT_ACTIVE)
1781 info->callout_termios = *tty->termios;
1782 if (info->flags & ASYNC_INITIALIZED) {
1783 wait_until_sent(tty, 3000);
1784
1785
1786
1787
1788
1789 while (!(serial_inp(info, UART_LSR) & UART_LSR_TEMT)) {
1790 current->state = TASK_INTERRUPTIBLE;
1791 current->timeout = jiffies + info->timeout;
1792 schedule();
1793 }
1794 }
1795 shutdown(info);
1796 if (tty->driver.flush_buffer)
1797 tty->driver.flush_buffer(tty);
1798 if (tty->ldisc.flush_buffer)
1799 tty->ldisc.flush_buffer(tty);
1800 info->event = 0;
1801 info->tty = 0;
1802 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1803 if (tty->ldisc.close)
1804 (tty->ldisc.close)(tty);
1805 tty->ldisc = ldiscs[N_TTY];
1806 tty->termios->c_line = N_TTY;
1807 if (tty->ldisc.open)
1808 (tty->ldisc.open)(tty);
1809 }
1810 if (info->blocked_open) {
1811 if (info->close_delay) {
1812 current->state = TASK_INTERRUPTIBLE;
1813 current->timeout = jiffies + info->close_delay;
1814 schedule();
1815 }
1816 wake_up_interruptible(&info->open_wait);
1817 }
1818 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
1819 ASYNC_CLOSING);
1820 wake_up_interruptible(&info->close_wait);
1821 restore_flags(flags);
1822 }
1823
1824
1825
1826
1827 void rs_hangup(struct tty_struct *tty)
1828 {
1829 struct async_struct * info = (struct async_struct *)tty->driver_data;
1830
1831 if (serial_paranoia_check(info, tty->device, "rs_hangup"))
1832 return;
1833
1834 shutdown(info);
1835 info->event = 0;
1836 info->count = 0;
1837 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
1838 info->tty = 0;
1839 wake_up_interruptible(&info->open_wait);
1840 }
1841
1842
1843
1844
1845
1846
1847 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1848 struct async_struct *info)
1849 {
1850 struct wait_queue wait = { current, NULL };
1851 int retval;
1852 int do_clocal = 0;
1853
1854
1855
1856
1857
1858 if (info->flags & ASYNC_CLOSING) {
1859 interruptible_sleep_on(&info->close_wait);
1860 #ifdef SERIAL_DO_RESTART
1861 if (info->flags & ASYNC_HUP_NOTIFY)
1862 return -EAGAIN;
1863 else
1864 return -ERESTARTSYS;
1865 #else
1866 return -EAGAIN;
1867 #endif
1868 }
1869
1870
1871
1872
1873
1874 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
1875 if (info->flags & ASYNC_NORMAL_ACTIVE)
1876 return -EBUSY;
1877 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1878 (info->flags & ASYNC_SESSION_LOCKOUT) &&
1879 (info->session != current->session))
1880 return -EBUSY;
1881 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1882 (info->flags & ASYNC_PGRP_LOCKOUT) &&
1883 (info->pgrp != current->pgrp))
1884 return -EBUSY;
1885 info->flags |= ASYNC_CALLOUT_ACTIVE;
1886 return 0;
1887 }
1888
1889
1890
1891
1892
1893 if (filp->f_flags & O_NONBLOCK) {
1894 if (info->flags & ASYNC_CALLOUT_ACTIVE)
1895 return -EBUSY;
1896 info->flags |= ASYNC_NORMAL_ACTIVE;
1897 return 0;
1898 }
1899
1900 if (info->normal_termios.c_cflag & CLOCAL)
1901 do_clocal = 1;
1902
1903
1904
1905
1906
1907
1908
1909
1910 retval = 0;
1911 add_wait_queue(&info->open_wait, &wait);
1912 #ifdef SERIAL_DEBUG_OPEN
1913 printk("block_til_ready before block: ttys%d, count = %d\n",
1914 info->line, info->count);
1915 #endif
1916 info->count--;
1917 info->blocked_open++;
1918 while (1) {
1919 cli();
1920 if (!(info->flags & ASYNC_CALLOUT_ACTIVE))
1921 serial_out(info, UART_MCR,
1922 serial_inp(info, UART_MCR) |
1923 (UART_MCR_DTR | UART_MCR_RTS));
1924 sti();
1925 current->state = TASK_INTERRUPTIBLE;
1926 if (tty_hung_up_p(filp) ||
1927 !(info->flags & ASYNC_INITIALIZED)) {
1928 #ifdef SERIAL_DO_RESTART
1929 if (info->flags & ASYNC_HUP_NOTIFY)
1930 retval = -EAGAIN;
1931 else
1932 retval = -ERESTARTSYS;
1933 #else
1934 retval = -EAGAIN;
1935 #endif
1936 break;
1937 }
1938 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
1939 !(info->flags & ASYNC_CLOSING) &&
1940 (do_clocal || (serial_in(info, UART_MSR) &
1941 UART_MSR_DCD)))
1942 break;
1943 if (current->signal & ~current->blocked) {
1944 retval = -ERESTARTSYS;
1945 break;
1946 }
1947 #ifdef SERIAL_DEBUG_OPEN
1948 printk("block_til_ready blocking: ttys%d, count = %d\n",
1949 info->line, info->count);
1950 #endif
1951 schedule();
1952 }
1953 current->state = TASK_RUNNING;
1954 remove_wait_queue(&info->open_wait, &wait);
1955 if (!tty_hung_up_p(filp))
1956 info->count++;
1957 info->blocked_open--;
1958 #ifdef SERIAL_DEBUG_OPEN
1959 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1960 info->line, info->count);
1961 #endif
1962 if (retval)
1963 return retval;
1964 info->flags |= ASYNC_NORMAL_ACTIVE;
1965 return 0;
1966 }
1967
1968
1969
1970
1971
1972
1973
1974 int rs_open(struct tty_struct *tty, struct file * filp)
1975 {
1976 struct async_struct *info;
1977 int retval, line;
1978
1979 line = MINOR(tty->device) - tty->driver.minor_start;
1980 if ((line < 0) || (line >= NR_PORTS))
1981 return -ENODEV;
1982 info = rs_table + line;
1983 if (serial_paranoia_check(info, tty->device, "rs_open"))
1984 return -ENODEV;
1985
1986 #ifdef SERIAL_DEBUG_OPEN
1987 printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
1988 info->count);
1989 #endif
1990 info->count++;
1991 tty->driver_data = info;
1992 info->tty = tty;
1993
1994 if (!tmp_buf) {
1995 tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
1996 if (!tmp_buf)
1997 return -ENOMEM;
1998 }
1999
2000
2001
2002
2003 retval = startup(info);
2004 if (retval)
2005 return retval;
2006
2007 retval = block_til_ready(tty, filp, info);
2008 if (retval) {
2009 #ifdef SERIAL_DEBUG_OPEN
2010 printk("rs_open returning after block_til_ready with %d\n",
2011 retval);
2012 #endif
2013 return retval;
2014 }
2015
2016 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
2017 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
2018 *tty->termios = info->normal_termios;
2019 else
2020 *tty->termios = info->callout_termios;
2021 change_speed(info);
2022 }
2023
2024 info->session = current->session;
2025 info->pgrp = current->pgrp;
2026
2027 #ifdef SERIAL_DEBUG_OPEN
2028 printk("rs_open ttys%d successful...", info->line);
2029 #endif
2030 return 0;
2031 }
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046 static void show_serial_version(void)
2047 {
2048 printk("Serial driver version 4.00 with");
2049 #ifdef CONFIG_HUB6
2050 printk(" HUB-6");
2051 #define SERIAL_OPT
2052 #endif
2053 #ifdef SERIAL_OPT
2054 printk(" enabled\n");
2055 #else
2056 printk(" no serial options enabled\n");
2057 #endif
2058 #undef SERIAL_OPT
2059 }
2060
2061
2062
2063
2064
2065
2066 static int get_auto_irq(struct async_struct *info)
2067 {
2068 unsigned char save_MCR, save_IER, save_ICP=0;
2069 unsigned short ICP=0, port = info->port;
2070 unsigned long timeout;
2071
2072
2073
2074
2075 rs_irq_triggered = 0;
2076 cli();
2077 save_IER = serial_inp(info, UART_IER);
2078 save_MCR = serial_inp(info, UART_MCR);
2079 if (info->flags & ASYNC_FOURPORT) {
2080 serial_outp(info, UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
2081 serial_outp(info, UART_IER, 0x0f);
2082 ICP = (port & 0xFE0) | 0x01F;
2083 save_ICP = inb_p(ICP);
2084 outb_p(0x80, ICP);
2085 (void) inb_p(ICP);
2086 } else {
2087 serial_outp(info, UART_MCR,
2088 UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
2089 serial_outp(info, UART_IER, 0x0f);
2090 }
2091 sti();
2092
2093
2094
2095 (void)serial_inp(info, UART_LSR);
2096 (void)serial_inp(info, UART_RX);
2097 (void)serial_inp(info, UART_IIR);
2098 (void)serial_inp(info, UART_MSR);
2099
2100 timeout = jiffies+2;
2101 while (timeout >= jiffies) {
2102 if (rs_irq_triggered)
2103 break;
2104 }
2105
2106
2107
2108 cli();
2109 serial_outp(info, UART_IER, save_IER);
2110 serial_outp(info, UART_MCR, save_MCR);
2111 if (info->flags & ASYNC_FOURPORT)
2112 outb_p(save_ICP, ICP);
2113 sti();
2114 return(rs_irq_triggered);
2115 }
2116
2117
2118
2119
2120
2121 static int do_auto_irq(struct async_struct * info)
2122 {
2123 unsigned port = info->port;
2124 int irq_lines = 0;
2125 int irq_try_1 = 0, irq_try_2 = 0;
2126 int retries;
2127 unsigned long flags;
2128
2129 if (!port)
2130 return 0;
2131
2132
2133 save_flags(flags); sti();
2134
2135 irq_lines = grab_all_interrupts(rs_wild_int_mask);
2136
2137 for (retries = 0; retries < 5; retries++) {
2138 if (!irq_try_1)
2139 irq_try_1 = get_auto_irq(info);
2140 if (!irq_try_2)
2141 irq_try_2 = get_auto_irq(info);
2142 if (irq_try_1 && irq_try_2) {
2143 if (irq_try_1 == irq_try_2)
2144 break;
2145 irq_try_1 = irq_try_2 = 0;
2146 }
2147 }
2148 restore_flags(flags);
2149 free_all_interrupts(irq_lines);
2150 return (irq_try_1 == irq_try_2) ? irq_try_1 : 0;
2151 }
2152
2153
2154
2155
2156
2157
2158
2159
2160 static void autoconfig(struct async_struct * info)
2161 {
2162 unsigned char status1, status2, scratch, scratch2;
2163 unsigned port = info->port;
2164 unsigned long flags;
2165
2166 info->type = PORT_UNKNOWN;
2167
2168 if (!port)
2169 return;
2170
2171 save_flags(flags); cli();
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182 scratch = serial_inp(info, UART_IER);
2183 serial_outp(info, UART_IER, 0);
2184 outb(0xff, 0x080);
2185 scratch2 = serial_inp(info, UART_IER);
2186 serial_outp(info, UART_IER, scratch);
2187 if (scratch2) {
2188 restore_flags(flags);
2189 return;
2190 }
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201 if (!(info->flags & ASYNC_SKIP_TEST)) {
2202 scratch = serial_inp(info, UART_MCR);
2203 serial_outp(info, UART_MCR, UART_MCR_LOOP | scratch);
2204 scratch2 = serial_inp(info, UART_MSR);
2205 serial_outp(info, UART_MCR, UART_MCR_LOOP | 0x0A);
2206 status1 = serial_inp(info, UART_MSR) & 0xF0;
2207 serial_outp(info, UART_MCR, scratch);
2208 serial_outp(info, UART_MSR, scratch2);
2209 if (status1 != 0x90) {
2210 restore_flags(flags);
2211 return;
2212 }
2213 }
2214
2215
2216
2217
2218
2219 if (info->flags & ASYNC_AUTO_IRQ)
2220 info->irq = do_auto_irq(info);
2221
2222 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
2223 scratch = serial_in(info, UART_IIR) >> 6;
2224 info->xmit_fifo_size = 1;
2225 switch (scratch) {
2226 case 0:
2227 info->type = PORT_16450;
2228 break;
2229 case 1:
2230 info->type = PORT_UNKNOWN;
2231 break;
2232 case 2:
2233 info->type = PORT_16550;
2234 break;
2235 case 3:
2236 info->type = PORT_16550A;
2237 info->xmit_fifo_size = 16;
2238 break;
2239 }
2240 if (info->type == PORT_16450) {
2241 scratch = serial_in(info, UART_SCR);
2242 serial_outp(info, UART_SCR, 0xa5);
2243 status1 = serial_in(info, UART_SCR);
2244 serial_outp(info, UART_SCR, 0x5a);
2245 status2 = serial_in(info, UART_SCR);
2246 serial_outp(info, UART_SCR, scratch);
2247
2248 if ((status1 != 0xa5) || (status2 != 0x5a))
2249 info->type = PORT_8250;
2250 }
2251
2252
2253
2254
2255 serial_outp(info, UART_MCR, 0x00);
2256 serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
2257 UART_FCR_CLEAR_XMIT));
2258 (void)serial_in(info, UART_RX);
2259
2260 restore_flags(flags);
2261 }
2262
2263
2264
2265
2266 long rs_init(long kmem_start)
2267 {
2268 int i;
2269 struct async_struct * info;
2270
2271 bh_base[SERIAL_BH].routine = do_serial_bh;
2272 timer_table[RS_TIMER].fn = rs_timer;
2273 timer_table[RS_TIMER].expires = 0;
2274 #ifdef CONFIG_AUTO_IRQ
2275 rs_wild_int_mask = check_wild_interrupts(1);
2276 #endif
2277
2278 for (i = 0; i < 16; i++) {
2279 IRQ_ports[i] = 0;
2280 IRQ_timeout[i] = 0;
2281 }
2282
2283 show_serial_version();
2284
2285
2286
2287 memset(&serial_driver, 0, sizeof(struct tty_driver));
2288 serial_driver.magic = TTY_DRIVER_MAGIC;
2289 serial_driver.name = "ttyS";
2290 serial_driver.major = TTY_MAJOR;
2291 serial_driver.minor_start = 64;
2292 serial_driver.num = NR_PORTS;
2293 serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
2294 serial_driver.subtype = SERIAL_TYPE_NORMAL;
2295 serial_driver.init_termios = tty_std_termios;
2296 serial_driver.init_termios.c_cflag =
2297 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2298 serial_driver.flags = TTY_DRIVER_REAL_RAW;
2299 serial_driver.refcount = &serial_refcount;
2300 serial_driver.table = serial_table;
2301 serial_driver.termios = serial_termios;
2302 serial_driver.termios_locked = serial_termios_locked;
2303
2304 serial_driver.open = rs_open;
2305 serial_driver.close = rs_close;
2306 serial_driver.write = rs_write;
2307 serial_driver.put_char = rs_put_char;
2308 serial_driver.flush_chars = rs_flush_chars;
2309 serial_driver.write_room = rs_write_room;
2310 serial_driver.chars_in_buffer = rs_chars_in_buffer;
2311 serial_driver.flush_buffer = rs_flush_buffer;
2312 serial_driver.ioctl = rs_ioctl;
2313 serial_driver.throttle = rs_throttle;
2314 serial_driver.unthrottle = rs_unthrottle;
2315 serial_driver.set_termios = rs_set_termios;
2316 serial_driver.stop = rs_stop;
2317 serial_driver.start = rs_start;
2318 serial_driver.hangup = rs_hangup;
2319
2320
2321
2322
2323
2324 callout_driver = serial_driver;
2325 callout_driver.name = "cua";
2326 callout_driver.major = TTYAUX_MAJOR;
2327 callout_driver.subtype = SERIAL_TYPE_CALLOUT;
2328
2329 if (tty_register_driver(&serial_driver))
2330 panic("Couldn't register serial driver\n");
2331 if (tty_register_driver(&callout_driver))
2332 panic("Couldn't register callout driver\n");
2333
2334 for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) {
2335 info->magic = SERIAL_MAGIC;
2336 info->line = i;
2337 info->tty = 0;
2338 info->type = PORT_UNKNOWN;
2339 info->custom_divisor = 0;
2340 info->close_delay = 50;
2341 info->x_char = 0;
2342 info->event = 0;
2343 info->count = 0;
2344 info->blocked_open = 0;
2345 info->tqueue.routine = do_softint;
2346 info->tqueue.data = info;
2347 info->callout_termios =callout_driver.init_termios;
2348 info->normal_termios = serial_driver.init_termios;
2349 info->open_wait = 0;
2350 info->close_wait = 0;
2351 info->next_port = 0;
2352 info->prev_port = 0;
2353 if (info->irq == 2)
2354 info->irq = 9;
2355 if (!(info->flags & ASYNC_BOOT_AUTOCONF))
2356 continue;
2357 autoconfig(info);
2358 if (info->type == PORT_UNKNOWN)
2359 continue;
2360 printk("tty%02d%s at 0x%04x (irq = %d)", info->line,
2361 (info->flags & ASYNC_FOURPORT) ? " FourPort" : "",
2362 info->port, info->irq);
2363 switch (info->type) {
2364 case PORT_8250:
2365 printk(" is a 8250\n");
2366 break;
2367 case PORT_16450:
2368 printk(" is a 16450\n");
2369 break;
2370 case PORT_16550:
2371 printk(" is a 16550\n");
2372 break;
2373 case PORT_16550A:
2374 printk(" is a 16550A\n");
2375 break;
2376 default:
2377 printk("\n");
2378 break;
2379 }
2380 }
2381 return kmem_start;
2382 }
2383
2384
2385
2386
2387
2388 int register_serial(struct serial_struct *req)
2389 {
2390 int i;
2391 unsigned long flags;
2392 struct async_struct *info;
2393
2394 save_flags(flags);
2395 cli();
2396 for (i = 0; i < NR_PORTS; i++) {
2397 if (rs_table[i].port == req->port)
2398 break;
2399 }
2400 if (i == NR_PORTS) {
2401 for (i = 0; i < NR_PORTS; i++)
2402 if ((rs_table[i].type == PORT_UNKNOWN) &&
2403 (rs_table[i].count == 0))
2404 break;
2405 }
2406 if (i == NR_PORTS) {
2407 restore_flags(flags);
2408 return -1;
2409 }
2410 info = &rs_table[i];
2411 if (rs_table[i].count) {
2412 restore_flags(flags);
2413 printk("Couldn't configure serial #%d (port=%d,irq=%d): "
2414 "device already open\n", i, req->port, req->irq);
2415 return -1;
2416 }
2417 info->irq = req->irq;
2418 info->port = req->port;
2419 autoconfig(info);
2420 if (info->type == PORT_UNKNOWN) {
2421 restore_flags(flags);
2422 printk("register_serial(): autoconfig failed\n");
2423 return -1;
2424 }
2425 printk("tty%02d at 0x%04x (irq = %d)", info->line,
2426 info->port, info->irq);
2427 switch (info->type) {
2428 case PORT_8250:
2429 printk(" is a 8250\n"); break;
2430 case PORT_16450:
2431 printk(" is a 16450\n"); break;
2432 case PORT_16550:
2433 printk(" is a 16550\n"); break;
2434 case PORT_16550A:
2435 printk(" is a 16550A\n"); break;
2436 default:
2437 printk("\n"); break;
2438 }
2439 restore_flags(flags);
2440 return info->line;
2441 }
2442
2443 void unregister_serial(int line)
2444 {
2445 unsigned long flags;
2446 struct async_struct *info = &rs_table[line];
2447
2448 save_flags(flags);
2449 cli();
2450 if (info->tty)
2451 tty_hangup(info->tty);
2452 info->type = PORT_UNKNOWN;
2453 printk("tty%02d unloaded\n", info->line);
2454 restore_flags(flags);
2455 }