Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Copyright (C) 1992 obz under the linux copyright |
| 3 | * |
| 4 | * Dynamic diacritical handling - aeb@cwi.nl - Dec 1993 |
| 5 | * Dynamic keymap and string allocation - aeb@cwi.nl - May 1994 |
| 6 | * Restrict VT switching via ioctl() - grif@cs.ucr.edu - Dec 1995 |
| 7 | * Some code moved for less code duplication - Andi Kleen - Mar 1997 |
| 8 | * Check put/get_user, cleanups - acme@conectiva.com.br - Jun 2001 |
| 9 | */ |
| 10 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/types.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/sched.h> |
| 14 | #include <linux/tty.h> |
| 15 | #include <linux/timer.h> |
| 16 | #include <linux/kernel.h> |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 17 | #include <linux/compat.h> |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 18 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/kd.h> |
| 20 | #include <linux/vt.h> |
| 21 | #include <linux/string.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/major.h> |
| 24 | #include <linux/fs.h> |
| 25 | #include <linux/console.h> |
Samuel Thibault | 04c7197 | 2007-10-16 23:27:04 -0700 | [diff] [blame] | 26 | #include <linux/consolemap.h> |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 27 | #include <linux/signal.h> |
Emmanuel Colbus | bcc8ca0 | 2005-06-28 20:44:49 -0700 | [diff] [blame] | 28 | #include <linux/timex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #include <asm/io.h> |
| 31 | #include <asm/uaccess.h> |
| 32 | |
| 33 | #include <linux/kbd_kern.h> |
| 34 | #include <linux/vt_kern.h> |
| 35 | #include <linux/kbd_diacr.h> |
| 36 | #include <linux/selection.h> |
| 37 | |
Andrew Johnson | b257bc0 | 2007-03-16 13:38:24 -0800 | [diff] [blame] | 38 | char vt_dont_switch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | extern struct tty_driver *console_driver; |
| 40 | |
| 41 | #define VT_IS_IN_USE(i) (console_driver->ttys[i] && console_driver->ttys[i]->count) |
| 42 | #define VT_BUSY(i) (VT_IS_IN_USE(i) || i == fg_console || vc_cons[i].d == sel_cons) |
| 43 | |
| 44 | /* |
| 45 | * Console (vt and kd) routines, as defined by USL SVR4 manual, and by |
| 46 | * experimentation and study of X386 SYSV handling. |
| 47 | * |
| 48 | * One point of difference: SYSV vt's are /dev/vtX, which X >= 0, and |
| 49 | * /dev/console is a separate ttyp. Under Linux, /dev/tty0 is /dev/console, |
| 50 | * and the vc start at /dev/ttyX, X >= 1. We maintain that here, so we will |
| 51 | * always treat our set of vt as numbered 1..MAX_NR_CONSOLES (corresponding to |
| 52 | * ttys 0..MAX_NR_CONSOLES-1). Explicitly naming VT 0 is illegal, but using |
| 53 | * /dev/tty0 (fg_console) as a target is legal, since an implicit aliasing |
| 54 | * to the current console is done by the main ioctl code. |
| 55 | */ |
| 56 | |
| 57 | #ifdef CONFIG_X86 |
| 58 | #include <linux/syscalls.h> |
| 59 | #endif |
| 60 | |
| 61 | static void complete_change_console(struct vc_data *vc); |
| 62 | |
| 63 | /* |
Alan Cox | 8b92e87 | 2009-09-19 13:13:24 -0700 | [diff] [blame] | 64 | * User space VT_EVENT handlers |
| 65 | */ |
| 66 | |
| 67 | struct vt_event_wait { |
| 68 | struct list_head list; |
| 69 | struct vt_event event; |
| 70 | int done; |
| 71 | }; |
| 72 | |
| 73 | static LIST_HEAD(vt_events); |
| 74 | static DEFINE_SPINLOCK(vt_event_lock); |
| 75 | static DECLARE_WAIT_QUEUE_HEAD(vt_event_waitqueue); |
| 76 | |
| 77 | /** |
| 78 | * vt_event_post |
| 79 | * @event: the event that occurred |
| 80 | * @old: old console |
| 81 | * @new: new console |
| 82 | * |
| 83 | * Post an VT event to interested VT handlers |
| 84 | */ |
| 85 | |
| 86 | void vt_event_post(unsigned int event, unsigned int old, unsigned int new) |
| 87 | { |
| 88 | struct list_head *pos, *head; |
| 89 | unsigned long flags; |
| 90 | int wake = 0; |
| 91 | |
| 92 | spin_lock_irqsave(&vt_event_lock, flags); |
| 93 | head = &vt_events; |
| 94 | |
| 95 | list_for_each(pos, head) { |
| 96 | struct vt_event_wait *ve = list_entry(pos, |
| 97 | struct vt_event_wait, list); |
| 98 | if (!(ve->event.event & event)) |
| 99 | continue; |
| 100 | ve->event.event = event; |
| 101 | /* kernel view is consoles 0..n-1, user space view is |
| 102 | console 1..n with 0 meaning current, so we must bias */ |
Alan Cox | 308efab | 2009-11-19 13:30:36 +0000 | [diff] [blame] | 103 | ve->event.oldev = old + 1; |
| 104 | ve->event.newev = new + 1; |
Alan Cox | 8b92e87 | 2009-09-19 13:13:24 -0700 | [diff] [blame] | 105 | wake = 1; |
| 106 | ve->done = 1; |
| 107 | } |
| 108 | spin_unlock_irqrestore(&vt_event_lock, flags); |
| 109 | if (wake) |
| 110 | wake_up_interruptible(&vt_event_waitqueue); |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * vt_event_wait - wait for an event |
| 115 | * @vw: our event |
| 116 | * |
| 117 | * Waits for an event to occur which completes our vt_event_wait |
| 118 | * structure. On return the structure has wv->done set to 1 for success |
| 119 | * or 0 if some event such as a signal ended the wait. |
| 120 | */ |
| 121 | |
| 122 | static void vt_event_wait(struct vt_event_wait *vw) |
| 123 | { |
| 124 | unsigned long flags; |
| 125 | /* Prepare the event */ |
| 126 | INIT_LIST_HEAD(&vw->list); |
| 127 | vw->done = 0; |
| 128 | /* Queue our event */ |
| 129 | spin_lock_irqsave(&vt_event_lock, flags); |
| 130 | list_add(&vw->list, &vt_events); |
| 131 | spin_unlock_irqrestore(&vt_event_lock, flags); |
| 132 | /* Wait for it to pass */ |
Arnd Bergmann | be1bc28 | 2010-06-01 22:53:05 +0200 | [diff] [blame] | 133 | wait_event_interruptible_tty(vt_event_waitqueue, vw->done); |
Alan Cox | 8b92e87 | 2009-09-19 13:13:24 -0700 | [diff] [blame] | 134 | /* Dequeue it */ |
| 135 | spin_lock_irqsave(&vt_event_lock, flags); |
| 136 | list_del(&vw->list); |
| 137 | spin_unlock_irqrestore(&vt_event_lock, flags); |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * vt_event_wait_ioctl - event ioctl handler |
| 142 | * @arg: argument to ioctl |
| 143 | * |
| 144 | * Implement the VT_WAITEVENT ioctl using the VT event interface |
| 145 | */ |
| 146 | |
| 147 | static int vt_event_wait_ioctl(struct vt_event __user *event) |
| 148 | { |
| 149 | struct vt_event_wait vw; |
| 150 | |
| 151 | if (copy_from_user(&vw.event, event, sizeof(struct vt_event))) |
| 152 | return -EFAULT; |
| 153 | /* Highest supported event for now */ |
| 154 | if (vw.event.event & ~VT_MAX_EVENT) |
| 155 | return -EINVAL; |
| 156 | |
| 157 | vt_event_wait(&vw); |
| 158 | /* If it occurred report it */ |
| 159 | if (vw.done) { |
| 160 | if (copy_to_user(event, &vw.event, sizeof(struct vt_event))) |
| 161 | return -EFAULT; |
| 162 | return 0; |
| 163 | } |
| 164 | return -EINTR; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * vt_waitactive - active console wait |
| 169 | * @event: event code |
| 170 | * @n: new console |
| 171 | * |
| 172 | * Helper for event waits. Used to implement the legacy |
| 173 | * event waiting ioctls in terms of events |
| 174 | */ |
| 175 | |
| 176 | int vt_waitactive(int n) |
| 177 | { |
| 178 | struct vt_event_wait vw; |
| 179 | do { |
| 180 | if (n == fg_console + 1) |
| 181 | break; |
| 182 | vw.event.event = VT_EVENT_SWITCH; |
| 183 | vt_event_wait(&vw); |
| 184 | if (vw.done == 0) |
| 185 | return -EINTR; |
Alan Cox | 308efab | 2009-11-19 13:30:36 +0000 | [diff] [blame] | 186 | } while (vw.event.newev != n); |
Alan Cox | 8b92e87 | 2009-09-19 13:13:24 -0700 | [diff] [blame] | 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | * these are the valid i/o ports we're allowed to change. they map all the |
| 192 | * video ports |
| 193 | */ |
| 194 | #define GPFIRST 0x3b4 |
| 195 | #define GPLAST 0x3df |
| 196 | #define GPNUM (GPLAST - GPFIRST + 1) |
| 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | static inline int |
| 201 | do_fontx_ioctl(int cmd, struct consolefontdesc __user *user_cfd, int perm, struct console_font_op *op) |
| 202 | { |
| 203 | struct consolefontdesc cfdarg; |
| 204 | int i; |
| 205 | |
| 206 | if (copy_from_user(&cfdarg, user_cfd, sizeof(struct consolefontdesc))) |
| 207 | return -EFAULT; |
| 208 | |
| 209 | switch (cmd) { |
| 210 | case PIO_FONTX: |
| 211 | if (!perm) |
| 212 | return -EPERM; |
| 213 | op->op = KD_FONT_OP_SET; |
| 214 | op->flags = KD_FONT_FLAG_OLD; |
| 215 | op->width = 8; |
| 216 | op->height = cfdarg.charheight; |
| 217 | op->charcount = cfdarg.charcount; |
| 218 | op->data = cfdarg.chardata; |
| 219 | return con_font_op(vc_cons[fg_console].d, op); |
| 220 | case GIO_FONTX: { |
| 221 | op->op = KD_FONT_OP_GET; |
| 222 | op->flags = KD_FONT_FLAG_OLD; |
| 223 | op->width = 8; |
| 224 | op->height = cfdarg.charheight; |
| 225 | op->charcount = cfdarg.charcount; |
| 226 | op->data = cfdarg.chardata; |
| 227 | i = con_font_op(vc_cons[fg_console].d, op); |
| 228 | if (i) |
| 229 | return i; |
| 230 | cfdarg.charheight = op->height; |
| 231 | cfdarg.charcount = op->charcount; |
| 232 | if (copy_to_user(user_cfd, &cfdarg, sizeof(struct consolefontdesc))) |
| 233 | return -EFAULT; |
| 234 | return 0; |
| 235 | } |
| 236 | } |
| 237 | return -EINVAL; |
| 238 | } |
| 239 | |
| 240 | static inline int |
| 241 | do_unimap_ioctl(int cmd, struct unimapdesc __user *user_ud, int perm, struct vc_data *vc) |
| 242 | { |
| 243 | struct unimapdesc tmp; |
| 244 | |
| 245 | if (copy_from_user(&tmp, user_ud, sizeof tmp)) |
| 246 | return -EFAULT; |
| 247 | if (tmp.entries) |
| 248 | if (!access_ok(VERIFY_WRITE, tmp.entries, |
| 249 | tmp.entry_ct*sizeof(struct unipair))) |
| 250 | return -EFAULT; |
| 251 | switch (cmd) { |
| 252 | case PIO_UNIMAP: |
| 253 | if (!perm) |
| 254 | return -EPERM; |
| 255 | return con_set_unimap(vc, tmp.entry_ct, tmp.entries); |
| 256 | case GIO_UNIMAP: |
| 257 | if (!perm && fg_console != vc->vc_num) |
| 258 | return -EPERM; |
| 259 | return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct), tmp.entries); |
| 260 | } |
| 261 | return 0; |
| 262 | } |
| 263 | |
Alan Cox | 8b92e87 | 2009-09-19 13:13:24 -0700 | [diff] [blame] | 264 | |
| 265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | /* |
| 267 | * We handle the console-specific ioctl's here. We allow the |
| 268 | * capability to modify any console, not just the fg_console. |
| 269 | */ |
Alan Cox | 6caa76b | 2011-02-14 16:27:22 +0000 | [diff] [blame] | 270 | int vt_ioctl(struct tty_struct *tty, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | unsigned int cmd, unsigned long arg) |
| 272 | { |
Alan Cox | c9f19e9 | 2009-01-02 13:47:26 +0000 | [diff] [blame] | 273 | struct vc_data *vc = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | struct console_font_op op; /* used in multiple places here */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | unsigned int console; |
| 276 | unsigned char ucval; |
Graham Gower | 1e0ad28 | 2010-10-27 15:33:00 -0700 | [diff] [blame] | 277 | unsigned int uival; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | void __user *up = (void __user *)arg; |
| 279 | int i, perm; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 280 | int ret = 0; |
| 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | console = vc->vc_num; |
| 283 | |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 284 | |
| 285 | if (!vc_cons_allocated(console)) { /* impossible? */ |
| 286 | ret = -ENOIOCTLCMD; |
| 287 | goto out; |
| 288 | } |
| 289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | /* |
| 292 | * To have permissions to do most of the vt ioctls, we either have |
| 293 | * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG. |
| 294 | */ |
| 295 | perm = 0; |
| 296 | if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG)) |
| 297 | perm = 1; |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | switch (cmd) { |
Alan Cox | e688510 | 2008-10-13 10:36:40 +0100 | [diff] [blame] | 300 | case TIOCLINUX: |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 301 | tty_lock(); |
Jiri Slaby | a115902 | 2009-06-22 18:42:18 +0100 | [diff] [blame] | 302 | ret = tioclinux(tty, arg); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 303 | tty_unlock(); |
Jiri Slaby | a115902 | 2009-06-22 18:42:18 +0100 | [diff] [blame] | 304 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | case KIOCSOUND: |
| 306 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 307 | return -EPERM; |
Arnd Bergmann | 2c4e967 | 2010-08-28 20:35:17 -0700 | [diff] [blame] | 308 | /* |
| 309 | * The use of PIT_TICK_RATE is historic, it used to be |
| 310 | * the platform-dependent CLOCK_TICK_RATE between 2.6.12 |
| 311 | * and 2.6.36, which was a minor but unfortunate ABI |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 312 | * change. kd_mksound is locked by the input layer. |
Arnd Bergmann | 2c4e967 | 2010-08-28 20:35:17 -0700 | [diff] [blame] | 313 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | if (arg) |
Arnd Bergmann | 2c4e967 | 2010-08-28 20:35:17 -0700 | [diff] [blame] | 315 | arg = PIT_TICK_RATE / arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | kd_mksound(arg, 0); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 317 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | case KDMKTONE: |
| 320 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 321 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | unsigned int ticks, count; |
| 324 | |
| 325 | /* |
| 326 | * Generate the tone for the appropriate number of ticks. |
| 327 | * If the time is zero, turn off sound ourselves. |
| 328 | */ |
| 329 | ticks = HZ * ((arg >> 16) & 0xffff) / 1000; |
| 330 | count = ticks ? (arg & 0xffff) : 0; |
| 331 | if (count) |
Arnd Bergmann | 2c4e967 | 2010-08-28 20:35:17 -0700 | [diff] [blame] | 332 | count = PIT_TICK_RATE / count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | kd_mksound(count, ticks); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 334 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | case KDGKBTYPE: |
| 338 | /* |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 339 | * this is naïve. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | */ |
| 341 | ucval = KB_101; |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 342 | ret = put_user(ucval, (char __user *)arg); |
| 343 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | |
| 345 | /* |
| 346 | * These cannot be implemented on any machine that implements |
| 347 | * ioperm() in user level (such as Alpha PCs) or not at all. |
| 348 | * |
| 349 | * XXX: you should never use these, just call ioperm directly.. |
| 350 | */ |
| 351 | #ifdef CONFIG_X86 |
| 352 | case KDADDIO: |
| 353 | case KDDELIO: |
| 354 | /* |
| 355 | * KDADDIO and KDDELIO may be able to add ports beyond what |
| 356 | * we reject here, but to be safe... |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 357 | * |
| 358 | * These are locked internally via sys_ioperm |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | */ |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 360 | if (arg < GPFIRST || arg > GPLAST) { |
| 361 | ret = -EINVAL; |
| 362 | break; |
| 363 | } |
| 364 | ret = sys_ioperm(arg, 1, (cmd == KDADDIO)) ? -ENXIO : 0; |
| 365 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | case KDENABIO: |
| 368 | case KDDISABIO: |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 369 | ret = sys_ioperm(GPFIRST, GPNUM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | (cmd == KDENABIO)) ? -ENXIO : 0; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 371 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | #endif |
| 373 | |
| 374 | /* Linux m68k/i386 interface for setting the keyboard delay/repeat rate */ |
| 375 | |
| 376 | case KDKBDREP: |
| 377 | { |
| 378 | struct kbd_repeat kbrep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
| 380 | if (!capable(CAP_SYS_TTY_CONFIG)) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 381 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 383 | if (copy_from_user(&kbrep, up, sizeof(struct kbd_repeat))) { |
| 384 | ret = -EFAULT; |
| 385 | break; |
| 386 | } |
| 387 | ret = kbd_rate(&kbrep); |
| 388 | if (ret) |
| 389 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | if (copy_to_user(up, &kbrep, sizeof(struct kbd_repeat))) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 391 | ret = -EFAULT; |
| 392 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | case KDSETMODE: |
| 396 | /* |
| 397 | * currently, setting the mode from KD_TEXT to KD_GRAPHICS |
| 398 | * doesn't do a whole lot. i'm not sure if it should do any |
| 399 | * restoration of modes or what... |
| 400 | * |
| 401 | * XXX It should at least call into the driver, fbdev's definitely |
| 402 | * need to restore their engine state. --BenH |
| 403 | */ |
| 404 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 405 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | switch (arg) { |
| 407 | case KD_GRAPHICS: |
| 408 | break; |
| 409 | case KD_TEXT0: |
| 410 | case KD_TEXT1: |
| 411 | arg = KD_TEXT; |
| 412 | case KD_TEXT: |
| 413 | break; |
| 414 | default: |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 415 | ret = -EINVAL; |
| 416 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 418 | /* FIXME: this needs the console lock extending */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | if (vc->vc_mode == (unsigned char) arg) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 420 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | vc->vc_mode = (unsigned char) arg; |
| 422 | if (console != fg_console) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 423 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | /* |
| 425 | * explicitly blank/unblank the screen if switching modes |
| 426 | */ |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 427 | console_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | if (arg == KD_TEXT) |
| 429 | do_unblank_screen(1); |
| 430 | else |
| 431 | do_blank_screen(1); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 432 | console_unlock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 433 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | case KDGETMODE: |
Graham Gower | 1e0ad28 | 2010-10-27 15:33:00 -0700 | [diff] [blame] | 436 | uival = vc->vc_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | goto setint; |
| 438 | |
| 439 | case KDMAPDISP: |
| 440 | case KDUNMAPDISP: |
| 441 | /* |
| 442 | * these work like a combination of mmap and KDENABIO. |
| 443 | * this could be easily finished. |
| 444 | */ |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 445 | ret = -EINVAL; |
| 446 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | |
| 448 | case KDSKBMODE: |
| 449 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 450 | return -EPERM; |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 451 | ret = vt_do_kdskbmode(console, arg); |
| 452 | if (ret == 0) |
| 453 | tty_ldisc_flush(tty); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 454 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
| 456 | case KDGKBMODE: |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 457 | uival = vt_do_kdgkbmode(console); |
| 458 | ret = put_user(uival, (int __user *)arg); |
| 459 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | /* this could be folded into KDSKBMODE, but for compatibility |
| 462 | reasons it is not so easy to fold KDGKBMETA into KDGKBMODE */ |
| 463 | case KDSKBMETA: |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 464 | ret = vt_do_kdskbmeta(console, arg); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 465 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | case KDGKBMETA: |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 468 | /* FIXME: should review whether this is worth locking */ |
| 469 | uival = vt_do_kdgkbmeta(console); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | setint: |
Graham Gower | 1e0ad28 | 2010-10-27 15:33:00 -0700 | [diff] [blame] | 471 | ret = put_user(uival, (int __user *)arg); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 472 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | case KDGETKEYCODE: |
| 475 | case KDSETKEYCODE: |
| 476 | if(!capable(CAP_SYS_TTY_CONFIG)) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 477 | perm = 0; |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 478 | ret = vt_do_kbkeycode_ioctl(cmd, up, perm); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 479 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
| 481 | case KDGKBENT: |
| 482 | case KDSKBENT: |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 483 | ret = vt_do_kdsk_ioctl(cmd, up, perm, console); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 484 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
| 486 | case KDGKBSENT: |
| 487 | case KDSKBSENT: |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 488 | ret = vt_do_kdgkb_ioctl(cmd, up, perm); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 489 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | |
Alan Cox | 247ff8e | 2012-02-24 12:47:11 +0000 | [diff] [blame] | 491 | /* Diacritical processing. Handled in keyboard.c as it has |
| 492 | to operate on the keyboard locks and structures */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | case KDGKBDIACR: |
Samuel Thibault | 04c7197 | 2007-10-16 23:27:04 -0700 | [diff] [blame] | 494 | case KDGKBDIACRUC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | case KDSKBDIACR: |
Samuel Thibault | 04c7197 | 2007-10-16 23:27:04 -0700 | [diff] [blame] | 496 | case KDSKBDIACRUC: |
Alan Cox | 247ff8e | 2012-02-24 12:47:11 +0000 | [diff] [blame] | 497 | ret = vt_do_diacrit(cmd, up, perm); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 498 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | /* the ioctls below read/set the flags usually shown in the leds */ |
| 501 | /* don't use them - they will go away without warning */ |
| 502 | case KDGKBLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | case KDSKBLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | case KDGETLED: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | case KDSETLED: |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 506 | ret = vt_do_kdskled(console, cmd, arg, perm); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 507 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | /* |
| 510 | * A process can indicate its willingness to accept signals |
| 511 | * generated by pressing an appropriate key combination. |
| 512 | * Thus, one can have a daemon that e.g. spawns a new console |
| 513 | * upon a keypress and then changes to it. |
| 514 | * See also the kbrequest field of inittab(5). |
| 515 | */ |
| 516 | case KDSIGACCEPT: |
| 517 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (!perm || !capable(CAP_KILL)) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 519 | return -EPERM; |
Jesper Juhl | 7ed20e1 | 2005-05-01 08:59:14 -0700 | [diff] [blame] | 520 | if (!valid_signal(arg) || arg < 1 || arg == SIGKILL) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 521 | ret = -EINVAL; |
| 522 | else { |
| 523 | spin_lock_irq(&vt_spawn_con.lock); |
| 524 | put_pid(vt_spawn_con.pid); |
| 525 | vt_spawn_con.pid = get_pid(task_pid(current)); |
| 526 | vt_spawn_con.sig = arg; |
| 527 | spin_unlock_irq(&vt_spawn_con.lock); |
| 528 | } |
| 529 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | case VT_SETMODE: |
| 533 | { |
| 534 | struct vt_mode tmp; |
| 535 | |
| 536 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 537 | return -EPERM; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 538 | if (copy_from_user(&tmp, up, sizeof(struct vt_mode))) { |
| 539 | ret = -EFAULT; |
| 540 | goto out; |
| 541 | } |
Greg Kroah-Hartman | 87a6aca | 2010-03-15 17:14:15 -0700 | [diff] [blame] | 542 | if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) { |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 543 | ret = -EINVAL; |
| 544 | goto out; |
| 545 | } |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 546 | console_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | vc->vt_mode = tmp; |
| 548 | /* the frsig is ignored, so we set it to 0 */ |
| 549 | vc->vt_mode.frsig = 0; |
Eric W. Biederman | 8b6312f | 2007-02-10 01:44:34 -0800 | [diff] [blame] | 550 | put_pid(vc->vt_pid); |
| 551 | vc->vt_pid = get_pid(task_pid(current)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | /* no switch is required -- saw@shade.msu.ru */ |
| 553 | vc->vt_newvt = -1; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 554 | console_unlock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 555 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | case VT_GETMODE: |
| 559 | { |
| 560 | struct vt_mode tmp; |
| 561 | int rc; |
| 562 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 563 | console_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | memcpy(&tmp, &vc->vt_mode, sizeof(struct vt_mode)); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 565 | console_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
| 567 | rc = copy_to_user(up, &tmp, sizeof(struct vt_mode)); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 568 | if (rc) |
| 569 | ret = -EFAULT; |
| 570 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /* |
| 574 | * Returns global vt state. Note that VT 0 is always open, since |
| 575 | * it's an alias for the current VT, and people can't use it here. |
| 576 | * We cannot return state for more than 16 VTs, since v_state is short. |
| 577 | */ |
| 578 | case VT_GETSTATE: |
| 579 | { |
| 580 | struct vt_stat __user *vtstat = up; |
| 581 | unsigned short state, mask; |
| 582 | |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 583 | /* Review: FIXME: Console lock ? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | if (put_user(fg_console + 1, &vtstat->v_active)) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 585 | ret = -EFAULT; |
| 586 | else { |
| 587 | state = 1; /* /dev/tty0 is always open */ |
| 588 | for (i = 0, mask = 2; i < MAX_NR_CONSOLES && mask; |
| 589 | ++i, mask <<= 1) |
| 590 | if (VT_IS_IN_USE(i)) |
| 591 | state |= mask; |
| 592 | ret = put_user(state, &vtstat->v_state); |
| 593 | } |
| 594 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /* |
| 598 | * Returns the first available (non-opened) console. |
| 599 | */ |
| 600 | case VT_OPENQRY: |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 601 | /* FIXME: locking ? - but then this is a stupid API */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | for (i = 0; i < MAX_NR_CONSOLES; ++i) |
| 603 | if (! VT_IS_IN_USE(i)) |
| 604 | break; |
Graham Gower | 1e0ad28 | 2010-10-27 15:33:00 -0700 | [diff] [blame] | 605 | uival = i < MAX_NR_CONSOLES ? (i+1) : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | goto setint; |
| 607 | |
| 608 | /* |
| 609 | * ioctl(fd, VT_ACTIVATE, num) will cause us to switch to vt # num, |
| 610 | * with num >= 1 (switches to vt 0, our console, are not allowed, just |
| 611 | * to preserve sanity). |
| 612 | */ |
| 613 | case VT_ACTIVATE: |
| 614 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 615 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | if (arg == 0 || arg > MAX_NR_CONSOLES) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 617 | ret = -ENXIO; |
| 618 | else { |
| 619 | arg--; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 620 | console_lock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 621 | ret = vc_allocate(arg); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 622 | console_unlock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 623 | if (ret) |
| 624 | break; |
| 625 | set_console(arg); |
| 626 | } |
| 627 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | |
Alan Cox | d3b5cff | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 629 | case VT_SETACTIVATE: |
| 630 | { |
| 631 | struct vt_setactivate vsa; |
| 632 | |
| 633 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 634 | return -EPERM; |
Alan Cox | d3b5cff | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 635 | |
| 636 | if (copy_from_user(&vsa, (struct vt_setactivate __user *)arg, |
Jiri Slaby | a09efb0 | 2009-10-01 15:43:59 -0700 | [diff] [blame] | 637 | sizeof(struct vt_setactivate))) { |
| 638 | ret = -EFAULT; |
| 639 | goto out; |
| 640 | } |
Alan Cox | d3b5cff | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 641 | if (vsa.console == 0 || vsa.console > MAX_NR_CONSOLES) |
| 642 | ret = -ENXIO; |
| 643 | else { |
| 644 | vsa.console--; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 645 | console_lock(); |
Alan Cox | d3b5cff | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 646 | ret = vc_allocate(vsa.console); |
| 647 | if (ret == 0) { |
| 648 | struct vc_data *nvc; |
| 649 | /* This is safe providing we don't drop the |
| 650 | console sem between vc_allocate and |
| 651 | finishing referencing nvc */ |
| 652 | nvc = vc_cons[vsa.console].d; |
| 653 | nvc->vt_mode = vsa.mode; |
| 654 | nvc->vt_mode.frsig = 0; |
| 655 | put_pid(nvc->vt_pid); |
| 656 | nvc->vt_pid = get_pid(task_pid(current)); |
| 657 | } |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 658 | console_unlock(); |
Alan Cox | d3b5cff | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 659 | if (ret) |
| 660 | break; |
| 661 | /* Commence switch and lock */ |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 662 | /* Review set_console locks */ |
Jiri Olsa | d637837 | 2011-02-11 15:39:28 +0100 | [diff] [blame] | 663 | set_console(vsa.console); |
Alan Cox | d3b5cff | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 664 | } |
Jiri Olsa | d637837 | 2011-02-11 15:39:28 +0100 | [diff] [blame] | 665 | break; |
Alan Cox | d3b5cff | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | /* |
| 669 | * wait until the specified VT has been activated |
| 670 | */ |
| 671 | case VT_WAITACTIVE: |
| 672 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 673 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | if (arg == 0 || arg > MAX_NR_CONSOLES) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 675 | ret = -ENXIO; |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 676 | else { |
| 677 | tty_lock(); |
Alan Cox | 8b92e87 | 2009-09-19 13:13:24 -0700 | [diff] [blame] | 678 | ret = vt_waitactive(arg); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 679 | tty_unlock(); |
| 680 | } |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 681 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
| 683 | /* |
| 684 | * If a vt is under process control, the kernel will not switch to it |
| 685 | * immediately, but postpone the operation until the process calls this |
| 686 | * ioctl, allowing the switch to complete. |
| 687 | * |
| 688 | * According to the X sources this is the behavior: |
| 689 | * 0: pending switch-from not OK |
| 690 | * 1: pending switch-from OK |
| 691 | * 2: completed switch-to OK |
| 692 | */ |
| 693 | case VT_RELDISP: |
| 694 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 695 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 697 | console_lock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 698 | if (vc->vt_mode.mode != VT_PROCESS) { |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 699 | console_unlock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 700 | ret = -EINVAL; |
| 701 | break; |
| 702 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | /* |
| 704 | * Switching-from response |
| 705 | */ |
| 706 | if (vc->vt_newvt >= 0) { |
| 707 | if (arg == 0) |
| 708 | /* |
| 709 | * Switch disallowed, so forget we were trying |
| 710 | * to do it. |
| 711 | */ |
| 712 | vc->vt_newvt = -1; |
| 713 | |
| 714 | else { |
| 715 | /* |
| 716 | * The current vt has been released, so |
| 717 | * complete the switch. |
| 718 | */ |
| 719 | int newvt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | newvt = vc->vt_newvt; |
| 721 | vc->vt_newvt = -1; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 722 | ret = vc_allocate(newvt); |
| 723 | if (ret) { |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 724 | console_unlock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 725 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
| 727 | /* |
| 728 | * When we actually do the console switch, |
| 729 | * make sure we are atomic with respect to |
| 730 | * other console switches.. |
| 731 | */ |
| 732 | complete_change_console(vc_cons[newvt].d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 734 | } else { |
| 735 | /* |
| 736 | * Switched-to response |
| 737 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | /* |
| 739 | * If it's just an ACK, ignore it |
| 740 | */ |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 741 | if (arg != VT_ACKACQ) |
| 742 | ret = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 744 | console_unlock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 745 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | |
| 747 | /* |
| 748 | * Disallocate memory associated to VT (but leave VT1) |
| 749 | */ |
| 750 | case VT_DISALLOCATE: |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 751 | if (arg > MAX_NR_CONSOLES) { |
| 752 | ret = -ENXIO; |
| 753 | break; |
| 754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | if (arg == 0) { |
Alan Cox | ca9bda0 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 756 | /* deallocate all unused consoles, but leave 0 */ |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 757 | console_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | for (i=1; i<MAX_NR_CONSOLES; i++) |
| 759 | if (! VT_BUSY(i)) |
Alan Cox | ca9bda0 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 760 | vc_deallocate(i); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 761 | console_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } else { |
Alan Cox | ca9bda0 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 763 | /* deallocate a single console, if possible */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | arg--; |
| 765 | if (VT_BUSY(arg)) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 766 | ret = -EBUSY; |
| 767 | else if (arg) { /* leave 0 */ |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 768 | console_lock(); |
Alan Cox | ca9bda0 | 2006-09-29 02:00:03 -0700 | [diff] [blame] | 769 | vc_deallocate(arg); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 770 | console_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 773 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | case VT_RESIZE: |
| 776 | { |
| 777 | struct vt_sizes __user *vtsizes = up; |
Antonino A. Daplas | e400b6e | 2007-10-16 01:29:35 -0700 | [diff] [blame] | 778 | struct vc_data *vc; |
| 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | ushort ll,cc; |
| 781 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 782 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | if (get_user(ll, &vtsizes->v_rows) || |
| 784 | get_user(cc, &vtsizes->v_cols)) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 785 | ret = -EFAULT; |
| 786 | else { |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 787 | console_lock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 788 | for (i = 0; i < MAX_NR_CONSOLES; i++) { |
| 789 | vc = vc_cons[i].d; |
Antonino A. Daplas | e400b6e | 2007-10-16 01:29:35 -0700 | [diff] [blame] | 790 | |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 791 | if (vc) { |
| 792 | vc->vc_resize_user = 1; |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 793 | /* FIXME: review v tty lock */ |
Alan Cox | 8c9a9dd | 2008-08-15 10:39:38 +0100 | [diff] [blame] | 794 | vc_resize(vc_cons[i].d, cc, ll); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 795 | } |
Antonino A. Daplas | e400b6e | 2007-10-16 01:29:35 -0700 | [diff] [blame] | 796 | } |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 797 | console_unlock(); |
Antonino A. Daplas | e400b6e | 2007-10-16 01:29:35 -0700 | [diff] [blame] | 798 | } |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 799 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | case VT_RESIZEX: |
| 803 | { |
| 804 | struct vt_consize __user *vtconsize = up; |
| 805 | ushort ll,cc,vlin,clin,vcol,ccol; |
| 806 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 807 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | if (!access_ok(VERIFY_READ, vtconsize, |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 809 | sizeof(struct vt_consize))) { |
| 810 | ret = -EFAULT; |
| 811 | break; |
| 812 | } |
| 813 | /* FIXME: Should check the copies properly */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | __get_user(ll, &vtconsize->v_rows); |
| 815 | __get_user(cc, &vtconsize->v_cols); |
| 816 | __get_user(vlin, &vtconsize->v_vlin); |
| 817 | __get_user(clin, &vtconsize->v_clin); |
| 818 | __get_user(vcol, &vtconsize->v_vcol); |
| 819 | __get_user(ccol, &vtconsize->v_ccol); |
| 820 | vlin = vlin ? vlin : vc->vc_scan_lines; |
| 821 | if (clin) { |
| 822 | if (ll) { |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 823 | if (ll != vlin/clin) { |
| 824 | /* Parameters don't add up */ |
| 825 | ret = -EINVAL; |
| 826 | break; |
| 827 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | } else |
| 829 | ll = vlin/clin; |
| 830 | } |
| 831 | if (vcol && ccol) { |
| 832 | if (cc) { |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 833 | if (cc != vcol/ccol) { |
| 834 | ret = -EINVAL; |
| 835 | break; |
| 836 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | } else |
| 838 | cc = vcol/ccol; |
| 839 | } |
| 840 | |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 841 | if (clin > 32) { |
| 842 | ret = -EINVAL; |
| 843 | break; |
| 844 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | |
| 846 | for (i = 0; i < MAX_NR_CONSOLES; i++) { |
| 847 | if (!vc_cons[i].d) |
| 848 | continue; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 849 | console_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | if (vlin) |
| 851 | vc_cons[i].d->vc_scan_lines = vlin; |
| 852 | if (clin) |
| 853 | vc_cons[i].d->vc_font.height = clin; |
Antonino A. Daplas | e400b6e | 2007-10-16 01:29:35 -0700 | [diff] [blame] | 854 | vc_cons[i].d->vc_resize_user = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | vc_resize(vc_cons[i].d, cc, ll); |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 856 | console_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | } |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 858 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | case PIO_FONT: { |
| 862 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 863 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | op.op = KD_FONT_OP_SET; |
| 865 | op.flags = KD_FONT_FLAG_OLD | KD_FONT_FLAG_DONT_RECALC; /* Compatibility */ |
| 866 | op.width = 8; |
| 867 | op.height = 0; |
| 868 | op.charcount = 256; |
| 869 | op.data = up; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 870 | ret = con_font_op(vc_cons[fg_console].d, &op); |
| 871 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | case GIO_FONT: { |
| 875 | op.op = KD_FONT_OP_GET; |
| 876 | op.flags = KD_FONT_FLAG_OLD; |
| 877 | op.width = 8; |
| 878 | op.height = 32; |
| 879 | op.charcount = 256; |
| 880 | op.data = up; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 881 | ret = con_font_op(vc_cons[fg_console].d, &op); |
| 882 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | case PIO_CMAP: |
| 886 | if (!perm) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 887 | ret = -EPERM; |
| 888 | else |
| 889 | ret = con_set_cmap(up); |
| 890 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
| 892 | case GIO_CMAP: |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 893 | ret = con_get_cmap(up); |
| 894 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | |
| 896 | case PIO_FONTX: |
| 897 | case GIO_FONTX: |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 898 | ret = do_fontx_ioctl(cmd, up, perm, &op); |
| 899 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | |
| 901 | case PIO_FONTRESET: |
| 902 | { |
| 903 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 904 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
| 906 | #ifdef BROKEN_GRAPHICS_PROGRAMS |
| 907 | /* With BROKEN_GRAPHICS_PROGRAMS defined, the default |
| 908 | font is not saved. */ |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 909 | ret = -ENOSYS; |
| 910 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | #else |
| 912 | { |
| 913 | op.op = KD_FONT_OP_SET_DEFAULT; |
| 914 | op.data = NULL; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 915 | ret = con_font_op(vc_cons[fg_console].d, &op); |
| 916 | if (ret) |
| 917 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | con_set_default_unimap(vc_cons[fg_console].d); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 919 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | #endif |
| 922 | } |
| 923 | |
| 924 | case KDFONTOP: { |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 925 | if (copy_from_user(&op, up, sizeof(op))) { |
| 926 | ret = -EFAULT; |
| 927 | break; |
| 928 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | if (!perm && op.op != KD_FONT_OP_GET) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 930 | return -EPERM; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 931 | ret = con_font_op(vc, &op); |
| 932 | if (ret) |
| 933 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | if (copy_to_user(up, &op, sizeof(op))) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 935 | ret = -EFAULT; |
| 936 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | case PIO_SCRNMAP: |
| 940 | if (!perm) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 941 | ret = -EPERM; |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 942 | else { |
| 943 | tty_lock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 944 | ret = con_set_trans_old(up); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 945 | tty_unlock(); |
| 946 | } |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 947 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
| 949 | case GIO_SCRNMAP: |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 950 | tty_lock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 951 | ret = con_get_trans_old(up); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 952 | tty_unlock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 953 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | |
| 955 | case PIO_UNISCRNMAP: |
| 956 | if (!perm) |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 957 | ret = -EPERM; |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 958 | else { |
| 959 | tty_lock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 960 | ret = con_set_trans_new(up); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 961 | tty_unlock(); |
| 962 | } |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 963 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | |
| 965 | case GIO_UNISCRNMAP: |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 966 | tty_lock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 967 | ret = con_get_trans_new(up); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 968 | tty_unlock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 969 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | |
| 971 | case PIO_UNIMAPCLR: |
| 972 | { struct unimapinit ui; |
| 973 | if (!perm) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 974 | return -EPERM; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 975 | ret = copy_from_user(&ui, up, sizeof(struct unimapinit)); |
Dan Carpenter | 3fde85d | 2010-06-04 12:20:46 +0200 | [diff] [blame] | 976 | if (ret) |
| 977 | ret = -EFAULT; |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 978 | else { |
| 979 | tty_lock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 980 | con_clear_unimap(vc, &ui); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 981 | tty_unlock(); |
| 982 | } |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 983 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | case PIO_UNIMAP: |
| 987 | case GIO_UNIMAP: |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 988 | tty_lock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 989 | ret = do_unimap_ioctl(cmd, up, perm, vc); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 990 | tty_unlock(); |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 991 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | |
| 993 | case VT_LOCKSWITCH: |
| 994 | if (!capable(CAP_SYS_TTY_CONFIG)) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 995 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | vt_dont_switch = 1; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 997 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | case VT_UNLOCKSWITCH: |
| 999 | if (!capable(CAP_SYS_TTY_CONFIG)) |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 1000 | return -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | vt_dont_switch = 0; |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 1002 | break; |
Samuel Thibault | 533475d | 2006-08-27 01:23:39 -0700 | [diff] [blame] | 1003 | case VT_GETHIFONTMASK: |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 1004 | ret = put_user(vc->vc_hi_font_mask, |
| 1005 | (unsigned short __user *)arg); |
| 1006 | break; |
Alan Cox | 8b92e87 | 2009-09-19 13:13:24 -0700 | [diff] [blame] | 1007 | case VT_WAITEVENT: |
| 1008 | ret = vt_event_wait_ioctl((struct vt_event __user *)arg); |
| 1009 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | default: |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 1011 | ret = -ENOIOCTLCMD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | } |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 1013 | out: |
Alan Cox | 9cc3c22 | 2008-04-30 00:53:26 -0700 | [diff] [blame] | 1014 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | void reset_vc(struct vc_data *vc) |
| 1018 | { |
| 1019 | vc->vc_mode = KD_TEXT; |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 1020 | vt_reset_unicode(vc->vc_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | vc->vt_mode.mode = VT_AUTO; |
| 1022 | vc->vt_mode.waitv = 0; |
| 1023 | vc->vt_mode.relsig = 0; |
| 1024 | vc->vt_mode.acqsig = 0; |
| 1025 | vc->vt_mode.frsig = 0; |
Eric W. Biederman | 8b6312f | 2007-02-10 01:44:34 -0800 | [diff] [blame] | 1026 | put_pid(vc->vt_pid); |
| 1027 | vc->vt_pid = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | vc->vt_newvt = -1; |
| 1029 | if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */ |
| 1030 | reset_palette(vc); |
| 1031 | } |
| 1032 | |
Eric W. Biederman | 8b6312f | 2007-02-10 01:44:34 -0800 | [diff] [blame] | 1033 | void vc_SAK(struct work_struct *work) |
| 1034 | { |
| 1035 | struct vc *vc_con = |
| 1036 | container_of(work, struct vc, SAK_work); |
| 1037 | struct vc_data *vc; |
| 1038 | struct tty_struct *tty; |
| 1039 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1040 | console_lock(); |
Eric W. Biederman | 8b6312f | 2007-02-10 01:44:34 -0800 | [diff] [blame] | 1041 | vc = vc_con->d; |
| 1042 | if (vc) { |
Alan Cox | 079c953 | 2012-02-28 14:49:23 +0000 | [diff] [blame] | 1043 | /* FIXME: review tty ref counting */ |
Alan Cox | 8ce7326 | 2010-06-01 22:52:56 +0200 | [diff] [blame] | 1044 | tty = vc->port.tty; |
Eric W. Biederman | 8b6312f | 2007-02-10 01:44:34 -0800 | [diff] [blame] | 1045 | /* |
| 1046 | * SAK should also work in all raw modes and reset |
| 1047 | * them properly. |
| 1048 | */ |
| 1049 | if (tty) |
| 1050 | __do_SAK(tty); |
| 1051 | reset_vc(vc); |
| 1052 | } |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1053 | console_unlock(); |
Eric W. Biederman | 8b6312f | 2007-02-10 01:44:34 -0800 | [diff] [blame] | 1054 | } |
| 1055 | |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 1056 | #ifdef CONFIG_COMPAT |
| 1057 | |
| 1058 | struct compat_consolefontdesc { |
| 1059 | unsigned short charcount; /* characters in font (256 or 512) */ |
| 1060 | unsigned short charheight; /* scan lines per character (1-32) */ |
| 1061 | compat_caddr_t chardata; /* font data in expanded form */ |
| 1062 | }; |
| 1063 | |
| 1064 | static inline int |
| 1065 | compat_fontx_ioctl(int cmd, struct compat_consolefontdesc __user *user_cfd, |
| 1066 | int perm, struct console_font_op *op) |
| 1067 | { |
| 1068 | struct compat_consolefontdesc cfdarg; |
| 1069 | int i; |
| 1070 | |
| 1071 | if (copy_from_user(&cfdarg, user_cfd, sizeof(struct compat_consolefontdesc))) |
| 1072 | return -EFAULT; |
| 1073 | |
| 1074 | switch (cmd) { |
| 1075 | case PIO_FONTX: |
| 1076 | if (!perm) |
| 1077 | return -EPERM; |
| 1078 | op->op = KD_FONT_OP_SET; |
| 1079 | op->flags = KD_FONT_FLAG_OLD; |
| 1080 | op->width = 8; |
| 1081 | op->height = cfdarg.charheight; |
| 1082 | op->charcount = cfdarg.charcount; |
| 1083 | op->data = compat_ptr(cfdarg.chardata); |
| 1084 | return con_font_op(vc_cons[fg_console].d, op); |
| 1085 | case GIO_FONTX: |
| 1086 | op->op = KD_FONT_OP_GET; |
| 1087 | op->flags = KD_FONT_FLAG_OLD; |
| 1088 | op->width = 8; |
| 1089 | op->height = cfdarg.charheight; |
| 1090 | op->charcount = cfdarg.charcount; |
| 1091 | op->data = compat_ptr(cfdarg.chardata); |
| 1092 | i = con_font_op(vc_cons[fg_console].d, op); |
| 1093 | if (i) |
| 1094 | return i; |
| 1095 | cfdarg.charheight = op->height; |
| 1096 | cfdarg.charcount = op->charcount; |
| 1097 | if (copy_to_user(user_cfd, &cfdarg, sizeof(struct compat_consolefontdesc))) |
| 1098 | return -EFAULT; |
| 1099 | return 0; |
| 1100 | } |
| 1101 | return -EINVAL; |
| 1102 | } |
| 1103 | |
| 1104 | struct compat_console_font_op { |
| 1105 | compat_uint_t op; /* operation code KD_FONT_OP_* */ |
| 1106 | compat_uint_t flags; /* KD_FONT_FLAG_* */ |
| 1107 | compat_uint_t width, height; /* font size */ |
| 1108 | compat_uint_t charcount; |
| 1109 | compat_caddr_t data; /* font data with height fixed to 32 */ |
| 1110 | }; |
| 1111 | |
| 1112 | static inline int |
| 1113 | compat_kdfontop_ioctl(struct compat_console_font_op __user *fontop, |
| 1114 | int perm, struct console_font_op *op, struct vc_data *vc) |
| 1115 | { |
| 1116 | int i; |
| 1117 | |
| 1118 | if (copy_from_user(op, fontop, sizeof(struct compat_console_font_op))) |
| 1119 | return -EFAULT; |
| 1120 | if (!perm && op->op != KD_FONT_OP_GET) |
| 1121 | return -EPERM; |
| 1122 | op->data = compat_ptr(((struct compat_console_font_op *)op)->data); |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 1123 | i = con_font_op(vc, op); |
| 1124 | if (i) |
| 1125 | return i; |
| 1126 | ((struct compat_console_font_op *)op)->data = (unsigned long)op->data; |
| 1127 | if (copy_to_user(fontop, op, sizeof(struct compat_console_font_op))) |
| 1128 | return -EFAULT; |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
| 1132 | struct compat_unimapdesc { |
| 1133 | unsigned short entry_ct; |
| 1134 | compat_caddr_t entries; |
| 1135 | }; |
| 1136 | |
| 1137 | static inline int |
| 1138 | compat_unimap_ioctl(unsigned int cmd, struct compat_unimapdesc __user *user_ud, |
| 1139 | int perm, struct vc_data *vc) |
| 1140 | { |
| 1141 | struct compat_unimapdesc tmp; |
| 1142 | struct unipair __user *tmp_entries; |
| 1143 | |
| 1144 | if (copy_from_user(&tmp, user_ud, sizeof tmp)) |
| 1145 | return -EFAULT; |
| 1146 | tmp_entries = compat_ptr(tmp.entries); |
| 1147 | if (tmp_entries) |
| 1148 | if (!access_ok(VERIFY_WRITE, tmp_entries, |
| 1149 | tmp.entry_ct*sizeof(struct unipair))) |
| 1150 | return -EFAULT; |
| 1151 | switch (cmd) { |
| 1152 | case PIO_UNIMAP: |
| 1153 | if (!perm) |
| 1154 | return -EPERM; |
| 1155 | return con_set_unimap(vc, tmp.entry_ct, tmp_entries); |
| 1156 | case GIO_UNIMAP: |
| 1157 | if (!perm && fg_console != vc->vc_num) |
| 1158 | return -EPERM; |
| 1159 | return con_get_unimap(vc, tmp.entry_ct, &(user_ud->entry_ct), tmp_entries); |
| 1160 | } |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
Alan Cox | 6caa76b | 2011-02-14 16:27:22 +0000 | [diff] [blame] | 1164 | long vt_compat_ioctl(struct tty_struct *tty, |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 1165 | unsigned int cmd, unsigned long arg) |
| 1166 | { |
| 1167 | struct vc_data *vc = tty->driver_data; |
| 1168 | struct console_font_op op; /* used in multiple places here */ |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 1169 | unsigned int console; |
| 1170 | void __user *up = (void __user *)arg; |
| 1171 | int perm; |
| 1172 | int ret = 0; |
| 1173 | |
| 1174 | console = vc->vc_num; |
| 1175 | |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 1176 | if (!vc_cons_allocated(console)) { /* impossible? */ |
| 1177 | ret = -ENOIOCTLCMD; |
| 1178 | goto out; |
| 1179 | } |
| 1180 | |
| 1181 | /* |
| 1182 | * To have permissions to do most of the vt ioctls, we either have |
| 1183 | * to be the owner of the tty, or have CAP_SYS_TTY_CONFIG. |
| 1184 | */ |
| 1185 | perm = 0; |
| 1186 | if (current->signal->tty == tty || capable(CAP_SYS_TTY_CONFIG)) |
| 1187 | perm = 1; |
| 1188 | |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 1189 | switch (cmd) { |
| 1190 | /* |
| 1191 | * these need special handlers for incompatible data structures |
| 1192 | */ |
| 1193 | case PIO_FONTX: |
| 1194 | case GIO_FONTX: |
| 1195 | ret = compat_fontx_ioctl(cmd, up, perm, &op); |
| 1196 | break; |
| 1197 | |
| 1198 | case KDFONTOP: |
| 1199 | ret = compat_kdfontop_ioctl(up, perm, &op, vc); |
| 1200 | break; |
| 1201 | |
| 1202 | case PIO_UNIMAP: |
| 1203 | case GIO_UNIMAP: |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 1204 | tty_lock(); |
Andreas Schwab | 4b1fe77 | 2009-09-28 20:10:02 +0200 | [diff] [blame] | 1205 | ret = compat_unimap_ioctl(cmd, up, perm, vc); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 1206 | tty_unlock(); |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 1207 | break; |
| 1208 | |
| 1209 | /* |
| 1210 | * all these treat 'arg' as an integer |
| 1211 | */ |
| 1212 | case KIOCSOUND: |
| 1213 | case KDMKTONE: |
| 1214 | #ifdef CONFIG_X86 |
| 1215 | case KDADDIO: |
| 1216 | case KDDELIO: |
| 1217 | #endif |
| 1218 | case KDSETMODE: |
| 1219 | case KDMAPDISP: |
| 1220 | case KDUNMAPDISP: |
| 1221 | case KDSKBMODE: |
| 1222 | case KDSKBMETA: |
| 1223 | case KDSKBLED: |
| 1224 | case KDSETLED: |
| 1225 | case KDSIGACCEPT: |
| 1226 | case VT_ACTIVATE: |
| 1227 | case VT_WAITACTIVE: |
| 1228 | case VT_RELDISP: |
| 1229 | case VT_DISALLOCATE: |
| 1230 | case VT_RESIZE: |
| 1231 | case VT_RESIZEX: |
| 1232 | goto fallback; |
| 1233 | |
| 1234 | /* |
| 1235 | * the rest has a compatible data structure behind arg, |
| 1236 | * but we have to convert it to a proper 64 bit pointer. |
| 1237 | */ |
| 1238 | default: |
| 1239 | arg = (unsigned long)compat_ptr(arg); |
| 1240 | goto fallback; |
| 1241 | } |
| 1242 | out: |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 1243 | return ret; |
| 1244 | |
| 1245 | fallback: |
Alan Cox | 6caa76b | 2011-02-14 16:27:22 +0000 | [diff] [blame] | 1246 | return vt_ioctl(tty, cmd, arg); |
Arnd Bergmann | e921665 | 2009-08-06 15:09:28 +0200 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | |
| 1250 | #endif /* CONFIG_COMPAT */ |
| 1251 | |
| 1252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1253 | /* |
Alan Cox | d3b5cff | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 1254 | * Performs the back end of a vt switch. Called under the console |
| 1255 | * semaphore. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | */ |
| 1257 | static void complete_change_console(struct vc_data *vc) |
| 1258 | { |
| 1259 | unsigned char old_vc_mode; |
Alan Cox | 8b92e87 | 2009-09-19 13:13:24 -0700 | [diff] [blame] | 1260 | int old = fg_console; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | |
| 1262 | last_console = fg_console; |
| 1263 | |
| 1264 | /* |
| 1265 | * If we're switching, we could be going from KD_GRAPHICS to |
| 1266 | * KD_TEXT mode or vice versa, which means we need to blank or |
| 1267 | * unblank the screen later. |
| 1268 | */ |
| 1269 | old_vc_mode = vc_cons[fg_console].d->vc_mode; |
| 1270 | switch_screen(vc); |
| 1271 | |
| 1272 | /* |
Eric W. Biederman | 3dfcaf16 | 2006-12-13 00:34:05 -0800 | [diff] [blame] | 1273 | * This can't appear below a successful kill_pid(). If it did, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | * then the *blank_screen operation could occur while X, having |
| 1275 | * received acqsig, is waking up on another processor. This |
| 1276 | * condition can lead to overlapping accesses to the VGA range |
| 1277 | * and the framebuffer (causing system lockups). |
| 1278 | * |
| 1279 | * To account for this we duplicate this code below only if the |
| 1280 | * controlling process is gone and we've called reset_vc. |
| 1281 | */ |
| 1282 | if (old_vc_mode != vc->vc_mode) { |
| 1283 | if (vc->vc_mode == KD_TEXT) |
| 1284 | do_unblank_screen(1); |
| 1285 | else |
| 1286 | do_blank_screen(1); |
| 1287 | } |
| 1288 | |
| 1289 | /* |
| 1290 | * If this new console is under process control, send it a signal |
| 1291 | * telling it that it has acquired. Also check if it has died and |
| 1292 | * clean up (similar to logic employed in change_console()) |
| 1293 | */ |
Greg Kroah-Hartman | 87a6aca | 2010-03-15 17:14:15 -0700 | [diff] [blame] | 1294 | if (vc->vt_mode.mode == VT_PROCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | /* |
Eric W. Biederman | 3dfcaf16 | 2006-12-13 00:34:05 -0800 | [diff] [blame] | 1296 | * Send the signal as privileged - kill_pid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | * tell us if the process has gone or something else |
| 1298 | * is awry |
| 1299 | */ |
Eric W. Biederman | bde0d2c | 2006-10-02 02:17:14 -0700 | [diff] [blame] | 1300 | if (kill_pid(vc->vt_pid, vc->vt_mode.acqsig, 1) != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | /* |
| 1302 | * The controlling process has died, so we revert back to |
| 1303 | * normal operation. In this case, we'll also change back |
| 1304 | * to KD_TEXT mode. I'm not sure if this is strictly correct |
| 1305 | * but it saves the agony when the X server dies and the screen |
| 1306 | * remains blanked due to KD_GRAPHICS! It would be nice to do |
| 1307 | * this outside of VT_PROCESS but there is no single process |
| 1308 | * to account for and tracking tty count may be undesirable. |
| 1309 | */ |
| 1310 | reset_vc(vc); |
| 1311 | |
| 1312 | if (old_vc_mode != vc->vc_mode) { |
| 1313 | if (vc->vc_mode == KD_TEXT) |
| 1314 | do_unblank_screen(1); |
| 1315 | else |
| 1316 | do_blank_screen(1); |
| 1317 | } |
| 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | /* |
| 1322 | * Wake anyone waiting for their VT to activate |
| 1323 | */ |
Alan Cox | 8b92e87 | 2009-09-19 13:13:24 -0700 | [diff] [blame] | 1324 | vt_event_post(VT_EVENT_SWITCH, old, vc->vc_num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | return; |
| 1326 | } |
| 1327 | |
| 1328 | /* |
| 1329 | * Performs the front-end of a vt switch |
| 1330 | */ |
| 1331 | void change_console(struct vc_data *new_vc) |
| 1332 | { |
| 1333 | struct vc_data *vc; |
| 1334 | |
| 1335 | if (!new_vc || new_vc->vc_num == fg_console || vt_dont_switch) |
| 1336 | return; |
| 1337 | |
| 1338 | /* |
| 1339 | * If this vt is in process mode, then we need to handshake with |
| 1340 | * that process before switching. Essentially, we store where that |
| 1341 | * vt wants to switch to and wait for it to tell us when it's done |
| 1342 | * (via VT_RELDISP ioctl). |
| 1343 | * |
| 1344 | * We also check to see if the controlling process still exists. |
| 1345 | * If it doesn't, we reset this vt to auto mode and continue. |
| 1346 | * This is a cheap way to track process control. The worst thing |
| 1347 | * that can happen is: we send a signal to a process, it dies, and |
| 1348 | * the switch gets "lost" waiting for a response; hopefully, the |
| 1349 | * user will try again, we'll detect the process is gone (unless |
| 1350 | * the user waits just the right amount of time :-) and revert the |
| 1351 | * vt to auto control. |
| 1352 | */ |
| 1353 | vc = vc_cons[fg_console].d; |
Greg Kroah-Hartman | 87a6aca | 2010-03-15 17:14:15 -0700 | [diff] [blame] | 1354 | if (vc->vt_mode.mode == VT_PROCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | /* |
Eric W. Biederman | 3dfcaf16 | 2006-12-13 00:34:05 -0800 | [diff] [blame] | 1356 | * Send the signal as privileged - kill_pid() will |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | * tell us if the process has gone or something else |
Jan Lübbe | a64314e | 2007-09-29 18:47:51 +0200 | [diff] [blame] | 1358 | * is awry. |
| 1359 | * |
| 1360 | * We need to set vt_newvt *before* sending the signal or we |
| 1361 | * have a race. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | */ |
Jan Lübbe | a64314e | 2007-09-29 18:47:51 +0200 | [diff] [blame] | 1363 | vc->vt_newvt = new_vc->vc_num; |
Eric W. Biederman | bde0d2c | 2006-10-02 02:17:14 -0700 | [diff] [blame] | 1364 | if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | /* |
Greg Kroah-Hartman | 87a6aca | 2010-03-15 17:14:15 -0700 | [diff] [blame] | 1366 | * It worked. Mark the vt to switch to and |
| 1367 | * return. The process needs to send us a |
| 1368 | * VT_RELDISP ioctl to complete the switch. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | */ |
Greg Kroah-Hartman | 87a6aca | 2010-03-15 17:14:15 -0700 | [diff] [blame] | 1370 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | /* |
Greg Kroah-Hartman | 87a6aca | 2010-03-15 17:14:15 -0700 | [diff] [blame] | 1374 | * The controlling process has died, so we revert back to |
| 1375 | * normal operation. In this case, we'll also change back |
| 1376 | * to KD_TEXT mode. I'm not sure if this is strictly correct |
| 1377 | * but it saves the agony when the X server dies and the screen |
| 1378 | * remains blanked due to KD_GRAPHICS! It would be nice to do |
| 1379 | * this outside of VT_PROCESS but there is no single process |
| 1380 | * to account for and tracking tty count may be undesirable. |
| 1381 | */ |
| 1382 | reset_vc(vc); |
| 1383 | |
| 1384 | /* |
| 1385 | * Fall through to normal (VT_AUTO) handling of the switch... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | */ |
| 1387 | } |
| 1388 | |
| 1389 | /* |
| 1390 | * Ignore all switches in KD_GRAPHICS+VT_AUTO mode |
| 1391 | */ |
| 1392 | if (vc->vc_mode == KD_GRAPHICS) |
| 1393 | return; |
| 1394 | |
| 1395 | complete_change_console(new_vc); |
| 1396 | } |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1397 | |
| 1398 | /* Perform a kernel triggered VT switch for suspend/resume */ |
| 1399 | |
| 1400 | static int disable_vt_switch; |
| 1401 | |
| 1402 | int vt_move_to_console(unsigned int vt, int alloc) |
| 1403 | { |
| 1404 | int prev; |
| 1405 | |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1406 | console_lock(); |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1407 | /* Graphics mode - up to X */ |
| 1408 | if (disable_vt_switch) { |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1409 | console_unlock(); |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1410 | return 0; |
| 1411 | } |
| 1412 | prev = fg_console; |
| 1413 | |
| 1414 | if (alloc && vc_allocate(vt)) { |
| 1415 | /* we can't have a free VC for now. Too bad, |
| 1416 | * we don't want to mess the screen for now. */ |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1417 | console_unlock(); |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1418 | return -ENOSPC; |
| 1419 | } |
| 1420 | |
| 1421 | if (set_console(vt)) { |
| 1422 | /* |
| 1423 | * We're unable to switch to the SUSPEND_CONSOLE. |
| 1424 | * Let the calling function know so it can decide |
| 1425 | * what to do. |
| 1426 | */ |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1427 | console_unlock(); |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1428 | return -EIO; |
| 1429 | } |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1430 | console_unlock(); |
Alan Cox | 4001d7b | 2012-03-02 14:59:20 +0000 | [diff] [blame^] | 1431 | /* Review: I don't see why we need tty_lock here FIXME */ |
Arnd Bergmann | be1bc28 | 2010-06-01 22:53:05 +0200 | [diff] [blame] | 1432 | tty_lock(); |
Jiri Slaby | 797938b | 2009-08-11 23:20:41 +0200 | [diff] [blame] | 1433 | if (vt_waitactive(vt + 1)) { |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1434 | pr_debug("Suspend: Can't switch VCs."); |
Arnd Bergmann | be1bc28 | 2010-06-01 22:53:05 +0200 | [diff] [blame] | 1435 | tty_unlock(); |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1436 | return -EINTR; |
| 1437 | } |
Arnd Bergmann | be1bc28 | 2010-06-01 22:53:05 +0200 | [diff] [blame] | 1438 | tty_unlock(); |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1439 | return prev; |
| 1440 | } |
| 1441 | |
| 1442 | /* |
| 1443 | * Normally during a suspend, we allocate a new console and switch to it. |
| 1444 | * When we resume, we switch back to the original console. This switch |
| 1445 | * can be slow, so on systems where the framebuffer can handle restoration |
| 1446 | * of video registers anyways, there's little point in doing the console |
| 1447 | * switch. This function allows you to disable it by passing it '0'. |
| 1448 | */ |
| 1449 | void pm_set_vt_switch(int do_switch) |
| 1450 | { |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1451 | console_lock(); |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1452 | disable_vt_switch = !do_switch; |
Torben Hohn | ac751ef | 2011-01-25 15:07:35 -0800 | [diff] [blame] | 1453 | console_unlock(); |
Alan Cox | 8d23355 | 2009-09-19 13:13:25 -0700 | [diff] [blame] | 1454 | } |
| 1455 | EXPORT_SYMBOL(pm_set_vt_switch); |