* [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2013-01-02 14:08 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 02/15] virtio-bus : Introduce virtio-bus fred.konrad
` (13 subsequent siblings)
14 siblings, 1 reply; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Add a max_dev field to BusState to specify the maximum amount of devices allowed
on the bus ( have no effect if max_dev=0 )
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/qdev-core.h | 2 ++
hw/qdev-monitor.c | 11 +++++++++++
2 files changed, 13 insertions(+)
diff --git a/hw/qdev-core.h b/hw/qdev-core.h
index d672cca..af909b9 100644
--- a/hw/qdev-core.h
+++ b/hw/qdev-core.h
@@ -104,6 +104,8 @@ struct BusState {
const char *name;
int allow_hotplug;
int max_index;
+ /* maximum devices allowed on the bus, 0 : no limit. */
+ int max_dev;
QTAILQ_HEAD(ChildrenHead, BusChild) children;
QLIST_ENTRY(BusState) sibling;
};
diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
index a1b4d6a..7a9d275 100644
--- a/hw/qdev-monitor.c
+++ b/hw/qdev-monitor.c
@@ -292,6 +292,17 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) {
match = 0;
}
+ if ((bus->max_dev != 0) && (bus->max_dev <= bus->max_index)) {
+ if (name != NULL) {
+ /* bus was explicitly specified : return an error. */
+ qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full",
+ bus->name);
+ return NULL;
+ } else {
+ /* bus was not specified : try to find another one. */
+ match = 0;
+ }
+ }
if (match) {
return bus;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus fred.konrad
@ 2013-01-02 14:08 ` Anthony Liguori
2013-01-02 14:16 ` Andreas Färber
2013-01-03 14:03 ` KONRAD Frédéric
0 siblings, 2 replies; 35+ messages in thread
From: Anthony Liguori @ 2013-01-02 14:08 UTC (permalink / raw)
To: fred.konrad, qemu-devel
Cc: peter.maydell, e.voevodin, mark.burton, agraf, stefanha,
cornelia.huck, afaerber
fred.konrad@greensocs.com writes:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Add a max_dev field to BusState to specify the maximum amount of devices allowed
> on the bus ( have no effect if max_dev=0 )
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/qdev-core.h | 2 ++
> hw/qdev-monitor.c | 11 +++++++++++
> 2 files changed, 13 insertions(+)
>
> diff --git a/hw/qdev-core.h b/hw/qdev-core.h
> index d672cca..af909b9 100644
> --- a/hw/qdev-core.h
> +++ b/hw/qdev-core.h
> @@ -104,6 +104,8 @@ struct BusState {
> const char *name;
> int allow_hotplug;
> int max_index;
> + /* maximum devices allowed on the bus, 0 : no limit. */
> + int max_dev;
> QTAILQ_HEAD(ChildrenHead, BusChild) children;
> QLIST_ENTRY(BusState) sibling;
> };
> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
> index a1b4d6a..7a9d275 100644
> --- a/hw/qdev-monitor.c
> +++ b/hw/qdev-monitor.c
> @@ -292,6 +292,17 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
> if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) {
> match = 0;
> }
> + if ((bus->max_dev != 0) && (bus->max_dev <= bus->max_index)) {
> + if (name != NULL) {
> + /* bus was explicitly specified : return an error. */
> + qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full",
> + bus->name);
> + return NULL;
> + } else {
> + /* bus was not specified : try to find another one. */
> + match = 0;
> + }
> + }
> if (match) {
> return bus;
> }
Nice change, but I wonder if this should be a class property instead of
an object property? Would different objects of the same class ever set
this differently?
Regards,
Anthony Liguori
> --
> 1.7.11.7
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus.
2013-01-02 14:08 ` Anthony Liguori
@ 2013-01-02 14:16 ` Andreas Färber
2013-01-02 14:30 ` KONRAD Frédéric
2013-01-03 14:03 ` KONRAD Frédéric
1 sibling, 1 reply; 35+ messages in thread
From: Andreas Färber @ 2013-01-02 14:16 UTC (permalink / raw)
To: Anthony Liguori, fred.konrad
Cc: peter.maydell, e.voevodin, mark.burton, qemu-devel, agraf,
stefanha, cornelia.huck
Am 02.01.2013 15:08, schrieb Anthony Liguori:
> fred.konrad@greensocs.com writes:
>
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> Add a max_dev field to BusState to specify the maximum amount of devices allowed
>> on the bus ( have no effect if max_dev=0 )
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> ---
>> hw/qdev-core.h | 2 ++
>> hw/qdev-monitor.c | 11 +++++++++++
>> 2 files changed, 13 insertions(+)
>>
>> diff --git a/hw/qdev-core.h b/hw/qdev-core.h
>> index d672cca..af909b9 100644
>> --- a/hw/qdev-core.h
>> +++ b/hw/qdev-core.h
>> @@ -104,6 +104,8 @@ struct BusState {
>> const char *name;
>> int allow_hotplug;
>> int max_index;
>> + /* maximum devices allowed on the bus, 0 : no limit. */
>> + int max_dev;
Can't for the virtio-bus case (which this is for AFAIU) the same effect
be achieved by setting max_index? If not, this could use some more
documentation - btw using gtk-doc style comments (above struct) would be
a bonus.
Regards,
Andreas
P.S. Please remember to use English punctuation rules, i.e. no spaces
before colon or inside parenthesis. ;)
--
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus.
2013-01-02 14:16 ` Andreas Färber
@ 2013-01-02 14:30 ` KONRAD Frédéric
0 siblings, 0 replies; 35+ messages in thread
From: KONRAD Frédéric @ 2013-01-02 14:30 UTC (permalink / raw)
To: Andreas Färber
Cc: peter.maydell, Anthony Liguori, e.voevodin, mark.burton,
qemu-devel, agraf, stefanha, cornelia.huck
On 02/01/2013 15:16, Andreas Färber wrote:
> Am 02.01.2013 15:08, schrieb Anthony Liguori:
>> fred.konrad@greensocs.com writes:
>>
>>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>>
>>> Add a max_dev field to BusState to specify the maximum amount of devices allowed
>>> on the bus ( have no effect if max_dev=0 )
>>>
>>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>>> ---
>>> hw/qdev-core.h | 2 ++
>>> hw/qdev-monitor.c | 11 +++++++++++
>>> 2 files changed, 13 insertions(+)
>>>
>>> diff --git a/hw/qdev-core.h b/hw/qdev-core.h
>>> index d672cca..af909b9 100644
>>> --- a/hw/qdev-core.h
>>> +++ b/hw/qdev-core.h
>>> @@ -104,6 +104,8 @@ struct BusState {
>>> const char *name;
>>> int allow_hotplug;
>>> int max_index;
>>> + /* maximum devices allowed on the bus, 0 : no limit. */
>>> + int max_dev;
> Can't for the virtio-bus case (which this is for AFAIU) the same effect
> be achieved by setting max_index? If not, this could use some more
> documentation - btw using gtk-doc style comments (above struct) would be
> a bonus.
no, max_index is just a variable which count the number of bus children
I think.
max_index is incremented each time bus_add_child is called.
maybe the name max_index is not a good choice ?
>
> Regards,
> Andreas
>
> P.S. Please remember to use English punctuation rules, i.e. no spaces
> before colon or inside parenthesis. ;)
:s sorry for that.
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus.
2013-01-02 14:08 ` Anthony Liguori
2013-01-02 14:16 ` Andreas Färber
@ 2013-01-03 14:03 ` KONRAD Frédéric
1 sibling, 0 replies; 35+ messages in thread
From: KONRAD Frédéric @ 2013-01-03 14:03 UTC (permalink / raw)
To: Anthony Liguori
Cc: peter.maydell, e.voevodin, mark.burton, qemu-devel, agraf,
stefanha, cornelia.huck, afaerber
On 02/01/2013 15:08, Anthony Liguori wrote:
> fred.konrad@greensocs.com writes:
>
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> Add a max_dev field to BusState to specify the maximum amount of devices allowed
>> on the bus ( have no effect if max_dev=0 )
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> ---
>> hw/qdev-core.h | 2 ++
>> hw/qdev-monitor.c | 11 +++++++++++
>> 2 files changed, 13 insertions(+)
>>
>> diff --git a/hw/qdev-core.h b/hw/qdev-core.h
>> index d672cca..af909b9 100644
>> --- a/hw/qdev-core.h
>> +++ b/hw/qdev-core.h
>> @@ -104,6 +104,8 @@ struct BusState {
>> const char *name;
>> int allow_hotplug;
>> int max_index;
>> + /* maximum devices allowed on the bus, 0 : no limit. */
>> + int max_dev;
>> QTAILQ_HEAD(ChildrenHead, BusChild) children;
>> QLIST_ENTRY(BusState) sibling;
>> };
>> diff --git a/hw/qdev-monitor.c b/hw/qdev-monitor.c
>> index a1b4d6a..7a9d275 100644
>> --- a/hw/qdev-monitor.c
>> +++ b/hw/qdev-monitor.c
>> @@ -292,6 +292,17 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name,
>> if (bus_typename && !object_dynamic_cast(OBJECT(bus), bus_typename)) {
>> match = 0;
>> }
>> + if ((bus->max_dev != 0) && (bus->max_dev <= bus->max_index)) {
>> + if (name != NULL) {
>> + /* bus was explicitly specified : return an error. */
>> + qerror_report(ERROR_CLASS_GENERIC_ERROR, "Bus '%s' is full",
>> + bus->name);
>> + return NULL;
>> + } else {
>> + /* bus was not specified : try to find another one. */
>> + match = 0;
>> + }
>> + }
>> if (match) {
>> return bus;
>> }
> Nice change, but I wonder if this should be a class property instead of
> an object property? Would different objects of the same class ever set
> this differently?
I don't know. What do you think is the best ?
Fred
>
> Regards,
>
> Anthony Liguori
>
>> --
>> 1.7.11.7
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 02/15] virtio-bus : Introduce virtio-bus
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2013-01-02 14:12 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 03/15] virtio-pci-bus : Introduce virtio-pci-bus fred.konrad
` (12 subsequent siblings)
14 siblings, 1 reply; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Introduce virtio-bus. Refactored transport device will create a bus which
extends virtio-bus.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/Makefile.objs | 1 +
hw/virtio-bus.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/virtio-bus.h | 98 ++++++++++++++++++++++++++++++++
3 files changed, 268 insertions(+)
create mode 100644 hw/virtio-bus.c
create mode 100644 hw/virtio-bus.h
diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index d581d8d..6fa4de4 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -3,6 +3,7 @@ common-obj-y += loader.o
common-obj-$(CONFIG_VIRTIO) += virtio-console.o
common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
+common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
common-obj-y += fw_cfg.o
common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
common-obj-$(CONFIG_PCI) += msix.o msi.o
diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
new file mode 100644
index 0000000..7a3d06e
--- /dev/null
+++ b/hw/virtio-bus.c
@@ -0,0 +1,169 @@
+/*
+ * VirtioBus
+ *
+ * Copyright (C) 2012 : GreenSocs Ltd
+ * http://www.greensocs.com/ , email: info@greensocs.com
+ *
+ * Developed by :
+ * Frederic Konrad <fred.konrad@greensocs.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "hw.h"
+#include "qemu-error.h"
+#include "qdev.h"
+#include "virtio-bus.h"
+#include "virtio.h"
+
+/* #define DEBUG_VIRTIO_BUS */
+
+#ifdef DEBUG_VIRTIO_BUS
+#define DPRINTF(fmt, ...) \
+do { printf("virtio_bus: " fmt , ## __VA_ARGS__); } while (0)
+#else
+#define DPRINTF(fmt, ...) do { } while (0)
+#endif
+
+/* Plug the VirtIODevice */
+int virtio_bus_plug_device(VirtIODevice *vdev)
+{
+ DeviceState *qdev = DEVICE(vdev);
+ BusState *qbus = BUS(qdev_get_parent_bus(qdev));
+ VirtioBusState *bus = VIRTIO_BUS(qbus);
+ VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
+ DPRINTF("%s : plug device.\n", qbus->name);
+
+ bus->vdev = vdev;
+
+ if (klass->device_plugged != NULL) {
+ klass->device_plugged(qbus->parent);
+ }
+
+ /*
+ * The lines below will disappear when we drop VirtIOBindings, at the end
+ * of the serie.
+ */
+ bus->bindings.notify = klass->notify;
+ bus->bindings.save_config = klass->save_config;
+ bus->bindings.save_queue = klass->save_queue;
+ bus->bindings.load_config = klass->load_config;
+ bus->bindings.load_queue = klass->load_queue;
+ bus->bindings.load_done = klass->load_done;
+ bus->bindings.get_features = klass->get_features;
+ bus->bindings.query_guest_notifiers = klass->query_guest_notifiers;
+ bus->bindings.set_guest_notifiers = klass->set_guest_notifiers;
+ bus->bindings.set_host_notifier = klass->set_host_notifier;
+ bus->bindings.vmstate_change = klass->vmstate_change;
+ virtio_bind_device(bus->vdev, &(bus->bindings), qbus->parent);
+ /*
+ */
+
+ return 0;
+}
+
+/* Reset the virtio_bus */
+void virtio_bus_reset(VirtioBusState *bus)
+{
+ DPRINTF("%s : reset device.\n", qbus->name);
+ if (bus->vdev != NULL) {
+ virtio_reset(bus->vdev);
+ }
+}
+
+/* Destroy the VirtIODevice */
+void virtio_bus_destroy_device(VirtioBusState *bus)
+{
+ DeviceState *qdev;
+ BusState *qbus = BUS(bus);
+ VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
+ DPRINTF("%s : remove device.\n", qbus->name);
+
+ if (bus->vdev != NULL) {
+ if (klass->device_unplug != NULL) {
+ klass->device_unplug(qbus->parent);
+ }
+ qdev = DEVICE(bus->vdev);
+ qdev_free(qdev);
+ bus->vdev = NULL;
+ }
+}
+
+/* Get the device id of the plugged device. */
+uint16_t get_virtio_device_id(VirtioBusState *bus)
+{
+ assert(bus->vdev != NULL);
+ return bus->vdev->device_id;
+}
+
+/* Get the nvectors field of the plugged device. */
+int get_virtio_device_nvectors(VirtioBusState *bus)
+{
+ assert(bus->vdev != NULL);
+ return bus->vdev->nvectors;
+}
+
+/* Set the nvectors field of the plugged device. */
+void set_virtio_device_nvectors(VirtioBusState *bus, int nvectors)
+{
+ assert(bus->vdev != NULL);
+ bus->vdev->nvectors = nvectors;
+}
+
+/* Get the config_len field of the plugged device. */
+size_t get_virtio_device_config_len(VirtioBusState *bus)
+{
+ assert(bus->vdev != NULL);
+ return bus->vdev->config_len;
+}
+
+/* Get the features of the plugged device. */
+uint32_t get_virtio_device_features(VirtioBusState *bus,
+ uint32_t requested_features)
+{
+ VirtioDeviceClass *k;
+ assert(bus->vdev != NULL);
+ k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
+ assert(k->get_features != NULL);
+ return k->get_features(bus->vdev, requested_features);
+}
+
+/* Get the bad features of the plugged device. */
+uint32_t get_virtio_device_bad_features(VirtioBusState *bus)
+{
+ VirtioDeviceClass *k;
+ assert(bus->vdev != NULL);
+ k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
+ if (k->bad_features != NULL) {
+ return k->bad_features(bus->vdev);
+ } else {
+ return 0;
+ }
+}
+
+static const TypeInfo virtio_bus_info = {
+ .name = TYPE_VIRTIO_BUS,
+ .parent = TYPE_BUS,
+ .instance_size = sizeof(VirtioBusState),
+ .abstract = true,
+ .class_size = sizeof(VirtioBusClass),
+};
+
+static void virtio_register_types(void)
+{
+ type_register_static(&virtio_bus_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-bus.h b/hw/virtio-bus.h
new file mode 100644
index 0000000..a2e2012
--- /dev/null
+++ b/hw/virtio-bus.h
@@ -0,0 +1,98 @@
+/*
+ * VirtioBus
+ *
+ * Copyright (C) 2012 : GreenSocs Ltd
+ * http://www.greensocs.com/ , email: info@greensocs.com
+ *
+ * Developed by :
+ * Frederic Konrad <fred.konrad@greensocs.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef VIRTIO_BUS_H
+#define VIRTIO_BUS_H
+
+#include "qdev.h"
+#include "sysemu.h"
+#include "virtio.h"
+
+#define TYPE_VIRTIO_BUS "virtio-bus"
+#define VIRTIO_BUS_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
+#define VIRTIO_BUS_CLASS(klass) \
+ OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
+#define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
+
+typedef struct VirtioBusState VirtioBusState;
+
+typedef struct VirtioBusClass {
+ /* This is what a VirtioBus must implement */
+ BusClass parent;
+ void (*notify)(void *opaque, uint16_t vector);
+ void (*save_config)(void *opaque, QEMUFile *f);
+ void (*save_queue)(void *opaque, int n, QEMUFile *f);
+ int (*load_config)(void *opaque, QEMUFile *f);
+ int (*load_queue)(void *opaque, int n, QEMUFile *f);
+ int (*load_done)(void *opaque, QEMUFile *f);
+ unsigned (*get_features)(void *opaque);
+ bool (*query_guest_notifiers)(void *opaque);
+ int (*set_guest_notifiers)(void *opaque, bool assigned);
+ int (*set_host_notifier)(void *opaque, int n, bool assigned);
+ void (*vmstate_change)(void *opaque, bool running);
+ /*
+ * transport independent init function.
+ * This is called by virtio-bus just after the device is plugged.
+ */
+ void (*device_plugged)(void *opaque);
+ /*
+ * transport independent exit function.
+ * This is called by virtio-bus just before the device is unplugged.
+ */
+ void (*device_unplug)(void *opaque);
+} VirtioBusClass;
+
+struct VirtioBusState {
+ BusState parent_obj;
+ /*
+ * Only one VirtIODevice can be plugged on the bus.
+ */
+ VirtIODevice *vdev;
+ /*
+ * This will be removed at the end of the serie.
+ */
+ VirtIOBindings bindings;
+ /*
+ */
+};
+
+int virtio_bus_plug_device(VirtIODevice *vdev);
+void virtio_bus_reset(VirtioBusState *bus);
+void virtio_bus_destroy_device(VirtioBusState *bus);
+/* Get the device id of the plugged device. */
+uint16_t get_virtio_device_id(VirtioBusState *bus);
+/* Get the nvectors field of the plugged device. */
+int get_virtio_device_nvectors(VirtioBusState *bus);
+/* Set the nvectors field of the plugged device. */
+void set_virtio_device_nvectors(VirtioBusState *bus, int nvectors);
+/* Get the config_len field of the plugged device. */
+size_t get_virtio_device_config_len(VirtioBusState *bus);
+/* Get the features of the plugged device. */
+uint32_t get_virtio_device_features(VirtioBusState *bus,
+ uint32_t requested_features);
+/* Get the bad features of the plugged device. */
+uint32_t get_virtio_device_bad_features(VirtioBusState *bus);
+
+#endif /* VIRTIO_BUS_H */
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 02/15] virtio-bus : Introduce virtio-bus
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 02/15] virtio-bus : Introduce virtio-bus fred.konrad
@ 2013-01-02 14:12 ` Anthony Liguori
2013-01-03 9:57 ` KONRAD Frédéric
0 siblings, 1 reply; 35+ messages in thread
From: Anthony Liguori @ 2013-01-02 14:12 UTC (permalink / raw)
To: fred.konrad, qemu-devel
Cc: peter.maydell, e.voevodin, mark.burton, agraf, stefanha,
cornelia.huck, afaerber
fred.konrad@greensocs.com writes:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Introduce virtio-bus. Refactored transport device will create a bus which
> extends virtio-bus.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/Makefile.objs | 1 +
> hw/virtio-bus.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/virtio-bus.h | 98 ++++++++++++++++++++++++++++++++
> 3 files changed, 268 insertions(+)
> create mode 100644 hw/virtio-bus.c
> create mode 100644 hw/virtio-bus.h
>
> diff --git a/hw/Makefile.objs b/hw/Makefile.objs
> index d581d8d..6fa4de4 100644
> --- a/hw/Makefile.objs
> +++ b/hw/Makefile.objs
> @@ -3,6 +3,7 @@ common-obj-y += loader.o
> common-obj-$(CONFIG_VIRTIO) += virtio-console.o
> common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
> common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
> +common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
> common-obj-y += fw_cfg.o
> common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
> common-obj-$(CONFIG_PCI) += msix.o msi.o
> diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
> new file mode 100644
> index 0000000..7a3d06e
> --- /dev/null
> +++ b/hw/virtio-bus.c
> @@ -0,0 +1,169 @@
> +/*
> + * VirtioBus
> + *
> + * Copyright (C) 2012 : GreenSocs Ltd
> + * http://www.greensocs.com/ , email: info@greensocs.com
> + *
> + * Developed by :
> + * Frederic Konrad <fred.konrad@greensocs.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, see <http://www.gnu.org/licenses/>.
> + *
> + */
> +
> +#include "hw.h"
> +#include "qemu-error.h"
> +#include "qdev.h"
> +#include "virtio-bus.h"
> +#include "virtio.h"
> +
> +/* #define DEBUG_VIRTIO_BUS */
> +
> +#ifdef DEBUG_VIRTIO_BUS
> +#define DPRINTF(fmt, ...) \
> +do { printf("virtio_bus: " fmt , ## __VA_ARGS__); } while (0)
> +#else
> +#define DPRINTF(fmt, ...) do { } while (0)
> +#endif
> +
> +/* Plug the VirtIODevice */
> +int virtio_bus_plug_device(VirtIODevice *vdev)
> +{
> + DeviceState *qdev = DEVICE(vdev);
> + BusState *qbus = BUS(qdev_get_parent_bus(qdev));
> + VirtioBusState *bus = VIRTIO_BUS(qbus);
> + VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
> + DPRINTF("%s : plug device.\n", qbus->name);
> +
> + bus->vdev = vdev;
> +
> + if (klass->device_plugged != NULL) {
> + klass->device_plugged(qbus->parent);
> + }
> +
> + /*
> + * The lines below will disappear when we drop VirtIOBindings, at the end
> + * of the serie.
s/serie/series/g
> + */
> + bus->bindings.notify = klass->notify;
> + bus->bindings.save_config = klass->save_config;
> + bus->bindings.save_queue = klass->save_queue;
> + bus->bindings.load_config = klass->load_config;
> + bus->bindings.load_queue = klass->load_queue;
> + bus->bindings.load_done = klass->load_done;
> + bus->bindings.get_features = klass->get_features;
> + bus->bindings.query_guest_notifiers = klass->query_guest_notifiers;
> + bus->bindings.set_guest_notifiers = klass->set_guest_notifiers;
> + bus->bindings.set_host_notifier = klass->set_host_notifier;
> + bus->bindings.vmstate_change = klass->vmstate_change;
> + virtio_bind_device(bus->vdev, &(bus->bindings), qbus->parent);
> + /*
> + */
No need for empty comment or the parens around bus->bindings.
> +
> + return 0;
> +}
> +
> +/* Reset the virtio_bus */
> +void virtio_bus_reset(VirtioBusState *bus)
> +{
> + DPRINTF("%s : reset device.\n", qbus->name);
> + if (bus->vdev != NULL) {
> + virtio_reset(bus->vdev);
> + }
> +}
> +
> +/* Destroy the VirtIODevice */
> +void virtio_bus_destroy_device(VirtioBusState *bus)
> +{
> + DeviceState *qdev;
> + BusState *qbus = BUS(bus);
> + VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
> + DPRINTF("%s : remove device.\n", qbus->name);
> +
> + if (bus->vdev != NULL) {
> + if (klass->device_unplug != NULL) {
> + klass->device_unplug(qbus->parent);
> + }
> + qdev = DEVICE(bus->vdev);
> + qdev_free(qdev);
> + bus->vdev = NULL;
> + }
> +}
> +
> +/* Get the device id of the plugged device. */
> +uint16_t get_virtio_device_id(VirtioBusState *bus)
> +{
> + assert(bus->vdev != NULL);
> + return bus->vdev->device_id;
> +}
> +
> +/* Get the nvectors field of the plugged device. */
> +int get_virtio_device_nvectors(VirtioBusState *bus)
> +{
> + assert(bus->vdev != NULL);
> + return bus->vdev->nvectors;
> +}
> +
> +/* Set the nvectors field of the plugged device. */
> +void set_virtio_device_nvectors(VirtioBusState *bus, int nvectors)
> +{
> + assert(bus->vdev != NULL);
> + bus->vdev->nvectors = nvectors;
> +}
> +
> +/* Get the config_len field of the plugged device. */
> +size_t get_virtio_device_config_len(VirtioBusState *bus)
> +{
> + assert(bus->vdev != NULL);
> + return bus->vdev->config_len;
> +}
> +
> +/* Get the features of the plugged device. */
> +uint32_t get_virtio_device_features(VirtioBusState *bus,
> + uint32_t requested_features)
> +{
> + VirtioDeviceClass *k;
> + assert(bus->vdev != NULL);
> + k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
> + assert(k->get_features != NULL);
> + return k->get_features(bus->vdev, requested_features);
> +}
> +
> +/* Get the bad features of the plugged device. */
> +uint32_t get_virtio_device_bad_features(VirtioBusState *bus)
> +{
> + VirtioDeviceClass *k;
> + assert(bus->vdev != NULL);
> + k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
> + if (k->bad_features != NULL) {
> + return k->bad_features(bus->vdev);
> + } else {
> + return 0;
> + }
> +}
These functions should be in the form:
virtio_device_get_bad_features()
With 'virtio_device_' as the common prefix.
> +static const TypeInfo virtio_bus_info = {
> + .name = TYPE_VIRTIO_BUS,
> + .parent = TYPE_BUS,
> + .instance_size = sizeof(VirtioBusState),
> + .abstract = true,
> + .class_size = sizeof(VirtioBusClass),
> +};
> +
> +static void virtio_register_types(void)
> +{
> + type_register_static(&virtio_bus_info);
> +}
> +
> +type_init(virtio_register_types)
> diff --git a/hw/virtio-bus.h b/hw/virtio-bus.h
> new file mode 100644
> index 0000000..a2e2012
> --- /dev/null
> +++ b/hw/virtio-bus.h
> @@ -0,0 +1,98 @@
> +/*
> + * VirtioBus
> + *
> + * Copyright (C) 2012 : GreenSocs Ltd
> + * http://www.greensocs.com/ , email: info@greensocs.com
> + *
> + * Developed by :
> + * Frederic Konrad <fred.konrad@greensocs.com>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation, either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License along
> + * with this program; if not, see <http://www.gnu.org/licenses/>.
> + *
> + */
> +
> +#ifndef VIRTIO_BUS_H
> +#define VIRTIO_BUS_H
> +
> +#include "qdev.h"
> +#include "sysemu.h"
> +#include "virtio.h"
> +
> +#define TYPE_VIRTIO_BUS "virtio-bus"
> +#define VIRTIO_BUS_GET_CLASS(obj) \
> + OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
> +#define VIRTIO_BUS_CLASS(klass) \
> + OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
> +#define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
> +
> +typedef struct VirtioBusState VirtioBusState;
> +
> +typedef struct VirtioBusClass {
> + /* This is what a VirtioBus must implement */
> + BusClass parent;
> + void (*notify)(void *opaque, uint16_t vector);
> + void (*save_config)(void *opaque, QEMUFile *f);
> + void (*save_queue)(void *opaque, int n, QEMUFile *f);
> + int (*load_config)(void *opaque, QEMUFile *f);
> + int (*load_queue)(void *opaque, int n, QEMUFile *f);
> + int (*load_done)(void *opaque, QEMUFile *f);
> + unsigned (*get_features)(void *opaque);
> + bool (*query_guest_notifiers)(void *opaque);
> + int (*set_guest_notifiers)(void *opaque, bool assigned);
> + int (*set_host_notifier)(void *opaque, int n, bool assigned);
> + void (*vmstate_change)(void *opaque, bool running);
> + /*
> + * transport independent init function.
> + * This is called by virtio-bus just after the device is plugged.
> + */
> + void (*device_plugged)(void *opaque);
> + /*
> + * transport independent exit function.
> + * This is called by virtio-bus just before the device is unplugged.
> + */
> + void (*device_unplug)(void *opaque);
These should not take a 'void *' but rather a VirtIODevice. You can
just do a cast in the short term to handle the mismatch with
VirtIOBindings.
Regards,
Anthony Liguori
> +} VirtioBusClass;
> +
> +struct VirtioBusState {
> + BusState parent_obj;
> + /*
> + * Only one VirtIODevice can be plugged on the bus.
> + */
> + VirtIODevice *vdev;
> + /*
> + * This will be removed at the end of the serie.
> + */
> + VirtIOBindings bindings;
> + /*
> + */
> +};
> +
> +int virtio_bus_plug_device(VirtIODevice *vdev);
> +void virtio_bus_reset(VirtioBusState *bus);
> +void virtio_bus_destroy_device(VirtioBusState *bus);
> +/* Get the device id of the plugged device. */
> +uint16_t get_virtio_device_id(VirtioBusState *bus);
> +/* Get the nvectors field of the plugged device. */
> +int get_virtio_device_nvectors(VirtioBusState *bus);
> +/* Set the nvectors field of the plugged device. */
> +void set_virtio_device_nvectors(VirtioBusState *bus, int nvectors);
> +/* Get the config_len field of the plugged device. */
> +size_t get_virtio_device_config_len(VirtioBusState *bus);
> +/* Get the features of the plugged device. */
> +uint32_t get_virtio_device_features(VirtioBusState *bus,
> + uint32_t requested_features);
> +/* Get the bad features of the plugged device. */
> +uint32_t get_virtio_device_bad_features(VirtioBusState *bus);
> +
> +#endif /* VIRTIO_BUS_H */
> --
> 1.7.11.7
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 02/15] virtio-bus : Introduce virtio-bus
2013-01-02 14:12 ` Anthony Liguori
@ 2013-01-03 9:57 ` KONRAD Frédéric
0 siblings, 0 replies; 35+ messages in thread
From: KONRAD Frédéric @ 2013-01-03 9:57 UTC (permalink / raw)
To: Anthony Liguori
Cc: peter.maydell, e.voevodin, mark.burton, qemu-devel, agraf,
stefanha, cornelia.huck, afaerber
On 02/01/2013 15:12, Anthony Liguori wrote:
> fred.konrad@greensocs.com writes:
>
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> Introduce virtio-bus. Refactored transport device will create a bus which
>> extends virtio-bus.
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> ---
>> hw/Makefile.objs | 1 +
>> hw/virtio-bus.c | 169 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> hw/virtio-bus.h | 98 ++++++++++++++++++++++++++++++++
>> 3 files changed, 268 insertions(+)
>> create mode 100644 hw/virtio-bus.c
>> create mode 100644 hw/virtio-bus.h
>>
>> diff --git a/hw/Makefile.objs b/hw/Makefile.objs
>> index d581d8d..6fa4de4 100644
>> --- a/hw/Makefile.objs
>> +++ b/hw/Makefile.objs
>> @@ -3,6 +3,7 @@ common-obj-y += loader.o
>> common-obj-$(CONFIG_VIRTIO) += virtio-console.o
>> common-obj-$(CONFIG_VIRTIO) += virtio-rng.o
>> common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
>> +common-obj-$(CONFIG_VIRTIO) += virtio-bus.o
>> common-obj-y += fw_cfg.o
>> common-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_bridge_dev.o
>> common-obj-$(CONFIG_PCI) += msix.o msi.o
>> diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
>> new file mode 100644
>> index 0000000..7a3d06e
>> --- /dev/null
>> +++ b/hw/virtio-bus.c
>> @@ -0,0 +1,169 @@
>> +/*
>> + * VirtioBus
>> + *
>> + * Copyright (C) 2012 : GreenSocs Ltd
>> + * http://www.greensocs.com/ , email: info@greensocs.com
>> + *
>> + * Developed by :
>> + * Frederic Konrad <fred.konrad@greensocs.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation, either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License along
>> + * with this program; if not, see <http://www.gnu.org/licenses/>.
>> + *
>> + */
>> +
>> +#include "hw.h"
>> +#include "qemu-error.h"
>> +#include "qdev.h"
>> +#include "virtio-bus.h"
>> +#include "virtio.h"
>> +
>> +/* #define DEBUG_VIRTIO_BUS */
>> +
>> +#ifdef DEBUG_VIRTIO_BUS
>> +#define DPRINTF(fmt, ...) \
>> +do { printf("virtio_bus: " fmt , ## __VA_ARGS__); } while (0)
>> +#else
>> +#define DPRINTF(fmt, ...) do { } while (0)
>> +#endif
>> +
>> +/* Plug the VirtIODevice */
>> +int virtio_bus_plug_device(VirtIODevice *vdev)
>> +{
>> + DeviceState *qdev = DEVICE(vdev);
>> + BusState *qbus = BUS(qdev_get_parent_bus(qdev));
>> + VirtioBusState *bus = VIRTIO_BUS(qbus);
>> + VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
>> + DPRINTF("%s : plug device.\n", qbus->name);
>> +
>> + bus->vdev = vdev;
>> +
>> + if (klass->device_plugged != NULL) {
>> + klass->device_plugged(qbus->parent);
>> + }
>> +
>> + /*
>> + * The lines below will disappear when we drop VirtIOBindings, at the end
>> + * of the serie.
> s/serie/series/g
>
>> + */
>> + bus->bindings.notify = klass->notify;
>> + bus->bindings.save_config = klass->save_config;
>> + bus->bindings.save_queue = klass->save_queue;
>> + bus->bindings.load_config = klass->load_config;
>> + bus->bindings.load_queue = klass->load_queue;
>> + bus->bindings.load_done = klass->load_done;
>> + bus->bindings.get_features = klass->get_features;
>> + bus->bindings.query_guest_notifiers = klass->query_guest_notifiers;
>> + bus->bindings.set_guest_notifiers = klass->set_guest_notifiers;
>> + bus->bindings.set_host_notifier = klass->set_host_notifier;
>> + bus->bindings.vmstate_change = klass->vmstate_change;
>> + virtio_bind_device(bus->vdev, &(bus->bindings), qbus->parent);
>> + /*
>> + */
> No need for empty comment or the parens around bus->bindings.
>
>> +
>> + return 0;
>> +}
>> +
>> +/* Reset the virtio_bus */
>> +void virtio_bus_reset(VirtioBusState *bus)
>> +{
>> + DPRINTF("%s : reset device.\n", qbus->name);
>> + if (bus->vdev != NULL) {
>> + virtio_reset(bus->vdev);
>> + }
>> +}
>> +
>> +/* Destroy the VirtIODevice */
>> +void virtio_bus_destroy_device(VirtioBusState *bus)
>> +{
>> + DeviceState *qdev;
>> + BusState *qbus = BUS(bus);
>> + VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus);
>> + DPRINTF("%s : remove device.\n", qbus->name);
>> +
>> + if (bus->vdev != NULL) {
>> + if (klass->device_unplug != NULL) {
>> + klass->device_unplug(qbus->parent);
>> + }
>> + qdev = DEVICE(bus->vdev);
>> + qdev_free(qdev);
>> + bus->vdev = NULL;
>> + }
>> +}
>> +
>> +/* Get the device id of the plugged device. */
>> +uint16_t get_virtio_device_id(VirtioBusState *bus)
>> +{
>> + assert(bus->vdev != NULL);
>> + return bus->vdev->device_id;
>> +}
>> +
>> +/* Get the nvectors field of the plugged device. */
>> +int get_virtio_device_nvectors(VirtioBusState *bus)
>> +{
>> + assert(bus->vdev != NULL);
>> + return bus->vdev->nvectors;
>> +}
>> +
>> +/* Set the nvectors field of the plugged device. */
>> +void set_virtio_device_nvectors(VirtioBusState *bus, int nvectors)
>> +{
>> + assert(bus->vdev != NULL);
>> + bus->vdev->nvectors = nvectors;
>> +}
>> +
>> +/* Get the config_len field of the plugged device. */
>> +size_t get_virtio_device_config_len(VirtioBusState *bus)
>> +{
>> + assert(bus->vdev != NULL);
>> + return bus->vdev->config_len;
>> +}
>> +
>> +/* Get the features of the plugged device. */
>> +uint32_t get_virtio_device_features(VirtioBusState *bus,
>> + uint32_t requested_features)
>> +{
>> + VirtioDeviceClass *k;
>> + assert(bus->vdev != NULL);
>> + k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
>> + assert(k->get_features != NULL);
>> + return k->get_features(bus->vdev, requested_features);
>> +}
>> +
>> +/* Get the bad features of the plugged device. */
>> +uint32_t get_virtio_device_bad_features(VirtioBusState *bus)
>> +{
>> + VirtioDeviceClass *k;
>> + assert(bus->vdev != NULL);
>> + k = VIRTIO_DEVICE_GET_CLASS(bus->vdev);
>> + if (k->bad_features != NULL) {
>> + return k->bad_features(bus->vdev);
>> + } else {
>> + return 0;
>> + }
>> +}
> These functions should be in the form:
>
> virtio_device_get_bad_features()
>
> With 'virtio_device_' as the common prefix.
>
>> +static const TypeInfo virtio_bus_info = {
>> + .name = TYPE_VIRTIO_BUS,
>> + .parent = TYPE_BUS,
>> + .instance_size = sizeof(VirtioBusState),
>> + .abstract = true,
>> + .class_size = sizeof(VirtioBusClass),
>> +};
>> +
>> +static void virtio_register_types(void)
>> +{
>> + type_register_static(&virtio_bus_info);
>> +}
>> +
>> +type_init(virtio_register_types)
>> diff --git a/hw/virtio-bus.h b/hw/virtio-bus.h
>> new file mode 100644
>> index 0000000..a2e2012
>> --- /dev/null
>> +++ b/hw/virtio-bus.h
>> @@ -0,0 +1,98 @@
>> +/*
>> + * VirtioBus
>> + *
>> + * Copyright (C) 2012 : GreenSocs Ltd
>> + * http://www.greensocs.com/ , email: info@greensocs.com
>> + *
>> + * Developed by :
>> + * Frederic Konrad <fred.konrad@greensocs.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation, either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License along
>> + * with this program; if not, see <http://www.gnu.org/licenses/>.
>> + *
>> + */
>> +
>> +#ifndef VIRTIO_BUS_H
>> +#define VIRTIO_BUS_H
>> +
>> +#include "qdev.h"
>> +#include "sysemu.h"
>> +#include "virtio.h"
>> +
>> +#define TYPE_VIRTIO_BUS "virtio-bus"
>> +#define VIRTIO_BUS_GET_CLASS(obj) \
>> + OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_BUS)
>> +#define VIRTIO_BUS_CLASS(klass) \
>> + OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_BUS)
>> +#define VIRTIO_BUS(obj) OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_BUS)
>> +
>> +typedef struct VirtioBusState VirtioBusState;
>> +
>> +typedef struct VirtioBusClass {
>> + /* This is what a VirtioBus must implement */
>> + BusClass parent;
>> + void (*notify)(void *opaque, uint16_t vector);
>> + void (*save_config)(void *opaque, QEMUFile *f);
>> + void (*save_queue)(void *opaque, int n, QEMUFile *f);
>> + int (*load_config)(void *opaque, QEMUFile *f);
>> + int (*load_queue)(void *opaque, int n, QEMUFile *f);
>> + int (*load_done)(void *opaque, QEMUFile *f);
>> + unsigned (*get_features)(void *opaque);
>> + bool (*query_guest_notifiers)(void *opaque);
>> + int (*set_guest_notifiers)(void *opaque, bool assigned);
>> + int (*set_host_notifier)(void *opaque, int n, bool assigned);
>> + void (*vmstate_change)(void *opaque, bool running);
>> + /*
>> + * transport independent init function.
>> + * This is called by virtio-bus just after the device is plugged.
>> + */
>> + void (*device_plugged)(void *opaque);
>> + /*
>> + * transport independent exit function.
>> + * This is called by virtio-bus just before the device is unplugged.
>> + */
>> + void (*device_unplug)(void *opaque);
> These should not take a 'void *' but rather a VirtIODevice. You can
> just do a cast in the short term to handle the mismatch with
> VirtIOBindings.
Are you sure ?
Here the opaque argument is not pointing a VirtIODevice but a transport.
eg for virtio-pci :
static void virtio_pci_notify(void *opaque, uint16_t vector)
{
VirtIOPCIProxy *proxy = opaque;
if (msix_enabled(&proxy->pci_dev))
msix_notify(&proxy->pci_dev, vector);
else
qemu_set_irq(proxy->pci_dev.irq[0], proxy->vdev->isr & 1);
}
>
> Regards,
>
> Anthony Liguori
>
>> +} VirtioBusClass;
>> +
>> +struct VirtioBusState {
>> + BusState parent_obj;
>> + /*
>> + * Only one VirtIODevice can be plugged on the bus.
>> + */
>> + VirtIODevice *vdev;
>> + /*
>> + * This will be removed at the end of the serie.
>> + */
>> + VirtIOBindings bindings;
>> + /*
>> + */
>> +};
>> +
>> +int virtio_bus_plug_device(VirtIODevice *vdev);
>> +void virtio_bus_reset(VirtioBusState *bus);
>> +void virtio_bus_destroy_device(VirtioBusState *bus);
>> +/* Get the device id of the plugged device. */
>> +uint16_t get_virtio_device_id(VirtioBusState *bus);
>> +/* Get the nvectors field of the plugged device. */
>> +int get_virtio_device_nvectors(VirtioBusState *bus);
>> +/* Set the nvectors field of the plugged device. */
>> +void set_virtio_device_nvectors(VirtioBusState *bus, int nvectors);
>> +/* Get the config_len field of the plugged device. */
>> +size_t get_virtio_device_config_len(VirtioBusState *bus);
>> +/* Get the features of the plugged device. */
>> +uint32_t get_virtio_device_features(VirtioBusState *bus,
>> + uint32_t requested_features);
>> +/* Get the bad features of the plugged device. */
>> +uint32_t get_virtio_device_bad_features(VirtioBusState *bus);
>> +
>> +#endif /* VIRTIO_BUS_H */
>> --
>> 1.7.11.7
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 03/15] virtio-pci-bus : Introduce virtio-pci-bus.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 01/15] qdev : add a maximum device allowed field for the bus fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 02/15] virtio-bus : Introduce virtio-bus fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2013-01-02 14:12 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device fred.konrad
` (11 subsequent siblings)
14 siblings, 1 reply; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Introduce virtio-pci-bus, which extends virtio-bus. It is used with virtio-pci
transport device.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-pci.c | 37 +++++++++++++++++++++++++++++++++++++
hw/virtio-pci.h | 19 +++++++++++++++++--
2 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 7684ac9..859a1ed 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -32,6 +32,7 @@
#include "blockdev.h"
#include "virtio-pci.h"
#include "range.h"
+#include "virtio-bus.h"
/* from Linux's linux/virtio_pci.h */
@@ -1117,6 +1118,41 @@ static TypeInfo virtio_scsi_info = {
.class_init = virtio_scsi_class_init,
};
+/* virtio-pci-bus */
+
+VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
+{
+ DeviceState *qdev = DEVICE(dev);
+ BusState *qbus = qbus_create(TYPE_VIRTIO_PCI_BUS, qdev, NULL);
+ VirtioBusState *bus = VIRTIO_BUS(qbus);
+ qbus->allow_hotplug = 0;
+ /* Only one virtio-device allowed for virtio-pci. */
+ qbus->max_dev = 1;
+ return bus;
+}
+
+static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
+{
+ VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
+ k->notify = virtio_pci_notify;
+ k->save_config = virtio_pci_save_config;
+ k->load_config = virtio_pci_load_config;
+ k->save_queue = virtio_pci_save_queue;
+ k->load_queue = virtio_pci_load_queue;
+ k->get_features = virtio_pci_get_features;
+ k->query_guest_notifiers = virtio_pci_query_guest_notifiers;
+ k->set_host_notifier = virtio_pci_set_host_notifier;
+ k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
+ k->vmstate_change = virtio_pci_vmstate_change;
+}
+
+static const TypeInfo virtio_pci_bus_info = {
+ .name = TYPE_VIRTIO_PCI_BUS,
+ .parent = TYPE_VIRTIO_BUS,
+ .instance_size = sizeof(VirtioBusState),
+ .class_init = virtio_pci_bus_class_init,
+};
+
static void virtio_pci_register_types(void)
{
type_register_static(&virtio_blk_info);
@@ -1125,6 +1161,7 @@ static void virtio_pci_register_types(void)
type_register_static(&virtio_balloon_info);
type_register_static(&virtio_scsi_info);
type_register_static(&virtio_rng_info);
+ type_register_static(&virtio_pci_bus_info);
}
type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index b58d9a2..0e3288e 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -20,6 +20,21 @@
#include "virtio-rng.h"
#include "virtio-serial.h"
#include "virtio-scsi.h"
+#include "virtio-bus.h"
+
+/* VirtIOPCIProxy will be renammed VirtioPCIState at the end. */
+typedef struct VirtIOPCIProxy VirtIOPCIProxy;
+
+/* virtio-pci-bus */
+#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
+#define VIRTIO_PCI_BUS_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_PCI_BUS)
+#define VIRTIO_PCI_BUS_CLASS(klass) \
+ OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_PCI_BUS)
+#define VIRTIO_PCI_BUS(obj) \
+ OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_PCI_BUS)
+
+VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev);
/* Performance improves when virtqueue kick processing is decoupled from the
* vcpu thread using ioeventfd for some devices. */
@@ -31,7 +46,7 @@ typedef struct {
unsigned int users;
} VirtIOIRQFD;
-typedef struct {
+struct VirtIOPCIProxy {
PCIDevice pci_dev;
VirtIODevice *vdev;
MemoryRegion bar;
@@ -51,7 +66,7 @@ typedef struct {
bool ioeventfd_disabled;
bool ioeventfd_started;
VirtIOIRQFD *vector_irqfd;
-} VirtIOPCIProxy;
+};
void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
void virtio_pci_reset(DeviceState *d);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 03/15] virtio-pci-bus : Introduce virtio-pci-bus.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 03/15] virtio-pci-bus : Introduce virtio-pci-bus fred.konrad
@ 2013-01-02 14:12 ` Anthony Liguori
0 siblings, 0 replies; 35+ messages in thread
From: Anthony Liguori @ 2013-01-02 14:12 UTC (permalink / raw)
To: fred.konrad, qemu-devel
Cc: peter.maydell, e.voevodin, mark.burton, agraf, stefanha,
cornelia.huck, afaerber
fred.konrad@greensocs.com writes:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Introduce virtio-pci-bus, which extends virtio-bus. It is used with virtio-pci
> transport device.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Regards,
Anthony Liguori
> ---
> hw/virtio-pci.c | 37 +++++++++++++++++++++++++++++++++++++
> hw/virtio-pci.h | 19 +++++++++++++++++--
> 2 files changed, 54 insertions(+), 2 deletions(-)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 7684ac9..859a1ed 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -32,6 +32,7 @@
> #include "blockdev.h"
> #include "virtio-pci.h"
> #include "range.h"
> +#include "virtio-bus.h"
>
> /* from Linux's linux/virtio_pci.h */
>
> @@ -1117,6 +1118,41 @@ static TypeInfo virtio_scsi_info = {
> .class_init = virtio_scsi_class_init,
> };
>
> +/* virtio-pci-bus */
> +
> +VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
> +{
> + DeviceState *qdev = DEVICE(dev);
> + BusState *qbus = qbus_create(TYPE_VIRTIO_PCI_BUS, qdev, NULL);
> + VirtioBusState *bus = VIRTIO_BUS(qbus);
> + qbus->allow_hotplug = 0;
> + /* Only one virtio-device allowed for virtio-pci. */
> + qbus->max_dev = 1;
> + return bus;
> +}
> +
> +static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
> +{
> + VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
> + k->notify = virtio_pci_notify;
> + k->save_config = virtio_pci_save_config;
> + k->load_config = virtio_pci_load_config;
> + k->save_queue = virtio_pci_save_queue;
> + k->load_queue = virtio_pci_load_queue;
> + k->get_features = virtio_pci_get_features;
> + k->query_guest_notifiers = virtio_pci_query_guest_notifiers;
> + k->set_host_notifier = virtio_pci_set_host_notifier;
> + k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
> + k->vmstate_change = virtio_pci_vmstate_change;
> +}
> +
> +static const TypeInfo virtio_pci_bus_info = {
> + .name = TYPE_VIRTIO_PCI_BUS,
> + .parent = TYPE_VIRTIO_BUS,
> + .instance_size = sizeof(VirtioBusState),
> + .class_init = virtio_pci_bus_class_init,
> +};
> +
> static void virtio_pci_register_types(void)
> {
> type_register_static(&virtio_blk_info);
> @@ -1125,6 +1161,7 @@ static void virtio_pci_register_types(void)
> type_register_static(&virtio_balloon_info);
> type_register_static(&virtio_scsi_info);
> type_register_static(&virtio_rng_info);
> + type_register_static(&virtio_pci_bus_info);
> }
>
> type_init(virtio_pci_register_types)
> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
> index b58d9a2..0e3288e 100644
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -20,6 +20,21 @@
> #include "virtio-rng.h"
> #include "virtio-serial.h"
> #include "virtio-scsi.h"
> +#include "virtio-bus.h"
> +
> +/* VirtIOPCIProxy will be renammed VirtioPCIState at the end. */
> +typedef struct VirtIOPCIProxy VirtIOPCIProxy;
> +
> +/* virtio-pci-bus */
> +#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
> +#define VIRTIO_PCI_BUS_GET_CLASS(obj) \
> + OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_PCI_BUS)
> +#define VIRTIO_PCI_BUS_CLASS(klass) \
> + OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_PCI_BUS)
> +#define VIRTIO_PCI_BUS(obj) \
> + OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_PCI_BUS)
> +
> +VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev);
>
> /* Performance improves when virtqueue kick processing is decoupled from the
> * vcpu thread using ioeventfd for some devices. */
> @@ -31,7 +46,7 @@ typedef struct {
> unsigned int users;
> } VirtIOIRQFD;
>
> -typedef struct {
> +struct VirtIOPCIProxy {
> PCIDevice pci_dev;
> VirtIODevice *vdev;
> MemoryRegion bar;
> @@ -51,7 +66,7 @@ typedef struct {
> bool ioeventfd_disabled;
> bool ioeventfd_started;
> VirtIOIRQFD *vector_irqfd;
> -} VirtIOPCIProxy;
> +};
>
> void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
> void virtio_pci_reset(DeviceState *d);
> --
> 1.7.11.7
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (2 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 03/15] virtio-pci-bus : Introduce virtio-pci-bus fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2012-12-19 19:53 ` Blue Swirl
2013-01-02 14:14 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 05/15] virtio-device : Refactor virtio-device fred.konrad
` (10 subsequent siblings)
14 siblings, 2 replies; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Create the virtio-pci device. This transport device will create a
virtio-pci-bus, so one VirtIODevice can be connected.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-pci.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hw/virtio-pci.h | 19 +++++++++
2 files changed, 149 insertions(+)
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 859a1ed..916ed7c 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1118,6 +1118,133 @@ static TypeInfo virtio_scsi_info = {
.class_init = virtio_scsi_class_init,
};
+/*
+ * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
+ */
+
+/* This is called by virtio-bus just after the device is plugged. */
+static void virtio_pci_device_plugged(void *opaque)
+{
+ VirtIOPCIProxy *proxy = VIRTIO_PCI(opaque);
+ VirtioBusState *bus = proxy->bus;
+ uint8_t *config;
+ uint32_t size;
+
+ /* Put the PCI IDs */
+ switch (get_virtio_device_id(proxy->bus)) {
+
+
+ default:
+ error_report("unknown device id\n");
+ break;
+
+ }
+
+ /*
+ * vdev shouldn't be accessed directly by virtio-pci.
+ * We will remove that at the end of the series to keep virtio-x-pci
+ * working.
+ */
+ proxy->vdev = proxy->bus->vdev;
+ /*
+ */
+
+ config = proxy->pci_dev.config;
+ if (proxy->class_code) {
+ pci_config_set_class(config, proxy->class_code);
+ }
+ pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
+ pci_get_word(config + PCI_VENDOR_ID));
+ pci_set_word(config + PCI_SUBSYSTEM_ID, get_virtio_device_id(proxy->bus));
+ config[PCI_INTERRUPT_PIN] = 1;
+
+ if (get_virtio_device_nvectors(bus) &&
+ msix_init_exclusive_bar(&proxy->pci_dev,
+ get_virtio_device_nvectors(bus), 1)) {
+ set_virtio_device_nvectors(bus, 0);
+ }
+
+ proxy->pci_dev.config_write = virtio_write_config;
+
+ size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev)
+ + get_virtio_device_config_len(bus);
+ if (size & (size-1)) {
+ size = 1 << qemu_fls(size);
+ }
+
+ memory_region_init_io(&proxy->bar, &virtio_pci_config_ops, proxy,
+ "virtio-pci", size);
+ pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
+ &proxy->bar);
+
+ if (!kvm_has_many_ioeventfds()) {
+ proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
+ }
+
+ proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
+ proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
+ proxy->host_features = get_virtio_device_features(bus,
+ proxy->host_features);
+}
+
+/* This is called by virtio-bus just before the device is unplugged. */
+static void virtio_pci_device_unplug(void *opaque)
+{
+ VirtIOPCIProxy *dev = VIRTIO_PCI(opaque);
+ virtio_pci_stop_ioeventfd(dev);
+}
+
+static int virtio_pci_init(PCIDevice *pci_dev)
+{
+ VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
+ VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev);
+ dev->bus = virtio_pci_bus_new(dev);
+ if (k->init != NULL) {
+ return k->init(dev);
+ }
+ return 0;
+}
+
+static void virtio_pci_exit(PCIDevice *pci_dev)
+{
+ VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
+ VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
+ BusState *qbus = BUS(proxy->bus);
+ virtio_bus_destroy_device(bus);
+ qbus_free(qbus);
+}
+
+static void virtio_pci_rst(DeviceState *qdev)
+{
+ VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
+ VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
+ virtio_pci_stop_ioeventfd(proxy);
+ virtio_bus_reset(bus);
+ msix_unuse_all_vectors(&proxy->pci_dev);
+ proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
+}
+
+static void virtio_pci_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
+
+ k->init = virtio_pci_init;
+ k->exit = virtio_pci_exit;
+ k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
+ k->revision = VIRTIO_PCI_ABI_VERSION;
+ k->class_id = PCI_CLASS_OTHERS;
+ dc->reset = virtio_pci_rst;
+}
+
+static const TypeInfo virtio_pci_info = {
+ .name = TYPE_VIRTIO_PCI,
+ .parent = TYPE_PCI_DEVICE,
+ .instance_size = sizeof(VirtIOPCIProxy),
+ .class_init = virtio_pci_class_init,
+ .class_size = sizeof(VirtioPCIClass),
+};
+
/* virtio-pci-bus */
VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1144,6 +1271,8 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
k->set_host_notifier = virtio_pci_set_host_notifier;
k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
k->vmstate_change = virtio_pci_vmstate_change;
+ k->device_plugged = virtio_pci_device_plugged;
+ k->device_unplug = virtio_pci_device_unplug;
}
static const TypeInfo virtio_pci_bus_info = {
@@ -1162,6 +1291,7 @@ static void virtio_pci_register_types(void)
type_register_static(&virtio_scsi_info);
type_register_static(&virtio_rng_info);
type_register_static(&virtio_pci_bus_info);
+ type_register_static(&virtio_pci_info);
}
type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index 0e3288e..e840cea 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -46,6 +46,22 @@ typedef struct {
unsigned int users;
} VirtIOIRQFD;
+/*
+ * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
+ */
+#define TYPE_VIRTIO_PCI "virtio-pci"
+#define VIRTIO_PCI_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
+#define VIRTIO_PCI_CLASS(klass) \
+ OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
+#define VIRTIO_PCI(obj) \
+ OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
+
+typedef struct VirtioPCIClass {
+ PCIDeviceClass parent_class;
+ int (*init)(VirtIOPCIProxy *vpci_dev);
+} VirtioPCIClass;
+
struct VirtIOPCIProxy {
PCIDevice pci_dev;
VirtIODevice *vdev;
@@ -66,6 +82,9 @@ struct VirtIOPCIProxy {
bool ioeventfd_disabled;
bool ioeventfd_started;
VirtIOIRQFD *vector_irqfd;
+ /* That's the virtio-bus on which VirtioDevice will be connected. */
+ VirtioBusState *bus;
+ /* Nothing more for the moment. */
};
void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device fred.konrad
@ 2012-12-19 19:53 ` Blue Swirl
2013-01-02 14:14 ` Anthony Liguori
1 sibling, 0 replies; 35+ messages in thread
From: Blue Swirl @ 2012-12-19 19:53 UTC (permalink / raw)
To: fred.konrad
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, qemu-devel,
agraf, stefanha, cornelia.huck, afaerber
On Wed, Dec 19, 2012 at 9:53 AM, <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Create the virtio-pci device. This transport device will create a
> virtio-pci-bus, so one VirtIODevice can be connected.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/virtio-pci.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/virtio-pci.h | 19 +++++++++
> 2 files changed, 149 insertions(+)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 859a1ed..916ed7c 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -1118,6 +1118,133 @@ static TypeInfo virtio_scsi_info = {
> .class_init = virtio_scsi_class_init,
> };
>
> +/*
> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
> + */
> +
> +/* This is called by virtio-bus just after the device is plugged. */
> +static void virtio_pci_device_plugged(void *opaque)
> +{
> + VirtIOPCIProxy *proxy = VIRTIO_PCI(opaque);
> + VirtioBusState *bus = proxy->bus;
> + uint8_t *config;
> + uint32_t size;
> +
> + /* Put the PCI IDs */
> + switch (get_virtio_device_id(proxy->bus)) {
> +
> +
Please delete this second empty line.
> + default:
> + error_report("unknown device id\n");
> + break;
Indentation of 'break' should match other code, not switch labels.
> +
> + }
> +
> + /*
> + * vdev shouldn't be accessed directly by virtio-pci.
> + * We will remove that at the end of the series to keep virtio-x-pci
> + * working.
> + */
> + proxy->vdev = proxy->bus->vdev;
> + /*
> + */
> +
> + config = proxy->pci_dev.config;
> + if (proxy->class_code) {
> + pci_config_set_class(config, proxy->class_code);
> + }
> + pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
> + pci_get_word(config + PCI_VENDOR_ID));
> + pci_set_word(config + PCI_SUBSYSTEM_ID, get_virtio_device_id(proxy->bus));
> + config[PCI_INTERRUPT_PIN] = 1;
> +
> + if (get_virtio_device_nvectors(bus) &&
> + msix_init_exclusive_bar(&proxy->pci_dev,
> + get_virtio_device_nvectors(bus), 1)) {
> + set_virtio_device_nvectors(bus, 0);
> + }
> +
> + proxy->pci_dev.config_write = virtio_write_config;
> +
> + size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev)
> + + get_virtio_device_config_len(bus);
> + if (size & (size-1)) {
Spaces around '-', please.
> + size = 1 << qemu_fls(size);
> + }
> +
> + memory_region_init_io(&proxy->bar, &virtio_pci_config_ops, proxy,
> + "virtio-pci", size);
> + pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
> + &proxy->bar);
> +
> + if (!kvm_has_many_ioeventfds()) {
> + proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
> + }
> +
> + proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
> + proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
> + proxy->host_features = get_virtio_device_features(bus,
> + proxy->host_features);
> +}
> +
> +/* This is called by virtio-bus just before the device is unplugged. */
> +static void virtio_pci_device_unplug(void *opaque)
> +{
> + VirtIOPCIProxy *dev = VIRTIO_PCI(opaque);
> + virtio_pci_stop_ioeventfd(dev);
> +}
> +
> +static int virtio_pci_init(PCIDevice *pci_dev)
> +{
> + VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
> + VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev);
> + dev->bus = virtio_pci_bus_new(dev);
> + if (k->init != NULL) {
> + return k->init(dev);
> + }
> + return 0;
> +}
> +
> +static void virtio_pci_exit(PCIDevice *pci_dev)
> +{
> + VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
> + VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
> + BusState *qbus = BUS(proxy->bus);
> + virtio_bus_destroy_device(bus);
> + qbus_free(qbus);
> +}
> +
> +static void virtio_pci_rst(DeviceState *qdev)
> +{
> + VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
> + VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
> + virtio_pci_stop_ioeventfd(proxy);
> + virtio_bus_reset(bus);
> + msix_unuse_all_vectors(&proxy->pci_dev);
> + proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
> +}
> +
> +static void virtio_pci_class_init(ObjectClass *klass, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
> +
> + k->init = virtio_pci_init;
> + k->exit = virtio_pci_exit;
> + k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
> + k->revision = VIRTIO_PCI_ABI_VERSION;
> + k->class_id = PCI_CLASS_OTHERS;
> + dc->reset = virtio_pci_rst;
> +}
> +
> +static const TypeInfo virtio_pci_info = {
> + .name = TYPE_VIRTIO_PCI,
> + .parent = TYPE_PCI_DEVICE,
> + .instance_size = sizeof(VirtIOPCIProxy),
> + .class_init = virtio_pci_class_init,
> + .class_size = sizeof(VirtioPCIClass),
> +};
> +
> /* virtio-pci-bus */
>
> VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
> @@ -1144,6 +1271,8 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
> k->set_host_notifier = virtio_pci_set_host_notifier;
> k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
> k->vmstate_change = virtio_pci_vmstate_change;
> + k->device_plugged = virtio_pci_device_plugged;
> + k->device_unplug = virtio_pci_device_unplug;
> }
>
> static const TypeInfo virtio_pci_bus_info = {
> @@ -1162,6 +1291,7 @@ static void virtio_pci_register_types(void)
> type_register_static(&virtio_scsi_info);
> type_register_static(&virtio_rng_info);
> type_register_static(&virtio_pci_bus_info);
> + type_register_static(&virtio_pci_info);
> }
>
> type_init(virtio_pci_register_types)
> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
> index 0e3288e..e840cea 100644
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -46,6 +46,22 @@ typedef struct {
> unsigned int users;
> } VirtIOIRQFD;
>
> +/*
> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
> + */
> +#define TYPE_VIRTIO_PCI "virtio-pci"
> +#define VIRTIO_PCI_GET_CLASS(obj) \
> + OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
> +#define VIRTIO_PCI_CLASS(klass) \
> + OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
> +#define VIRTIO_PCI(obj) \
> + OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
> +
> +typedef struct VirtioPCIClass {
> + PCIDeviceClass parent_class;
> + int (*init)(VirtIOPCIProxy *vpci_dev);
> +} VirtioPCIClass;
> +
> struct VirtIOPCIProxy {
> PCIDevice pci_dev;
> VirtIODevice *vdev;
> @@ -66,6 +82,9 @@ struct VirtIOPCIProxy {
> bool ioeventfd_disabled;
> bool ioeventfd_started;
> VirtIOIRQFD *vector_irqfd;
> + /* That's the virtio-bus on which VirtioDevice will be connected. */
> + VirtioBusState *bus;
> + /* Nothing more for the moment. */
> };
>
> void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
> --
> 1.7.11.7
>
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device fred.konrad
2012-12-19 19:53 ` Blue Swirl
@ 2013-01-02 14:14 ` Anthony Liguori
2013-01-02 14:17 ` KONRAD Frédéric
1 sibling, 1 reply; 35+ messages in thread
From: Anthony Liguori @ 2013-01-02 14:14 UTC (permalink / raw)
To: fred.konrad, qemu-devel
Cc: peter.maydell, e.voevodin, mark.burton, agraf, stefanha,
cornelia.huck, afaerber
fred.konrad@greensocs.com writes:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Create the virtio-pci device. This transport device will create a
> virtio-pci-bus, so one VirtIODevice can be connected.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/virtio-pci.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/virtio-pci.h | 19 +++++++++
> 2 files changed, 149 insertions(+)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 859a1ed..916ed7c 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -1118,6 +1118,133 @@ static TypeInfo virtio_scsi_info = {
> .class_init = virtio_scsi_class_init,
> };
>
> +/*
> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
> + */
> +
> +/* This is called by virtio-bus just after the device is plugged. */
> +static void virtio_pci_device_plugged(void *opaque)
> +{
> + VirtIOPCIProxy *proxy = VIRTIO_PCI(opaque);
> + VirtioBusState *bus = proxy->bus;
> + uint8_t *config;
> + uint32_t size;
> +
> + /* Put the PCI IDs */
> + switch (get_virtio_device_id(proxy->bus)) {
> +
> +
> + default:
> + error_report("unknown device id\n");
> + break;
> +
> + }
> +
> + /*
> + * vdev shouldn't be accessed directly by virtio-pci.
> + * We will remove that at the end of the series to keep virtio-x-pci
> + * working.
> + */
> + proxy->vdev = proxy->bus->vdev;
> + /*
> + */
> +
> + config = proxy->pci_dev.config;
> + if (proxy->class_code) {
> + pci_config_set_class(config, proxy->class_code);
> + }
> + pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
> + pci_get_word(config + PCI_VENDOR_ID));
> + pci_set_word(config + PCI_SUBSYSTEM_ID, get_virtio_device_id(proxy->bus));
> + config[PCI_INTERRUPT_PIN] = 1;
> +
> + if (get_virtio_device_nvectors(bus) &&
> + msix_init_exclusive_bar(&proxy->pci_dev,
> + get_virtio_device_nvectors(bus), 1)) {
> + set_virtio_device_nvectors(bus, 0);
> + }
> +
> + proxy->pci_dev.config_write = virtio_write_config;
> +
> + size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev)
> + + get_virtio_device_config_len(bus);
> + if (size & (size-1)) {
> + size = 1 << qemu_fls(size);
> + }
> +
> + memory_region_init_io(&proxy->bar, &virtio_pci_config_ops, proxy,
> + "virtio-pci", size);
> + pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
> + &proxy->bar);
> +
> + if (!kvm_has_many_ioeventfds()) {
> + proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
> + }
> +
> + proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
> + proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
> + proxy->host_features = get_virtio_device_features(bus,
> + proxy->host_features);
> +}
> +
> +/* This is called by virtio-bus just before the device is unplugged. */
> +static void virtio_pci_device_unplug(void *opaque)
> +{
> + VirtIOPCIProxy *dev = VIRTIO_PCI(opaque);
> + virtio_pci_stop_ioeventfd(dev);
> +}
> +
> +static int virtio_pci_init(PCIDevice *pci_dev)
> +{
> + VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
> + VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev);
> + dev->bus = virtio_pci_bus_new(dev);
> + if (k->init != NULL) {
> + return k->init(dev);
> + }
> + return 0;
> +}
> +
> +static void virtio_pci_exit(PCIDevice *pci_dev)
> +{
> + VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
> + VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
> + BusState *qbus = BUS(proxy->bus);
> + virtio_bus_destroy_device(bus);
> + qbus_free(qbus);
> +}
> +
> +static void virtio_pci_rst(DeviceState *qdev)
s/rst/reset/
Regards,
Anthony Liguori
> +{
> + VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
> + VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
> + virtio_pci_stop_ioeventfd(proxy);
> + virtio_bus_reset(bus);
> + msix_unuse_all_vectors(&proxy->pci_dev);
> + proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
> +}
> +
> +static void virtio_pci_class_init(ObjectClass *klass, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
> +
> + k->init = virtio_pci_init;
> + k->exit = virtio_pci_exit;
> + k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
> + k->revision = VIRTIO_PCI_ABI_VERSION;
> + k->class_id = PCI_CLASS_OTHERS;
> + dc->reset = virtio_pci_rst;
> +}
> +
> +static const TypeInfo virtio_pci_info = {
> + .name = TYPE_VIRTIO_PCI,
> + .parent = TYPE_PCI_DEVICE,
> + .instance_size = sizeof(VirtIOPCIProxy),
> + .class_init = virtio_pci_class_init,
> + .class_size = sizeof(VirtioPCIClass),
> +};
> +
> /* virtio-pci-bus */
>
> VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
> @@ -1144,6 +1271,8 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
> k->set_host_notifier = virtio_pci_set_host_notifier;
> k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
> k->vmstate_change = virtio_pci_vmstate_change;
> + k->device_plugged = virtio_pci_device_plugged;
> + k->device_unplug = virtio_pci_device_unplug;
> }
>
> static const TypeInfo virtio_pci_bus_info = {
> @@ -1162,6 +1291,7 @@ static void virtio_pci_register_types(void)
> type_register_static(&virtio_scsi_info);
> type_register_static(&virtio_rng_info);
> type_register_static(&virtio_pci_bus_info);
> + type_register_static(&virtio_pci_info);
> }
>
> type_init(virtio_pci_register_types)
> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
> index 0e3288e..e840cea 100644
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -46,6 +46,22 @@ typedef struct {
> unsigned int users;
> } VirtIOIRQFD;
>
> +/*
> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
> + */
> +#define TYPE_VIRTIO_PCI "virtio-pci"
> +#define VIRTIO_PCI_GET_CLASS(obj) \
> + OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
> +#define VIRTIO_PCI_CLASS(klass) \
> + OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
> +#define VIRTIO_PCI(obj) \
> + OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
> +
> +typedef struct VirtioPCIClass {
> + PCIDeviceClass parent_class;
> + int (*init)(VirtIOPCIProxy *vpci_dev);
> +} VirtioPCIClass;
> +
> struct VirtIOPCIProxy {
> PCIDevice pci_dev;
> VirtIODevice *vdev;
> @@ -66,6 +82,9 @@ struct VirtIOPCIProxy {
> bool ioeventfd_disabled;
> bool ioeventfd_started;
> VirtIOIRQFD *vector_irqfd;
> + /* That's the virtio-bus on which VirtioDevice will be connected. */
> + VirtioBusState *bus;
> + /* Nothing more for the moment. */
> };
>
> void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
> --
> 1.7.11.7
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device.
2013-01-02 14:14 ` Anthony Liguori
@ 2013-01-02 14:17 ` KONRAD Frédéric
0 siblings, 0 replies; 35+ messages in thread
From: KONRAD Frédéric @ 2013-01-02 14:17 UTC (permalink / raw)
To: Anthony Liguori
Cc: peter.maydell, e.voevodin, mark.burton, qemu-devel, agraf,
stefanha, cornelia.huck, afaerber
On 02/01/2013 15:14, Anthony Liguori wrote:
> fred.konrad@greensocs.com writes:
>
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> Create the virtio-pci device. This transport device will create a
>> virtio-pci-bus, so one VirtIODevice can be connected.
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> ---
>> hw/virtio-pci.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> hw/virtio-pci.h | 19 +++++++++
>> 2 files changed, 149 insertions(+)
>>
>> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
>> index 859a1ed..916ed7c 100644
>> --- a/hw/virtio-pci.c
>> +++ b/hw/virtio-pci.c
>> @@ -1118,6 +1118,133 @@ static TypeInfo virtio_scsi_info = {
>> .class_init = virtio_scsi_class_init,
>> };
>>
>> +/*
>> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
>> + */
>> +
>> +/* This is called by virtio-bus just after the device is plugged. */
>> +static void virtio_pci_device_plugged(void *opaque)
>> +{
>> + VirtIOPCIProxy *proxy = VIRTIO_PCI(opaque);
>> + VirtioBusState *bus = proxy->bus;
>> + uint8_t *config;
>> + uint32_t size;
>> +
>> + /* Put the PCI IDs */
>> + switch (get_virtio_device_id(proxy->bus)) {
>> +
>> +
>> + default:
>> + error_report("unknown device id\n");
>> + break;
>> +
>> + }
>> +
>> + /*
>> + * vdev shouldn't be accessed directly by virtio-pci.
>> + * We will remove that at the end of the series to keep virtio-x-pci
>> + * working.
>> + */
>> + proxy->vdev = proxy->bus->vdev;
>> + /*
>> + */
>> +
>> + config = proxy->pci_dev.config;
>> + if (proxy->class_code) {
>> + pci_config_set_class(config, proxy->class_code);
>> + }
>> + pci_set_word(config + PCI_SUBSYSTEM_VENDOR_ID,
>> + pci_get_word(config + PCI_VENDOR_ID));
>> + pci_set_word(config + PCI_SUBSYSTEM_ID, get_virtio_device_id(proxy->bus));
>> + config[PCI_INTERRUPT_PIN] = 1;
>> +
>> + if (get_virtio_device_nvectors(bus) &&
>> + msix_init_exclusive_bar(&proxy->pci_dev,
>> + get_virtio_device_nvectors(bus), 1)) {
>> + set_virtio_device_nvectors(bus, 0);
>> + }
>> +
>> + proxy->pci_dev.config_write = virtio_write_config;
>> +
>> + size = VIRTIO_PCI_REGION_SIZE(&proxy->pci_dev)
>> + + get_virtio_device_config_len(bus);
>> + if (size & (size-1)) {
>> + size = 1 << qemu_fls(size);
>> + }
>> +
>> + memory_region_init_io(&proxy->bar, &virtio_pci_config_ops, proxy,
>> + "virtio-pci", size);
>> + pci_register_bar(&proxy->pci_dev, 0, PCI_BASE_ADDRESS_SPACE_IO,
>> + &proxy->bar);
>> +
>> + if (!kvm_has_many_ioeventfds()) {
>> + proxy->flags &= ~VIRTIO_PCI_FLAG_USE_IOEVENTFD;
>> + }
>> +
>> + proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY;
>> + proxy->host_features |= 0x1 << VIRTIO_F_BAD_FEATURE;
>> + proxy->host_features = get_virtio_device_features(bus,
>> + proxy->host_features);
>> +}
>> +
>> +/* This is called by virtio-bus just before the device is unplugged. */
>> +static void virtio_pci_device_unplug(void *opaque)
>> +{
>> + VirtIOPCIProxy *dev = VIRTIO_PCI(opaque);
>> + virtio_pci_stop_ioeventfd(dev);
>> +}
>> +
>> +static int virtio_pci_init(PCIDevice *pci_dev)
>> +{
>> + VirtIOPCIProxy *dev = VIRTIO_PCI(pci_dev);
>> + VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev);
>> + dev->bus = virtio_pci_bus_new(dev);
>> + if (k->init != NULL) {
>> + return k->init(dev);
>> + }
>> + return 0;
>> +}
>> +
>> +static void virtio_pci_exit(PCIDevice *pci_dev)
>> +{
>> + VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev);
>> + VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
>> + BusState *qbus = BUS(proxy->bus);
>> + virtio_bus_destroy_device(bus);
>> + qbus_free(qbus);
>> +}
>> +
>> +static void virtio_pci_rst(DeviceState *qdev)
> s/rst/reset/
>
> Regards,
>
> Anthony Liguori
virtio_pci_reset conflicts with another function.
Can I add a step to renamed it at the end when virtio_pci_reset is unused ?
>
>> +{
>> + VirtIOPCIProxy *proxy = VIRTIO_PCI(qdev);
>> + VirtioBusState *bus = VIRTIO_BUS(proxy->bus);
>> + virtio_pci_stop_ioeventfd(proxy);
>> + virtio_bus_reset(bus);
>> + msix_unuse_all_vectors(&proxy->pci_dev);
>> + proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG;
>> +}
>> +
>> +static void virtio_pci_class_init(ObjectClass *klass, void *data)
>> +{
>> + DeviceClass *dc = DEVICE_CLASS(klass);
>> + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
>> +
>> + k->init = virtio_pci_init;
>> + k->exit = virtio_pci_exit;
>> + k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
>> + k->revision = VIRTIO_PCI_ABI_VERSION;
>> + k->class_id = PCI_CLASS_OTHERS;
>> + dc->reset = virtio_pci_rst;
>> +}
>> +
>> +static const TypeInfo virtio_pci_info = {
>> + .name = TYPE_VIRTIO_PCI,
>> + .parent = TYPE_PCI_DEVICE,
>> + .instance_size = sizeof(VirtIOPCIProxy),
>> + .class_init = virtio_pci_class_init,
>> + .class_size = sizeof(VirtioPCIClass),
>> +};
>> +
>> /* virtio-pci-bus */
>>
>> VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
>> @@ -1144,6 +1271,8 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
>> k->set_host_notifier = virtio_pci_set_host_notifier;
>> k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
>> k->vmstate_change = virtio_pci_vmstate_change;
>> + k->device_plugged = virtio_pci_device_plugged;
>> + k->device_unplug = virtio_pci_device_unplug;
>> }
>>
>> static const TypeInfo virtio_pci_bus_info = {
>> @@ -1162,6 +1291,7 @@ static void virtio_pci_register_types(void)
>> type_register_static(&virtio_scsi_info);
>> type_register_static(&virtio_rng_info);
>> type_register_static(&virtio_pci_bus_info);
>> + type_register_static(&virtio_pci_info);
>> }
>>
>> type_init(virtio_pci_register_types)
>> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
>> index 0e3288e..e840cea 100644
>> --- a/hw/virtio-pci.h
>> +++ b/hw/virtio-pci.h
>> @@ -46,6 +46,22 @@ typedef struct {
>> unsigned int users;
>> } VirtIOIRQFD;
>>
>> +/*
>> + * virtio-pci : This is the PCIDevice which have a virtio-pci-bus.
>> + */
>> +#define TYPE_VIRTIO_PCI "virtio-pci"
>> +#define VIRTIO_PCI_GET_CLASS(obj) \
>> + OBJECT_GET_CLASS(VirtioPCIClass, obj, TYPE_VIRTIO_PCI)
>> +#define VIRTIO_PCI_CLASS(klass) \
>> + OBJECT_CLASS_CHECK(VirtioPCIClass, klass, TYPE_VIRTIO_PCI)
>> +#define VIRTIO_PCI(obj) \
>> + OBJECT_CHECK(VirtIOPCIProxy, (obj), TYPE_VIRTIO_PCI)
>> +
>> +typedef struct VirtioPCIClass {
>> + PCIDeviceClass parent_class;
>> + int (*init)(VirtIOPCIProxy *vpci_dev);
>> +} VirtioPCIClass;
>> +
>> struct VirtIOPCIProxy {
>> PCIDevice pci_dev;
>> VirtIODevice *vdev;
>> @@ -66,6 +82,9 @@ struct VirtIOPCIProxy {
>> bool ioeventfd_disabled;
>> bool ioeventfd_started;
>> VirtIOIRQFD *vector_irqfd;
>> + /* That's the virtio-bus on which VirtioDevice will be connected. */
>> + VirtioBusState *bus;
>> + /* Nothing more for the moment. */
>> }; c
>>
>> void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
>> --
>> 1.7.11.7
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 05/15] virtio-device : Refactor virtio-device.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (3 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 04/15] virtio-pci : Refactor virtio-pci device fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2013-01-02 14:15 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 06/15] virtio-s390-bus : Add virtio-s390-bus fred.konrad
` (9 subsequent siblings)
14 siblings, 1 reply; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Create the virtio-device which is abstract. All the virtio-device can extend
this class.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
hw/virtio.h | 31 +++++++++++++++++++++++++++
2 files changed, 89 insertions(+), 12 deletions(-)
diff --git a/hw/virtio.c b/hw/virtio.c
index f40a8c5..e40fa12 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -16,6 +16,7 @@
#include "trace.h"
#include "qemu-error.h"
#include "virtio.h"
+#include "virtio-bus.h"
#include "qemu-barrier.h"
/* The alignment to use between consumer and producer parts of vring.
@@ -875,11 +876,16 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
return 0;
}
-void virtio_cleanup(VirtIODevice *vdev)
+void virtio_common_cleanup(VirtIODevice *vdev)
{
qemu_del_vm_change_state_handler(vdev->vmstate);
g_free(vdev->config);
g_free(vdev->vq);
+}
+
+void virtio_cleanup(VirtIODevice *vdev)
+{
+ virtio_common_cleanup(vdev);
g_free(vdev);
}
@@ -902,14 +908,10 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
}
}
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
- size_t config_size, size_t struct_size)
+void virtio_init(VirtIODevice *vdev, const char *name,
+ uint16_t device_id, size_t config_size)
{
- VirtIODevice *vdev;
int i;
-
- vdev = g_malloc0(struct_size);
-
vdev->device_id = device_id;
vdev->status = 0;
vdev->isr = 0;
@@ -917,20 +919,28 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
vdev->config_vector = VIRTIO_NO_VECTOR;
vdev->vq = g_malloc0(sizeof(VirtQueue) * VIRTIO_PCI_QUEUE_MAX);
vdev->vm_running = runstate_is_running();
- for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
+ for (i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
vdev->vq[i].vector = VIRTIO_NO_VECTOR;
vdev->vq[i].vdev = vdev;
}
vdev->name = name;
vdev->config_len = config_size;
- if (vdev->config_len)
+ if (vdev->config_len) {
vdev->config = g_malloc0(config_size);
- else
+ } else {
vdev->config = NULL;
+ }
+ vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change,
+ vdev);
+}
- vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change, vdev);
-
+VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
+ size_t config_size, size_t struct_size)
+{
+ VirtIODevice *vdev;
+ vdev = g_malloc0(struct_size);
+ virtio_init(vdev, name, device_id, config_size);
return vdev;
}
@@ -1056,3 +1066,39 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
{
return &vq->host_notifier;
}
+
+static int virtio_device_init(DeviceState *qdev)
+{
+ VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
+ assert(k->init != NULL);
+ if (k->init(vdev) < 0) {
+ return -1;
+ }
+ virtio_bus_plug_device(vdev);
+ return 0;
+}
+
+static void virtio_device_class_init(ObjectClass *klass, void *data)
+{
+ /* Set the default value here. */
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ dc->init = virtio_device_init;
+ dc->bus_type = TYPE_VIRTIO_BUS;
+}
+
+static const TypeInfo virtio_device_info = {
+ .name = TYPE_VIRTIO_DEVICE,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(VirtIODevice),
+ .class_init = virtio_device_class_init,
+ .abstract = true,
+ .class_size = sizeof(VirtioDeviceClass),
+};
+
+static void virtio_register_types(void)
+{
+ type_register_static(&virtio_device_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio.h b/hw/virtio.h
index 7c17f7b..98596a9 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -108,8 +108,17 @@ typedef struct {
#define VIRTIO_NO_VECTOR 0xffff
+#define TYPE_VIRTIO_DEVICE "virtio-device"
+#define VIRTIO_DEVICE_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(VirtioDeviceClass, obj, TYPE_VIRTIO_DEVICE)
+#define VIRTIO_DEVICE_CLASS(klass) \
+ OBJECT_CLASS_CHECK(VirtioDeviceClass, klass, TYPE_VIRTIO_DEVICE)
+#define VIRTIO_DEVICE(obj) \
+ OBJECT_CHECK(VirtIODevice, (obj), TYPE_VIRTIO_DEVICE)
+
struct VirtIODevice
{
+ DeviceState parent_obj;
const char *name;
uint8_t status;
uint8_t isr;
@@ -119,6 +128,10 @@ struct VirtIODevice
void *config;
uint16_t config_vector;
int nvectors;
+ /*
+ * Will be removed ( at the end of the series ) as we have it in
+ * VirtioDeviceClass.
+ */
uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
uint32_t (*bad_features)(VirtIODevice *vdev);
void (*set_features)(VirtIODevice *vdev, uint32_t val);
@@ -126,6 +139,7 @@ struct VirtIODevice
void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
void (*reset)(VirtIODevice *vdev);
void (*set_status)(VirtIODevice *vdev, uint8_t val);
+ /***/
VirtQueue *vq;
const VirtIOBindings *binding;
void *binding_opaque;
@@ -134,6 +148,23 @@ struct VirtIODevice
VMChangeStateEntry *vmstate;
};
+typedef struct {
+ /* This is what a VirtioDevice must implement */
+ DeviceClass parent;
+ int (*init)(VirtIODevice *vdev);
+ uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
+ uint32_t (*bad_features)(VirtIODevice *vdev);
+ void (*set_features)(VirtIODevice *vdev, uint32_t val);
+ void (*get_config)(VirtIODevice *vdev, uint8_t *config);
+ void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
+ void (*reset)(VirtIODevice *vdev);
+ void (*set_status)(VirtIODevice *vdev, uint8_t val);
+} VirtioDeviceClass;
+
+void virtio_init(VirtIODevice *vdev, const char *name,
+ uint16_t device_id, size_t config_size);
+void virtio_common_cleanup(VirtIODevice *vdev);
+
VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
void (*handle_output)(VirtIODevice *,
VirtQueue *));
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 05/15] virtio-device : Refactor virtio-device.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 05/15] virtio-device : Refactor virtio-device fred.konrad
@ 2013-01-02 14:15 ` Anthony Liguori
0 siblings, 0 replies; 35+ messages in thread
From: Anthony Liguori @ 2013-01-02 14:15 UTC (permalink / raw)
To: fred.konrad, qemu-devel
Cc: peter.maydell, e.voevodin, mark.burton, agraf, stefanha,
cornelia.huck, afaerber
fred.konrad@greensocs.com writes:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Create the virtio-device which is abstract. All the virtio-device can extend
> this class.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Regards,
Anthony Liguori
> ---
> hw/virtio.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++-----------
> hw/virtio.h | 31 +++++++++++++++++++++++++++
> 2 files changed, 89 insertions(+), 12 deletions(-)
>
> diff --git a/hw/virtio.c b/hw/virtio.c
> index f40a8c5..e40fa12 100644
> --- a/hw/virtio.c
> +++ b/hw/virtio.c
> @@ -16,6 +16,7 @@
> #include "trace.h"
> #include "qemu-error.h"
> #include "virtio.h"
> +#include "virtio-bus.h"
> #include "qemu-barrier.h"
>
> /* The alignment to use between consumer and producer parts of vring.
> @@ -875,11 +876,16 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
> return 0;
> }
>
> -void virtio_cleanup(VirtIODevice *vdev)
> +void virtio_common_cleanup(VirtIODevice *vdev)
> {
> qemu_del_vm_change_state_handler(vdev->vmstate);
> g_free(vdev->config);
> g_free(vdev->vq);
> +}
> +
> +void virtio_cleanup(VirtIODevice *vdev)
> +{
> + virtio_common_cleanup(vdev);
> g_free(vdev);
> }
>
> @@ -902,14 +908,10 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
> }
> }
>
> -VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
> - size_t config_size, size_t struct_size)
> +void virtio_init(VirtIODevice *vdev, const char *name,
> + uint16_t device_id, size_t config_size)
> {
> - VirtIODevice *vdev;
> int i;
> -
> - vdev = g_malloc0(struct_size);
> -
> vdev->device_id = device_id;
> vdev->status = 0;
> vdev->isr = 0;
> @@ -917,20 +919,28 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
> vdev->config_vector = VIRTIO_NO_VECTOR;
> vdev->vq = g_malloc0(sizeof(VirtQueue) * VIRTIO_PCI_QUEUE_MAX);
> vdev->vm_running = runstate_is_running();
> - for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
> + for (i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) {
> vdev->vq[i].vector = VIRTIO_NO_VECTOR;
> vdev->vq[i].vdev = vdev;
> }
>
> vdev->name = name;
> vdev->config_len = config_size;
> - if (vdev->config_len)
> + if (vdev->config_len) {
> vdev->config = g_malloc0(config_size);
> - else
> + } else {
> vdev->config = NULL;
> + }
> + vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change,
> + vdev);
> +}
>
> - vdev->vmstate = qemu_add_vm_change_state_handler(virtio_vmstate_change, vdev);
> -
> +VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
> + size_t config_size, size_t struct_size)
> +{
> + VirtIODevice *vdev;
> + vdev = g_malloc0(struct_size);
> + virtio_init(vdev, name, device_id, config_size);
> return vdev;
> }
>
> @@ -1056,3 +1066,39 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
> {
> return &vq->host_notifier;
> }
> +
> +static int virtio_device_init(DeviceState *qdev)
> +{
> + VirtIODevice *vdev = VIRTIO_DEVICE(qdev);
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(qdev);
> + assert(k->init != NULL);
> + if (k->init(vdev) < 0) {
> + return -1;
> + }
> + virtio_bus_plug_device(vdev);
> + return 0;
> +}
> +
> +static void virtio_device_class_init(ObjectClass *klass, void *data)
> +{
> + /* Set the default value here. */
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + dc->init = virtio_device_init;
> + dc->bus_type = TYPE_VIRTIO_BUS;
> +}
> +
> +static const TypeInfo virtio_device_info = {
> + .name = TYPE_VIRTIO_DEVICE,
> + .parent = TYPE_DEVICE,
> + .instance_size = sizeof(VirtIODevice),
> + .class_init = virtio_device_class_init,
> + .abstract = true,
> + .class_size = sizeof(VirtioDeviceClass),
> +};
> +
> +static void virtio_register_types(void)
> +{
> + type_register_static(&virtio_device_info);
> +}
> +
> +type_init(virtio_register_types)
> diff --git a/hw/virtio.h b/hw/virtio.h
> index 7c17f7b..98596a9 100644
> --- a/hw/virtio.h
> +++ b/hw/virtio.h
> @@ -108,8 +108,17 @@ typedef struct {
>
> #define VIRTIO_NO_VECTOR 0xffff
>
> +#define TYPE_VIRTIO_DEVICE "virtio-device"
> +#define VIRTIO_DEVICE_GET_CLASS(obj) \
> + OBJECT_GET_CLASS(VirtioDeviceClass, obj, TYPE_VIRTIO_DEVICE)
> +#define VIRTIO_DEVICE_CLASS(klass) \
> + OBJECT_CLASS_CHECK(VirtioDeviceClass, klass, TYPE_VIRTIO_DEVICE)
> +#define VIRTIO_DEVICE(obj) \
> + OBJECT_CHECK(VirtIODevice, (obj), TYPE_VIRTIO_DEVICE)
> +
> struct VirtIODevice
> {
> + DeviceState parent_obj;
> const char *name;
> uint8_t status;
> uint8_t isr;
> @@ -119,6 +128,10 @@ struct VirtIODevice
> void *config;
> uint16_t config_vector;
> int nvectors;
> + /*
> + * Will be removed ( at the end of the series ) as we have it in
> + * VirtioDeviceClass.
> + */
> uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
> uint32_t (*bad_features)(VirtIODevice *vdev);
> void (*set_features)(VirtIODevice *vdev, uint32_t val);
> @@ -126,6 +139,7 @@ struct VirtIODevice
> void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
> void (*reset)(VirtIODevice *vdev);
> void (*set_status)(VirtIODevice *vdev, uint8_t val);
> + /***/
> VirtQueue *vq;
> const VirtIOBindings *binding;
> void *binding_opaque;
> @@ -134,6 +148,23 @@ struct VirtIODevice
> VMChangeStateEntry *vmstate;
> };
>
> +typedef struct {
> + /* This is what a VirtioDevice must implement */
> + DeviceClass parent;
> + int (*init)(VirtIODevice *vdev);
> + uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
> + uint32_t (*bad_features)(VirtIODevice *vdev);
> + void (*set_features)(VirtIODevice *vdev, uint32_t val);
> + void (*get_config)(VirtIODevice *vdev, uint8_t *config);
> + void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
> + void (*reset)(VirtIODevice *vdev);
> + void (*set_status)(VirtIODevice *vdev, uint8_t val);
> +} VirtioDeviceClass;
> +
> +void virtio_init(VirtIODevice *vdev, const char *name,
> + uint16_t device_id, size_t config_size);
> +void virtio_common_cleanup(VirtIODevice *vdev);
> +
> VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
> void (*handle_output)(VirtIODevice *,
> VirtQueue *));
> --
> 1.7.11.7
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 06/15] virtio-s390-bus : Add virtio-s390-bus.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (4 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 05/15] virtio-device : Refactor virtio-device fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2012-12-19 18:09 ` Cornelia Huck
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 07/15] virtio-s390-device : create a virtio-s390-bus during init fred.konrad
` (8 subsequent siblings)
14 siblings, 1 reply; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Introduce virtio-s390-bus, which extends virtio-bus. It is used with s390
transport device.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/s390-virtio-bus.c | 28 ++++++++++++++++++++++++++++
hw/s390-virtio-bus.h | 13 +++++++++++++
2 files changed, 41 insertions(+)
diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index e0ac2d1..720dbb9 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -33,6 +33,7 @@
#include "kvm.h"
#include "hw/s390-virtio-bus.h"
+#include "hw/virtio-bus.h"
/* #define DEBUG_S390 */
@@ -556,8 +557,35 @@ static TypeInfo s390_virtio_bridge_info = {
.class_init = s390_virtio_bridge_class_init,
};
+/* virtio-s390-bus */
+
+VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev)
+{
+ DeviceState *qdev = DEVICE(dev);
+ BusState *qbus = qbus_create(TYPE_VIRTIO_S390_BUS, qdev, NULL);
+ VirtioBusState *bus = VIRTIO_BUS(qbus);
+ qbus->allow_hotplug = 0;
+ qbus->max_dev = 1;
+ return bus;
+}
+
+static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
+{
+ VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
+ k->notify = virtio_s390_notify;
+ k->get_features = virtio_s390_get_features;
+}
+
+static const TypeInfo virtio_s390_bus_info = {
+ .name = TYPE_VIRTIO_S390_BUS,
+ .parent = TYPE_VIRTIO_BUS,
+ .instance_size = sizeof(VirtioBusState),
+ .class_init = virtio_s390_bus_class_init,
+};
+
static void s390_virtio_register_types(void)
{
+ type_register_static(&virtio_s390_bus_info);
type_register_static(&s390_virtio_bus_info);
type_register_static(&virtio_s390_device_info);
type_register_static(&s390_virtio_serial);
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index a83afe7..7c5a945 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -22,6 +22,7 @@
#include "virtio-rng.h"
#include "virtio-serial.h"
#include "virtio-scsi.h"
+#include "virtio-bus.h"
#define VIRTIO_DEV_OFFS_TYPE 0 /* 8 bits */
#define VIRTIO_DEV_OFFS_NUM_VQ 1 /* 8 bits */
@@ -57,8 +58,20 @@
#define S390_VIRTIO_BUS(obj) \
OBJECT_CHECK(VirtIOS390Bus, (obj), TYPE_S390_VIRTIO_BUS)
+/* virtio-s390-bus */
+
+#define TYPE_VIRTIO_S390_BUS "virtio-s390-bus"
+#define VIRTIO_S390_BUS_GET_CLASS(obj) \
+ OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_S390_BUS)
+#define VIRTIO_PCI_BUS_CLASS(klass) \
+ OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_S390_BUS)
+#define VIRTIO_PCI_BUS(obj) \
+ OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_S390_BUS)
+
typedef struct VirtIOS390Device VirtIOS390Device;
+VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev);
+
typedef struct VirtIOS390DeviceClass {
DeviceClass qdev;
int (*init)(VirtIOS390Device *dev);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 06/15] virtio-s390-bus : Add virtio-s390-bus.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 06/15] virtio-s390-bus : Add virtio-s390-bus fred.konrad
@ 2012-12-19 18:09 ` Cornelia Huck
2012-12-20 8:03 ` KONRAD Frédéric
0 siblings, 1 reply; 35+ messages in thread
From: Cornelia Huck @ 2012-12-19 18:09 UTC (permalink / raw)
To: fred.konrad
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, qemu-devel,
agraf, stefanha, afaerber
On Wed, 19 Dec 2012 10:53:32 +0100
fred.konrad@greensocs.com wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Introduce virtio-s390-bus, which extends virtio-bus. It is used with s390
> transport device.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/s390-virtio-bus.c | 28 ++++++++++++++++++++++++++++
> hw/s390-virtio-bus.h | 13 +++++++++++++
> 2 files changed, 41 insertions(+)
>
> diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
> index e0ac2d1..720dbb9 100644
> --- a/hw/s390-virtio-bus.c
> +++ b/hw/s390-virtio-bus.c
> @@ -33,6 +33,7 @@
> #include "kvm.h"
>
> #include "hw/s390-virtio-bus.h"
> +#include "hw/virtio-bus.h"
>
> /* #define DEBUG_S390 */
>
> @@ -556,8 +557,35 @@ static TypeInfo s390_virtio_bridge_info = {
> .class_init = s390_virtio_bridge_class_init,
> };
>
> +/* virtio-s390-bus */
> +
> +VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev)
> +{
> + DeviceState *qdev = DEVICE(dev);
> + BusState *qbus = qbus_create(TYPE_VIRTIO_S390_BUS, qdev, NULL);
> + VirtioBusState *bus = VIRTIO_BUS(qbus);
> + qbus->allow_hotplug = 0;
> + qbus->max_dev = 1;
> + return bus;
> +}
> +
> +static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
> +{
> + VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
> + k->notify = virtio_s390_notify;
> + k->get_features = virtio_s390_get_features;
> +}
> +
> +static const TypeInfo virtio_s390_bus_info = {
> + .name = TYPE_VIRTIO_S390_BUS,
> + .parent = TYPE_VIRTIO_BUS,
> + .instance_size = sizeof(VirtioBusState),
> + .class_init = virtio_s390_bus_class_init,
> +};
> +
> static void s390_virtio_register_types(void)
> {
> + type_register_static(&virtio_s390_bus_info);
> type_register_static(&s390_virtio_bus_info);
> type_register_static(&virtio_s390_device_info);
> type_register_static(&s390_virtio_serial);
> diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
> index a83afe7..7c5a945 100644
> --- a/hw/s390-virtio-bus.h
> +++ b/hw/s390-virtio-bus.h
> @@ -22,6 +22,7 @@
> #include "virtio-rng.h"
> #include "virtio-serial.h"
> #include "virtio-scsi.h"
> +#include "virtio-bus.h"
>
> #define VIRTIO_DEV_OFFS_TYPE 0 /* 8 bits */
> #define VIRTIO_DEV_OFFS_NUM_VQ 1 /* 8 bits */
> @@ -57,8 +58,20 @@
> #define S390_VIRTIO_BUS(obj) \
> OBJECT_CHECK(VirtIOS390Bus, (obj), TYPE_S390_VIRTIO_BUS)
>
> +/* virtio-s390-bus */
> +
> +#define TYPE_VIRTIO_S390_BUS "virtio-s390-bus"
> +#define VIRTIO_S390_BUS_GET_CLASS(obj) \
> + OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_S390_BUS)
> +#define VIRTIO_PCI_BUS_CLASS(klass) \
> + OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_S390_BUS)
> +#define VIRTIO_PCI_BUS(obj) \
> + OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_S390_BUS)
PCI? This looks wrong.
> +
> typedef struct VirtIOS390Device VirtIOS390Device;
>
> +VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev);
> +
> typedef struct VirtIOS390DeviceClass {
> DeviceClass qdev;
> int (*init)(VirtIOS390Device *dev);
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 06/15] virtio-s390-bus : Add virtio-s390-bus.
2012-12-19 18:09 ` Cornelia Huck
@ 2012-12-20 8:03 ` KONRAD Frédéric
0 siblings, 0 replies; 35+ messages in thread
From: KONRAD Frédéric @ 2012-12-20 8:03 UTC (permalink / raw)
To: Cornelia Huck
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, qemu-devel,
agraf, stefanha, afaerber
On 19/12/2012 19:09, Cornelia Huck wrote:
> On Wed, 19 Dec 2012 10:53:32 +0100
> fred.konrad@greensocs.com wrote:
>
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> Introduce virtio-s390-bus, which extends virtio-bus. It is used with s390
>> transport device.
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> ---
>> hw/s390-virtio-bus.c | 28 ++++++++++++++++++++++++++++
>> hw/s390-virtio-bus.h | 13 +++++++++++++
>> 2 files changed, 41 insertions(+)
>>
>> diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
>> index e0ac2d1..720dbb9 100644
>> --- a/hw/s390-virtio-bus.c
>> +++ b/hw/s390-virtio-bus.c
>> @@ -33,6 +33,7 @@
>> #include "kvm.h"
>>
>> #include "hw/s390-virtio-bus.h"
>> +#include "hw/virtio-bus.h"
>>
>> /* #define DEBUG_S390 */
>>
>> @@ -556,8 +557,35 @@ static TypeInfo s390_virtio_bridge_info = {
>> .class_init = s390_virtio_bridge_class_init,
>> };
>>
>> +/* virtio-s390-bus */
>> +
>> +VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev)
>> +{
>> + DeviceState *qdev = DEVICE(dev);
>> + BusState *qbus = qbus_create(TYPE_VIRTIO_S390_BUS, qdev, NULL);
>> + VirtioBusState *bus = VIRTIO_BUS(qbus);
>> + qbus->allow_hotplug = 0;
>> + qbus->max_dev = 1;
>> + return bus;
>> +}
>> +
>> +static void virtio_s390_bus_class_init(ObjectClass *klass, void *data)
>> +{
>> + VirtioBusClass *k = VIRTIO_BUS_CLASS(klass);
>> + k->notify = virtio_s390_notify;
>> + k->get_features = virtio_s390_get_features;
>> +}
>> +
>> +static const TypeInfo virtio_s390_bus_info = {
>> + .name = TYPE_VIRTIO_S390_BUS,
>> + .parent = TYPE_VIRTIO_BUS,
>> + .instance_size = sizeof(VirtioBusState),
>> + .class_init = virtio_s390_bus_class_init,
>> +};
>> +
>> static void s390_virtio_register_types(void)
>> {
>> + type_register_static(&virtio_s390_bus_info);
>> type_register_static(&s390_virtio_bus_info);
>> type_register_static(&virtio_s390_device_info);
>> type_register_static(&s390_virtio_serial);
>> diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
>> index a83afe7..7c5a945 100644
>> --- a/hw/s390-virtio-bus.h
>> +++ b/hw/s390-virtio-bus.h
>> @@ -22,6 +22,7 @@
>> #include "virtio-rng.h"
>> #include "virtio-serial.h"
>> #include "virtio-scsi.h"
>> +#include "virtio-bus.h"
>>
>> #define VIRTIO_DEV_OFFS_TYPE 0 /* 8 bits */
>> #define VIRTIO_DEV_OFFS_NUM_VQ 1 /* 8 bits */
>> @@ -57,8 +58,20 @@
>> #define S390_VIRTIO_BUS(obj) \
>> OBJECT_CHECK(VirtIOS390Bus, (obj), TYPE_S390_VIRTIO_BUS)
>>
>> +/* virtio-s390-bus */
>> +
>> +#define TYPE_VIRTIO_S390_BUS "virtio-s390-bus"
>> +#define VIRTIO_S390_BUS_GET_CLASS(obj) \
>> + OBJECT_GET_CLASS(VirtioBusClass, obj, TYPE_VIRTIO_S390_BUS)
>> +#define VIRTIO_PCI_BUS_CLASS(klass) \
>> + OBJECT_CLASS_CHECK(VirtioBusClass, klass, TYPE_VIRTIO_S390_BUS)
>> +#define VIRTIO_PCI_BUS(obj) \
>> + OBJECT_CHECK(VirtioBusState, (obj), TYPE_VIRTIO_S390_BUS)
> PCI? This looks wrong.
oops, yes sorry for that.
It didn't complain as I don't use the VirtioBusClass for the moment.
I fixed it.
Thanks.
>
>> +
>> typedef struct VirtIOS390Device VirtIOS390Device;
>>
>> +VirtioBusState *virtio_s390_bus_new(VirtIOS390Device *dev);
>> +
>> typedef struct VirtIOS390DeviceClass {
>> DeviceClass qdev;
>> int (*init)(VirtIOS390Device *dev);
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 07/15] virtio-s390-device : create a virtio-s390-bus during init.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (5 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 06/15] virtio-s390-bus : Add virtio-s390-bus fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 08/15] virtio-blk : Add the virtio-blk device fred.konrad
` (7 subsequent siblings)
14 siblings, 0 replies; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Create a virtio-s390-bus during init, so the refactored virtio device can be
connected.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/s390-virtio-bus.c | 2 ++
hw/s390-virtio-bus.h | 1 +
2 files changed, 3 insertions(+)
diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 720dbb9..849adab 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -490,6 +490,8 @@ static int s390_virtio_busdev_init(DeviceState *dev)
VirtIOS390Device *_dev = (VirtIOS390Device *)dev;
VirtIOS390DeviceClass *_info = VIRTIO_S390_DEVICE_GET_CLASS(dev);
+ _dev->bus = virtio_s390_bus_new(_dev);
+
return _info->init(_dev);
}
diff --git a/hw/s390-virtio-bus.h b/hw/s390-virtio-bus.h
index 7c5a945..08e68c2 100644
--- a/hw/s390-virtio-bus.h
+++ b/hw/s390-virtio-bus.h
@@ -90,6 +90,7 @@ struct VirtIOS390Device {
virtio_net_conf net;
VirtIOSCSIConf scsi;
VirtIORNGConf rng;
+ VirtioBusState *bus;
};
typedef struct VirtIOS390Bus {
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 08/15] virtio-blk : Add the virtio-blk device.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (6 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 07/15] virtio-s390-device : create a virtio-s390-bus during init fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2012-12-19 20:00 ` Blue Swirl
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 09/15] virtio-blk-pci : Switch to new API fred.konrad
` (6 subsequent siblings)
14 siblings, 1 reply; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Create virtio-blk which extends virtio-device, so it can be connected on
virtio-bus.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-blk.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
hw/virtio-blk.h | 19 +++++++++++
hw/virtio-pci.c | 7 ++--
3 files changed, 116 insertions(+), 11 deletions(-)
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index e25cc96..5511999 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -21,6 +21,7 @@
#ifdef __linux__
# include <scsi/sg.h>
#endif
+#include "virtio-bus.h"
typedef struct VirtIOBlock
{
@@ -30,11 +31,14 @@ typedef struct VirtIOBlock
void *rq;
QEMUBH *bh;
BlockConf *conf;
- VirtIOBlkConf *blk;
+ VirtIOBlkConf blk;
unsigned short sector_mask;
DeviceState *qdev;
} VirtIOBlock;
+/*
+ * Moving to QOM later in this series.
+ */
static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
{
return (VirtIOBlock *)vdev;
@@ -164,7 +168,7 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
*/
req->scsi = (void *)req->elem.in_sg[req->elem.in_num - 2].iov_base;
- if (!req->dev->blk->scsi) {
+ if (!req->dev->blk.scsi) {
status = VIRTIO_BLK_S_UNSUPP;
goto fail;
}
@@ -384,7 +388,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
* terminated by '\0' only when shorter than buffer.
*/
strncpy(req->elem.in_sg[0].iov_base,
- s->blk->serial ? s->blk->serial : "",
+ s->blk.serial ? s->blk.serial : "",
MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
g_free(req);
@@ -600,9 +604,16 @@ static const BlockDevOps virtio_block_ops = {
.resize_cb = virtio_blk_resize,
};
-VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
+void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
+{
+ VirtIOBlock *s = VIRTIO_BLK(dev);
+ memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
+}
+
+static VirtIODevice *virtio_blk_common_init(DeviceState *dev,
+ VirtIOBlkConf *blk, VirtIOBlock **ps)
{
- VirtIOBlock *s;
+ VirtIOBlock *s = *ps;
static int virtio_blk_id;
if (!blk->conf.bs) {
@@ -619,9 +630,20 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
return NULL;
}
- s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
- sizeof(struct virtio_blk_config),
- sizeof(VirtIOBlock));
+ /*
+ * We have two cases here : the old virtio-blk-pci device, and the
+ * refactored virtio-blk.
+ */
+ if (s == NULL) {
+ /* virtio-blk-pci */
+ s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
+ sizeof(struct virtio_blk_config),
+ sizeof(VirtIOBlock));
+ } else {
+ /* virtio-blk */
+ virtio_init(VIRTIO_DEVICE(s), "virtio-blk", VIRTIO_ID_BLOCK,
+ sizeof(struct virtio_blk_config));
+ }
s->vdev.get_config = virtio_blk_update_config;
s->vdev.set_config = virtio_blk_set_config;
@@ -630,7 +652,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
s->vdev.reset = virtio_blk_reset;
s->bs = blk->conf.bs;
s->conf = &blk->conf;
- s->blk = blk;
+ virtio_blk_set_conf(dev, blk);
s->rq = NULL;
s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
@@ -649,6 +671,12 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
return &s->vdev;
}
+VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
+{
+ VirtIOBlock *s = NULL;
+ return virtio_blk_common_init(dev, blk, &s);
+}
+
void virtio_blk_exit(VirtIODevice *vdev)
{
VirtIOBlock *s = to_virtio_blk(vdev);
@@ -656,3 +684,58 @@ void virtio_blk_exit(VirtIODevice *vdev)
blockdev_mark_auto_del(s->bs);
virtio_cleanup(vdev);
}
+
+
+static int virtio_blk_device_init(VirtIODevice *vdev)
+{
+ DeviceState *qdev = DEVICE(vdev);
+ VirtIOBlock *s = VIRTIO_BLK(vdev);
+ VirtIOBlkConf *blk = &(s->blk);
+ if (virtio_blk_common_init(qdev, blk, &s) == NULL) {
+ return -1;
+ }
+ return 0;
+}
+
+static int virtio_blk_device_exit(DeviceState *dev)
+{
+ VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+ VirtIOBlock *s = VIRTIO_BLK(dev);
+ unregister_savevm(s->qdev, "virtio-blk", s);
+ blockdev_mark_auto_del(s->bs);
+ virtio_common_cleanup(vdev);
+ return 0;
+}
+
+static Property virtio_blk_properties[] = {
+ DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlock, blk),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void virtio_blk_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
+ dc->exit = virtio_blk_device_exit;
+ dc->props = virtio_blk_properties;
+ vdc->init = virtio_blk_device_init;
+ vdc->get_config = virtio_blk_update_config;
+ vdc->set_config = virtio_blk_set_config;
+ vdc->get_features = virtio_blk_get_features;
+ vdc->set_status = virtio_blk_set_status;
+ vdc->reset = virtio_blk_reset;
+}
+
+static const TypeInfo virtio_device_info = {
+ .name = TYPE_VIRTIO_BLK,
+ .parent = TYPE_VIRTIO_DEVICE,
+ .instance_size = sizeof(VirtIOBlock),
+ .class_init = virtio_blk_class_init,
+};
+
+static void virtio_register_types(void)
+{
+ type_register_static(&virtio_device_info);
+}
+
+type_init(virtio_register_types)
diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
index 651a000..e89c88e 100644
--- a/hw/virtio-blk.h
+++ b/hw/virtio-blk.h
@@ -17,6 +17,10 @@
#include "virtio.h"
#include "hw/block-common.h"
+#define TYPE_VIRTIO_BLK "virtio-blk"
+#define VIRTIO_BLK(obj) \
+ OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
+
/* from Linux's linux/virtio_blk.h */
/* The ID for virtio_block */
@@ -110,4 +114,19 @@ struct VirtIOBlkConf
DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
DEFINE_PROP_BIT("config-wce", _state, _field, VIRTIO_BLK_F_CONFIG_WCE, true)
+#ifdef __linux__
+#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
+ DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
+ DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
+ DEFINE_PROP_STRING("serial", _state, _field.serial), \
+ DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true)
+#else
+#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
+ DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
+ DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
+ DEFINE_PROP_STRING("serial", _state, _field.serial)
+#endif /* __linux__ */
+
+void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk);
+
#endif
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 916ed7c..877bf38 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -1132,8 +1132,11 @@ static void virtio_pci_device_plugged(void *opaque)
/* Put the PCI IDs */
switch (get_virtio_device_id(proxy->bus)) {
-
-
+ case VIRTIO_ID_BLOCK:
+ pci_config_set_device_id(proxy->pci_dev.config,
+ PCI_DEVICE_ID_VIRTIO_BLOCK);
+ pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_STORAGE_SCSI);
+ break;
default:
error_report("unknown device id\n");
break;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 08/15] virtio-blk : Add the virtio-blk device.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 08/15] virtio-blk : Add the virtio-blk device fred.konrad
@ 2012-12-19 20:00 ` Blue Swirl
2012-12-19 23:22 ` Peter Maydell
0 siblings, 1 reply; 35+ messages in thread
From: Blue Swirl @ 2012-12-19 20:00 UTC (permalink / raw)
To: fred.konrad
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, qemu-devel,
agraf, stefanha, cornelia.huck, afaerber
On Wed, Dec 19, 2012 at 9:53 AM, <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Create virtio-blk which extends virtio-device, so it can be connected on
> virtio-bus.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/virtio-blk.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
> hw/virtio-blk.h | 19 +++++++++++
> hw/virtio-pci.c | 7 ++--
> 3 files changed, 116 insertions(+), 11 deletions(-)
>
> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index e25cc96..5511999 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -21,6 +21,7 @@
> #ifdef __linux__
> # include <scsi/sg.h>
> #endif
> +#include "virtio-bus.h"
>
> typedef struct VirtIOBlock
> {
> @@ -30,11 +31,14 @@ typedef struct VirtIOBlock
> void *rq;
> QEMUBH *bh;
> BlockConf *conf;
> - VirtIOBlkConf *blk;
> + VirtIOBlkConf blk;
> unsigned short sector_mask;
> DeviceState *qdev;
> } VirtIOBlock;
>
> +/*
> + * Moving to QOM later in this series.
> + */
> static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
> {
> return (VirtIOBlock *)vdev;
> @@ -164,7 +168,7 @@ static void virtio_blk_handle_scsi(VirtIOBlockReq *req)
> */
> req->scsi = (void *)req->elem.in_sg[req->elem.in_num - 2].iov_base;
>
> - if (!req->dev->blk->scsi) {
> + if (!req->dev->blk.scsi) {
> status = VIRTIO_BLK_S_UNSUPP;
> goto fail;
> }
> @@ -384,7 +388,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
> * terminated by '\0' only when shorter than buffer.
> */
> strncpy(req->elem.in_sg[0].iov_base,
> - s->blk->serial ? s->blk->serial : "",
> + s->blk.serial ? s->blk.serial : "",
> MIN(req->elem.in_sg[0].iov_len, VIRTIO_BLK_ID_BYTES));
> virtio_blk_req_complete(req, VIRTIO_BLK_S_OK);
> g_free(req);
> @@ -600,9 +604,16 @@ static const BlockDevOps virtio_block_ops = {
> .resize_cb = virtio_blk_resize,
> };
>
> -VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
> +void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
> +{
> + VirtIOBlock *s = VIRTIO_BLK(dev);
> + memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
> +}
> +
> +static VirtIODevice *virtio_blk_common_init(DeviceState *dev,
> + VirtIOBlkConf *blk, VirtIOBlock **ps)
> {
> - VirtIOBlock *s;
> + VirtIOBlock *s = *ps;
> static int virtio_blk_id;
>
> if (!blk->conf.bs) {
> @@ -619,9 +630,20 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
> return NULL;
> }
>
> - s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
> - sizeof(struct virtio_blk_config),
> - sizeof(VirtIOBlock));
> + /*
> + * We have two cases here : the old virtio-blk-pci device, and the
> + * refactored virtio-blk.
> + */
> + if (s == NULL) {
> + /* virtio-blk-pci */
> + s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
> + sizeof(struct virtio_blk_config),
> + sizeof(VirtIOBlock));
> + } else {
> + /* virtio-blk */
> + virtio_init(VIRTIO_DEVICE(s), "virtio-blk", VIRTIO_ID_BLOCK,
> + sizeof(struct virtio_blk_config));
> + }
>
> s->vdev.get_config = virtio_blk_update_config;
> s->vdev.set_config = virtio_blk_set_config;
> @@ -630,7 +652,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
> s->vdev.reset = virtio_blk_reset;
> s->bs = blk->conf.bs;
> s->conf = &blk->conf;
> - s->blk = blk;
> + virtio_blk_set_conf(dev, blk);
> s->rq = NULL;
> s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
>
> @@ -649,6 +671,12 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
> return &s->vdev;
> }
>
> +VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
> +{
> + VirtIOBlock *s = NULL;
> + return virtio_blk_common_init(dev, blk, &s);
> +}
> +
> void virtio_blk_exit(VirtIODevice *vdev)
> {
> VirtIOBlock *s = to_virtio_blk(vdev);
> @@ -656,3 +684,58 @@ void virtio_blk_exit(VirtIODevice *vdev)
> blockdev_mark_auto_del(s->bs);
> virtio_cleanup(vdev);
> }
> +
> +
> +static int virtio_blk_device_init(VirtIODevice *vdev)
> +{
> + DeviceState *qdev = DEVICE(vdev);
> + VirtIOBlock *s = VIRTIO_BLK(vdev);
> + VirtIOBlkConf *blk = &(s->blk);
> + if (virtio_blk_common_init(qdev, blk, &s) == NULL) {
> + return -1;
> + }
> + return 0;
> +}
> +
> +static int virtio_blk_device_exit(DeviceState *dev)
> +{
> + VirtIODevice *vdev = VIRTIO_DEVICE(dev);
> + VirtIOBlock *s = VIRTIO_BLK(dev);
> + unregister_savevm(s->qdev, "virtio-blk", s);
> + blockdev_mark_auto_del(s->bs);
> + virtio_common_cleanup(vdev);
> + return 0;
> +}
> +
> +static Property virtio_blk_properties[] = {
> + DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlock, blk),
> + DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static void virtio_blk_class_init(ObjectClass *klass, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
> + dc->exit = virtio_blk_device_exit;
> + dc->props = virtio_blk_properties;
> + vdc->init = virtio_blk_device_init;
> + vdc->get_config = virtio_blk_update_config;
> + vdc->set_config = virtio_blk_set_config;
> + vdc->get_features = virtio_blk_get_features;
> + vdc->set_status = virtio_blk_set_status;
> + vdc->reset = virtio_blk_reset;
> +}
> +
> +static const TypeInfo virtio_device_info = {
> + .name = TYPE_VIRTIO_BLK,
> + .parent = TYPE_VIRTIO_DEVICE,
> + .instance_size = sizeof(VirtIOBlock),
> + .class_init = virtio_blk_class_init,
> +};
> +
> +static void virtio_register_types(void)
> +{
> + type_register_static(&virtio_device_info);
> +}
> +
> +type_init(virtio_register_types)
> diff --git a/hw/virtio-blk.h b/hw/virtio-blk.h
> index 651a000..e89c88e 100644
> --- a/hw/virtio-blk.h
> +++ b/hw/virtio-blk.h
> @@ -17,6 +17,10 @@
> #include "virtio.h"
> #include "hw/block-common.h"
>
> +#define TYPE_VIRTIO_BLK "virtio-blk"
> +#define VIRTIO_BLK(obj) \
> + OBJECT_CHECK(VirtIOBlock, (obj), TYPE_VIRTIO_BLK)
> +
> /* from Linux's linux/virtio_blk.h */
>
> /* The ID for virtio_block */
> @@ -110,4 +114,19 @@ struct VirtIOBlkConf
> DEFINE_VIRTIO_COMMON_FEATURES(_state, _field), \
> DEFINE_PROP_BIT("config-wce", _state, _field, VIRTIO_BLK_F_CONFIG_WCE, true)
>
> +#ifdef __linux__
> +#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
> + DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
> + DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
> + DEFINE_PROP_STRING("serial", _state, _field.serial), \
> + DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true)
> +#else
> +#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
> + DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
> + DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
> + DEFINE_PROP_STRING("serial", _state, _field.serial)
Does the different property set mean that it would not be possible to
migrate VMs which use virtio from non-Linux host to Linux and vice
versa?
> +#endif /* __linux__ */
> +
> +void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk);
> +
> #endif
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 916ed7c..877bf38 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -1132,8 +1132,11 @@ static void virtio_pci_device_plugged(void *opaque)
>
> /* Put the PCI IDs */
> switch (get_virtio_device_id(proxy->bus)) {
> -
> -
> + case VIRTIO_ID_BLOCK:
> + pci_config_set_device_id(proxy->pci_dev.config,
> + PCI_DEVICE_ID_VIRTIO_BLOCK);
> + pci_config_set_class(proxy->pci_dev.config, PCI_CLASS_STORAGE_SCSI);
> + break;
Again wrong indentation.
> default:
> error_report("unknown device id\n");
> break;
> --
> 1.7.11.7
>
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 08/15] virtio-blk : Add the virtio-blk device.
2012-12-19 20:00 ` Blue Swirl
@ 2012-12-19 23:22 ` Peter Maydell
0 siblings, 0 replies; 35+ messages in thread
From: Peter Maydell @ 2012-12-19 23:22 UTC (permalink / raw)
To: Blue Swirl
Cc: aliguori, e.voevodin, mark.burton, agraf, qemu-devel, stefanha,
cornelia.huck, afaerber, fred.konrad
On 19 December 2012 20:00, Blue Swirl <blauwirbel@gmail.com> wrote:
> On Wed, Dec 19, 2012 at 9:53 AM, <fred.konrad@greensocs.com> wrote:
>> +#ifdef __linux__
>> +#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
>> + DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
>> + DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
>> + DEFINE_PROP_STRING("serial", _state, _field.serial), \
>> + DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true)
>> +#else
>> +#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field) \
>> + DEFINE_BLOCK_PROPERTIES(_state, _field.conf), \
>> + DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf), \
>> + DEFINE_PROP_STRING("serial", _state, _field.serial)
>
> Does the different property set mean that it would not be possible to
> migrate VMs which use virtio from non-Linux host to Linux and vice
> versa?
Probably, but note that this is just reflecting an existing ifdef in
the non-refactored implementation.
(I looked at that existing ifdef and thought "smells dubious", but
presumably there is a reason.)
-- PMM
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 09/15] virtio-blk-pci : Switch to new API.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (7 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 08/15] virtio-blk : Add the virtio-blk device fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2013-01-02 14:18 ` Anthony Liguori
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 10/15] virtio-blk-s390 : Switch to the " fred.konrad
` (5 subsequent siblings)
14 siblings, 1 reply; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Here the virtio-blk-pci is modified for the new API. The device virtio-blk-pci
extends virtio-pci. It creates and connects a virtio-blk during the init.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-pci.c | 106 +++++++++++++++++++++-----------------------------------
hw/virtio-pci.h | 14 +++++++-
2 files changed, 53 insertions(+), 67 deletions(-)
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index 877bf38..e3a8276 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -734,26 +734,6 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
proxy->host_features = vdev->get_features(vdev, proxy->host_features);
}
-static int virtio_blk_init_pci(PCIDevice *pci_dev)
-{
- VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
- VirtIODevice *vdev;
-
- if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
- proxy->class_code != PCI_CLASS_STORAGE_OTHER)
- proxy->class_code = PCI_CLASS_STORAGE_SCSI;
-
- vdev = virtio_blk_init(&pci_dev->qdev, &proxy->blk);
- if (!vdev) {
- return -1;
- }
- vdev->nvectors = proxy->nvectors;
- virtio_init_pci(proxy, vdev);
- /* make the actual value visible */
- proxy->nvectors = vdev->nvectors;
- return 0;
-}
-
static void virtio_exit_pci(PCIDevice *pci_dev)
{
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -762,15 +742,6 @@ static void virtio_exit_pci(PCIDevice *pci_dev)
msix_uninit_exclusive_bar(pci_dev);
}
-static void virtio_blk_exit_pci(PCIDevice *pci_dev)
-{
- VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
-
- virtio_pci_stop_ioeventfd(proxy);
- virtio_blk_exit(proxy->vdev);
- virtio_exit_pci(pci_dev);
-}
-
static int virtio_serial_init_pci(PCIDevice *pci_dev)
{
VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
@@ -888,42 +859,6 @@ static void virtio_rng_exit_pci(PCIDevice *pci_dev)
virtio_exit_pci(pci_dev);
}
-static Property virtio_blk_properties[] = {
- DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
- DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, blk.conf),
- DEFINE_BLOCK_CHS_PROPERTIES(VirtIOPCIProxy, blk.conf),
- DEFINE_PROP_STRING("serial", VirtIOPCIProxy, blk.serial),
-#ifdef __linux__
- DEFINE_PROP_BIT("scsi", VirtIOPCIProxy, blk.scsi, 0, true),
-#endif
- DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
- DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
- DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
- DEFINE_PROP_END_OF_LIST(),
-};
-
-static void virtio_blk_class_init(ObjectClass *klass, void *data)
-{
- DeviceClass *dc = DEVICE_CLASS(klass);
- PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
-
- k->init = virtio_blk_init_pci;
- k->exit = virtio_blk_exit_pci;
- k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
- k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
- k->revision = VIRTIO_PCI_ABI_VERSION;
- k->class_id = PCI_CLASS_STORAGE_SCSI;
- dc->reset = virtio_pci_reset;
- dc->props = virtio_blk_properties;
-}
-
-static TypeInfo virtio_blk_info = {
- .name = "virtio-blk-pci",
- .parent = TYPE_PCI_DEVICE,
- .instance_size = sizeof(VirtIOPCIProxy),
- .class_init = virtio_blk_class_init,
-};
-
static Property virtio_net_properties[] = {
DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
@@ -1248,6 +1183,45 @@ static const TypeInfo virtio_pci_info = {
.class_size = sizeof(VirtioPCIClass),
};
+/* virtio-blk-pci */
+
+static Property virtio_blk_pci_properties[] = {
+ DEFINE_PROP_HEX32("class", VirtIOBlkPCI, parent_obj.class_code, 0),
+ DEFINE_PROP_BIT("ioeventfd", VirtIOBlkPCI, parent_obj.flags,
+ VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
+ DEFINE_PROP_UINT32("vectors", VirtIOBlkPCI, parent_obj.nvectors, 2),
+ DEFINE_VIRTIO_BLK_FEATURES(VirtIOBlkPCI, parent_obj.host_features),
+ DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkPCI, blk),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static int virtio_blk_pci_init(VirtIOPCIProxy *vpci_dev)
+{
+ DeviceState *vdev;
+ VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
+ vdev = qdev_create(BUS(vpci_dev->bus), "virtio-blk");
+ virtio_blk_set_conf(vdev, &(dev->blk));
+ if (qdev_init(vdev) < 0) {
+ return -1;
+ }
+ return 0;
+}
+
+static void virtio_blk_pci_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
+ dc->props = virtio_blk_pci_properties;
+ k->init = virtio_blk_pci_init;
+}
+
+static const TypeInfo virtio_blk_pci_info = {
+ .name = TYPE_VIRTIO_BLK_PCI,
+ .parent = TYPE_VIRTIO_PCI,
+ .instance_size = sizeof(VirtIOBlkPCI),
+ .class_init = virtio_blk_pci_class_init,
+};
+
/* virtio-pci-bus */
VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
@@ -1287,7 +1261,6 @@ static const TypeInfo virtio_pci_bus_info = {
static void virtio_pci_register_types(void)
{
- type_register_static(&virtio_blk_info);
type_register_static(&virtio_net_info);
type_register_static(&virtio_serial_info);
type_register_static(&virtio_balloon_info);
@@ -1295,6 +1268,7 @@ static void virtio_pci_register_types(void)
type_register_static(&virtio_rng_info);
type_register_static(&virtio_pci_bus_info);
type_register_static(&virtio_pci_info);
+ type_register_static(&virtio_blk_pci_info);
}
type_init(virtio_pci_register_types)
diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
index e840cea..8a68d6e 100644
--- a/hw/virtio-pci.h
+++ b/hw/virtio-pci.h
@@ -24,6 +24,7 @@
/* VirtIOPCIProxy will be renammed VirtioPCIState at the end. */
typedef struct VirtIOPCIProxy VirtIOPCIProxy;
+typedef struct VirtIOBlkPCI VirtIOBlkPCI;
/* virtio-pci-bus */
#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
@@ -69,7 +70,6 @@ struct VirtIOPCIProxy {
uint32_t flags;
uint32_t class_code;
uint32_t nvectors;
- VirtIOBlkConf blk;
NICConf nic;
uint32_t host_features;
#ifdef CONFIG_LINUX
@@ -87,6 +87,18 @@ struct VirtIOPCIProxy {
/* Nothing more for the moment. */
};
+/*
+ * virtio-blk-pci : This extends VirtioPCIProxy.
+ */
+#define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
+#define VIRTIO_BLK_PCI(obj) \
+ OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
+
+struct VirtIOBlkPCI {
+ VirtIOPCIProxy parent_obj;
+ VirtIOBlkConf blk;
+};
+
void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
void virtio_pci_reset(DeviceState *d);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 09/15] virtio-blk-pci : Switch to new API.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 09/15] virtio-blk-pci : Switch to new API fred.konrad
@ 2013-01-02 14:18 ` Anthony Liguori
0 siblings, 0 replies; 35+ messages in thread
From: Anthony Liguori @ 2013-01-02 14:18 UTC (permalink / raw)
To: fred.konrad, qemu-devel
Cc: peter.maydell, e.voevodin, mark.burton, agraf, stefanha,
cornelia.huck, afaerber
fred.konrad@greensocs.com writes:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> Here the virtio-blk-pci is modified for the new API. The device virtio-blk-pci
> extends virtio-pci. It creates and connects a virtio-blk during the init.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/virtio-pci.c | 106 +++++++++++++++++++++-----------------------------------
> hw/virtio-pci.h | 14 +++++++-
> 2 files changed, 53 insertions(+), 67 deletions(-)
>
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index 877bf38..e3a8276 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -734,26 +734,6 @@ void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev)
> proxy->host_features = vdev->get_features(vdev, proxy->host_features);
> }
>
> -static int virtio_blk_init_pci(PCIDevice *pci_dev)
> -{
> - VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> - VirtIODevice *vdev;
> -
> - if (proxy->class_code != PCI_CLASS_STORAGE_SCSI &&
> - proxy->class_code != PCI_CLASS_STORAGE_OTHER)
> - proxy->class_code = PCI_CLASS_STORAGE_SCSI;
> -
> - vdev = virtio_blk_init(&pci_dev->qdev, &proxy->blk);
> - if (!vdev) {
> - return -1;
> - }
> - vdev->nvectors = proxy->nvectors;
> - virtio_init_pci(proxy, vdev);
> - /* make the actual value visible */
> - proxy->nvectors = vdev->nvectors;
> - return 0;
> -}
> -
> static void virtio_exit_pci(PCIDevice *pci_dev)
> {
> VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> @@ -762,15 +742,6 @@ static void virtio_exit_pci(PCIDevice *pci_dev)
> msix_uninit_exclusive_bar(pci_dev);
> }
>
> -static void virtio_blk_exit_pci(PCIDevice *pci_dev)
> -{
> - VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> -
> - virtio_pci_stop_ioeventfd(proxy);
> - virtio_blk_exit(proxy->vdev);
> - virtio_exit_pci(pci_dev);
> -}
> -
> static int virtio_serial_init_pci(PCIDevice *pci_dev)
> {
> VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev);
> @@ -888,42 +859,6 @@ static void virtio_rng_exit_pci(PCIDevice *pci_dev)
> virtio_exit_pci(pci_dev);
> }
>
> -static Property virtio_blk_properties[] = {
> - DEFINE_PROP_HEX32("class", VirtIOPCIProxy, class_code, 0),
> - DEFINE_BLOCK_PROPERTIES(VirtIOPCIProxy, blk.conf),
> - DEFINE_BLOCK_CHS_PROPERTIES(VirtIOPCIProxy, blk.conf),
> - DEFINE_PROP_STRING("serial", VirtIOPCIProxy, blk.serial),
> -#ifdef __linux__
> - DEFINE_PROP_BIT("scsi", VirtIOPCIProxy, blk.scsi, 0, true),
> -#endif
> - DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
> - DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2),
> - DEFINE_VIRTIO_BLK_FEATURES(VirtIOPCIProxy, host_features),
> - DEFINE_PROP_END_OF_LIST(),
> -};
> -
> -static void virtio_blk_class_init(ObjectClass *klass, void *data)
> -{
> - DeviceClass *dc = DEVICE_CLASS(klass);
> - PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
> -
> - k->init = virtio_blk_init_pci;
> - k->exit = virtio_blk_exit_pci;
> - k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET;
> - k->device_id = PCI_DEVICE_ID_VIRTIO_BLOCK;
> - k->revision = VIRTIO_PCI_ABI_VERSION;
> - k->class_id = PCI_CLASS_STORAGE_SCSI;
> - dc->reset = virtio_pci_reset;
> - dc->props = virtio_blk_properties;
> -}
> -
> -static TypeInfo virtio_blk_info = {
> - .name = "virtio-blk-pci",
> - .parent = TYPE_PCI_DEVICE,
> - .instance_size = sizeof(VirtIOPCIProxy),
> - .class_init = virtio_blk_class_init,
> -};
> -
> static Property virtio_net_properties[] = {
> DEFINE_PROP_BIT("ioeventfd", VirtIOPCIProxy, flags, VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false),
> DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 3),
> @@ -1248,6 +1183,45 @@ static const TypeInfo virtio_pci_info = {
> .class_size = sizeof(VirtioPCIClass),
> };
>
> +/* virtio-blk-pci */
> +
> +static Property virtio_blk_pci_properties[] = {
> + DEFINE_PROP_HEX32("class", VirtIOBlkPCI, parent_obj.class_code, 0),
> + DEFINE_PROP_BIT("ioeventfd", VirtIOBlkPCI, parent_obj.flags,
> + VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, true),
> + DEFINE_PROP_UINT32("vectors", VirtIOBlkPCI, parent_obj.nvectors, 2),
> + DEFINE_VIRTIO_BLK_FEATURES(VirtIOBlkPCI, parent_obj.host_features),
> + DEFINE_VIRTIO_BLK_PROPERTIES(VirtIOBlkPCI, blk),
> + DEFINE_PROP_END_OF_LIST(),
> +};
> +
> +static int virtio_blk_pci_init(VirtIOPCIProxy *vpci_dev)
> +{
> + DeviceState *vdev;
> + VirtIOBlkPCI *dev = VIRTIO_BLK_PCI(vpci_dev);
> + vdev = qdev_create(BUS(vpci_dev->bus), "virtio-blk");
This is the wrong way to do this.
You should do object_initialize() and object_property_add_child() in an
initialization function for this type.
You can qdev_set_parent_bus() in the initialization function, but defer
the qdev_init() until here for the child.
Regards,
Anthony Liguori
> + virtio_blk_set_conf(vdev, &(dev->blk));
> + if (qdev_init(vdev) < 0) {
> + return -1;
> + }
> + return 0;
> +}
> +
> +static void virtio_blk_pci_class_init(ObjectClass *klass, void *data)
> +{
> + DeviceClass *dc = DEVICE_CLASS(klass);
> + VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass);
> + dc->props = virtio_blk_pci_properties;
> + k->init = virtio_blk_pci_init;
> +}
> +
> +static const TypeInfo virtio_blk_pci_info = {
> + .name = TYPE_VIRTIO_BLK_PCI,
> + .parent = TYPE_VIRTIO_PCI,
> + .instance_size = sizeof(VirtIOBlkPCI),
> + .class_init = virtio_blk_pci_class_init,
> +};
> +
> /* virtio-pci-bus */
>
> VirtioBusState *virtio_pci_bus_new(VirtIOPCIProxy *dev)
> @@ -1287,7 +1261,6 @@ static const TypeInfo virtio_pci_bus_info = {
>
> static void virtio_pci_register_types(void)
> {
> - type_register_static(&virtio_blk_info);
> type_register_static(&virtio_net_info);
> type_register_static(&virtio_serial_info);
> type_register_static(&virtio_balloon_info);
> @@ -1295,6 +1268,7 @@ static void virtio_pci_register_types(void)
> type_register_static(&virtio_rng_info);
> type_register_static(&virtio_pci_bus_info);
> type_register_static(&virtio_pci_info);
> + type_register_static(&virtio_blk_pci_info);
> }
>
> type_init(virtio_pci_register_types)
> diff --git a/hw/virtio-pci.h b/hw/virtio-pci.h
> index e840cea..8a68d6e 100644
> --- a/hw/virtio-pci.h
> +++ b/hw/virtio-pci.h
> @@ -24,6 +24,7 @@
>
> /* VirtIOPCIProxy will be renammed VirtioPCIState at the end. */
> typedef struct VirtIOPCIProxy VirtIOPCIProxy;
> +typedef struct VirtIOBlkPCI VirtIOBlkPCI;
>
> /* virtio-pci-bus */
> #define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus"
> @@ -69,7 +70,6 @@ struct VirtIOPCIProxy {
> uint32_t flags;
> uint32_t class_code;
> uint32_t nvectors;
> - VirtIOBlkConf blk;
> NICConf nic;
> uint32_t host_features;
> #ifdef CONFIG_LINUX
> @@ -87,6 +87,18 @@ struct VirtIOPCIProxy {
> /* Nothing more for the moment. */
> };
>
> +/*
> + * virtio-blk-pci : This extends VirtioPCIProxy.
> + */
> +#define TYPE_VIRTIO_BLK_PCI "virtio-blk-pci"
> +#define VIRTIO_BLK_PCI(obj) \
> + OBJECT_CHECK(VirtIOBlkPCI, (obj), TYPE_VIRTIO_BLK_PCI)
> +
> +struct VirtIOBlkPCI {
> + VirtIOPCIProxy parent_obj;
> + VirtIOBlkConf blk;
> +};
> +
> void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev);
> void virtio_pci_reset(DeviceState *d);
>
> --
> 1.7.11.7
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 10/15] virtio-blk-s390 : Switch to the new API.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (8 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 09/15] virtio-blk-pci : Switch to new API fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 11/15] virtio-blk : cleanup : use QOM cast fred.konrad
` (4 subsequent siblings)
14 siblings, 0 replies; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Here the virtio-blk-s390 is modified for the new API. The device virtio-blk-s390
extends virtio-s390-device. It creates and connects a virtio-blk during the
init.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/s390-virtio-bus.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/hw/s390-virtio-bus.c b/hw/s390-virtio-bus.c
index 849adab..eba4f3f 100644
--- a/hw/s390-virtio-bus.c
+++ b/hw/s390-virtio-bus.c
@@ -165,14 +165,13 @@ static int s390_virtio_net_init(VirtIOS390Device *dev)
static int s390_virtio_blk_init(VirtIOS390Device *dev)
{
- VirtIODevice *vdev;
-
- vdev = virtio_blk_init((DeviceState *)dev, &dev->blk);
- if (!vdev) {
+ DeviceState *vdev;
+ vdev = qdev_create(BUS(dev->bus), "virtio-blk");
+ virtio_blk_set_conf(vdev, &(dev->blk));
+ if (qdev_init(vdev) < 0) {
return -1;
}
-
- return s390_virtio_device_init(dev, vdev);
+ return s390_virtio_device_init(dev, VIRTIO_DEVICE(vdev));
}
static int s390_virtio_serial_init(VirtIOS390Device *dev)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 11/15] virtio-blk : cleanup : use QOM cast.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (9 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 10/15] virtio-blk-s390 : Switch to the " fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 12/15] virtio-blk : cleanup : remove qdev field fred.konrad
` (3 subsequent siblings)
14 siblings, 0 replies; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
As the virtio-blk-pci is switched to the new API, we can use QOM casts and
remove the separate init for the old API. This shouldn't been applyied
before virtio-blk-pci refactoring and virtio-blk-s390 refactoring.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-blk.c | 117 ++++++++++++++++++--------------------------------------
1 file changed, 37 insertions(+), 80 deletions(-)
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 5511999..93b9746 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -25,7 +25,7 @@
typedef struct VirtIOBlock
{
- VirtIODevice vdev;
+ VirtIODevice parent_obj;
BlockDriverState *bs;
VirtQueue *vq;
void *rq;
@@ -36,14 +36,6 @@ typedef struct VirtIOBlock
DeviceState *qdev;
} VirtIOBlock;
-/*
- * Moving to QOM later in this series.
- */
-static VirtIOBlock *to_virtio_blk(VirtIODevice *vdev)
-{
- return (VirtIOBlock *)vdev;
-}
-
typedef struct VirtIOBlockReq
{
VirtIOBlock *dev;
@@ -59,12 +51,13 @@ typedef struct VirtIOBlockReq
static void virtio_blk_req_complete(VirtIOBlockReq *req, int status)
{
VirtIOBlock *s = req->dev;
+ VirtIODevice *vdev = VIRTIO_DEVICE(s);
trace_virtio_blk_req_complete(req, status);
stb_p(&req->in->status, status);
virtqueue_push(s->vq, &req->elem, req->qiov.size + sizeof(*req->in));
- virtio_notify(&s->vdev, s->vq);
+ virtio_notify(vdev, s->vq);
}
static int virtio_blk_handle_rw_error(VirtIOBlockReq *req, int error,
@@ -405,7 +398,7 @@ static void virtio_blk_handle_request(VirtIOBlockReq *req,
static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
{
- VirtIOBlock *s = to_virtio_blk(vdev);
+ VirtIOBlock *s = VIRTIO_BLK(vdev);
VirtIOBlockReq *req;
MultiReqBuffer mrb = {
.num_writes = 0,
@@ -426,7 +419,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev, VirtQueue *vq)
static void virtio_blk_dma_restart_bh(void *opaque)
{
- VirtIOBlock *s = opaque;
+ VirtIOBlock *s = VIRTIO_BLK(opaque);
VirtIOBlockReq *req = s->rq;
MultiReqBuffer mrb = {
.num_writes = 0,
@@ -448,7 +441,7 @@ static void virtio_blk_dma_restart_bh(void *opaque)
static void virtio_blk_dma_restart_cb(void *opaque, int running,
RunState state)
{
- VirtIOBlock *s = opaque;
+ VirtIOBlock *s = VIRTIO_BLK(opaque);
if (!running)
return;
@@ -472,7 +465,7 @@ static void virtio_blk_reset(VirtIODevice *vdev)
*/
static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
{
- VirtIOBlock *s = to_virtio_blk(vdev);
+ VirtIOBlock *s = VIRTIO_BLK(vdev);
struct virtio_blk_config blkcfg;
uint64_t capacity;
int blk_size = s->conf->logical_block_size;
@@ -511,7 +504,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config)
static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
{
- VirtIOBlock *s = to_virtio_blk(vdev);
+ VirtIOBlock *s = VIRTIO_BLK(vdev);
struct virtio_blk_config blkcfg;
memcpy(&blkcfg, config, sizeof(blkcfg));
@@ -520,7 +513,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
{
- VirtIOBlock *s = to_virtio_blk(vdev);
+ VirtIOBlock *s = VIRTIO_BLK(vdev);
features |= (1 << VIRTIO_BLK_F_SEG_MAX);
features |= (1 << VIRTIO_BLK_F_GEOMETRY);
@@ -539,7 +532,7 @@ static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
{
- VirtIOBlock *s = to_virtio_blk(vdev);
+ VirtIOBlock *s = VIRTIO_BLK(vdev);
uint32_t features;
if (!(status & VIRTIO_CONFIG_S_DRIVER_OK)) {
@@ -552,10 +545,11 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status)
static void virtio_blk_save(QEMUFile *f, void *opaque)
{
- VirtIOBlock *s = opaque;
+ VirtIOBlock *s = VIRTIO_BLK(opaque);
+ VirtIODevice *vdev = VIRTIO_DEVICE(s);
VirtIOBlockReq *req = s->rq;
- virtio_save(&s->vdev, f);
+ virtio_save(vdev, f);
while (req) {
qemu_put_sbyte(f, 1);
@@ -567,13 +561,14 @@ static void virtio_blk_save(QEMUFile *f, void *opaque)
static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
{
- VirtIOBlock *s = opaque;
+ VirtIOBlock *s = VIRTIO_BLK(opaque);
+ VirtIODevice *vdev = VIRTIO_DEVICE(s);
int ret;
if (version_id != 2)
return -EINVAL;
- ret = virtio_load(&s->vdev, f);
+ ret = virtio_load(vdev, f);
if (ret) {
return ret;
}
@@ -595,9 +590,9 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int version_id)
static void virtio_blk_resize(void *opaque)
{
- VirtIOBlock *s = opaque;
+ VirtIODevice *vdev = VIRTIO_DEVICE(opaque);
- virtio_notify_config(&s->vdev);
+ virtio_notify_config(vdev);
}
static const BlockDevOps virtio_block_ops = {
@@ -610,90 +605,52 @@ void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk)
memcpy(&(s->blk), blk, sizeof(struct VirtIOBlkConf));
}
-static VirtIODevice *virtio_blk_common_init(DeviceState *dev,
- VirtIOBlkConf *blk, VirtIOBlock **ps)
+static int virtio_blk_device_init(VirtIODevice *vdev)
{
- VirtIOBlock *s = *ps;
+ DeviceState *qdev = DEVICE(vdev);
+ VirtIOBlock *s = VIRTIO_BLK(vdev);
+ VirtIOBlkConf *blk = &(s->blk);
static int virtio_blk_id;
if (!blk->conf.bs) {
error_report("drive property not set");
- return NULL;
+ return -1;
}
if (!bdrv_is_inserted(blk->conf.bs)) {
error_report("Device needs media, but drive is empty");
- return NULL;
+ return -1;
}
blkconf_serial(&blk->conf, &blk->serial);
if (blkconf_geometry(&blk->conf, NULL, 65535, 255, 255) < 0) {
- return NULL;
+ return -1;
}
- /*
- * We have two cases here : the old virtio-blk-pci device, and the
- * refactored virtio-blk.
- */
- if (s == NULL) {
- /* virtio-blk-pci */
- s = (VirtIOBlock *)virtio_common_init("virtio-blk", VIRTIO_ID_BLOCK,
- sizeof(struct virtio_blk_config),
- sizeof(VirtIOBlock));
- } else {
- /* virtio-blk */
- virtio_init(VIRTIO_DEVICE(s), "virtio-blk", VIRTIO_ID_BLOCK,
- sizeof(struct virtio_blk_config));
- }
+ virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
+ sizeof(struct virtio_blk_config));
- s->vdev.get_config = virtio_blk_update_config;
- s->vdev.set_config = virtio_blk_set_config;
- s->vdev.get_features = virtio_blk_get_features;
- s->vdev.set_status = virtio_blk_set_status;
- s->vdev.reset = virtio_blk_reset;
+ vdev->get_config = virtio_blk_update_config;
+ vdev->set_config = virtio_blk_set_config;
+ vdev->get_features = virtio_blk_get_features;
+ vdev->set_status = virtio_blk_set_status;
+ vdev->reset = virtio_blk_reset;
s->bs = blk->conf.bs;
s->conf = &blk->conf;
- virtio_blk_set_conf(dev, blk);
+ virtio_blk_set_conf(qdev, blk);
s->rq = NULL;
s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
- s->vq = virtio_add_queue(&s->vdev, 128, virtio_blk_handle_output);
+ s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
- s->qdev = dev;
- register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
+ s->qdev = qdev;
+ register_savevm(qdev, "virtio-blk", virtio_blk_id++, 2,
virtio_blk_save, virtio_blk_load, s);
bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
bdrv_set_buffer_alignment(s->bs, s->conf->logical_block_size);
bdrv_iostatus_enable(s->bs);
- add_boot_device_path(s->conf->bootindex, dev, "/disk@0,0");
-
- return &s->vdev;
-}
-
-VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
-{
- VirtIOBlock *s = NULL;
- return virtio_blk_common_init(dev, blk, &s);
-}
-
-void virtio_blk_exit(VirtIODevice *vdev)
-{
- VirtIOBlock *s = to_virtio_blk(vdev);
- unregister_savevm(s->qdev, "virtio-blk", s);
- blockdev_mark_auto_del(s->bs);
- virtio_cleanup(vdev);
-}
-
-
-static int virtio_blk_device_init(VirtIODevice *vdev)
-{
- DeviceState *qdev = DEVICE(vdev);
- VirtIOBlock *s = VIRTIO_BLK(vdev);
- VirtIOBlkConf *blk = &(s->blk);
- if (virtio_blk_common_init(qdev, blk, &s) == NULL) {
- return -1;
- }
+ add_boot_device_path(s->conf->bootindex, qdev, "/disk@0,0");
return 0;
}
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 12/15] virtio-blk : cleanup : remove qdev field.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (10 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 11/15] virtio-blk : cleanup : use QOM cast fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 13/15] virtio : Remove the function pointer fred.konrad
` (2 subsequent siblings)
14 siblings, 0 replies; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
The qdev field is not needed, just drop it.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-blk.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 93b9746..65932fd 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -33,7 +33,6 @@ typedef struct VirtIOBlock
BlockConf *conf;
VirtIOBlkConf blk;
unsigned short sector_mask;
- DeviceState *qdev;
} VirtIOBlock;
typedef struct VirtIOBlockReq
@@ -643,7 +642,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
s->vq = virtio_add_queue(vdev, 128, virtio_blk_handle_output);
qemu_add_vm_change_state_handler(virtio_blk_dma_restart_cb, s);
- s->qdev = qdev;
register_savevm(qdev, "virtio-blk", virtio_blk_id++, 2,
virtio_blk_save, virtio_blk_load, s);
bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
@@ -658,7 +656,7 @@ static int virtio_blk_device_exit(DeviceState *dev)
{
VirtIODevice *vdev = VIRTIO_DEVICE(dev);
VirtIOBlock *s = VIRTIO_BLK(dev);
- unregister_savevm(s->qdev, "virtio-blk", s);
+ unregister_savevm(dev, "virtio-blk", s);
blockdev_mark_auto_del(s->bs);
virtio_common_cleanup(vdev);
return 0;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 13/15] virtio : Remove the function pointer.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (11 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 12/15] virtio-blk : cleanup : remove qdev field fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2012-12-19 19:50 ` Blue Swirl
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 14/15] virtio : Remove VirtIOBindings fred.konrad
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 15/15] virtio : cleanup : init and exit function fred.konrad
14 siblings, 1 reply; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
This remove the function pointer in VirtIODevice, and use only
VirtioDeviceClass function pointer. It should be applied after all
the device have been refactored.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-blk.c | 5 -----
hw/virtio-pci.c | 2 +-
hw/virtio.c | 41 ++++++++++++++++++++++++++---------------
hw/virtio.h | 12 ------------
4 files changed, 27 insertions(+), 33 deletions(-)
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index 65932fd..fbb829e 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -628,11 +628,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
sizeof(struct virtio_blk_config));
- vdev->get_config = virtio_blk_update_config;
- vdev->set_config = virtio_blk_set_config;
- vdev->get_features = virtio_blk_get_features;
- vdev->set_status = virtio_blk_set_status;
- vdev->reset = virtio_blk_reset;
s->bs = blk->conf.bs;
s->conf = &blk->conf;
virtio_blk_set_conf(qdev, blk);
diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
index e3a8276..cdc3473 100644
--- a/hw/virtio-pci.c
+++ b/hw/virtio-pci.c
@@ -262,7 +262,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
case VIRTIO_PCI_GUEST_FEATURES:
/* Guest does not negotiate properly? We have to assume nothing. */
if (val & (1 << VIRTIO_F_BAD_FEATURE)) {
- val = vdev->bad_features ? vdev->bad_features(vdev) : 0;
+ val = get_virtio_device_bad_features(proxy->bus);
}
virtio_set_features(vdev, val);
break;
diff --git a/hw/virtio.c b/hw/virtio.c
index e40fa12..82bf3dd 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -517,10 +517,11 @@ void virtio_update_irq(VirtIODevice *vdev)
void virtio_set_status(VirtIODevice *vdev, uint8_t val)
{
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
trace_virtio_set_status(vdev, val);
- if (vdev->set_status) {
- vdev->set_status(vdev, val);
+ if (k->set_status) {
+ k->set_status(vdev, val);
}
vdev->status = val;
}
@@ -528,12 +529,14 @@ void virtio_set_status(VirtIODevice *vdev, uint8_t val)
void virtio_reset(void *opaque)
{
VirtIODevice *vdev = opaque;
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
int i;
virtio_set_status(vdev, 0);
- if (vdev->reset)
- vdev->reset(vdev);
+ if (k->reset) {
+ k->reset(vdev);
+ }
vdev->guest_features = 0;
vdev->queue_sel = 0;
@@ -557,9 +560,10 @@ void virtio_reset(void *opaque)
uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
{
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint8_t val;
- vdev->get_config(vdev, vdev->config);
+ k->get_config(vdev, vdev->config);
if (addr > (vdev->config_len - sizeof(val)))
return (uint32_t)-1;
@@ -570,9 +574,10 @@ uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
{
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint16_t val;
- vdev->get_config(vdev, vdev->config);
+ k->get_config(vdev, vdev->config);
if (addr > (vdev->config_len - sizeof(val)))
return (uint32_t)-1;
@@ -583,9 +588,10 @@ uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
{
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint32_t val;
- vdev->get_config(vdev, vdev->config);
+ k->get_config(vdev, vdev->config);
if (addr > (vdev->config_len - sizeof(val)))
return (uint32_t)-1;
@@ -596,6 +602,7 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
{
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint8_t val = data;
if (addr > (vdev->config_len - sizeof(val)))
@@ -603,12 +610,13 @@ void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
stb_p(vdev->config + addr, val);
- if (vdev->set_config)
- vdev->set_config(vdev, vdev->config);
+ if (k->set_config)
+ k->set_config(vdev, vdev->config);
}
void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
{
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint16_t val = data;
if (addr > (vdev->config_len - sizeof(val)))
@@ -616,12 +624,13 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
stw_p(vdev->config + addr, val);
- if (vdev->set_config)
- vdev->set_config(vdev, vdev->config);
+ if (k->set_config)
+ k->set_config(vdev, vdev->config);
}
void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
{
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint32_t val = data;
if (addr > (vdev->config_len - sizeof(val)))
@@ -629,8 +638,9 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
stl_p(vdev->config + addr, val);
- if (vdev->set_config)
- vdev->set_config(vdev, vdev->config);
+ if (k->set_config) {
+ k->set_config(vdev, vdev->config);
+ }
}
void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
@@ -799,13 +809,14 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
int virtio_set_features(VirtIODevice *vdev, uint32_t val)
{
+ VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint32_t supported_features =
vdev->binding->get_features(vdev->binding_opaque);
bool bad = (val & ~supported_features) != 0;
val &= supported_features;
- if (vdev->set_features) {
- vdev->set_features(vdev, val);
+ if (k->set_features) {
+ k->set_features(vdev, val);
}
vdev->guest_features = val;
return bad ? -1 : 0;
diff --git a/hw/virtio.h b/hw/virtio.h
index 98596a9..857fd78 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -128,18 +128,6 @@ struct VirtIODevice
void *config;
uint16_t config_vector;
int nvectors;
- /*
- * Will be removed ( at the end of the series ) as we have it in
- * VirtioDeviceClass.
- */
- uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
- uint32_t (*bad_features)(VirtIODevice *vdev);
- void (*set_features)(VirtIODevice *vdev, uint32_t val);
- void (*get_config)(VirtIODevice *vdev, uint8_t *config);
- void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
- void (*reset)(VirtIODevice *vdev);
- void (*set_status)(VirtIODevice *vdev, uint8_t val);
- /***/
VirtQueue *vq;
const VirtIOBindings *binding;
void *binding_opaque;
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 13/15] virtio : Remove the function pointer.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 13/15] virtio : Remove the function pointer fred.konrad
@ 2012-12-19 19:50 ` Blue Swirl
2012-12-20 8:02 ` KONRAD Frédéric
0 siblings, 1 reply; 35+ messages in thread
From: Blue Swirl @ 2012-12-19 19:50 UTC (permalink / raw)
To: fred.konrad
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, qemu-devel,
agraf, stefanha, cornelia.huck, afaerber
On Wed, Dec 19, 2012 at 9:53 AM, <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> This remove the function pointer in VirtIODevice, and use only
> VirtioDeviceClass function pointer. It should be applied after all
> the device have been refactored.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/virtio-blk.c | 5 -----
> hw/virtio-pci.c | 2 +-
> hw/virtio.c | 41 ++++++++++++++++++++++++++---------------
> hw/virtio.h | 12 ------------
> 4 files changed, 27 insertions(+), 33 deletions(-)
>
> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index 65932fd..fbb829e 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -628,11 +628,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
> virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
> sizeof(struct virtio_blk_config));
>
> - vdev->get_config = virtio_blk_update_config;
> - vdev->set_config = virtio_blk_set_config;
> - vdev->get_features = virtio_blk_get_features;
> - vdev->set_status = virtio_blk_set_status;
> - vdev->reset = virtio_blk_reset;
> s->bs = blk->conf.bs;
> s->conf = &blk->conf;
> virtio_blk_set_conf(qdev, blk);
> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
> index e3a8276..cdc3473 100644
> --- a/hw/virtio-pci.c
> +++ b/hw/virtio-pci.c
> @@ -262,7 +262,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
> case VIRTIO_PCI_GUEST_FEATURES:
> /* Guest does not negotiate properly? We have to assume nothing. */
> if (val & (1 << VIRTIO_F_BAD_FEATURE)) {
> - val = vdev->bad_features ? vdev->bad_features(vdev) : 0;
> + val = get_virtio_device_bad_features(proxy->bus);
> }
> virtio_set_features(vdev, val);
> break;
> diff --git a/hw/virtio.c b/hw/virtio.c
> index e40fa12..82bf3dd 100644
> --- a/hw/virtio.c
> +++ b/hw/virtio.c
> @@ -517,10 +517,11 @@ void virtio_update_irq(VirtIODevice *vdev)
>
> void virtio_set_status(VirtIODevice *vdev, uint8_t val)
> {
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> trace_virtio_set_status(vdev, val);
>
> - if (vdev->set_status) {
> - vdev->set_status(vdev, val);
> + if (k->set_status) {
> + k->set_status(vdev, val);
> }
> vdev->status = val;
> }
> @@ -528,12 +529,14 @@ void virtio_set_status(VirtIODevice *vdev, uint8_t val)
> void virtio_reset(void *opaque)
> {
> VirtIODevice *vdev = opaque;
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> int i;
>
> virtio_set_status(vdev, 0);
>
> - if (vdev->reset)
> - vdev->reset(vdev);
> + if (k->reset) {
> + k->reset(vdev);
> + }
>
> vdev->guest_features = 0;
> vdev->queue_sel = 0;
> @@ -557,9 +560,10 @@ void virtio_reset(void *opaque)
>
> uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
> {
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> uint8_t val;
>
> - vdev->get_config(vdev, vdev->config);
> + k->get_config(vdev, vdev->config);
>
> if (addr > (vdev->config_len - sizeof(val)))
> return (uint32_t)-1;
> @@ -570,9 +574,10 @@ uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
>
> uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
> {
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> uint16_t val;
>
> - vdev->get_config(vdev, vdev->config);
> + k->get_config(vdev, vdev->config);
>
> if (addr > (vdev->config_len - sizeof(val)))
> return (uint32_t)-1;
> @@ -583,9 +588,10 @@ uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
>
> uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
> {
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> uint32_t val;
>
> - vdev->get_config(vdev, vdev->config);
> + k->get_config(vdev, vdev->config);
>
> if (addr > (vdev->config_len - sizeof(val)))
> return (uint32_t)-1;
> @@ -596,6 +602,7 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
>
> void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
> {
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> uint8_t val = data;
>
> if (addr > (vdev->config_len - sizeof(val)))
> @@ -603,12 +610,13 @@ void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>
> stb_p(vdev->config + addr, val);
>
> - if (vdev->set_config)
> - vdev->set_config(vdev, vdev->config);
> + if (k->set_config)
Missing braces, please use checkpatch.pl.
> + k->set_config(vdev, vdev->config);
> }
>
> void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
> {
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> uint16_t val = data;
>
> if (addr > (vdev->config_len - sizeof(val)))
> @@ -616,12 +624,13 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>
> stw_p(vdev->config + addr, val);
>
> - if (vdev->set_config)
> - vdev->set_config(vdev, vdev->config);
> + if (k->set_config)
Ditto.
> + k->set_config(vdev, vdev->config);
> }
>
> void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
> {
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> uint32_t val = data;
>
> if (addr > (vdev->config_len - sizeof(val)))
> @@ -629,8 +638,9 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>
> stl_p(vdev->config + addr, val);
>
> - if (vdev->set_config)
> - vdev->set_config(vdev, vdev->config);
> + if (k->set_config) {
> + k->set_config(vdev, vdev->config);
> + }
> }
>
> void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
> @@ -799,13 +809,14 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
>
> int virtio_set_features(VirtIODevice *vdev, uint32_t val)
> {
> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> uint32_t supported_features =
> vdev->binding->get_features(vdev->binding_opaque);
> bool bad = (val & ~supported_features) != 0;
>
> val &= supported_features;
> - if (vdev->set_features) {
> - vdev->set_features(vdev, val);
> + if (k->set_features) {
> + k->set_features(vdev, val);
> }
> vdev->guest_features = val;
> return bad ? -1 : 0;
> diff --git a/hw/virtio.h b/hw/virtio.h
> index 98596a9..857fd78 100644
> --- a/hw/virtio.h
> +++ b/hw/virtio.h
> @@ -128,18 +128,6 @@ struct VirtIODevice
> void *config;
> uint16_t config_vector;
> int nvectors;
> - /*
> - * Will be removed ( at the end of the series ) as we have it in
> - * VirtioDeviceClass.
> - */
> - uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
> - uint32_t (*bad_features)(VirtIODevice *vdev);
> - void (*set_features)(VirtIODevice *vdev, uint32_t val);
> - void (*get_config)(VirtIODevice *vdev, uint8_t *config);
> - void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
> - void (*reset)(VirtIODevice *vdev);
> - void (*set_status)(VirtIODevice *vdev, uint8_t val);
> - /***/
> VirtQueue *vq;
> const VirtIOBindings *binding;
> void *binding_opaque;
> --
> 1.7.11.7
>
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 13/15] virtio : Remove the function pointer.
2012-12-19 19:50 ` Blue Swirl
@ 2012-12-20 8:02 ` KONRAD Frédéric
0 siblings, 0 replies; 35+ messages in thread
From: KONRAD Frédéric @ 2012-12-20 8:02 UTC (permalink / raw)
To: Blue Swirl
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, qemu-devel,
agraf, stefanha, cornelia.huck, afaerber
On 19/12/2012 20:50, Blue Swirl wrote:
> On Wed, Dec 19, 2012 at 9:53 AM, <fred.konrad@greensocs.com> wrote:
>> From: KONRAD Frederic <fred.konrad@greensocs.com>
>>
>> This remove the function pointer in VirtIODevice, and use only
>> VirtioDeviceClass function pointer. It should be applied after all
>> the device have been refactored.
>>
>> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
>> ---
>> hw/virtio-blk.c | 5 -----
>> hw/virtio-pci.c | 2 +-
>> hw/virtio.c | 41 ++++++++++++++++++++++++++---------------
>> hw/virtio.h | 12 ------------
>> 4 files changed, 27 insertions(+), 33 deletions(-)
>>
>> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
>> index 65932fd..fbb829e 100644
>> --- a/hw/virtio-blk.c
>> +++ b/hw/virtio-blk.c
>> @@ -628,11 +628,6 @@ static int virtio_blk_device_init(VirtIODevice *vdev)
>> virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
>> sizeof(struct virtio_blk_config));
>>
>> - vdev->get_config = virtio_blk_update_config;
>> - vdev->set_config = virtio_blk_set_config;
>> - vdev->get_features = virtio_blk_get_features;
>> - vdev->set_status = virtio_blk_set_status;
>> - vdev->reset = virtio_blk_reset;
>> s->bs = blk->conf.bs;
>> s->conf = &blk->conf;
>> virtio_blk_set_conf(qdev, blk);
>> diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c
>> index e3a8276..cdc3473 100644
>> --- a/hw/virtio-pci.c
>> +++ b/hw/virtio-pci.c
>> @@ -262,7 +262,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val)
>> case VIRTIO_PCI_GUEST_FEATURES:
>> /* Guest does not negotiate properly? We have to assume nothing. */
>> if (val & (1 << VIRTIO_F_BAD_FEATURE)) {
>> - val = vdev->bad_features ? vdev->bad_features(vdev) : 0;
>> + val = get_virtio_device_bad_features(proxy->bus);
>> }
>> virtio_set_features(vdev, val);
>> break;
>> diff --git a/hw/virtio.c b/hw/virtio.c
>> index e40fa12..82bf3dd 100644
>> --- a/hw/virtio.c
>> +++ b/hw/virtio.c
>> @@ -517,10 +517,11 @@ void virtio_update_irq(VirtIODevice *vdev)
>>
>> void virtio_set_status(VirtIODevice *vdev, uint8_t val)
>> {
>> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>> trace_virtio_set_status(vdev, val);
>>
>> - if (vdev->set_status) {
>> - vdev->set_status(vdev, val);
>> + if (k->set_status) {
>> + k->set_status(vdev, val);
>> }
>> vdev->status = val;
>> }
>> @@ -528,12 +529,14 @@ void virtio_set_status(VirtIODevice *vdev, uint8_t val)
>> void virtio_reset(void *opaque)
>> {
>> VirtIODevice *vdev = opaque;
>> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>> int i;
>>
>> virtio_set_status(vdev, 0);
>>
>> - if (vdev->reset)
>> - vdev->reset(vdev);
>> + if (k->reset) {
>> + k->reset(vdev);
>> + }
>>
>> vdev->guest_features = 0;
>> vdev->queue_sel = 0;
>> @@ -557,9 +560,10 @@ void virtio_reset(void *opaque)
>>
>> uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
>> {
>> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>> uint8_t val;
>>
>> - vdev->get_config(vdev, vdev->config);
>> + k->get_config(vdev, vdev->config);
>>
>> if (addr > (vdev->config_len - sizeof(val)))
>> return (uint32_t)-1;
>> @@ -570,9 +574,10 @@ uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr)
>>
>> uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
>> {
>> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>> uint16_t val;
>>
>> - vdev->get_config(vdev, vdev->config);
>> + k->get_config(vdev, vdev->config);
>>
>> if (addr > (vdev->config_len - sizeof(val)))
>> return (uint32_t)-1;
>> @@ -583,9 +588,10 @@ uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr)
>>
>> uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
>> {
>> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>> uint32_t val;
>>
>> - vdev->get_config(vdev, vdev->config);
>> + k->get_config(vdev, vdev->config);
>>
>> if (addr > (vdev->config_len - sizeof(val)))
>> return (uint32_t)-1;
>> @@ -596,6 +602,7 @@ uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr)
>>
>> void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>> {
>> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>> uint8_t val = data;
>>
>> if (addr > (vdev->config_len - sizeof(val)))
>> @@ -603,12 +610,13 @@ void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>>
>> stb_p(vdev->config + addr, val);
>>
>> - if (vdev->set_config)
>> - vdev->set_config(vdev, vdev->config);
>> + if (k->set_config)
> Missing braces, please use checkpatch.pl.
I don't understand, I used checkpatch.pl before submitting but it didn't
find it.
>
>> + k->set_config(vdev, vdev->config);
>> }
>>
>> void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>> {
>> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>> uint16_t val = data;
>>
>> if (addr > (vdev->config_len - sizeof(val)))
>> @@ -616,12 +624,13 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>>
>> stw_p(vdev->config + addr, val);
>>
>> - if (vdev->set_config)
>> - vdev->set_config(vdev, vdev->config);
>> + if (k->set_config)
> Ditto.
>
>> + k->set_config(vdev, vdev->config);
>> }
>>
>> void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>> {
>> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>> uint32_t val = data;
>>
>> if (addr > (vdev->config_len - sizeof(val)))
>> @@ -629,8 +638,9 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data)
>>
>> stl_p(vdev->config + addr, val);
>>
>> - if (vdev->set_config)
>> - vdev->set_config(vdev, vdev->config);
>> + if (k->set_config) {
>> + k->set_config(vdev, vdev->config);
>> + }
But it found this one, that's why I added brace here.
>> }
>>
>> void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr)
>> @@ -799,13 +809,14 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
>>
>> int virtio_set_features(VirtIODevice *vdev, uint32_t val)
>> {
>> + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
>> uint32_t supported_features =
>> vdev->binding->get_features(vdev->binding_opaque);
>> bool bad = (val & ~supported_features) != 0;
>>
>> val &= supported_features;
>> - if (vdev->set_features) {
>> - vdev->set_features(vdev, val);
>> + if (k->set_features) {
>> + k->set_features(vdev, val);
>> }
>> vdev->guest_features = val;
>> return bad ? -1 : 0;
>> diff --git a/hw/virtio.h b/hw/virtio.h
>> index 98596a9..857fd78 100644
>> --- a/hw/virtio.h
>> +++ b/hw/virtio.h
>> @@ -128,18 +128,6 @@ struct VirtIODevice
>> void *config;
>> uint16_t config_vector;
>> int nvectors;
>> - /*
>> - * Will be removed ( at the end of the series ) as we have it in
>> - * VirtioDeviceClass.
>> - */
>> - uint32_t (*get_features)(VirtIODevice *vdev, uint32_t requested_features);
>> - uint32_t (*bad_features)(VirtIODevice *vdev);
>> - void (*set_features)(VirtIODevice *vdev, uint32_t val);
>> - void (*get_config)(VirtIODevice *vdev, uint8_t *config);
>> - void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
>> - void (*reset)(VirtIODevice *vdev);
>> - void (*set_status)(VirtIODevice *vdev, uint8_t val);
>> - /***/
>> VirtQueue *vq;
>> const VirtIOBindings *binding;
>> void *binding_opaque;
>> --
>> 1.7.11.7
>>
>>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 14/15] virtio : Remove VirtIOBindings.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (12 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 13/15] virtio : Remove the function pointer fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
2012-12-19 19:54 ` Blue Swirl
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 15/15] virtio : cleanup : init and exit function fred.konrad
14 siblings, 1 reply; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
This remove VirtIOBindings and use VirtioBusClass instead. It should be applied
when all the device have been refactored.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio-bus.c | 20 --------------------
hw/virtio-bus.h | 6 ------
hw/virtio.c | 52 +++++++++++++++++++++++++++++++---------------------
hw/virtio.h | 19 -------------------
4 files changed, 31 insertions(+), 66 deletions(-)
diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
index 7a3d06e..6da587d 100644
--- a/hw/virtio-bus.c
+++ b/hw/virtio-bus.c
@@ -51,26 +51,6 @@ int virtio_bus_plug_device(VirtIODevice *vdev)
if (klass->device_plugged != NULL) {
klass->device_plugged(qbus->parent);
}
-
- /*
- * The lines below will disappear when we drop VirtIOBindings, at the end
- * of the serie.
- */
- bus->bindings.notify = klass->notify;
- bus->bindings.save_config = klass->save_config;
- bus->bindings.save_queue = klass->save_queue;
- bus->bindings.load_config = klass->load_config;
- bus->bindings.load_queue = klass->load_queue;
- bus->bindings.load_done = klass->load_done;
- bus->bindings.get_features = klass->get_features;
- bus->bindings.query_guest_notifiers = klass->query_guest_notifiers;
- bus->bindings.set_guest_notifiers = klass->set_guest_notifiers;
- bus->bindings.set_host_notifier = klass->set_host_notifier;
- bus->bindings.vmstate_change = klass->vmstate_change;
- virtio_bind_device(bus->vdev, &(bus->bindings), qbus->parent);
- /*
- */
-
return 0;
}
diff --git a/hw/virtio-bus.h b/hw/virtio-bus.h
index a2e2012..a5e2a87 100644
--- a/hw/virtio-bus.h
+++ b/hw/virtio-bus.h
@@ -70,12 +70,6 @@ struct VirtioBusState {
* Only one VirtIODevice can be plugged on the bus.
*/
VirtIODevice *vdev;
- /*
- * This will be removed at the end of the serie.
- */
- VirtIOBindings bindings;
- /*
- */
};
int virtio_bus_plug_device(VirtIODevice *vdev);
diff --git a/hw/virtio.c b/hw/virtio.c
index 82bf3dd..d124ca0 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -505,8 +505,12 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
/* virtio device */
static void virtio_notify_vector(VirtIODevice *vdev, uint16_t vector)
{
- if (vdev->binding->notify) {
- vdev->binding->notify(vdev->binding_opaque, vector);
+ BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+ VirtioBusState *vbus = VIRTIO_BUS(qbus);
+ VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
+
+ if (k->notify) {
+ k->notify(qbus->parent, vector);
}
}
@@ -776,10 +780,14 @@ void virtio_notify_config(VirtIODevice *vdev)
void virtio_save(VirtIODevice *vdev, QEMUFile *f)
{
+ BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+ VirtioBusState *vbus = VIRTIO_BUS(qbus);
+ VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
int i;
- if (vdev->binding->save_config)
- vdev->binding->save_config(vdev->binding_opaque, f);
+ if (k->save_config) {
+ k->save_config(qbus->parent, f);
+ }
qemu_put_8s(f, &vdev->status);
qemu_put_8s(f, &vdev->isr);
@@ -802,16 +810,19 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
qemu_put_be32(f, vdev->vq[i].vring.num);
qemu_put_be64(f, vdev->vq[i].pa);
qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
- if (vdev->binding->save_queue)
- vdev->binding->save_queue(vdev->binding_opaque, i, f);
+ if (k->save_queue)
+ k->save_queue(qbus->parent, i, f);
}
}
int virtio_set_features(VirtIODevice *vdev, uint32_t val)
{
+ BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+ VirtioBusState *vbus = VIRTIO_BUS(qbus);
+ VirtioBusClass *vbusk = VIRTIO_BUS_GET_CLASS(vbus);
VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
uint32_t supported_features =
- vdev->binding->get_features(vdev->binding_opaque);
+ vbusk->get_features(qbus->parent);
bool bad = (val & ~supported_features) != 0;
val &= supported_features;
@@ -827,9 +838,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
int num, i, ret;
uint32_t features;
uint32_t supported_features;
+ BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+ VirtioBusState *vbus = VIRTIO_BUS(qbus);
+ VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
- if (vdev->binding->load_config) {
- ret = vdev->binding->load_config(vdev->binding_opaque, f);
+ if (k->load_config) {
+ ret = k->load_config(qbus->parent, f);
if (ret)
return ret;
}
@@ -840,7 +854,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
qemu_get_be32s(f, &features);
if (virtio_set_features(vdev, features) < 0) {
- supported_features = vdev->binding->get_features(vdev->binding_opaque);
+ supported_features = k->get_features(qbus->parent);
error_report("Features 0x%x unsupported. Allowed features: 0x%x",
features, supported_features);
return -1;
@@ -876,8 +890,8 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
i, vdev->vq[i].last_avail_idx);
return -1;
}
- if (vdev->binding->load_queue) {
- ret = vdev->binding->load_queue(vdev->binding_opaque, i, f);
+ if (k->load_queue) {
+ ret = k->load_queue(qbus->parent, i, f);
if (ret)
return ret;
}
@@ -903,6 +917,9 @@ void virtio_cleanup(VirtIODevice *vdev)
static void virtio_vmstate_change(void *opaque, int running, RunState state)
{
VirtIODevice *vdev = opaque;
+ BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
+ VirtioBusState *vbus = VIRTIO_BUS(qbus);
+ VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK);
vdev->vm_running = running;
@@ -910,8 +927,8 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
virtio_set_status(vdev, vdev->status);
}
- if (vdev->binding->vmstate_change) {
- vdev->binding->vmstate_change(vdev->binding_opaque, backend_run);
+ if (k->vmstate_change) {
+ k->vmstate_change(qbus->parent, backend_run);
}
if (!backend_run) {
@@ -955,13 +972,6 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
return vdev;
}
-void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
- void *opaque)
-{
- vdev->binding = binding;
- vdev->binding_opaque = opaque;
-}
-
hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n)
{
return vdev->vq[n].vring.desc;
diff --git a/hw/virtio.h b/hw/virtio.h
index 857fd78..82726a3 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -90,20 +90,6 @@ typedef struct VirtQueueElement
struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
} VirtQueueElement;
-typedef struct {
- void (*notify)(void * opaque, uint16_t vector);
- void (*save_config)(void * opaque, QEMUFile *f);
- void (*save_queue)(void * opaque, int n, QEMUFile *f);
- int (*load_config)(void * opaque, QEMUFile *f);
- int (*load_queue)(void * opaque, int n, QEMUFile *f);
- int (*load_done)(void * opaque, QEMUFile *f);
- unsigned (*get_features)(void * opaque);
- bool (*query_guest_notifiers)(void * opaque);
- int (*set_guest_notifiers)(void * opaque, bool assigned);
- int (*set_host_notifier)(void * opaque, int n, bool assigned);
- void (*vmstate_change)(void * opaque, bool running);
-} VirtIOBindings;
-
#define VIRTIO_PCI_QUEUE_MAX 64
#define VIRTIO_NO_VECTOR 0xffff
@@ -129,8 +115,6 @@ struct VirtIODevice
uint16_t config_vector;
int nvectors;
VirtQueue *vq;
- const VirtIOBindings *binding;
- void *binding_opaque;
uint16_t device_id;
bool vm_running;
VMChangeStateEntry *vmstate;
@@ -209,9 +193,6 @@ void virtio_reset(void *opaque);
void virtio_update_irq(VirtIODevice *vdev);
int virtio_set_features(VirtIODevice *vdev, uint32_t val);
-void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
- void *opaque);
-
/* Base devices. */
typedef struct VirtIOBlkConf VirtIOBlkConf;
VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread
* Re: [Qemu-devel] [RFC PATCH V8 14/15] virtio : Remove VirtIOBindings.
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 14/15] virtio : Remove VirtIOBindings fred.konrad
@ 2012-12-19 19:54 ` Blue Swirl
0 siblings, 0 replies; 35+ messages in thread
From: Blue Swirl @ 2012-12-19 19:54 UTC (permalink / raw)
To: fred.konrad
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, qemu-devel,
agraf, stefanha, cornelia.huck, afaerber
On Wed, Dec 19, 2012 at 9:53 AM, <fred.konrad@greensocs.com> wrote:
> From: KONRAD Frederic <fred.konrad@greensocs.com>
>
> This remove VirtIOBindings and use VirtioBusClass instead. It should be applied
> when all the device have been refactored.
>
> Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
> ---
> hw/virtio-bus.c | 20 --------------------
> hw/virtio-bus.h | 6 ------
> hw/virtio.c | 52 +++++++++++++++++++++++++++++++---------------------
> hw/virtio.h | 19 -------------------
> 4 files changed, 31 insertions(+), 66 deletions(-)
>
> diff --git a/hw/virtio-bus.c b/hw/virtio-bus.c
> index 7a3d06e..6da587d 100644
> --- a/hw/virtio-bus.c
> +++ b/hw/virtio-bus.c
> @@ -51,26 +51,6 @@ int virtio_bus_plug_device(VirtIODevice *vdev)
> if (klass->device_plugged != NULL) {
> klass->device_plugged(qbus->parent);
> }
> -
> - /*
> - * The lines below will disappear when we drop VirtIOBindings, at the end
> - * of the serie.
> - */
> - bus->bindings.notify = klass->notify;
> - bus->bindings.save_config = klass->save_config;
> - bus->bindings.save_queue = klass->save_queue;
> - bus->bindings.load_config = klass->load_config;
> - bus->bindings.load_queue = klass->load_queue;
> - bus->bindings.load_done = klass->load_done;
> - bus->bindings.get_features = klass->get_features;
> - bus->bindings.query_guest_notifiers = klass->query_guest_notifiers;
> - bus->bindings.set_guest_notifiers = klass->set_guest_notifiers;
> - bus->bindings.set_host_notifier = klass->set_host_notifier;
> - bus->bindings.vmstate_change = klass->vmstate_change;
> - virtio_bind_device(bus->vdev, &(bus->bindings), qbus->parent);
> - /*
> - */
> -
> return 0;
> }
>
> diff --git a/hw/virtio-bus.h b/hw/virtio-bus.h
> index a2e2012..a5e2a87 100644
> --- a/hw/virtio-bus.h
> +++ b/hw/virtio-bus.h
> @@ -70,12 +70,6 @@ struct VirtioBusState {
> * Only one VirtIODevice can be plugged on the bus.
> */
> VirtIODevice *vdev;
> - /*
> - * This will be removed at the end of the serie.
> - */
> - VirtIOBindings bindings;
> - /*
> - */
> };
>
> int virtio_bus_plug_device(VirtIODevice *vdev);
> diff --git a/hw/virtio.c b/hw/virtio.c
> index 82bf3dd..d124ca0 100644
> --- a/hw/virtio.c
> +++ b/hw/virtio.c
> @@ -505,8 +505,12 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
> /* virtio device */
> static void virtio_notify_vector(VirtIODevice *vdev, uint16_t vector)
> {
> - if (vdev->binding->notify) {
> - vdev->binding->notify(vdev->binding_opaque, vector);
> + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
> + VirtioBusState *vbus = VIRTIO_BUS(qbus);
> + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
> +
> + if (k->notify) {
> + k->notify(qbus->parent, vector);
> }
> }
>
> @@ -776,10 +780,14 @@ void virtio_notify_config(VirtIODevice *vdev)
>
> void virtio_save(VirtIODevice *vdev, QEMUFile *f)
> {
> + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
> + VirtioBusState *vbus = VIRTIO_BUS(qbus);
> + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
> int i;
>
> - if (vdev->binding->save_config)
> - vdev->binding->save_config(vdev->binding_opaque, f);
> + if (k->save_config) {
> + k->save_config(qbus->parent, f);
> + }
>
> qemu_put_8s(f, &vdev->status);
> qemu_put_8s(f, &vdev->isr);
> @@ -802,16 +810,19 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f)
> qemu_put_be32(f, vdev->vq[i].vring.num);
> qemu_put_be64(f, vdev->vq[i].pa);
> qemu_put_be16s(f, &vdev->vq[i].last_avail_idx);
> - if (vdev->binding->save_queue)
> - vdev->binding->save_queue(vdev->binding_opaque, i, f);
> + if (k->save_queue)
Please add braces.
> + k->save_queue(qbus->parent, i, f);
> }
> }
>
> int virtio_set_features(VirtIODevice *vdev, uint32_t val)
> {
> + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
> + VirtioBusState *vbus = VIRTIO_BUS(qbus);
> + VirtioBusClass *vbusk = VIRTIO_BUS_GET_CLASS(vbus);
> VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev);
> uint32_t supported_features =
> - vdev->binding->get_features(vdev->binding_opaque);
> + vbusk->get_features(qbus->parent);
> bool bad = (val & ~supported_features) != 0;
>
> val &= supported_features;
> @@ -827,9 +838,12 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
> int num, i, ret;
> uint32_t features;
> uint32_t supported_features;
> + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
> + VirtioBusState *vbus = VIRTIO_BUS(qbus);
> + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
>
> - if (vdev->binding->load_config) {
> - ret = vdev->binding->load_config(vdev->binding_opaque, f);
> + if (k->load_config) {
> + ret = k->load_config(qbus->parent, f);
> if (ret)
> return ret;
> }
> @@ -840,7 +854,7 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
> qemu_get_be32s(f, &features);
>
> if (virtio_set_features(vdev, features) < 0) {
> - supported_features = vdev->binding->get_features(vdev->binding_opaque);
> + supported_features = k->get_features(qbus->parent);
> error_report("Features 0x%x unsupported. Allowed features: 0x%x",
> features, supported_features);
> return -1;
> @@ -876,8 +890,8 @@ int virtio_load(VirtIODevice *vdev, QEMUFile *f)
> i, vdev->vq[i].last_avail_idx);
> return -1;
> }
> - if (vdev->binding->load_queue) {
> - ret = vdev->binding->load_queue(vdev->binding_opaque, i, f);
> + if (k->load_queue) {
> + ret = k->load_queue(qbus->parent, i, f);
> if (ret)
> return ret;
> }
> @@ -903,6 +917,9 @@ void virtio_cleanup(VirtIODevice *vdev)
> static void virtio_vmstate_change(void *opaque, int running, RunState state)
> {
> VirtIODevice *vdev = opaque;
> + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev)));
> + VirtioBusState *vbus = VIRTIO_BUS(qbus);
> + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus);
> bool backend_run = running && (vdev->status & VIRTIO_CONFIG_S_DRIVER_OK);
> vdev->vm_running = running;
>
> @@ -910,8 +927,8 @@ static void virtio_vmstate_change(void *opaque, int running, RunState state)
> virtio_set_status(vdev, vdev->status);
> }
>
> - if (vdev->binding->vmstate_change) {
> - vdev->binding->vmstate_change(vdev->binding_opaque, backend_run);
> + if (k->vmstate_change) {
> + k->vmstate_change(qbus->parent, backend_run);
> }
>
> if (!backend_run) {
> @@ -955,13 +972,6 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
> return vdev;
> }
>
> -void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
> - void *opaque)
> -{
> - vdev->binding = binding;
> - vdev->binding_opaque = opaque;
> -}
> -
> hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n)
> {
> return vdev->vq[n].vring.desc;
> diff --git a/hw/virtio.h b/hw/virtio.h
> index 857fd78..82726a3 100644
> --- a/hw/virtio.h
> +++ b/hw/virtio.h
> @@ -90,20 +90,6 @@ typedef struct VirtQueueElement
> struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
> } VirtQueueElement;
>
> -typedef struct {
> - void (*notify)(void * opaque, uint16_t vector);
> - void (*save_config)(void * opaque, QEMUFile *f);
> - void (*save_queue)(void * opaque, int n, QEMUFile *f);
> - int (*load_config)(void * opaque, QEMUFile *f);
> - int (*load_queue)(void * opaque, int n, QEMUFile *f);
> - int (*load_done)(void * opaque, QEMUFile *f);
> - unsigned (*get_features)(void * opaque);
> - bool (*query_guest_notifiers)(void * opaque);
> - int (*set_guest_notifiers)(void * opaque, bool assigned);
> - int (*set_host_notifier)(void * opaque, int n, bool assigned);
> - void (*vmstate_change)(void * opaque, bool running);
> -} VirtIOBindings;
> -
> #define VIRTIO_PCI_QUEUE_MAX 64
>
> #define VIRTIO_NO_VECTOR 0xffff
> @@ -129,8 +115,6 @@ struct VirtIODevice
> uint16_t config_vector;
> int nvectors;
> VirtQueue *vq;
> - const VirtIOBindings *binding;
> - void *binding_opaque;
> uint16_t device_id;
> bool vm_running;
> VMChangeStateEntry *vmstate;
> @@ -209,9 +193,6 @@ void virtio_reset(void *opaque);
> void virtio_update_irq(VirtIODevice *vdev);
> int virtio_set_features(VirtIODevice *vdev, uint32_t val);
>
> -void virtio_bind_device(VirtIODevice *vdev, const VirtIOBindings *binding,
> - void *opaque);
> -
> /* Base devices. */
> typedef struct VirtIOBlkConf VirtIOBlkConf;
> VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk);
> --
> 1.7.11.7
>
>
^ permalink raw reply [flat|nested] 35+ messages in thread
* [Qemu-devel] [RFC PATCH V8 15/15] virtio : cleanup : init and exit function.
2012-12-19 9:53 [Qemu-devel] [RFC PATCH V8 00/15] Virtio refactoring fred.konrad
` (13 preceding siblings ...)
2012-12-19 9:53 ` [Qemu-devel] [RFC PATCH V8 14/15] virtio : Remove VirtIOBindings fred.konrad
@ 2012-12-19 9:53 ` fred.konrad
14 siblings, 0 replies; 35+ messages in thread
From: fred.konrad @ 2012-12-19 9:53 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, aliguori, e.voevodin, mark.burton, agraf,
stefanha, cornelia.huck, afaerber, fred.konrad
From: KONRAD Frederic <fred.konrad@greensocs.com>
Clean the init and the exit function. It should be applied when all the device
have been refactored.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
hw/virtio.c | 15 ---------------
hw/virtio.h | 4 ----
2 files changed, 19 deletions(-)
diff --git a/hw/virtio.c b/hw/virtio.c
index d124ca0..39cdebe 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -908,12 +908,6 @@ void virtio_common_cleanup(VirtIODevice *vdev)
g_free(vdev->vq);
}
-void virtio_cleanup(VirtIODevice *vdev)
-{
- virtio_common_cleanup(vdev);
- g_free(vdev);
-}
-
static void virtio_vmstate_change(void *opaque, int running, RunState state)
{
VirtIODevice *vdev = opaque;
@@ -963,15 +957,6 @@ void virtio_init(VirtIODevice *vdev, const char *name,
vdev);
}
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
- size_t config_size, size_t struct_size)
-{
- VirtIODevice *vdev;
- vdev = g_malloc0(struct_size);
- virtio_init(vdev, name, device_id, config_size);
- return vdev;
-}
-
hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n)
{
return vdev->vq[n].vring.desc;
diff --git a/hw/virtio.h b/hw/virtio.h
index 82726a3..de46098 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -162,8 +162,6 @@ void virtio_save(VirtIODevice *vdev, QEMUFile *f);
int virtio_load(VirtIODevice *vdev, QEMUFile *f);
-void virtio_cleanup(VirtIODevice *vdev);
-
void virtio_notify_config(VirtIODevice *vdev);
void virtio_queue_set_notification(VirtQueue *vq, int enable);
@@ -174,8 +172,6 @@ int virtio_queue_empty(VirtQueue *vq);
/* Host binding interface. */
-VirtIODevice *virtio_common_init(const char *name, uint16_t device_id,
- size_t config_size, size_t struct_size);
uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr);
uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr);
uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr);
--
1.7.11.7
^ permalink raw reply related [flat|nested] 35+ messages in thread