#ifdef CONFIG_VIRTFS
#include "fsdev/qemu-fsdev.h"
#endif
+#include "qtest.h"
#include "disas.h"
if (value) {
if (!strcmp(value, "host")) {
rtc_clock = host_clock;
+ } else if (!strcmp(value, "rt")) {
+ rtc_clock = rt_clock;
} else if (!strcmp(value, "vm")) {
rtc_clock = vm_clock;
} else {
#ifndef CONFIG_LINUX
/* only the linux version is qdev-ified, usb-bsd still needs this */
if (strstart(devname, "host:", &p)) {
- dev = usb_host_device_open(p);
+ dev = usb_host_device_open(usb_bus_find(-1), p);
} else
#endif
if (!strcmp(devname, "bt") || strstart(devname, "bt:", &p)) {
- dev = usb_bt_init(devname[2] ? hci_init(p) :
- bt_new_hci(qemu_find_bt_vlan(0)));
+ dev = usb_bt_init(usb_bus_find(-1),
+ devname[2] ? hci_init(p)
+ : bt_new_hci(qemu_find_bt_vlan(0)));
} else {
return -1;
}
return NULL;
}
-static QEMUMachine *find_default_machine(void)
+QEMUMachine *find_default_machine(void)
{
QEMUMachine *m;
static pid_t shutdown_pid;
static int powerdown_requested;
static int debug_requested;
+static int suspend_requested;
+static bool is_suspended;
+static NotifierList suspend_notifiers =
+ NOTIFIER_LIST_INITIALIZER(suspend_notifiers);
+static NotifierList wakeup_notifiers =
+ NOTIFIER_LIST_INITIALIZER(wakeup_notifiers);
+static uint32_t wakeup_reason_mask = ~0;
static RunState vmstop_requested = RUN_STATE_MAX;
int qemu_shutdown_requested_get(void)
void qemu_kill_report(void)
{
- if (shutdown_signal != -1) {
+ if (!qtest_enabled() && shutdown_signal != -1) {
fprintf(stderr, "qemu: terminating on signal %d", shutdown_signal);
if (shutdown_pid == 0) {
/* This happens for eg ^C at the terminal, so it's worth
return r;
}
+static int qemu_suspend_requested(void)
+{
+ int r = suspend_requested;
+ suspend_requested = 0;
+ return r;
+}
+
int qemu_powerdown_requested(void)
{
int r = powerdown_requested;
qemu_notify_event();
}
+static void qemu_system_suspend(void)
+{
+ pause_all_vcpus();
+ notifier_list_notify(&suspend_notifiers, NULL);
+ monitor_protocol_event(QEVENT_SUSPEND, NULL);
+ is_suspended = true;
+}
+
+void qemu_system_suspend_request(void)
+{
+ if (is_suspended) {
+ return;
+ }
+ suspend_requested = 1;
+ cpu_stop_current();
+ qemu_notify_event();
+}
+
+void qemu_register_suspend_notifier(Notifier *notifier)
+{
+ notifier_list_add(&suspend_notifiers, notifier);
+}
+
+void qemu_system_wakeup_request(WakeupReason reason)
+{
+ if (!is_suspended) {
+ return;
+ }
+ if (!(wakeup_reason_mask & (1 << reason))) {
+ return;
+ }
+ monitor_protocol_event(QEVENT_WAKEUP, NULL);
+ notifier_list_notify(&wakeup_notifiers, &reason);
+ reset_requested = 1;
+ qemu_notify_event();
+ is_suspended = false;
+}
+
+void qemu_system_wakeup_enable(WakeupReason reason, bool enabled)
+{
+ if (enabled) {
+ wakeup_reason_mask |= (1 << reason);
+ } else {
+ wakeup_reason_mask &= ~(1 << reason);
+ }
+}
+
+void qemu_register_wakeup_notifier(Notifier *notifier)
+{
+ notifier_list_add(&wakeup_notifiers, notifier);
+}
+
void qemu_system_killed(int signal, pid_t pid)
{
shutdown_signal = signal;
if (qemu_debug_requested()) {
vm_stop(RUN_STATE_DEBUG);
}
+ if (qemu_suspend_requested()) {
+ qemu_system_suspend();
+ }
if (qemu_shutdown_requested()) {
qemu_kill_report();
monitor_protocol_event(QEVENT_SHUTDOWN, NULL);
DEV_PARALLEL, /* -parallel */
DEV_VIRTCON, /* -virtioconsole */
DEV_DEBUGCON, /* -debugcon */
+ DEV_GDB, /* -gdb, -s */
} type;
const char *cmdline;
+ Location loc;
QTAILQ_ENTRY(device_config) next;
};
QTAILQ_HEAD(, device_config) device_configs = QTAILQ_HEAD_INITIALIZER(device_configs);
conf = g_malloc0(sizeof(*conf));
conf->type = type;
conf->cmdline = cmdline;
+ loc_save(&conf->loc);
QTAILQ_INSERT_TAIL(&device_configs, conf, next);
}
QTAILQ_FOREACH(conf, &device_configs, next) {
if (conf->type != type)
continue;
+ loc_push_restore(&conf->loc);
rc = func(conf->cmdline);
+ loc_pop(&conf->loc);
if (0 != rc)
return rc;
}
printf("Supported machines are:\n");
for (m = first_machine; m != NULL; m = m->next) {
if (m->alias) {
- printf("%-10s %s (alias of %s)\n", m->alias, m->desc, m->name);
+ printf("%-20s %s (alias of %s)\n", m->alias, m->desc, m->name);
}
- printf("%-10s %s%s\n", m->name, m->desc,
+ printf("%-20s %s%s\n", m->name, m->desc,
m->is_default ? " (default)" : "");
}
exit(!name || *name != '?');
{ "tcg", "tcg", tcg_available, tcg_init, &tcg_allowed },
{ "xen", "Xen", xen_available, xen_init, &xen_allowed },
{ "kvm", "KVM", kvm_available, kvm_init, &kvm_allowed },
+ { "qtest", "QTest", qtest_available, qtest_init, &qtest_allowed },
};
static int configure_accelerator(void)
void qemu_remove_exit_notifier(Notifier *notify)
{
- notifier_list_remove(&exit_notifiers, notify);
+ notifier_remove(notify);
}
static void qemu_run_exit_notifiers(void)
int main(int argc, char **argv, char **envp)
{
- const char *gdbstub_dev = NULL;
int i;
int snapshot, linux_boot;
const char *icount_option = NULL;
DisplayState *ds;
DisplayChangeListener *dcl;
int cyls, heads, secs, translation;
- QemuOpts *hda_opts = NULL, *opts;
+ QemuOpts *hda_opts = NULL, *opts, *machine_opts;
QemuOptsList *olist;
int optind;
const char *optarg;
#endif
}
+ module_call_init(MODULE_INIT_QOM);
+
runstate_init();
init_clocks();
module_call_init(MODULE_INIT_MACHINE);
machine = find_default_machine();
cpu_model = NULL;
- initrd_filename = NULL;
ram_size = 0;
snapshot = 0;
- kernel_filename = NULL;
- kernel_cmdline = "";
cyls = heads = secs = 0;
translation = BIOS_ATA_TRANSLATION_AUTO;
exit(1);
}
}
- cpudef_init();
/* second pass of option parsing */
optind = 1;
break;
case QEMU_OPTION_cpu:
/* hw initialization will check this */
- if (*optarg == '?') {
- list_cpus(stdout, &fprintf, optarg);
- exit(0);
- } else {
- cpu_model = optarg;
- }
- break;
- case QEMU_OPTION_initrd:
- initrd_filename = optarg;
+ cpu_model = optarg;
break;
case QEMU_OPTION_hda:
{
}
break;
case QEMU_OPTION_kernel:
- kernel_filename = optarg;
+ qemu_opts_set(qemu_find_opts("machine"), 0, "kernel", optarg);
+ break;
+ case QEMU_OPTION_initrd:
+ qemu_opts_set(qemu_find_opts("machine"), 0, "initrd", optarg);
break;
case QEMU_OPTION_append:
- kernel_cmdline = optarg;
+ qemu_opts_set(qemu_find_opts("machine"), 0, "append", optarg);
+ break;
+ case QEMU_OPTION_dtb:
+ qemu_opts_set(qemu_find_opts("machine"), 0, "dtb", optarg);
break;
case QEMU_OPTION_cdrom:
drive_add(IF_DEFAULT, 2, optarg, CDROM_OPTS);
log_file = optarg;
break;
case QEMU_OPTION_s:
- gdbstub_dev = "tcp::" DEFAULT_GDBSTUB_PORT;
+ add_device_config(DEV_GDB, "tcp::" DEFAULT_GDBSTUB_PORT);
break;
case QEMU_OPTION_gdb:
- gdbstub_dev = optarg;
+ add_device_config(DEV_GDB, optarg);
break;
case QEMU_OPTION_L:
data_dir = optarg;
break;
case QEMU_OPTION_incoming:
incoming = optarg;
+ runstate_set(RUN_STATE_INMIGRATE);
break;
case QEMU_OPTION_nodefaults:
default_serial = 0;
fclose(fp);
break;
}
+ case QEMU_OPTION_qtest:
+ qtest_chrdev = optarg;
+ break;
+ case QEMU_OPTION_qtest_log:
+ qtest_log = optarg;
+ break;
default:
os_parse_cmd_args(popt->index, optarg);
}
}
loc_set_none();
+ /* Init CPU def lists, based on config
+ * - Must be called after all the qemu_read_config_file() calls
+ * - Must be called before list_cpus()
+ * - Must be called before machine->init()
+ */
+ cpudef_init();
+
+ if (cpu_model && *cpu_model == '?') {
+ list_cpus(stdout, &fprintf, cpu_model);
+ exit(0);
+ }
+
/* Open the logfile at this point, if necessary. We can't open the logfile
* when encountering either of the logging options (-d or -D) because the
* other one may be encountered later on the command line, changing the
fprintf(stderr, "qemu_init_main_loop failed\n");
exit(1);
}
+
+ machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
+ if (machine_opts) {
+ kernel_filename = qemu_opt_get(machine_opts, "kernel");
+ initrd_filename = qemu_opt_get(machine_opts, "initrd");
+ kernel_cmdline = qemu_opt_get(machine_opts, "append");
+ } else {
+ kernel_filename = initrd_filename = kernel_cmdline = NULL;
+ }
+
+ if (!kernel_cmdline) {
+ kernel_cmdline = "";
+ }
+
linux_boot = (kernel_filename != NULL);
if (!linux_boot && *kernel_cmdline != '\0') {
exit(1);
}
+ if (!linux_boot && machine_opts && qemu_opt_get(machine_opts, "dtb")) {
+ fprintf(stderr, "-dtb only allowed with -kernel option\n");
+ exit(1);
+ }
+
os_set_line_buffering();
if (init_timer_alarm() < 0) {
exit(1);
}
+#ifdef CONFIG_SPICE
+ /* spice needs the timers to be initialized by this point */
+ qemu_spice_init();
+#endif
+
if (icount_option && (kvm_enabled() || xen_enabled())) {
fprintf(stderr, "-icount is not allowed with kvm or xen\n");
exit(1);
if (foreach_device_config(DEV_DEBUGCON, debugcon_parse) < 0)
exit(1);
- module_call_init(MODULE_INIT_QOM);
-
/* must be after qdev registration but before machine init */
if (vga_model) {
select_vgahw(vga_model);
}
text_consoles_set_display(ds);
- if (gdbstub_dev && gdbserver_start(gdbstub_dev) < 0) {
- fprintf(stderr, "qemu: could not open gdbserver on device '%s'\n",
- gdbstub_dev);
+ if (foreach_device_config(DEV_GDB, gdbserver_start) < 0) {
exit(1);
}
}
if (incoming) {
- runstate_set(RUN_STATE_INMIGRATE);
int ret = qemu_start_incoming_migration(incoming);
if (ret < 0) {
fprintf(stderr, "Migration failed. Exit code %s(%d), exiting.\n",