mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-08-23 22:46:05 +00:00
kvm tools: allow arch's to provide their own command-line options
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@arm.com> Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
+6
-15
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
+2
-2
@@ -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;
|
||||
|
||||
@@ -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 */
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user