diff mbox

[24/33] kvm tools: ui improvements

Message ID 1346833927-15740-25-git-send-email-levinsasha928@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Sasha Levin Sept. 5, 2012, 8:31 a.m. UTC
Move the vesa initialization logic into sdl__init() and vnc__init(), builtin-run
shouldn't have to know about the conditions for initializing vesa on it's own.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 tools/kvm/builtin-run.c            | 49 ++++++++++----------------------------
 tools/kvm/hw/vesa.c                |  3 +++
 tools/kvm/include/kvm/kvm-config.h |  1 +
 tools/kvm/include/kvm/sdl.h        |  8 +++----
 tools/kvm/include/kvm/vnc.h        | 10 ++++----
 tools/kvm/ui/sdl.c                 | 19 ++++++++++++---
 tools/kvm/ui/vnc.c                 | 21 ++++++++++++----
 7 files changed, 60 insertions(+), 51 deletions(-)
diff mbox

Patch

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 96a3d70..c59f100 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -60,8 +60,6 @@  static int  kvm_run_wrapper;
 
 bool do_debug_print = false;
 
-static int vidmode = -1;
-
 extern char _binary_guest_init_start;
 extern char _binary_guest_init_size;
 
@@ -201,7 +199,7 @@  static int virtio_9p_rootdir_parser(const struct option *opt, const char *arg, i
 			in rootfs mode"),				\
 									\
 	OPT_GROUP("BIOS options:"),					\
-	OPT_INTEGER('\0', "vidmode", &vidmode,				\
+	OPT_INTEGER('\0', "vidmode", &(cfg)->vidmode,			\
 		    "Video mode"),					\
 									\
 	OPT_GROUP("Debug options:"),					\
@@ -530,7 +528,6 @@  static void kvm_run_write_sandbox_cmd(const char **argv, int argc)
 static int kvm_cmd_run_init(int argc, const char **argv)
 {
 	static char real_cmdline[2048], default_name[20];
-	struct framebuffer *fb = NULL;
 	unsigned int nr_online_cpus;
 	int r;
 
@@ -642,6 +639,9 @@  static int kvm_cmd_run_init(int argc, const char **argv)
 	if (!kvm->cfg.script)
 		kvm->cfg.script = DEFAULT_SCRIPT;
 
+	if (!kvm->cfg.vnc && !kvm->cfg.sdl)
+		kvm->cfg.vidmode = -1;
+
 	r = term_init(kvm);
 	if (r < 0) {
 		pr_err("term_init() failed with error %d\n", r);
@@ -691,17 +691,6 @@  static int kvm_cmd_run_init(int argc, const char **argv)
 		goto fail;
 	}
 
-	/*
-	 * vidmode should be either specified
-	 * either set by default
-	 */
-	if (kvm->cfg.vnc || kvm->cfg.sdl) {
-		if (vidmode == -1)
-			vidmode = 0x312;
-	} else {
-		vidmode = 0;
-	}
-
 	memset(real_cmdline, 0, sizeof(real_cmdline));
 	kvm__arch_set_cmdline(real_cmdline, kvm->cfg.vnc || kvm->cfg.sdl);
 
@@ -752,7 +741,7 @@  static int kvm_cmd_run_init(int argc, const char **argv)
 
 	if (!kvm->cfg.firmware_filename) {
 		if (!kvm__load_kernel(kvm, kvm->cfg.kernel_filename,
-				kvm->cfg.initrd_filename, real_cmdline, vidmode))
+				kvm->cfg.initrd_filename, real_cmdline, kvm->cfg.vidmode))
 			die("unable to load kernel %s", kvm->cfg.kernel_filename);
 
 		kvm->vmlinux = kvm->cfg.vmlinux_filename;
@@ -830,28 +819,16 @@  static int kvm_cmd_run_init(int argc, const char **argv)
 		goto fail;
 	}
 
