[PATCH 3/3] kvm tools: allow arch's to provide their own command-line options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently, only x86 has architecture command-line options (for setting
the BIOS video mode) however this is likely to become more common in the
future.

This patch adds some simple macros and a struct definition to allow
architectures to augment the command-line options with private
definitions. The BIOS video mode option (--vidmode) is also migrated to
the new framework.

Signed-off-by: Will Deacon <will.deacon@xxxxxxx>
---
 tools/kvm/arm/fdt.c                             |  4 ++--
 tools/kvm/arm/include/kvm/kvm-config-arch.h     |  7 +++++++
 tools/kvm/builtin-run.c                         | 21 ++++++---------------
 tools/kvm/include/kvm/kvm-config.h              |  3 ++-
 tools/kvm/include/kvm/kvm.h                     |  4 ++--
 tools/kvm/include/kvm/parse-options.h           |  3 +++
 tools/kvm/kvm.c                                 |  6 +++---
 tools/kvm/powerpc/include/kvm/kvm-config-arch.h |  7 +++++++
 tools/kvm/powerpc/kvm.c                         |  4 ++--
 tools/kvm/x86/include/kvm/kvm-config-arch.h     | 15 +++++++++++++++
 tools/kvm/x86/kvm.c                             | 16 ++++++++++++++--
 11 files changed, 63 insertions(+), 27 deletions(-)
 create mode 100644 tools/kvm/arm/include/kvm/kvm-config-arch.h
 create mode 100644 tools/kvm/powerpc/include/kvm/kvm-config-arch.h
 create mode 100644 tools/kvm/x86/include/kvm/kvm-config-arch.h

diff --git a/tools/kvm/arm/fdt.c b/tools/kvm/arm/fdt.c
index 8e17d3c..c7f4b52 100644
--- a/tools/kvm/arm/fdt.c
+++ b/tools/kvm/arm/fdt.c
@@ -258,8 +258,8 @@ int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd,
 	return true;
 }
 
-bool load_bzimage(struct kvm *kvm, int fd_kernel,
-		  int fd_initrd, const char *kernel_cmdline, u16 vidmode)
+bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd,
+		  const char *kernel_cmdline)
 {
 	/* To b or not to b? That is the zImage. */
 	return false;
diff --git a/tools/kvm/arm/include/kvm/kvm-config-arch.h b/tools/kvm/arm/include/kvm/kvm-config-arch.h
new file mode 100644
index 0000000..60f61de
--- /dev/null
+++ b/tools/kvm/arm/include/kvm/kvm-config-arch.h
@@ -0,0 +1,7 @@
+#ifndef KVM__KVM_CONFIG_ARCH_H
+#define KVM__KVM_CONFIG_ARCH_H
+
+struct kvm_config_arch {
+};
+
+#endif /* KVM__KVM_CONFIG_ARCH_H */
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 96e68af..d0b876a 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -90,6 +90,10 @@ void kvm_run_set_wrapper_sandbox(void)
 	kvm_run_wrapper = KVM_RUN_SANDBOX;
 }
 
+#ifndef OPT_ARCH_RUN
+#define OPT_ARCH_RUN(...)
+#endif
+
 #define BUILD_OPTIONS(name, cfg, kvm)					\
 	struct option name[] = {					\
 	OPT_GROUP("Basic options:"),					\
@@ -144,10 +148,6 @@ void kvm_run_set_wrapper_sandbox(void)
 	OPT_BOOLEAN('\0', "no-dhcp", &(cfg)->no_dhcp, "Disable kernel"	\
 			" DHCP in rootfs mode"),			\
 									\
-	OPT_GROUP("BIOS options:"),					\
-	OPT_INTEGER('\0', "vidmode", &(cfg)->vidmode,			\
-		    "Video mode"),					\
-									\
 	OPT_GROUP("Debug options:"),					\
 	OPT_BOOLEAN('\0', "debug", &do_debug_print,			\
 			"Enable debug messages"),			\
@@ -159,6 +159,8 @@ void kvm_run_set_wrapper_sandbox(void)
 			"Enable MMIO debugging"),			\
 	OPT_INTEGER('\0', "debug-iodelay", &(cfg)->debug_iodelay,	\
 			"Delay IO by millisecond"),			\
