Skip to content

Commit

Permalink
accel: Create accel object when initializing machine
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ehabkost authored and bonzini committed Oct 9, 2014
1 parent f6a1ef6 commit ac2da55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions accel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions include/hw/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "qemu/typedefs.h"
#include "sysemu/blockdev.h"
#include "sysemu/accel.h"
#include "hw/qdev.h"
#include "qom/object.h"

Expand Down Expand Up @@ -131,6 +132,7 @@ struct MachineState {
char *kernel_cmdline;
char *initrd_filename;
const char *cpu_model;
AccelState *accelerator;
};

#endif

0 comments on commit ac2da55

Please sign in to comment.