diff options
author | Jason Wang <jasowang@redhat.com> | 2012-08-28 07:54:13 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2012-09-28 01:35:15 -0400 |
commit | 17bb6d40880d4178f5f8a75900ed8c9ff47d3fb2 (patch) | |
tree | f9888385b33c144f909eff14713a328dc72296f2 | |
parent | 7a23eb28fa645f1f0c2ec38274c11bc78c50c047 (diff) |
virtio-ring: move queue_index to vring_virtqueue
Instead of storing the queue index in transport-specific virtio structs,
this patch moves them to vring_virtqueue and introduces an helper to get
the value. This lets drivers simplify their management and tracing of
virtqueues.
Signed-off-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r-- | drivers/lguest/lguest_device.c | 2 | ||||
-rw-r--r-- | drivers/remoteproc/remoteproc_virtio.c | 2 | ||||
-rw-r--r-- | drivers/s390/kvm/kvm_virtio.c | 2 | ||||
-rw-r--r-- | drivers/virtio/virtio_mmio.c | 12 | ||||
-rw-r--r-- | drivers/virtio/virtio_pci.c | 13 | ||||
-rw-r--r-- | drivers/virtio/virtio_ring.c | 14 | ||||
-rw-r--r-- | include/linux/virtio.h | 2 | ||||
-rw-r--r-- | include/linux/virtio_ring.h | 3 |
8 files changed, 29 insertions, 21 deletions
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c index 9e8388efd88e..ccb7dfb028fa 100644 --- a/drivers/lguest/lguest_device.c +++ b/drivers/lguest/lguest_device.c | |||
@@ -296,7 +296,7 @@ static struct virtqueue *lg_find_vq(struct virtio_device *vdev, | |||
296 | * to 'true': the host just a(nother) SMP CPU, so we only need inter-cpu | 296 | * to 'true': the host just a(nother) SMP CPU, so we only need inter-cpu |
297 | * barriers. | 297 | * barriers. |
298 | */ | 298 | */ |
299 | vq = vring_new_virtqueue(lvq->config.num, LGUEST_VRING_ALIGN, vdev, | 299 | vq = vring_new_virtqueue(index, lvq->config.num, LGUEST_VRING_ALIGN, vdev, |
300 | true, lvq->pages, lg_notify, callback, name); | 300 | true, lvq->pages, lg_notify, callback, name); |
301 | if (!vq) { | 301 | if (!vq) { |
302 | err = -ENOMEM; | 302 | err = -ENOMEM; |
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c index 3541b4492f64..343c1941c123 100644 --- a/drivers/remoteproc/remoteproc_virtio.c +++ b/drivers/remoteproc/remoteproc_virtio.c | |||
@@ -103,7 +103,7 @@ static struct virtqueue *rp_find_vq(struct virtio_device *vdev, | |||
103 | * Create the new vq, and tell virtio we're not interested in | 103 | * Create the new vq, and tell virtio we're not interested in |
104 | * the 'weak' smp barriers, since we're talking with a real device. | 104 | * the 'weak' smp barriers, since we're talking with a real device. |
105 | */ | 105 | */ |
106 | vq = vring_new_virtqueue(len, rvring->align, vdev, false, addr, | 106 | vq = vring_new_virtqueue(id, len, rvring->align, vdev, false, addr, |
107 | rproc_virtio_notify, callback, name); | 107 | rproc_virtio_notify, callback, name); |
108 | if (!vq) { | 108 | if (!vq) { |
109 | dev_err(dev, "vring_new_virtqueue %s failed\n", name); | 109 | dev_err(dev, "vring_new_virtqueue %s failed\n", name); |
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c index 47cccd52aae8..5565af20592f 100644 --- a/drivers/s390/kvm/kvm_virtio.c +++ b/drivers/s390/kvm/kvm_virtio.c | |||
@@ -198,7 +198,7 @@ static struct virtqueue *kvm_find_vq(struct virtio_device *vdev, | |||
198 | if (err) | 198 | if (err) |
199 | goto out; | 199 | goto out; |
200 | 200 | ||
201 | vq = vring_new_virtqueue(config->num, KVM_S390_VIRTIO_RING_ALIGN, | 201 | vq = vring_new_virtqueue(index, config->num, KVM_S390_VIRTIO_RING_ALIGN, |
202 | vdev, true, (void *) config->address, | 202 | vdev, true, (void *) config->address, |
203 | kvm_notify, callback, name); | 203 | kvm_notify, callback, name); |
204 | if (!vq) { | 204 | if (!vq) { |
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c index 453db0c403d8..008bf58bdaae 100644 --- a/drivers/virtio/virtio_mmio.c +++ b/drivers/virtio/virtio_mmio.c | |||
@@ -131,9 +131,6 @@ struct virtio_mmio_vq_info { | |||
131 | /* the number of entries in the queue */ | 131 | /* the number of entries in the queue */ |
132 | unsigned int num; | 132 | unsigned int num; |
133 | 133 | ||
134 | /* the index of the queue */ | ||
135 | int queue_index; | ||
136 | |||
137 | /* the virtual address of the ring queue */ | 134 | /* the virtual address of the ring queue */ |
138 | void *queue; | 135 | void *queue; |
139 | 136 | ||
@@ -225,11 +222,10 @@ static void vm_reset(struct virtio_device *vdev) | |||
225 | static void vm_notify(struct virtqueue *vq) | 222 | static void vm_notify(struct virtqueue *vq) |
226 | { | 223 | { |
227 | struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev); | 224 | struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev); |
228 | struct virtio_mmio_vq_info *info = vq->priv; | ||
229 | 225 | ||
230 | /* We write the queue's selector into the notification register to | 226 | /* We write the queue's selector into the notification register to |
231 | * signal the other end */ | 227 | * signal the other end */ |
232 | writel(info->queue_index, vm_dev->base + VIRTIO_MMIO_QUEUE_NOTIFY); | 228 | writel(virtqueue_get_queue_index(vq), vm_dev->base + VIRTIO_MMIO_QUEUE_NOTIFY); |
233 | } | 229 | } |
234 | 230 | ||
235 | /* Notify all virtqueues on an interrupt. */ | 231 | /* Notify all virtqueues on an interrupt. */ |
@@ -270,6 +266,7 @@ static void vm_del_vq(struct virtqueue *vq) | |||
270 | struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev); | 266 | struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev); |
271 | struct virtio_mmio_vq_info *info = vq->priv; | 267 | struct virtio_mmio_vq_info *info = vq->priv; |
272 | unsigned long flags, size; | 268 | unsigned long flags, size; |
269 | unsigned int index = virtqueue_get_queue_index(vq); | ||
273 | 270 | ||
274 | spin_lock_irqsave(&vm_dev->lock, flags); | 271 | spin_lock_irqsave(&vm_dev->lock, flags); |
275 | list_del(&info->node); | 272 | list_del(&info->node); |
@@ -278,7 +275,7 @@ static void vm_del_vq(struct virtqueue *vq) | |||
278 | vring_del_virtqueue(vq); | 275 | vring_del_virtqueue(vq); |
279 | 276 | ||
280 | /* Select and deactivate the queue */ | 277 | /* Select and deactivate the queue */ |
281 | writel(info->queue_index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL); | 278 | writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL); |
282 | writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN); | 279 | writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN); |
283 | 280 | ||
284 | size = PAGE_ALIGN(vring_size(info->num, VIRTIO_MMIO_VRING_ALIGN)); | 281 | size = PAGE_ALIGN(vring_size(info->num, VIRTIO_MMIO_VRING_ALIGN)); |
@@ -324,7 +321,6 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, | |||
324 | err = -ENOMEM; | 321 | err = -ENOMEM; |
325 | goto error_kmalloc; | 322 | goto error_kmalloc; |
326 | } | 323 | } |
327 | info->queue_index = index; | ||
328 | 324 | ||
329 | /* Allocate pages for the queue - start with a queue as big as | 325 | /* Allocate pages for the queue - start with a queue as big as |
330 | * possible (limited by maximum size allowed by device), drop down | 326 | * possible (limited by maximum size allowed by device), drop down |
@@ -356,7 +352,7 @@ static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index, | |||
356 | vm_dev->base + VIRTIO_MMIO_QUEUE_PFN); | 352 | vm_dev->base + VIRTIO_MMIO_QUEUE_PFN); |
357 | 353 | ||
358 | /* Create the vring */ | 354 | /* Create the vring */ |
359 | vq = vring_new_virtqueue(info->num, VIRTIO_MMIO_VRING_ALIGN, vdev, | 355 | vq = vring_new_virtqueue(index, info->num, VIRTIO_MMIO_VRING_ALIGN, vdev, |
360 | true, info->queue, vm_notify, callback, name); | 356 | true, info->queue, vm_notify, callback, name); |
361 | if (!vq) { | 357 | if (!vq) { |
362 | err = -ENOMEM; | 358 | err = -ENOMEM; |
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c index 2e03d416b9af..d902464b89ce 100644 --- a/drivers/virtio/virtio_pci.c +++ b/drivers/virtio/virtio_pci.c | |||
@@ -79,9 +79,6 @@ struct virtio_pci_vq_info | |||
79 | /* the number of entries in the queue */ | 79 | /* the number of entries in the queue */ |
80 | int num; | 80 | int num; |
81 | 81 | ||
82 | /* the index of the queue */ | ||
83 | int queue_index; | ||
84 | |||
85 | /* the virtual address of the ring queue */ | 82 | /* the virtual address of the ring queue */ |
86 | void *queue; | 83 | void *queue; |
87 | 84 | ||
@@ -202,11 +199,11 @@ static void vp_reset(struct virtio_device *vdev) | |||
202 | static void vp_notify(struct virtqueue *vq) | 199 | static void vp_notify(struct virtqueue *vq) |
203 | { | 200 | { |
204 | struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); | 201 | struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); |
205 | struct virtio_pci_vq_info *info = vq->priv; | ||
206 | 202 | ||
207 | /* we write the queue's selector into the notification register to | 203 | /* we write the queue's selector into the notification register to |
208 | * signal the other end */ | 204 | * signal the other end */ |
209 | iowrite16(info->queue_index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY); | 205 | iowrite16(virtqueue_get_queue_index(vq), |
206 | vp_dev->ioaddr + VIRTIO_PCI_QUEUE_NOTIFY); | ||
210 | } | 207 | } |
211 | 208 | ||
212 | /* Handle a configuration change: Tell driver if it wants to know. */ | 209 | /* Handle a configuration change: Tell driver if it wants to know. */ |
@@ -402,7 +399,6 @@ static struct virtqueue *setup_vq(struct virtio_device *vdev, unsigned index, | |||
402 | if (!info) | 399 | if (!info) |
403 | return ERR_PTR(-ENOMEM); | 400 | return ERR_PTR(-ENOMEM); |
404 | 401 | ||
405 | info->queue_index = index; | ||
406 | info->num = num; | 402 | info->num = num; |
407 | info->msix_vector = msix_vec; | 403 | info->msix_vector = msix_vec; |
408 | 404 | ||
@@ -418,7 +414,7 @@ static struct virtqueue *setup_vq(struct virtio_device *vdev, unsigned index, | |||
418 | vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN); | 414 | vp_dev->ioaddr + VIRTIO_PCI_QUEUE_PFN); |
419 | 415 | ||
420 | /* create the vring */ | 416 | /* create the vring */ |
421 | vq = vring_new_virtqueue(info->num, VIRTIO_PCI_VRING_ALIGN, vdev, | 417 | vq = vring_new_virtqueue(index, info->num, VIRTIO_PCI_VRING_ALIGN, vdev, |
422 | true, info->queue, vp_notify, callback, name); | 418 | true, info->queue, vp_notify, callback, name); |
423 | if (!vq) { | 419 | if (!vq) { |
424 | err = -ENOMEM; | 420 | err = -ENOMEM; |
@@ -467,7 +463,8 @@ static void vp_del_vq(struct virtqueue *vq) | |||
467 | list_del(&info->node); | 463 | list_del(&info->node); |
468 | spin_unlock_irqrestore(&vp_dev->lock, flags); | 464 | spin_unlock_irqrestore(&vp_dev->lock, flags); |
469 | 465 | ||
470 | iowrite16(info->queue_index, vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL); | 466 | iowrite16(virtqueue_get_queue_index(vq), |
467 | vp_dev->ioaddr + VIRTIO_PCI_QUEUE_SEL); | ||
471 | 468 | ||
472 | if (vp_dev->msix_enabled) { | 469 | if (vp_dev->msix_enabled) { |
473 | iowrite16(VIRTIO_MSI_NO_VECTOR, | 470 | iowrite16(VIRTIO_MSI_NO_VECTOR, |
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 5aa43c3392a2..e639584b2dbd 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c | |||
@@ -106,6 +106,9 @@ struct vring_virtqueue | |||
106 | /* How to notify other side. FIXME: commonalize hcalls! */ | 106 | /* How to notify other side. FIXME: commonalize hcalls! */ |
107 | void (*notify)(struct virtqueue *vq); | 107 | void (*notify)(struct virtqueue *vq); |
108 | 108 | ||
109 | /* Index of the queue */ | ||
110 | int queue_index; | ||
111 | |||
109 | #ifdef DEBUG | 112 | #ifdef DEBUG |
110 | /* They're supposed to lock for us. */ | 113 | /* They're supposed to lock for us. */ |
111 | unsigned int in_use; | 114 | unsigned int in_use; |
@@ -171,6 +174,13 @@ static int vring_add_indirect(struct vring_virtqueue *vq, | |||
171 | return head; | 174 | return head; |
172 | } | 175 | } |
173 | 176 | ||
177 | int virtqueue_get_queue_index(struct virtqueue *_vq) | ||
178 | { | ||
179 | struct vring_virtqueue *vq = to_vvq(_vq); | ||
180 | return vq->queue_index; | ||
181 | } | ||
182 | EXPORT_SYMBOL_GPL(virtqueue_get_queue_index); | ||
183 | |||
174 | /** | 184 | /** |
175 | * virtqueue_add_buf - expose buffer to other end | 185 | * virtqueue_add_buf - expose buffer to other end |
176 | * @vq: the struct virtqueue we're talking about. | 186 | * @vq: the struct virtqueue we're talking about. |
@@ -616,7 +626,8 @@ irqreturn_t vring_interrupt(int irq, void *_vq) | |||
616 | } | 626 | } |
617 | EXPORT_SYMBOL_GPL(vring_interrupt); | 627 | EXPORT_SYMBOL_GPL(vring_interrupt); |
618 | 628 | ||
619 | struct virtqueue *vring_new_virtqueue(unsigned int num, | 629 | struct virtqueue *vring_new_virtqueue(unsigned int index, |
630 | unsigned int num, | ||
620 | unsigned int vring_align, | 631 | unsigned int vring_align, |
621 | struct virtio_device *vdev, | 632 | struct virtio_device *vdev, |
622 | bool weak_barriers, | 633 | bool weak_barriers, |
@@ -647,6 +658,7 @@ struct virtqueue *vring_new_virtqueue(unsigned int num, | |||
647 | vq->broken = false; | 658 | vq->broken = false; |
648 | vq->last_used_idx = 0; | 659 | vq->last_used_idx = 0; |
649 | vq->num_added = 0; | 660 | vq->num_added = 0; |
661 | vq->queue_index = index; | ||
650 | list_add_tail(&vq->vq.list, &vdev->vqs); | 662 | list_add_tail(&vq->vq.list, &vdev->vqs); |
651 | #ifdef DEBUG | 663 | #ifdef DEBUG |
652 | vq->in_use = false; | 664 | vq->in_use = false; |
diff --git a/include/linux/virtio.h b/include/linux/virtio.h index a1ba8bbd9fbe..533b1157f22e 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h | |||
@@ -50,6 +50,8 @@ void *virtqueue_detach_unused_buf(struct virtqueue *vq); | |||
50 | 50 | ||
51 | unsigned int virtqueue_get_vring_size(struct virtqueue *vq); | 51 | unsigned int virtqueue_get_vring_size(struct virtqueue *vq); |
52 | 52 | ||
53 | int virtqueue_get_queue_index(struct virtqueue *vq); | ||
54 | |||
53 | /** | 55 | /** |
54 | * virtio_device - representation of a device using virtio | 56 | * virtio_device - representation of a device using virtio |
55 | * @index: unique position on the virtio bus | 57 | * @index: unique position on the virtio bus |
diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h index e338730c2660..c2d793a06ad7 100644 --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h | |||
@@ -165,7 +165,8 @@ static inline int vring_need_event(__u16 event_idx, __u16 new_idx, __u16 old) | |||
165 | struct virtio_device; | 165 | struct virtio_device; |
166 | struct virtqueue; | 166 | struct virtqueue; |
167 | 167 | ||
168 | struct virtqueue *vring_new_virtqueue(unsigned int num, | 168 | struct virtqueue *vring_new_virtqueue(unsigned int index, |
169 | unsigned int num, | ||
169 | unsigned int vring_align, | 170 | unsigned int vring_align, |
170 | struct virtio_device *vdev, | 171 | struct virtio_device *vdev, |
171 | bool weak_barriers, | 172 | bool weak_barriers, |