+									\
+	OPT_ARCH(RUN, cfg)						\
 	OPT_END()							\
 	};
 
@@ -598,17 +600,6 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
 	if (!kvm->cfg.script)
 		kvm->cfg.script = DEFAULT_SCRIPT;
 
-	if (!kvm->cfg.vidmode)
-		kvm->cfg.vidmode = -1;
-
-	/* vidmode should be either specified or set by default */
-	if (kvm->cfg.vnc || kvm->cfg.sdl) {
-		if (kvm->cfg.vidmode == -1)
-			kvm->cfg.vidmode = 0x312;
-	} else {
-		kvm->cfg.vidmode = 0;
-	}
-
 	if (!kvm->cfg.network)
                 kvm->cfg.network = DEFAULT_NETWORK;
 
diff --git a/tools/kvm/include/kvm/kvm-config.h b/tools/kvm/include/kvm/kvm-config.h
index df36a76..c66f481 100644
--- a/tools/kvm/include/kvm/kvm-config.h
+++ b/tools/kvm/include/kvm/kvm-config.h
@@ -2,6 +2,7 @@
 #define KVM_CONFIG_H_
 
 #include "kvm/disk-image.h"
+#include "kvm/kvm-config-arch.h"
 
 #define DEFAULT_KVM_DEV		"/dev/kvm"
 #define DEFAULT_CONSOLE		"serial"
@@ -17,6 +18,7 @@
 #define MIN_RAM_SIZE_BYTE	(MIN_RAM_SIZE_MB << MB_SHIFT)
 
 struct kvm_config {
+	struct kvm_config_arch arch;
 	struct disk_image_params disk_image[MAX_DISK_IMAGES];
 	u64 ram_size;
 	u8  image_count;
@@ -25,7 +27,6 @@ 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/kvm.h b/tools/kvm/include/kvm/kvm.h
index b54ac03..acb0818 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -78,7 +78,7 @@ void kvm__init_ram(struct kvm *kvm);
 int kvm__exit(struct kvm *kvm);
 bool kvm__load_firmware(struct kvm *kvm, const char *firmware_filename);
 bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
-			const char *initrd_filename, const char *kernel_cmdline, u16 vidmode);
+			const char *initrd_filename, const char *kernel_cmdline);
 int kvm_timer__init(struct kvm *kvm);
 int kvm_timer__exit(struct kvm *kvm);
 void kvm__irq_line(struct kvm *kvm, int irq, int level);
@@ -109,7 +109,7 @@ void *guest_flat_to_host(struct kvm *kvm, u64 offset);
 u64 host_to_guest_flat(struct kvm *kvm, void *ptr);
 
 int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline);
-bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline, u16 vidmode);
+bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *kernel_cmdline);
 
 /*
  * Debugging
diff --git a/tools/kvm/include/kvm/parse-options.h b/tools/kvm/include/kvm/parse-options.h
index cc188b9..09a5fca 100644
--- a/tools/kvm/include/kvm/parse-options.h
+++ b/tools/kvm/include/kvm/parse-options.h
@@ -191,6 +191,9 @@ struct option {
 
 #define OPT_END() { .type = OPTION_END }
 
+#define OPT_ARCH(cmd, cfg)		    \
+	OPT_ARCH_##cmd(OPT_GROUP("Arch-specific options:"), &(cfg)->arch)
+
 enum {
 	PARSE_OPT_HELP = -1,
 	PARSE_OPT_DONE,
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index af19e37..3ea6339 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -303,7 +303,7 @@ int kvm__init(struct kvm *kvm)
 
 	if (!kvm->cfg.firmware_filename) {
 		if (!kvm__load_kernel(kvm, kvm->cfg.kernel_filename,
-				kvm->cfg.initrd_filename, kvm->cfg.real_cmdline, kvm->cfg.vidmode))
+				kvm->cfg.initrd_filename, kvm->cfg.real_cmdline))
 			die("unable to load kernel %s", kvm->cfg.kernel_filename);
 	}
 
@@ -349,7 +349,7 @@ static bool initrd_check(int fd)
 }
 
 bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
-		const char *initrd_filename, const char *kernel_cmdline, u16 vidmode)
+		const char *initrd_filename, const char *kernel_cmdline)
 {
 	bool ret;
 	int fd_kernel = -1, fd_initrd = -1;
@@ -367,7 +367,7 @@ bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
 			die("%s is not an initrd", initrd_filename);
 	}
 
-	ret = load_bzimage(kvm, fd_kernel, fd_initrd, kernel_cmdline, vidmode);
+	ret = load_bzimage(kvm, fd_kernel, fd_initrd, kernel_cmdline);
 
 	if (ret)
 		goto found_kernel;
diff --git a/tools/kvm/powerpc/include/kvm/kvm-config-arch.h b/tools/kvm/powerpc/include/kvm/kvm-config-arch.h
new file mode 100644
index 0000000..60f61de
--- /dev/null
+++ b/tools/kvm/powerpc/include/kvm/kvm-config-arch.h
@@ -0,0 +1,7 @@
+#ifndef KVM__KVM_CONFIG_ARCH_H
+#define KVM__KVM_CONFIG_ARCH_H
+
+struct kvm_config_arch {
+};
+
+#endif /* KVM__KVM_CONFIG_ARCH_H */
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index d8dfc01..dc9f89d 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -204,8 +204,8 @@ int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *
 	return true;
 }
 
