* [Qemu-devel] [PATCH v2 0/4] xed: add qdevs for each backend, correct pvUSB
@ 2016-11-02 7:24 ` Juergen Gross
0 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, kraxel, sstabellini, armbru, Juergen Gross
Trying to use pvUSB in a Xen guest with a qemu emulated USB controller
will crash qemu as it tries to attach a pvUSB device to the emulated
controller.
This can be avoided by adding a unique id to each pvUSB controller which
can be used when attaching the pvUSB device. In order to make this
possible the pvUSB controller has to be a hotpluggable qemu device.
This is achieved by adding a qdev for each Xen backend all attached to
a new Xen specific bus.
Changes in V2:
- one qdev for each backend instead of pvUSB only
Juergen Gross (4):
xen: add an own bus for xen backend devices
qdev: add function qdev_set_id()
xen: create qdev for each backend device
xen: attach pvusb usb bus to backend qdev
hw/usb/xen-usb.c | 23 +++++++--------
hw/xen/xen_backend.c | 67 +++++++++++++++++++++++++++++++++++++++++---
hw/xen/xen_pvdev.c | 5 +++-
include/hw/xen/xen_backend.h | 8 ++++++
include/hw/xen/xen_pvdev.h | 1 +
include/monitor/qdev.h | 1 +
qdev-monitor.c | 36 +++++++++++++-----------
7 files changed, 107 insertions(+), 34 deletions(-)
--
2.6.6
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 0/4] xed: add qdevs for each backend, correct pvUSB
@ 2016-11-02 7:24 ` Juergen Gross
0 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, Juergen Gross, sstabellini, kraxel, armbru
Trying to use pvUSB in a Xen guest with a qemu emulated USB controller
will crash qemu as it tries to attach a pvUSB device to the emulated
controller.
This can be avoided by adding a unique id to each pvUSB controller which
can be used when attaching the pvUSB device. In order to make this
possible the pvUSB controller has to be a hotpluggable qemu device.
This is achieved by adding a qdev for each Xen backend all attached to
a new Xen specific bus.
Changes in V2:
- one qdev for each backend instead of pvUSB only
Juergen Gross (4):
xen: add an own bus for xen backend devices
qdev: add function qdev_set_id()
xen: create qdev for each backend device
xen: attach pvusb usb bus to backend qdev
hw/usb/xen-usb.c | 23 +++++++--------
hw/xen/xen_backend.c | 67 +++++++++++++++++++++++++++++++++++++++++---
hw/xen/xen_pvdev.c | 5 +++-
include/hw/xen/xen_backend.h | 8 ++++++
include/hw/xen/xen_pvdev.h | 1 +
include/monitor/qdev.h | 1 +
qdev-monitor.c | 36 +++++++++++++-----------
7 files changed, 107 insertions(+), 34 deletions(-)
--
2.6.6
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v2 1/4] xen: add an own bus for xen backend devices
2016-11-02 7:24 ` Juergen Gross
@ 2016-11-02 7:24 ` Juergen Gross
-1 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, kraxel, sstabellini, armbru, Juergen Gross
Add a bus for Xen backend devices in order to be able to establish a
dedicated device path for pluggable devices.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
hw/xen/xen_backend.c | 19 ++++++++++++++++---
include/hw/xen/xen_backend.h | 4 ++++
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index 41ba5c5..5ad3caa 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -29,14 +29,14 @@
#include "hw/sysbus.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 <xen/grant_table.h>
-#define TYPE_XENSYSDEV "xensysdev"
-
DeviceState *xen_sysdev;
+BusState *xen_sysbus;
/* ------------------------------------------------------------- */
@@ -528,6 +528,8 @@ int xen_be_init(void)
xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
qdev_init_nofail(xen_sysdev);
+ xen_sysbus = qbus_create(TYPE_XENSYSBUS, DEVICE(xen_sysdev), "xen-sysbus");
+ qbus_set_bus_hotplug_handler(xen_sysbus, &error_abort);
return 0;
@@ -586,6 +588,15 @@ int xen_be_bind_evtchn(struct XenDevice *xendev)
}
+static const TypeInfo xensysbus_info = {
+ .name = TYPE_XENSYSBUS,
+ .parent = TYPE_BUS,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_HOTPLUG_HANDLER },
+ { }
+ }
+};
+
static int xen_sysdev_init(SysBusDevice *dev)
{
return 0;
@@ -602,6 +613,7 @@ static void xen_sysdev_class_init(ObjectClass *klass, void *data)
k->init = xen_sysdev_init;
dc->props = xen_sysdev_properties;
+ dc->bus_type = TYPE_XENSYSBUS;
}
static const TypeInfo xensysdev_info = {
@@ -613,7 +625,8 @@ static const TypeInfo xensysdev_info = {
static void xenbe_register_types(void)
{
+ type_register_static(&xensysbus_info);
type_register_static(&xensysdev_info);
}
-type_init(xenbe_register_types);
+type_init(xenbe_register_types)
diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h
index cbda40e..38f730e 100644
--- a/include/hw/xen/xen_backend.h
+++ b/include/hw/xen/xen_backend.h
@@ -6,12 +6,16 @@
#include "sysemu/sysemu.h"
#include "net/net.h"
+#define TYPE_XENSYSDEV "xen-sysdev"
+#define TYPE_XENSYSBUS "xen-sysbus"
+
/* variables */
extern xc_interface *xen_xc;
extern xenforeignmemory_handle *xen_fmem;
extern struct xs_handle *xenstore;
extern const char *xen_protocol;
extern DeviceState *xen_sysdev;
+extern BusState *xen_sysbus;
int xenstore_mkdir(char *path, int p);
int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val);
--
2.6.6
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 1/4] xen: add an own bus for xen backend devices
@ 2016-11-02 7:24 ` Juergen Gross
0 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, Juergen Gross, sstabellini, kraxel, armbru
Add a bus for Xen backend devices in order to be able to establish a
dedicated device path for pluggable devices.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
hw/xen/xen_backend.c | 19 ++++++++++++++++---
include/hw/xen/xen_backend.h | 4 ++++
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
index 41ba5c5..5ad3caa 100644
--- a/hw/xen/xen_backend.c
+++ b/hw/xen/xen_backend.c
@@ -29,14 +29,14 @@
#include "hw/sysbus.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 <xen/grant_table.h>
-#define TYPE_XENSYSDEV "xensysdev"
-
DeviceState *xen_sysdev;
+BusState *xen_sysbus;
/* ------------------------------------------------------------- */
@@ -528,6 +528,8 @@ int xen_be_init(void)
xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
qdev_init_nofail(xen_sysdev);
+ xen_sysbus = qbus_create(TYPE_XENSYSBUS, DEVICE(xen_sysdev), "xen-sysbus");
+ qbus_set_bus_hotplug_handler(xen_sysbus, &error_abort);
return 0;
@@ -586,6 +588,15 @@ int xen_be_bind_evtchn(struct XenDevice *xendev)
}
+static const TypeInfo xensysbus_info = {
+ .name = TYPE_XENSYSBUS,
+ .parent = TYPE_BUS,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_HOTPLUG_HANDLER },
+ { }
+ }
+};
+
static int xen_sysdev_init(SysBusDevice *dev)
{
return 0;
@@ -602,6 +613,7 @@ static void xen_sysdev_class_init(ObjectClass *klass, void *data)
k->init = xen_sysdev_init;
dc->props = xen_sysdev_properties;
+ dc->bus_type = TYPE_XENSYSBUS;
}
static const TypeInfo xensysdev_info = {
@@ -613,7 +625,8 @@ static const TypeInfo xensysdev_info = {
static void xenbe_register_types(void)
{
+ type_register_static(&xensysbus_info);
type_register_static(&xensysdev_info);
}
-type_init(xenbe_register_types);
+type_init(xenbe_register_types)
diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h
index cbda40e..38f730e 100644
--- a/include/hw/xen/xen_backend.h
+++ b/include/hw/xen/xen_backend.h
@@ -6,12 +6,16 @@
#include "sysemu/sysemu.h"
#include "net/net.h"
+#define TYPE_XENSYSDEV "xen-sysdev"
+#define TYPE_XENSYSBUS "xen-sysbus"
+
/* variables */
extern xc_interface *xen_xc;
extern xenforeignmemory_handle *xen_fmem;
extern struct xs_handle *xenstore;
extern const char *xen_protocol;
extern DeviceState *xen_sysdev;
+extern BusState *xen_sysbus;
int xenstore_mkdir(char *path, int p);
int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val);
--
2.6.6
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v2 2/4] qdev: add function qdev_set_id()
2016-11-02 7:24 ` Juergen Gross
@ 2016-11-02 7:24 ` Juergen Gross
-1 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, kraxel, sstabellini, armbru, Juergen Gross
In order to have an easy way to add a new qdev with a specific id
carve out the needed functionality from qdev_device_add() into a new
function qdev_set_id().
Signed-off-by: Juergen Gross <jgross@suse.com>
---
include/monitor/qdev.h | 1 +
qdev-monitor.c | 36 ++++++++++++++++++++----------------
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
index 8e504bc..0ff3331 100644
--- a/include/monitor/qdev.h
+++ b/include/monitor/qdev.h
@@ -12,5 +12,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
int qdev_device_help(QemuOpts *opts);
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
+void qdev_set_id(DeviceState *dev, const char *id);
#endif
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 4f78ecb..c73410c 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -539,10 +539,28 @@ static BusState *qbus_find(const char *path, Error **errp)
return bus;
}
+void qdev_set_id(DeviceState *dev, const char *id)
+{
+ if (id) {
+ dev->id = id;
+ }
+
+ if (dev->id) {
+ object_property_add_child(qdev_get_peripheral(), dev->id,
+ OBJECT(dev), NULL);
+ } else {
+ static int anon_count;
+ gchar *name = g_strdup_printf("device[%d]", anon_count++);
+ object_property_add_child(qdev_get_peripheral_anon(), name,
+ OBJECT(dev), NULL);
+ g_free(name);
+ }
+}
+
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
{
DeviceClass *dc;
- const char *driver, *path, *id;
+ const char *driver, *path;
DeviceState *dev;
BusState *bus = NULL;
Error *err = NULL;
@@ -591,21 +609,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
qdev_set_parent_bus(dev, bus);
}
- id = qemu_opts_id(opts);
- if (id) {
- dev->id = id;
- }
-
- if (dev->id) {
- object_property_add_child(qdev_get_peripheral(), dev->id,
- OBJECT(dev), NULL);
- } else {
- static int anon_count;
- gchar *name = g_strdup_printf("device[%d]", anon_count++);
- object_property_add_child(qdev_get_peripheral_anon(), name,
- OBJECT(dev), NULL);
- g_free(name);
- }
+ qdev_set_id(dev, qemu_opts_id(opts));
/* set properties */
if (qemu_opt_foreach(opts, set_property, dev, &err)) {
--
2.6.6
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 2/4] qdev: add function qdev_set_id()
@ 2016-11-02 7:24 ` Juergen Gross
0 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, Juergen Gross, sstabellini, kraxel, armbru
In order to have an easy way to add a new qdev with a specific id
carve out the needed functionality from qdev_device_add() into a new
function qdev_set_id().
Signed-off-by: Juergen Gross <jgross@suse.com>
---
include/monitor/qdev.h | 1 +
qdev-monitor.c | 36 ++++++++++++++++++++----------------
2 files changed, 21 insertions(+), 16 deletions(-)
diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
index 8e504bc..0ff3331 100644
--- a/include/monitor/qdev.h
+++ b/include/monitor/qdev.h
@@ -12,5 +12,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
int qdev_device_help(QemuOpts *opts);
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
+void qdev_set_id(DeviceState *dev, const char *id);
#endif
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 4f78ecb..c73410c 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -539,10 +539,28 @@ static BusState *qbus_find(const char *path, Error **errp)
return bus;
}
+void qdev_set_id(DeviceState *dev, const char *id)
+{
+ if (id) {
+ dev->id = id;
+ }
+
+ if (dev->id) {
+ object_property_add_child(qdev_get_peripheral(), dev->id,
+ OBJECT(dev), NULL);
+ } else {
+ static int anon_count;
+ gchar *name = g_strdup_printf("device[%d]", anon_count++);
+ object_property_add_child(qdev_get_peripheral_anon(), name,
+ OBJECT(dev), NULL);
+ g_free(name);
+ }
+}
+
DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
{
DeviceClass *dc;
- const char *driver, *path, *id;
+ const char *driver, *path;
DeviceState *dev;
BusState *bus = NULL;
Error *err = NULL;
@@ -591,21 +609,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
qdev_set_parent_bus(dev, bus);
}
- id = qemu_opts_id(opts);
- if (id) {
- dev->id = id;
- }
-
- if (dev->id) {
- object_property_add_child(qdev_get_peripheral(), dev->id,
- OBJECT(dev), NULL);
- } else {
- static int anon_count;
- gchar *name = g_strdup_printf("device[%d]", anon_count++);
- object_property_add_child(qdev_get_peripheral_anon(), name,
- OBJECT(dev), NULL);
- g_free(name);
- }
+ qdev_set_id(dev, qemu_opts_id(opts));
/* set properties */
if (qemu_opt_foreach(opts, set_property, dev, &err)) {
--
2.6.6
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v2 3/4] xen: create qdev for each backend device
2016-11-02 7:24 ` Juergen Gross
@ 2016-11-02 7:24 ` Juergen Gross
-1 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, kraxel, sstabellini, armbru, Juergen Gross
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;
}
-
/*
* 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;
--
2.6.6
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 3/4] xen: create qdev for each backend device
@ 2016-11-02 7:24 ` Juergen Gross
0 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, Juergen Gross, sstabellini, kraxel, armbru
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;
}
-
/*
* 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;
--
2.6.6
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v2 4/4] xen: attach pvusb usb bus to backend qdev
2016-11-02 7:24 ` Juergen Gross
@ 2016-11-02 7:24 ` Juergen Gross
-1 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, kraxel, sstabellini, armbru, Juergen Gross
Attach the usb bus of a new pvusb controller to the qdev associated
with the Xen backend. Any device connected to that controller can now
specify the bus and port directly via its properties.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
hw/usb/xen-usb.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c
index 1b3c2fb..8e676e6 100644
--- a/hw/usb/xen-usb.c
+++ b/hw/usb/xen-usb.c
@@ -712,15 +712,10 @@ static void usbback_portid_detach(struct usbback_info *usbif, unsigned port)
static void usbback_portid_remove(struct usbback_info *usbif, unsigned port)
{
- USBPort *p;
-
if (!usbif->ports[port - 1].dev) {
return;
}
- p = &(usbif->ports[port - 1].port);
- snprintf(p->path, sizeof(p->path), "%d", 99);
-
object_unparent(OBJECT(usbif->ports[port - 1].dev));
usbif->ports[port - 1].dev = NULL;
usbback_portid_detach(usbif, port);
@@ -733,10 +728,10 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
{
unsigned speed;
char *portname;
- USBPort *p;
Error *local_err = NULL;
QDict *qdict;
QemuOpts *opts;
+ char *tmp;
if (usbif->ports[port - 1].dev) {
return;
@@ -749,11 +744,16 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
return;
}
portname++;
- p = &(usbif->ports[port - 1].port);
- snprintf(p->path, sizeof(p->path), "%s", portname);
qdict = qdict_new();
qdict_put(qdict, "driver", qstring_from_str("usb-host"));
+ tmp = g_strdup_printf("%s.0", usbif->xendev.qdev.id);
+ qdict_put(qdict, "bus", qstring_from_str(tmp));
+ g_free(tmp);
+ tmp = g_strdup_printf("%s-%u", usbif->xendev.qdev.id, port);
+ qdict_put(qdict, "id", qstring_from_str(tmp));
+ g_free(tmp);
+ qdict_put(qdict, "port", qint_from_int(port));
qdict_put(qdict, "hostbus", qint_from_int(atoi(busid)));
qdict_put(qdict, "hostport", qstring_from_str(portname));
opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
@@ -765,7 +765,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
goto err;
}
QDECREF(qdict);
- snprintf(p->path, sizeof(p->path), "%d", port);
speed = usbif->ports[port - 1].dev->speed;
switch (speed) {
case USB_SPEED_LOW:
@@ -799,7 +798,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
err:
QDECREF(qdict);
- snprintf(p->path, sizeof(p->path), "%d", 99);
xen_pv_printf(&usbif->xendev, 0, "device %s could not be opened\n", busid);
}
@@ -1012,13 +1010,13 @@ static void usbback_alloc(struct XenDevice *xendev)
usbif = container_of(xendev, struct usbback_info, xendev);
- usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops, xen_sysdev);
+ usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops,
+ DEVICE(&xendev->qdev));
for (i = 0; i < USBBACK_MAXPORTS; i++) {
p = &(usbif->ports[i].port);
usb_register_port(&usbif->bus, p, usbif, i, &xen_usb_port_ops,
USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL |
USB_SPEED_MASK_HIGH);
- snprintf(p->path, sizeof(p->path), "%d", 99);
}
QTAILQ_INIT(&usbif->req_free_q);
@@ -1066,7 +1064,6 @@ static int usbback_free(struct XenDevice *xendev)
}
usb_bus_release(&usbif->bus);
- object_unparent(OBJECT(&usbif->bus));
TR_BUS(xendev, "finished\n");
--
2.6.6
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [PATCH v2 4/4] xen: attach pvusb usb bus to backend qdev
@ 2016-11-02 7:24 ` Juergen Gross
0 siblings, 0 replies; 20+ messages in thread
From: Juergen Gross @ 2016-11-02 7:24 UTC (permalink / raw)
To: qemu-devel, xen-devel
Cc: anthony.perard, Juergen Gross, sstabellini, kraxel, armbru
Attach the usb bus of a new pvusb controller to the qdev associated
with the Xen backend. Any device connected to that controller can now
specify the bus and port directly via its properties.
Signed-off-by: Juergen Gross <jgross@suse.com>
---
hw/usb/xen-usb.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c
index 1b3c2fb..8e676e6 100644
--- a/hw/usb/xen-usb.c
+++ b/hw/usb/xen-usb.c
@@ -712,15 +712,10 @@ static void usbback_portid_detach(struct usbback_info *usbif, unsigned port)
static void usbback_portid_remove(struct usbback_info *usbif, unsigned port)
{
- USBPort *p;
-
if (!usbif->ports[port - 1].dev) {
return;
}
- p = &(usbif->ports[port - 1].port);
- snprintf(p->path, sizeof(p->path), "%d", 99);
-
object_unparent(OBJECT(usbif->ports[port - 1].dev));
usbif->ports[port - 1].dev = NULL;
usbback_portid_detach(usbif, port);
@@ -733,10 +728,10 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
{
unsigned speed;
char *portname;
- USBPort *p;
Error *local_err = NULL;
QDict *qdict;
QemuOpts *opts;
+ char *tmp;
if (usbif->ports[port - 1].dev) {
return;
@@ -749,11 +744,16 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
return;
}
portname++;
- p = &(usbif->ports[port - 1].port);
- snprintf(p->path, sizeof(p->path), "%s", portname);
qdict = qdict_new();
qdict_put(qdict, "driver", qstring_from_str("usb-host"));
+ tmp = g_strdup_printf("%s.0", usbif->xendev.qdev.id);
+ qdict_put(qdict, "bus", qstring_from_str(tmp));
+ g_free(tmp);
+ tmp = g_strdup_printf("%s-%u", usbif->xendev.qdev.id, port);
+ qdict_put(qdict, "id", qstring_from_str(tmp));
+ g_free(tmp);
+ qdict_put(qdict, "port", qint_from_int(port));
qdict_put(qdict, "hostbus", qint_from_int(atoi(busid)));
qdict_put(qdict, "hostport", qstring_from_str(portname));
opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
@@ -765,7 +765,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
goto err;
}
QDECREF(qdict);
- snprintf(p->path, sizeof(p->path), "%d", port);
speed = usbif->ports[port - 1].dev->speed;
switch (speed) {
case USB_SPEED_LOW:
@@ -799,7 +798,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
err:
QDECREF(qdict);
- snprintf(p->path, sizeof(p->path), "%d", 99);
xen_pv_printf(&usbif->xendev, 0, "device %s could not be opened\n", busid);
}
@@ -1012,13 +1010,13 @@ static void usbback_alloc(struct XenDevice *xendev)
usbif = container_of(xendev, struct usbback_info, xendev);
- usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops, xen_sysdev);
+ usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops,
+ DEVICE(&xendev->qdev));
for (i = 0; i < USBBACK_MAXPORTS; i++) {
p = &(usbif->ports[i].port);
usb_register_port(&usbif->bus, p, usbif, i, &xen_usb_port_ops,
USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL |
USB_SPEED_MASK_HIGH);
- snprintf(p->path, sizeof(p->path), "%d", 99);
}
QTAILQ_INIT(&usbif->req_free_q);
@@ -1066,7 +1064,6 @@ static int usbback_free(struct XenDevice *xendev)
}
usb_bus_release(&usbif->bus);
- object_unparent(OBJECT(&usbif->bus));
TR_BUS(xendev, "finished\n");
--
2.6.6
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v2 1/4] xen: add an own bus for xen backend devices
2016-11-02 7:24 ` Juergen Gross
@ 2016-11-19 4:34 ` Stefano Stabellini
-1 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-19 4:34 UTC (permalink / raw)
To: Juergen Gross
Cc: qemu-devel, xen-devel, anthony.perard, kraxel, sstabellini, armbru
On Wed, 2 Nov 2016, Juergen Gross wrote:
> Add a bus for Xen backend devices in order to be able to establish a
> dedicated device path for pluggable devices.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> hw/xen/xen_backend.c | 19 ++++++++++++++++---
> include/hw/xen/xen_backend.h | 4 ++++
> 2 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
> index 41ba5c5..5ad3caa 100644
> --- a/hw/xen/xen_backend.c
> +++ b/hw/xen/xen_backend.c
> @@ -29,14 +29,14 @@
> #include "hw/sysbus.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 <xen/grant_table.h>
>
> -#define TYPE_XENSYSDEV "xensysdev"
> -
> DeviceState *xen_sysdev;
> +BusState *xen_sysbus;
>
> /* ------------------------------------------------------------- */
>
> @@ -528,6 +528,8 @@ int xen_be_init(void)
>
> xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
> qdev_init_nofail(xen_sysdev);
> + xen_sysbus = qbus_create(TYPE_XENSYSBUS, DEVICE(xen_sysdev), "xen-sysbus");
> + qbus_set_bus_hotplug_handler(xen_sysbus, &error_abort);
>
> return 0;
>
> @@ -586,6 +588,15 @@ int xen_be_bind_evtchn(struct XenDevice *xendev)
> }
>
>
> +static const TypeInfo xensysbus_info = {
> + .name = TYPE_XENSYSBUS,
> + .parent = TYPE_BUS,
> + .interfaces = (InterfaceInfo[]) {
> + { TYPE_HOTPLUG_HANDLER },
> + { }
> + }
> +};
> +
> static int xen_sysdev_init(SysBusDevice *dev)
> {
> return 0;
> @@ -602,6 +613,7 @@ static void xen_sysdev_class_init(ObjectClass *klass, void *data)
>
> k->init = xen_sysdev_init;
> dc->props = xen_sysdev_properties;
> + dc->bus_type = TYPE_XENSYSBUS;
> }
>
> static const TypeInfo xensysdev_info = {
> @@ -613,7 +625,8 @@ static const TypeInfo xensysdev_info = {
>
> static void xenbe_register_types(void)
> {
> + type_register_static(&xensysbus_info);
> type_register_static(&xensysdev_info);
> }
>
> -type_init(xenbe_register_types);
> +type_init(xenbe_register_types)
> diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h
> index cbda40e..38f730e 100644
> --- a/include/hw/xen/xen_backend.h
> +++ b/include/hw/xen/xen_backend.h
> @@ -6,12 +6,16 @@
> #include "sysemu/sysemu.h"
> #include "net/net.h"
>
> +#define TYPE_XENSYSDEV "xen-sysdev"
> +#define TYPE_XENSYSBUS "xen-sysbus"
> +
> /* variables */
> extern xc_interface *xen_xc;
> extern xenforeignmemory_handle *xen_fmem;
> extern struct xs_handle *xenstore;
> extern const char *xen_protocol;
> extern DeviceState *xen_sysdev;
> +extern BusState *xen_sysbus;
>
> int xenstore_mkdir(char *path, int p);
> int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val);
> --
> 2.6.6
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 1/4] xen: add an own bus for xen backend devices
@ 2016-11-19 4:34 ` Stefano Stabellini
0 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-19 4:34 UTC (permalink / raw)
To: Juergen Gross
Cc: xen-devel, armbru, qemu-devel, sstabellini, kraxel, anthony.perard
On Wed, 2 Nov 2016, Juergen Gross wrote:
> Add a bus for Xen backend devices in order to be able to establish a
> dedicated device path for pluggable devices.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> hw/xen/xen_backend.c | 19 ++++++++++++++++---
> include/hw/xen/xen_backend.h | 4 ++++
> 2 files changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c
> index 41ba5c5..5ad3caa 100644
> --- a/hw/xen/xen_backend.c
> +++ b/hw/xen/xen_backend.c
> @@ -29,14 +29,14 @@
> #include "hw/sysbus.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 <xen/grant_table.h>
>
> -#define TYPE_XENSYSDEV "xensysdev"
> -
> DeviceState *xen_sysdev;
> +BusState *xen_sysbus;
>
> /* ------------------------------------------------------------- */
>
> @@ -528,6 +528,8 @@ int xen_be_init(void)
>
> xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
> qdev_init_nofail(xen_sysdev);
> + xen_sysbus = qbus_create(TYPE_XENSYSBUS, DEVICE(xen_sysdev), "xen-sysbus");
> + qbus_set_bus_hotplug_handler(xen_sysbus, &error_abort);
>
> return 0;
>
> @@ -586,6 +588,15 @@ int xen_be_bind_evtchn(struct XenDevice *xendev)
> }
>
>
> +static const TypeInfo xensysbus_info = {
> + .name = TYPE_XENSYSBUS,
> + .parent = TYPE_BUS,
> + .interfaces = (InterfaceInfo[]) {
> + { TYPE_HOTPLUG_HANDLER },
> + { }
> + }
> +};
> +
> static int xen_sysdev_init(SysBusDevice *dev)
> {
> return 0;
> @@ -602,6 +613,7 @@ static void xen_sysdev_class_init(ObjectClass *klass, void *data)
>
> k->init = xen_sysdev_init;
> dc->props = xen_sysdev_properties;
> + dc->bus_type = TYPE_XENSYSBUS;
> }
>
> static const TypeInfo xensysdev_info = {
> @@ -613,7 +625,8 @@ static const TypeInfo xensysdev_info = {
>
> static void xenbe_register_types(void)
> {
> + type_register_static(&xensysbus_info);
> type_register_static(&xensysdev_info);
> }
>
> -type_init(xenbe_register_types);
> +type_init(xenbe_register_types)
> diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h
> index cbda40e..38f730e 100644
> --- a/include/hw/xen/xen_backend.h
> +++ b/include/hw/xen/xen_backend.h
> @@ -6,12 +6,16 @@
> #include "sysemu/sysemu.h"
> #include "net/net.h"
>
> +#define TYPE_XENSYSDEV "xen-sysdev"
> +#define TYPE_XENSYSBUS "xen-sysbus"
> +
> /* variables */
> extern xc_interface *xen_xc;
> extern xenforeignmemory_handle *xen_fmem;
> extern struct xs_handle *xenstore;
> extern const char *xen_protocol;
> extern DeviceState *xen_sysdev;
> +extern BusState *xen_sysbus;
>
> int xenstore_mkdir(char *path, int p);
> int xenstore_write_be_str(struct XenDevice *xendev, const char *node, const char *val);
> --
> 2.6.6
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v2 2/4] qdev: add function qdev_set_id()
2016-11-02 7:24 ` Juergen Gross
@ 2016-11-19 4:34 ` Stefano Stabellini
-1 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-19 4:34 UTC (permalink / raw)
To: Juergen Gross
Cc: qemu-devel, xen-devel, anthony.perard, kraxel, sstabellini, armbru
On Wed, 2 Nov 2016, Juergen Gross wrote:
> In order to have an easy way to add a new qdev with a specific id
> carve out the needed functionality from qdev_device_add() into a new
> function qdev_set_id().
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> include/monitor/qdev.h | 1 +
> qdev-monitor.c | 36 ++++++++++++++++++++----------------
> 2 files changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
> index 8e504bc..0ff3331 100644
> --- a/include/monitor/qdev.h
> +++ b/include/monitor/qdev.h
> @@ -12,5 +12,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
>
> int qdev_device_help(QemuOpts *opts);
> DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
> +void qdev_set_id(DeviceState *dev, const char *id);
>
> #endif
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index 4f78ecb..c73410c 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -539,10 +539,28 @@ static BusState *qbus_find(const char *path, Error **errp)
> return bus;
> }
>
> +void qdev_set_id(DeviceState *dev, const char *id)
> +{
> + if (id) {
> + dev->id = id;
> + }
> +
> + if (dev->id) {
> + object_property_add_child(qdev_get_peripheral(), dev->id,
> + OBJECT(dev), NULL);
> + } else {
> + static int anon_count;
> + gchar *name = g_strdup_printf("device[%d]", anon_count++);
> + object_property_add_child(qdev_get_peripheral_anon(), name,
> + OBJECT(dev), NULL);
> + g_free(name);
> + }
> +}
> +
> DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
> {
> DeviceClass *dc;
> - const char *driver, *path, *id;
> + const char *driver, *path;
> DeviceState *dev;
> BusState *bus = NULL;
> Error *err = NULL;
> @@ -591,21 +609,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
> qdev_set_parent_bus(dev, bus);
> }
>
> - id = qemu_opts_id(opts);
> - if (id) {
> - dev->id = id;
> - }
> -
> - if (dev->id) {
> - object_property_add_child(qdev_get_peripheral(), dev->id,
> - OBJECT(dev), NULL);
> - } else {
> - static int anon_count;
> - gchar *name = g_strdup_printf("device[%d]", anon_count++);
> - object_property_add_child(qdev_get_peripheral_anon(), name,
> - OBJECT(dev), NULL);
> - g_free(name);
> - }
> + qdev_set_id(dev, qemu_opts_id(opts));
>
> /* set properties */
> if (qemu_opt_foreach(opts, set_property, dev, &err)) {
> --
> 2.6.6
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 2/4] qdev: add function qdev_set_id()
@ 2016-11-19 4:34 ` Stefano Stabellini
0 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-19 4:34 UTC (permalink / raw)
To: Juergen Gross
Cc: xen-devel, armbru, qemu-devel, sstabellini, kraxel, anthony.perard
On Wed, 2 Nov 2016, Juergen Gross wrote:
> In order to have an easy way to add a new qdev with a specific id
> carve out the needed functionality from qdev_device_add() into a new
> function qdev_set_id().
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> include/monitor/qdev.h | 1 +
> qdev-monitor.c | 36 ++++++++++++++++++++----------------
> 2 files changed, 21 insertions(+), 16 deletions(-)
>
> diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
> index 8e504bc..0ff3331 100644
> --- a/include/monitor/qdev.h
> +++ b/include/monitor/qdev.h
> @@ -12,5 +12,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp);
>
> int qdev_device_help(QemuOpts *opts);
> DeviceState *qdev_device_add(QemuOpts *opts, Error **errp);
> +void qdev_set_id(DeviceState *dev, const char *id);
>
> #endif
> diff --git a/qdev-monitor.c b/qdev-monitor.c
> index 4f78ecb..c73410c 100644
> --- a/qdev-monitor.c
> +++ b/qdev-monitor.c
> @@ -539,10 +539,28 @@ static BusState *qbus_find(const char *path, Error **errp)
> return bus;
> }
>
> +void qdev_set_id(DeviceState *dev, const char *id)
> +{
> + if (id) {
> + dev->id = id;
> + }
> +
> + if (dev->id) {
> + object_property_add_child(qdev_get_peripheral(), dev->id,
> + OBJECT(dev), NULL);
> + } else {
> + static int anon_count;
> + gchar *name = g_strdup_printf("device[%d]", anon_count++);
> + object_property_add_child(qdev_get_peripheral_anon(), name,
> + OBJECT(dev), NULL);
> + g_free(name);
> + }
> +}
> +
> DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
> {
> DeviceClass *dc;
> - const char *driver, *path, *id;
> + const char *driver, *path;
> DeviceState *dev;
> BusState *bus = NULL;
> Error *err = NULL;
> @@ -591,21 +609,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
> qdev_set_parent_bus(dev, bus);
> }
>
> - id = qemu_opts_id(opts);
> - if (id) {
> - dev->id = id;
> - }
> -
> - if (dev->id) {
> - object_property_add_child(qdev_get_peripheral(), dev->id,
> - OBJECT(dev), NULL);
> - } else {
> - static int anon_count;
> - gchar *name = g_strdup_printf("device[%d]", anon_count++);
> - object_property_add_child(qdev_get_peripheral_anon(), name,
> - OBJECT(dev), NULL);
> - g_free(name);
> - }
> + qdev_set_id(dev, qemu_opts_id(opts));
>
> /* set properties */
> if (qemu_opt_foreach(opts, set_property, dev, &err)) {
> --
> 2.6.6
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v2 3/4] xen: create qdev for each backend device
2016-11-02 7:24 ` Juergen Gross
@ 2016-11-19 4:34 ` Stefano Stabellini
-1 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-19 4:34 UTC (permalink / raw)
To: Juergen Gross
Cc: qemu-devel, xen-devel, anthony.perard, kraxel, sstabellini, armbru
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
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 3/4] xen: create qdev for each backend device
@ 2016-11-19 4:34 ` Stefano Stabellini
0 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-19 4:34 UTC (permalink / raw)
To: Juergen Gross
Cc: xen-devel, armbru, qemu-devel, sstabellini, kraxel, anthony.perard
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
>
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v2 4/4] xen: attach pvusb usb bus to backend qdev
2016-11-02 7:24 ` Juergen Gross
@ 2016-11-19 4:34 ` Stefano Stabellini
-1 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-19 4:34 UTC (permalink / raw)
To: Juergen Gross
Cc: qemu-devel, xen-devel, anthony.perard, kraxel, sstabellini, armbru
On Wed, 2 Nov 2016, Juergen Gross wrote:
> Attach the usb bus of a new pvusb controller to the qdev associated
> with the Xen backend. Any device connected to that controller can now
> specify the bus and port directly via its properties.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> hw/usb/xen-usb.c | 23 ++++++++++-------------
> 1 file changed, 10 insertions(+), 13 deletions(-)
>
> diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c
> index 1b3c2fb..8e676e6 100644
> --- a/hw/usb/xen-usb.c
> +++ b/hw/usb/xen-usb.c
> @@ -712,15 +712,10 @@ static void usbback_portid_detach(struct usbback_info *usbif, unsigned port)
>
> static void usbback_portid_remove(struct usbback_info *usbif, unsigned port)
> {
> - USBPort *p;
> -
> if (!usbif->ports[port - 1].dev) {
> return;
> }
>
> - p = &(usbif->ports[port - 1].port);
> - snprintf(p->path, sizeof(p->path), "%d", 99);
> -
> object_unparent(OBJECT(usbif->ports[port - 1].dev));
> usbif->ports[port - 1].dev = NULL;
> usbback_portid_detach(usbif, port);
> @@ -733,10 +728,10 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
> {
> unsigned speed;
> char *portname;
> - USBPort *p;
> Error *local_err = NULL;
> QDict *qdict;
> QemuOpts *opts;
> + char *tmp;
>
> if (usbif->ports[port - 1].dev) {
> return;
> @@ -749,11 +744,16 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
> return;
> }
> portname++;
> - p = &(usbif->ports[port - 1].port);
> - snprintf(p->path, sizeof(p->path), "%s", portname);
>
> qdict = qdict_new();
> qdict_put(qdict, "driver", qstring_from_str("usb-host"));
> + tmp = g_strdup_printf("%s.0", usbif->xendev.qdev.id);
> + qdict_put(qdict, "bus", qstring_from_str(tmp));
> + g_free(tmp);
> + tmp = g_strdup_printf("%s-%u", usbif->xendev.qdev.id, port);
> + qdict_put(qdict, "id", qstring_from_str(tmp));
> + g_free(tmp);
> + qdict_put(qdict, "port", qint_from_int(port));
> qdict_put(qdict, "hostbus", qint_from_int(atoi(busid)));
> qdict_put(qdict, "hostport", qstring_from_str(portname));
> opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
> @@ -765,7 +765,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
> goto err;
> }
> QDECREF(qdict);
> - snprintf(p->path, sizeof(p->path), "%d", port);
> speed = usbif->ports[port - 1].dev->speed;
> switch (speed) {
> case USB_SPEED_LOW:
> @@ -799,7 +798,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
>
> err:
> QDECREF(qdict);
> - snprintf(p->path, sizeof(p->path), "%d", 99);
> xen_pv_printf(&usbif->xendev, 0, "device %s could not be opened\n", busid);
> }
>
> @@ -1012,13 +1010,13 @@ static void usbback_alloc(struct XenDevice *xendev)
>
> usbif = container_of(xendev, struct usbback_info, xendev);
>
> - usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops, xen_sysdev);
> + usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops,
> + DEVICE(&xendev->qdev));
> for (i = 0; i < USBBACK_MAXPORTS; i++) {
> p = &(usbif->ports[i].port);
> usb_register_port(&usbif->bus, p, usbif, i, &xen_usb_port_ops,
> USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL |
> USB_SPEED_MASK_HIGH);
> - snprintf(p->path, sizeof(p->path), "%d", 99);
> }
>
> QTAILQ_INIT(&usbif->req_free_q);
> @@ -1066,7 +1064,6 @@ static int usbback_free(struct XenDevice *xendev)
> }
>
> usb_bus_release(&usbif->bus);
> - object_unparent(OBJECT(&usbif->bus));
>
> TR_BUS(xendev, "finished\n");
>
> --
> 2.6.6
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 4/4] xen: attach pvusb usb bus to backend qdev
@ 2016-11-19 4:34 ` Stefano Stabellini
0 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-19 4:34 UTC (permalink / raw)
To: Juergen Gross
Cc: xen-devel, armbru, qemu-devel, sstabellini, kraxel, anthony.perard
On Wed, 2 Nov 2016, Juergen Gross wrote:
> Attach the usb bus of a new pvusb controller to the qdev associated
> with the Xen backend. Any device connected to that controller can now
> specify the bus and port directly via its properties.
>
> Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
> hw/usb/xen-usb.c | 23 ++++++++++-------------
> 1 file changed, 10 insertions(+), 13 deletions(-)
>
> diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c
> index 1b3c2fb..8e676e6 100644
> --- a/hw/usb/xen-usb.c
> +++ b/hw/usb/xen-usb.c
> @@ -712,15 +712,10 @@ static void usbback_portid_detach(struct usbback_info *usbif, unsigned port)
>
> static void usbback_portid_remove(struct usbback_info *usbif, unsigned port)
> {
> - USBPort *p;
> -
> if (!usbif->ports[port - 1].dev) {
> return;
> }
>
> - p = &(usbif->ports[port - 1].port);
> - snprintf(p->path, sizeof(p->path), "%d", 99);
> -
> object_unparent(OBJECT(usbif->ports[port - 1].dev));
> usbif->ports[port - 1].dev = NULL;
> usbback_portid_detach(usbif, port);
> @@ -733,10 +728,10 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
> {
> unsigned speed;
> char *portname;
> - USBPort *p;
> Error *local_err = NULL;
> QDict *qdict;
> QemuOpts *opts;
> + char *tmp;
>
> if (usbif->ports[port - 1].dev) {
> return;
> @@ -749,11 +744,16 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
> return;
> }
> portname++;
> - p = &(usbif->ports[port - 1].port);
> - snprintf(p->path, sizeof(p->path), "%s", portname);
>
> qdict = qdict_new();
> qdict_put(qdict, "driver", qstring_from_str("usb-host"));
> + tmp = g_strdup_printf("%s.0", usbif->xendev.qdev.id);
> + qdict_put(qdict, "bus", qstring_from_str(tmp));
> + g_free(tmp);
> + tmp = g_strdup_printf("%s-%u", usbif->xendev.qdev.id, port);
> + qdict_put(qdict, "id", qstring_from_str(tmp));
> + g_free(tmp);
> + qdict_put(qdict, "port", qint_from_int(port));
> qdict_put(qdict, "hostbus", qint_from_int(atoi(busid)));
> qdict_put(qdict, "hostport", qstring_from_str(portname));
> opts = qemu_opts_from_qdict(qemu_find_opts("device"), qdict, &local_err);
> @@ -765,7 +765,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
> goto err;
> }
> QDECREF(qdict);
> - snprintf(p->path, sizeof(p->path), "%d", port);
> speed = usbif->ports[port - 1].dev->speed;
> switch (speed) {
> case USB_SPEED_LOW:
> @@ -799,7 +798,6 @@ static void usbback_portid_add(struct usbback_info *usbif, unsigned port,
>
> err:
> QDECREF(qdict);
> - snprintf(p->path, sizeof(p->path), "%d", 99);
> xen_pv_printf(&usbif->xendev, 0, "device %s could not be opened\n", busid);
> }
>
> @@ -1012,13 +1010,13 @@ static void usbback_alloc(struct XenDevice *xendev)
>
> usbif = container_of(xendev, struct usbback_info, xendev);
>
> - usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops, xen_sysdev);
> + usb_bus_new(&usbif->bus, sizeof(usbif->bus), &xen_usb_bus_ops,
> + DEVICE(&xendev->qdev));
> for (i = 0; i < USBBACK_MAXPORTS; i++) {
> p = &(usbif->ports[i].port);
> usb_register_port(&usbif->bus, p, usbif, i, &xen_usb_port_ops,
> USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL |
> USB_SPEED_MASK_HIGH);
> - snprintf(p->path, sizeof(p->path), "%d", 99);
> }
>
> QTAILQ_INIT(&usbif->req_free_q);
> @@ -1066,7 +1064,6 @@ static int usbback_free(struct XenDevice *xendev)
> }
>
> usb_bus_release(&usbif->bus);
> - object_unparent(OBJECT(&usbif->bus));
>
> TR_BUS(xendev, "finished\n");
>
> --
> 2.6.6
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v2 0/4] xed: add qdevs for each backend, correct pvUSB
2016-11-02 7:24 ` Juergen Gross
@ 2016-11-21 17:49 ` Stefano Stabellini
-1 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-21 17:49 UTC (permalink / raw)
To: Juergen Gross
Cc: qemu-devel, xen-devel, anthony.perard, kraxel, sstabellini, armbru
Hi Juergen,
it would be helpful if you could resend this series with the small
changes I requested. But if it is a problem for you, I can do that
myself while committing.
Cheers,
Stefano
On Wed, 2 Nov 2016, Juergen Gross wrote:
> Trying to use pvUSB in a Xen guest with a qemu emulated USB controller
> will crash qemu as it tries to attach a pvUSB device to the emulated
> controller.
>
> This can be avoided by adding a unique id to each pvUSB controller which
> can be used when attaching the pvUSB device. In order to make this
> possible the pvUSB controller has to be a hotpluggable qemu device.
>
> This is achieved by adding a qdev for each Xen backend all attached to
> a new Xen specific bus.
>
> Changes in V2:
> - one qdev for each backend instead of pvUSB only
>
> Juergen Gross (4):
> xen: add an own bus for xen backend devices
> qdev: add function qdev_set_id()
> xen: create qdev for each backend device
> xen: attach pvusb usb bus to backend qdev
>
> hw/usb/xen-usb.c | 23 +++++++--------
> hw/xen/xen_backend.c | 67 +++++++++++++++++++++++++++++++++++++++++---
> hw/xen/xen_pvdev.c | 5 +++-
> include/hw/xen/xen_backend.h | 8 ++++++
> include/hw/xen/xen_pvdev.h | 1 +
> include/monitor/qdev.h | 1 +
> qdev-monitor.c | 36 +++++++++++++-----------
> 7 files changed, 107 insertions(+), 34 deletions(-)
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 0/4] xed: add qdevs for each backend, correct pvUSB
@ 2016-11-21 17:49 ` Stefano Stabellini
0 siblings, 0 replies; 20+ messages in thread
From: Stefano Stabellini @ 2016-11-21 17:49 UTC (permalink / raw)
To: Juergen Gross
Cc: xen-devel, armbru, qemu-devel, sstabellini, kraxel, anthony.perard
Hi Juergen,
it would be helpful if you could resend this series with the small
changes I requested. But if it is a problem for you, I can do that
myself while committing.
Cheers,
Stefano
On Wed, 2 Nov 2016, Juergen Gross wrote:
> Trying to use pvUSB in a Xen guest with a qemu emulated USB controller
> will crash qemu as it tries to attach a pvUSB device to the emulated
> controller.
>
> This can be avoided by adding a unique id to each pvUSB controller which
> can be used when attaching the pvUSB device. In order to make this
> possible the pvUSB controller has to be a hotpluggable qemu device.
>
> This is achieved by adding a qdev for each Xen backend all attached to
> a new Xen specific bus.
>
> Changes in V2:
> - one qdev for each backend instead of pvUSB only
>
> Juergen Gross (4):
> xen: add an own bus for xen backend devices
> qdev: add function qdev_set_id()
> xen: create qdev for each backend device
> xen: attach pvusb usb bus to backend qdev
>
> hw/usb/xen-usb.c | 23 +++++++--------
> hw/xen/xen_backend.c | 67 +++++++++++++++++++++++++++++++++++++++++---
> hw/xen/xen_pvdev.c | 5 +++-
> include/hw/xen/xen_backend.h | 8 ++++++
> include/hw/xen/xen_pvdev.h | 1 +
> include/monitor/qdev.h | 1 +
> qdev-monitor.c | 36 +++++++++++++-----------
> 7 files changed, 107 insertions(+), 34 deletions(-)
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2016-11-21 17:49 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-02 7:24 [Qemu-devel] [PATCH v2 0/4] xed: add qdevs for each backend, correct pvUSB Juergen Gross
2016-11-02 7:24 ` Juergen Gross
2016-11-02 7:24 ` [Qemu-devel] [PATCH v2 1/4] xen: add an own bus for xen backend devices Juergen Gross
2016-11-02 7:24 ` Juergen Gross
2016-11-19 4:34 ` [Qemu-devel] " Stefano Stabellini
2016-11-19 4:34 ` Stefano Stabellini
2016-11-02 7:24 ` [Qemu-devel] [PATCH v2 2/4] qdev: add function qdev_set_id() Juergen Gross
2016-11-02 7:24 ` Juergen Gross
2016-11-19 4:34 ` [Qemu-devel] " Stefano Stabellini
2016-11-19 4:34 ` Stefano Stabellini
2016-11-02 7:24 ` [Qemu-devel] [PATCH v2 3/4] xen: create qdev for each backend device Juergen Gross
2016-11-02 7:24 ` Juergen Gross
2016-11-19 4:34 ` [Qemu-devel] " Stefano Stabellini
2016-11-19 4:34 ` Stefano Stabellini
2016-11-02 7:24 ` [Qemu-devel] [PATCH v2 4/4] xen: attach pvusb usb bus to backend qdev Juergen Gross
2016-11-02 7:24 ` Juergen Gross
2016-11-19 4:34 ` [Qemu-devel] " Stefano Stabellini
2016-11-19 4:34 ` Stefano Stabellini
2016-11-21 17:49 ` [Qemu-devel] [PATCH v2 0/4] xed: add qdevs for each backend, correct pvUSB Stefano Stabellini
2016-11-21 17:49 ` Stefano Stabellini
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.