#include "qom/object.h"
#include "qemu/error-report.h"
#include "qemu/option.h"
+#include "qapi/error.h"
static const TypeInfo accel_type = {
.name = TYPE_ACCEL,
ms->accelerator = NULL;
*(acc->allowed) = false;
object_unref(OBJECT(accel));
+ } else {
+ object_set_accelerator_compat_props(acc->compat_props);
}
return ret;
}
-void configure_accelerator(MachineState *ms)
+void configure_accelerator(MachineState *ms, const char *progname)
{
- const char *accel, *p;
- char buf[10];
+ const char *accel;
+ char **accel_list, **tmp;
int ret;
bool accel_initialised = false;
bool init_failed = false;
accel = qemu_opt_get(qemu_get_machine_opts(), "accel");
if (accel == NULL) {
- /* Use the default "accelerator", tcg */
- accel = "tcg";
+ /* Select the default accelerator */
+ int pnlen = strlen(progname);
+ if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) {
+ /* If the program name ends with "kvm", we prefer KVM */
+ accel = "kvm:tcg";
+ } else {
+#if defined(CONFIG_TCG)
+ accel = "tcg";
+#elif defined(CONFIG_KVM)
+ accel = "kvm";
+#else
+ error_report("No accelerator selected and"
+ " no default accelerator available");
+ exit(1);
+#endif
+ }
}
- p = accel;
- while (!accel_initialised && *p != '\0') {
- if (*p == ':') {
- p++;
- }
- p = get_opt_name(buf, sizeof(buf), p, ':');
- acc = accel_find(buf);
+ accel_list = g_strsplit(accel, ":", 0);
+
+ for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) {
+ acc = accel_find(*tmp);
if (!acc) {
continue;
}
- if (acc->available && !acc->available()) {
- printf("%s not supported for this target\n",
- acc->name);
- continue;
- }
ret = accel_init_machine(acc, ms);
if (ret < 0) {
init_failed = true;
accel_initialised = true;
}
}
+ g_strfreev(accel_list);
if (!accel_initialised) {
if (!init_failed) {
}
}
-void accel_register_compat_props(AccelState *accel)
+void accel_setup_post(MachineState *ms)
{
- AccelClass *class = ACCEL_GET_CLASS(accel);
- register_compat_props_array(class->global_props);
+ AccelState *accel = ms->accelerator;
+ AccelClass *acc = ACCEL_GET_CLASS(accel);
+ if (acc->setup_post) {
+ acc->setup_post(ms, accel);
+ }
}
static void register_accel_types(void)