2 * linux/drivers/char/vt.c
4 * Copyright (C) 1992 obz under the linux copyright
6 * Dynamic diacritical handling - aeb@cwi.nl - Dec 1993
7 * Dynamic keymap and string allocation - aeb@cwi.nl - May 1994
8 * Restrict VT switching via ioctl() - grif@cs.ucr.edu - Dec 1995
9 * Some code moved for less code duplication - Andi Kleen - Mar 1997
12 #include <linux/config.h>
13 #include <linux/types.h>
14 #include <linux/errno.h>
15 #include <linux/sched.h>
16 #include <linux/tty.h>
17 #include <linux/timer.h>
18 #include <linux/kernel.h>
21 #include <linux/string.h>
22 #include <linux/malloc.h>
23 #include <linux/major.h>
25 #include <linux/console.h>
28 #include <asm/uaccess.h>
30 #include <linux/kbd_kern.h>
31 #include <linux/vt_kern.h>
32 #include <linux/kbd_diacr.h>
33 #include <linux/selection.h>
35 #ifdef CONFIG_FB_COMPAT_XPMAC
36 #include <asm/vc_ioctl.h>
37 #endif /* CONFIG_FB_COMPAT_XPMAC */
39 char vt_dont_switch
= 0;
40 extern struct tty_driver console_driver
;
42 #define VT_IS_IN_USE(i) (console_driver.table[i] && console_driver.table[i]->count)
43 #define VT_BUSY(i) (VT_IS_IN_USE(i) || i == fg_console || i == sel_cons)
46 * Console (vt and kd) routines, as defined by USL SVR4 manual, and by
47 * experimentation and study of X386 SYSV handling.
49 * One point of difference: SYSV vt's are /dev/vtX, which X >= 0, and
50 * /dev/console is a separate ttyp. Under Linux, /dev/tty0 is /dev/console,
51 * and the vc start at /dev/ttyX, X >= 1. We maintain that here, so we will
52 * always treat our set of vt as numbered 1..MAX_NR_CONSOLES (corresponding to
53 * ttys 0..MAX_NR_CONSOLES-1). Explicitly naming VT 0 is illegal, but using
54 * /dev/tty0 (fg_console) as a target is legal, since an implicit aliasing
55 * to the current console is done by the main ioctl code.
58 struct vt_struct
*vt_cons
[MAX_NR_CONSOLES
];
60 /* Keyboard type: Default is KB_101, but can be set by machine
63 unsigned char keyboard_type
= KB_101
;
65 #if !defined(__alpha__) && !defined(__mips__) && !defined(__arm__) && !defined(__sh__)
66 asmlinkage
long sys_ioperm(unsigned long from
, unsigned long num
, int on
);
69 unsigned int video_font_height
;
70 unsigned int default_font_height
;
71 unsigned int video_scan_lines
;
74 * these are the valid i/o ports we're allowed to change. they map all the
79 #define GPNUM (GPLAST - GPFIRST + 1)
82 * Generates sound of some frequency for some number of clock ticks
84 * If freq is 0, will turn off sound, else will turn it on for that time.
85 * If msec is 0, will return immediately, else will sleep for msec time, then
88 * We also return immediately, which is what was implied within the X
89 * comments - KDMKTONE doesn't put the process to sleep.
92 #if defined(__i386__) || defined(__alpha__) || defined(__powerpc__) \
93 || (defined(__mips__) && defined(CONFIG_ISA)) \
94 || (defined(__arm__) && defined(CONFIG_HOST_FOOTBRIDGE))
97 kd_nosound(unsigned long ignored
)
99 /* disable counter 2 */
100 outb(inb_p(0x61)&0xFC, 0x61);
105 _kd_mksound(unsigned int hz
, unsigned int ticks
)
107 static struct timer_list sound_timer
= { function
: kd_nosound
};
108 unsigned int count
= 0;
111 if (hz
> 20 && hz
< 32767)
112 count
= 1193180 / hz
;
116 del_timer(&sound_timer
);
118 /* enable counter 2 */
119 outb_p(inb_p(0x61)|3, 0x61);
120 /* set command for counter 2, 2 byte write */
122 /* select desired HZ */
123 outb_p(count
& 0xff, 0x42);
124 outb((count
>> 8) & 0xff, 0x42);
127 sound_timer
.expires
= jiffies
+ticks
;
128 add_timer(&sound_timer
);
132 restore_flags(flags
);
139 _kd_mksound(unsigned int hz
, unsigned int ticks
)
145 void (*kd_mksound
)(unsigned int hz
, unsigned int ticks
) = _kd_mksound
;
148 #define i (tmp.kb_index)
149 #define s (tmp.kb_table)
150 #define v (tmp.kb_value)
152 do_kdsk_ioctl(int cmd
, struct kbentry
*user_kbe
, int perm
, struct kbd_struct
*kbd
)
155 ushort
*key_map
, val
, ov
;
157 if (copy_from_user(&tmp
, user_kbe
, sizeof(struct kbentry
)))
159 if (i
>= NR_KEYS
|| s
>= MAX_NR_KEYMAPS
)
164 key_map
= key_maps
[s
];
167 if (kbd
->kbdmode
!= VC_UNICODE
&& KTYP(val
) >= NR_TYPES
)
170 val
= (i
? K_HOLE
: K_NOSUCHMAP
);
171 return put_user(val
, &user_kbe
->kb_value
);
175 if (!i
&& v
== K_NOSUCHMAP
) {
176 /* disallocate map */
177 key_map
= key_maps
[s
];
180 if (key_map
[0] == U(K_ALLOCATED
)) {
181 kfree_s(key_map
, sizeof(plain_map
));
188 if (KTYP(v
) < NR_TYPES
) {
189 if (KVAL(v
) > max_vals
[KTYP(v
)])
192 if (kbd
->kbdmode
!= VC_UNICODE
)
195 /* ++Geert: non-PC keyboards may generate keycode zero */
196 #if !defined(__mc68000__) && !defined(__powerpc__)
197 /* assignment to entry 0 only tests validity of args */
202 if (!(key_map
= key_maps
[s
])) {
205 if (keymap_count
>= MAX_NR_OF_USER_KEYMAPS
&&
206 !capable(CAP_SYS_RESOURCE
))
209 key_map
= (ushort
*) kmalloc(sizeof(plain_map
),
213 key_maps
[s
] = key_map
;
214 key_map
[0] = U(K_ALLOCATED
);
215 for (j
= 1; j
< NR_KEYS
; j
++)
216 key_map
[j
] = U(K_HOLE
);
221 break; /* nothing to do */
225 if (((ov
== K_SAK
) || (v
== K_SAK
)) && !capable(CAP_SYS_ADMIN
))
228 if (!s
&& (KTYP(ov
) == KT_SHIFT
|| KTYP(v
) == KT_SHIFT
))
229 compute_shiftstate();
239 do_kbkeycode_ioctl(int cmd
, struct kbkeycode
*user_kbkc
, int perm
)
241 struct kbkeycode tmp
;
244 if (copy_from_user(&tmp
, user_kbkc
, sizeof(struct kbkeycode
)))
248 kc
= getkeycode(tmp
.scancode
);
250 kc
= put_user(kc
, &user_kbkc
->keycode
);
255 kc
= setkeycode(tmp
.scancode
, tmp
.keycode
);
262 do_kdgkb_ioctl(int cmd
, struct kbsentry
*user_kdgkb
, int perm
)
269 char *first_free
, *fj
, *fnw
;
272 /* we mostly copy too much here (512bytes), but who cares ;) */
273 if (copy_from_user(&tmp
, user_kdgkb
, sizeof(struct kbsentry
)))
275 tmp
.kb_string
[sizeof(tmp
.kb_string
)-1] = '\0';
276 if (tmp
.kb_func
>= MAX_NR_FUNC
)
282 sz
= sizeof(tmp
.kb_string
) - 1; /* sz should have been
284 q
= user_kdgkb
->kb_string
;
287 for ( ; *p
&& sz
; p
++, sz
--)
290 return ((p
&& *p
) ? -EOVERFLOW
: 0);
296 first_free
= funcbufptr
+ (funcbufsize
- funcbufleft
);
297 for (j
= i
+1; j
< MAX_NR_FUNC
&& !func_table
[j
]; j
++)
304 delta
= (q
? -strlen(q
) : 1) + strlen(tmp
.kb_string
);
305 if (delta
<= funcbufleft
) { /* it fits in current buf */
306 if (j
< MAX_NR_FUNC
) {
307 memmove(fj
+ delta
, fj
, first_free
- fj
);
308 for (k
= j
; k
< MAX_NR_FUNC
; k
++)
310 func_table
[k
] += delta
;
314 funcbufleft
-= delta
;
315 } else { /* allocate a larger buffer */
317 while (sz
< funcbufsize
- funcbufleft
+ delta
)
319 fnw
= (char *) kmalloc(sz
, GFP_KERNEL
);
326 memmove(fnw
, funcbufptr
, fj
- funcbufptr
);
327 for (k
= 0; k
< j
; k
++)
329 func_table
[k
] = fnw
+ (func_table
[k
] - funcbufptr
);
331 if (first_free
> fj
) {
332 memmove(fnw
+ (fj
- funcbufptr
) + delta
, fj
, first_free
- fj
);
333 for (k
= j
; k
< MAX_NR_FUNC
; k
++)
335 func_table
[k
] = fnw
+ (func_table
[k
] - funcbufptr
) + delta
;
337 if (funcbufptr
!= func_buf
)
338 kfree_s(funcbufptr
, funcbufsize
);
340 funcbufleft
= funcbufleft
- delta
+ sz
- funcbufsize
;
343 strcpy(func_table
[i
], tmp
.kb_string
);
350 do_fontx_ioctl(int cmd
, struct consolefontdesc
*user_cfd
, int perm
)
352 struct consolefontdesc cfdarg
;
353 struct console_font_op op
;
356 if (copy_from_user(&cfdarg
, user_cfd
, sizeof(struct consolefontdesc
)))
363 op
.op
= KD_FONT_OP_SET
;
364 op
.flags
= KD_FONT_FLAG_OLD
;
366 op
.height
= cfdarg
.charheight
;
367 op
.charcount
= cfdarg
.charcount
;
368 op
.data
= cfdarg
.chardata
;
369 return con_font_op(fg_console
, &op
);
371 op
.op
= KD_FONT_OP_GET
;
372 op
.flags
= KD_FONT_FLAG_OLD
;
374 op
.height
= cfdarg
.charheight
;
375 op
.charcount
= cfdarg
.charcount
;
376 op
.data
= cfdarg
.chardata
;
377 i
= con_font_op(fg_console
, &op
);
380 cfdarg
.charheight
= op
.height
;
381 cfdarg
.charcount
= op
.charcount
;
382 if (copy_to_user(user_cfd
, &cfdarg
, sizeof(struct consolefontdesc
)))
391 do_unimap_ioctl(int cmd
, struct unimapdesc
*user_ud
,int perm
)
393 struct unimapdesc tmp
;
396 if (copy_from_user(&tmp
, user_ud
, sizeof tmp
))
399 i
= verify_area(VERIFY_WRITE
, tmp
.entries
,
400 tmp
.entry_ct
*sizeof(struct unipair
));
407 return con_set_unimap(fg_console
, tmp
.entry_ct
, tmp
.entries
);
409 return con_get_unimap(fg_console
, tmp
.entry_ct
, &(user_ud
->entry_ct
), tmp
.entries
);
415 * We handle the console-specific ioctl's here. We allow the
416 * capability to modify any console, not just the fg_console.
418 int vt_ioctl(struct tty_struct
*tty
, struct file
* file
,
419 unsigned int cmd
, unsigned long arg
)
422 unsigned int console
;
424 struct kbd_struct
* kbd
;
425 struct vt_struct
*vt
= (struct vt_struct
*)tty
->driver_data
;
427 console
= vt
->vc_num
;
429 if (!vc_cons_allocated(console
)) /* impossible? */
433 * To have permissions to do most of the vt ioctls, we either have
434 * to be the owner of the tty, or super-user.
437 if (current
->tty
== tty
|| suser())
440 kbd
= kbd_table
+ console
;
454 unsigned int ticks
, count
;
457 * Generate the tone for the appropriate number of ticks.
458 * If the time is zero, turn off sound ourselves.
460 ticks
= HZ
* ((arg
>> 16) & 0xffff) / 1000;
461 count
= ticks
? (arg
& 0xffff) : 0;
463 count
= 1193180 / count
;
464 kd_mksound(count
, ticks
);
472 ucval
= keyboard_type
;
475 #if !defined(__alpha__) && !defined(__mips__) && !defined(__arm__) && !defined(__sh__)
477 * These cannot be implemented on any machine that implements
478 * ioperm() in user level (such as Alpha PCs).
483 * KDADDIO and KDDELIO may be able to add ports beyond what
484 * we reject here, but to be safe...
486 if (arg
< GPFIRST
|| arg
> GPLAST
)
488 return sys_ioperm(arg
, 1, (cmd
== KDADDIO
)) ? -ENXIO
: 0;
492 return sys_ioperm(GPFIRST
, GPNUM
,
493 (cmd
== KDENABIO
)) ? -ENXIO
: 0;
498 * currently, setting the mode from KD_TEXT to KD_GRAPHICS
499 * doesn't do a whole lot. i'm not sure if it should do any
500 * restoration of modes or what...
515 if (vt_cons
[console
]->vc_mode
== (unsigned char) arg
)
517 vt_cons
[console
]->vc_mode
= (unsigned char) arg
;
518 if (console
!= fg_console
)
521 * explicitly blank/unblank the screen if switching modes
530 ucval
= vt_cons
[console
]->vc_mode
;
536 * these work like a combination of mmap and KDENABIO.
537 * this could be easily finished.
546 kbd
->kbdmode
= VC_RAW
;
549 kbd
->kbdmode
= VC_MEDIUMRAW
;
552 kbd
->kbdmode
= VC_XLATE
;
553 compute_shiftstate();
556 kbd
->kbdmode
= VC_UNICODE
;
557 compute_shiftstate();
562 if (tty
->ldisc
.flush_buffer
)
563 tty
->ldisc
.flush_buffer(tty
);
567 ucval
= ((kbd
->kbdmode
== VC_RAW
) ? K_RAW
:
568 (kbd
->kbdmode
== VC_MEDIUMRAW
) ? K_MEDIUMRAW
:
569 (kbd
->kbdmode
== VC_UNICODE
) ? K_UNICODE
:
573 /* this could be folded into KDSKBMODE, but for compatibility
574 reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
578 clr_vc_kbd_mode(kbd
, VC_META
);
581 set_vc_kbd_mode(kbd
, VC_META
);
589 ucval
= (vc_kbd_mode(kbd
, VC_META
) ? K_ESCPREFIX
: K_METABIT
);
591 return put_user(ucval
, (int *)arg
);
595 if(!capable(CAP_SYS_ADMIN
))
597 return do_kbkeycode_ioctl(cmd
, (struct kbkeycode
*)arg
, perm
);
601 return do_kdsk_ioctl(cmd
, (struct kbentry
*)arg
, perm
, kbd
);
605 return do_kdgkb_ioctl(cmd
, (struct kbsentry
*)arg
, perm
);
609 struct kbdiacrs
*a
= (struct kbdiacrs
*)arg
;
611 if (put_user(accent_table_size
, &a
->kb_cnt
))
613 if (copy_to_user(a
->kbdiacr
, accent_table
, accent_table_size
*sizeof(struct kbdiacr
)))
620 struct kbdiacrs
*a
= (struct kbdiacrs
*)arg
;
625 if (get_user(ct
,&a
->kb_cnt
))
629 accent_table_size
= ct
;
630 if (copy_from_user(accent_table
, a
->kbdiacr
, ct
*sizeof(struct kbdiacr
)))
635 /* the ioctls below read/set the flags usually shown in the leds */
636 /* don't use them - they will go away without warning */
638 ucval
= kbd
->ledflagstate
| (kbd
->default_ledflagstate
<< 4);
646 kbd
->ledflagstate
= (arg
& 7);
647 kbd
->default_ledflagstate
= ((arg
>> 4) & 7);
651 /* the ioctls below only set the lights, not the functions */
652 /* for those, see KDGKBLED and KDSKBLED above */
654 ucval
= getledstate();
656 return put_user(ucval
, (char*)arg
);
661 setledstate(kbd
, arg
);
665 * A process can indicate its willingness to accept signals
666 * generated by pressing an appropriate key combination.
667 * Thus, one can have a daemon that e.g. spawns a new console
668 * upon a keypress and then changes to it.
669 * Probably init should be changed to do this (and have a
670 * field ks (`keyboard signal') in inittab describing the
671 * desired action), so that the number of background daemons
676 extern int spawnpid
, spawnsig
;
677 if (!perm
|| !capable(CAP_KILL
))
679 if (arg
< 1 || arg
> _NSIG
|| arg
== SIGKILL
)
681 spawnpid
= current
->pid
;
692 if (copy_from_user(&tmp
, (void*)arg
, sizeof(struct vt_mode
)))
694 if (tmp
.mode
!= VT_AUTO
&& tmp
.mode
!= VT_PROCESS
)
696 vt_cons
[console
]->vt_mode
= tmp
;
697 /* the frsig is ignored, so we set it to 0 */
698 vt_cons
[console
]->vt_mode
.frsig
= 0;
699 vt_cons
[console
]->vt_pid
= current
->pid
;
700 /* no switch is required -- saw@shade.msu.ru */
701 vt_cons
[console
]->vt_newvt
= -1;
706 return copy_to_user((void*)arg
, &(vt_cons
[console
]->vt_mode
),
707 sizeof(struct vt_mode
)) ? -EFAULT
: 0;
710 * Returns global vt state. Note that VT 0 is always open, since
711 * it's an alias for the current VT, and people can't use it here.
712 * We cannot return state for more than 16 VTs, since v_state is short.
716 struct vt_stat
*vtstat
= (struct vt_stat
*)arg
;
717 unsigned short state
, mask
;
719 i
= verify_area(VERIFY_WRITE
,(void *)vtstat
, sizeof(struct vt_stat
));
722 put_user(fg_console
+ 1, &vtstat
->v_active
);
723 state
= 1; /* /dev/tty0 is always open */
724 for (i
= 0, mask
= 2; i
< MAX_NR_CONSOLES
&& mask
; ++i
, mask
<<= 1)
727 return put_user(state
, &vtstat
->v_state
);
731 * Returns the first available (non-opened) console.
734 for (i
= 0; i
< MAX_NR_CONSOLES
; ++i
)
735 if (! VT_IS_IN_USE(i
))
737 ucval
= i
< MAX_NR_CONSOLES
? (i
+1) : -1;
741 * ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num,
742 * with num >= 1 (switches to vt 0, our console, are not allowed, just
743 * to preserve sanity).
748 if (arg
== 0 || arg
> MAX_NR_CONSOLES
)
751 i
= vc_allocate(arg
);
758 * wait until the specified VT has been activated
763 if (arg
== 0 || arg
> MAX_NR_CONSOLES
)
765 return vt_waitactive(arg
-1);
768 * If a vt is under process control, the kernel will not switch to it
769 * immediately, but postpone the operation until the process calls this
770 * ioctl, allowing the switch to complete.
772 * According to the X sources this is the behavior:
773 * 0: pending switch-from not OK
774 * 1: pending switch-from OK
775 * 2: completed switch-to OK
780 if (vt_cons
[console
]->vt_mode
.mode
!= VT_PROCESS
)
784 * Switching-from response
786 if (vt_cons
[console
]->vt_newvt
>= 0)
790 * Switch disallowed, so forget we were trying
793 vt_cons
[console
]->vt_newvt
= -1;
798 * The current vt has been released, so
799 * complete the switch.
801 int newvt
= vt_cons
[console
]->vt_newvt
;
802 vt_cons
[console
]->vt_newvt
= -1;
803 i
= vc_allocate(newvt
);
807 * When we actually do the console switch,
808 * make sure we are atomic with respect to
809 * other console switches..
811 spin_lock_irq(&console_lock
);
812 complete_change_console(newvt
);
813 spin_unlock_irq(&console_lock
);
818 * Switched-to response
823 * If it's just an ACK, ignore it
825 if (arg
!= VT_ACKACQ
)
832 * Disallocate memory associated to VT (but leave VT1)
835 if (arg
> MAX_NR_CONSOLES
)
838 /* disallocate all unused consoles, but leave 0 */
839 for (i
=1; i
<MAX_NR_CONSOLES
; i
++)
843 /* disallocate a single console, if possible */
847 if (arg
) /* leave 0 */
854 struct vt_sizes
*vtsizes
= (struct vt_sizes
*) arg
;
858 i
= verify_area(VERIFY_READ
, (void *)vtsizes
, sizeof(struct vt_sizes
));
861 get_user(ll
, &vtsizes
->v_rows
);
862 get_user(cc
, &vtsizes
->v_cols
);
863 return vc_resize_all(ll
, cc
);
868 struct vt_consize
*vtconsize
= (struct vt_consize
*) arg
;
869 ushort ll
,cc
,vlin
,clin
,vcol
,ccol
;
872 i
= verify_area(VERIFY_READ
, (void *)vtconsize
, sizeof(struct vt_consize
));
875 get_user(ll
, &vtconsize
->v_rows
);
876 get_user(cc
, &vtconsize
->v_cols
);
877 get_user(vlin
, &vtconsize
->v_vlin
);
878 get_user(clin
, &vtconsize
->v_clin
);
879 get_user(vcol
, &vtconsize
->v_vcol
);
880 get_user(ccol
, &vtconsize
->v_ccol
);
881 vlin
= vlin
? vlin
: video_scan_lines
;
886 if ( ll
!= vlin
/clin
)
887 return -EINVAL
; /* Parameters don't add up */
896 if ( cc
!= vcol
/ccol
)
907 video_scan_lines
= vlin
;
909 video_font_height
= clin
;
911 return vc_resize_all(ll
, cc
);
915 struct console_font_op op
;
918 op
.op
= KD_FONT_OP_SET
;
919 op
.flags
= KD_FONT_FLAG_OLD
| KD_FONT_FLAG_DONT_RECALC
; /* Compatibility */
923 op
.data
= (char *) arg
;
924 return con_font_op(fg_console
, &op
);
928 struct console_font_op op
;
929 op
.op
= KD_FONT_OP_GET
;
930 op
.flags
= KD_FONT_FLAG_OLD
;
934 op
.data
= (char *) arg
;
935 return con_font_op(fg_console
, &op
);
941 return con_set_cmap((char *)arg
);
944 return con_get_cmap((char *)arg
);
948 return do_fontx_ioctl(cmd
, (struct consolefontdesc
*)arg
, perm
);
955 #ifdef BROKEN_GRAPHICS_PROGRAMS
956 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
957 font is not saved. */
961 struct console_font_op op
;
962 op
.op
= KD_FONT_OP_SET_DEFAULT
;
964 i
= con_font_op(fg_console
, &op
);
966 con_set_default_unimap(fg_console
);
973 struct console_font_op op
;
974 if (copy_from_user(&op
, (void *) arg
, sizeof(op
)))
976 if (!perm
&& op
.op
!= KD_FONT_OP_GET
)
978 i
= con_font_op(console
, &op
);
980 if (copy_to_user((void *) arg
, &op
, sizeof(op
)))
988 return con_set_trans_old((unsigned char *)arg
);
991 return con_get_trans_old((unsigned char *)arg
);
996 return con_set_trans_new((unsigned short *)arg
);
999 return con_get_trans_new((unsigned short *)arg
);
1002 { struct unimapinit ui
;
1005 i
= copy_from_user(&ui
, (void *)arg
, sizeof(struct unimapinit
));
1006 if (i
) return -EFAULT
;
1007 con_clear_unimap(fg_console
, &ui
);
1013 return do_unimap_ioctl(cmd
, (struct unimapdesc
*)arg
, perm
);
1020 case VT_UNLOCKSWITCH
:
1025 #ifdef CONFIG_FB_COMPAT_XPMAC
1028 struct vc_mode mode
;
1030 i
= verify_area(VERIFY_WRITE
, (void *) arg
,
1031 sizeof(struct vc_mode
));
1033 i
= console_getmode(&mode
);
1036 if (copy_to_user((void *) arg
, &mode
, sizeof(mode
)))
1043 struct vc_mode mode
;
1047 i
= verify_area(VERIFY_READ
, (void *) arg
,
1048 sizeof(struct vc_mode
));
1051 if (copy_from_user(&mode
, (void *) arg
, sizeof(mode
)))
1053 return console_setmode(&mode
, cmd
== VC_SETMODE
);
1057 unsigned char cmap
[3][256], *p
;
1058 int n_entries
, cmap_size
, i
, j
;
1062 if (arg
== (unsigned long) VC_POWERMODE_INQUIRY
1063 || arg
<= VESA_POWERDOWN
) {
1064 /* compatibility hack: VC_POWERMODE
1065 was changed from 0x766a to 0x766c */
1066 return console_powermode((int) arg
);
1068 i
= verify_area(VERIFY_READ
, (void *) arg
,
1072 if (get_user(cmap_size
, (int *) arg
))
1076 n_entries
= cmap_size
/ 3;
1077 if ((unsigned) n_entries
> 256)
1079 p
= (unsigned char *) (arg
+ sizeof(int));
1080 for (j
= 0; j
< n_entries
; ++j
)
1081 for (i
= 0; i
< 3; ++i
)
1082 if (get_user(cmap
[i
][j
], p
++))
1084 return console_setcmap(n_entries
, cmap
[0],
1088 /* not implemented yet */
1089 return -ENOIOCTLCMD
;
1093 return console_powermode((int) arg
);
1094 #endif /* CONFIG_FB_COMPAT_XPMAC */
1096 return -ENOIOCTLCMD
;
1101 * Sometimes we want to wait until a particular VT has been activated. We
1102 * do it in a very simple manner. Everybody waits on a single queue and
1103 * get woken up at once. Those that are satisfied go on with their business,
1104 * while those not ready go back to sleep. Seems overkill to add a wait
1105 * to each vt just for this - usually this does nothing!
1107 static DECLARE_WAIT_QUEUE_HEAD(vt_activate_queue
);
1110 * Sleeps until a vt is activated, or the task is interrupted. Returns
1111 * 0 if activation, -EINTR if interrupted.
1113 int vt_waitactive(int vt
)
1116 DECLARE_WAITQUEUE(wait
, current
);
1118 add_wait_queue(&vt_activate_queue
, &wait
);
1120 set_current_state(TASK_INTERRUPTIBLE
);
1122 if (vt
== fg_console
)
1125 if (signal_pending(current
))
1129 remove_wait_queue(&vt_activate_queue
, &wait
);
1130 current
->state
= TASK_RUNNING
;
1134 #define vt_wake_waitactive() wake_up(&vt_activate_queue)
1136 void reset_vc(unsigned int new_console
)
1138 vt_cons
[new_console
]->vc_mode
= KD_TEXT
;
1139 kbd_table
[new_console
].kbdmode
= VC_XLATE
;
1140 vt_cons
[new_console
]->vt_mode
.mode
= VT_AUTO
;
1141 vt_cons
[new_console
]->vt_mode
.waitv
= 0;
1142 vt_cons
[new_console
]->vt_mode
.relsig
= 0;
1143 vt_cons
[new_console
]->vt_mode
.acqsig
= 0;
1144 vt_cons
[new_console
]->vt_mode
.frsig
= 0;
1145 vt_cons
[new_console
]->vt_pid
= -1;
1146 vt_cons
[new_console
]->vt_newvt
= -1;
1147 reset_palette (new_console
) ;
1151 * Performs the back end of a vt switch
1153 void complete_change_console(unsigned int new_console
)
1155 unsigned char old_vc_mode
;
1157 last_console
= fg_console
;
1160 * If we're switching, we could be going from KD_GRAPHICS to
1161 * KD_TEXT mode or vice versa, which means we need to blank or
1162 * unblank the screen later.
1164 old_vc_mode
= vt_cons
[fg_console
]->vc_mode
;
1165 switch_screen(new_console
);
1168 * If this new console is under process control, send it a signal
1169 * telling it that it has acquired. Also check if it has died and
1170 * clean up (similar to logic employed in change_console())
1172 if (vt_cons
[new_console
]->vt_mode
.mode
== VT_PROCESS
)
1175 * Send the signal as privileged - kill_proc() will
1176 * tell us if the process has gone or something else
1179 if (kill_proc(vt_cons
[new_console
]->vt_pid
,
1180 vt_cons
[new_console
]->vt_mode
.acqsig
,
1184 * The controlling process has died, so we revert back to
1185 * normal operation. In this case, we'll also change back
1186 * to KD_TEXT mode. I'm not sure if this is strictly correct
1187 * but it saves the agony when the X server dies and the screen
1188 * remains blanked due to KD_GRAPHICS! It would be nice to do
1189 * this outside of VT_PROCESS but there is no single process
1190 * to account for and tracking tty count may be undesirable.
1192 reset_vc(new_console
);
1197 * We do this here because the controlling process above may have
1198 * gone, and so there is now a new vc_mode
1200 if (old_vc_mode
!= vt_cons
[new_console
]->vc_mode
)
1202 if (vt_cons
[new_console
]->vc_mode
== KD_TEXT
)
1209 * Wake anyone waiting for their VT to activate
1211 vt_wake_waitactive();
1216 * Performs the front-end of a vt switch
1218 void change_console(unsigned int new_console
)
1220 if ((new_console
== fg_console
) || (vt_dont_switch
))
1222 if (!vc_cons_allocated(new_console
))
1226 * If this vt is in process mode, then we need to handshake with
1227 * that process before switching. Essentially, we store where that
1228 * vt wants to switch to and wait for it to tell us when it's done
1229 * (via VT_RELDISP ioctl).
1231 * We also check to see if the controlling process still exists.
1232 * If it doesn't, we reset this vt to auto mode and continue.
1233 * This is a cheap way to track process control. The worst thing
1234 * that can happen is: we send a signal to a process, it dies, and
1235 * the switch gets "lost" waiting for a response; hopefully, the
1236 * user will try again, we'll detect the process is gone (unless
1237 * the user waits just the right amount of time :-) and revert the
1238 * vt to auto control.
1240 if (vt_cons
[fg_console
]->vt_mode
.mode
== VT_PROCESS
)
1243 * Send the signal as privileged - kill_proc() will
1244 * tell us if the process has gone or something else
1247 if (kill_proc(vt_cons
[fg_console
]->vt_pid
,
1248 vt_cons
[fg_console
]->vt_mode
.relsig
,
1252 * It worked. Mark the vt to switch to and
1253 * return. The process needs to send us a
1254 * VT_RELDISP ioctl to complete the switch.
1256 vt_cons
[fg_console
]->vt_newvt
= new_console
;
1261 * The controlling process has died, so we revert back to
1262 * normal operation. In this case, we'll also change back
1263 * to KD_TEXT mode. I'm not sure if this is strictly correct
1264 * but it saves the agony when the X server dies and the screen
1265 * remains blanked due to KD_GRAPHICS! It would be nice to do
1266 * this outside of VT_PROCESS but there is no single process
1267 * to account for and tracking tty count may be undesirable.
1269 reset_vc(fg_console
);
1272 * Fall through to normal (VT_AUTO) handling of the switch...
1277 * Ignore all switches in KD_GRAPHICS+VT_AUTO mode
1279 if (vt_cons
[fg_console
]->vc_mode
== KD_GRAPHICS
)
1282 complete_change_console(new_console
);