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 unsigned long timeout;
1739
1740 if (!info || serial_paranoia_check(info, tty->device, "rs_close"))
1741 return;
1742
1743 save_flags(flags); cli();
1744
1745 if (tty_hung_up_p(filp)) {
1746 restore_flags(flags);
1747 return;
1748 }
1749
1750 #ifdef SERIAL_DEBUG_OPEN
1751 printk("rs_close ttys%d, count = %d\n", info->line, info->count);
1752 #endif
1753 if ((tty->count == 1) && (info->count != 1)) {
1754
1755
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 timeout = jiffies+HZ;
1791 while (!(serial_inp(info, UART_LSR) & UART_LSR_TEMT)) {
1792 current->state = TASK_INTERRUPTIBLE;
1793 current->timeout = jiffies + info->timeout;
1794 schedule();
1795 if (jiffies > timeout)
1796 break;
1797 }
1798 }
1799 shutdown(info);
1800 if (tty->driver.flush_buffer)
1801 tty->driver.flush_buffer(tty);
1802 if (tty->ldisc.flush_buffer)
1803 tty->ldisc.flush_buffer(tty);
1804 info->event = 0;
1805 info->tty = 0;
1806 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1807 if (tty->ldisc.close)
1808 (tty->ldisc.close)(tty);
1809 tty->ldisc = ldiscs[N_TTY];
1810 tty->termios->c_line = N_TTY;
1811 if (tty->ldisc.open)
1812 (tty->ldisc.open)(tty);
1813 }
1814 if (info->blocked_open) {
1815 if (info->close_delay) {
1816 current->state = TASK_INTERRUPTIBLE;
1817 current->timeout = jiffies + info->close_delay;
1818 schedule();
1819 }
1820 wake_up_interruptible(&info->open_wait);
1821 }
1822 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
1823 ASYNC_CLOSING);
1824 wake_up_interruptible(&info->close_wait);
1825 restore_flags(flags);
1826 }
1827
1828
1829
1830
1831 void rs_hangup(struct tty_struct *tty)
1832 {
1833 struct async_struct * info = (struct async_struct *)tty->driver_data;
1834
1835 if (serial_paranoia_check(info, tty->device, "rs_hangup"))
1836 return;
1837
1838 shutdown(info);
1839 info->event = 0;
1840 info->count = 0;
1841 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
1842 info->tty = 0;
1843 wake_up_interruptible(&info->open_wait);
1844 }
1845
1846
1847
1848
1849
1850
1851 static int block_til_ready(struct tty_struct *tty, struct file * filp,
1852 struct async_struct *info)
1853 {
1854 struct wait_queue wait = { current, NULL };
1855 int retval;
1856 int do_clocal = 0;
1857
1858
1859
1860
1861
1862 if (info->flags & ASYNC_CLOSING) {
1863 interruptible_sleep_on(&info->close_wait);
1864 #ifdef SERIAL_DO_RESTART
1865 if (info->flags & ASYNC_HUP_NOTIFY)
1866 return -EAGAIN;
1867 else
1868 return -ERESTARTSYS;
1869 #else
1870 return -EAGAIN;
1871 #endif
1872 }
1873
1874
1875
1876
1877
1878 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
1879 if (info->flags & ASYNC_NORMAL_ACTIVE)
1880 return -EBUSY;
1881 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1882 (info->flags & ASYNC_SESSION_LOCKOUT) &&
1883 (info->session != current->session))
1884 return -EBUSY;
1885 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
1886 (info->flags & ASYNC_PGRP_LOCKOUT) &&
1887 (info->pgrp != current->pgrp))
1888 return -EBUSY;
1889 info->flags |= ASYNC_CALLOUT_ACTIVE;
1890 return 0;
1891 }
1892
1893
1894
1895
1896
1897 if (filp->f_flags & O_NONBLOCK) {
1898 if (info->flags & ASYNC_CALLOUT_ACTIVE)
1899 return -EBUSY;
1900 info->flags |= ASYNC_NORMAL_ACTIVE;
1901 return 0;
1902 }
1903
1904 if (info->normal_termios.c_cflag & CLOCAL)
1905 do_clocal = 1;
1906
1907
1908
1909
1910
1911
1912
1913
1914 retval = 0;
1915 add_wait_queue(&info->open_wait, &wait);
1916 #ifdef SERIAL_DEBUG_OPEN
1917 printk("block_til_ready before block: ttys%d, count = %d\n",
1918 info->line, info->count);
1919 #endif
1920 info->count--;
1921 info->blocked_open++;
1922 while (1) {
1923 cli();
1924 if (!(info->flags & ASYNC_CALLOUT_ACTIVE))
1925 serial_out(info, UART_MCR,
1926 serial_inp(info, UART_MCR) |
1927 (UART_MCR_DTR | UART_MCR_RTS));
1928 sti();
1929 current->state = TASK_INTERRUPTIBLE;
1930 if (tty_hung_up_p(filp) ||
1931 !(info->flags & ASYNC_INITIALIZED)) {
1932 #ifdef SERIAL_DO_RESTART
1933 if (info->flags & ASYNC_HUP_NOTIFY)
1934 retval = -EAGAIN;
1935 else
1936 retval = -ERESTARTSYS;
1937 #else
1938 retval = -EAGAIN;
1939 #endif
1940 break;
1941 }
1942 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
1943 !(info->flags & ASYNC_CLOSING) &&
1944 (do_clocal || (serial_in(info, UART_MSR) &
1945 UART_MSR_DCD)))
1946 break;
1947 if (current->signal & ~current->blocked) {
1948 retval = -ERESTARTSYS;
1949 break;
1950 }
1951 #ifdef SERIAL_DEBUG_OPEN
1952 printk("block_til_ready blocking: ttys%d, count = %d\n",
1953 info->line, info->count);
1954 #endif
1955 schedule();
1956 }
1957 current->state = TASK_RUNNING;
1958 remove_wait_queue(&info->open_wait, &wait);
1959 if (!tty_hung_up_p(filp))
1960 info->count++;
1961 info->blocked_open--;
1962 #ifdef SERIAL_DEBUG_OPEN
1963 printk("block_til_ready after blocking: ttys%d, count = %d\n",
1964 info->line, info->count);
1965 #endif
1966 if (retval)
1967 return retval;
1968 info->flags |= ASYNC_NORMAL_ACTIVE;
1969 return 0;
1970 }
1971
1972
1973
1974
1975
1976
1977
1978 int rs_open(struct tty_struct *tty, struct file * filp)
1979 {
1980 struct async_struct *info;
1981 int retval, line;
1982
1983 line = MINOR(tty->device) - tty->driver.minor_start;
1984 if ((line < 0) || (line >= NR_PORTS))
1985 return -ENODEV;
1986 info = rs_table + line;
1987 if (serial_paranoia_check(info, tty->device, "rs_open"))
1988 return -ENODEV;
1989
1990 #ifdef SERIAL_DEBUG_OPEN
1991 printk("rs_open %s%d, count = %d\n", tty->driver.name, info->line,
1992 info->count);
1993 #endif
1994 info->count++;
1995 tty->driver_data = info;
1996 info->tty = tty;
1997
1998 if (!tmp_buf) {
1999 tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
2000 if (!tmp_buf)
2001 return -ENOMEM;
2002 }
2003
2004
2005
2006
2007 retval = startup(info);
2008 if (retval)
2009 return retval;
2010
2011 retval = block_til_ready(tty, filp, info);
2012 if (retval) {
2013 #ifdef SERIAL_DEBUG_OPEN
2014 printk("rs_open returning after block_til_ready with %d\n",
2015 retval);
2016 #endif
2017 return retval;
2018 }
2019
2020 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
2021 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
2022 *tty->termios = info->normal_termios;
2023 else
2024 *tty->termios = info->callout_termios;
2025 change_speed(info);
2026 }
2027
2028 info->session = current->session;
2029 info->pgrp = current->pgrp;
2030
2031 #ifdef SERIAL_DEBUG_OPEN
2032 printk("rs_open ttys%d successful...", info->line);
2033 #endif
2034 return 0;
2035 }
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050 static void show_serial_version(void)
2051 {
2052 printk("Serial driver version 4.00 with");
2053 #ifdef CONFIG_HUB6
2054 printk(" HUB-6");
2055 #define SERIAL_OPT
2056 #endif
2057 #ifdef SERIAL_OPT
2058 printk(" enabled\n");
2059 #else
2060 printk(" no serial options enabled\n");
2061 #endif
2062 #undef SERIAL_OPT
2063 }
2064
2065
2066
2067
2068
2069
2070 static int get_auto_irq(struct async_struct *info)
2071 {
2072 unsigned char save_MCR, save_IER, save_ICP=0;
2073 unsigned short ICP=0, port = info->port;
2074 unsigned long timeout;
2075
2076
2077
2078
2079 rs_irq_triggered = 0;
2080 cli();
2081 save_IER = serial_inp(info, UART_IER);
2082 save_MCR = serial_inp(info, UART_MCR);
2083 if (info->flags & ASYNC_FOURPORT) {
2084 serial_outp(info, UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
2085 serial_outp(info, UART_IER, 0x0f);
2086 ICP = (port & 0xFE0) | 0x01F;
2087 save_ICP = inb_p(ICP);
2088 outb_p(0x80, ICP);
2089 (void) inb_p(ICP);
2090 } else {
2091 serial_outp(info, UART_MCR,
2092 UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2);
2093 serial_outp(info, UART_IER, 0x0f);
2094 }
2095 sti();
2096
2097
2098
2099 (void)serial_inp(info, UART_LSR);
2100 (void)serial_inp(info, UART_RX);
2101 (void)serial_inp(info, UART_IIR);
2102 (void)serial_inp(info, UART_MSR);
2103
2104 timeout = jiffies+2;
2105 while (timeout >= jiffies) {
2106 if (rs_irq_triggered)
2107 break;
2108 }
2109
2110
2111
2112 cli();
2113 serial_outp(info, UART_IER, save_IER);
2114 serial_outp(info, UART_MCR, save_MCR);
2115 if (info->flags & ASYNC_FOURPORT)
2116 outb_p(save_ICP, ICP);
2117 sti();
2118 return(rs_irq_triggered);
2119 }
2120
2121
2122
2123
2124
2125 static int do_auto_irq(struct async_struct * info)
2126 {
2127 unsigned port = info->port;
2128 int irq_lines = 0;
2129 int irq_try_1 = 0, irq_try_2 = 0;
2130 int retries;
2131 unsigned long flags;
2132
2133 if (!port)
2134 return 0;
2135
2136
2137 save_flags(flags); sti();
2138
2139 irq_lines = grab_all_interrupts(rs_wild_int_mask);
2140
2141 for (retries = 0; retries < 5; retries++) {
2142 if (!irq_try_1)
2143 irq_try_1 = get_auto_irq(info);
2144 if (!irq_try_2)
2145 irq_try_2 = get_auto_irq(info);
2146 if (irq_try_1 && irq_try_2) {
2147 if (irq_try_1 == irq_try_2)
2148 break;
2149 irq_try_1 = irq_try_2 = 0;
2150 }
2151 }
2152 restore_flags(flags);
2153 free_all_interrupts(irq_lines);
2154 return (irq_try_1 == irq_try_2) ? irq_try_1 : 0;
2155 }
2156
2157
2158
2159
2160
2161
2162
2163
2164 static void autoconfig(struct async_struct * info)
2165 {
2166 unsigned char status1, status2, scratch, scratch2;
2167 unsigned port = info->port;
2168 unsigned long flags;
2169
2170 info->type = PORT_UNKNOWN;
2171
2172 if (!port)
2173 return;
2174
2175 save_flags(flags); cli();
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186 scratch = serial_inp(info, UART_IER);
2187 serial_outp(info, UART_IER, 0);
2188 outb(0xff, 0x080);
2189 scratch2 = serial_inp(info, UART_IER);
2190 serial_outp(info, UART_IER, scratch);
2191 if (scratch2) {
2192 restore_flags(flags);
2193 return;
2194 }
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205 if (!(info->flags & ASYNC_SKIP_TEST)) {
2206 scratch = serial_inp(info, UART_MCR);
2207 serial_outp(info, UART_MCR, UART_MCR_LOOP | scratch);
2208 scratch2 = serial_inp(info, UART_MSR);
2209 serial_outp(info, UART_MCR, UART_MCR_LOOP | 0x0A);
2210 status1 = serial_inp(info, UART_MSR) & 0xF0;
2211 serial_outp(info, UART_MCR, scratch);
2212 serial_outp(info, UART_MSR, scratch2);
2213 if (status1 != 0x90) {
2214 restore_flags(flags);
2215 return;
2216 }
2217 }
2218
2219
2220
2221
2222
2223 if (info->flags & ASYNC_AUTO_IRQ)
2224 info->irq = do_auto_irq(info);
2225
2226 serial_outp(info, UART_FCR, UART_FCR_ENABLE_FIFO);
2227 scratch = serial_in(info, UART_IIR) >> 6;
2228 info->xmit_fifo_size = 1;
2229 switch (scratch) {
2230 case 0:
2231 info->type = PORT_16450;
2232 break;
2233 case 1:
2234 info->type = PORT_UNKNOWN;
2235 break;
2236 case 2:
2237 info->type = PORT_16550;
2238 break;
2239 case 3:
2240 info->type = PORT_16550A;
2241 info->xmit_fifo_size = 16;
2242 break;
2243 }
2244 if (info->type == PORT_16450) {
2245 scratch = serial_in(info, UART_SCR);
2246 serial_outp(info, UART_SCR, 0xa5);
2247 status1 = serial_in(info, UART_SCR);
2248 serial_outp(info, UART_SCR, 0x5a);
2249 status2 = serial_in(info, UART_SCR);
2250 serial_outp(info, UART_SCR, scratch);
2251
2252 if ((status1 != 0xa5) || (status2 != 0x5a))
2253 info->type = PORT_8250;
2254 }
2255
2256
2257
2258
2259 serial_outp(info, UART_MCR, 0x00);
2260 serial_outp(info, UART_FCR, (UART_FCR_CLEAR_RCVR |
2261 UART_FCR_CLEAR_XMIT));
2262 (void)serial_in(info, UART_RX);
2263
2264 restore_flags(flags);
2265 }
2266
2267
2268
2269
2270 long rs_init(long kmem_start)
2271 {
2272 int i;
2273 struct async_struct * info;
2274
2275 bh_base[SERIAL_BH].routine = do_serial_bh;
2276 timer_table[RS_TIMER].fn = rs_timer;
2277 timer_table[RS_TIMER].expires = 0;
2278 #ifdef CONFIG_AUTO_IRQ
2279 rs_wild_int_mask = check_wild_interrupts(1);
2280 #endif
2281
2282 for (i = 0; i < 16; i++) {
2283 IRQ_ports[i] = 0;
2284 IRQ_timeout[i] = 0;
2285 }
2286
2287 show_serial_version();
2288
2289
2290
2291 memset(&serial_driver, 0, sizeof(struct tty_driver));
2292 serial_driver.magic = TTY_DRIVER_MAGIC;
2293 serial_driver.name = "ttyS";
2294 serial_driver.major = TTY_MAJOR;
2295 serial_driver.minor_start = 64;
2296 serial_driver.num = NR_PORTS;
2297 serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
2298 serial_driver.subtype = SERIAL_TYPE_NORMAL;
2299 serial_driver.init_termios = tty_std_termios;
2300 serial_driver.init_termios.c_cflag =
2301 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2302 serial_driver.flags = TTY_DRIVER_REAL_RAW;
2303 serial_driver.refcount = &serial_refcount;
2304 serial_driver.table = serial_table;
2305 serial_driver.termios = serial_termios;
2306 serial_driver.termios_locked = serial_termios_locked;
2307
2308 serial_driver.open = rs_open;
2309 serial_driver.close = rs_close;
2310 serial_driver.write = rs_write;
2311 serial_driver.put_char = rs_put_char;
2312 serial_driver.flush_chars = rs_flush_chars;
2313 serial_driver.write_room = rs_write_room;
2314 serial_driver.chars_in_buffer = rs_chars_in_buffer;
2315 serial_driver.flush_buffer = rs_flush_buffer;
2316 serial_driver.ioctl = rs_ioctl;
2317 serial_driver.throttle = rs_throttle;
2318 serial_driver.unthrottle = rs_unthrottle;
2319 serial_driver.set_termios = rs_set_termios;
2320 serial_driver.stop = rs_stop;
2321 serial_driver.start = rs_start;
2322 serial_driver.hangup = rs_hangup;
2323
2324
2325
2326
2327
2328 callout_driver = serial_driver;
2329 callout_driver.name = "cua";
2330 callout_driver.major = TTYAUX_MAJOR;
2331 callout_driver.subtype = SERIAL_TYPE_CALLOUT;
2332
2333 if (tty_register_driver(&serial_driver))
2334 panic("Couldn't register serial driver\n");
2335 if (tty_register_driver(&callout_driver))
2336 panic("Couldn't register callout driver\n");
2337
2338 for (i = 0, info = rs_table; i < NR_PORTS; i++,info++) {
2339 info->magic = SERIAL_MAGIC;
2340 info->line = i;
2341 info->tty = 0;
2342 info->type = PORT_UNKNOWN;
2343 info->custom_divisor = 0;
2344 info->close_delay = 50;
2345 info->x_char = 0;
2346 info->event = 0;
2347 info->count = 0;
2348 info->blocked_open = 0;
2349 info->tqueue.routine = do_softint;
2350 info->tqueue.data = info;
2351 info->callout_termios =callout_driver.init_termios;
2352 info->normal_termios = serial_driver.init_termios;
2353 info->open_wait = 0;
2354 info->close_wait = 0;
2355 info->next_port = 0;
2356 info->prev_port = 0;
2357 if (info->irq == 2)
2358 info->irq = 9;
2359 if (!(info->flags & ASYNC_BOOT_AUTOCONF))
2360 continue;
2361 autoconfig(info);
2362 if (info->type == PORT_UNKNOWN)
2363 continue;
2364 printk("tty%02d%s at 0x%04x (irq = %d)", info->line,
2365 (info->flags & ASYNC_FOURPORT) ? " FourPort" : "",
2366 info->port, info->irq);
2367 switch (info->type) {
2368 case PORT_8250:
2369 printk(" is a 8250\n");
2370 break;
2371 case PORT_16450:
2372 printk(" is a 16450\n");
2373 break;
2374 case PORT_16550:
2375 printk(" is a 16550\n");
2376 break;
2377 case PORT_16550A:
2378 printk(" is a 16550A\n");
2379 break;
2380 default:
2381 printk("\n");
2382 break;
2383 }
2384 }
2385 return kmem_start;
2386 }
2387
2388
2389
2390
2391
2392 int register_serial(struct serial_struct *req)
2393 {
2394 int i;
2395 unsigned long flags;
2396 struct async_struct *info;
2397
2398 save_flags(flags);
2399 cli();
2400 for (i = 0; i < NR_PORTS; i++) {
2401 if (rs_table[i].port == req->port)
2402 break;
2403 }
2404 if (i == NR_PORTS) {
2405 for (i = 0; i < NR_PORTS; i++)
2406 if ((rs_table[i].type == PORT_UNKNOWN) &&
2407 (rs_table[i].count == 0))
2408 break;
2409 }
2410 if (i == NR_PORTS) {
2411 restore_flags(flags);
2412 return -1;
2413 }
2414 info = &rs_table[i];
2415 if (rs_table[i].count) {
2416 restore_flags(flags);
2417 printk("Couldn't configure serial #%d (port=%d,irq=%d): "
2418 "device already open\n", i, req->port, req->irq);
2419 return -1;
2420 }
2421 info->irq = req->irq;
2422 info->port = req->port;
2423 autoconfig(info);
2424 if (info->type == PORT_UNKNOWN) {
2425 restore_flags(flags);
2426 printk("register_serial(): autoconfig failed\n");
2427 return -1;
2428 }
2429 printk("tty%02d at 0x%04x (irq = %d)", info->line,
2430 info->port, info->irq);
2431 switch (info->type) {
2432 case PORT_8250:
2433 printk(" is a 8250\n"); break;
2434 case PORT_16450:
2435 printk(" is a 16450\n"); break;
2436 case PORT_16550:
2437 printk(" is a 16550\n"); break;
2438 case PORT_16550A:
2439 printk(" is a 16550A\n"); break;
2440 default:
2441 printk("\n"); break;
2442 }
2443 restore_flags(flags);
2444 return info->line;
2445 }
2446
2447 void unregister_serial(int line)
2448 {
2449 unsigned long flags;
2450 struct async_struct *info = &rs_table[line];
2451
2452 save_flags(flags);
2453 cli();
2454 if (info->tty)
2455 tty_hangup(info->tty);
2456 info->type = PORT_UNKNOWN;
2457 printk("tty%02d unloaded\n", info->line);
2458 restore_flags(flags);
2459 }