-bool load_bzimage(struct kvm *kvm, int fd_kernel,
-		  int fd_initrd, const char *kernel_cmdline, u16 vidmode)
+bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd,
+		  const char *kernel_cmdline)
 {
 	/* We don't support bzImages. */
 	return false;
diff --git a/tools/kvm/x86/include/kvm/kvm-config-arch.h b/tools/kvm/x86/include/kvm/kvm-config-arch.h
new file mode 100644
index 0000000..3eae8db
--- /dev/null
+++ b/tools/kvm/x86/include/kvm/kvm-config-arch.h
@@ -0,0 +1,15 @@
+#ifndef KVM__KVM_CONFIG_ARCH_H
+#define KVM__KVM_CONFIG_ARCH_H
+
+#include "kvm/parse-options.h"
+
+struct kvm_config_arch {
+	int vidmode;
+};
+
+#define OPT_ARCH_RUN(pfx, cfg)						\
+	pfx,								\
+	OPT_GROUP("BIOS options:"),					\
+	OPT_INTEGER('\0', "vidmode", &(cfg)->vidmode, "Video mode"),
+
+#endif /* KVM__KVM_CONFIG_ARCH_H */
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index 9971ffd..687e6b7 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -235,8 +235,8 @@ int load_flat_binary(struct kvm *kvm, int fd_kernel, int fd_initrd, const char *
 
 static const char *BZIMAGE_MAGIC = "HdrS";
 
-bool load_bzimage(struct kvm *kvm, int fd_kernel,
-		  int fd_initrd, const char *kernel_cmdline, u16 vidmode)
+bool load_bzimage(struct kvm *kvm, int fd_kernel, int fd_initrd,
+		  const char *kernel_cmdline)
 {
 	struct boot_params *kern_boot;
 	unsigned long setup_sects;
@@ -245,6 +245,7 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel,
 	ssize_t setup_size;
 	void *p;
 	int nr;
+	u16 vidmode;
 
 	/*
 	 * See Documentation/x86/boot.txt for details no bzImage on-disk and
@@ -293,6 +294,17 @@ bool load_bzimage(struct kvm *kvm, int fd_kernel,
 		memcpy(p, kernel_cmdline, cmdline_size - 1);
 	}
 
+	if (!kvm->cfg.arch.vidmode)
+		vidmode = -1;
+
+	/* vidmode should be either specified or set by default */
+	if (kvm->cfg.vnc || kvm->cfg.sdl) {
+		if (vidmode == -1)
+			vidmode = 0x312;
+	} else {
+		vidmode = 0;
+	}
+
 	kern_boot	= guest_real_to_host(kvm, BOOT_LOADER_SELECTOR, 0x00);
 
 	kern_boot->hdr.cmd_line_ptr	= BOOT_CMDLINE_OFFSET;
-- 
1.8.0

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux