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