2 * linux/drivers/char/tty_io.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
8 * 'tty_io.c' gives an orthogonal feeling to tty's, be they consoles
9 * or rs-channels. It also implements echoing, cooked mode etc.
11 * Kill-line thanks to John T Kohl, who also corrected VMIN = VTIME = 0.
13 * Modified by Theodore Ts'o, 9/14/92, to dynamically allocate the
14 * tty_struct and tty_queue structures. Previously there was an array
15 * of 256 tty_struct's which was statically allocated, and the
16 * tty_queue structures were allocated at boot time. Both are now
17 * dynamically allocated only when the tty is open.
19 * Also restructured routines so that there is more of a separation
20 * between the high-level tty routines (tty_io.c and tty_ioctl.c) and
21 * the low-level tty routines (serial.c, pty.c, console.c). This
22 * makes for cleaner and more compact code. -TYT, 9/17/92
24 * Modified by Fred N. van Kempen, 01/29/93, to add line disciplines
25 * which can be dynamically activated and de-activated by the line
26 * discipline handling modules (like SLIP).
28 * NOTE: pay no attention to the line discipline code (yet); its
29 * interface is still subject to change in this version...
32 * Added functionality to the OPOST tty handling. No delays, but all
33 * other bits should be there.
34 * -- Nick Holloway <alfie@dcs.warwick.ac.uk>, 27th May 1993.
36 * Rewrote canonical mode and added more termios flags.
37 * -- julian@uhunix.uhcc.hawaii.edu (J. Cowley), 13Jan94
39 * Reorganized FASYNC support so mouse code can share it.
40 * -- ctm@ardi.com, 9Sep95
42 * New TIOCLINUX variants added.
43 * -- mj@k332.feld.cvut.cz, 19-Nov-95
45 * Restrict vt switching via ioctl()
46 * -- grif@cs.ucr.edu, 5-Dec-95
48 * Move console and virtual terminal code to more apropriate files,
49 * implement CONFIG_VT and generalize console device interface.
50 * -- Marko Kohtala <Marko.Kohtala@hut.fi>, March 97
53 #include <linux/config.h>
54 #include <linux/types.h>
55 #include <linux/major.h>
56 #include <linux/errno.h>
57 #include <linux/signal.h>
58 #include <linux/fcntl.h>
59 #include <linux/sched.h>
60 #include <linux/interrupt.h>
61 #include <linux/tty.h>
62 #include <linux/tty_flip.h>
63 #include <linux/console.h>
64 #include <linux/timer.h>
65 #include <linux/ctype.h>
68 #include <linux/string.h>
69 #include <linux/malloc.h>
70 #include <linux/poll.h>
72 #include <linux/proc_fs.h>
75 #include <asm/uaccess.h>
76 #include <asm/system.h>
77 #include <asm/bitops.h>
81 #include "selection.h"
84 #include <linux/kerneld.h>
87 #define CONSOLE_DEV MKDEV(TTY_MAJOR,0)
88 #define TTY_DEV MKDEV(TTYAUX_MAJOR,0)
90 #undef TTY_DEBUG_HANGUP
92 #define TTY_PARANOIA_CHECK
93 #define CHECK_TTY_COUNT
95 struct termios tty_std_termios
; /* for the benefit of tty drivers */
96 struct tty_driver
*tty_drivers
= NULL
; /* linked list of tty drivers */
97 struct tty_ldisc ldiscs
[NR_LDISCS
]; /* line disc dispatch table */
100 * redirect is the pseudo-tty that console output
101 * is redirected to if asked by TIOCCONS.
103 struct tty_struct
* redirect
= NULL
;
105 static void initialize_tty_struct(struct tty_struct
*tty
);
107 static long tty_read(struct inode
*, struct file
*, char *, unsigned long);
108 static long tty_write(struct inode
*, struct file
*, const char *, unsigned long);
109 static unsigned int tty_poll(struct file
*, poll_table
*);
110 static int tty_open(struct inode
*, struct file
*);
111 static int tty_release(struct inode
*, struct file
*);
112 static int tty_ioctl(struct inode
* inode
, struct file
* file
,
113 unsigned int cmd
, unsigned long arg
);
114 static int tty_fasync(struct inode
* inode
, struct file
* filp
, int on
);
117 #define MIN(a,b) ((a) < (b) ? (a) : (b))
121 * These two routines return the name of tty. tty_name() should NOT
122 * be used in interrupt drivers, since it's not re-entrant. Use
123 * _tty_name() instead.
125 char *_tty_name(struct tty_struct
*tty
, char *buf
)
128 sprintf(buf
, "%s%d", tty
->driver
.name
,
129 MINOR(tty
->device
) - tty
->driver
.minor_start
+
130 tty
->driver
.name_base
);
132 strcpy(buf
, "NULL tty");
136 char *tty_name(struct tty_struct
*tty
)
140 return(_tty_name(tty
, buf
));
143 inline int tty_paranoia_check(struct tty_struct
*tty
, kdev_t device
,
146 #ifdef TTY_PARANOIA_CHECK
147 static const char *badmagic
=
148 "Warning: bad magic number for tty struct (%s) in %s\n";
149 static const char *badtty
=
150 "Warning: null TTY for (%s) in %s\n";
153 printk(badtty
, kdevname(device
), routine
);
156 if (tty
->magic
!= TTY_MAGIC
) {
157 printk(badmagic
, kdevname(device
), routine
);
164 static int check_tty_count(struct tty_struct
*tty
, const char *routine
)
166 #ifdef CHECK_TTY_COUNT
170 for (f
= first_file
, i
=0; i
<nr_files
; i
++, f
= f
->f_next
) {
173 if (f
->private_data
== tty
) {
177 if (tty
->driver
.type
== TTY_DRIVER_TYPE_PTY
&&
178 tty
->driver
.subtype
== PTY_TYPE_SLAVE
&&
179 tty
->link
&& tty
->link
->count
)
181 if (tty
->count
!= count
) {
182 printk("Warning: dev (%s) tty->count(%d) != #fd's(%d) in %s\n",
183 kdevname(tty
->device
), tty
->count
, count
, routine
);
190 int tty_register_ldisc(int disc
, struct tty_ldisc
*new_ldisc
)
192 if (disc
< N_TTY
|| disc
>= NR_LDISCS
)
196 ldiscs
[disc
] = *new_ldisc
;
197 ldiscs
[disc
].flags
|= LDISC_FLAG_DEFINED
;
198 ldiscs
[disc
].num
= disc
;
200 memset(&ldiscs
[disc
], 0, sizeof(struct tty_ldisc
));
205 /* Set the discipline of a tty line. */
206 static int tty_set_ldisc(struct tty_struct
*tty
, int ldisc
)
209 struct tty_ldisc o_ldisc
;
211 if ((ldisc
< N_TTY
) || (ldisc
>= NR_LDISCS
))
213 #ifdef CONFIG_KERNELD
214 /* Eduardo Blanco <ejbs@cs.cs.com.uy> */
215 if (!(ldiscs
[ldisc
].flags
& LDISC_FLAG_DEFINED
)) {
217 sprintf(modname
, "tty-ldisc-%d", ldisc
);
218 request_module (modname
);
221 if (!(ldiscs
[ldisc
].flags
& LDISC_FLAG_DEFINED
))
224 if (tty
->ldisc
.num
== ldisc
)
225 return 0; /* We are already in the desired discipline */
226 o_ldisc
= tty
->ldisc
;
228 tty_wait_until_sent(tty
, 0);
230 /* Shutdown the current discipline. */
231 if (tty
->ldisc
.close
)
232 (tty
->ldisc
.close
)(tty
);
234 /* Now set up the new line discipline. */
235 tty
->ldisc
= ldiscs
[ldisc
];
236 tty
->termios
->c_line
= ldisc
;
238 retval
= (tty
->ldisc
.open
)(tty
);
240 tty
->ldisc
= o_ldisc
;
241 tty
->termios
->c_line
= tty
->ldisc
.num
;
242 if (tty
->ldisc
.open
&& (tty
->ldisc
.open(tty
) < 0)) {
243 tty
->ldisc
= ldiscs
[N_TTY
];
244 tty
->termios
->c_line
= N_TTY
;
245 if (tty
->ldisc
.open
) {
246 int r
= tty
->ldisc
.open(tty
);
249 panic("Couldn't open N_TTY ldisc for "
255 if (tty
->ldisc
.num
!= o_ldisc
.num
&& tty
->driver
.set_ldisc
)
256 tty
->driver
.set_ldisc(tty
);
261 * This routine returns a tty driver structure, given a device number
263 struct tty_driver
*get_tty_driver(kdev_t device
)
266 struct tty_driver
*p
;
268 minor
= MINOR(device
);
269 major
= MAJOR(device
);
271 for (p
= tty_drivers
; p
; p
= p
->next
) {
272 if (p
->major
!= major
)
274 if (minor
< p
->minor_start
)
276 if (minor
>= p
->minor_start
+ p
->num
)
284 * If we try to write to, or set the state of, a terminal and we're
285 * not in the foreground, send a SIGTTOU. If the signal is blocked or
286 * ignored, go ahead and perform the operation. (POSIX 7.2)
288 int tty_check_change(struct tty_struct
* tty
)
290 if (current
->tty
!= tty
)
292 if (tty
->pgrp
<= 0) {
293 printk("tty_check_change: tty->pgrp <= 0!\n");
296 if (current
->pgrp
== tty
->pgrp
)
298 if (is_ignored(SIGTTOU
))
300 if (is_orphaned_pgrp(current
->pgrp
))
302 (void) kill_pg(current
->pgrp
,SIGTTOU
,1);
306 static long hung_up_tty_read(struct inode
* inode
, struct file
* file
,
307 char * buf
, unsigned long count
)
312 static long hung_up_tty_write(struct inode
* inode
,
313 struct file
* file
, const char * buf
, unsigned long count
)
318 static unsigned int hung_up_tty_poll(struct file
* filp
, poll_table
* wait
)
320 return POLLIN
| POLLOUT
| POLLERR
| POLLHUP
| POLLRDNORM
| POLLWRNORM
;
323 static int hung_up_tty_ioctl(struct inode
* inode
, struct file
* file
,
324 unsigned int cmd
, unsigned long arg
)
326 return cmd
== TIOCSPGRP
? -ENOTTY
: -EIO
;
329 static long long tty_lseek(struct inode
* inode
, struct file
* file
,
330 long long offset
, int orig
)
335 static struct file_operations tty_fops
= {
339 NULL
, /* tty_readdir */
345 NULL
, /* tty_fsync */
349 static struct file_operations hung_up_tty_fops
= {
353 NULL
, /* hung_up_tty_readdir */
356 NULL
, /* hung_up_tty_mmap */
357 NULL
, /* hung_up_tty_open */
358 tty_release
, /* hung_up_tty_release */
359 NULL
, /* hung_up_tty_fsync */
360 NULL
/* hung_up_tty_fasync */
363 void do_tty_hangup(struct tty_struct
* tty
, struct file_operations
*fops
)
367 struct task_struct
*p
;
371 check_tty_count(tty
, "do_tty_hangup");
372 for (filp
= first_file
, i
=0; i
<nr_files
; i
++, filp
= filp
->f_next
) {
375 if (filp
->private_data
!= tty
)
379 if (filp
->f_inode
->i_rdev
== CONSOLE_DEV
)
381 if (filp
->f_op
!= &tty_fops
)
383 tty_fasync(filp
->f_inode
, filp
, 0);
387 if (tty
->ldisc
.flush_buffer
)
388 tty
->ldisc
.flush_buffer(tty
);
389 if (tty
->driver
.flush_buffer
)
390 tty
->driver
.flush_buffer(tty
);
391 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
392 tty
->ldisc
.write_wakeup
)
393 (tty
->ldisc
.write_wakeup
)(tty
);
394 wake_up_interruptible(&tty
->write_wait
);
395 wake_up_interruptible(&tty
->read_wait
);
398 * Shutdown the current line discipline, and reset it to
401 if (tty
->ldisc
.num
!= ldiscs
[N_TTY
].num
) {
402 if (tty
->ldisc
.close
)
403 (tty
->ldisc
.close
)(tty
);
404 tty
->ldisc
= ldiscs
[N_TTY
];
405 tty
->termios
->c_line
= N_TTY
;
406 if (tty
->ldisc
.open
) {
407 i
= (tty
->ldisc
.open
)(tty
);
409 printk("do_tty_hangup: N_TTY open: error %d\n",
415 if ((tty
->session
> 0) && (p
->session
== tty
->session
) &&
417 send_sig(SIGHUP
,p
,1);
418 send_sig(SIGCONT
,p
,1);
420 p
->tty_old_pgrp
= tty
->pgrp
;
428 tty
->ctrl_status
= 0;
429 if (tty
->driver
.flags
& TTY_DRIVER_RESET_TERMIOS
)
430 *tty
->termios
= tty
->driver
.init_termios
;
431 if (tty
->driver
.hangup
)
432 (tty
->driver
.hangup
)(tty
);
435 void tty_hangup(struct tty_struct
* tty
)
437 #ifdef TTY_DEBUG_HANGUP
438 printk("%s hangup...\n", tty_name(tty
));
440 do_tty_hangup(tty
, &hung_up_tty_fops
);
443 void tty_vhangup(struct tty_struct
* tty
)
445 #ifdef TTY_DEBUG_HANGUP
446 printk("%s vhangup...\n", tty_name(tty
));
448 do_tty_hangup(tty
, &hung_up_tty_fops
);
451 int tty_hung_up_p(struct file
* filp
)
453 return (filp
->f_op
== &hung_up_tty_fops
);
457 * This function is typically called only by the session leader, when
458 * it wants to disassociate itself from its controlling tty.
460 * It performs the following functions:
461 * (1) Sends a SIGHUP and SIGCONT to the foreground process group
462 * (2) Clears the tty from being controlling the session
463 * (3) Clears the controlling tty for all processes in the
466 * The argument on_exit is set to 1 if called when a process is
467 * exiting; it is 0 if called by the ioctl TIOCNOTTY.
469 void disassociate_ctty(int on_exit
)
471 struct tty_struct
*tty
= current
->tty
;
472 struct task_struct
*p
;
476 tty_pgrp
= tty
->pgrp
;
477 if (on_exit
&& tty
->driver
.type
!= TTY_DRIVER_TYPE_PTY
)
480 if (current
->tty_old_pgrp
) {
481 kill_pg(current
->tty_old_pgrp
, SIGHUP
, on_exit
);
482 kill_pg(current
->tty_old_pgrp
, SIGCONT
, on_exit
);
487 kill_pg(tty_pgrp
, SIGHUP
, on_exit
);
489 kill_pg(tty_pgrp
, SIGCONT
, on_exit
);
492 current
->tty_old_pgrp
= 0;
497 if (p
->session
== current
->session
)
501 void wait_for_keypress(void)
503 struct console
*c
= console_drivers
;
504 while(c
&& !c
->wait_key
)
506 if (c
) c
->wait_key();
509 void stop_tty(struct tty_struct
*tty
)
514 if (tty
->link
&& tty
->link
->packet
) {
515 tty
->ctrl_status
&= ~TIOCPKT_START
;
516 tty
->ctrl_status
|= TIOCPKT_STOP
;
517 wake_up_interruptible(&tty
->link
->read_wait
);
519 if (tty
->driver
.stop
)
520 (tty
->driver
.stop
)(tty
);
523 void start_tty(struct tty_struct
*tty
)
525 if (!tty
->stopped
|| tty
->flow_stopped
)
528 if (tty
->link
&& tty
->link
->packet
) {
529 tty
->ctrl_status
&= ~TIOCPKT_STOP
;
530 tty
->ctrl_status
|= TIOCPKT_START
;
531 wake_up_interruptible(&tty
->link
->read_wait
);
533 if (tty
->driver
.start
)
534 (tty
->driver
.start
)(tty
);
535 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
536 tty
->ldisc
.write_wakeup
)
537 (tty
->ldisc
.write_wakeup
)(tty
);
538 wake_up_interruptible(&tty
->write_wait
);
541 static long tty_read(struct inode
* inode
, struct file
* file
,
542 char * buf
, unsigned long count
)
545 struct tty_struct
* tty
;
547 tty
= (struct tty_struct
*)file
->private_data
;
548 if (tty_paranoia_check(tty
, inode
->i_rdev
, "tty_read"))
550 if (!tty
|| (tty
->flags
& (1 << TTY_IO_ERROR
)))
553 /* This check not only needs to be done before reading, but also
554 whenever read_chan() gets woken up after sleeping, so I've
555 moved it to there. This should only be done for the N_TTY
556 line discipline, anyway. Same goes for write_chan(). -- jlc. */
558 if ((inode
->i_rdev
!= CONSOLE_DEV
) && /* don't stop on /dev/console */
560 (current
->tty
== tty
) &&
561 (tty
->pgrp
!= current
->pgrp
))
562 if (is_ignored(SIGTTIN
) || is_orphaned_pgrp(current
->pgrp
))
565 (void) kill_pg(current
->pgrp
, SIGTTIN
, 1);
570 i
= (tty
->ldisc
.read
)(tty
,file
,buf
,count
);
574 inode
->i_atime
= CURRENT_TIME
;
579 * Split writes up in sane blocksizes to avoid
580 * denial-of-service type attacks
582 static inline int do_tty_write(
583 int (*write
)(struct tty_struct
*, struct file
*, const unsigned char *, unsigned int),
585 struct tty_struct
*tty
,
587 const unsigned char *buf
,
590 int ret
= 0, written
= 0;
593 unsigned long size
= PAGE_SIZE
*2;
596 ret
= write(tty
, file
, buf
, size
);
605 if (current
->signal
& ~current
->blocked
)
611 inode
->i_mtime
= CURRENT_TIME
;
618 static long tty_write(struct inode
* inode
, struct file
* file
,
619 const char * buf
, unsigned long count
)
622 struct tty_struct
* tty
;
624 is_console
= (inode
->i_rdev
== CONSOLE_DEV
);
626 if (is_console
&& redirect
)
629 tty
= (struct tty_struct
*)file
->private_data
;
630 if (tty_paranoia_check(tty
, inode
->i_rdev
, "tty_write"))
632 if (!tty
|| !tty
->driver
.write
|| (tty
->flags
& (1 << TTY_IO_ERROR
)))
635 if (!is_console
&& L_TOSTOP(tty
) && (tty
->pgrp
> 0) &&
636 (current
->tty
== tty
) && (tty
->pgrp
!= current
->pgrp
)) {
637 if (is_orphaned_pgrp(current
->pgrp
))
639 if (!is_ignored(SIGTTOU
)) {
640 (void) kill_pg(current
->pgrp
, SIGTTOU
, 1);
645 if (!tty
->ldisc
.write
)
647 return do_tty_write(tty
->ldisc
.write
,
649 (const unsigned char *)buf
,
650 (unsigned int)count
);
654 * This is so ripe with races that you should *really* not touch this
655 * unless you know exactly what you are doing. All the changes have to be
656 * made atomically, or there may be incorrect pointers all over the place.
658 static int init_dev(kdev_t device
, struct tty_struct
**ret_tty
)
660 struct tty_struct
*tty
, **tty_loc
, *o_tty
, **o_tty_loc
;
661 struct termios
*tp
, **tp_loc
, *o_tp
, **o_tp_loc
;
662 struct termios
*ltp
, **ltp_loc
, *o_ltp
, **o_ltp_loc
;
663 struct tty_driver
*driver
;
667 driver
= get_tty_driver(device
);
671 idx
= MINOR(device
) - driver
->minor_start
;
676 o_tp_loc
= o_ltp_loc
= NULL
;
678 tty_loc
= &driver
->table
[idx
];
679 tp_loc
= &driver
->termios
[idx
];
680 ltp_loc
= &driver
->termios_locked
[idx
];
684 if (driver
->type
== TTY_DRIVER_TYPE_PTY
&&
685 driver
->subtype
== PTY_TYPE_MASTER
&&
686 *tty_loc
&& (*tty_loc
)->count
)
689 if (!*tty_loc
&& !tty
) {
690 if (!(tty
= (struct tty_struct
*) get_free_page(GFP_KERNEL
)))
692 initialize_tty_struct(tty
);
693 tty
->device
= device
;
694 tty
->driver
= *driver
;
697 if (!*tp_loc
&& !tp
) {
698 tp
= (struct termios
*) kmalloc(sizeof(struct termios
),
702 *tp
= driver
->init_termios
;
705 if (!*ltp_loc
&& !ltp
) {
706 ltp
= (struct termios
*) kmalloc(sizeof(struct termios
),
710 memset(ltp
, 0, sizeof(struct termios
));
713 if (driver
->type
== TTY_DRIVER_TYPE_PTY
) {
714 o_tty_loc
= &driver
->other
->table
[idx
];
715 o_tp_loc
= &driver
->other
->termios
[idx
];
716 o_ltp_loc
= &driver
->other
->termios_locked
[idx
];
718 if (!*o_tty_loc
&& !o_tty
) {
721 o_tty
= (struct tty_struct
*)
722 get_free_page(GFP_KERNEL
);
725 o_device
= MKDEV(driver
->other
->major
,
726 driver
->other
->minor_start
+ idx
);
727 initialize_tty_struct(o_tty
);
728 o_tty
->device
= o_device
;
729 o_tty
->driver
= *driver
->other
;
732 if (!*o_tp_loc
&& !o_tp
) {
733 o_tp
= (struct termios
*)
734 kmalloc(sizeof(struct termios
), GFP_KERNEL
);
737 *o_tp
= driver
->other
->init_termios
;
740 if (!*o_ltp_loc
&& !o_ltp
) {
741 o_ltp
= (struct termios
*)
742 kmalloc(sizeof(struct termios
), GFP_KERNEL
);
745 memset(o_ltp
, 0, sizeof(struct termios
));
750 /* Now we have allocated all the structures: update all the pointers.. */
760 tty
->termios
= *tp_loc
;
761 tty
->termios_locked
= *ltp_loc
;
763 (*driver
->refcount
)++;
765 if (tty
->ldisc
.open
) {
766 retval
= (tty
->ldisc
.open
)(tty
);
775 if ((*tty_loc
)->flags
& (1 << TTY_CLOSING
)) {
776 printk("Attempt to open closing tty %s.\n",
778 printk("Ack!!!! This should never happen!!\n");
783 if (driver
->type
== TTY_DRIVER_TYPE_PTY
) {
793 o_tty
->termios
= *o_tp_loc
;
794 o_tty
->termios_locked
= *o_ltp_loc
;
796 (*driver
->other
->refcount
)++;
797 if (o_tty
->ldisc
.open
) {
798 retval
= (o_tty
->ldisc
.open
)(o_tty
);
807 (*tty_loc
)->link
= *o_tty_loc
;
808 (*o_tty_loc
)->link
= *tty_loc
;
809 if (driver
->subtype
== PTY_TYPE_MASTER
)
810 (*o_tty_loc
)->count
++;
812 (*tty_loc
)->driver
= *driver
;
817 free_page((unsigned long) tty
);
819 free_page((unsigned long) o_tty
);
821 kfree_s(tp
, sizeof(struct termios
));
823 kfree_s(o_tp
, sizeof(struct termios
));
825 kfree_s(ltp
, sizeof(struct termios
));
827 kfree_s(o_ltp
, sizeof(struct termios
));
832 * Even releasing the tty structures is a tricky business.. We have
833 * to be very careful that the structures are all released at the
834 * same time, as interrupts might otherwise get the wrong pointers.
836 static void release_dev(struct file
* filp
)
838 struct tty_struct
*tty
, *o_tty
;
839 struct termios
*tp
, *o_tp
, *ltp
, *o_ltp
;
840 struct task_struct
**p
;
843 tty
= (struct tty_struct
*)filp
->private_data
;
844 if (tty_paranoia_check(tty
, filp
->f_inode
->i_rdev
, "release_dev"))
847 check_tty_count(tty
, "release_dev");
849 tty_fasync(filp
->f_inode
, filp
, 0);
852 ltp
= tty
->termios_locked
;
854 idx
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
855 #ifdef TTY_PARANOIA_CHECK
856 if (idx
< 0 || idx
>= tty
->driver
.num
) {
857 printk("release_dev: bad idx when trying to free (%s)\n",
858 kdevname(tty
->device
));
861 if (tty
!= tty
->driver
.table
[idx
]) {
862 printk("release_dev: driver.table[%d] not tty for (%s)\n",
863 idx
, kdevname(tty
->device
));
866 if (tp
!= tty
->driver
.termios
[idx
]) {
867 printk("release_dev: driver.termios[%d] not termios for ("
869 idx
, kdevname(tty
->device
));
872 if (ltp
!= tty
->driver
.termios_locked
[idx
]) {
873 printk("release_dev: driver.termios_locked[%d] not termios_locked for ("
875 idx
, kdevname(tty
->device
));
880 #ifdef TTY_DEBUG_HANGUP
881 printk("release_dev of %s (tty count=%d)...", tty_name(tty
),
886 o_tp
= (o_tty
) ? o_tty
->termios
: NULL
;
887 o_ltp
= (o_tty
) ? o_tty
->termios_locked
: NULL
;
889 #ifdef TTY_PARANOIA_CHECK
890 if (tty
->driver
.other
) {
891 if (o_tty
!= tty
->driver
.other
->table
[idx
]) {
892 printk("release_dev: other->table[%d] not o_tty for ("
894 idx
, kdevname(tty
->device
));
897 if (o_tp
!= tty
->driver
.other
->termios
[idx
]) {
898 printk("release_dev: other->termios[%d] not o_termios for ("
900 idx
, kdevname(tty
->device
));
903 if (o_ltp
!= tty
->driver
.other
->termios_locked
[idx
]) {
904 printk("release_dev: other->termios_locked[%d] not o_termios_locked for ("
906 idx
, kdevname(tty
->device
));
910 if (o_tty
->link
!= tty
) {
911 printk("release_dev: bad pty pointers\n");
917 if (tty
->driver
.close
)
918 tty
->driver
.close(tty
, filp
);
919 if (tty
->driver
.type
== TTY_DRIVER_TYPE_PTY
&&
920 tty
->driver
.subtype
== PTY_TYPE_MASTER
) {
921 if (--tty
->link
->count
< 0) {
922 printk("release_dev: bad pty slave count (%d) for %s\n",
923 tty
->count
, tty_name(tty
));
924 tty
->link
->count
= 0;
927 if (--tty
->count
< 0) {
928 printk("release_dev: bad tty->count (%d) for %s\n",
929 tty
->count
, tty_name(tty
));
936 * Sanity check --- if tty->count is zero, there shouldn't be
937 * any waiters on tty->read_wait or tty->write_wait. But just
941 if (waitqueue_active(&tty
->read_wait
)) {
942 printk("release_dev: %s: read_wait active?!?\n",
944 wake_up(&tty
->read_wait
);
945 } else if (waitqueue_active(&tty
->write_wait
)) {
946 printk("release_dev: %s: write_wait active?!?\n",
948 wake_up(&tty
->write_wait
);
955 * We're committed; at this point, we must not block!
960 tty
->driver
.other
->table
[idx
] = NULL
;
961 tty
->driver
.other
->termios
[idx
] = NULL
;
962 kfree_s(o_tp
, sizeof(struct termios
));
965 #ifdef TTY_DEBUG_HANGUP
966 printk("freeing tty structure...");
968 tty
->flags
|= (1 << TTY_CLOSING
);
971 * Make sure there aren't any processes that still think this
972 * tty is their controlling tty.
974 for (p
= &LAST_TASK
; p
> &FIRST_TASK
; --p
) {
977 if ((*p
)->tty
== tty
)
979 if (o_tty
&& (*p
)->tty
== o_tty
)
984 * Shutdown the current line discipline, and reset it to
987 if (tty
->ldisc
.close
)
988 (tty
->ldisc
.close
)(tty
);
989 tty
->ldisc
= ldiscs
[N_TTY
];
990 tty
->termios
->c_line
= N_TTY
;
992 if (o_tty
->ldisc
.close
)
993 (o_tty
->ldisc
.close
)(o_tty
);
994 o_tty
->ldisc
= ldiscs
[N_TTY
];
997 tty
->driver
.table
[idx
] = NULL
;
998 if (tty
->driver
.flags
& TTY_DRIVER_RESET_TERMIOS
) {
999 tty
->driver
.termios
[idx
] = NULL
;
1000 kfree_s(tp
, sizeof(struct termios
));
1002 if (tty
== redirect
|| o_tty
== redirect
)
1005 * Make sure that the tty's task queue isn't activated. If it
1006 * is, take it out of the linked list.
1008 spin_lock_irq(&tqueue_lock
);
1009 if (tty
->flip
.tqueue
.sync
) {
1010 struct tq_struct
*tq
, *prev
;
1012 for (tq
=tq_timer
, prev
=0; tq
; prev
=tq
, tq
=tq
->next
) {
1013 if (tq
== &tty
->flip
.tqueue
) {
1015 prev
->next
= tq
->next
;
1017 tq_timer
= tq
->next
;
1022 spin_unlock_irq(&tqueue_lock
);
1024 (*tty
->driver
.refcount
)--;
1025 free_page((unsigned long) tty
);
1026 filp
->private_data
= 0;
1029 (*o_tty
->driver
.refcount
)--;
1030 free_page((unsigned long) o_tty
);
1035 * tty_open and tty_release keep up the tty count that contains the
1036 * number of opens done on a tty. We cannot use the inode-count, as
1037 * different inodes might point to the same tty.
1039 * Open-counting is needed for pty masters, as well as for keeping
1040 * track of serial lines: DTR is dropped when the last close happens.
1041 * (This is not done solely through tty->count, now. - Ted 1/27/92)
1043 * The termios state of a pty is reset on first open so that
1044 * settings don't persist across reuse.
1046 static int tty_open(struct inode
* inode
, struct file
* filp
)
1048 struct tty_struct
*tty
;
1052 unsigned short saved_flags
;
1054 saved_flags
= filp
->f_flags
;
1056 noctty
= filp
->f_flags
& O_NOCTTY
;
1057 device
= inode
->i_rdev
;
1058 if (device
== TTY_DEV
) {
1061 device
= current
->tty
->device
;
1062 filp
->f_flags
|= O_NONBLOCK
; /* Don't let /dev/tty block */
1065 if (device
== CONSOLE_DEV
) {
1066 struct console
*c
= console_drivers
;
1067 while(c
&& !c
->device
)
1071 device
= c
->device();
1074 minor
= MINOR(device
);
1076 retval
= init_dev(device
, &tty
);
1079 filp
->private_data
= tty
;
1080 check_tty_count(tty
, "tty_open");
1081 if (tty
->driver
.type
== TTY_DRIVER_TYPE_PTY
&&
1082 tty
->driver
.subtype
== PTY_TYPE_MASTER
)
1084 #ifdef TTY_DEBUG_HANGUP
1085 printk("opening %s...", tty_name(tty
));
1087 if (tty
->driver
.open
)
1088 retval
= tty
->driver
.open(tty
, filp
);
1091 filp
->f_flags
= saved_flags
;
1093 if (!retval
&& test_bit(TTY_EXCLUSIVE
, &tty
->flags
) && !suser())
1097 #ifdef TTY_DEBUG_HANGUP
1098 printk("error %d in opening %s...", retval
, tty_name(tty
));
1102 if (retval
!= -ERESTARTSYS
)
1104 if (current
->signal
& ~current
->blocked
)
1108 * Need to reset f_op in case a hangup happened.
1110 filp
->f_op
= &tty_fops
;
1116 tty
->session
== 0) {
1118 current
->tty_old_pgrp
= 0;
1119 tty
->session
= current
->session
;
1120 tty
->pgrp
= current
->pgrp
;
1126 * Note that releasing a pty master also releases the child, so
1127 * we have to make the redirection checks after that and on both
1130 static int tty_release(struct inode
* inode
, struct file
* filp
)
1136 static unsigned int tty_poll(struct file
* filp
, poll_table
* wait
)
1138 struct tty_struct
* tty
;
1140 tty
= (struct tty_struct
*)filp
->private_data
;
1141 if (tty_paranoia_check(tty
, filp
->f_inode
->i_rdev
, "tty_poll"))
1144 if (tty
->ldisc
.poll
)
1145 return (tty
->ldisc
.poll
)(tty
, filp
, wait
);
1150 * fasync_helper() is used by some character device drivers (mainly mice)
1151 * to set up the fasync queue. It returns negative on error, 0 if it did
1152 * no changes and positive if it added/deleted the entry.
1154 int fasync_helper(struct inode
* inode
, struct file
* filp
, int on
, struct fasync_struct
**fapp
)
1156 struct fasync_struct
*fa
, **fp
;
1157 unsigned long flags
;
1159 for (fp
= fapp
; (fa
= *fp
) != NULL
; fp
= &fa
->fa_next
) {
1160 if (fa
->fa_file
== filp
)
1167 fa
= (struct fasync_struct
*)kmalloc(sizeof(struct fasync_struct
), GFP_KERNEL
);
1170 fa
->magic
= FASYNC_MAGIC
;
1174 fa
->fa_next
= *fapp
;
1176 restore_flags(flags
);
1184 restore_flags(flags
);
1189 static int tty_fasync(struct inode
* inode
, struct file
* filp
, int on
)
1191 struct tty_struct
* tty
;
1194 tty
= (struct tty_struct
*)filp
->private_data
;
1195 if (tty_paranoia_check(tty
, inode
->i_rdev
, "tty_fasync"))
1198 retval
= fasync_helper(inode
, filp
, on
, &tty
->fasync
);
1203 if (!waitqueue_active(&tty
->read_wait
))
1204 tty
->minimum_to_wake
= 1;
1205 if (filp
->f_owner
== 0) {
1207 filp
->f_owner
= -tty
->pgrp
;
1209 filp
->f_owner
= current
->pid
;
1212 if (!tty
->fasync
&& !waitqueue_active(&tty
->read_wait
))
1213 tty
->minimum_to_wake
= N_TTY_BUF_SIZE
;
1220 * XXX does anyone use this anymore?!?
1222 static int do_get_ps_info(unsigned long arg
)
1226 int present
[NR_TASKS
];
1227 struct task_struct tasks
[NR_TASKS
];
1229 struct tstruct
*ts
= (struct tstruct
*)arg
;
1230 struct task_struct
**p
;
1234 i
= verify_area(VERIFY_WRITE
, (void *)arg
, sizeof(struct tstruct
));
1237 for (p
= &FIRST_TASK
; p
<= &LAST_TASK
; p
++, n
++)
1241 d
= (char *)(ts
->tasks
+n
);
1242 for (i
=0 ; i
<sizeof(struct task_struct
) ; i
++)
1243 put_user(*c
++, d
++);
1244 put_user(1, ts
->present
+n
);
1247 put_user(0, ts
->present
+n
);
1252 static int tiocsti(struct tty_struct
*tty
, char * arg
)
1256 if ((current
->tty
!= tty
) && !suser())
1258 if (get_user(ch
, arg
))
1260 tty
->ldisc
.receive_buf(tty
, &ch
, &mbz
, 1);
1264 static int tiocgwinsz(struct tty_struct
*tty
, struct winsize
* arg
)
1266 if (copy_to_user(arg
, &tty
->winsize
, sizeof(*arg
)))
1271 static int tiocswinsz(struct tty_struct
*tty
, struct tty_struct
*real_tty
,
1272 struct winsize
* arg
)
1274 struct winsize tmp_ws
;
1276 if (copy_from_user(&tmp_ws
, arg
, sizeof(*arg
)))
1278 if (!memcmp(&tmp_ws
, &tty
->winsize
, sizeof(*arg
)))
1281 kill_pg(tty
->pgrp
, SIGWINCH
, 1);
1282 if ((real_tty
->pgrp
!= tty
->pgrp
) && (real_tty
->pgrp
> 0))
1283 kill_pg(real_tty
->pgrp
, SIGWINCH
, 1);
1284 tty
->winsize
= tmp_ws
;
1285 real_tty
->winsize
= tmp_ws
;
1289 static int tioccons(struct tty_struct
*tty
, struct tty_struct
*real_tty
)
1291 if (tty
->driver
.type
== TTY_DRIVER_TYPE_CONSOLE
) {
1299 redirect
= real_tty
;
1304 static int fionbio(struct file
*file
, int *arg
)
1308 if (get_user(nonblock
, arg
))
1312 file
->f_flags
|= O_NONBLOCK
;
1314 file
->f_flags
&= ~O_NONBLOCK
;
1318 static int tiocsctty(struct tty_struct
*tty
, int arg
)
1320 if (current
->leader
&&
1321 (current
->session
== tty
->session
))
1324 * The process must be a session leader and
1325 * not have a controlling tty already.
1327 if (!current
->leader
|| current
->tty
)
1329 if (tty
->session
> 0) {
1331 * This tty is already the controlling
1332 * tty for another session group!
1334 if ((arg
== 1) && suser()) {
1338 struct task_struct
*p
;
1347 current
->tty_old_pgrp
= 0;
1348 tty
->session
= current
->session
;
1349 tty
->pgrp
= current
->pgrp
;
1353 static int tiocgpgrp(struct tty_struct
*tty
, struct tty_struct
*real_tty
, pid_t
*arg
)
1356 * (tty == real_tty) is a cheap way of
1357 * testing if the tty is NOT a master pty.
1359 if (tty
== real_tty
&& current
->tty
!= real_tty
)
1361 return put_user(real_tty
->pgrp
, arg
);
1364 static int tiocspgrp(struct tty_struct
*tty
, struct tty_struct
*real_tty
, pid_t
*arg
)
1367 int retval
= tty_check_change(real_tty
);
1373 if (!current
->tty
||
1374 (current
->tty
!= real_tty
) ||
1375 (real_tty
->session
!= current
->session
))
1377 get_user(pgrp
, (pid_t
*) arg
);
1380 if (session_of_pgrp(pgrp
) != current
->session
)
1382 real_tty
->pgrp
= pgrp
;
1386 static int tiocttygstruct(struct tty_struct
*tty
, struct tty_struct
*arg
)
1388 if (copy_to_user(arg
, tty
, sizeof(*arg
)))
1393 static int tiocsetd(struct tty_struct
*tty
, int *arg
)
1397 retval
= tty_check_change(tty
);
1400 retval
= get_user(ldisc
, arg
);
1403 return tty_set_ldisc(tty
, ldisc
);
1407 * Split this up, as gcc can choke on it otherwise..
1409 static int tty_ioctl(struct inode
* inode
, struct file
* file
,
1410 unsigned int cmd
, unsigned long arg
)
1412 struct tty_struct
*tty
, *real_tty
;
1414 tty
= (struct tty_struct
*)file
->private_data
;
1415 if (tty_paranoia_check(tty
, inode
->i_rdev
, "tty_ioctl"))
1419 if (tty
->driver
.type
== TTY_DRIVER_TYPE_PTY
&&
1420 tty
->driver
.subtype
== PTY_TYPE_MASTER
)
1421 real_tty
= tty
->link
;
1425 return tiocsti(tty
, (char *)arg
);
1427 return tiocgwinsz(tty
, (struct winsize
*) arg
);
1429 return tiocswinsz(tty
, real_tty
, (struct winsize
*) arg
);
1431 return tioccons(tty
, real_tty
);
1433 return fionbio(file
, (int *) arg
);
1435 set_bit(TTY_EXCLUSIVE
, &tty
->flags
);
1438 clear_bit(TTY_EXCLUSIVE
, &tty
->flags
);
1441 if (current
->tty
!= tty
)
1443 if (current
->leader
)
1444 disassociate_ctty(0);
1445 current
->tty
= NULL
;
1448 return tiocsctty(tty
, arg
);
1450 return tiocgpgrp(tty
, real_tty
, (pid_t
*) arg
);
1452 return tiocspgrp(tty
, real_tty
, (pid_t
*) arg
);
1454 return put_user(tty
->ldisc
.num
, (int *) arg
);
1456 return tiocsetd(tty
, (int *) arg
);
1459 return tioclinux(tty
, arg
);
1461 case TIOCTTYGSTRUCT
:
1462 return tiocttygstruct(tty
, (struct tty_struct
*) arg
);
1464 if (tty
->driver
.ioctl
) {
1465 int retval
= (tty
->driver
.ioctl
)(tty
, file
, cmd
, arg
);
1466 if (retval
!= -ENOIOCTLCMD
)
1469 if (tty
->ldisc
.ioctl
) {
1470 int retval
= (tty
->ldisc
.ioctl
)(tty
, file
, cmd
, arg
);
1471 if (retval
!= -ENOIOCTLCMD
)
1479 * This implements the "Secure Attention Key" --- the idea is to
1480 * prevent trojan horses by killing all processes associated with this
1481 * tty when the user hits the "Secure Attention Key". Required for
1482 * super-paranoid applications --- see the Orange Book for more details.
1484 * This code could be nicer; ideally it should send a HUP, wait a few
1485 * seconds, then send a INT, and then a KILL signal. But you then
1486 * have to coordinate with the init process, since all processes associated
1487 * with the current tty must be dead before the new getty is allowed
1490 void do_SAK( struct tty_struct
*tty
)
1495 struct task_struct
**p
;
1502 session
= tty
->session
;
1503 if (tty
->ldisc
.flush_buffer
)
1504 tty
->ldisc
.flush_buffer(tty
);
1505 if (tty
->driver
.flush_buffer
)
1506 tty
->driver
.flush_buffer(tty
);
1507 for (p
= &LAST_TASK
; p
> &FIRST_TASK
; --p
) {
1510 if (((*p
)->tty
== tty
) ||
1511 ((session
> 0) && ((*p
)->session
== session
)))
1512 send_sig(SIGKILL
, *p
, 1);
1513 else if ((*p
)->files
) {
1514 for (i
=0; i
< NR_OPEN
; i
++) {
1515 filp
= (*p
)->files
->fd
[i
];
1516 if (filp
&& (filp
->f_op
== &tty_fops
) &&
1517 (filp
->private_data
== tty
)) {
1518 send_sig(SIGKILL
, *p
, 1);
1528 * This routine is called out of the software interrupt to flush data
1529 * from the flip buffer to the line discipline.
1531 static void flush_to_ldisc(void *private_
)
1533 struct tty_struct
*tty
= (struct tty_struct
*) private_
;
1538 if (tty
->flip
.buf_num
) {
1539 cp
= tty
->flip
.char_buf
+ TTY_FLIPBUF_SIZE
;
1540 fp
= tty
->flip
.flag_buf
+ TTY_FLIPBUF_SIZE
;
1541 tty
->flip
.buf_num
= 0;
1544 tty
->flip
.char_buf_ptr
= tty
->flip
.char_buf
;
1545 tty
->flip
.flag_buf_ptr
= tty
->flip
.flag_buf
;
1547 cp
= tty
->flip
.char_buf
;
1548 fp
= tty
->flip
.flag_buf
;
1549 tty
->flip
.buf_num
= 1;
1552 tty
->flip
.char_buf_ptr
= tty
->flip
.char_buf
+ TTY_FLIPBUF_SIZE
;
1553 tty
->flip
.flag_buf_ptr
= tty
->flip
.flag_buf
+ TTY_FLIPBUF_SIZE
;
1555 count
= tty
->flip
.count
;
1556 tty
->flip
.count
= 0;
1560 if (count
> tty
->max_flip_cnt
)
1561 tty
->max_flip_cnt
= count
;
1563 tty
->ldisc
.receive_buf(tty
, cp
, fp
, count
);
1567 * This subroutine initializes a tty structure.
1569 static void initialize_tty_struct(struct tty_struct
*tty
)
1571 memset(tty
, 0, sizeof(struct tty_struct
));
1572 tty
->magic
= TTY_MAGIC
;
1573 tty
->ldisc
= ldiscs
[N_TTY
];
1575 tty
->flip
.char_buf_ptr
= tty
->flip
.char_buf
;
1576 tty
->flip
.flag_buf_ptr
= tty
->flip
.flag_buf
;
1577 tty
->flip
.tqueue
.routine
= flush_to_ldisc
;
1578 tty
->flip
.tqueue
.data
= tty
;
1582 * The default put_char routine if the driver did not define one.
1584 void tty_default_put_char(struct tty_struct
*tty
, unsigned char ch
)
1586 tty
->driver
.write(tty
, 0, &ch
, 1);
1590 * Called by a tty driver to register itself.
1592 int tty_register_driver(struct tty_driver
*driver
)
1596 if (driver
->flags
& TTY_DRIVER_INSTALLED
)
1599 error
= register_chrdev(driver
->major
, driver
->name
, &tty_fops
);
1602 else if(driver
->major
== 0)
1603 driver
->major
= error
;
1605 if (!driver
->put_char
)
1606 driver
->put_char
= tty_default_put_char
;
1609 driver
->next
= tty_drivers
;
1610 if (tty_drivers
) tty_drivers
->prev
= driver
;
1611 tty_drivers
= driver
;
1613 #ifdef CONFIG_PROC_FS
1614 proc_tty_register_driver(driver
);
1620 * Called by a tty driver to unregister itself.
1622 int tty_unregister_driver(struct tty_driver
*driver
)
1625 struct tty_driver
*p
;
1627 const char *othername
= NULL
;
1629 if (*driver
->refcount
)
1632 for (p
= tty_drivers
; p
; p
= p
->next
) {
1635 else if (p
->major
== driver
->major
)
1636 othername
= p
->name
;
1642 if (othername
== NULL
) {
1643 retval
= unregister_chrdev(driver
->major
, driver
->name
);
1647 register_chrdev(driver
->major
, othername
, &tty_fops
);
1650 driver
->prev
->next
= driver
->next
;
1652 tty_drivers
= driver
->next
;
1655 driver
->next
->prev
= driver
->prev
;
1657 #ifdef CONFIG_PROC_FS
1658 proc_tty_unregister_driver(driver
);
1665 * Initialize the console device. This is called *early*, so
1666 * we can't necessarily depend on lots of kernel help here.
1667 * Just do some early initializations, and do the complex setup
1670 long console_init(long kmem_start
, long kmem_end
)
1672 /* Setup the default TTY line discipline. */
1673 memset(ldiscs
, 0, sizeof(ldiscs
));
1674 (void) tty_register_ldisc(N_TTY
, &tty_ldisc_N_TTY
);
1677 * Set up the standard termios. Individual tty drivers may
1678 * deviate from this; this is used as a template.
1680 memset(&tty_std_termios
, 0, sizeof(struct termios
));
1681 memcpy(tty_std_termios
.c_cc
, INIT_C_CC
, NCCS
);
1682 tty_std_termios
.c_iflag
= ICRNL
| IXON
;
1683 tty_std_termios
.c_oflag
= OPOST
| ONLCR
;
1684 tty_std_termios
.c_cflag
= B38400
| CS8
| CREAD
| HUPCL
;
1685 tty_std_termios
.c_lflag
= ISIG
| ICANON
| ECHO
| ECHOE
| ECHOK
|
1686 ECHOCTL
| ECHOKE
| IEXTEN
;
1689 * set up the console device so that later boot sequences can
1690 * inform about problems etc..
1692 #ifdef CONFIG_SERIAL_CONSOLE
1693 kmem_start
= serial_console_init(kmem_start
, kmem_end
);
1696 kmem_start
= con_init(kmem_start
);
1701 static struct tty_driver dev_tty_driver
, dev_console_driver
;
1704 * Ok, now we can initialize the rest of the tty devices and can count
1705 * on memory allocations, interrupts etc..
1709 if (sizeof(struct tty_struct
) > PAGE_SIZE
)
1710 panic("size of tty structure > PAGE_SIZE!");
1713 * dev_tty_driver and dev_console_driver are actually magic
1714 * devices which get redirected at open time. Nevertheless,
1715 * we register them so that register_chrdev is called
1718 memset(&dev_tty_driver
, 0, sizeof(struct tty_driver
));
1719 dev_tty_driver
.magic
= TTY_DRIVER_MAGIC
;
1720 dev_tty_driver
.driver_name
= "/dev/tty";
1721 dev_tty_driver
.name
= dev_tty_driver
.driver_name
+ 5;
1722 dev_tty_driver
.name_base
= 0;
1723 dev_tty_driver
.major
= TTYAUX_MAJOR
;
1724 dev_tty_driver
.minor_start
= 0;
1725 dev_tty_driver
.num
= 1;
1726 dev_tty_driver
.type
= TTY_DRIVER_TYPE_SYSTEM
;
1727 dev_tty_driver
.subtype
= SYSTEM_TYPE_TTY
;
1729 if (tty_register_driver(&dev_tty_driver
))
1730 panic("Couldn't register /dev/tty driver\n");
1732 dev_console_driver
= dev_tty_driver
;
1733 dev_console_driver
.driver_name
= "/dev/console";
1734 dev_console_driver
.name
= dev_console_driver
.driver_name
+ 5;
1735 dev_console_driver
.major
= TTY_MAJOR
;
1736 dev_console_driver
.type
= TTY_DRIVER_TYPE_SYSTEM
;
1737 dev_console_driver
.subtype
= SYSTEM_TYPE_CONSOLE
;
1739 if (tty_register_driver(&dev_console_driver
))
1740 panic("Couldn't register /dev/console driver\n");
1745 #ifdef CONFIG_ESPSERIAL /* init ESP before rs, so rs doesn't see the port */
1748 #ifdef CONFIG_SERIAL
1751 #ifdef CONFIG_CYCLADES
1754 #ifdef CONFIG_STALLION
1757 #ifdef CONFIG_ISTALLION
1763 #ifdef CONFIG_RISCOM8