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 &&
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
785 for (i = 0, mask = 1; i < 16; i++, mask <<= 1) {
786 if (!(mask & dontgrab) && !request_irq(i, rs_probe, SA_INTERRUPT, "serial probe")) {
787 irq_lines |= mask;
788 }
789 }
790 return irq_lines;
791 }
792
793
794
795
796 static void free_all_interrupts(int irq_lines)
797 {
798 int i;
799
800 for (i = 0; i < 16; i++) {
801 if (irq_lines & (1 << i))
802 free_irq(i);
803 }
804 }
805
806
807
808
809
810
811 static void figure_IRQ_timeout(int irq)
812 {
813 struct async_struct *info;
814 int timeout = 6000;
815
816 info = IRQ_ports[irq];
817 if (!info) {
818 IRQ_timeout[irq] = 6000;
819 return;
820 }
821 while (info) {
822 if (info->timeout < timeout)
823 timeout = info->timeout;
824 info = info->next_port;
825 }
826 if (!irq)
827 timeout = timeout / 2;
828 IRQ_timeout[irq] = timeout ? timeout : 1;
829 }
830
831 static int startup(struct async_struct * info)
832 {
833 unsigned short ICP;
834 unsigned long flags;
835 int retval;
836 void (*handler)(int);
837
838 if (info->flags & ASYNC_INITIALIZED)
839 return 0;
840
841 if (!info->port || !info->type) {
842 if (info->tty)
843 set_bit(TTY_IO_ERROR, &info->tty->flags);
844 return 0;
845 }
846
847 if (!info->xmit_buf) {
848 info->xmit_buf = (unsigned char *) get_free_page(GFP_KERNEL);
849 if (!info->xmit_buf)
850 return -ENOMEM;
851 }
852
853 save_flags(flags); cli();
854
855 #ifdef SERIAL_DEBUG_OPEN
856 printk("starting up ttys%d (irq %d)...", info->line, info->irq);
857 #endif
858
859
860
861
862
863 if (info->type == PORT_16550A) {
864 serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
865 UART_FCR_CLEAR_XMIT));
866 info->xmit_fifo_size = 16;
867 } else
868 info->xmit_fifo_size = 1;
869
870
871
872
873
874
875 if (serial_inp(info, UART_LSR) == 0xff) {
876 restore_flags(flags);
877 if (suser()) {
878 if (info->tty)
879 set_bit(TTY_IO_ERROR, &info->tty->flags);
880 return 0;
881 } else
882 return -ENODEV;
883 }
884
885
886
887
888 if (info->irq && (!IRQ_ports[info->irq] ||
889 !IRQ_ports[info->irq]->next_port)) {
890 if (IRQ_ports[info->irq]) {
891 free_irq(info->irq);
892 handler = rs_interrupt;
893 } else
894 handler = rs_interrupt_single;
895
896 retval = request_irq(info->irq, handler, SA_INTERRUPT, "serial");
897 if (retval) {
898 restore_flags(flags);
899 if (suser()) {
900 if (info->tty)
901 set_bit(TTY_IO_ERROR,
902 &info->tty->flags);
903 return 0;
904 } else
905 return retval;
906 }
907 }
908
909
910
911
912
913 (void) serial_inp(info, UART_RX);
914 (void) serial_inp(info, UART_IIR);
915 (void) serial_inp(info, UART_MSR);
916
917
918
919
920 serial_outp(info, UART_LCR, UART_LCR_WLEN8);
921 if (info->flags & ASYNC_FOURPORT) {
922 info->MCR = UART_MCR_DTR | UART_MCR_RTS;
923 info->MCR_noint = UART_MCR_DTR | UART_MCR_OUT1;
924 } else {
925 info->MCR = UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2;
926 info->MCR_noint = UART_MCR_DTR | UART_MCR_RTS;
927 }
928 if (info->irq == 0)
929 info->MCR = info->MCR_noint;
930 serial_outp(info, UART_MCR, info->MCR);
931
932
933
934
935 info->IER = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
936 serial_outp(info, UART_IER, info->IER);
937
938 if (info->flags & ASYNC_FOURPORT) {
939
940 ICP = (info->port & 0xFE0) | 0x01F;
941 outb_p(0x80, ICP);
942 (void) inb_p(ICP);
943 }
944
945
946
947
948 (void)serial_inp(info, UART_LSR);
949 (void)serial_inp(info, UART_RX);
950 (void)serial_inp(info, UART_IIR);
951 (void)serial_inp(info, UART_MSR);
952
953 if (info->tty)
954 clear_bit(TTY_IO_ERROR, &info->tty->flags);
955 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
956
957
958
959
960 info->prev_port = 0;
961 info->next_port = IRQ_ports[info->irq];
962 if (info->next_port)
963 info->next_port->prev_port = info;
964 IRQ_ports[info->irq] = info;
965 figure_IRQ_timeout(info->irq);
966
967
968
969
970 timer_table[RS_TIMER].expires = jiffies + 2;
971 timer_active |= 1 << RS_TIMER;
972
973
974
975
976 change_speed(info);
977
978 info->flags |= ASYNC_INITIALIZED;
979 restore_flags(flags);
980 return 0;
981 }
982
983
984
985
986
987 static void shutdown(struct async_struct * info)
988 {
989 unsigned long flags;
990 int retval;
991
992 if (!(info->flags & ASYNC_INITIALIZED))
993 return;
994
995 #ifdef SERIAL_DEBUG_OPEN
996 printk("Shutting down serial port %d (irq %d)....", info->line,
997 info->irq);
998 #endif
999
1000 save_flags(flags); cli();
1001
1002
1003
1004
1005 if (info->next_port)
1006 info->next_port->prev_port = info->prev_port;
1007 if (info->prev_port)
1008 info->prev_port->next_port = info->next_port;
1009 else
1010 IRQ_ports[info->irq] = info->next_port;
1011 figure_IRQ_timeout(info->irq);
1012
1013
1014
1015
1016 if (info->irq && (!IRQ_ports[info->irq] ||
1017 !IRQ_ports[info->irq]->next_port)) {
1018 if (IRQ_ports[info->irq]) {
1019 free_irq(info->irq);
1020 retval = request_irq(info->irq, rs_interrupt_single, SA_INTERRUPT, "serial");
1021
1022 if (retval)
1023 printk("serial shutdown: request_irq: error %d"
1024 " Couldn't reacquire IRQ.\n", retval);
1025 } else
1026 free_irq(info->irq);
1027 }
1028
1029 if (info->xmit_buf) {
1030 free_page((unsigned long) info->xmit_buf);
1031 info->xmit_buf = 0;
1032 }
1033
1034 info->IER = 0;
1035 serial_outp(info, UART_IER, 0x00);
1036 if (info->flags & ASYNC_FOURPORT) {
1037
1038 (void) inb((info->port & 0xFE0) | 0x01F);
1039 }
1040
1041 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
1042 info->MCR &= ~(UART_MCR_DTR|UART_MCR_RTS);
1043 info->MCR_noint &= ~(UART_MCR_DTR|UART_MCR_RTS);
1044 }
1045 serial_outp(info, UART_MCR, info->MCR_noint);
1046
1047
1048 serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
1049 UART_FCR_CLEAR_XMIT));
1050 (void)serial_in(info, UART_RX);
1051
1052 if (info->tty)
1053 set_bit(TTY_IO_ERROR, &info->tty->flags);
1054
1055 info->flags &= ~ASYNC_INITIALIZED;
1056 restore_flags(flags);
1057 }
1058
1059
1060
1061
1062
1063 static void change_speed(struct async_struct *info)
1064 {
1065 unsigned short port;
1066 int quot = 0;
1067 unsigned cflag,cval,fcr;
1068 int i;
1069
1070 if (!info->tty || !info->tty->termios)
1071 return;
1072 cflag = info->tty->termios->c_cflag;
1073 if (!(port = info->port))
1074 return;
1075 i = cflag & CBAUD;
1076 if (i == 15) {
1077 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1078 i += 1;
1079 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1080 i += 2;
1081 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
1082 quot = info->custom_divisor;
1083 }
1084 if (quot) {
1085 info->timeout = ((info->xmit_fifo_size*HZ*15*quot) /
1086 info->baud_base) + 2;
1087 } else if (baud_table[i] == 134) {
1088 quot = (2*info->baud_base / 269);
1089 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
1090 } else if (baud_table[i]) {
1091 quot = info->baud_base / baud_table[i];
1092 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
1093 } else {
1094 quot = 0;
1095 info->timeout = 0;
1096 }
1097 if (quot) {
1098 info->MCR |= UART_MCR_DTR;
1099 info->MCR_noint |= UART_MCR_DTR;
1100 cli();
1101 serial_out(info, UART_MCR, info->MCR);
1102 sti();
1103 } else {
1104 info->MCR &= ~UART_MCR_DTR;
1105 info->MCR_noint &= ~UART_MCR_DTR;
1106 cli();
1107 serial_out(info, UART_MCR, info->MCR);
1108 sti();
1109 return;
1110 }
1111
1112 cval = cflag & (CSIZE | CSTOPB);
1113 cval >>= 4;
1114 if (cflag & PARENB)
1115 cval |= UART_LCR_PARITY;
1116 if (!(cflag & PARODD))
1117 cval |= UART_LCR_EPAR;
1118 if (info->type == PORT_16550A) {
1119 if ((info->baud_base / quot) < 2400)
1120 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_1;
1121 else
1122 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_TRIGGER_8;
1123 } else
1124 fcr = 0;
1125
1126
1127 info->IER &= ~UART_IER_MSI;
1128 if (cflag & CRTSCTS) {
1129 info->flags |= ASYNC_CTS_FLOW;
1130 info->IER |= UART_IER_MSI;
1131 } else
1132 info->flags &= ~ASYNC_CTS_FLOW;
1133 if (cflag & CLOCAL)
1134 info->flags &= ~ASYNC_CHECK_CD;
1135 else {
1136 info->flags |= ASYNC_CHECK_CD;
1137 info->IER |= UART_IER_MSI;
1138 }
1139 serial_out(info, UART_IER, info->IER);
1140
1141
1142
1143
1144 info->read_status_mask = UART_LSR_OE;
1145 if (I_INPCK(info->tty))
1146 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
1147 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
1148 info->read_status_mask |= UART_LSR_BI;
1149
1150 info->ignore_status_mask = 0;
1151 if (I_IGNPAR(info->tty))
1152 info->ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
1153 if (I_IGNBRK(info->tty)) {
1154 info->ignore_status_mask |= UART_LSR_BI;
1155
1156
1157
1158
1159 if (I_IGNPAR(info->tty))
1160 info->ignore_status_mask |= UART_LSR_OE;
1161 }
1162
1163 cli();
1164 serial_outp(info, UART_LCR, cval | UART_LCR_DLAB);
1165 serial_outp(info, UART_DLL, quot & 0xff);
1166 serial_outp(info, UART_DLM, quot >> 8);
1167 serial_outp(info, UART_LCR, cval);
1168 serial_outp(info, UART_FCR, fcr);
1169 sti();
1170 }
1171
1172 static void rs_put_char(struct tty_struct *tty, unsigned char ch)
1173 {
1174 struct async_struct *info = (struct async_struct *)tty->driver_data;
1175 unsigned long flags;
1176
1177 if (serial_paranoia_check(info, tty->device, "rs_put_char"))
1178 return;
1179
1180 if (!tty || !info->xmit_buf)
1181 return;
1182
1183 save_flags(flags); cli();
1184 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
1185 restore_flags(flags);
1186 return;
1187 }
1188
1189 info->xmit_buf[info->xmit_head++] = ch;
1190 info->xmit_head &= SERIAL_XMIT_SIZE-1;
1191 info->xmit_cnt++;
1192 restore_flags(flags);
1193 }
1194
1195 static void rs_flush_chars(struct tty_struct *tty)
1196 {
1197 struct async_struct *info = (struct async_struct *)tty->driver_data;
1198 unsigned long flags;
1199
1200 if (serial_paranoia_check(info, tty->device, "rs_flush_chars"))
1201 return;
1202
1203 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
1204 !info->xmit_buf)
1205 return;
1206
1207 save_flags(flags); cli();
1208 info->IER |= UART_IER_THRI;
1209 serial_out(info, UART_IER, info->IER);
1210 restore_flags(flags);
1211 }
1212
1213 static int rs_write(struct tty_struct * tty, int from_user,
1214 unsigned char *buf, int count)
1215 {
1216 int c, total = 0;
1217 struct async_struct *info = (struct async_struct *)tty->driver_data;
1218 unsigned long flags;
1219
1220 if (serial_paranoia_check(info, tty->device, "rs_write"))
1221 return 0;
1222
1223 if (!tty || !info->xmit_buf || !tmp_buf)
1224 return 0;
1225
1226 save_flags(flags);
1227 while (1) {
1228 cli();
1229 c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1230 SERIAL_XMIT_SIZE - info->xmit_head));
1231 if (c <= 0)
1232 break;
1233
1234 if (from_user) {
1235 down(&tmp_buf_sem);
1236 memcpy_fromfs(tmp_buf, buf, c);
1237 c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1238 SERIAL_XMIT_SIZE - info->xmit_head));
1239 memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
1240 up(&tmp_buf_sem);
1241 } else
1242 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1243 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1244 info->xmit_cnt += c;
1245 restore_flags(flags);
1246 buf += c;
1247 count -= c;
1248 total += c;
1249 }
1250 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped &&
1251 !(info->IER & UART_IER_THRI)) {
1252 info->IER |= UART_IER_THRI;
1253 serial_out(info, UART_IER, info->IER);
1254 }
1255 restore_flags(flags);
1256 return total;
1257 }
1258
1259 static int rs_write_room(struct tty_struct *tty)
1260 {
1261 struct async_struct *info = (struct async_struct *)tty->driver_data;
1262 int ret;
1263
1264 if (serial_paranoia_check(info, tty->device, "rs_write_room"))
1265 return 0;
1266 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
1267 if (ret < 0)
1268 ret = 0;
1269 return ret;
1270 }
1271
1272 static int rs_chars_in_buffer(struct tty_struct *tty)
1273 {
1274 struct async_struct *info = (struct async_struct *)tty->driver_data;
1275
1276 if (serial_paranoia_check(info, tty->device, "rs_chars_in_buffer"))
1277 return 0;
1278 return info->xmit_cnt;
1279 }
1280
1281 static void rs_flush_buffer(struct tty_struct *tty)
1282 {
1283 struct async_struct *info = (struct async_struct *)tty->driver_data;
1284
1285 if (serial_paranoia_check(info, tty->device, "rs_flush_buffer"))
1286 return;
1287 cli();
1288 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1289 sti();
1290 wake_up_interruptible(&tty->write_wait);
1291 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1292 tty->ldisc.write_wakeup)
1293 (tty->ldisc.write_wakeup)(tty);
1294 }
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304 static void rs_throttle(struct tty_struct * tty)
1305 {
1306 struct async_struct *info = (struct async_struct *)tty->driver_data;
1307 #ifdef SERIAL_DEBUG_THROTTLE
1308 char buf[64];
1309
1310 printk("throttle %s: %d....\n", _tty_name(tty, buf),
1311 tty->ldisc.chars_in_buffer(tty));
1312 #endif
1313
1314 if (serial_paranoia_check(info, tty->device, "rs_throttle"))
1315 return;
1316
1317 if (I_IXOFF(tty))
1318 info->x_char = STOP_CHAR(tty);
1319
1320 info->MCR &= ~UART_MCR_RTS;
1321 info->MCR_noint &= ~UART_MCR_RTS;
1322 cli();
1323 serial_out(info, UART_MCR, info->MCR);
1324 sti();
1325 }
1326
1327 static void rs_unthrottle(struct tty_struct * tty)
1328 {
1329 struct async_struct *info = (struct async_struct *)tty->driver_data;
1330 #ifdef SERIAL_DEBUG_THROTTLE
1331 char buf[64];
1332
1333 printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
1334 tty->ldisc.chars_in_buffer(tty));
1335 #endif
1336
1337 if (serial_paranoia_check(info, tty->device, "rs_unthrottle"))
1338 return;
1339
1340 if (I_IXOFF(tty)) {
1341 if (info->x_char)
1342 info->x_char = 0;
1343 else
1344 info->x_char = START_CHAR(tty);
1345 }
1346 info->MCR |= UART_MCR_RTS;
1347 info->MCR_noint |= UART_MCR_RTS;
1348 cli();
1349 serial_out(info, UART_MCR, info->MCR);
1350 sti();
1351 }
1352
1353
1354
1355
1356
1357
1358
1359 static int get_serial_info(struct async_struct * info,
1360 struct serial_struct * retinfo)
1361 {
1362 struct serial_struct tmp;
1363
1364 if (!retinfo)
1365 return -EFAULT;
1366 memset(&tmp, 0, sizeof(tmp));
1367 tmp.type = info->type;
1368 tmp.line = info->line;
1369 tmp.port = info->port;
1370 tmp.irq = info->irq;
1371 tmp.flags = info->flags;
1372 tmp.baud_base = info->baud_base;
1373 tmp.close_delay = info->close_delay;
1374 tmp.custom_divisor = info->custom_divisor;
1375 tmp.hub6 = info->hub6;
1376 memcpy_tofs(retinfo,&tmp,sizeof(*retinfo));
1377 return 0;
1378 }
1379
1380 static int set_serial_info(struct async_struct * info,
1381 struct serial_struct * new_info)
1382 {
1383 struct serial_struct new_serial;
1384 struct async_struct old_info;
1385 unsigned int i,change_irq,change_port;
1386 int retval = 0;
1387
1388 if (!new_info)
1389 return -EFAULT;
1390 memcpy_fromfs(&new_serial,new_info,sizeof(new_serial));
1391 old_info = *info;
1392
1393 change_irq = new_serial.irq != info->irq;
1394 change_port = (new_serial.port != info->port) || (new_serial.hub6 != info->hub6);
1395
1396 if (!suser()) {
1397 if (change_irq || change_port ||
1398 (new_serial.baud_base != info->baud_base) ||
1399 (new_serial.type != info->type) ||
1400 (new_serial.close_delay != info->close_delay) ||
1401 ((new_serial.flags & ~ASYNC_USR_MASK) !=
1402 (info->flags & ~ASYNC_USR_MASK)))
1403 return -EPERM;
1404 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1405 (new_serial.flags & ASYNC_USR_MASK));
1406 info->custom_divisor = new_serial.custom_divisor;
1407 goto check_and_exit;
1408 }
1409
1410 if (new_serial.irq == 2)
1411 new_serial.irq = 9;
1412
1413 if ((new_serial.irq > 15) || (new_serial.port > 0xffff) ||
1414 (new_serial.type < PORT_UNKNOWN) || (new_serial.type > PORT_MAX)) {
1415 return -EINVAL;
1416 }
1417
1418
1419 if (new_serial.type) {
1420 for (i = 0 ; i < NR_PORTS; i++)
1421 if ((info != &rs_table[i]) &&
1422 (rs_table[i].port == new_serial.port) &&
1423 rs_table[i].type)
1424 return -EADDRINUSE;
1425 }
1426
1427 if ((change_port || change_irq) && (info->count > 1))
1428 return -EBUSY;
1429
1430
1431
1432
1433
1434
1435 info->baud_base = new_serial.baud_base;
1436 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1437 (new_serial.flags & ASYNC_FLAGS));
1438 info->custom_divisor = new_serial.custom_divisor;
1439 info->type = new_serial.type;
1440 info->close_delay = new_serial.close_delay;
1441
1442 if (change_port || change_irq) {
1443
1444
1445
1446
1447 shutdown(info);
1448 info->irq = new_serial.irq;
1449 info->port = new_serial.port;
1450 info->hub6 = new_serial.hub6;
1451 }
1452
1453 check_and_exit:
1454 if (!info->port || !info->type)
1455 return 0;
1456 if (info->flags & ASYNC_INITIALIZED) {
1457 if (((old_info.flags & ASYNC_SPD_MASK) !=
1458 (info->flags & ASYNC_SPD_MASK)) ||
1459 (old_info.custom_divisor != info->custom_divisor))
1460 change_speed(info);
1461 } else
1462 retval = startup(info);
1463 return retval;
1464 }
1465
1466 static int get_modem_info(struct async_struct * info, unsigned int *value)
1467 {
1468 unsigned char control, status;
1469 unsigned int result;
1470
1471 control = info->MCR;
1472 cli();
1473 status = serial_in(info, UART_MSR);
1474 sti();
1475 result = ((control & UART_MCR_RTS) ? TIOCM_RTS : 0)
1476 | ((control & UART_MCR_DTR) ? TIOCM_DTR : 0)
1477 | ((status & UART_MSR_DCD) ? TIOCM_CAR : 0)
1478 | ((status & UART_MSR_RI) ? TIOCM_RNG : 0)
1479 | ((status & UART_MSR_DSR) ? TIOCM_DSR : 0)
1480 | ((status & UART_MSR_CTS) ? TIOCM_CTS : 0);
1481 put_fs_long(result,(unsigned long *) value);
1482 return 0;
1483 }
1484
1485 static int set_modem_info(struct async_struct * info, unsigned int cmd,
1486 unsigned int *value)
1487 {
1488 unsigned int arg = get_fs_long((unsigned long *) value);
1489
1490 switch (cmd) {
1491 case TIOCMBIS:
1492 if (arg & TIOCM_RTS) {
1493 info->MCR |= UART_MCR_RTS;
1494 info->MCR_noint |= UART_MCR_RTS;
1495 }
1496 if (arg & TIOCM_DTR) {
1497 info->MCR |= UART_MCR_DTR;
1498 info->MCR_noint |= UART_MCR_DTR;
1499 }
1500 break;
1501 case TIOCMBIC:
1502 if (arg & TIOCM_RTS) {
1503 info->MCR &= ~UART_MCR_RTS;
1504 info->MCR_noint &= ~UART_MCR_RTS;
1505 }
1506 if (arg & TIOCM_DTR) {
1507 info->MCR &= ~UART_MCR_DTR;
1508 info->MCR_noint &= ~UART_MCR_DTR;
1509 }
1510 break;
1511 case TIOCMSET:
1512 info->MCR = ((info->MCR & ~(UART_MCR_RTS | UART_MCR_DTR))
1513 | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1514 | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1515 info->MCR_noint = ((info->MCR_noint
1516 & ~(UART_MCR_RTS | UART_MCR_DTR))
1517 | ((arg & TIOCM_RTS) ? UART_MCR_RTS : 0)
1518 | ((arg & TIOCM_DTR) ? UART_MCR_DTR : 0));
1519 break;
1520 default:
1521 return -EINVAL;
1522 }
1523 cli();
1524 serial_out(info, UART_MCR, info->MCR);
1525 sti();
1526 return 0;
1527 }
1528
1529 static int do_autoconfig(struct async_struct * info)
1530 {
1531 int retval;
1532
1533 if (!suser())
1534 return -EPERM;
1535
1536 if (info->count > 1)
1537 return -EBUSY;
1538
1539 shutdown(info);
1540
1541 cli();
1542 autoconfig(info);
1543 sti();
1544
1545 retval = startup(info);
1546 if (retval)
1547 return retval;
1548 return 0;
1549 }
1550
1551
1552
1553
1554
1555 static void send_break( struct async_struct * info, int duration)
1556 {
1557 if (!info->port)
1558 return;
1559 current->state = TASK_INTERRUPTIBLE;
1560 current->timeout = jiffies + duration;
1561 cli();
1562 serial_out(info, UART_LCR, serial_inp(info, UART_LCR) | UART_LCR_SBC);
1563 schedule();
1564 serial_out(info, UART_LCR, serial_inp(info, UART_LCR) & ~UART_LCR_SBC);
1565 sti();
1566 }
1567
1568
1569
1570
1571
1572 static int check_wild_interrupts(int doprint)
1573 {
1574 int i, mask;
1575 int wild_interrupts = 0;
1576 int irq_lines;
1577 unsigned long timeout;
1578 unsigned long flags;
1579
1580
1581 save_flags(flags); sti();
1582
1583 irq_lines = grab_all_interrupts(0);
1584
1585
1586
1587
1588
1589 timeout = jiffies+10;
1590 while (timeout >= jiffies)
1591 ;
1592
1593 rs_triggered = 0;
1594
1595 timeout = jiffies+10;
1596 while (timeout >= jiffies)
1597 ;
1598
1599 for (i = 0, mask = 1; i < 16; i++, mask <<= 1) {
1600 if ((rs_triggered & (1 << i)) &&
1601 (irq_lines & (1 << i))) {
1602 wild_interrupts |= mask;
1603 if (doprint)
1604 printk("Wild interrupt? (IRQ %d)\n", i);
1605 }
1606 }
1607 free_all_interrupts(irq_lines);
1608 restore_flags(flags);
1609 return wild_interrupts;
1610 }
1611
1612 static int rs_ioctl(struct tty_struct *tty, struct file * file,
1613 unsigned int cmd, unsigned long arg)
1614 {
1615 int error;
1616 struct async_struct * info = (struct async_struct *)tty->driver_data;
1617 int retval;
1618
1619 if (serial_paranoia_check(info, tty->device, "rs_ioctl"))
1620 return -ENODEV;
1621
1622 switch (cmd) {
1623 case TCSBRK:
1624 retval = tty_check_change(tty);
1625 if (retval)
1626 return retval;
1627 wait_until_sent(tty, 0);
1628 if (!arg)
1629 send_break(info, HZ/4);
1630 return 0;
1631 case TCSBRKP:
1632 retval = tty_check_change(tty);
1633 if (retval)
1634 return retval;
1635 wait_until_sent(tty, 0);
1636 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1637 return 0;
1638 case TIOCGSOFTCAR:
1639 error = verify_area(VERIFY_WRITE, (void *) arg,sizeof(long));
1640 if (error)
1641 return error;
1642 put_fs_long(C_CLOCAL(tty) ? 1 : 0,
1643 (unsigned long *) arg);
1644 return 0;
1645 case TIOCSSOFTCAR:
1646 arg = get_fs_long((unsigned long *) arg);
1647 tty->termios->c_cflag =
1648 ((tty->termios->c_cflag & ~CLOCAL) |
1649 (arg ? CLOCAL : 0));
1650 return 0;
1651 case TIOCMGET:
1652 error = verify_area(VERIFY_WRITE, (void *) arg,
1653 sizeof(unsigned int));
1654 if (error)
1655 return error;
1656 return get_modem_info(info, (unsigned int *) arg);
1657 case TIOCMBIS:
1658 case TIOCMBIC:
1659 case TIOCMSET:
1660 return set_modem_info(info, cmd, (unsigned int *) arg);
1661 case TIOCGSERIAL:
1662 error = verify_area(VERIFY_WRITE, (void *) arg,
1663 sizeof(struct serial_struct));
1664 if (error)
1665 return error;
1666 return get_serial_info(info,
1667 (struct serial_struct *) arg);
1668 case TIOCSSERIAL:
1669 return set_serial_info(info,
1670 (struct serial_struct *) arg);
1671 case TIOCSERCONFIG:
1672 return do_autoconfig(info);
1673
1674 case TIOCSERGWILD:
1675 error = verify_area(VERIFY_WRITE, (void *) arg,
1676 sizeof(int));
1677 if (error)
1678 return error;
1679 put_fs_long(rs_wild_int_mask, (unsigned long *) arg);
1680 return 0;
1681
1682 case TIOCSERSWILD:
1683 if (!suser())
1684 return -EPERM;
1685 rs_wild_int_mask = get_fs_long((unsigned long *) arg);
1686 if (rs_wild_int_mask < 0)
1687 rs_wild_int_mask = check_wild_interrupts(0);
1688 return 0;
1689
1690 case TIOCSERGSTRUCT:
1691 error = verify_area(VERIFY_WRITE, (void *) arg,
1692 sizeof(struct async_struct));
1693 if (error)
1694 return error;
1695 memcpy_tofs((struct async_struct *) arg,
1696 info, sizeof(struct async_struct));
1697 return 0;
1698
1699 default:
1700 return -ENOIOCTLCMD;
1701 }
1702 return 0;
1703 }
1704
1705 static void rs_set_termios(struct tty_struct *tty, struct termios *old_termios)
1706 {
1707 struct async_struct *info = (struct async_struct *)tty->driver_data;
1708
1709 if (tty->termios->c_cflag == old_termios->c_cflag)
1710 return;
1711
1712 change_speed(info);
1713
1714 if ((old_termios->c_cflag & CRTSCTS) &&
1715 !(tty->termios->c_cflag & CRTSCTS)) {
1716 tty->hw_stopped = 0;
1717 rs_start(tty);
1718 }
1719
1720 if (!(old_termios->c_cflag & CLOCAL) &&
1721 (tty->termios->c_cflag & CLOCAL))
1722 wake_up_interruptible(&info->open_wait);
1723 }
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735 static void rs_close(struct tty_struct *tty, struct file * filp)
1736 {
1737 struct async_struct * info = (struct async_struct *)tty->driver_data;
1738 unsigned long flags;
1739
1740 if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
1741 return;
1742
1743 save_flags(flags); cli();
1744
1745 if (tty_hung_up_p(filp)) {
1746 restore_flags(flags);
1747 return;
1748 }
1749
1750 #ifdef SERIAL_DEBUG_OPEN
1751 printk("rs_close ttys%d, count = %d\n", info->line, info->count);
1752 #endif
1753 if ((tty->count == 1) && (info->count != 1)) {
1754
1755
1756
1757
1758
1759
1760
1761 printk("rs_close: bad serial port count; tty->count is 1, "
1762 "info->count is %d\n", info->count);
1763 info->count = 1;
1764 }
1765 if (--info->count < 0) {
1766 printk("rs_close: bad serial port count for ttys%d: %d\n",
1767 info->line, info->count);
1768 info->count = 0;
1769 }
1770 if (info->count) {
1771 restore_flags(flags);
1772 return;
1773 }
1774 info->flags |= ASYNC_CLOSING;
1775
1776
1777
1778
1779 if (info->flags & ASYNC_NORMAL_ACTIVE)
1780 info->normal_termios = *tty->termios;
1781 if (info->flags & ASYNC_CALLOUT_ACTIVE)
1782 info->callout_termios = *tty->termios;
1783 if (info->flags & ASYNC_INITIALIZED) {
1784 wait_until_sent(tty, 3000);
1785
1786
1787
1788
1789
1790 while (!(serial_inp(info, UART_LSR) & UART_LSR_TEMT)) {
1791 current->state = TASK_INTERRUPTIBLE;
1792 current->timeout = jiffies + info->timeout;
1793 schedule();
1794 }
1795 }
1796 shutdown(info);
1797 if (tty->driver.flush_buffer)
1798 tty->driver.flush_buffer(tty);
1799 if (tty->ldisc.flush_buffer)
1800 tty->ldisc.flush_buffer(tty);
1801 info->event = 0;
1802 info->tty = 0;
1803 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1804 if (tty->ldisc.close)
1805 (tty->ldisc.close)(tty);
1806 tty->ldisc = ldiscs[N_TTY];
1807 tty->termios->c_line = N_TTY;
1808 if (tty->ldisc.open)
1809 (tty->ldisc.open)(tty);
1810 }
1811 if (info->blocked_open) {
1812 if (info->close_delay) {
1813 current->state = TASK_INTERRUPTIBLE;
1814 current->timeout = jiffies + info->close_delay;
1815 schedule();
1816 }
1817 wake_up_interruptible(&info->open_wait);
1818 }
1819 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
1820 ASYNC_CLOSING);
1821 wake_up_interruptible(&info->close_wait);
1822 restore_flags(flags);
1823 }
1824
1825
1826
1827
1828 void rs_hangup(struct tty_struct *tty)
1829 {
1830 struct async_struct * info = (struct async_struct *)tty->driver_data;
1831
1832 if (serial_paranoia_check(info, tty->device, "rs_hangup"))
1833 return;
1834
1835 shutdown(info);
1836 info->event = 0;
1837 info->count = 0;
1838 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
1839 info->tty = 0;
1840 wake_up_interruptible(&info->open_wait);
1841 }
1842
1843
1844
1845
1846
1847
1848 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1849 struct async_struct *info)
1850 {
1851 struct wait_queue wait = { current, NULL };
1852 int retval;
1853 int do_clocal = 0;
1854
1855
1856
1857
1858
1859 if (info->flags & ASYNC_CLOSING) {
1860 interruptible_sleep_on(&info->close_wait);
1861 #ifdef SERIAL_DO_RESTART
1862 if (info->flags & ASYNC_HUP_NOTIFY)
1863 return -EAGAIN;
1864 else
1865 return -ERESTARTSYS;
1866 #else
1867 return -EAGAIN;
1868 #endif
1869 }
1870
1871
1872
1873
1874
1875 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
1876 if (info->flags & ASYNC_NORMAL_ACTIVE)
1877 return -EBUSY;
1878 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1879 (info->flags & ASYNC_SESSION_LOCKOUT) &&
1880 (info->session != current->session))
1881 return -EBUSY;
1882 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1883 (info->flags & ASYNC_PGRP_LOCKOUT) &&
1884 (info->pgrp != current->pgrp))
1885 return -EBUSY;
1886 info->flags |= ASYNC_CALLOUT_ACTIVE;
1887 return 0;
1888 }
1889
1890
1891
1892
1893
1894 if (filp->f_flags & O_NONBLOCK) {
1895 if (info->flags & ASYNC_CALLOUT_ACTIVE)
1896 return -EBUSY;
1897 info->flags |= ASYNC_NORMAL_ACTIVE;
1898 return 0;
1899 }
1900
1901 if (info->normal_termios.c_cflag & CLOCAL)
1902 do_clocal = 1;
1903
1904
1905
1906
1907
1908
1909
1910
1911 retval = 0;
1912 add_wait_queue(&info->open_wait, &wait);
1913 #ifdef SERIAL_DEBUG_OPEN
1914 printk("block_til_ready before block: ttys%d, count = %d\n",
1915 info->line, info->count);
1916 #endif
1917 info->count--;
1918 info->blocked_open++;
1919 while (1) {
1920 cli();
1921 if (!(info->flags & ASYNC_CALLOUT_ACTIVE))
1922 serial_out(info, UART_MCR,
1923 serial_inp(info, UART_MCR) |
1924 (UART_MCR_DTR | UART_MCR_RTS));
1925 sti();
1926 current->state = TASK_INTERRUPTIBLE;
1927 if (tty_hung_up_p(filp) ||
1928 !(info->flags & ASYNC_INITIALIZED)) {
1929 #ifdef SERIAL_DO_RESTART
1930 if (info->flags & ASYNC_HUP_NOTIFY)
1931 retval = -EAGAIN;
1932 else
1933 retval = -ERESTARTSYS;
1934 #else
1935 retval = -EAGAIN;
1936 #endif
1937 break;
1938 }
1939 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
1940 !(info->flags & ASYNC_CLOSING) &&
1941 (do_clocal || (serial_in(info, UART_MSR) &
1942 UART_MSR_DCD)))
1943 break;
1944 if (current->signal & ~current->blocked) {
1945 retval = -ERESTARTSYS;
1946 break;
1947 }
1948 #ifdef SERIAL_DEBUG_OPEN
1949 printk("block_til_ready blocking: ttys%d, count = %d\n",
1950 info->line, info->count);
1951 #endif
1952 schedule();
1953 }
1954 current->state = TASK_RUNNING;
1955 remove_wait_queue(&info->open_wait, &wait);
1956 if (!tty_hung_up_p(filp))
1957 info->count++;
1958 info->blocked_open--;
1959 #ifdef SERIAL_DEBUG_OPEN
1960 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1961 info->line, info->count);
1962 #endif
1963 if (retval)
1964 return retval;
1965 info->flags |= ASYNC_NORMAL_ACTIVE;
1966 return 0;
1967 }
1968
1969
1970
1971
1972
1973
1974
1975 int rs_open(struct tty_struct *tty, struct file * filp)
1976 {
1977 struct async_struct *info;
1978 int retval, line;
1979
1980 line = MINOR(tty->device) - tty->driver.minor_start;
1981 if ((line < 0) || (line >= NR_PORTS))
1982 return -ENODEV;
1983 info = rs_table + line;
1984 if (serial_paranoia_check(info, tty->device, "rs_open"))
1985 return -ENODEV;
1986
1987 #ifdef SERIAL_DEBUG_OPEN
1988 printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
1989 info->count);
1990 #endif
1991 info->count++;
1992 tty->driver_data = info;
1993 info->tty = tty;
1994
1995 if (!tmp_buf) {
1996 tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
1997 if (!tmp_buf)
1998 return -ENOMEM;
1999 }
2000
2001
2002
2003
2004 retval = startup(info);
2005 if (retval)
2006 return retval;
2007
2008 retval = block_til_ready(tty, filp, info);
2009 if (retval) {
2010 #ifdef SERIAL_DEBUG_OPEN
2011 printk("rs_open returning after block_til_ready with %d\n",
2012 retval);
2013 #endif
2014 return retval;
2015 }
2016
2017 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
2018 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
2019 *tty->termios = info->normal_termios;
2020 else
2021 *tty->termios = info->callout_termios;
2022 change_speed(info);
2023 }
2024
2025 info->session = current->session;
2026 info->pgrp = current->pgrp;
2027
2028 #ifdef SERIAL_DEBUG_OPEN
2029 printk("rs_open ttys%d successful...", info->line);
2030 #endif
2031 return 0;
2032 }
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047 static void show_serial_version(void)
2048 {
2049 printk("Serial driver version 4.00 with");
2050 #ifdef CONFIG_HUB6
2051 printk(" HUB-6");
2052 #define SERIAL_OPT
2053 #endif
2054 #ifdef SERIAL_OPT
2055 printk(" enabled\n");
2056 #else
2057 printk(" no serial options enabled\n");
2058 #endif
2059 #undef SERIAL_OPT
2060 }
2061
2062
2063
2064
2065
2066
2067 static int get_auto_irq(struct async_struct *info)
2068 {
2069 unsigned char save_MCR, save_IER, save_ICP=0;
2070 unsigned short ICP=0, port = info->port;
2071 unsigned long timeout;
2072
2073
2074
2075
2076 rs_irq_triggered = 0;
2077 cli();
2078 save_IER = serial_inp(info, UART_IER);
2079 save_MCR = serial_inp(info, UART_MCR);
2080 if (info->flags & ASYNC_FOURPORT) {
2081 serial_outp(info, UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
2082 serial_outp(info, UART_IER, 0x0f);
2083 ICP = (port & 0xFE0) | 0x01F;
2084 save_ICP = inb_p(ICP);
2085 outb_p(0x80, ICP);
2086 (void) inb_p(ICP);
2087 } else {
2088 serial_outp(info, UART_MCR,
2089 UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
2090 serial_outp(info, UART_IER, 0x0f);
2091 }
2092 sti();
2093
2094
2095
2096 (void)serial_inp(info, UART_LSR);
2097 (void)serial_inp(info, UART_RX);
2098 (void)serial_inp(info, UART_IIR);
2099 (void)serial_inp(info, UART_MSR);
2100
2101 timeout = jiffies+2;
2102 while (timeout >= jiffies) {
2103 if (rs_irq_triggered)
2104 break;
2105 }
2106
2107
2108
2109 cli();
2110 serial_outp(info, UART_IER, save_IER);
2111 serial_outp(info, UART_MCR, save_MCR);
2112 if (info->flags & ASYNC_FOURPORT)
2113 outb_p(save_ICP, ICP);
2114 sti();
2115 return(rs_irq_triggered);
2116 }
2117
2118
2119
2120
2121
2122 static int do_auto_irq(struct async_struct * info)
2123 {
2124 unsigned port = info->port;
2125 int irq_lines = 0;
2126 int irq_try_1 = 0, irq_try_2 = 0;
2127 int retries;
2128 unsigned long flags;
2129
2130 if (!port)
2131 return 0;
2132
2133
2134 save_flags(flags); sti();
2135
2136 irq_lines = grab_all_interrupts(rs_wild_int_mask);
2137
2138 for (retries = 0; retries < 5; retries++) {
2139 if (!irq_try_1)
2140 irq_try_1 = get_auto_irq(info);
2141 if (!irq_try_2)
2142 irq_try_2 = get_auto_irq(info);
2143 if (irq_try_1 && irq_try_2) {
2144 if (irq_try_1 == irq_try_2)
2145 break;
2146 irq_try_1 = irq_try_2 = 0;
2147 }
2148 }
2149 restore_flags(flags);
2150 free_all_interrupts(irq_lines);
2151 return (irq_try_1 == irq_try_2) ? irq_try_1 : 0;
2152 }
2153
2154
2155
2156
2157
2158
2159
2160
2161 static void autoconfig(struct async_struct * info)
2162 {
2163 unsigned char status1, status2, scratch, scratch2;
2164 unsigned port = info->port;
2165 unsigned long flags;
2166
2167 info->type = PORT_UNKNOWN;
2168
2169 if (!port)
2170 return;
2171
2172 save_flags(flags); cli();
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183 scratch = serial_inp(info, UART_IER);
2184 serial_outp(info, UART_IER, 0);
2185 outb(0xff, 0x080);
2186 scratch2 = serial_inp(info, UART_IER);
2187 serial_outp(info, UART_IER, scratch);
2188 if (scratch2) {
2189 restore_flags(flags);
2190 return;
2191 }
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202 if (!(info->flags & ASYNC_SKIP_TEST)) {
2203 scratch = serial_inp(info, UART_MCR);
2204 serial_outp(info, UART_MCR, UART_MCR_LOOP | scratch);
2205 scratch2 = serial_inp(info, UART_MSR);
2206 serial_outp(info, UART_MCR, UART_MCR_LOOP | 0x0A);
2207 status1 = serial_inp(info, UART_MSR) & 0xF0;
2208 serial_outp(info, UART_MCR, scratch);
2209 serial_outp(info, UART_MSR, scratch2);
2210 if (status1 != 0x90) {
2211 restore_flags(flags);
2212 return;
2213 }
2214 }
2215
2216
2217
2218
2219
2220 if (info->flags & ASYNC_AUTO_IRQ)
2221 info->irq = do_auto_irq(info);
2222
2223 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
2224 scratch = serial_in(info, UART_IIR) >> 6;
2225 info->xmit_fifo_size = 1;
2226 switch (scratch) {
2227 case 0:
2228 info->type = PORT_16450;
2229 break;
2230 case 1:
2231 info->type = PORT_UNKNOWN;
2232 break;
2233 case 2:
2234 info->type = PORT_16550;
2235 break;
2236 case 3:
2237 info->type = PORT_16550A;
2238 info->xmit_fifo_size = 16;
2239 break;
2240 }
2241 if (info->type == PORT_16450) {
2242 scratch = serial_in(info, UART_SCR);
2243 serial_outp(info, UART_SCR, 0xa5);
2244 status1 = serial_in(info, UART_SCR);
2245 serial_outp(info, UART_SCR, 0x5a);
2246 status2 = serial_in(info, UART_SCR);
2247 serial_outp(info, UART_SCR, scratch);
2248
2249 if ((status1 != 0xa5) || (status2 != 0x5a))
2250 info->type = PORT_8250;
2251 }
2252
2253
2254
2255
2256 serial_outp(info, UART_MCR, 0x00);
2257 serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
2258 UART_FCR_CLEAR_XMIT));
2259 (void)serial_in(info, UART_RX);
2260
2261 restore_flags(flags);
2262 }
2263
2264
2265
2266
2267 long rs_init(long kmem_start)
2268 {
2269 int i;
2270 struct async_struct * info;
2271
2272 bh_base[SERIAL_BH].routine = do_serial_bh;
2273 timer_table[RS_TIMER].fn = rs_timer;
2274 timer_table[RS_TIMER].expires = 0;
2275 #ifdef CONFIG_AUTO_IRQ
2276 rs_wild_int_mask = check_wild_interrupts(1);
2277 #endif
2278
2279 for (i = 0; i < 16; i++) {
2280 IRQ_ports[i] = 0;
2281 IRQ_timeout[i] = 0;
2282 }
2283
2284 show_serial_version();
2285
2286
2287
2288 memset(&serial_driver, 0, sizeof(struct tty_driver));
2289 serial_driver.magic = TTY_DRIVER_MAGIC;
2290 serial_driver.name = "ttyS";
2291 serial_driver.major = TTY_MAJOR;
2292 serial_driver.minor_start = 64;
2293 serial_driver.num = NR_PORTS;
2294 serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
2295 serial_driver.subtype = SERIAL_TYPE_NORMAL;
2296 serial_driver.init_termios = tty_std_termios;
2297 serial_driver.init_termios.c_cflag =
2298 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2299 serial_driver.flags = TTY_DRIVER_REAL_RAW;
2300 serial_driver.refcount = &serial_refcount;
2301 serial_driver.table = serial_table;
2302 serial_driver.termios = serial_termios;
2303 serial_driver.termios_locked = serial_termios_locked;
2304
2305 serial_driver.open = rs_open;
2306 serial_driver.close = rs_close;
2307 serial_driver.write = rs_write;
2308 serial_driver.put_char = rs_put_char;
2309 serial_driver.flush_chars = rs_flush_chars;
2310 serial_driver.write_room = rs_write_room;
2311 serial_driver.chars_in_buffer = rs_chars_in_buffer;
2312 serial_driver.flush_buffer = rs_flush_buffer;
2313 serial_driver.ioctl = rs_ioctl;
2314 serial_driver.throttle = rs_throttle;
2315 serial_driver.unthrottle = rs_unthrottle;
2316 serial_driver.set_termios = rs_set_termios;
2317 serial_driver.stop = rs_stop;
2318 serial_driver.start = rs_start;
2319 serial_driver.hangup = rs_hangup;
2320
2321
2322
2323
2324
2325 callout_driver = serial_driver;
2326 callout_driver.name = "cua";
2327 callout_driver.major = TTYAUX_MAJOR;
2328 callout_driver.subtype = SERIAL_TYPE_CALLOUT;
2329
2330 if (tty_register_driver(&serial_driver))
2331 panic("Couldn't register serial driver\n");
2332 if (tty_register_driver(&callout_driver))
2333 panic("Couldn't register callout driver\n");
2334
2335 for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) {
2336 info->magic = SERIAL_MAGIC;
2337 info->line = i;
2338 info->tty = 0;
2339 info->type = PORT_UNKNOWN;
2340 info->custom_divisor = 0;
2341 info->close_delay = 50;
2342 info->x_char = 0;
2343 info->event = 0;
2344 info->count = 0;
2345 info->blocked_open = 0;
2346 info->tqueue.routine = do_softint;
2347 info->tqueue.data = info;
2348 info->callout_termios =callout_driver.init_termios;
2349 info->normal_termios = serial_driver.init_termios;
2350 info->open_wait = 0;
2351 info->close_wait = 0;
2352 info->next_port = 0;
2353 info->prev_port = 0;
2354 if (info->irq == 2)
2355 info->irq = 9;
2356 if (!(info->flags & ASYNC_BOOT_AUTOCONF))
2357 continue;
2358 autoconfig(info);
2359 if (info->type == PORT_UNKNOWN)
2360 continue;
2361 printk("tty%02d%s at 0x%04x (irq = %d)", info->line,
2362 (info->flags & ASYNC_FOURPORT) ? " FourPort" : "",
2363 info->port, info->irq);
2364 switch (info->type) {
2365 case PORT_8250:
2366 printk(" is a 8250\n");
2367 break;
2368 case PORT_16450:
2369 printk(" is a 16450\n");
2370 break;
2371 case PORT_16550:
2372 printk(" is a 16550\n");
2373 break;
2374 case PORT_16550A:
2375 printk(" is a 16550A\n");
2376 break;
2377 default:
2378 printk("\n");
2379 break;
2380 }
2381 }
2382 return kmem_start;
2383 }
2384
2385
2386
2387
2388
2389 int register_serial(struct serial_struct *req)
2390 {
2391 int i;
2392 unsigned long flags;
2393 struct async_struct *info;
2394
2395 save_flags(flags);
2396 cli();
2397 for (i = 0; i < NR_PORTS; i++) {
2398 if (rs_table[i].port == req->port)
2399 break;
2400 }
2401 if (i == NR_PORTS) {
2402 for (i = 0; i < NR_PORTS; i++)
2403 if ((rs_table[i].type == PORT_UNKNOWN) &&
2404 (rs_table[i].count == 0))
2405 break;
2406 }
2407 if (i == NR_PORTS) {
2408 restore_flags(flags);
2409 return -1;
2410 }
2411 info = &rs_table[i];
2412 if (rs_table[i].count) {
2413 restore_flags(flags);
2414 printk("Couldn't configure serial #%d (port=%d,irq=%d): "
2415 "device already open\n", i, req->port, req->irq);
2416 return -1;
2417 }
2418 info->irq = req->irq;
2419 info->port = req->port;
2420 autoconfig(info);
2421 if (info->type == PORT_UNKNOWN) {
2422 restore_flags(flags);
2423 printk("register_serial(): autoconfig failed\n");
2424 return -1;
2425 }
2426 printk("tty%02d at 0x%04x (irq = %d)", info->line,
2427 info->port, info->irq);
2428 switch (info->type) {
2429 case PORT_8250:
2430 printk(" is a 8250\n"); break;
2431 case PORT_16450:
2432 printk(" is a 16450\n"); break;
2433 case PORT_16550:
2434 printk(" is a 16550\n"); break;
2435 case PORT_16550A:
2436 printk(" is a 16550A\n"); break;
2437 default:
2438 printk("\n"); break;
2439 }
2440 restore_flags(flags);
2441 return info->line;
2442 }
2443
2444 void unregister_serial(int line)
2445 {
2446 unsigned long flags;
2447 struct async_struct *info = &rs_table[line];
2448
2449 save_flags(flags);
2450 cli();
2451 if (info->tty)
2452 tty_hangup(info->tty);
2453 info->type = PORT_UNKNOWN;
2454 printk("tty%02d unloaded\n", info->line);
2455 restore_flags(flags);
2456 }