-	if (kvm->cfg.vnc || kvm->cfg.sdl) {
-		fb = vesa__init(kvm);
-		if (IS_ERR(fb)) {
-			pr_err("vesa__init() failed with error %ld\n", PTR_ERR(fb));
-			goto fail;
-		}
-	}
-
-	if (kvm->cfg.vnc && fb) {
-		r = vnc__init(fb);
-		if (r < 0) {
-			pr_err("vnc__init() failed with error %d\n", r);
-			goto fail;
-		}
+	r = vnc__init(kvm);
+	if (r < 0) {
+		pr_err("vnc__init() failed with error %d\n", r);
+		goto fail;
 	}
 
-	if (kvm->cfg.sdl && fb) {
-		sdl__init(fb);
-		if (r < 0) {
-			pr_err("sdl__init() failed with error %d\n", r);
-			goto fail;
-		}
+	r = sdl__init(kvm);
+	if (r < 0) {
+		pr_err("sdl__init() failed with error %d\n", r);
+		goto fail;
 	}
 
 	r = fb__init(kvm);
diff --git a/tools/kvm/hw/vesa.c b/tools/kvm/hw/vesa.c
index 09512d5..6f2d9f4 100644
--- a/tools/kvm/hw/vesa.c
+++ b/tools/kvm/hw/vesa.c
@@ -53,6 +53,9 @@  struct framebuffer *vesa__init(struct kvm *kvm)
 	char *mem;
 	int r;
 
+	if (!kvm->cfg.vnc && !kvm->cfg.sdl)
+		return NULL;
+
 	r = irq__register_device(PCI_DEVICE_ID_VESA, &dev, &pin, &line);
 	if (r < 0)
 		return ERR_PTR(r);
diff --git a/tools/kvm/include/kvm/kvm-config.h b/tools/kvm/include/kvm/kvm-config.h
index 1f06df3..5e7dc28 100644
--- a/tools/kvm/include/kvm/kvm-config.h
+++ b/tools/kvm/include/kvm/kvm-config.h
@@ -25,6 +25,7 @@  struct kvm_config {
 	int active_console;
 	int debug_iodelay;
 	int nrcpus;
+	int vidmode;
 	const char *kernel_cmdline;
 	const char *kernel_filename;
 	const char *vmlinux_filename;
diff --git a/tools/kvm/include/kvm/sdl.h b/tools/kvm/include/kvm/sdl.h
index 36e5986..b444333 100644
--- a/tools/kvm/include/kvm/sdl.h
+++ b/tools/kvm/include/kvm/sdl.h
@@ -6,14 +6,14 @@ 
 struct framebuffer;
 
 #ifdef CONFIG_HAS_SDL
-int sdl__init(struct framebuffer *fb);
-int sdl__exit(struct framebuffer *fb);
+int sdl__init(struct kvm *kvm);
+int sdl__exit(struct kvm *kvm);
 #else
-static inline void sdl__init(struct framebuffer *fb)
+static inline void sdl__init(struct kvm *kvm)
 {
 	die("SDL support not compiled in. (install the SDL-dev[el] package)");
 }
-static inline void sdl__exit(struct framebuffer *fb)
+static inline void sdl__exit(struct kvm *kvm)
 {
 	die("SDL support not compiled in. (install the SDL-dev[el] package)");
 }
diff --git a/tools/kvm/include/kvm/vnc.h b/tools/kvm/include/kvm/vnc.h
index 3278c07..c2934a4 100644
--- a/tools/kvm/include/kvm/vnc.h
+++ b/tools/kvm/include/kvm/vnc.h
@@ -1,17 +1,19 @@ 
 #ifndef KVM__VNC_H
 #define KVM__VNC_H
 
+#include "kvm/kvm.h"
+
 struct framebuffer;
 
 #ifdef CONFIG_HAS_VNCSERVER
-int vnc__init(struct framebuffer *fb);
-int vnc__exit(struct framebuffer *fb);
+int vnc__init(struct kvm *kvm);
+int vnc__exit(struct kvm *kvm);
 #else
-static inline int vnc__init(struct framebuffer *fb)
+static inline int vnc__init(struct kvm *kvm)
 {
 	return 0;
 }
-static inline int vnc__exit(struct framebuffer *fb)
+static inline int vnc__exit(struct kvm *kvm)
 {
 	return 0;
 }
diff --git a/tools/kvm/ui/sdl.c b/tools/kvm/ui/sdl.c
index 33c2582..a041b3b 100644
--- a/tools/kvm/ui/sdl.c
+++ b/tools/kvm/ui/sdl.c
@@ -5,10 +5,12 @@ 
 #include "kvm/util.h"
 #include "kvm/kvm.h"
 #include "kvm/kvm-cpu.h"
+#include "kvm/vesa.h"
 
 #include <SDL/SDL.h>
 #include <pthread.h>
 #include <signal.h>
+#include <linux/err.h>
 
 #define FRAME_RATE		25
 
@@ -292,12 +294,23 @@  static struct fb_target_operations sdl_ops = {
 	.stop	= sdl__stop,
 };
 
-int sdl__init(struct framebuffer *fb)
+int sdl__init(struct kvm *kvm)
 {
+	struct framebuffer *fb;
+
+	if (!kvm->cfg.sdl)
+		return 0;
+
+	fb = vesa__init(kvm);
+	if (IS_ERR(fb)) {
+		pr_err("vesa__init() failed with error %ld\n", PTR_ERR(fb));
+		return PTR_ERR(fb);
+	}
+
 	return fb__attach(fb, &sdl_ops);
 }
 
-int sdl__exit(struct framebuffer *fb)
+int sdl__exit(struct kvm *kvm)
 {
-	return sdl__stop(fb);
+	return sdl__stop(NULL);
 }
diff --git a/tools/kvm/ui/vnc.c b/tools/kvm/ui/vnc.c
index 91254c5..d445059 100644
--- a/tools/kvm/ui/vnc.c
+++ b/tools/kvm/ui/vnc.c
@@ -2,11 +2,13 @@ 
 
 #include "kvm/framebuffer.h"
 #include "kvm/i8042.h"
+#include "kvm/vesa.h"
 
 #include <linux/types.h>
 #include <rfb/keysym.h>
 #include <rfb/rfb.h>
 #include <pthread.h>
+#include <linux/err.h>
 
 #define VESA_QUEUE_SIZE		128
 #define VESA_IRQ		14
@@ -219,12 +221,23 @@  static struct fb_target_operations vnc_ops = {
 	.stop	= vnc__stop,
 };
 
-int vnc__init(struct framebuffer *fb)
+int vnc__init(struct kvm *kvm)
 {
+	struct framebuffer *fb;
+
+	if (!kvm->cfg.vnc)
+		return 0;
+
+	fb = vesa__init(kvm);
+	if (IS_ERR(fb)) {
+		pr_err("vesa__init() failed with error %ld\n", PTR_ERR(fb));
+		return PTR_ERR(fb);
+	}
+
 	return fb__attach(fb, &vnc_ops);
 }
 
-int vnc__exit(struct framebuffer *fb)
+int vnc__exit(struct kvm *kvm)
 {
-	return vnc__stop(fb);
-}
\ No newline at end of file
+	return vnc__stop(NULL);
+}