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/types.h>
13 #include <linux/errno.h>
14 #include <linux/sched.h>
15 #include <linux/tty.h>
16 #include <linux/timer.h>
17 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/malloc.h>
22 #include <linux/major.h>
26 #include <asm/uaccess.h>
31 #include "selection.h"
33 char vt_dont_switch
= 0;
34 extern struct tty_driver console_driver
;
36 #define VT_IS_IN_USE(i) (console_driver.table[i] && console_driver.table[i]->count)
37 #define VT_BUSY(i) (VT_IS_IN_USE(i) || i == fg_console || i == sel_cons)
40 * Console (vt and kd) routines, as defined by USL SVR4 manual, and by
41 * experimentation and study of X386 SYSV handling.
43 * One point of difference: SYSV vt's are /dev/vtX, which X >= 0, and
44 * /dev/console is a separate ttyp. Under Linux, /dev/tty0 is /dev/console,
45 * and the vc start at /dev/ttyX, X >= 1. We maintain that here, so we will
46 * always treat our set of vt as numbered 1..MAX_NR_CONSOLES (corresponding to
47 * ttys 0..MAX_NR_CONSOLES-1). Explicitly naming VT 0 is illegal, but using
48 * /dev/tty0 (fg_console) as a target is legal, since an implicit aliasing
49 * to the current console is done by the main ioctl code.
52 struct vt_struct
*vt_cons
[MAX_NR_CONSOLES
];
55 asmlinkage
int sys_ioperm(unsigned long from
, unsigned long num
, int on
);
58 extern int getkeycode(unsigned int scancode
);
59 extern int setkeycode(unsigned int scancode
, unsigned int keycode
);
60 extern void compute_shiftstate(void);
61 extern void complete_change_console(unsigned int new_console
);
62 extern int vt_waitactive(int vt
);
63 extern void do_blank_screen(int nopowersave
);
65 extern unsigned int keymap_count
;
68 * routines to load custom translation table, EGA/VGA font and
69 * VGA colour palette from console.c
71 extern int con_set_trans_old(unsigned char * table
);
72 extern int con_get_trans_old(unsigned char * table
);
73 extern int con_set_trans_new(unsigned short * table
);
74 extern int con_get_trans_new(unsigned short * table
);
75 extern void con_clear_unimap(struct unimapinit
*ui
);
76 extern int con_set_unimap(ushort ct
, struct unipair
*list
);
77 extern int con_get_unimap(ushort ct
, ushort
*uct
, struct unipair
*list
);
78 extern void con_set_default_unimap(void);
79 extern int con_set_font(char * fontmap
, int ch512
);
80 extern int con_get_font(char * fontmap
);
81 extern int con_set_cmap(unsigned char *cmap
);
82 extern int con_get_cmap(unsigned char *cmap
);
83 extern void reset_palette(int currcons
);
84 extern void set_palette(void) ;
85 extern int con_adjust_height(unsigned long fontheight
);
87 extern int video_mode_512ch
;
88 extern unsigned long video_font_height
;
89 extern unsigned long default_font_height
;
90 extern unsigned long video_scan_lines
;
93 * these are the valid i/o ports we're allowed to change. they map all the
98 #define GPNUM (GPLAST - GPFIRST + 1)
101 * This function is called when the size of the physical screen has been
102 * changed. If either the row or col argument is nonzero, set the appropriate
103 * entry in each winsize structure for all the virtual consoles, then
104 * send SIGWINCH to all processes with a virtual console as controlling
109 kd_size_changed(int row
, int col
)
111 struct task_struct
*p
;
114 if ( !row
&& !col
) return 0;
116 for ( i
= 0 ; i
< MAX_NR_CONSOLES
; i
++ )
118 if ( console_driver
.table
[i
] )
120 if ( row
) console_driver
.table
[i
]->winsize
.ws_row
= row
;
121 if ( col
) console_driver
.table
[i
]->winsize
.ws_col
= col
;
127 if ( p
->tty
&& MAJOR(p
->tty
->device
) == TTY_MAJOR
&&
128 MINOR(p
->tty
->device
) <= MAX_NR_CONSOLES
&& MINOR(p
->tty
->device
) )
130 send_sig(SIGWINCH
, p
, 1);
138 * Generates sound of some count for some number of clock ticks
139 * [count = 1193180 / frequency]
141 * If freq is 0, will turn off sound, else will turn it on for that time.
142 * If msec is 0, will return immediately, else will sleep for msec time, then
145 * We use the BEEP_TIMER vector since we're using the same method to
146 * generate sound, and we'll overwrite any beep in progress. That may
147 * be something to fix later, if we like.
149 * We also return immediately, which is what was implied within the X
150 * comments - KDMKTONE doesn't put the process to sleep.
153 kd_nosound(unsigned long ignored
)
155 /* disable counter 2 */
156 outb(inb_p(0x61)&0xFC, 0x61);
161 _kd_mksound(unsigned int hz
, unsigned int ticks
)
163 static struct timer_list sound_timer
= { NULL
, NULL
, 0, 0,
166 unsigned int count
= 0;
168 if (hz
> 20 && hz
< 32767)
169 count
= 1193180 / hz
;
172 del_timer(&sound_timer
);
174 /* enable counter 2 */
175 outb_p(inb_p(0x61)|3, 0x61);
176 /* set command for counter 2, 2 byte write */
178 /* select desired HZ */
179 outb_p(count
& 0xff, 0x42);
180 outb((count
>> 8) & 0xff, 0x42);
183 sound_timer
.expires
= jiffies
+ticks
;
184 add_timer(&sound_timer
);
192 void (*kd_mksound
)(unsigned int hz
, unsigned int ticks
) = _kd_mksound
;
195 #define i (tmp.kb_index)
196 #define s (tmp.kb_table)
197 #define v (tmp.kb_value)
199 do_kdsk_ioctl(int cmd
, struct kbentry
*user_kbe
, int perm
, struct kbd_struct
*kbd
)
202 ushort
*key_map
, val
, ov
;
204 if (copy_from_user(&tmp
, user_kbe
, sizeof(struct kbentry
)))
206 if (i
>= NR_KEYS
|| s
>= MAX_NR_KEYMAPS
)
211 key_map
= key_maps
[s
];
214 if (kbd
->kbdmode
!= VC_UNICODE
&& KTYP(val
) >= NR_TYPES
)
217 val
= (i
? K_HOLE
: K_NOSUCHMAP
);
218 return __put_user(val
, &user_kbe
->kb_value
);
222 if (!i
&& v
== K_NOSUCHMAP
) {
223 /* disallocate map */
224 key_map
= key_maps
[s
];
227 if (key_map
[0] == U(K_ALLOCATED
)) {
228 kfree_s(key_map
, sizeof(plain_map
));
235 if (KTYP(v
) < NR_TYPES
) {
236 if (KVAL(v
) > max_vals
[KTYP(v
)])
239 if (kbd
->kbdmode
!= VC_UNICODE
)
242 /* assignment to entry 0 only tests validity of args */
246 if (!(key_map
= key_maps
[s
])) {
249 if (keymap_count
>= MAX_NR_OF_USER_KEYMAPS
&& !suser())
252 key_map
= (ushort
*) kmalloc(sizeof(plain_map
),
256 key_maps
[s
] = key_map
;
257 key_map
[0] = U(K_ALLOCATED
);
258 for (j
= 1; j
< NR_KEYS
; j
++)
259 key_map
[j
] = U(K_HOLE
);
264 break; /* nothing to do */
268 if (((ov
== K_SAK
) || (v
== K_SAK
)) && !suser())
271 if (!s
&& (KTYP(ov
) == KT_SHIFT
|| KTYP(v
) == KT_SHIFT
))
272 compute_shiftstate();
282 do_kbkeycode_ioctl(int cmd
, struct kbkeycode
*user_kbkc
, int perm
)
284 struct kbkeycode tmp
;
287 if (copy_from_user(&tmp
, user_kbkc
, sizeof(struct kbkeycode
)))
291 kc
= getkeycode(tmp
.scancode
);
293 kc
= __put_user(kc
, &user_kbkc
->keycode
);
298 kc
= setkeycode(tmp
.scancode
, tmp
.keycode
);
305 do_kdgkb_ioctl(int cmd
, struct kbsentry
*user_kdgkb
, int perm
)
312 char *first_free
, *fj
, *fnw
;
315 /* we mostly copy too much here (512bytes), but who cares ;) */
316 if (copy_from_user(&tmp
, user_kdgkb
, sizeof(struct kbsentry
)))
318 tmp
.kb_string
[sizeof(tmp
.kb_string
)-1] = '\0';
319 if (tmp
.kb_func
>= MAX_NR_FUNC
)
324 sz
= sizeof(tmp
.kb_string
) - 1; /* sz should have been
326 q
= user_kdgkb
->kb_string
;
329 for ( ; *p
&& sz
; p
++, sz
--)
332 return ((p
&& *p
) ? -EOVERFLOW
: 0);
338 first_free
= funcbufptr
+ (funcbufsize
- funcbufleft
);
339 for (j
= i
+1; j
< MAX_NR_FUNC
&& !func_table
[j
]; j
++)
346 delta
= (q
? -strlen(q
) : 1) + strlen(tmp
.kb_string
);
347 if (delta
<= funcbufleft
) { /* it fits in current buf */
348 if (j
< MAX_NR_FUNC
) {
349 memmove(fj
+ delta
, fj
, first_free
- fj
);
350 for (k
= j
; k
< MAX_NR_FUNC
; k
++)
352 func_table
[k
] += delta
;
356 funcbufleft
-= delta
;
357 } else { /* allocate a larger buffer */
359 while (sz
< funcbufsize
- funcbufleft
+ delta
)
361 fnw
= (char *) kmalloc(sz
, GFP_KERNEL
);
368 memmove(fnw
, funcbufptr
, fj
- funcbufptr
);
369 for (k
= 0; k
< j
; k
++)
371 func_table
[k
] = fnw
+ (func_table
[k
] - funcbufptr
);
373 if (first_free
> fj
) {
374 memmove(fnw
+ (fj
- funcbufptr
) + delta
, fj
, first_free
- fj
);
375 for (k
= j
; k
< MAX_NR_FUNC
; k
++)
377 func_table
[k
] = fnw
+ (func_table
[k
] - funcbufptr
) + delta
;
379 if (funcbufptr
!= func_buf
)
380 kfree_s(funcbufptr
, funcbufsize
);
382 funcbufleft
= funcbufleft
- delta
+ sz
- funcbufsize
;
385 strcpy(func_table
[i
], tmp
.kb_string
);
392 do_fontx_ioctl(int cmd
, struct consolefontdesc
*user_cfd
, int perm
)
395 struct consolefontdesc cfdarg
;
398 if (copy_from_user(&cfdarg
, user_cfd
, sizeof(struct consolefontdesc
)))
400 if (vt_cons
[fg_console
]->vc_mode
!= KD_TEXT
)
407 if ( cfdarg
.charcount
== 256 ||
408 cfdarg
.charcount
== 512 ) {
409 i
= con_set_font(cfdarg
.chardata
,
410 cfdarg
.charcount
== 512);
413 i
= con_adjust_height(cfdarg
.charheight
);
414 return (i
<= 0) ? i
: kd_size_changed(i
, 0);
418 i
= cfdarg
.charcount
;
419 cfdarg
.charcount
= nchar
= video_mode_512ch
? 512 : 256;
420 cfdarg
.charheight
= video_font_height
;
421 __copy_to_user(user_cfd
, &cfdarg
,
422 sizeof(struct consolefontdesc
));
423 if ( cfdarg
.chardata
)
427 return con_get_font(cfdarg
.chardata
);
435 do_unimap_ioctl(int cmd
, struct unimapdesc
*user_ud
,int perm
)
437 struct unimapdesc tmp
;
440 if (copy_from_user(&tmp
, user_ud
, sizeof tmp
))
443 i
= verify_area(VERIFY_WRITE
, tmp
.entries
,
444 tmp
.entry_ct
*sizeof(struct unipair
));
451 return con_set_unimap(tmp
.entry_ct
, tmp
.entries
);
453 return con_get_unimap(tmp
.entry_ct
, &(user_ud
->entry_ct
), tmp
.entries
);
459 * We handle the console-specific ioctl's here. We allow the
460 * capability to modify any console, not just the fg_console.
462 int vt_ioctl(struct tty_struct
*tty
, struct file
* file
,
463 unsigned int cmd
, unsigned long arg
)
466 unsigned int console
;
468 struct kbd_struct
* kbd
;
469 struct vt_struct
*vt
= (struct vt_struct
*)tty
->driver_data
;
471 console
= vt
->vc_num
;
473 if (!vc_cons_allocated(console
)) /* impossible? */
477 * To have permissions to do most of the vt ioctls, we either have
478 * to be the owner of the tty, or super-user.
481 if (current
->tty
== tty
|| suser())
484 kbd
= kbd_table
+ console
;
498 unsigned int ticks
, count
;
501 * Generate the tone for the appropriate number of ticks.
502 * If the time is zero, turn off sound ourselves.
504 ticks
= HZ
* ((arg
>> 16) & 0xffff) / 1000;
505 if ((arg
& 0xffff) == 0 ) arg
|= 1; /* jp: huh? */
506 count
= ticks
? (1193180 / (arg
& 0xffff)) : 0;
507 kd_mksound(count
, ticks
);
520 * These cannot be implemented on any machine that implements
521 * ioperm() in user level (such as Alpha PCs).
526 * KDADDIO and KDDELIO may be able to add ports beyond what
527 * we reject here, but to be safe...
529 if (arg
< GPFIRST
|| arg
> GPLAST
)
531 return sys_ioperm(arg
, 1, (cmd
== KDADDIO
)) ? -ENXIO
: 0;
535 return sys_ioperm(GPFIRST
, GPNUM
,
536 (cmd
== KDENABIO
)) ? -ENXIO
: 0;
541 * currently, setting the mode from KD_TEXT to KD_GRAPHICS
542 * doesn't do a whole lot. i'm not sure if it should do any
543 * restoration of modes or what...
558 if (vt_cons
[console
]->vc_mode
== (unsigned char) arg
)
560 vt_cons
[console
]->vc_mode
= (unsigned char) arg
;
561 if (console
!= fg_console
)
564 * explicitly blank/unblank the screen if switching modes
573 ucval
= vt_cons
[console
]->vc_mode
;
579 * these work like a combination of mmap and KDENABIO.
580 * this could be easily finished.
589 kbd
->kbdmode
= VC_RAW
;
592 kbd
->kbdmode
= VC_MEDIUMRAW
;
595 kbd
->kbdmode
= VC_XLATE
;
596 compute_shiftstate();
599 kbd
->kbdmode
= VC_UNICODE
;
600 compute_shiftstate();
605 if (tty
->ldisc
.flush_buffer
)
606 tty
->ldisc
.flush_buffer(tty
);
610 ucval
= ((kbd
->kbdmode
== VC_RAW
) ? K_RAW
:
611 (kbd
->kbdmode
== VC_MEDIUMRAW
) ? K_MEDIUMRAW
:
612 (kbd
->kbdmode
== VC_UNICODE
) ? K_UNICODE
:
616 /* this could be folded into KDSKBMODE, but for compatibility
617 reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */
621 clr_vc_kbd_mode(kbd
, VC_META
);
624 set_vc_kbd_mode(kbd
, VC_META
);
632 ucval
= (vc_kbd_mode(kbd
, VC_META
) ? K_ESCPREFIX
: K_METABIT
);
634 return put_user(ucval
, (int *)arg
);
638 return do_kbkeycode_ioctl(cmd
, (struct kbkeycode
*)arg
, perm
);
642 return do_kdsk_ioctl(cmd
, (struct kbentry
*)arg
, perm
, kbd
);
646 return do_kdgkb_ioctl(cmd
, (struct kbsentry
*)arg
, perm
);
650 struct kbdiacrs
*a
= (struct kbdiacrs
*)arg
;
652 i
= verify_area(VERIFY_WRITE
, (void *) a
, sizeof(struct kbdiacrs
));
655 __put_user(accent_table_size
, &a
->kb_cnt
);
656 __copy_to_user(a
->kbdiacr
, accent_table
,
657 accent_table_size
*sizeof(struct kbdiacr
));
663 struct kbdiacrs
*a
= (struct kbdiacrs
*)arg
;
668 i
= verify_area(VERIFY_READ
, (void *) a
, sizeof(struct kbdiacrs
));
671 __get_user(ct
,&a
->kb_cnt
);
674 accent_table_size
= ct
;
675 __copy_from_user(accent_table
, a
->kbdiacr
, ct
*sizeof(struct kbdiacr
));
679 /* the ioctls below read/set the flags usually shown in the leds */
680 /* don't use them - they will go away without warning */
682 ucval
= kbd
->ledflagstate
| (kbd
->default_ledflagstate
<< 4);
690 kbd
->ledflagstate
= (arg
& 7);
691 kbd
->default_ledflagstate
= ((arg
>> 4) & 7);
695 /* the ioctls below only set the lights, not the functions */
696 /* for those, see KDGKBLED and KDSKBLED above */
698 ucval
= getledstate();
700 return put_user(ucval
, (char*)arg
);
705 setledstate(kbd
, arg
);
709 * A process can indicate its willingness to accept signals
710 * generated by pressing an appropriate key combination.
711 * Thus, one can have a daemon that e.g. spawns a new console
712 * upon a keypress and then changes to it.
713 * Probably init should be changed to do this (and have a
714 * field ks (`keyboard signal') in inittab describing the
715 * desired action), so that the number of background daemons
720 extern int spawnpid
, spawnsig
;
723 if (arg
< 1 || arg
> NSIG
|| arg
== SIGKILL
)
725 spawnpid
= current
->pid
;
736 if (copy_from_user(&tmp
, (void*)arg
, sizeof(struct vt_mode
)))
738 if (tmp
.mode
!= VT_AUTO
&& tmp
.mode
!= VT_PROCESS
)
740 vt_cons
[console
]->vt_mode
= tmp
;
741 /* the frsig is ignored, so we set it to 0 */
742 vt_cons
[console
]->vt_mode
.frsig
= 0;
743 vt_cons
[console
]->vt_pid
= current
->pid
;
744 /* no switch is required -- saw@shade.msu.ru */
745 vt_cons
[console
]->vt_newvt
= -1;
750 return copy_to_user((void*)arg
, &(vt_cons
[console
]->vt_mode
),
751 sizeof(struct vt_mode
)) ? -EFAULT
: 0;
754 * Returns global vt state. Note that VT 0 is always open, since
755 * it's an alias for the current VT, and people can't use it here.
756 * We cannot return state for more than 16 VTs, since v_state is short.
760 struct vt_stat
*vtstat
= (struct vt_stat
*)arg
;
761 unsigned short state
, mask
;
763 i
= verify_area(VERIFY_WRITE
,(void *)vtstat
, sizeof(struct vt_stat
));
766 __put_user(fg_console
+ 1, &vtstat
->v_active
);
767 state
= 1; /* /dev/tty0 is always open */
768 for (i
= 0, mask
= 2; i
< MAX_NR_CONSOLES
&& mask
; ++i
, mask
<<= 1)
771 return __put_user(state
, &vtstat
->v_state
);
775 * Returns the first available (non-opened) console.
778 for (i
= 0; i
< MAX_NR_CONSOLES
; ++i
)
779 if (! VT_IS_IN_USE(i
))
781 ucval
= i
< MAX_NR_CONSOLES
? (i
+1) : -1;
785 * ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num,
786 * with num >= 1 (switches to vt 0, our console, are not allowed, just
787 * to preserve sanity).
792 if (arg
== 0 || arg
> MAX_NR_CONSOLES
)
795 i
= vc_allocate(arg
);
802 * wait until the specified VT has been activated
807 if (arg
== 0 || arg
> MAX_NR_CONSOLES
)
809 return vt_waitactive(arg
-1);
812 * If a vt is under process control, the kernel will not switch to it
813 * immediately, but postpone the operation until the process calls this
814 * ioctl, allowing the switch to complete.
816 * According to the X sources this is the behavior:
817 * 0: pending switch-from not OK
818 * 1: pending switch-from OK
819 * 2: completed switch-to OK
824 if (vt_cons
[console
]->vt_mode
.mode
!= VT_PROCESS
)
828 * Switching-from response
830 if (vt_cons
[console
]->vt_newvt
>= 0)
834 * Switch disallowed, so forget we were trying
837 vt_cons
[console
]->vt_newvt
= -1;
842 * The current vt has been released, so
843 * complete the switch.
845 int newvt
= vt_cons
[console
]->vt_newvt
;
846 vt_cons
[console
]->vt_newvt
= -1;
847 i
= vc_allocate(newvt
);
851 * When we actually do the console switch,
852 * make sure we are atomic with respect to
853 * other console switches..
856 complete_change_console(newvt
);
862 * Switched-to response
867 * If it's just an ACK, ignore it
869 if (arg
!= VT_ACKACQ
)
876 * Disallocate memory associated to VT (but leave VT1)
879 if (arg
> MAX_NR_CONSOLES
)
882 /* disallocate all unused consoles, but leave 0 */
883 for (i
=1; i
<MAX_NR_CONSOLES
; i
++)
887 /* disallocate a single console, if possible */
891 if (arg
) /* leave 0 */
898 struct vt_sizes
*vtsizes
= (struct vt_sizes
*) arg
;
902 i
= verify_area(VERIFY_READ
, (void *)vtsizes
, sizeof(struct vt_sizes
));
905 __get_user(ll
, &vtsizes
->v_rows
);
906 __get_user(cc
, &vtsizes
->v_cols
);
907 i
= vc_resize(ll
, cc
);
908 return i
? i
: kd_size_changed(ll
, cc
);
913 struct vt_consize
*vtconsize
= (struct vt_consize
*) arg
;
914 ushort ll
,cc
,vlin
,clin
,vcol
,ccol
;
917 i
= verify_area(VERIFY_READ
, (void *)vtconsize
, sizeof(struct vt_consize
));
920 __get_user(ll
, &vtconsize
->v_rows
);
921 __get_user(cc
, &vtconsize
->v_cols
);
922 __get_user(vlin
, &vtconsize
->v_vlin
);
923 __get_user(clin
, &vtconsize
->v_clin
);
924 __get_user(vcol
, &vtconsize
->v_vcol
);
925 __get_user(ccol
, &vtconsize
->v_ccol
);
926 vlin
= vlin
? vlin
: video_scan_lines
;
931 if ( ll
!= vlin
/clin
)
932 return -EINVAL
; /* Parameters don't add up */
941 if ( cc
!= vcol
/ccol
)
952 video_scan_lines
= vlin
;
954 video_font_height
= clin
;
956 i
= vc_resize(ll
, cc
);
960 kd_size_changed(ll
, cc
);
967 if (vt_cons
[fg_console
]->vc_mode
!= KD_TEXT
)
969 return con_set_font((char *)arg
, 0);
970 /* con_set_font() defined in console.c */
973 if (vt_cons
[fg_console
]->vc_mode
!= KD_TEXT
||
976 return con_get_font((char *)arg
);
977 /* con_get_font() defined in console.c */
982 return con_set_cmap((char *)arg
);
983 /* con_set_cmap() defined in console.c */
986 return con_get_cmap((char *)arg
);
987 /* con_get_cmap() defined in console.c */
991 return do_fontx_ioctl(cmd
, (struct consolefontdesc
*)arg
, perm
);
997 if (vt_cons
[fg_console
]->vc_mode
!= KD_TEXT
)
1000 #ifdef BROKEN_GRAPHICS_PROGRAMS
1001 /* With BROKEN_GRAPHICS_PROGRAMS defined, the default
1002 font is not saved. */
1006 i
= con_set_font(NULL
, 0); /* Set font to default */
1009 i
= con_adjust_height(default_font_height
);
1010 if ( i
> 0 ) kd_size_changed(i
, 0);
1011 con_set_default_unimap();
1020 return con_set_trans_old((unsigned char *)arg
);
1023 return con_get_trans_old((unsigned char *)arg
);
1025 case PIO_UNISCRNMAP
:
1028 return con_set_trans_new((unsigned short *)arg
);
1030 case GIO_UNISCRNMAP
:
1031 return con_get_trans_new((unsigned short *)arg
);
1034 { struct unimapinit ui
;
1037 i
= copy_from_user(&ui
, (void *)arg
, sizeof(struct unimapinit
));
1038 if (i
) return -EFAULT
;
1039 con_clear_unimap(&ui
);
1045 return do_unimap_ioctl(cmd
, (struct unimapdesc
*)arg
, perm
);
1052 case VT_UNLOCKSWITCH
:
1058 return -ENOIOCTLCMD
;
1063 * Sometimes we want to wait until a particular VT has been activated. We
1064 * do it in a very simple manner. Everybody waits on a single queue and
1065 * get woken up at once. Those that are satisfied go on with their business,
1066 * while those not ready go back to sleep. Seems overkill to add a wait
1067 * to each vt just for this - usually this does nothing!
1069 static struct wait_queue
*vt_activate_queue
= NULL
;
1072 * Sleeps until a vt is activated, or the task is interrupted. Returns
1073 * 0 if activation, -EINTR if interrupted.
1075 int vt_waitactive(int vt
)
1078 struct wait_queue wait
= { current
, NULL
};
1080 add_wait_queue(&vt_activate_queue
, &wait
);
1082 current
->state
= TASK_INTERRUPTIBLE
;
1084 if (vt
== fg_console
)
1087 if (current
->signal
& ~current
->blocked
)
1091 remove_wait_queue(&vt_activate_queue
, &wait
);
1092 current
->state
= TASK_RUNNING
;
1096 #define vt_wake_waitactive() wake_up(&vt_activate_queue)
1098 void reset_vc(unsigned int new_console
)
1100 vt_cons
[new_console
]->vc_mode
= KD_TEXT
;
1101 kbd_table
[new_console
].kbdmode
= VC_XLATE
;
1102 vt_cons
[new_console
]->vt_mode
.mode
= VT_AUTO
;
1103 vt_cons
[new_console
]->vt_mode
.waitv
= 0;
1104 vt_cons
[new_console
]->vt_mode
.relsig
= 0;
1105 vt_cons
[new_console
]->vt_mode
.acqsig
= 0;
1106 vt_cons
[new_console
]->vt_mode
.frsig
= 0;
1107 vt_cons
[new_console
]->vt_pid
= -1;
1108 vt_cons
[new_console
]->vt_newvt
= -1;
1109 reset_palette (new_console
) ;
1113 * Performs the back end of a vt switch
1115 void complete_change_console(unsigned int new_console
)
1117 unsigned char old_vc_mode
;
1119 if ((new_console
== fg_console
) || (vt_dont_switch
))
1121 if (!vc_cons_allocated(new_console
))
1123 last_console
= fg_console
;
1126 * If we're switching, we could be going from KD_GRAPHICS to
1127 * KD_TEXT mode or vice versa, which means we need to blank or
1128 * unblank the screen later.
1130 old_vc_mode
= vt_cons
[fg_console
]->vc_mode
;
1131 update_screen(new_console
);
1134 * If this new console is under process control, send it a signal
1135 * telling it that it has acquired. Also check if it has died and
1136 * clean up (similar to logic employed in change_console())
1138 if (vt_cons
[new_console
]->vt_mode
.mode
== VT_PROCESS
)
1141 * Send the signal as privileged - kill_proc() will
1142 * tell us if the process has gone or something else
1145 if (kill_proc(vt_cons
[new_console
]->vt_pid
,
1146 vt_cons
[new_console
]->vt_mode
.acqsig
,
1150 * The controlling process has died, so we revert back to
1151 * normal operation. In this case, we'll also change back
1152 * to KD_TEXT mode. I'm not sure if this is strictly correct
1153 * but it saves the agony when the X server dies and the screen
1154 * remains blanked due to KD_GRAPHICS! It would be nice to do
1155 * this outside of VT_PROCESS but there is no single process
1156 * to account for and tracking tty count may be undesirable.
1158 reset_vc(new_console
);
1163 * We do this here because the controlling process above may have
1164 * gone, and so there is now a new vc_mode
1166 if (old_vc_mode
!= vt_cons
[new_console
]->vc_mode
)
1168 if (vt_cons
[new_console
]->vc_mode
== KD_TEXT
)
1169 do_unblank_screen();
1174 /* Set the colour palette for this VT */
1175 if (vt_cons
[new_console
]->vc_mode
== KD_TEXT
)
1178 #ifdef CONFIG_SUN_CONSOLE
1179 if (old_vc_mode
!= vt_cons
[new_console
]->vc_mode
)
1181 extern void set_cursor(int currcons
);
1182 extern void hide_cursor(void);
1184 if (old_vc_mode
== KD_GRAPHICS
)
1186 extern void sun_clear_margin(void);
1187 extern void render_screen(void);
1191 set_cursor(fg_console
);
1198 * Wake anyone waiting for their VT to activate
1200 vt_wake_waitactive();
1205 * Performs the front-end of a vt switch
1207 void change_console(unsigned int new_console
)
1209 if ((new_console
== fg_console
) || (vt_dont_switch
))
1211 if (!vc_cons_allocated(new_console
))
1215 * If this vt is in process mode, then we need to handshake with
1216 * that process before switching. Essentially, we store where that
1217 * vt wants to switch to and wait for it to tell us when it's done
1218 * (via VT_RELDISP ioctl).
1220 * We also check to see if the controlling process still exists.
1221 * If it doesn't, we reset this vt to auto mode and continue.
1222 * This is a cheap way to track process control. The worst thing
1223 * that can happen is: we send a signal to a process, it dies, and
1224 * the switch gets "lost" waiting for a response; hopefully, the
1225 * user will try again, we'll detect the process is gone (unless
1226 * the user waits just the right amount of time :-) and revert the
1227 * vt to auto control.
1229 if (vt_cons
[fg_console
]->vt_mode
.mode
== VT_PROCESS
)
1232 * Send the signal as privileged - kill_proc() will
1233 * tell us if the process has gone or something else
1236 if (kill_proc(vt_cons
[fg_console
]->vt_pid
,
1237 vt_cons
[fg_console
]->vt_mode
.relsig
,
1241 * It worked. Mark the vt to switch to and
1242 * return. The process needs to send us a
1243 * VT_RELDISP ioctl to complete the switch.
1245 vt_cons
[fg_console
]->vt_newvt
= new_console
;
1250 * The controlling process has died, so we revert back to
1251 * normal operation. In this case, we'll also change back
1252 * to KD_TEXT mode. I'm not sure if this is strictly correct
1253 * but it saves the agony when the X server dies and the screen
1254 * remains blanked due to KD_GRAPHICS! It would be nice to do
1255 * this outside of VT_PROCESS but there is no single process
1256 * to account for and tracking tty count may be undesirable.
1258 reset_vc(fg_console
);
1261 * Fall through to normal (VT_AUTO) handling of the switch...
1266 * Ignore all switches in KD_GRAPHICS+VT_AUTO mode
1268 if (vt_cons
[fg_console
]->vc_mode
== KD_GRAPHICS
)
1271 complete_change_console(new_console
);