@@ -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);
@@ -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);
@@ -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;
@@ -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)");
}
@@ -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;
}
@@ -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);
}
@@ -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);
+}
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(-)