diff options
author | KONRAD Frederic <fred.konrad@greensocs.com> | 2013-01-15 00:08:02 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2013-01-21 13:23:12 -0600 |
commit | 8e05db9234050cb3f0ffb765608dd8b176334ae1 (patch) | |
tree | 416e9423918dc781faa542d02ab0cbbaa699f730 /hw/virtio.h | |
parent | ff8eca5536edd3f84bc87277e158e4db11dadf82 (diff) |
virtio-device: refactor virtio-device.
Create the virtio-device which is abstract. All the virtio-device can extend
this class. It also add some functions to virtio-bus.
Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/virtio.h')
-rw-r--r-- | hw/virtio.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/hw/virtio.h b/hw/virtio.h index b9f1873fd6..9cc7b85671 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; + /* + * 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 VirtIODevice VMChangeStateEntry *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 *)); |