diff mbox

[v2,3/4] xen: create qdev for each backend device

Message ID 1478071455-5738-4-git-send-email-jgross@suse.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jürgen Groß Nov. 2, 2016, 7:24 a.m. UTC
Create a qdev plugged to the xen-sysbus for each new backend device.
This device can be used as a parent for all needed devices of that
backend. The id of the new device will be "xen-<type>-<dev>" with
<type> being the xen backend type (e.g. "qdisk") and <dev> the xen
backend number of the type under which it is to be found in xenstore.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 hw/xen/xen_backend.c         | 48 +++++++++++++++++++++++++++++++++++++++++++-
 hw/xen/xen_pvdev.c           |  5 ++++-
 include/hw/xen/xen_backend.h |  4 ++++
 include/hw/xen/xen_pvdev.h   |  1 +
 4 files changed, 56 insertions(+), 2 deletions(-)

Comments

Stefano Stabellini Nov. 19, 2016, 4:34 a.m. UTC | #1
On Wed, 2 Nov 2016, Juergen Gross wrote:
> Create a qdev plugged to the xen-sysbus for each new backend device.
> This device can be used as a parent for all needed devices of that
> backend. The id of the new device will be "xen-<type>-<dev>" with
> <type> being the xen backend type (e.g. "qdisk") and <dev> the xen
> backend number of the type under which it is to be found in xenstore.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>  hw/xen/xen_backend.c         | 48 +++++++++++++++++++++++++++++++++++++++++++-
>  hw/xen/xen_pvdev.c           |  5 ++++-
>  include/hw/xen/xen_backend.h |  4 ++++
>  include/hw/xen/xen_pvdev.h   |  1 +
>  4 files changed, 56 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
> index 5ad3caa..3cb40b2 100644
> --- a/hw/xen/xen_backend.c
> +++ b/hw/xen/xen_backend.c
> @@ -27,11 +27,13 @@
>  
>  #include "hw/hw.h"
>  #include "hw/sysbus.h"
> +#include "hw/boards.h"
>  #include "sysemu/char.h"
>  #include "qemu/log.h"
>  #include "qapi/error.h"
>  #include "hw/xen/xen_backend.h"
>  #include "hw/xen/xen_pvdev.h"
> +#include "monitor/qdev.h"
>  
>  #include <xen/grant_table.h>
>  
> @@ -121,6 +123,12 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
>  
>      /* init new xendev */
>      xendev = g_malloc0(ops->size);
> +    object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND);
> +    qdev_set_parent_bus(&xendev->qdev, xen_sysbus);
> +    qdev_set_id(&xendev->qdev, g_strdup_printf("xen-%s-%d", type, dev));
> +    qdev_init_nofail(&xendev->qdev);
> +    object_unref(OBJECT(&xendev->qdev));
> +
>      xendev->type  = type;
>      xendev->dom   = dom;
>      xendev->dev   = dev;
> @@ -163,7 +171,6 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
>      return xendev;
>  }
>  
> -

spurious change


