]> xenbits.xensource.com Git - qemu-upstream-4.6-testing.git/commitdiff
accel: Create accel object when initializing machine
authorEduardo Habkost <ehabkost@redhat.com>
Fri, 26 Sep 2014 20:45:31 +0000 (17:45 -0300)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 9 Oct 2014 13:36:14 +0000 (15:36 +0200)
Create an actual TYPE_ACCEL object when initializing a machine. This
will allow accelerator classes to implement some initialization on
instance_init, and to save state on the TYPE_ACCEL object.

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
accel.c
include/hw/boards.h

diff --git a/accel.c b/accel.c
index 6087ab32b72cec61800b15289af041ab52dbb42d..74e41daaa5d86de944ba1a913ce7d7fe5d878b6d 100644 (file)
--- a/accel.c
+++ b/accel.c
@@ -32,6 +32,7 @@
 #include "sysemu/qtest.h"
 #include "hw/xen/xen.h"
 #include "qom/object.h"
+#include "hw/boards.h"
 
 int tcg_tb_size;
 static bool tcg_allowed = true;
@@ -60,11 +61,17 @@ static AccelClass *accel_find(const char *opt_name)
 
 static int accel_init_machine(AccelClass *acc, MachineState *ms)
 {
+    ObjectClass *oc = OBJECT_CLASS(acc);
+    const char *cname = object_class_get_name(oc);
+    AccelState *accel = ACCEL(object_new(cname));
     int ret;
+    ms->accelerator = accel;
     *(acc->allowed) = true;
     ret = acc->init_machine(ms);
     if (ret < 0) {
+        ms->accelerator = NULL;
         *(acc->allowed) = false;
+        object_unref(OBJECT(accel));
     }
     return ret;
 }
index 0058c49d8d7bac9f8edf387fbf0f2913ff717400..6a60c3cf976270f24c78541bbe212a051cdbb999 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "qemu/typedefs.h"
 #include "sysemu/blockdev.h"
+#include "sysemu/accel.h"
 #include "hw/qdev.h"
 #include "qom/object.h"
 
@@ -131,6 +132,7 @@ struct MachineState {
     char *kernel_cmdline;
     char *initrd_filename;
     const char *cpu_model;
+    AccelState *accelerator;
 };
 
 #endif