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