qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/5] qdev: introduce qdev_create_kid(Object *par


From: Andreas Färber
Subject: Re: [Qemu-devel] [PATCH 1/5] qdev: introduce qdev_create_kid(Object *parent, const char *type)
Date: Tue, 10 Jul 2012 10:12:32 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120601 Thunderbird/13.0

Am 10.07.2012 08:16, schrieb Liu Ping Fan:
> DeviceState can be created as kid of DeviceState/CPUState, not neccesary
> attached to bus. This will be helpful to simulate the real hardware
> submodule which sits inside package.
> 
> Signed-off-by: Liu Ping Fan <address@hidden>
> ---
>  hw/qdev.c |   28 ++++++++++++++++++++++++++++
>  hw/qdev.h |    1 +
>  2 files changed, 29 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/qdev.c b/hw/qdev.c
> index af54467..d2100a1 100644
> --- a/hw/qdev.c
> +++ b/hw/qdev.c
> @@ -26,6 +26,7 @@
>     this API directly.  */
>  
>  #include "net.h"
> +#include "qemu/cpu.h"
>  #include "qdev.h"
>  #include "sysemu.h"
>  #include "error.h"
> @@ -145,6 +146,33 @@ DeviceState *qdev_try_create(BusState *bus, const char 
> *type)
>      return dev;
>  }
>  
> +DeviceState *qdev_create_kid(Object *parent, const char *type)
> +{
> +    DeviceState *dev;
> +    assert(parent);
> +
> +    if (object_class_by_name(type) == NULL) {
> +        return NULL;
> +    }
> +
> +    if (object_is_type_str(parent, TYPE_BUS)) {

This is only introduced in patch 2, no?

Andreas

> +        return qdev_create(BUS(parent), type);
> +    }
> +
> +    if (!object_is_type_str(parent, TYPE_DEVICE)
> +        || !object_is_type_str(parent, TYPE_CPU)) {
> +        return NULL;
> +    }
> +
> +    dev = DEVICE(object_new(type));
> +    if (!dev) {
> +        return NULL;
> +    }
> +    object_property_add_child(OBJECT(parent), type, OBJECT(dev), NULL);
> +
> +    return dev;
> +}
> +
>  /* Initialize a device.  Device properties should be set before calling
>     this function.  IRQs and MMIO regions should be connected/mapped after
>     calling this function.
> diff --git a/hw/qdev.h b/hw/qdev.h
> index f4683dc..aecc69e 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -154,6 +154,7 @@ typedef struct GlobalProperty {
>  
>  DeviceState *qdev_create(BusState *bus, const char *name);
>  DeviceState *qdev_try_create(BusState *bus, const char *name);
> +DeviceState *qdev_create_kid(Object *parent, const char *type);
>  bool qdev_exists(const char *name);
>  int qdev_device_help(QemuOpts *opts);
>  DeviceState *qdev_device_add(QemuOpts *opts);
> 


-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg





reply via email to

[Prev in Thread] Current Thread [Next in Thread]