From patchwork Wed Sep 5 08:31:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 1406681 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 7204A3FC71 for ; Wed, 5 Sep 2012 08:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758219Ab2IEIgr (ORCPT ); Wed, 5 Sep 2012 04:36:47 -0400 Received: from mail-wg0-f44.google.com ([74.125.82.44]:58173 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758159Ab2IEIgW (ORCPT ); Wed, 5 Sep 2012 04:36:22 -0400 Received: by mail-wg0-f44.google.com with SMTP id dr13so393355wgb.1 for ; Wed, 05 Sep 2012 01:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=dbWTkuZCsbqPoM3/lvTaLnmJOpwP+eDb2VK5J10TL84=; b=KsJCPxW01Vhpnom9EWEeCICB5hlym+shiTVSawVx+qhhHSCW0nwmnUxN1SaoUZDxlQ JHQ6D8n23yg9VH9NNee5D31JdrSILgth7ARt68DrlUA0XWg7Tc7MbdyAAw+1V4Px7tVm 1KT6Ue3ojQGCoF6mn6wWHVFUmAeEmkHRMY1OdE1Zm1co4eUuUFaraqlk9r+ZVJVh949c YlFLokn9M9AaaCbXHe1kj967o8gCnnsm267OkHiYDx8dx0CSpSI/kzvIx55LEsHJYt3F xCMq1D01Eb68ScybZb8nmbXOyi7xyCVHH64Ie6fn/rDDNzATjkcrVI8++wq22cwSJIzD TzOw== Received: by 10.180.81.38 with SMTP id w6mr36433638wix.10.1346834182057; Wed, 05 Sep 2012 01:36:22 -0700 (PDT) Received: from lappy.capriciverd.com (20.Red-80-59-140.staticIP.rima-tde.net. [80.59.140.20]) by mx.google.com with ESMTPS id q4sm27971068wix.9.2012.09.05.01.36.20 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 05 Sep 2012 01:36:21 -0700 (PDT) From: Sasha Levin To: penberg@kernel.org Cc: asias.hejun@gmail.com, mingo@elte.hu, gorcunov@openvz.org, kvm@vger.kernel.org, Sasha Levin Subject: [PATCH 24/33] kvm tools: ui improvements Date: Wed, 5 Sep 2012 10:31:58 +0200 Message-Id: <1346833927-15740-25-git-send-email-levinsasha928@gmail.com> X-Mailer: git-send-email 1.7.12 In-Reply-To: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> References: <1346833927-15740-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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 --- 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 --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 #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 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 #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); +}