1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68#include <linux/config.h>
69#include <linux/types.h>
70#include <linux/major.h>
71#include <linux/errno.h>
72#include <linux/signal.h>
73#include <linux/fcntl.h>
74#include <linux/sched.h>
75#include <linux/interrupt.h>
76#include <linux/tty.h>
77#include <linux/tty_driver.h>
78#include <linux/tty_flip.h>
79#include <linux/devpts_fs.h>
80#include <linux/file.h>
81#include <linux/console.h>
82#include <linux/timer.h>
83#include <linux/ctype.h>
84#include <linux/kd.h>
85#include <linux/mm.h>
86#include <linux/string.h>
87#include <linux/slab.h>
88#include <linux/poll.h>
89#include <linux/proc_fs.h>
90#include <linux/init.h>
91#include <linux/module.h>
92#include <linux/smp_lock.h>
93
94#include <asm/uaccess.h>
95#include <asm/system.h>
96#include <asm/bitops.h>
97
98#include <linux/kbd_kern.h>
99#include <linux/vt_kern.h>
100#include <linux/selection.h>
101#include <linux/devfs_fs_kernel.h>
102
103#include <linux/kmod.h>
104
105#ifdef CONFIG_VT
106extern void con_init_devfs (void);
107#endif
108
109extern void disable_early_printk(void);
110
111#define CONSOLE_DEV MKDEV(TTY_MAJOR,0)
112#define TTY_DEV MKDEV(TTYAUX_MAJOR,0)
113#define SYSCONS_DEV MKDEV(TTYAUX_MAJOR,1)
114#define PTMX_DEV MKDEV(TTYAUX_MAJOR,2)
115
116#undef TTY_DEBUG_HANGUP
117
118#define TTY_PARANOIA_CHECK 1
119#define CHECK_TTY_COUNT 1
120
121struct termios tty_std_termios;
122struct tty_driver *tty_drivers;
123struct tty_ldisc ldiscs[NR_LDISCS];
124
125#ifdef CONFIG_UNIX98_PTYS
126extern struct tty_driver ptm_driver[];
127extern struct tty_driver pts_driver[];
128#endif
129
130static void initialize_tty_struct(struct tty_struct *tty);
131
132static ssize_t tty_read(struct file *, char *, size_t, loff_t *);
133static ssize_t tty_write(struct file *, const char *, size_t, loff_t *);
134static unsigned int tty_poll(struct file *, poll_table *);
135static int tty_open(struct inode *, struct file *);
136static int tty_release(struct inode *, struct file *);
137int tty_ioctl(struct inode * inode, struct file * file,
138 unsigned int cmd, unsigned long arg);
139static int tty_fasync(int fd, struct file * filp, int on);
140extern int vme_scc_init (void);
141extern long vme_scc_console_init(void);
142extern int serial167_init(void);
143extern long serial167_console_init(void);
144extern void console_8xx_init(void);
145extern void au1x00_serial_console_init(void);
146extern int rs_8xx_init(void);
147extern void mac_scc_console_init(void);
148extern void hwc_console_init(void);
149extern void hwc_tty_init(void);
150extern void con3215_init(void);
151extern void tty3215_init(void);
152extern void tub3270_con_init(void);
153extern void tub3270_init(void);
154extern void rs285_console_init(void);
155extern void sa1100_rs_console_init(void);
156extern void sgi_serial_console_init(void);
157extern void sn_sal_serial_console_init(void);
158extern void sci_console_init(void);
159extern void dec_serial_console_init(void);
160extern void tx3912_console_init(void);
161extern void tx3912_rs_init(void);
162extern void txx927_console_init(void);
163extern void txx9_rs_init(void);
164extern void txx9_serial_console_init(void);
165extern void sb1250_serial_console_init(void);
166extern void arc_console_init(void);
167extern int hvc_console_init(void);
168
169#ifndef MIN
170#define MIN(a,b) ((a) < (b) ? (a) : (b))
171#endif
172#ifndef MAX
173#define MAX(a,b) ((a) < (b) ? (b) : (a))
174#endif
175
176static struct tty_struct *alloc_tty_struct(void)
177{
178 struct tty_struct *tty;
179
180 tty = kmalloc(sizeof(struct tty_struct), GFP_KERNEL);
181 if (tty)
182 memset(tty, 0, sizeof(struct tty_struct));
183 return tty;
184}
185
186static inline void free_tty_struct(struct tty_struct *tty)
187{
188 kfree(tty);
189}
190
191
192
193
194static char *
195_tty_make_name(struct tty_struct *tty, const char *name, char *buf)
196{
197 int idx = (tty)?MINOR(tty->device) - tty->driver.minor_start:0;
198
199 if (!tty)
200 strcpy(buf, "NULL tty");
201 else
202 sprintf(buf, name,
203 idx + tty->driver.name_base);
204
205 return buf;
206}
207
208#define TTY_NUMBER(tty) (MINOR((tty)->device) - (tty)->driver.minor_start + \
209 (tty)->driver.name_base)
210
211char *tty_name(struct tty_struct *tty, char *buf)
212{
213 return _tty_make_name(tty, (tty)?tty->driver.name:NULL, buf);
214}
215
216inline int tty_paranoia_check(struct tty_struct *tty, kdev_t device,
217 const char *routine)
218{
219#ifdef TTY_PARANOIA_CHECK
220 static const char badmagic[] = KERN_WARNING
221 "Warning: bad magic number for tty struct (%s) in %s\n";
222 static const char badtty[] = KERN_WARNING
223 "Warning: null TTY for (%s) in %s\n";
224
225 if (!tty) {
226 printk(badtty, kdevname(device), routine);
227 return 1;
228 }
229 if (tty->magic != TTY_MAGIC) {
230 printk(badmagic, kdevname(device), routine);
231 return 1;
232 }
233#endif
234 return 0;
235}
236
237static int check_tty_count(struct tty_struct *tty, const char *routine)
238{
239#ifdef CHECK_TTY_COUNT
240 struct list_head *p;
241 int count = 0;
242
243 file_list_lock();
244 for(p = tty->tty_files.next; p != &tty->tty_files; p = p->next) {
245 if(list_entry(p, struct file, f_list)->private_data == tty)
246 count++;
247 }
248 file_list_unlock();
249 if (tty->driver.type == TTY_DRIVER_TYPE_PTY &&
250 tty->driver.subtype == PTY_TYPE_SLAVE &&
251 tty->link && tty->link->count)
252 count++;
253 if (tty->count != count) {
254 printk(KERN_WARNING "Warning: dev (%s) tty->count(%d) "
255 "!= #fd's(%d) in %s\n",
256 kdevname(tty->device), tty->count, count, routine);
257 return count;
258 }
259#endif
260 return 0;
261}
262
263int tty_register_ldisc(int disc, struct tty_ldisc *new_ldisc)
264{
265 if (disc < N_TTY || disc >= NR_LDISCS)
266 return -EINVAL;
267
268 if (new_ldisc) {
269 ldiscs[disc] = *new_ldisc;
270 ldiscs[disc].flags |= LDISC_FLAG_DEFINED;
271 ldiscs[disc].num = disc;
272 } else
273 memset(&ldiscs[disc], 0, sizeof(struct tty_ldisc));
274
275 return 0;
276}
277
278EXPORT_SYMBOL(tty_register_ldisc);
279
280
281static int tty_set_ldisc(struct tty_struct *tty, int ldisc)
282{
283 int retval = 0;
284 struct tty_ldisc o_ldisc;
285 char buf[64];
286
287 if ((ldisc < N_TTY) || (ldisc >= NR_LDISCS))
288 return -EINVAL;
289
290
291 if (!(ldiscs[ldisc].flags & LDISC_FLAG_DEFINED)) {
292 char modname [20];
293 sprintf(modname, "tty-ldisc-%d", ldisc);
294 request_module (modname);
295 }
296 if (!(ldiscs[ldisc].flags & LDISC_FLAG_DEFINED))
297 return -EINVAL;
298
299 if (tty->ldisc.num == ldisc)
300 return 0;
301 o_ldisc = tty->ldisc;
302
303 tty_wait_until_sent(tty, 0);
304
305
306 if (tty->ldisc.close)
307 (tty->ldisc.close)(tty);
308
309
310 tty->ldisc = ldiscs[ldisc];
311 tty->termios->c_line = ldisc;
312 if (tty->ldisc.open)
313 retval = (tty->ldisc.open)(tty);
314 if (retval < 0) {
315 tty->ldisc = o_ldisc;
316 tty->termios->c_line = tty->ldisc.num;
317 if (tty->ldisc.open && (tty->ldisc.open(tty) < 0)) {
318 tty->ldisc = ldiscs[N_TTY];
319 tty->termios->c_line = N_TTY;
320 if (tty->ldisc.open) {
321 int r = tty->ldisc.open(tty);
322
323 if (r < 0)
324 panic("Couldn't open N_TTY ldisc for "
325 "%s --- error %d.",
326 tty_name(tty, buf), r);
327 }
328 }
329 }
330 if (tty->ldisc.num != o_ldisc.num && tty->driver.set_ldisc)
331 tty->driver.set_ldisc(tty);
332 return retval;
333}
334
335
336
337
338struct tty_driver *get_tty_driver(kdev_t device)
339{
340 int major, minor;
341 struct tty_driver *p;
342
343 minor = MINOR(device);
344 major = MAJOR(device);
345
346 for (p = tty_drivers; p; p = p->next) {
347 if (p->major != major)
348 continue;
349 if (minor < p->minor_start)
350 continue;
351 if (minor >= p->minor_start + p->num)
352 continue;
353 return p;
354 }
355 return NULL;
356}
357
358
359
360
361
362
363int tty_check_change(struct tty_struct * tty)
364{
365 if (current->tty != tty)
366 return 0;
367 if (tty->pgrp <= 0) {
368 printk(KERN_WARNING "tty_check_change: tty->pgrp <= 0!\n");
369 return 0;
370 }
371 if (current->pgrp == tty->pgrp)
372 return 0;
373 if (is_ignored(SIGTTOU))
374 return 0;
375 if (is_orphaned_pgrp(current->pgrp))
376 return -EIO;
377 (void) kill_pg(current->pgrp,SIGTTOU,1);
378 return -ERESTARTSYS;
379}
380
381static ssize_t hung_up_tty_read(struct file * file, char * buf,
382 size_t count, loff_t *ppos)
383{
384
385 if (ppos != &file->f_pos)
386 return -ESPIPE;
387 return 0;
388}
389
390static ssize_t hung_up_tty_write(struct file * file, const char * buf,
391 size_t count, loff_t *ppos)
392{
393
394 if (ppos != &file->f_pos)
395 return -ESPIPE;
396 return -EIO;
397}
398
399
400static unsigned int hung_up_tty_poll(struct file * filp, poll_table * wait)
401{
402 return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM;
403}
404
405static int hung_up_tty_ioctl(struct inode * inode, struct file * file,
406 unsigned int cmd, unsigned long arg)
407{
408 return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
409}
410
411static struct file_operations tty_fops = {
412 llseek: no_llseek,
413 read: tty_read,
414 write: tty_write,
415 poll: tty_poll,
416 ioctl: tty_ioctl,
417 open: tty_open,
418 release: tty_release,
419 fasync: tty_fasync,
420};
421
422static struct file_operations hung_up_tty_fops = {
423 llseek: no_llseek,
424 read: hung_up_tty_read,
425 write: hung_up_tty_write,
426 poll: hung_up_tty_poll,
427 ioctl: hung_up_tty_ioctl,
428 release: tty_release,
429};
430
431static spinlock_t redirect_lock = SPIN_LOCK_UNLOCKED;
432static struct file *redirect;
433
434
435
436
437
438void do_tty_hangup(void *data)
439{
440 struct tty_struct *tty = (struct tty_struct *) data;
441 struct file * cons_filp = NULL;
442 struct file *f = NULL;
443 struct task_struct *p;
444 struct list_head *l;
445 int closecount = 0, n;
446
447 if (!tty)
448 return;
449
450
451 lock_kernel();
452
453 spin_lock(&redirect_lock);
454 if (redirect && redirect->private_data == tty) {
455 f = redirect;
456 redirect = NULL;
457 }
458 spin_unlock(&redirect_lock);
459
460 check_tty_count(tty, "do_tty_hangup");
461 file_list_lock();
462 for (l = tty->tty_files.next; l != &tty->tty_files; l = l->next) {
463 struct file * filp = list_entry(l, struct file, f_list);
464 if (filp->f_dentry->d_inode->i_rdev == CONSOLE_DEV ||
465 filp->f_dentry->d_inode->i_rdev == SYSCONS_DEV) {
466 cons_filp = filp;
467 continue;
468 }
469 if (filp->f_op != &tty_fops)
470 continue;
471 closecount++;
472 tty_fasync(-1, filp, 0);
473 filp->f_op = &hung_up_tty_fops;
474 }
475 file_list_unlock();
476
477
478 {
479 unsigned long flags;
480
481 save_flags(flags); cli();
482 if (tty->ldisc.flush_buffer)
483 tty->ldisc.flush_buffer(tty);
484 if (tty->driver.flush_buffer)
485 tty->driver.flush_buffer(tty);
486 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) &&
487 tty->ldisc.write_wakeup)
488 (tty->ldisc.write_wakeup)(tty);
489 restore_flags(flags);
490 }
491
492 wake_up_interruptible(&tty->write_wait);
493 wake_up_interruptible(&tty->read_wait);
494
495
496
497
498
499 if (tty->driver.flags & TTY_DRIVER_RESET_TERMIOS)
500 *tty->termios = tty->driver.init_termios;
501 if (tty->ldisc.num != ldiscs[N_TTY].num) {
502 if (tty->ldisc.close)
503 (tty->ldisc.close)(tty);
504 tty->ldisc = ldiscs[N_TTY];
505 tty->termios->c_line = N_TTY;
506 if (tty->ldisc.open) {
507 int i = (tty->ldisc.open)(tty);
508 if (i < 0)
509 printk(KERN_ERR "do_tty_hangup: N_TTY open: "
510 "error %d\n", -i);
511 }
512 }
513
514 read_lock(&tasklist_lock);
515 for_each_task(p) {
516 if ((tty->session > 0) && (p->session == tty->session) &&
517 p->leader) {
518 send_sig(SIGHUP,p,1);
519 send_sig(SIGCONT,p,1);
520 if (tty->pgrp > 0)
521 p->tty_old_pgrp = tty->pgrp;
522 }
523 if (p->tty == tty)
524 p->tty = NULL;
525 }
526 read_unlock(&tasklist_lock);
527
528 tty->flags = 0;
529 tty->session = 0;
530 tty->pgrp = -1;
531 tty->ctrl_status = 0;
532
533
534
535
536
537
538 if (cons_filp) {
539 if (tty->driver.close)
540 for (n = 0; n < closecount; n++)
541 tty->driver.close(tty, cons_filp);
542 } else if (tty->driver.hangup)
543 (tty->driver.hangup)(tty);
544 unlock_kernel();
545 if (f)
546 fput(f);
547}
548
549void tty_hangup(struct tty_struct * tty)
550{
551#ifdef TTY_DEBUG_HANGUP
552 char buf[64];
553
554 printk(KERN_DEBUG "%s hangup...\n", tty_name(tty, buf));
555#endif
556 schedule_task(&tty->tq_hangup);
557}
558
559void tty_vhangup(struct tty_struct * tty)
560{
561#ifdef TTY_DEBUG_HANGUP
562 char buf[64];
563
564 printk(KERN_DEBUG "%s vhangup...\n", tty_name(tty, buf));
565#endif
566 do_tty_hangup((void *) tty);
567}
568
569int tty_hung_up_p(struct file * filp)
570{
571 return (filp->f_op == &hung_up_tty_fops);
572}
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587void disassociate_ctty(int on_exit)
588{
589 struct tty_struct *tty = current->tty;
590 struct task_struct *p;
591 int tty_pgrp = -1;
592
593 if (tty) {
594 tty_pgrp = tty->pgrp;
595 if (on_exit && tty->driver.type != TTY_DRIVER_TYPE_PTY)
596 tty_vhangup(tty);
597 } else {
598 if (current->tty_old_pgrp) {
599 kill_pg(current->tty_old_pgrp, SIGHUP, on_exit);
600 kill_pg(current->tty_old_pgrp, SIGCONT, on_exit);
601 }
602 return;
603 }
604 if (tty_pgrp > 0) {
605 kill_pg(tty_pgrp, SIGHUP, on_exit);
606 if (!on_exit)
607 kill_pg(tty_pgrp, SIGCONT, on_exit);
608 }
609
610 current->tty_old_pgrp = 0;
611 tty->session = 0;
612 tty->pgrp = -1;
613
614 read_lock(&tasklist_lock);
615 for_each_task(p)
616 if (p->session == current->session)
617 p->tty = NULL;
618 read_unlock(&tasklist_lock);
619}
620
621void stop_tty(struct tty_struct *tty)
622{
623 if (tty->stopped)
624 return;
625 tty->stopped = 1;
626 if (tty->link && tty->link->packet) {
627 tty->ctrl_status &= ~TIOCPKT_START;
628 tty->ctrl_status |= TIOCPKT_STOP;
629 wake_up_interruptible(&tty->link->read_wait);
630 }
631 if (tty->driver.stop)
632 (tty->driver.stop)(tty);
633}
634
635void start_tty(struct tty_struct *tty)
636{
637 if (!tty->stopped || tty->flow_stopped)
638 return;
639 tty->stopped = 0;
640 if (tty->link && tty->link->packet) {
641 tty->ctrl_status &= ~TIOCPKT_STOP;
642 tty->ctrl_status |= TIOCPKT_START;
643 wake_up_interruptible(&tty->link->read_wait);
644 }
645 if (tty->driver.start)
646 (tty->driver.start)(tty);
647 if ((test_bit(TTY_DO_WRITE_WAKEUP, &tty->flags)) &&
648 tty->ldisc.write_wakeup)
649 (tty->ldisc.write_wakeup)(tty);
650 wake_up_interruptible(&tty->write_wait);
651}
652
653static ssize_t tty_read(struct file * file, char * buf, size_t count,
654 loff_t *ppos)
655{
656 int i;
657 struct tty_struct * tty;
658 struct inode *inode;
659
660
661 if (ppos != &file->f_pos)
662 return -ESPIPE;
663
664 tty = (struct tty_struct *)file->private_data;
665 inode = file->f_dentry->d_inode;
666 if (tty_paranoia_check(tty, inode->i_rdev, "tty_read"))
667 return -EIO;
668 if (!tty || (test_bit(TTY_IO_ERROR, &tty->flags)))
669 return -EIO;
670
671
672
673
674
675#if 0
676 if ((inode->i_rdev != CONSOLE_DEV) &&
677 (tty->pgrp > 0) &&
678 (current->tty == tty) &&
679 (tty->pgrp != current->pgrp))
680 if (is_ignored(SIGTTIN) || is_orphaned_pgrp(current->pgrp))
681 return -EIO;
682 else {
683 (void) kill_pg(current->pgrp, SIGTTIN, 1);
684 return -ERESTARTSYS;
685 }
686#endif
687 lock_kernel();
688 if (tty->ldisc.read)
689 i = (tty->ldisc.read)(tty,file,buf,count);
690 else
691 i = -EIO;
692 unlock_kernel();
693 if (i > 0)
694 inode->i_atime = CURRENT_TIME;
695 return i;
696}
697
698
699
700
701
702static inline ssize_t do_tty_write(
703 ssize_t (*write)(struct tty_struct *, struct file *, const unsigned char *, size_t),
704 struct tty_struct *tty,
705 struct file *file,
706 const unsigned char *buf,
707 size_t count)
708{
709 ssize_t ret = 0, written = 0;
710
711 if (file->f_flags & O_NONBLOCK) {
712 if (down_trylock(&tty->atomic_write))
713 return -EAGAIN;
714 }
715 else {
716 if (down_interruptible(&tty->atomic_write))
717 return -ERESTARTSYS;
718 }
719 if ( test_bit(TTY_NO_WRITE_SPLIT, &tty->flags) ) {
720 lock_kernel();
721 written = write(tty, file, buf, count);
722 unlock_kernel();
723 } else {
724 for (;;) {
725 unsigned long size = MAX(PAGE_SIZE*2,16384);
726 if (size > count)
727 size = count;
728 lock_kernel();
729 ret = write(tty, file, buf, size);
730 unlock_kernel();
731 if (ret <= 0)
732 break;
733 written += ret;
734 buf += ret;
735 count -= ret;
736 if (!count)
737 break;
738 ret = -ERESTARTSYS;
739 if (signal_pending(current))
740 break;
741 if (current->need_resched)
742 schedule();
743 }
744 }
745 if (written) {
746 file->f_dentry->d_inode->i_mtime = CURRENT_TIME;
747 ret = written;
748 }
749 up(&tty->atomic_write);
750 return ret;
751}
752
753
754static ssize_t tty_write(struct file * file, const char * buf, size_t count,
755 loff_t *ppos)
756{
757 int is_console;
758 struct tty_struct * tty;
759 struct inode *inode = file->f_dentry->d_inode;
760
761
762 if (ppos != &file->f_pos)
763 return -ESPIPE;
764
765
766
767
768
769 inode = file->f_dentry->d_inode;
770 is_console = (inode->i_rdev == SYSCONS_DEV ||
771 inode->i_rdev == CONSOLE_DEV);
772
773 if (is_console) {
774 struct file *p = NULL;
775
776 spin_lock(&redirect_lock);
777 if (redirect) {
778 get_file(redirect);
779 p = redirect;
780 }
781 spin_unlock(&redirect_lock);
782
783 if (p) {
784 ssize_t res = p->f_op->write(p, buf, count, &p->f_pos);
785 fput(p);
786 return res;
787 }
788 }
789
790 tty = (struct tty_struct *)file->private_data;
791 if (tty_paranoia_check(tty, inode->i_rdev, "tty_write"))
792 return -EIO;
793 if (!tty || !tty->driver.write || (test_bit(TTY_IO_ERROR, &tty->flags)))
794 return -EIO;
795#if 0
796 if (!is_console && L_TOSTOP(tty) && (tty->pgrp > 0) &&
797 (current->tty == tty) && (tty->pgrp != current->pgrp)) {
798 if (is_orphaned_pgrp(current->pgrp))
799 return -EIO;
800 if (!is_ignored(SIGTTOU)) {
801 (void) kill_pg(current->pgrp, SIGTTOU, 1);
802 return -ERESTARTSYS;
803 }
804 }
805#endif
806 if (!tty->ldisc.write)
807 return -EIO;
808 return do_tty_write(tty->ldisc.write, tty, file,
809 (const unsigned char *)buf, count);
810}
811
812
813static DECLARE_MUTEX(tty_sem);
814
815static void down_tty_sem(int index)
816{
817 down(&tty_sem);
818}
819
820static void up_tty_sem(int index)
821{
822 up(&tty_sem);
823}
824
825static void release_mem(struct tty_struct *tty, int idx);
826
827
828
829
830
831
832
833static int init_dev(kdev_t device, struct tty_struct **ret_tty)
834{
835 struct tty_struct *tty, *o_tty;
836 struct termios *tp, **tp_loc, *o_tp, **o_tp_loc;
837 struct termios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
838 struct tty_driver *driver;
839 int retval=0;
840 int idx;
841
842 driver = get_tty_driver(device);
843 if (!driver)
844 return -ENODEV;
845
846 idx = MINOR(device) - driver->minor_start;
847
848
849
850
851
852 down_tty_sem(idx);
853
854
855 tty = driver->table[idx];
856 if (tty) goto fast_track;
857
858
859
860
861
862
863
864
865
866 o_tty = NULL;
867 tp = o_tp = NULL;
868 ltp = o_ltp = NULL;
869
870 tty = alloc_tty_struct();
871 if(!tty)
872 goto fail_no_mem;
873 initialize_tty_struct(tty);
874 tty->device = device;
875 tty->driver = *driver;
876
877 tp_loc = &driver->termios[idx];
878 if (!*tp_loc) {
879 tp = (struct termios *) kmalloc(sizeof(struct termios),
880 GFP_KERNEL);
881 if (!tp)
882 goto free_mem_out;
883 *tp = driver->init_termios;
884 }
885
886 ltp_loc = &driver->termios_locked[idx];
887 if (!*ltp_loc) {
888 ltp = (struct termios *) kmalloc(sizeof(struct termios),
889 GFP_KERNEL);
890 if (!ltp)
891 goto free_mem_out;
892 memset(ltp, 0, sizeof(struct termios));
893 }
894
895 if (driver->type == TTY_DRIVER_TYPE_PTY) {
896 o_tty = alloc_tty_struct();
897 if (!o_tty)
898 goto free_mem_out;
899 initialize_tty_struct(o_tty);
900 o_tty->device = (kdev_t) MKDEV(driver->other->major,
901 driver->other->minor_start + idx);
902 o_tty->driver = *driver->other;
903
904 o_tp_loc = &driver->other->termios[idx];
905 if (!*o_tp_loc) {
906 o_tp = (struct termios *)
907 kmalloc(sizeof(struct termios), GFP_KERNEL);
908 if (!o_tp)
909 goto free_mem_out;
910 *o_tp = driver->other->init_termios;
911 }
912
913 o_ltp_loc = &driver->other->termios_locked[idx];
914 if (!*o_ltp_loc) {
915 o_ltp = (struct termios *)
916 kmalloc(sizeof(struct termios), GFP_KERNEL);
917 if (!o_ltp)
918 goto free_mem_out;
919 memset(o_ltp, 0, sizeof(struct termios));
920 }
921
922
923
924
925 driver->other->table[idx] = o_tty;
926 if (!*o_tp_loc)
927 *o_tp_loc = o_tp;
928 if (!*o_ltp_loc)
929 *o_ltp_loc = o_ltp;
930 o_tty->termios = *o_tp_loc;
931 o_tty->termios_locked = *o_ltp_loc;
932 (*driver->other->refcount)++;
933 if (driver->subtype == PTY_TYPE_MASTER)
934 o_tty->count++;
935
936
937 tty->link = o_tty;
938 o_tty->link = tty;
939 }
940
941
942
943
944
945
946 driver->table[idx] = tty;
947
948 if (!*tp_loc)
949 *tp_loc = tp;
950 if (!*ltp_loc)
951 *ltp_loc = ltp;
952 tty->termios = *tp_loc;
953 tty->termios_locked = *ltp_loc;
954 (*driver->refcount)++;
955 tty->count++;
956
957
958
959
960
961
962 if (tty->ldisc.open) {
963 retval = (tty->ldisc.open)(tty);
964 if (retval)
965 goto release_mem_out;
966 }
967 if (o_tty && o_tty->ldisc.open) {
968 retval = (o_tty->ldisc.open)(o_tty);
969 if (retval) {
970 if (tty->ldisc.close)
971 (tty->ldisc.close)(tty);
972 goto release_mem_out;
973 }
974 }
975 goto success;
976
977
978
979
980
981
982
983fast_track:
984 if (test_bit(TTY_CLOSING, &tty->flags)) {
985 retval = -EIO;
986 goto end_init;
987 }
988 if (driver->type == TTY_DRIVER_TYPE_PTY &&
989 driver->subtype == PTY_TYPE_MASTER) {
990
991
992
993
994 if (tty->count) {
995 retval = -EIO;
996 goto end_init;
997 }
998 tty->link->count++;
999 }
1000 tty->count++;
1001 tty->driver = *driver;
1002
1003success:
1004 *ret_tty = tty;
1005
1006
1007end_init:
1008 up_tty_sem(idx);
1009 return retval;
1010
1011
1012free_mem_out:
1013 if (o_tp)
1014 kfree(o_tp);
1015 if (o_tty)
1016 free_tty_struct(o_tty);
1017 if (ltp)
1018 kfree(ltp);
1019 if (tp)
1020 kfree(tp);
1021 free_tty_struct(tty);
1022
1023fail_no_mem:
1024 retval = -ENOMEM;
1025 goto end_init;
1026
1027
1028release_mem_out:
1029 printk(KERN_INFO "init_dev: ldisc open failed, "
1030 "clearing slot %d\n", idx);
1031 release_mem(tty, idx);
1032 goto end_init;
1033}
1034
1035
1036
1037
1038
1039static void release_mem(struct tty_struct *tty, int idx)
1040{
1041 struct tty_struct *o_tty;
1042 struct termios *tp;
1043
1044 if ((o_tty = tty->link) != NULL) {
1045 o_tty->driver.table[idx] = NULL;
1046 if (o_tty->driver.flags & TTY_DRIVER_RESET_TERMIOS) {
1047 tp = o_tty->driver.termios[idx];
1048 o_tty->driver.termios[idx] = NULL;
1049 kfree(tp);
1050 }
1051 o_tty->magic = 0;
1052 (*o_tty->driver.refcount)--;
1053 list_del_init(&o_tty->tty_files);
1054 free_tty_struct(o_tty);
1055 }
1056
1057 tty->driver.table[idx] = NULL;
1058 if (tty->driver.flags & TTY_DRIVER_RESET_TERMIOS) {
1059 tp = tty->driver.termios[idx];
1060 tty->driver.termios[idx] = NULL;
1061 kfree(tp);
1062 }
1063 tty->magic = 0;
1064 (*tty->driver.refcount)--;
1065 list_del_init(&tty->tty_files);
1066 free_tty_struct(tty);
1067}
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077static void release_dev(struct file * filp)
1078{
1079 struct tty_struct *tty, *o_tty;
1080 int pty_master, tty_closing, o_tty_closing, do_sleep;
1081 int idx;
1082 char buf[64];
1083
1084 tty = (struct tty_struct *)filp->private_data;
1085 if (tty_paranoia_check(tty, filp->f_dentry->d_inode->i_rdev, "release_dev"))
1086 return;
1087
1088 check_tty_count(tty, "release_dev");
1089
1090 tty_fasync(-1, filp, 0);
1091
1092 idx = MINOR(tty->device) - tty->driver.minor_start;
1093 pty_master = (tty->driver.type == TTY_DRIVER_TYPE_PTY &&
1094 tty->driver.subtype == PTY_TYPE_MASTER);
1095 o_tty = tty->link;
1096
1097#ifdef TTY_PARANOIA_CHECK
1098 if (idx < 0 || idx >= tty->driver.num) {
1099 printk(KERN_DEBUG "release_dev: bad idx when trying to "
1100 "free (%s)\n", kdevname(tty->device));
1101 return;
1102 }
1103 if (tty != tty->driver.table[idx]) {
1104 printk(KERN_DEBUG "release_dev: driver.table[%d] not tty "
1105 "for (%s)\n", idx, kdevname(tty->device));
1106 return;
1107 }
1108 if (tty->termios != tty->driver.termios[idx]) {
1109 printk(KERN_DEBUG "release_dev: driver.termios[%d] not termios "
1110 "for (%s)\n",
1111 idx, kdevname(tty->device));
1112 return;
1113 }
1114 if (tty->termios_locked != tty->driver.termios_locked[idx]) {
1115 printk(KERN_DEBUG "release_dev: driver.termios_locked[%d] not "
1116 "termios_locked for (%s)\n",
1117 idx, kdevname(tty->device));
1118 return;
1119 }
1120#endif
1121
1122#ifdef TTY_DEBUG_HANGUP
1123 printk(KERN_DEBUG "release_dev of %s (tty count=%d)...",
1124 tty_name(tty, buf), tty->count);
1125#endif
1126
1127#ifdef TTY_PARANOIA_CHECK
1128 if (tty->driver.other) {
1129 if (o_tty != tty->driver.other->table[idx]) {
1130 printk(KERN_DEBUG "release_dev: other->table[%d] "
1131 "not o_tty for (%s)\n",
1132 idx, kdevname(tty->device));
1133 return;
1134 }
1135 if (o_tty->termios != tty->driver.other->termios[idx]) {
1136 printk(KERN_DEBUG "release_dev: other->termios[%d] "
1137 "not o_termios for (%s)\n",
1138 idx, kdevname(tty->device));
1139 return;
1140 }
1141 if (o_tty->termios_locked !=
1142 tty->driver.other->termios_locked[idx]) {
1143 printk(KERN_DEBUG "release_dev: other->termios_locked["
1144 "%d] not o_termios_locked for (%s)\n",
1145 idx, kdevname(tty->device));
1146 return;
1147 }
1148 if (o_tty->link != tty) {
1149 printk(KERN_DEBUG "release_dev: bad pty pointers\n");
1150 return;
1151 }
1152 }
1153#endif
1154
1155 if (tty->driver.close)
1156 tty->driver.close(tty, filp);
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175 while (1) {
1176 tty_closing = tty->count <= 1;
1177 o_tty_closing = o_tty &&
1178 (o_tty->count <= (pty_master ? 1 : 0));
1179 do_sleep = 0;
1180
1181 if (tty_closing) {
1182 if (waitqueue_active(&tty->read_wait)) {
1183 wake_up(&tty->read_wait);
1184 do_sleep++;
1185 }
1186 if (waitqueue_active(&tty->write_wait)) {
1187 wake_up(&tty->write_wait);
1188 do_sleep++;
1189 }
1190 }
1191 if (o_tty_closing) {
1192 if (waitqueue_active(&o_tty->read_wait)) {
1193 wake_up(&o_tty->read_wait);
1194 do_sleep++;
1195 }
1196 if (waitqueue_active(&o_tty->write_wait)) {
1197 wake_up(&o_tty->write_wait);
1198 do_sleep++;
1199 }
1200 }
1201 if (!do_sleep)
1202 break;
1203
1204 printk(KERN_WARNING "release_dev: %s: read/write wait queue "
1205 "active!\n", tty_name(tty, buf));
1206 schedule();
1207 }
1208
1209
1210
1211
1212
1213
1214 if (pty_master) {
1215 if (--o_tty->count < 0) {
1216 printk(KERN_WARNING "release_dev: bad pty slave count "
1217 "(%d) for %s\n",
1218 o_tty->count, tty_name(o_tty, buf));
1219 o_tty->count = 0;
1220 }
1221 }
1222 if (--tty->count < 0) {
1223 printk(KERN_WARNING "release_dev: bad tty->count (%d) for %s\n",
1224 tty->count, tty_name(tty, buf));
1225 tty->count = 0;
1226 }
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236 filp->private_data = 0;
1237
1238
1239
1240
1241
1242
1243
1244
1245 if(tty_closing)
1246 set_bit(TTY_CLOSING, &tty->flags);
1247 if(o_tty_closing)
1248 set_bit(TTY_CLOSING, &o_tty->flags);
1249
1250
1251
1252
1253
1254
1255 if (tty_closing || o_tty_closing) {
1256 struct task_struct *p;
1257
1258 read_lock(&tasklist_lock);
1259 for_each_task(p) {
1260 if (p->tty == tty || (o_tty && p->tty == o_tty))
1261 p->tty = NULL;
1262 }
1263 read_unlock(&tasklist_lock);
1264 }
1265
1266
1267 if (!tty_closing || (o_tty && !o_tty_closing))
1268 return;
1269
1270#ifdef TTY_DEBUG_HANGUP
1271 printk(KERN_DEBUG "freeing tty structure...");
1272#endif
1273
1274
1275
1276
1277
1278 if (tty->ldisc.close)
1279 (tty->ldisc.close)(tty);
1280 tty->ldisc = ldiscs[N_TTY];
1281 tty->termios->c_line = N_TTY;
1282 if (o_tty) {
1283 if (o_tty->ldisc.close)
1284 (o_tty->ldisc.close)(o_tty);
1285 o_tty->ldisc = ldiscs[N_TTY];
1286 }
1287
1288
1289
1290
1291 run_task_queue(&tq_timer);
1292 flush_scheduled_tasks();
1293
1294
1295
1296
1297
1298 release_mem(tty, idx);
1299}
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313static int tty_open(struct inode * inode, struct file * filp)
1314{
1315 struct tty_struct *tty;
1316 int noctty, retval;
1317 kdev_t device;
1318 unsigned short saved_flags;
1319 char buf[64];
1320
1321 saved_flags = filp->f_flags;
1322retry_open:
1323 noctty = filp->f_flags & O_NOCTTY;
1324 device = inode->i_rdev;
1325 if (device == TTY_DEV) {
1326 if (!current->tty)
1327 return -ENXIO;
1328 device = current->tty->device;
1329 filp->f_flags |= O_NONBLOCK;
1330
1331 }
1332#ifdef CONFIG_VT
1333 if (device == CONSOLE_DEV) {
1334 extern int fg_console;
1335 device = MKDEV(TTY_MAJOR, fg_console + 1);
1336 noctty = 1;
1337 }
1338#endif
1339 if (device == SYSCONS_DEV) {
1340 struct console *c = console_drivers;
1341 while(c && !c->device)
1342 c = c->next;
1343 if (!c)
1344 return -ENODEV;
1345 device = c->device(c);
1346 filp->f_flags |= O_NONBLOCK;
1347 noctty = 1;
1348 }
1349
1350 if (device == PTMX_DEV) {
1351#ifdef CONFIG_UNIX98_PTYS
1352
1353
1354 int major, minor;
1355 struct tty_driver *driver;
1356
1357
1358 retval = -1;
1359 for ( major = 0 ; major < UNIX98_NR_MAJORS ; major++ ) {
1360 driver = &ptm_driver[major];
1361 for (minor = driver->minor_start ;
1362 minor < driver->minor_start + driver->num ;
1363 minor++) {
1364 device = MKDEV(driver->major, minor);
1365 if (!init_dev(device, &tty)) goto ptmx_found;
1366 }
1367 }
1368 return -EIO;
1369 ptmx_found:
1370 set_bit(TTY_PTY_LOCK, &tty->flags);
1371 minor -= driver->minor_start;
1372 devpts_pty_new(driver->other->name_base + minor, MKDEV(driver->other->major, minor + driver->other->minor_start));
1373 tty_register_devfs(&pts_driver[major], DEVFS_FL_DEFAULT,
1374 pts_driver[major].minor_start + minor);
1375 noctty = 1;
1376 goto init_dev_done;
1377
1378#else
1379
1380 return -ENODEV;
1381
1382#endif
1383 }
1384
1385 retval = init_dev(device, &tty);
1386 if (retval)
1387 return retval;
1388
1389#ifdef CONFIG_UNIX98_PTYS
1390init_dev_done:
1391#endif
1392 filp->private_data = tty;
1393 file_move(filp, &tty->tty_files);
1394 check_tty_count(tty, "tty_open");
1395 if (tty->driver.type == TTY_DRIVER_TYPE_PTY &&
1396 tty->driver.subtype == PTY_TYPE_MASTER)
1397 noctty = 1;
1398#ifdef TTY_DEBUG_HANGUP
1399 printk(KERN_DEBUG "opening %s...", tty_name(tty, buf));
1400#endif
1401 if (tty->driver.open)
1402 retval = tty->driver.open(tty, filp);
1403 else
1404 retval = -ENODEV;
1405 filp->f_flags = saved_flags;
1406
1407 if (!retval && test_bit(TTY_EXCLUSIVE, &tty->flags) && !suser())
1408 retval = -EBUSY;
1409
1410 if (retval) {
1411#ifdef TTY_DEBUG_HANGUP
1412 printk(KERN_DEBUG "error %d in opening %s...", retval,
1413 tty_name(tty, buf));
1414#endif
1415
1416 release_dev(filp);
1417 if (retval != -ERESTARTSYS)
1418 return retval;
1419 if (signal_pending(current))
1420 return retval;
1421 schedule();
1422
1423
1424
1425 filp->f_op = &tty_fops;
1426 goto retry_open;
1427 }
1428 if (!noctty &&
1429 current->leader &&
1430 !current->tty &&
1431 tty->session == 0) {
1432 task_lock(current);
1433 current->tty = tty;
1434 task_unlock(current);
1435 current->tty_old_pgrp = 0;
1436 tty->session = current->session;
1437 tty->pgrp = current->pgrp;
1438 }
1439 if ((tty->driver.type == TTY_DRIVER_TYPE_SERIAL) &&
1440 (tty->driver.subtype == SERIAL_TYPE_CALLOUT) &&
1441 (tty->count == 1)) {
1442 static int nr_warns;
1443 if (nr_warns < 5) {
1444 printk(KERN_WARNING "tty_io.c: "
1445 "process %d (%s) used obsolete /dev/%s - "
1446 "update software to use /dev/ttyS%d\n",
1447 current->pid, current->comm,
1448 tty_name(tty, buf), TTY_NUMBER(tty));
1449 nr_warns++;
1450 }
1451 }
1452 return 0;
1453}
1454
1455static int tty_release(struct inode * inode, struct file * filp)
1456{
1457 lock_kernel();
1458 release_dev(filp);
1459 unlock_kernel();
1460 return 0;
1461}
1462
1463
1464static unsigned int tty_poll(struct file * filp, poll_table * wait)
1465{
1466 struct tty_struct * tty;
1467
1468 tty = (struct tty_struct *)filp->private_data;
1469 if (tty_paranoia_check(tty, filp->f_dentry->d_inode->i_rdev, "tty_poll"))
1470 return 0;
1471
1472 if (tty->ldisc.poll)
1473 return (tty->ldisc.poll)(tty, filp, wait);
1474 return 0;
1475}
1476
1477static int tty_fasync(int fd, struct file * filp, int on)
1478{
1479 struct tty_struct * tty;
1480 int retval;
1481
1482 tty = (struct tty_struct *)filp->private_data;
1483 if (tty_paranoia_check(tty, filp->f_dentry->d_inode->i_rdev, "tty_fasync"))
1484 return 0;
1485
1486 retval = fasync_helper(fd, filp, on, &tty->fasync);
1487 if (retval <= 0)
1488 return retval;
1489
1490 if (on) {
1491 if (!waitqueue_active(&tty->read_wait))
1492 tty->minimum_to_wake = 1;
1493 if (filp->f_owner.pid == 0) {
1494 filp->f_owner.pid = (-tty->pgrp) ? : current->pid;
1495 filp->f_owner.uid = current->uid;
1496 filp->f_owner.euid = current->euid;
1497 }
1498 } else {
1499 if (!tty->fasync && !waitqueue_active(&tty->read_wait))
1500 tty->minimum_to_wake = N_TTY_BUF_SIZE;
1501 }
1502 return 0;
1503}
1504
1505static int tiocsti(struct tty_struct *tty, char * arg)
1506{
1507 char ch, mbz = 0;
1508
1509 if ((current->tty != tty) && !suser())
1510 return -EPERM;
1511 if (get_user(ch, arg))
1512 return -EFAULT;
1513 tty->ldisc.receive_buf(tty, &ch, &mbz, 1);
1514 return 0;
1515}
1516
1517static int tiocgwinsz(struct tty_struct *tty, struct winsize * arg)
1518{
1519 if (copy_to_user(arg, &tty->winsize, sizeof(*arg)))
1520 return -EFAULT;
1521 return 0;
1522}
1523
1524static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
1525 struct winsize * arg)
1526{
1527 struct winsize tmp_ws;
1528
1529 if (copy_from_user(&tmp_ws, arg, sizeof(*arg)))
1530 return -EFAULT;
1531 if (!memcmp(&tmp_ws, &tty->winsize, sizeof(*arg)))
1532 return 0;
1533 if (tty->pgrp > 0)
1534 kill_pg(tty->pgrp, SIGWINCH, 1);
1535 if ((real_tty->pgrp != tty->pgrp) && (real_tty->pgrp > 0))
1536 kill_pg(real_tty->pgrp, SIGWINCH, 1);
1537 tty->winsize = tmp_ws;
1538 real_tty->winsize = tmp_ws;
1539 return 0;
1540}
1541
1542static int tioccons(struct inode *inode, struct file *file)
1543{
1544 if (inode->i_rdev == SYSCONS_DEV ||
1545 inode->i_rdev == CONSOLE_DEV) {
1546 struct file *f;
1547 if (!suser())
1548 return -EPERM;
1549 spin_lock(&redirect_lock);
1550 f = redirect;
1551 redirect = NULL;
1552 spin_unlock(&redirect_lock);
1553 if (f)
1554 fput(f);
1555 return 0;
1556 }
1557 spin_lock(&redirect_lock);
1558 if (redirect) {
1559 spin_unlock(&redirect_lock);
1560 return -EBUSY;
1561 }
1562 get_file(file);
1563 redirect = file;
1564 spin_unlock(&redirect_lock);
1565 return 0;
1566}
1567
1568
1569static int fionbio(struct file *file, int *arg)
1570{
1571 int nonblock;
1572
1573 if (get_user(nonblock, arg))
1574 return -EFAULT;
1575
1576 if (nonblock)
1577 file->f_flags |= O_NONBLOCK;
1578 else
1579 file->f_flags &= ~O_NONBLOCK;
1580 return 0;
1581}
1582
1583static int tiocsctty(struct tty_struct *tty, int arg)
1584{
1585 if (current->leader &&
1586 (current->session == tty->session))
1587 return 0;
1588
1589
1590
1591
1592 if (!current->leader || current->tty)
1593 return -EPERM;
1594 if (tty->session > 0) {
1595
1596
1597
1598
1599 if ((arg == 1) && suser()) {
1600
1601
1602
1603 struct task_struct *p;
1604
1605 read_lock(&tasklist_lock);
1606 for_each_task(p)
1607 if (p->tty == tty)
1608 p->tty = NULL;
1609 read_unlock(&tasklist_lock);
1610 } else
1611 return -EPERM;
1612 }
1613 task_lock(current);
1614 current->tty = tty;
1615 task_unlock(current);
1616 current->tty_old_pgrp = 0;
1617 tty->session = current->session;
1618 tty->pgrp = current->pgrp;
1619 return 0;
1620}
1621
1622static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t *arg)
1623{
1624
1625
1626
1627
1628 if (tty == real_tty && current->tty != real_tty)
1629 return -ENOTTY;
1630 return put_user(real_tty->pgrp, arg);
1631}
1632
1633static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t *arg)
1634{
1635 pid_t pgrp;
1636 int retval = tty_check_change(real_tty);
1637
1638 if (retval == -EIO)
1639 return -ENOTTY;
1640 if (retval)
1641 return retval;
1642 if (!current->tty ||
1643 (current->tty != real_tty) ||
1644 (real_tty->session != current->session))
1645 return -ENOTTY;
1646 if (get_user(pgrp, (pid_t *) arg))
1647 return -EFAULT;
1648 if (pgrp < 0)
1649 return -EINVAL;
1650 if (session_of_pgrp(pgrp) != current->session)
1651 return -EPERM;
1652 real_tty->pgrp = pgrp;
1653 return 0;
1654}
1655
1656static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t *arg)
1657{
1658
1659
1660
1661
1662 if (tty == real_tty && current->tty != real_tty)
1663 return -ENOTTY;
1664 if (real_tty->session <= 0)
1665 return -ENOTTY;
1666 return put_user(real_tty->session, arg);
1667}
1668
1669static int tiocttygstruct(struct tty_struct *tty, struct tty_struct *arg)
1670{
1671 if (copy_to_user(arg, tty, sizeof(*arg)))
1672 return -EFAULT;
1673 return 0;
1674}
1675
1676static int tiocsetd(struct tty_struct *tty, int *arg)
1677{
1678 int ldisc;
1679
1680 if (get_user(ldisc, arg))
1681 return -EFAULT;
1682 return tty_set_ldisc(tty, ldisc);
1683}
1684
1685static int send_break(struct tty_struct *tty, int duration)
1686{
1687 tty->driver.break_ctl(tty, -1);
1688 if (!signal_pending(current)) {
1689 set_current_state(TASK_INTERRUPTIBLE);
1690 schedule_timeout(duration);
1691 }
1692 tty->driver.break_ctl(tty, 0);
1693 if (signal_pending(current))
1694 return -EINTR;
1695 return 0;
1696}
1697
1698static int tty_generic_brk(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1699{
1700 if (cmd == TCSBRK && arg)
1701 {
1702
1703 int retval = tty_check_change(tty);
1704 if (retval)
1705 return retval;
1706 tty_wait_until_sent(tty, 0);
1707 if (signal_pending(current))
1708 return -EINTR;
1709 }
1710 return 0;
1711}
1712
1713
1714
1715
1716int tty_ioctl(struct inode * inode, struct file * file,
1717 unsigned int cmd, unsigned long arg)
1718{
1719 struct tty_struct *tty, *real_tty;
1720 int retval;
1721
1722 tty = (struct tty_struct *)file->private_data;
1723 if (tty_paranoia_check(tty, inode->i_rdev, "tty_ioctl"))
1724 return -EINVAL;
1725
1726 real_tty = tty;
1727 if (tty->driver.type == TTY_DRIVER_TYPE_PTY &&
1728 tty->driver.subtype == PTY_TYPE_MASTER)
1729 real_tty = tty->link;
1730
1731
1732
1733
1734 if (!tty->driver.break_ctl) {
1735 switch(cmd) {
1736 case TIOCSBRK:
1737 case TIOCCBRK:
1738 if (tty->driver.ioctl)
1739 return tty->driver.ioctl(tty, file, cmd, arg);
1740 return -EINVAL;
1741
1742
1743
1744 case TCSBRK:
1745 case TCSBRKP:
1746 retval = -ENOIOCTLCMD;
1747 if (tty->driver.ioctl)
1748 retval = tty->driver.ioctl(tty, file, cmd, arg);
1749
1750 if (retval == -ENOIOCTLCMD)
1751 retval = tty_generic_brk(tty, file, cmd, arg);
1752 return retval;
1753 }
1754 }
1755
1756
1757
1758
1759 switch (cmd) {
1760 case TIOCSETD:
1761 case TIOCSBRK:
1762 case TIOCCBRK:
1763 case TCSBRK:
1764 case TCSBRKP:
1765 retval = tty_check_change(tty);
1766 if (retval)
1767 return retval;
1768 if (cmd != TIOCCBRK) {
1769 tty_wait_until_sent(tty, 0);
1770 if (signal_pending(current))
1771 return -EINTR;
1772 }
1773 break;
1774 }
1775
1776 switch (cmd) {
1777 case TIOCSTI:
1778 return tiocsti(tty, (char *)arg);
1779 case TIOCGWINSZ:
1780 return tiocgwinsz(tty, (struct winsize *) arg);
1781 case TIOCSWINSZ:
1782 return tiocswinsz(tty, real_tty, (struct winsize *) arg);
1783 case TIOCCONS:
1784 return real_tty!=tty ? -EINVAL : tioccons(inode, file);
1785 case FIONBIO:
1786 return fionbio(file, (int *) arg);
1787 case TIOCEXCL:
1788 set_bit(TTY_EXCLUSIVE, &tty->flags);
1789 return 0;
1790 case TIOCNXCL:
1791 clear_bit(TTY_EXCLUSIVE, &tty->flags);
1792 return 0;
1793 case TIOCNOTTY:
1794 if (current->tty != tty)
1795 return -ENOTTY;
1796 if (current->leader)
1797 disassociate_ctty(0);
1798 task_lock(current);
1799 current->tty = NULL;
1800 task_unlock(current);
1801 return 0;
1802 case TIOCSCTTY:
1803 return tiocsctty(tty, arg);
1804 case TIOCGPGRP:
1805 return tiocgpgrp(tty, real_tty, (pid_t *) arg);
1806 case TIOCSPGRP:
1807 return tiocspgrp(tty, real_tty, (pid_t *) arg);
1808 case TIOCGSID:
1809 return tiocgsid(tty, real_tty, (pid_t *) arg);
1810 case TIOCGETD:
1811 return put_user(tty->ldisc.num, (int *) arg);
1812 case TIOCSETD:
1813 return tiocsetd(tty, (int *) arg);
1814#ifdef CONFIG_VT
1815 case TIOCLINUX:
1816 return tioclinux(tty, arg);
1817#endif
1818 case TIOCTTYGSTRUCT:
1819 return tiocttygstruct(tty, (struct tty_struct *) arg);
1820
1821
1822
1823
1824 case TIOCSBRK:
1825 tty->driver.break_ctl(tty, -1);
1826 return 0;
1827
1828 case TIOCCBRK:
1829 tty->driver.break_ctl(tty, 0);
1830 return 0;
1831 case TCSBRK:
1832
1833
1834
1835
1836
1837 if (!arg)
1838 return send_break(tty, HZ/4);
1839 return 0;
1840 case TCSBRKP:
1841 return send_break(tty, arg ? arg*(HZ/10) : HZ/4);
1842 }
1843 if (tty->driver.ioctl) {
1844 int retval = (tty->driver.ioctl)(tty, file, cmd, arg);
1845 if (retval != -ENOIOCTLCMD)
1846 return retval;
1847 }
1848 if (tty->ldisc.ioctl) {
1849 int retval = (tty->ldisc.ioctl)(tty, file, cmd, arg);
1850 if (retval != -ENOIOCTLCMD)
1851 return retval;
1852 }
1853 return -EINVAL;
1854}
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876static void __do_SAK(void *arg)
1877{
1878#ifdef TTY_SOFT_SAK
1879 tty_hangup(tty);
1880#else
1881 struct tty_struct *tty = arg;
1882 struct task_struct *p;
1883 int session;
1884 int i;
1885 struct file *filp;
1886
1887 if (!tty)
1888 return;
1889 session = tty->session;
1890 if (tty->ldisc.flush_buffer)
1891 tty->ldisc.flush_buffer(tty);
1892 if (tty->driver.flush_buffer)
1893 tty->driver.flush_buffer(tty);
1894 read_lock(&tasklist_lock);
1895 for_each_task(p) {
1896 if ((p->tty == tty) ||
1897 ((session > 0) && (p->session == session))) {
1898 send_sig(SIGKILL, p, 1);
1899 continue;
1900 }
1901 task_lock(p);
1902 if (p->files) {
1903 read_lock(&p->files->file_lock);
1904 for (i=0; i < p->files->max_fds; i++) {
1905 filp = fcheck_files(p->files, i);
1906 if (filp && (filp->f_op == &tty_fops) &&
1907 (filp->private_data == tty)) {
1908 send_sig(SIGKILL, p, 1);
1909 break;
1910 }
1911 }
1912 read_unlock(&p->files->file_lock);
1913 }
1914 task_unlock(p);
1915 }
1916 read_unlock(&tasklist_lock);
1917#endif
1918}
1919
1920
1921
1922
1923
1924
1925
1926
1927void do_SAK(struct tty_struct *tty)
1928{
1929 if (!tty)
1930 return;
1931 PREPARE_TQUEUE(&tty->SAK_tq, __do_SAK, tty);
1932 schedule_task(&tty->SAK_tq);
1933}
1934
1935
1936
1937
1938
1939static void flush_to_ldisc(void *private_)
1940{
1941 struct tty_struct *tty = (struct tty_struct *) private_;
1942 unsigned char *cp;
1943 char *fp;
1944 int count;
1945 unsigned long flags;
1946
1947 if (test_bit(TTY_DONT_FLIP, &tty->flags)) {
1948 queue_task(&tty->flip.tqueue, &tq_timer);
1949 return;
1950 }
1951 if (tty->flip.buf_num) {
1952 cp = tty->flip.char_buf + TTY_FLIPBUF_SIZE;
1953 fp = tty->flip.flag_buf + TTY_FLIPBUF_SIZE;
1954 tty->flip.buf_num = 0;
1955
1956 save_flags(flags); cli();
1957 tty->flip.char_buf_ptr = tty->flip.char_buf;
1958 tty->flip.flag_buf_ptr = tty->flip.flag_buf;
1959 } else {
1960 cp = tty->flip.char_buf;
1961 fp = tty->flip.flag_buf;
1962 tty->flip.buf_num = 1;
1963
1964 save_flags(flags); cli();
1965 tty->flip.char_buf_ptr = tty->flip.char_buf + TTY_FLIPBUF_SIZE;
1966 tty->flip.flag_buf_ptr = tty->flip.flag_buf + TTY_FLIPBUF_SIZE;
1967 }
1968 count = tty->flip.count;
1969 tty->flip.count = 0;
1970 restore_flags(flags);
1971
1972 tty->ldisc.receive_buf(tty, cp, fp, count);
1973}
1974
1975
1976
1977
1978
1979
1980
1981static int baud_table[] = {
1982 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
1983 9600, 19200, 38400, 57600, 115200, 230400, 460800,
1984#ifdef __sparc__
1985 76800, 153600, 307200, 614400, 921600
1986#else
1987 500000, 576000, 921600, 1000000, 1152000, 1500000, 2000000,
1988 2500000, 3000000, 3500000, 4000000
1989#endif
1990};
1991
1992static int n_baud_table = sizeof(baud_table)/sizeof(int);
1993
1994int tty_get_baud_rate(struct tty_struct *tty)
1995{
1996 unsigned int cflag, i;
1997
1998 cflag = tty->termios->c_cflag;
1999
2000 i = cflag & CBAUD;
2001 if (i & CBAUDEX) {
2002 i &= ~CBAUDEX;
2003 if (i < 1 || i+15 >= n_baud_table)
2004 tty->termios->c_cflag &= ~CBAUDEX;
2005 else
2006 i += 15;
2007 }
2008 if (i==15 && tty->alt_speed) {
2009 if (!tty->warned) {
2010 printk(KERN_WARNING "Use of setserial/setrocket to "
2011 "set SPD_* flags is deprecated\n");
2012 tty->warned = 1;
2013 }
2014 return(tty->alt_speed);
2015 }
2016
2017 return baud_table[i];
2018}
2019
2020void tty_flip_buffer_push(struct tty_struct *tty)
2021{
2022 if (tty->low_latency)
2023 flush_to_ldisc((void *) tty);
2024 else
2025 queue_task(&tty->flip.tqueue, &tq_timer);
2026}
2027
2028
2029
2030
2031static void initialize_tty_struct(struct tty_struct *tty)
2032{
2033 memset(tty, 0, sizeof(struct tty_struct));
2034 tty->magic = TTY_MAGIC;
2035 tty->ldisc = ldiscs[N_TTY];
2036 tty->pgrp = -1;
2037 tty->flip.char_buf_ptr = tty->flip.char_buf;
2038 tty->flip.flag_buf_ptr = tty->flip.flag_buf;
2039 tty->flip.tqueue.routine = flush_to_ldisc;
2040 tty->flip.tqueue.data = tty;
2041 init_MUTEX(&tty->flip.pty_sem);
2042 init_waitqueue_head(&tty->write_wait);
2043 init_waitqueue_head(&tty->read_wait);
2044 tty->tq_hangup.routine = do_tty_hangup;
2045 tty->tq_hangup.data = tty;
2046 sema_init(&tty->atomic_read, 1);
2047 sema_init(&tty->atomic_write, 1);
2048 spin_lock_init(&tty->read_lock);
2049 INIT_LIST_HEAD(&tty->tty_files);
2050 INIT_TQUEUE(&tty->SAK_tq, 0, 0);
2051}
2052
2053
2054
2055
2056void tty_default_put_char(struct tty_struct *tty, unsigned char ch)
2057{
2058 tty->driver.write(tty, 0, &ch, 1);
2059}
2060
2061
2062
2063
2064void tty_register_devfs (struct tty_driver *driver, unsigned int flags, unsigned minor)
2065{
2066#ifdef CONFIG_DEVFS_FS
2067 umode_t mode = S_IFCHR | S_IRUSR | S_IWUSR;
2068 kdev_t device = MKDEV (driver->major, minor);
2069 int idx = minor - driver->minor_start;
2070 char buf[32];
2071
2072 switch (device) {
2073 case TTY_DEV:
2074 case PTMX_DEV:
2075 mode |= S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
2076 break;
2077 default:
2078 if (driver->major == PTY_MASTER_MAJOR)
2079 mode |= S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
2080 break;
2081 }
2082 if ( (minor < driver->minor_start) ||
2083 (minor >= driver->minor_start + driver->num) ) {
2084 printk(KERN_ERR "Attempt to register invalid minor number "
2085 "with devfs (%d:%d).\n", (int)driver->major,(int)minor);
2086 return;
2087 }
2088# ifdef CONFIG_UNIX98_PTYS
2089 if ( (driver->major >= UNIX98_PTY_SLAVE_MAJOR) &&
2090 (driver->major < UNIX98_PTY_SLAVE_MAJOR + UNIX98_NR_MAJORS) )
2091 flags |= DEVFS_FL_CURRENT_OWNER;
2092# endif
2093 sprintf(buf, driver->name, idx + driver->name_base);
2094 devfs_register (NULL, buf, flags | DEVFS_FL_DEFAULT,
2095 driver->major, minor, mode, &tty_fops, NULL);
2096#endif
2097}
2098
2099void tty_unregister_devfs (struct tty_driver *driver, unsigned minor)
2100{
2101#ifdef CONFIG_DEVFS_FS
2102 void * handle;
2103 int idx = minor - driver->minor_start;
2104 char buf[32];
2105
2106 sprintf(buf, driver->name, idx + driver->name_base);
2107 handle = devfs_find_handle (NULL, buf, driver->major, minor,
2108 DEVFS_SPECIAL_CHR, 0);
2109 devfs_unregister (handle);
2110#endif
2111}
2112
2113EXPORT_SYMBOL(tty_register_devfs);
2114EXPORT_SYMBOL(tty_unregister_devfs);
2115
2116
2117
2118
2119int tty_register_driver(struct tty_driver *driver)
2120{
2121 int error;
2122 int i;
2123
2124 if (driver->flags & TTY_DRIVER_INSTALLED)
2125 return 0;
2126
2127 error = devfs_register_chrdev(driver->major, driver->name, &tty_fops);
2128 if (error < 0)
2129 return error;
2130 else if(driver->major == 0)
2131 driver->major = error;
2132
2133 if (!driver->put_char)
2134 driver->put_char = tty_default_put_char;
2135
2136 driver->prev = 0;
2137 driver->next = tty_drivers;
2138 if (tty_drivers) tty_drivers->prev = driver;
2139 tty_drivers = driver;
2140
2141 if ( !(driver->flags & TTY_DRIVER_NO_DEVFS) ) {
2142 for(i = 0; i < driver->num; i++)
2143 tty_register_devfs(driver, 0, driver->minor_start + i);
2144 }
2145 proc_tty_register_driver(driver);
2146 return error;
2147}
2148
2149
2150
2151
2152int tty_unregister_driver(struct tty_driver *driver)
2153{
2154 int retval;
2155 struct tty_driver *p;
2156 int i, found = 0;
2157 struct termios *tp;
2158 const char *othername = NULL;
2159
2160 if (*driver->refcount)
2161 return -EBUSY;
2162
2163 for (p = tty_drivers; p; p = p->next) {
2164 if (p == driver)
2165 found++;
2166 else if (p->major == driver->major)
2167 othername = p->name;
2168 }
2169
2170 if (!found)
2171 return -ENOENT;
2172
2173 if (othername == NULL) {
2174 retval = devfs_unregister_chrdev(driver->major, driver->name);
2175 if (retval)
2176 return retval;
2177 } else
2178 devfs_register_chrdev(driver->major, othername, &tty_fops);
2179
2180 if (driver->prev)
2181 driver->prev->next = driver->next;
2182 else
2183 tty_drivers = driver->next;
2184
2185 if (driver->next)
2186 driver->next->prev = driver->prev;
2187
2188
2189
2190
2191
2192
2193 for (i = 0; i < driver->num; i++) {
2194 tp = driver->termios[i];
2195 if (tp) {
2196 driver->termios[i] = NULL;
2197 kfree(tp);
2198 }
2199 tp = driver->termios_locked[i];
2200 if (tp) {
2201 driver->termios_locked[i] = NULL;
2202 kfree(tp);
2203 }
2204 tty_unregister_devfs(driver, driver->minor_start + i);
2205 }
2206 proc_tty_unregister_driver(driver);
2207 return 0;
2208}
2209
2210
2211
2212
2213
2214
2215
2216
2217void __init console_init(void)
2218{
2219
2220 memset(ldiscs, 0, sizeof(ldiscs));
2221 (void) tty_register_ldisc(N_TTY, &tty_ldisc_N_TTY);
2222
2223
2224
2225
2226
2227 memset(&tty_std_termios, 0, sizeof(struct termios));
2228 memcpy(tty_std_termios.c_cc, INIT_C_CC, NCCS);
2229 tty_std_termios.c_iflag = ICRNL | IXON;
2230 tty_std_termios.c_oflag = OPOST | ONLCR;
2231 tty_std_termios.c_cflag = B38400 | CS8 | CREAD | HUPCL;
2232 tty_std_termios.c_lflag = ISIG | ICANON | ECHO | ECHOE | ECHOK |
2233 ECHOCTL | ECHOKE | IEXTEN;
2234
2235
2236
2237
2238
2239#ifdef CONFIG_EARLY_PRINTK
2240 disable_early_printk();
2241#endif
2242#ifdef CONFIG_HVC_CONSOLE
2243 hvc_console_init();
2244#endif
2245#ifdef CONFIG_VT
2246 con_init();
2247#endif
2248#ifdef CONFIG_AU1X00_SERIAL_CONSOLE
2249 au1x00_serial_console_init();
2250#endif
2251#ifdef CONFIG_SERIAL_CONSOLE
2252#if (defined(CONFIG_8xx) || defined(CONFIG_CPM2))
2253 console_8xx_init();
2254#elif defined(CONFIG_MAC_SERIAL) && defined(CONFIG_SERIAL)
2255 if (_machine == _MACH_Pmac)
2256 mac_scc_console_init();
2257 else
2258 serial_console_init();
2259#elif defined(CONFIG_MAC_SERIAL)
2260 mac_scc_console_init();
2261#elif defined(CONFIG_PARISC)
2262 pdc_console_init();
2263#elif defined(CONFIG_SERIAL)
2264 serial_console_init();
2265#endif
2266#if defined(CONFIG_MVME162_SCC) || defined(CONFIG_BVME6000_SCC) || defined(CONFIG_MVME147_SCC)
2267 vme_scc_console_init();
2268#endif
2269#if defined(CONFIG_SERIAL167)
2270 serial167_console_init();
2271#endif
2272#if defined(CONFIG_SH_SCI)
2273 sci_console_init();
2274#endif
2275#endif
2276#ifdef CONFIG_SERIAL_DEC_CONSOLE
2277 dec_serial_console_init();
2278#endif
2279#ifdef CONFIG_TN3270_CONSOLE
2280 tub3270_con_init();
2281#endif
2282#ifdef CONFIG_TN3215
2283 con3215_init();
2284#endif
2285#ifdef CONFIG_HWC
2286 hwc_console_init();
2287#endif
2288#ifdef CONFIG_STDIO_CONSOLE
2289 stdio_console_init();
2290#endif
2291#ifdef CONFIG_SERIAL_21285_CONSOLE
2292 rs285_console_init();
2293#endif
2294#ifdef CONFIG_SERIAL_SA1100_CONSOLE
2295 sa1100_rs_console_init();
2296#endif
2297#ifdef CONFIG_ARC_CONSOLE
2298 arc_console_init();
2299#endif
2300#ifdef CONFIG_SERIAL_AMBA_CONSOLE
2301 ambauart_console_init();
2302#endif
2303#ifdef CONFIG_SERIAL_TX3912_CONSOLE
2304 tx3912_console_init();
2305#endif
2306#ifdef CONFIG_TXX927_SERIAL_CONSOLE
2307 txx927_console_init();
2308#endif
2309#ifdef CONFIG_SERIAL_TXX9_CONSOLE
2310 txx9_serial_console_init();
2311#endif
2312#ifdef CONFIG_SIBYTE_SB1250_DUART_CONSOLE
2313 sb1250_serial_console_init();
2314#endif
2315#ifdef CONFIG_IP22_SERIAL
2316 sgi_serial_console_init();
2317#endif
2318}
2319
2320static struct tty_driver dev_tty_driver, dev_syscons_driver;
2321#ifdef CONFIG_UNIX98_PTYS
2322static struct tty_driver dev_ptmx_driver;
2323#endif
2324#ifdef CONFIG_VT
2325static struct tty_driver dev_console_driver;
2326#endif
2327
2328
2329
2330
2331
2332void __init tty_init(void)
2333{
2334
2335
2336
2337
2338
2339
2340 memset(&dev_tty_driver, 0, sizeof(struct tty_driver));
2341 dev_tty_driver.magic = TTY_DRIVER_MAGIC;
2342 dev_tty_driver.driver_name = "/dev/tty";
2343 dev_tty_driver.name = dev_tty_driver.driver_name + 5;
2344 dev_tty_driver.name_base = 0;
2345 dev_tty_driver.major = TTYAUX_MAJOR;
2346 dev_tty_driver.minor_start = 0;
2347 dev_tty_driver.num = 1;
2348 dev_tty_driver.type = TTY_DRIVER_TYPE_SYSTEM;
2349 dev_tty_driver.subtype = SYSTEM_TYPE_TTY;
2350
2351 if (tty_register_driver(&dev_tty_driver))
2352 panic("Couldn't register /dev/tty driver\n");
2353
2354 dev_syscons_driver = dev_tty_driver;
2355 dev_syscons_driver.driver_name = "/dev/console";
2356 dev_syscons_driver.name = dev_syscons_driver.driver_name + 5;
2357 dev_syscons_driver.major = TTYAUX_MAJOR;
2358 dev_syscons_driver.minor_start = 1;
2359 dev_syscons_driver.type = TTY_DRIVER_TYPE_SYSTEM;
2360 dev_syscons_driver.subtype = SYSTEM_TYPE_SYSCONS;
2361
2362 if (tty_register_driver(&dev_syscons_driver))
2363 panic("Couldn't register /dev/console driver\n");
2364
2365
2366
2367
2368#ifdef CONFIG_VT
2369 con_init_devfs();
2370#endif
2371
2372#ifdef CONFIG_UNIX98_PTYS
2373 dev_ptmx_driver = dev_tty_driver;
2374 dev_ptmx_driver.driver_name = "/dev/ptmx";
2375 dev_ptmx_driver.name = dev_ptmx_driver.driver_name + 5;
2376 dev_ptmx_driver.major= MAJOR(PTMX_DEV);
2377 dev_ptmx_driver.minor_start = MINOR(PTMX_DEV);
2378 dev_ptmx_driver.type = TTY_DRIVER_TYPE_SYSTEM;
2379 dev_ptmx_driver.subtype = SYSTEM_TYPE_SYSPTMX;
2380
2381 if (tty_register_driver(&dev_ptmx_driver))
2382 panic("Couldn't register /dev/ptmx driver\n");
2383#endif
2384
2385#ifdef CONFIG_VT
2386 dev_console_driver = dev_tty_driver;
2387 dev_console_driver.driver_name = "/dev/vc/0";
2388 dev_console_driver.name = dev_console_driver.driver_name + 5;
2389 dev_console_driver.major = TTY_MAJOR;
2390 dev_console_driver.type = TTY_DRIVER_TYPE_SYSTEM;
2391 dev_console_driver.subtype = SYSTEM_TYPE_CONSOLE;
2392
2393 if (tty_register_driver(&dev_console_driver))
2394 panic("Couldn't register /dev/tty0 driver\n");
2395
2396 kbd_init();
2397#endif
2398
2399#ifdef CONFIG_SGI_L1_SERIAL_CONSOLE
2400 if (ia64_platform_is("sn2")) {
2401 sn_sal_serial_console_init();
2402 return;
2403 }
2404#endif
2405#ifdef CONFIG_ESPSERIAL
2406 espserial_init();
2407#endif
2408#if defined(CONFIG_MVME162_SCC) || defined(CONFIG_BVME6000_SCC) || defined(CONFIG_MVME147_SCC)
2409 vme_scc_init();
2410#endif
2411#ifdef CONFIG_SERIAL_TX3912
2412 tx3912_rs_init();
2413#endif
2414#ifdef CONFIG_ROCKETPORT
2415 rp_init();
2416#endif
2417#ifdef CONFIG_SERIAL167
2418 serial167_init();
2419#endif
2420#ifdef CONFIG_CYCLADES
2421 cy_init();
2422#endif
2423#ifdef CONFIG_STALLION
2424 stl_init();
2425#endif
2426#ifdef CONFIG_ISTALLION
2427 stli_init();
2428#endif
2429#ifdef CONFIG_DIGI
2430 pcxe_init();
2431#endif
2432#ifdef CONFIG_DIGIEPCA
2433 pc_init();
2434#endif
2435#ifdef CONFIG_SPECIALIX
2436 specialix_init();
2437#endif
2438#if (defined(CONFIG_8xx) || defined(CONFIG_CPM2))
2439 rs_8xx_init();
2440#endif
2441 pty_init();
2442#ifdef CONFIG_MOXA_SMARTIO
2443 mxser_init();
2444#endif
2445#ifdef CONFIG_MOXA_INTELLIO
2446 moxa_init();
2447#endif
2448#ifdef CONFIG_VT
2449 vcs_init();
2450#endif
2451#ifdef CONFIG_TN3270
2452 tub3270_init();
2453#endif
2454#ifdef CONFIG_TN3215
2455 tty3215_init();
2456#endif
2457#ifdef CONFIG_HWC
2458 hwc_tty_init();
2459#endif
2460#ifdef CONFIG_A2232
2461 a2232board_init();
2462#endif
2463}
2464