From: Sasha Levin Date: Wed, 5 Sep 2012 08:31:58 +0000 (+0200) Subject: kvm tools: ui improvements X-Git-Tag: next-20120910~8^2~5 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=d73b168b3145f7bfe3f0e5d968653a1125b93a4e;p=karo-tx-linux.git kvm tools: ui improvements 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 Signed-off-by: Pekka Enberg --- diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c index 56639e25b380..1ad574d75030 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 09512d5d75f9..6f2d9f410767 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 1f06df32b35b..5e7dc282455d 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 36e5986d9cee..b44433375689 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 3278c078b828..c2934a45f6dc 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 33c25826a17d..a041b3b84d54 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 #include #include +#include #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 91254c561d94..d445059929b2 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 #include #include #include +#include #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); +}