On Wed, Dec 19, 2012 at 9:53 AM,  <fred.kon...@greensocs.com> wrote:
> From: KONRAD Frederic <fred.kon...@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.kon...@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
>
>

Reply via email to