diff mbox

[V1,1/3] xen: introduce dummy system device

Message ID 1441277113-30693-2-git-send-email-jgross@suse.com
State New
Headers show

Commit Message

Jürgen Groß Sept. 3, 2015, 10:45 a.m. UTC
Introduce a new dummy system device serving as parent for virtual
buses. This will enable new pv backends to introduce virtual buses
which are removable again opposed to system buses which are meant
to stay once added.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 hw/xenpv/xen_machine_pv.c    | 39 +++++++++++++++++++++++++++++++++++++++
 include/hw/xen/xen_backend.h |  1 +
 2 files changed, 40 insertions(+)

Comments

Stefano Stabellini Sept. 7, 2015, 3:29 p.m. UTC | #1
On Thu, 3 Sep 2015, Juergen Gross wrote:
> Introduce a new dummy system device serving as parent for virtual
> buses. This will enable new pv backends to introduce virtual buses
> which are removable again opposed to system buses which are meant
> to stay once added.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>  hw/xenpv/xen_machine_pv.c    | 39 +++++++++++++++++++++++++++++++++++++++
>  include/hw/xen/xen_backend.h |  1 +
>  2 files changed, 40 insertions(+)
> 
> diff --git a/hw/xenpv/xen_machine_pv.c b/hw/xenpv/xen_machine_pv.c
> index 2e545d2..57bc071 100644
> --- a/hw/xenpv/xen_machine_pv.c
> +++ b/hw/xenpv/xen_machine_pv.c
> @@ -24,10 +24,15 @@
>  
>  #include "hw/hw.h"
>  #include "hw/boards.h"
> +#include "hw/sysbus.h"
>  #include "hw/xen/xen_backend.h"
>  #include "xen_domainbuild.h"
>  #include "sysemu/block-backend.h"
>  
> +#define TYPE_XENSYSDEV "xensysdev"
> +
> +DeviceState *xen_sysdev;
> +
>  static void xen_init_pv(MachineState *machine)
>  {
>      const char *kernel_filename = machine->kernel_filename;
> @@ -59,6 +64,9 @@ static void xen_init_pv(MachineState *machine)
>          break;
>      }
>  
> +    xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
> +    qdev_init_nofail(xen_sysdev);
> +
>      xen_be_register("console", &xen_console_ops);
>      xen_be_register("vkbd", &xen_kbdmouse_ops);
>      xen_be_register("vfb", &xen_framebuffer_ops);
> @@ -93,6 +101,31 @@ static void xen_init_pv(MachineState *machine)
>      xen_init_display(xen_domid);
>  }
>  
> +static int xen_sysdev_init(SysBusDevice *dev)
> +{
> +    return 0;
> +}
> +
> +static Property xen_sysdev_properties[] = {
> +    {/* end of property list */},
> +};
> +
> +static void xen_sysdev_class_init(ObjectClass *klass, void *data)
> +{
> +    DeviceClass *dc = DEVICE_CLASS(klass);
> +    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
> +
> +    k->init = xen_sysdev_init;
> +    dc->props = xen_sysdev_properties;
> +}
> +
> +static const TypeInfo xensysdev_info = {
> +    .name          = TYPE_XENSYSDEV,
> +    .parent        = TYPE_SYS_BUS_DEVICE,
> +    .instance_size = sizeof(SysBusDevice),
> +    .class_init    = xen_sysdev_class_init,
> +};
> +
>  static QEMUMachine xenpv_machine = {
>      .name = "xenpv",
>      .desc = "Xen Para-virtualized PC",
> @@ -101,9 +134,15 @@ static QEMUMachine xenpv_machine = {
>      .default_machine_opts = "accel=xen",
>  };
>  
> +static void xenpv_register_types(void)
> +{
> +    type_register_static(&xensysdev_info);
> +}

Given that you need this just for usbback, I wonder if you could
move xen_sysdev and its initalization to usbback_init.
Jürgen Groß Sept. 9, 2015, 11:01 a.m. UTC | #2
On 09/07/2015 05:29 PM, Stefano Stabellini wrote:
> On Thu, 3 Sep 2015, Juergen Gross wrote:
>> Introduce a new dummy system device serving as parent for virtual
>> buses. This will enable new pv backends to introduce virtual buses
>> which are removable again opposed to system buses which are meant
>> to stay once added.
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
>> ---
>>   hw/xenpv/xen_machine_pv.c    | 39 +++++++++++++++++++++++++++++++++++++++
>>   include/hw/xen/xen_backend.h |  1 +
>>   2 files changed, 40 insertions(+)
>>
>> diff --git a/hw/xenpv/xen_machine_pv.c b/hw/xenpv/xen_machine_pv.c
>> index 2e545d2..57bc071 100644
>> --- a/hw/xenpv/xen_machine_pv.c
>> +++ b/hw/xenpv/xen_machine_pv.c
>> @@ -24,10 +24,15 @@
>>
>>   #include "hw/hw.h"
>>   #include "hw/boards.h"
>> +#include "hw/sysbus.h"
>>   #include "hw/xen/xen_backend.h"
>>   #include "xen_domainbuild.h"
>>   #include "sysemu/block-backend.h"
>>
>> +#define TYPE_XENSYSDEV "xensysdev"
>> +
>> +DeviceState *xen_sysdev;
>> +
>>   static void xen_init_pv(MachineState *machine)
>>   {
>>       const char *kernel_filename = machine->kernel_filename;
>> @@ -59,6 +64,9 @@ static void xen_init_pv(MachineState *machine)
>>           break;
>>       }
>>
>> +    xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
>> +    qdev_init_nofail(xen_sysdev);
>> +
>>       xen_be_register("console", &xen_console_ops);
>>       xen_be_register("vkbd", &xen_kbdmouse_ops);
>>       xen_be_register("vfb", &xen_framebuffer_ops);
>> @@ -93,6 +101,31 @@ static void xen_init_pv(MachineState *machine)
>>       xen_init_display(xen_domid);
>>   }
>>
>> +static int xen_sysdev_init(SysBusDevice *dev)
>> +{
>> +    return 0;
>> +}
>> +
>> +static Property xen_sysdev_properties[] = {
>> +    {/* end of property list */},
>> +};
>> +
>> +static void xen_sysdev_class_init(ObjectClass *klass, void *data)
>> +{
>> +    DeviceClass *dc = DEVICE_CLASS(klass);
>> +    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
>> +
>> +    k->init = xen_sysdev_init;
>> +    dc->props = xen_sysdev_properties;
>> +}
>> +
>> +static const TypeInfo xensysdev_info = {
>> +    .name          = TYPE_XENSYSDEV,
>> +    .parent        = TYPE_SYS_BUS_DEVICE,
>> +    .instance_size = sizeof(SysBusDevice),
>> +    .class_init    = xen_sysdev_class_init,
>> +};
>> +
>>   static QEMUMachine xenpv_machine = {
>>       .name = "xenpv",
>>       .desc = "Xen Para-virtualized PC",
>> @@ -101,9 +134,15 @@ static QEMUMachine xenpv_machine = {
>>       .default_machine_opts = "accel=xen",
>>   };
>>
>> +static void xenpv_register_types(void)
>> +{
>> +    type_register_static(&xensysdev_info);
>> +}
>
> Given that you need this just for usbback, I wonder if you could
> move xen_sysdev and its initalization to usbback_init.

Sure I could. OTOH I think this system device could really be of common
interest.


Juergen
diff mbox

Patch

diff --git a/hw/xenpv/xen_machine_pv.c b/hw/xenpv/xen_machine_pv.c
index 2e545d2..57bc071 100644
--- a/hw/xenpv/xen_machine_pv.c
+++ b/hw/xenpv/xen_machine_pv.c
@@ -24,10 +24,15 @@ 
 
 #include "hw/hw.h"
 #include "hw/boards.h"
+#include "hw/sysbus.h"
 #include "hw/xen/xen_backend.h"
 #include "xen_domainbuild.h"
 #include "sysemu/block-backend.h"
 
+#define TYPE_XENSYSDEV "xensysdev"
+
+DeviceState *xen_sysdev;
+
 static void xen_init_pv(MachineState *machine)
 {
     const char *kernel_filename = machine->kernel_filename;
@@ -59,6 +64,9 @@  static void xen_init_pv(MachineState *machine)
         break;
     }
 
+    xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
+    qdev_init_nofail(xen_sysdev);
+
     xen_be_register("console", &xen_console_ops);
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("vfb", &xen_framebuffer_ops);
@@ -93,6 +101,31 @@  static void xen_init_pv(MachineState *machine)
     xen_init_display(xen_domid);
 }
 