>  /*
>   * Sync internal data structures on xenstore updates.
>   * Node specifies the changed field.  node = NULL means
> @@ -541,6 +548,15 @@ err:
>      return -1;
>  }
>  
> +static void xen_set_dynamic_sysbus(void)
> +{
> +    Object *machine = qdev_get_machine();
> +    ObjectClass *oc = object_get_class(machine);
> +    MachineClass *mc = MACHINE_CLASS(oc);
> +
> +    mc->has_dynamic_sysbus = true;
> +}
> +
>  int xen_be_register(const char *type, struct XenDevOps *ops)
>  {
>      char path[50];
> @@ -562,6 +578,8 @@ int xen_be_register(const char *type, struct XenDevOps *ops)
>  
>  void xen_be_register_common(void)
>  {
> +    xen_set_dynamic_sysbus();
> +
>      xen_be_register("console", &xen_console_ops);
>      xen_be_register("vkbd", &xen_kbdmouse_ops);
>      xen_be_register("qdisk", &xen_blkdev_ops);
> @@ -588,9 +606,36 @@ int xen_be_bind_evtchn(struct XenDevice *xendev)
>  }
>  
>  
> +static Property xendev_properties[] = {
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void xendev_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +
> +    dc->props = xendev_properties;
> +    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
> +}
> +
> +static const TypeInfo xendev_type_info = {
> +    .name          = TYPE_XENBACKEND,
> +    .parent        = TYPE_XENSYSDEV,
> +    .class_init    = xendev_class_init,
> +    .instance_size = sizeof(struct XenDevice),
> +};
> +
> +static void xen_sysbus_class_init(ObjectClass *klass, void *data)
> +{
> +    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
> +
> +    hc->unplug = qdev_simple_device_unplug_cb;
> +}
> +
>  static const TypeInfo xensysbus_info = {
>      .name       = TYPE_XENSYSBUS,
>      .parent     = TYPE_BUS,
> +    .class_init = xen_sysbus_class_init,
>      .interfaces = (InterfaceInfo[]) {
>          { TYPE_HOTPLUG_HANDLER },
>          { }
> @@ -627,6 +672,7 @@ static void xenbe_register_types(void)
>  {
>      type_register_static(&xensysbus_info);
>      type_register_static(&xensysdev_info);
> +    type_register_static(&xendev_type_info);
>  }
>  
>  type_init(xenbe_register_types)
> diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c
> index 405e154..773c278 100644
> --- a/hw/xen/xen_pvdev.c
> +++ b/hw/xen/xen_pvdev.c
> @@ -18,10 +18,12 @@
>   */
>  
>  #include "qemu/osdep.h"
> +#include "hw/qdev-core.h"
>  
>  #include "hw/xen/xen_backend.h"
>  #include "hw/xen/xen_pvdev.h"
>  
> +

spurious change

but aside from that:

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


>  /* private */
>  static int debug;
>  
> @@ -307,7 +309,8 @@ void xen_pv_del_xendev(struct XenDevice *xendev)
>      }
>  
>      QTAILQ_REMOVE(&xendevs, xendev, next);
> -    g_free(xendev);
> +
> +    qdev_unplug(&xendev->qdev, NULL);
>  }
>  
>  void xen_pv_insert_xendev(struct XenDevice *xendev)
> diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h
> index 38f730e..4f4799a 100644
> --- a/include/hw/xen/xen_backend.h
> +++ b/include/hw/xen/xen_backend.h
> @@ -8,6 +8,10 @@
>  
>  #define TYPE_XENSYSDEV "xen-sysdev"
>  #define TYPE_XENSYSBUS "xen-sysbus"
> +#define TYPE_XENBACKEND "xen-backend"
> +
> +#define XENBACKEND_DEVICE(obj) \
> +    OBJECT_CHECK(XenDevice, (obj), TYPE_XENBACKEND)
>  
>  /* variables */
>  extern xc_interface *xen_xc;
> diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h
> index 083f0a9..d473e9b 100644
> --- a/include/hw/xen/xen_pvdev.h
> +++ b/include/hw/xen/xen_pvdev.h
> @@ -29,6 +29,7 @@ struct XenDevOps {
>  };
>  
>  struct XenDevice {
> +    DeviceState        qdev;
>      const char         *type;
>      int                dom;
>      int                dev;
> -- 
> 2.6.6
>
diff mbox

Patch

diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index 5ad3caa..3cb40b2 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -27,11 +27,13 @@ 
 
 #include "hw/hw.h"
 #include "hw/sysbus.h"
+#include "hw/boards.h"
 #include "sysemu/char.h"
 #include "qemu/log.h"
 #include "qapi/error.h"
 #include "hw/xen/xen_backend.h"
 #include "hw/xen/xen_pvdev.h"
+#include "monitor/qdev.h"
 
 #include <xen/grant_table.h>
 
@@ -121,6 +123,12 @@  static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
 
     /* init new xendev */
     xendev = g_malloc0(ops->size);
+    object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND);
+    qdev_set_parent_bus(&xendev->qdev, xen_sysbus);
+    qdev_set_id(&xendev->qdev, g_strdup_printf("xen-%s-%d", type, dev));
+    qdev_init_nofail(&xendev->qdev);
+    object_unref(OBJECT(&xendev->qdev));
+
     xendev->type  = type;
     xendev->dom   = dom;
     xendev->dev   = dev;
