VMware Balloon driver
[safe/jmp/linux-2.6] / drivers / char / vt.c
index e47a4c8..bd1d116 100644 (file)
@@ -161,6 +161,11 @@ static void set_palette(struct vc_data *vc);
 static int printable;          /* Is console ready for printing? */
 int default_utf8 = true;
 module_param(default_utf8, int, S_IRUGO | S_IWUSR);
+int global_cursor_default = -1;
+module_param(global_cursor_default, int, S_IRUGO | S_IWUSR);
+
+static int cur_default = CUR_DEFAULT;
+module_param(cur_default, int, S_IRUGO | S_IWUSR);
 
 /*
  * ignore_poke: don't unblank the screen when things are typed.  This is
@@ -182,12 +187,10 @@ static DECLARE_WORK(console_work, console_callback);
  * fg_console is the current virtual console,
  * last_console is the last used one,
  * want_console is the console we want to switch to,
- * kmsg_redirect is the console for kernel messages,
  */
 int fg_console;
 int last_console;
 int want_console = -1;
-int kmsg_redirect;
 
 /*
  * For each existing display, we have a pointer to console currently visible
@@ -252,7 +255,6 @@ static void notify_update(struct vc_data *vc)
        struct vt_notifier_param param = { .vc = vc };
        atomic_notifier_call_chain(&vt_notifier_list, VT_UPDATE, &param);
 }
-
 /*
  *     Low-Level Functions
  */
@@ -776,6 +778,12 @@ int vc_allocate(unsigned int currcons)     /* return 0 on success */
                vc_cons[currcons].d = NULL;
                return -ENOMEM;
            }
+
+           /* If no drivers have overridden us and the user didn't pass a
+              boot option, default to displaying the cursor */
+           if (global_cursor_default == -1)
+                   global_cursor_default = 1;
+
            vc_init(vc, vc->vc_rows, vc->vc_cols, 1);
            vcs_make_sysfs(currcons);
            atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param);
@@ -813,7 +821,7 @@ static inline int resize_screen(struct vc_data *vc, int width, int height,
  *
  *     Resize a virtual console, clipping according to the actual constraints.
  *     If the caller passes a tty structure then update the termios winsize
- *     information and perform any neccessary signal handling.
+ *     information and perform any necessary signal handling.
  *
  *     Caller must hold the console semaphore. Takes the termios mutex and
  *     ctrl_lock of the tty IFF a tty is passed.
@@ -935,6 +943,7 @@ static int vc_do_resize(struct tty_struct *tty, struct vc_data *vc,
 
        if (CON_IS_VISIBLE(vc))
                update_screen(vc);
+       vt_event_post(VT_EVENT_RESIZE, vc->vc_num, vc->vc_num);
        return err;
 }
 
@@ -1616,7 +1625,7 @@ static void reset_terminal(struct vc_data *vc, int do_clear)
        vc->vc_decscnm          = 0;
        vc->vc_decom            = 0;
        vc->vc_decawm           = 1;
-       vc->vc_deccm            = 1;
+       vc->vc_deccm            = global_cursor_default;
        vc->vc_decim            = 0;
 
        set_kbd(vc, decarm);
@@ -1630,7 +1639,7 @@ static void reset_terminal(struct vc_data *vc, int do_clear)
        /* do not do set_leds here because this causes an endless tasklet loop
           when the keyboard hasn't been initialized yet */
 
-       vc->vc_cursor_type = CUR_DEFAULT;
+       vc->vc_cursor_type = cur_default;
        vc->vc_complement_mask = vc->vc_s_complement_mask;
 
        default_attr(vc);
@@ -1832,7 +1841,7 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
                                if (vc->vc_par[0])
                                        vc->vc_cursor_type = vc->vc_par[0] | (vc->vc_par[1] << 8) | (vc->vc_par[2] << 16);
                                else
-                                       vc->vc_cursor_type = CUR_DEFAULT;
+                                       vc->vc_cursor_type = cur_default;
                                return;
                        }
                        break;
@@ -2110,8 +2119,6 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
        uint8_t inverse;
        uint8_t width;
        u16 himask, charmask;
-       const unsigned char *orig_buf = NULL;
-       int orig_count;
 
        if (in_interrupt())
                return count;
@@ -2129,16 +2136,10 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
        currcons = vc->vc_num;
        if (!vc_cons_allocated(currcons)) {
            /* could this happen? */
-           static int error = 0;
-           if (!error) {
-               error = 1;
-               printk("con_write: tty %d not allocated\n", currcons+1);
-           }
+               printk_once("con_write: tty %d not allocated\n", currcons+1);
            release_console_sem();
            return 0;
        }
