fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / xen / console / console.c
index ec7dd9e..f7e07f9 100644 (file)
@@ -30,7 +30,6 @@
  * IN THE SOFTWARE.
  */
 
-#include <linux/config.h>
 #include <linux/version.h>
 #include <linux/module.h>
 #include <linux/errno.h>
@@ -39,6 +38,7 @@
 #include <linux/interrupt.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
+#include <linux/vt.h>
 #include <linux/serial.h>
 #include <linux/major.h>
 #include <linux/ptrace.h>
@@ -49,6 +49,7 @@
 #include <linux/console.h>
 #include <linux/bootmem.h>
 #include <linux/sysrq.h>
+#include <linux/screen_info.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/uaccess.h>
@@ -56,6 +57,7 @@
 #include <xen/interface/event_channel.h>
 #include <asm/hypervisor.h>
 #include <xen/evtchn.h>
+#include <xen/xenbus.h>
 #include <xen/xencons.h>
 
 /*
  *  'xencons=off'  [XC_OFF]:     Console is disabled.
  *  'xencons=tty'  [XC_TTY]:     Console attached to '/dev/tty[0-9]+'.
  *  'xencons=ttyS' [XC_SERIAL]:  Console attached to '/dev/ttyS[0-9]+'.
+ *  'xencons=xvc'  [XC_XVC]:     Console attached to '/dev/xvc0'.
  *                 [XC_DEFAULT]: DOM0 -> XC_SERIAL ; all others -> XC_TTY.
  * 
  * NB. In mode XC_TTY, we create dummy consoles for tty2-63. This suppresses
  * warnings from standard distro startup scripts.
  */
-static enum { XC_OFF, XC_DEFAULT, XC_TTY, XC_SERIAL } xc_mode = XC_DEFAULT;
+static enum {
+       XC_OFF, XC_DEFAULT, XC_TTY, XC_SERIAL, XC_XVC
+} xc_mode = XC_DEFAULT;
 static int xc_num = -1;
 
+/* /dev/xvc0 device number allocated by lanana.org. */
+#define XEN_XVC_MAJOR 204
+#define XEN_XVC_MINOR 191
+
 #ifdef CONFIG_MAGIC_SYSRQ
 static unsigned long sysrq_requested;
-extern int sysrq_enabled;
 #endif
 
 static int __init xencons_setup(char *str)
@@ -81,28 +89,24 @@ static int __init xencons_setup(char *str)
        char *q;
        int n;
 
-       if (!strncmp(str, "ttyS", 4))
+       if (!strncmp(str, "ttyS", 4)) {
                xc_mode = XC_SERIAL;
-       else if (!strncmp(str, "tty", 3))
+               str += 4;
+       } else if (!strncmp(str, "tty", 3)) {
                xc_mode = XC_TTY;
-       else if (!strncmp(str, "off", 3))
+               str += 3;
+       } else if (!strncmp(str, "xvc", 3)) {
+               xc_mode = XC_XVC;
+               str += 3;
+       } else if (!strncmp(str, "off", 3)) {
                xc_mode = XC_OFF;
-
-       switch (xc_mode) {
-       case XC_SERIAL:
-               n = simple_strtol(str+4, &q, 10);
-               if (q > (str + 4))
-                       xc_num = n;
-               break;
-       case XC_TTY:
-               n = simple_strtol(str+3, &q, 10);
-               if (q > (str + 3))
-                       xc_num = n;
-               break;
-       default:
-               break;
+               str += 3;
        }
 
+       n = simple_strtol(str, &q, 10);
+       if (q != str)
+               xc_num = n;
+
        return 1;
 }
 __setup("xencons=", xencons_setup);
@@ -182,23 +186,30 @@ static struct console kcons_info = {
        .index  = -1,
 };
 
-#define __RETCODE 0
 static int __init xen_console_init(void)
 {
        if (!is_running_on_xen())
-               return __RETCODE;
+               goto out;
 
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
+       if (is_initial_xendomain()) {
                if (xc_mode == XC_DEFAULT)
                        xc_mode = XC_SERIAL;
                kcons_info.write = kcons_write_dom0;
        } else {
+               if (!xen_start_info->console.domU.evtchn)
+                       goto out;
                if (xc_mode == XC_DEFAULT)
-                       xc_mode = XC_TTY;
+                       xc_mode = XC_XVC;
                kcons_info.write = kcons_write;
        }
 
        switch (xc_mode) {
+       case XC_XVC:
+               strcpy(kcons_info.name, "xvc");
+               if (xc_num == -1)
+                       xc_num = 0;
+               break;
+
        case XC_SERIAL:
                strcpy(kcons_info.name, "ttyS");
                if (xc_num == -1)
@@ -212,14 +223,15 @@ static int __init xen_console_init(void)
                break;
 
        default:
-               return __RETCODE;
+               goto out;
        }
 
        wbuf = alloc_bootmem(wbuf_size);
 
        register_console(&kcons_info);
 
-       return __RETCODE;
+ out:
+       return 0;
 }
 console_initcall(xen_console_init);
 