@@ -163,7 +171,6 @@  static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev,
     return xendev;
 }
 
-
 /*
  * Sync internal data structures on xenstore updates.
  * Node specifies the changed field.  node = NULL means
@@ -541,6 +548,15 @@  err:
     return -1;
 }
 
+static void xen_set_dynamic_sysbus(void)
+{
+    Object *machine = qdev_get_machine();
+    ObjectClass *oc = object_get_class(machine);
+    MachineClass *mc = MACHINE_CLASS(oc);
+
+    mc->has_dynamic_sysbus = true;
+}
+
 int xen_be_register(const char *type, struct XenDevOps *ops)
 {
     char path[50];
@@ -562,6 +578,8 @@  int xen_be_register(const char *type, struct XenDevOps *ops)
 
 void xen_be_register_common(void)
 {
+    xen_set_dynamic_sysbus();
+
     xen_be_register("console", &xen_console_ops);
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("qdisk", &xen_blkdev_ops);
@@ -588,9 +606,36 @@  int xen_be_bind_evtchn(struct XenDevice *xendev)
 }
 
 
+static Property xendev_properties[] = {
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void xendev_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->props = xendev_properties;
+    set_bit(DEVICE_CATEGORY_MISC, dc->categories);
+}
+
+static const TypeInfo xendev_type_info = {
+    .name          = TYPE_XENBACKEND,
+    .parent        = TYPE_XENSYSDEV,
+    .class_init    = xendev_class_init,
+    .instance_size = sizeof(struct XenDevice),
+};
+
+static void xen_sysbus_class_init(ObjectClass *klass, void *data)
+{
+    HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass);
+
+    hc->unplug = qdev_simple_device_unplug_cb;
+}
+
 static const TypeInfo xensysbus_info = {
     .name       = TYPE_XENSYSBUS,
     .parent     = TYPE_BUS,
+    .class_init = xen_sysbus_class_init,
     .interfaces = (InterfaceInfo[]) {
         { TYPE_HOTPLUG_HANDLER },
         { }
@@ -627,6 +672,7 @@  static void xenbe_register_types(void)
 {
     type_register_static(&xensysbus_info);
     type_register_static(&xensysdev_info);
+    type_register_static(&xendev_type_info);
 }
 
 type_init(xenbe_register_types)
diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c
index 405e154..773c278 100644
--- a/hw/xen/xen_pvdev.c
+++ b/hw/xen/xen_pvdev.c
@@ -18,10 +18,12 @@ 
  */
 
 #include "qemu/osdep.h"
+#include "hw/qdev-core.h"
 
 #include "hw/xen/xen_backend.h"
 #include "hw/xen/xen_pvdev.h"
 
+
 /* private */
 static int debug;
 
@@ -307,7 +309,8 @@  void xen_pv_del_xendev(struct XenDevice *xendev)
     }
 
     QTAILQ_REMOVE(&xendevs, xendev, next);
-    g_free(xendev);
+
+    qdev_unplug(&xendev->qdev, NULL);
 }
 
 void xen_pv_insert_xendev(struct XenDevice *xendev)
diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h
index 38f730e..4f4799a 100644
--- a/include/hw/xen/xen_backend.h
+++ b/include/hw/xen/xen_backend.h
@@ -8,6 +8,10 @@ 
 
 #define TYPE_XENSYSDEV "xen-sysdev"
 #define TYPE_XENSYSBUS "xen-sysbus"
+#define TYPE_XENBACKEND "xen-backend"
+
+#define XENBACKEND_DEVICE(obj) \
+    OBJECT_CHECK(XenDevice, (obj), TYPE_XENBACKEND)
 
 /* variables */
 extern xc_interface *xen_xc;
diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h
index 083f0a9..d473e9b 100644
--- a/include/hw/xen/xen_pvdev.h
+++ b/include/hw/xen/xen_pvdev.h
@@ -29,6 +29,7 @@  struct XenDevOps {
 };
 
 struct XenDevice {
+    DeviceState        qdev;
     const char         *type;
     int                dom;
     int                dev;