-       orig_buf = buf;
-       orig_count = count;
 
        himask = vc->vc_hi_font_mask;
        charmask = himask ? 0x1ff : 0xff;
@@ -2430,6 +2431,37 @@ struct tty_driver *console_driver;
 
 #ifdef CONFIG_VT_CONSOLE
 
+/**
+ * vt_kmsg_redirect() - Sets/gets the kernel message console
+ * @new:       The new virtual terminal number or -1 if the console should stay
+ *             unchanged
+ *
+ * By default, the kernel messages are always printed on the current virtual
+ * console. However, the user may modify that default with the
+ * TIOCL_SETKMSGREDIRECT ioctl call.
+ *
+ * This function sets the kernel message console to be @new. It returns the old
+ * virtual console number. The virtual terminal number 0 (both as parameter and
+ * return value) means no redirection (i.e. always printed on the currently
+ * active console).
+ *
+ * The parameter -1 means that only the current console is returned, but the
+ * value is not modified. You may use the macro vt_get_kmsg_redirect() in that
+ * case to make the code more understandable.
+ *
+ * When the kernel is compiled without CONFIG_VT_CONSOLE, this function ignores
+ * the parameter and always returns 0.
+ */
+int vt_kmsg_redirect(int new)
+{
+       static int kmsg_con;
+
+       if (new != -1)
+               return xchg(&kmsg_con, new);
+       else
+               return kmsg_con;
+}
+
 /*
  *     Console on virtual terminal
  *
@@ -2444,6 +2476,7 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
        const ushort *start;
        ushort cnt = 0;
        ushort myx;
+       int kmsg_console;
 
        /* console busy or not yet initialized */
        if (!printable)
@@ -2451,8 +2484,9 @@ static void vt_console_print(struct console *co, const char *b, unsigned count)
        if (!spin_trylock(&printing_lock))
                return;
 
-       if (kmsg_redirect && vc_cons_allocated(kmsg_redirect - 1))
-               vc = vc_cons[kmsg_redirect - 1].d;
+       kmsg_console = vt_get_kmsg_redirect();
+       if (kmsg_console && vc_cons_allocated(kmsg_console - 1))
+               vc = vc_cons[kmsg_console - 1].d;
 
        /* read `x' only after setting currcons properly (otherwise
           the `x' macro will read the x of the foreground console). */
@@ -2609,7 +2643,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
                        ret = set_vesa_blanking(p);
                        break;
                case TIOCL_GETKMSGREDIRECT:
-                       data = kmsg_redirect;
+                       data = vt_get_kmsg_redirect();
                        ret = __put_user(data, p);
                        break;
                case TIOCL_SETKMSGREDIRECT:
@@ -2619,7 +2653,7 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
                                if (get_user(data, p+1))
                                        ret = -EFAULT;
                                else
-                                       kmsg_redirect = data;
+                                       vt_kmsg_redirect(data);
                        }
                        break;
                case TIOCL_GETFGCONSOLE:
@@ -2910,6 +2944,9 @@ static const struct tty_operations con_ops = {
        .flush_chars = con_flush_chars,
        .chars_in_buffer = con_chars_in_buffer,
        .ioctl = vt_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl = vt_compat_ioctl,
+#endif
        .stop = con_stop,
        .start = con_start,
        .throttle = con_throttle,
@@ -3637,6 +3674,7 @@ void do_blank_screen(int entering_gfx)
                blank_state = blank_vesa_wait;
                mod_timer(&console_timer, jiffies + vesa_off_interval);
        }
+       vt_event_post(VT_EVENT_BLANK, vc->vc_num, vc->vc_num);
 }
 EXPORT_SYMBOL(do_blank_screen);
 
@@ -3681,6 +3719,7 @@ void do_unblank_screen(int leaving_gfx)
                console_blank_hook(0);
        set_palette(vc);
        set_cursor(vc);
+       vt_event_post(VT_EVENT_UNBLANK, vc->vc_num, vc->vc_num);
 }
 EXPORT_SYMBOL(do_unblank_screen);
 
@@ -4077,6 +4116,7 @@ EXPORT_SYMBOL(fg_console);
 EXPORT_SYMBOL(console_blank_hook);
 EXPORT_SYMBOL(console_blanked);
 EXPORT_SYMBOL(vc_cons);
+EXPORT_SYMBOL(global_cursor_default);
 #ifndef VT_SINGLE_DRIVER
 EXPORT_SYMBOL(take_over_console);
 EXPORT_SYMBOL(give_up_console);