@@ -247,7 +259,9 @@ void xencons_force_flush(void)
        int sz;
 
        /* Emergency console is synchronous, so there's nothing to flush. */
-       if (xen_start_info->flags & SIF_INITDOMAIN)
+       if (!is_running_on_xen() ||
+           is_initial_xendomain() ||
+           !xen_start_info->console.domU.evtchn)
                return;
 
        /* Spin until console data is flushed through to the daemon. */
@@ -262,19 +276,54 @@ void xencons_force_flush(void)
 }
 
 
+void dom0_init_screen_info(const struct dom0_vga_console_info *info)
+{
+       switch (info->video_type) {
+       case XEN_VGATYPE_TEXT_MODE_3:
+               screen_info.orig_video_mode = 3;
+               screen_info.orig_video_ega_bx = 3;
+               screen_info.orig_video_isVGA = 1;
+               screen_info.orig_video_lines = info->u.text_mode_3.rows;
+               screen_info.orig_video_cols = info->u.text_mode_3.columns;
+               screen_info.orig_x = info->u.text_mode_3.cursor_x;
+               screen_info.orig_y = info->u.text_mode_3.cursor_y;
+               screen_info.orig_video_points =
+                       info->u.text_mode_3.font_height;
+               break;
+       case XEN_VGATYPE_VESA_LFB:
+               screen_info.orig_video_isVGA = VIDEO_TYPE_VLFB;
+               screen_info.lfb_width = info->u.vesa_lfb.width;
+               screen_info.lfb_height = info->u.vesa_lfb.height;
+               screen_info.lfb_depth = info->u.vesa_lfb.bits_per_pixel;
+               screen_info.lfb_base = info->u.vesa_lfb.lfb_base;
+               screen_info.lfb_size = info->u.vesa_lfb.lfb_size;
+               screen_info.lfb_linelength = info->u.vesa_lfb.bytes_per_line;
+               screen_info.red_size = info->u.vesa_lfb.red_size;
+               screen_info.red_pos = info->u.vesa_lfb.red_pos;
+               screen_info.green_size = info->u.vesa_lfb.green_size;
+               screen_info.green_pos = info->u.vesa_lfb.green_pos;
+               screen_info.blue_size = info->u.vesa_lfb.blue_size;
+               screen_info.blue_pos = info->u.vesa_lfb.blue_pos;
+               screen_info.rsvd_size = info->u.vesa_lfb.rsvd_size;
+               screen_info.rsvd_pos = info->u.vesa_lfb.rsvd_pos;
+               break;
+       }
+}
+
+
 /******************** User-space console driver (/dev/console) ************/
 
 #define DRV(_d)         (_d)
-#define DUMMY_TTY(_tty) ((xc_mode != XC_SERIAL) &&             \
+#define DUMMY_TTY(_tty) ((xc_mode == XC_TTY) &&                \
                         ((_tty)->index != (xc_num - 1)))
 
-static struct termios *xencons_termios[MAX_NR_CONSOLES];
-static struct termios *xencons_termios_locked[MAX_NR_CONSOLES];
+static struct ktermios *xencons_termios[MAX_NR_CONSOLES];
+static struct ktermios *xencons_termios_locked[MAX_NR_CONSOLES];
 static struct tty_struct *xencons_tty;
 static int xencons_priv_irq;
 static char x_char;
 
