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