Virtio-refactoring part1.
v3 cover Virtio-refactoring part1.
From: KONRAD Frederic <[email protected]>
This is the part 1/3 of the virtio-refactoring with some fixes.
It introduces virtio-bus, virtio-pci-bus, virtio-s390-bus, and creates virtio-pci, virtio-device.
You can clone that from here :git://git.greensocs.com/qemu_virtio.git virtio_v3_part1
Changes patch v2 -> v3:
* virtio-bus: change prefix: virtio_device_ -> virtio_bus_.
* virtio-bus: drop get/set nvectors functions.
* virtio-pci: use qbus_create_inplace instead of qbus_create.
* virtio-pci: abstracted.
* virtio-pci: remove the setting of PCI identifier in virtio_pci_device_plugged.
* virtio-s390: same as above.
Changes since patch v1:
* virtio-pci: Avoid code duplication (in switch/case).
* virtio-x-bus: Add the VirtioXBusClass.
* cut the series.
Changes since v9:
* Refactored all the remaining devices with the same way as virtio-blk.
* Moved the virtio device's structure in the header.
* Fixed the init with only one allocation.
* Fixed the indentation and code style errors.
* s390 device's are refactored the same way as pci one.
* Moved max_dev from BusState to BusClass.
Changes v8 -> v9:
* Modified virtio-bus.c function name. (virtio_device_ prefix.)
* Removed qdev_create(..) in virtio-blk-x, object_new
+ object_property_add_child used instead.
Changes v7 -> v8:
* Moved virtio-blk-pci PCI IDs to "Add the virtio-blk device.".
* virtio : Added virtio_device_init which init children and plug the device.
* virtio : Added virtio_common_cleanup in the same way as virtio_common_init.
* virtio-blk : Moved virtio_plug_device to virtio-device init.
* virtio-blk : Inline the virtio_blk_exit function in virtio_blk_device_exit and use virtio_common_cleanup.
* virtio-s390-bus : Added virtio-s390-bus.
* virtio-s390-device : Added a virtio-s390-bus.
* virtio-blk-s390 : Switched to the new API.
* virtio : removed function pointer.
* virtio : removed VirtinBindings.
* virtio : cleaned up init and exit function.
Changes v6 -> v7:
* virtio-bus : Added virtio-bus-reset.
* virtio-pci : Fixed virtio-pci-exit.
* virtio-pci : Added virtio-pci-rst.
* virtio-pci : Added VirtioPCIClass filled with an init function.
* virtio-blk : Added virtio_blk_set_conf.
* virtio-blk : QOM casts.
* virtio-blk-pci : Switched to the new API.
Changes v5 -> v6:
* Renamed virtio_common_init_ to virtio_init, modify virtio_common_init to allocate and call virtio_init. Drop the unused structure size parameters.
* Renamed init/exit callback in VirtioBusClass.
* Renamed virtio_blk_init virtio_blk_common_init.
* Modified virtio_blk_init to call virtio_blk_common_init.
Changes v4 -> v5:
* use ERROR_CLASS_GENERIC_ERROR in place of creating a new error type for the maximum device limitation. ( Peter )
* Removed bus_in_use function. We assume that the virtio-bus is not in use, when plugin in. ( Peter )
* Added virtio_bus_destroy_device().
* Implemented the exit function of virtio-pci.
* Implemented the init callback for virtio-pci ( must be modified, it still access vdev directly. ).
* Implemented the exit callback for virtio-pci.
* Started virtio-device refactoring.
* Started virtio-blk refactoring.
Changes v3 -> v4:
* Added virtio-bus.o in Makefile.objs ( accidentally dropped from v3 ).
* *const* TypeInfo in virtio-bus.
* Introduced virtio-pci-bus.
* Reintroduced virtio-pci.
* Introduced virtio-device.
* Started virtio-blk refactoring.
* Added an error type in qerror.h for the "bus full" error.
Changes v2 -> v3:
* Added VirtioBusClass.
* Renamed VirtioBus -> VirtioBusState.
* Renamed qbus -> parent_obj.
* Plug the device only in a non-full bus.
Changes v1 -> v2:
* All the little fix you suggest ( License, Debug printf, naming convention, ...)
* Added get_virtio_device_id(), and remove the pci_id* from the VirtioBus structure.
* Added virtio_bus_reset().
* Added cast macros VIRTIO_BUS.
* Added virtio_bus_plug_device.
* Replaced the old-style "bus->qbus" by BUS() macro.
KONRAD Frederic (7):
qdev: add a maximum device allowed field for the bus.
virtio-bus: introduce virtio-bus
virtio-device: refactor virtio-device.
virtio-pci-bus: introduce virtio-pci-bus.
virtio-pci: refactor virtio-pci device.
virtio-s390-bus: add virtio-s390-bus.
virtio-s390-device: create a virtio-s390-bus during init.
hw/Makefile.objs | 1 + hw/qdev-core.h | 2 + hw/qdev-monitor.c | 12 ++++ hw/s390-virtio-bus.c | 31 ++++++++++ hw/s390-virtio-bus.h | 18 ++++++ hw/virtio-bus.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-bus.h | 94 +++++++++++++++++++++++++++++ hw/virtio-pci.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-pci.h | 38 +++++++++++- hw/virtio.c | 70 ++++++++++++++++++---- hw/virtio.h | 30 ++++++++++ 11 files changed, 601 insertions(+), 14 deletions(-) create mode 100644 hw/virtio-bus.c create mode 100644 hw/virtio-bus.h
Signature · 1 line
1.7.11.7
PATCH v3 1/7 qdev: add a maximum device allowed field for the bus.
From: KONRAD Frederic <[email protected]>
Add a max_dev field to BusClass to specify the maximum amount of devices allowed on the bus (has no effect if max_dev=0)
--- hw/qdev-core.h | 2 ++ hw/qdev-monitor.c | 12 ++++++++++++ 2 files changed, 14 insertions(+)
hw/qdev-core.h +2 -0
@@ -87,6 +87,8 @@ struct BusClass {*/ char *(*get_fw_dev_path)(DeviceState *dev);int (*reset)(BusState *bus); +/* maximum devices allowed on the bus, 0: no limit. */ +int max_dev; }; typedef struct BusChild {
hw/qdev-monitor.c +12 -0
@@ -283,6 +283,7 @@ static DeviceState *qbus_find_dev(BusState *bus, char *elem)static BusState *qbus_find_recursive (BusState *bus,const char *name,const char *bus_typename) { +BusClass *bus_class =BUS_GET_CLASS (bus);BusChild *kid;BusState *child, *ret;int match =1 ;
@@ -293,6 +294,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_class->max_dev !=0 ) && (bus_class->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; }
Signature · 1 line
1.7.11.7
PATCH v3 2/7 virtio-bus: introduce virtio-bus
In reply to [email protected]From: KONRAD Frederic <[email protected]>
Introduce virtio-bus. Refactored transport device will create a bus which extends virtio-bus.
--- hw/Makefile.objs | 1 + hw/virtio-bus.c | 129 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-bus.h | 87 +++++++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+) create mode 100644 hw/virtio-bus.c create mode 100644 hw/virtio-bus.h
hw/Makefile.objs +1 -0
@@ -8,6 +8,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_bridge_dev.o common-obj-$(CONFIG_PCI) += ioh3420.o xio3130_upstream.o xio3130_downstream.o
hw/virtio-bus.c new file +129 -0
129 lines not on this page · raw message
hw/virtio-bus.h new file +87 -0
87 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH v3 3/7 virtio-device: refactor virtio-device.
In reply to [email protected]From: KONRAD Frederic <[email protected]>
Create the virtio-device which is abstract. All the virtio-device can extend this class. It also add some functions to virtio-bus.
--- hw/virtio-bus.c | 35 +++++++++++++++++++++++++++++ hw/virtio-bus.h | 7 ++++++ hw/virtio.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++---------- hw/virtio.h | 30 +++++++++++++++++++++++++ 4 files changed, 130 insertions(+), 12 deletions(-)
hw/virtio-bus.c +35 -0
@@ -113,6 +113,41 @@ size_t virtio_bus_get_vdev_config_len(VirtioBusState *bus)return bus->vdev->config_len; } +/* Get the features of the plugged device. */ +uint32_t virtio_bus_get_vdev_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 bad features of the plugged device. */ +uint32_t virtio_bus_get_vdev_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 ; + } +} + +/* Get config of the plugged device. */ +void virtio_bus_get_vdev_config (VirtioBusState *bus,uint8_t *config) +{ +VirtioDeviceClass *k; +assert (bus->vdev !=NULL ); + k =VIRTIO_DEVICE_GET_CLASS (bus->vdev); +if (k->get_config !=NULL ) { + k->get_config (bus->vdev, config); + } +} +static const TypeInfo virtio_bus_info = { .name =TYPE_VIRTIO_BUS , .parent =TYPE_BUS ,
hw/virtio-bus.h +7 -0
@@ -83,5 +83,12 @@ void virtio_bus_destroy_device(VirtioBusState *bus);uint16_t virtio_bus_get_vdev_id (VirtioBusState *bus);/* Get the config_len field of the plugged device. */ size_t virtio_bus_get_vdev_config_len (VirtioBusState *bus); +/* Get the features of the plugged device. */ +uint32_t virtio_bus_get_vdev_features (VirtioBusState *bus, +uint32_t requested_features); +/* Get bad features of the plugged device. */ +uint32_t virtio_bus_get_vdev_bad_features (VirtioBusState *bus); +/* Get config of the plugged device. */ +void virtio_bus_get_vdev_config (VirtioBusState *bus,uint8_t *config);#endif /* VIRTIO_BUS_H */
hw/virtio.c +58 -12
112 lines not on this page · raw message
hw/virtio.h +30 -0
@@ -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 VirtIODevicevoid *config;uint16_t config_vector;int nvectors; +/* +* Function pointers will be removed at the end of the series as they are 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);
@@ -147,6 +160,23 @@ struct VirtIODeviceVMChangeStateEntry *vmstate; }; +typedef struct VirtioDeviceClass { +/* 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 *));
Signature · 1 line
1.7.11.7
PATCH v3 4/7 virtio-pci-bus: introduce virtio-pci-bus.
In reply to [email protected]From: KONRAD Frederic <[email protected]>
Introduce virtio-pci-bus, which extends virtio-bus. It is used with virtio-pci transport device.
--- hw/virtio-pci.c | 37 +++++++++++++++++++++++++++++++++++++ hw/virtio-pci.h | 15 +++++++++++++++ 2 files changed, 52 insertions(+)
hw/virtio-pci.c +37 -0
@@ -31,6 +31,7 @@#include "sysemu/blockdev.h" #include "virtio-pci.h" #include "qemu/range.h" +#include "virtio-bus.h" /* from Linux's linux/virtio_pci.h */
@@ -1311,6 +1312,41 @@ static const TypeInfo virtio_scsi_info = { .class_init = virtio_scsi_class_init, }; +/* virtio-pci-bus */ + +void virtio_pci_bus_new (VirtioBusState *bus,VirtIOPCIProxy *dev) +{ +DeviceState *qdev =DEVICE (dev); +BusState *qbus; +qbus_create_inplace ((BusState *)bus,TYPE_VIRTIO_PCI_BUS , qdev,NULL ); + qbus =BUS (bus); + qbus->allow_hotplug =0 ; +} + +static void virtio_pci_bus_class_init (ObjectClass *klass,void *data) +{ +BusClass *bus_class =BUS_CLASS (klass); +VirtioBusClass *k =VIRTIO_BUS_CLASS (klass); + bus_class->max_dev =1 ; + 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 (VirtioPCIBusState), + .class_init = virtio_pci_bus_class_init, +}; +static void virtio_pci_register_types (void ) {type_register_static (&virtio_blk_info);
@@ -1319,6 +1355,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)
hw/virtio-pci.h +15 -0
@@ -21,6 +21,20 @@#include "virtio-rng.h" #include "virtio-serial.h" #include "virtio-scsi.h" +#include "virtio-bus.h" + +/* virtio-pci-bus */ + +typedef struct VirtioBusState VirtioPCIBusState ; +typedef struct VirtioBusClass VirtioPCIBusClass ; + +#define TYPE_VIRTIO_PCI_BUS "virtio-pci-bus" +#define VIRTIO_PCI_BUS (obj) \ + OBJECT_CHECK(VirtioPCIBusState, (obj), TYPE_VIRTIO_PCI_BUS) +#define VIRTIO_PCI_BUS_GET_CLASS (obj) \ + OBJECT_GET_CLASS(VirtioPCIBusClass, obj, TYPE_VIRTIO_PCI_BUS) +#define VIRTIO_PCI_BUS_CLASS (klass) \ + OBJECT_CLASS_CHECK(VirtioPCIBusClass, klass, TYPE_VIRTIO_PCI_BUS)/* Performance improves when virtqueue kick processing is decoupled from the * vcpu thread using ioeventfd for some devices. */
@@ -58,6 +72,7 @@ typedef struct {void virtio_init_pci (VirtIOPCIProxy *proxy,VirtIODevice *vdev);void virtio_pci_reset (DeviceState *d); +void virtio_pci_bus_new (VirtioBusState *bus,VirtIOPCIProxy *dev);/* Virtio ABI version, if we increment this, we break the guest driver. */ #define VIRTIO_PCI_ABI_VERSION 0
Signature · 1 line
1.7.11.7
PATCH v3 5/7 virtio-pci: refactor virtio-pci device.
In reply to [email protected]From: KONRAD Frederic <[email protected]>
Create the virtio-pci device which is abstract. This transport device will create a virtio-pci-bus, so one VirtIODevice can be connected.
--- hw/virtio-pci.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/virtio-pci.h | 23 ++++++++++- 2 files changed, 139 insertions(+), 2 deletions(-)
hw/virtio-pci.c +118 -0
@@ -1312,6 +1312,121 @@ static const TypeInfo virtio_scsi_info = { .class_init = virtio_scsi_class_init, }; +/* +* virtio-pci: This is the PCIDevice which has a virtio-pci-bus. +*/ + +/* This is called by virtio-bus just after the device is plugged. */ +static void virtio_pci_device_plugged (DeviceState *d) +{ +VirtIOPCIProxy *proxy =VIRTIO_PCI (d); +VirtioBusState *bus = &proxy->bus; +uint8_t *config; +uint32_t size; + + proxy->vdev = 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 ,virtio_bus_get_vdev_id (bus)); + config[PCI_INTERRUPT_PIN ] =1 ; + +if (proxy->nvectors && +msix_init_exclusive_bar (&proxy->pci_dev, proxy->nvectors,1 )) { + proxy->nvectors =0 ; + } + + proxy->pci_dev.config_write = virtio_write_config; + + size =VIRTIO_PCI_REGION_SIZE (&proxy->pci_dev) + +virtio_bus_get_vdev_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 =virtio_bus_get_vdev_features (bus, + proxy->host_features); +} + +/* This is called by virtio-bus just before the device is unplugged. */ +static void virtio_pci_device_unplug (DeviceState *d) +{ +VirtIOPCIProxy *dev =VIRTIO_PCI (d); +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); +virtio_pci_bus_new (&dev->bus, 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); +virtio_exit_pci (pci_dev); +} + +/* +* This will be renamed virtio_pci_reset at the end of the series. +* virtio_pci_reset is still in use at this moment. +*/ +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), + .abstract = true, +}; +/* virtio-pci-bus */ void virtio_pci_bus_new (VirtioBusState *bus,VirtIOPCIProxy *dev)
@@ -1338,6 +1453,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 = {
@@ -1356,6 +1473,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)
hw/virtio-pci.h +21 -2
@@ -23,6 +23,8 @@#include "virtio-scsi.h" #include "virtio-bus.h" +typedef struct VirtIOPCIProxy VirtIOPCIProxy ; +/* virtio-pci-bus */ typedef struct VirtioBusState VirtioPCIBusState ;
@@ -47,7 +49,23 @@ typedef struct {unsigned int users; } VirtIOIRQFD; -typedef struct { +/* +* virtio-pci: This is the PCIDevice which has 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;MemoryRegion bar;
@@ -68,7 +86,8 @@ typedef struct {bool ioeventfd_started;VirtIOIRQFD *vector_irqfd;int nvqs_with_notifiers; -} VirtIOPCIProxy; +VirtioBusState bus; +};void virtio_init_pci (VirtIOPCIProxy *proxy,VirtIODevice *vdev);void virtio_pci_reset (DeviceState *d);
Signature · 1 line
1.7.11.7
PATCH v3 6/7 virtio-s390-bus: add virtio-s390-bus.
In reply to [email protected]From: KONRAD Frederic <[email protected]>
This add the virtio-s390-bus which extends virtio-bus. So one VirtIODevice can be connected on this bus.
--- hw/s390-virtio-bus.c | 29 +++++++++++++++++++++++++++++ hw/s390-virtio-bus.h | 17 +++++++++++++++++ 2 files changed, 46 insertions(+)
hw/s390-virtio-bus.c +29 -0
@@ -32,6 +32,7 @@#include "sysemu/kvm.h" #include "hw/s390-virtio-bus.h" +#include "hw/virtio-bus.h" /* #define DEBUG_S390 */
@@ -569,8 +570,36 @@ static const TypeInfo s390_virtio_bridge_info = { .class_init = s390_virtio_bridge_class_init, }; +/* virtio-s390-bus */ + +void virtio_s390_bus_new (VirtioBusState *bus,VirtIOS390Device *dev) +{ +DeviceState *qdev =DEVICE (dev); +BusState *qbus; +qbus_create_inplace ((BusState *)bus,TYPE_VIRTIO_S390_BUS , qdev,NULL ); + qbus =BUS (bus); + qbus->allow_hotplug =0 ; +} + +static void virtio_s390_bus_class_init (ObjectClass *klass,void *data) +{ +VirtioBusClass *k =VIRTIO_BUS_CLASS (klass); +BusClass *bus_class =BUS_CLASS (klass); + bus_class->max_dev =1 ; + 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 (VirtioS390BusState), + .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);
hw/s390-virtio-bus.h +17 -0
@@ -24,6 +24,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 */
@@ -59,8 +60,24 @@#define S390_VIRTIO_BUS (obj) \ OBJECT_CHECK(VirtIOS390Bus, (obj), TYPE_S390_VIRTIO_BUS) +/* virtio-s390-bus */ + +typedef struct VirtioBusState VirtioS390BusState ; +typedef struct VirtioBusClass VirtioS390BusClass ; + +#define TYPE_VIRTIO_S390_BUS "virtio-s390-bus" +#define VIRTIO_S390_BUS (obj) \ + OBJECT_CHECK(VirtioS390BusState, (obj), TYPE_VIRTIO_S390_BUS) +#define VIRTIO_S390_BUS_GET_CLASS (obj) \ + OBJECT_GET_CLASS(VirtioS390BusClass, obj, TYPE_VIRTIO_S390_BUS) +#define VIRTIO_S390_BUS_CLASS (klass) \ + OBJECT_CLASS_CHECK(VirtioS390BusClass, klass, TYPE_VIRTIO_S390_BUS) + +typedef struct VirtIOS390Device VirtIOS390Device ; +void virtio_s390_bus_new (VirtioBusState *bus,VirtIOS390Device *dev); + typedef struct VirtIOS390DeviceClass { DeviceClass qdev; int (*init)(VirtIOS390Device *dev);
Signature · 1 line
1.7.11.7
PATCH v3 7/7 virtio-s390-device: create a virtio-s390-bus during init.
In reply to [email protected]From: KONRAD Frederic <[email protected]>
A virtio-s390-bus is created during the init. So one VirtIODevice can be connected on the virtio-s390-device through this bus.
--- hw/s390-virtio-bus.c | 2 ++ hw/s390-virtio-bus.h | 1 + 2 files changed, 3 insertions(+)
hw/s390-virtio-bus.c +2 -0
@@ -503,6 +503,8 @@ static int s390_virtio_busdev_init(DeviceState *dev)VirtIOS390Device *_dev = (VirtIOS390Device *)dev;VirtIOS390DeviceClass *_info =VIRTIO_S390_DEVICE_GET_CLASS (dev); +virtio_s390_bus_new (&_dev->bus, _dev); +return _info->init (_dev); }
hw/s390-virtio-bus.h +1 -0
@@ -96,6 +96,7 @@ struct VirtIOS390Device {virtio_net_conf net;VirtIOSCSIConf scsi;VirtIORNGConf rng; +VirtioBusState bus; }; typedef struct VirtIOS390Bus {
Signature · 1 line
1.7.11.7