-void xencons_rx(char *buf, unsigned len, struct pt_regs *regs)
+void xencons_rx(char *buf, unsigned len)
 {
        int           i;
        unsigned long flags;
@@ -285,7 +334,7 @@ void xencons_rx(char *buf, unsigned len, struct pt_regs *regs)
 
        for (i = 0; i < len; i++) {
 #ifdef CONFIG_MAGIC_SYSRQ
-               if (sysrq_enabled) {
+               if (sysrq_on()) {
                        if (buf[i] == '\x0f') { /* ^O */
                                sysrq_requested = jiffies;
                                continue; /* don't print the sysrq key */
@@ -297,7 +346,7 @@ void xencons_rx(char *buf, unsigned len, struct pt_regs *regs)
                                        spin_unlock_irqrestore(
                                                &xencons_lock, flags);
                                        handle_sysrq(
-                                               buf[i], regs, xencons_tty);
+                                               buf[i], xencons_tty);
                                        spin_lock_irqsave(
                                                &xencons_lock, flags);
                                        continue;
@@ -318,7 +367,7 @@ static void __xencons_tx_flush(void)
        int sent, sz, work_done = 0;
 
        if (x_char) {
-               if (xen_start_info->flags & SIF_INITDOMAIN)
+               if (is_initial_xendomain())
                        kcons_write_dom0(NULL, &x_char, 1);
                else
                        while (x_char)
@@ -332,7 +381,7 @@ static void __xencons_tx_flush(void)
                sz = wp - wc;
                if (sz > (wbuf_size - WBUF_MASK(wc)))
                        sz = wbuf_size - WBUF_MASK(wc);
-               if (xen_start_info->flags & SIF_INITDOMAIN) {
+               if (is_initial_xendomain()) {
                        kcons_write_dom0(NULL, &wbuf[WBUF_MASK(wc)], sz);
                        wc += sz;
                } else {
@@ -362,14 +411,13 @@ void xencons_tx(void)
 }
 
 /* Privileged receive callback and transmit kicker. */
-static irqreturn_t xencons_priv_interrupt(int irq, void *dev_id,
-                                         struct pt_regs *regs)
+static irqreturn_t xencons_priv_interrupt(int irq, void *dev_id)
 {
        static char rbuf[16];
        int         l;
 
        while ((l = HYPERVISOR_console_io(CONSOLEIO_read, 16, rbuf)) > 0)
-               xencons_rx(rbuf, l, regs);
+               xencons_rx(rbuf, l);
 
        xencons_tx();
 
@@ -582,10 +630,14 @@ static int __init xencons_init(void)
        if (xc_mode == XC_OFF)
                return 0;
 
-       xencons_ring_init();
+       if (!is_initial_xendomain()) {
+               rc = xencons_ring_init();
+               if (rc)
+                       return rc;
+       }
 
-       xencons_driver = alloc_tty_driver((xc_mode == XC_SERIAL) ?
-                                         1 : MAX_NR_CONSOLES);
+       xencons_driver = alloc_tty_driver((xc_mode == XC_TTY) ?
+                                         MAX_NR_CONSOLES : 1);
        if (xencons_driver == NULL)
                return -ENOMEM;
 
@@ -600,14 +652,23 @@ static int __init xencons_init(void)
        DRV(xencons_driver)->termios         = xencons_termios;
        DRV(xencons_driver)->termios_locked  = xencons_termios_locked;
 
-       if (xc_mode == XC_SERIAL) {
+       switch (xc_mode) {
+       case XC_XVC:
+               DRV(xencons_driver)->name        = "xvc";
+               DRV(xencons_driver)->major       = XEN_XVC_MAJOR;
+               DRV(xencons_driver)->minor_start = XEN_XVC_MINOR;
+               DRV(xencons_driver)->name_base   = xc_num;
+               break;
+       case XC_SERIAL:
                DRV(xencons_driver)->name        = "ttyS";
                DRV(xencons_driver)->minor_start = 64 + xc_num;
-               DRV(xencons_driver)->name_base   = 0 + xc_num;
-       } else {
+               DRV(xencons_driver)->name_base   = xc_num;
+               break;
+       default:
                DRV(xencons_driver)->name        = "tty";
                DRV(xencons_driver)->minor_start = 1;
                DRV(xencons_driver)->name_base   = 1;
+               break;
        }
 
        tty_set_operations(xencons_driver, &xencons_ops);
@@ -622,7 +683,7 @@ static int __init xencons_init(void)
                return rc;
        }
 
-       if (xen_start_info->flags & SIF_INITDOMAIN) {
+       if (is_initial_xendomain()) {
                xencons_priv_irq = bind_virq_to_irqhandler(
                        VIRQ_CONSOLE,
                        0,
@@ -636,6 +697,15 @@ static int __init xencons_init(void)
        printk("Xen virtual console successfully installed as %s%d\n",
               DRV(xencons_driver)->name, xc_num);
 
+        /* Check about framebuffer messing up the console */
+        if (!is_initial_xendomain() &&
+           !xenbus_exists(XBT_NIL, "device", "vfb")) {
+               /* FIXME: this is ugly */
+               unregister_console(&kcons_info);
+               kcons_info.flags |= CON_CONSDEV;
+               register_console(&kcons_info);
+       }
+
        return 0;
 }