+static int xen_sysdev_init(SysBusDevice *dev)
+{
+    return 0;
+}
+
+static Property xen_sysdev_properties[] = {
+    {/* end of property list */},
+};
+
+static void xen_sysdev_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = xen_sysdev_init;
+    dc->props = xen_sysdev_properties;
+}
+
+static const TypeInfo xensysdev_info = {
+    .name          = TYPE_XENSYSDEV,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(SysBusDevice),
+    .class_init    = xen_sysdev_class_init,
+};
+
 static QEMUMachine xenpv_machine = {
     .name = "xenpv",
     .desc = "Xen Para-virtualized PC",
@@ -101,9 +134,15 @@  static QEMUMachine xenpv_machine = {
     .default_machine_opts = "accel=xen",
 };
 
+static void xenpv_register_types(void)
+{
+    type_register_static(&xensysdev_info);
+}
+
 static void xenpv_machine_init(void)
 {
     qemu_register_machine(&xenpv_machine);
 }
 
+type_init(xenpv_register_types)
 machine_init(xenpv_machine_init);
diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h
index 3b4125e..911ba6d 100644
--- a/include/hw/xen/xen_backend.h
+++ b/include/hw/xen/xen_backend.h
@@ -59,6 +59,7 @@  struct XenDevice {
 extern XenXC xen_xc;
 extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
+extern DeviceState *xen_sysdev;
 
 /* xenstore helper functions */
 int xenstore_write_str(const char *base, const char *node, const char *val);