aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/virtio
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2009-06-13 00:16:36 -0400
committerRusty Russell <rusty@rustcorp.com.au>2009-06-12 08:46:36 -0400
commitd2a7ddda9ffb1c8961abff6714b0f1eb925c120f (patch)
tree1090884fd260d042255255467367e4e6b6193e5d /drivers/virtio
parent9499f5e7ed5224c40706f0cec6542a9916bc7606 (diff)
virtio: find_vqs/del_vqs virtio operations
This replaces find_vq/del_vq with find_vqs/del_vqs virtio operations, and updates all drivers. This is needed for MSI support, because MSI needs to know the total number of vectors upfront. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (+ lguest/9p compile fixes)
Diffstat (limited to 'drivers/virtio')
-rw-r--r--drivers/virtio/virtio_balloon.c27
-rw-r--r--drivers/virtio/virtio_pci.c37
2 files changed, 41 insertions, 23 deletions
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index 0fa73b4d18b0..26b278264796 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -204,6 +204,9 @@ static int balloon(void *_vballoon)
204static int virtballoon_probe(struct virtio_device *vdev) 204static int virtballoon_probe(struct virtio_device *vdev)
205{ 205{
206 struct virtio_balloon *vb; 206 struct virtio_balloon *vb;
207 struct virtqueue *vqs[2];
208 vq_callback_t *callbacks[] = { balloon_ack, balloon_ack };
209 const char *names[] = { "inflate", "deflate" };
207 int err; 210 int err;
208 211
209 vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL); 212 vdev->priv = vb = kmalloc(sizeof(*vb), GFP_KERNEL);
@@ -218,22 +221,17 @@ static int virtballoon_probe(struct virtio_device *vdev)
218 vb->vdev = vdev; 221 vb->vdev = vdev;
219 222
220 /* We expect two virtqueues. */ 223 /* We expect two virtqueues. */
221 vb->inflate_vq = vdev->config->find_vq(vdev, 0, balloon_ack, "inflate"); 224 err = vdev->config->find_vqs(vdev, 2, vqs, callbacks, names);
222 if (IS_ERR(vb->inflate_vq)) { 225 if (err)
223 err = PTR_ERR(vb->inflate_vq);
224 goto out_free_vb; 226 goto out_free_vb;
225 }
226 227
227 vb->deflate_vq = vdev->config->find_vq(vdev, 1, balloon_ack, "deflate"); 228 vb->inflate_vq = vqs[0];
228 if (IS_ERR(vb->deflate_vq)) { 229 vb->deflate_vq = vqs[1];
229 err = PTR_ERR(vb->deflate_vq);
230 goto out_del_inflate_vq;
231 }
232 230
233 vb->thread = kthread_run(balloon, vb, "vballoon"); 231 vb->thread = kthread_run(balloon, vb, "vballoon");
234 if (IS_ERR(vb->thread)) { 232 if (IS_ERR(vb->thread)) {
235 err = PTR_ERR(vb->thread); 233 err = PTR_ERR(vb->thread);
236 goto out_del_deflate_vq; 234 goto out_del_vqs;
237 } 235 }
238 236
239 vb->tell_host_first 237 vb->tell_host_first
@@ -241,10 +239,8 @@ static int virtballoon_probe(struct virtio_device *vdev)
241 239
242 return 0; 240 return 0;
243 241
244out_del_deflate_vq: 242out_del_vqs:
245 vdev->config->del_vq(vb->deflate_vq); 243 vdev->config->del_vqs(vdev);
246out_del_inflate_vq:
247 vdev->config->del_vq(vb->inflate_vq);
248out_free_vb: 244out_free_vb:
249 kfree(vb); 245 kfree(vb);
250out: 246out:
@@ -264,8 +260,7 @@ static void virtballoon_remove(struct virtio_device *vdev)
264 /* Now we reset the device so we can clean up the queues. */ 260 /* Now we reset the device so we can clean up the queues. */
265 vdev->config->reset(vdev); 261 vdev->config->reset(vdev);
266 262
267 vdev->config->del_vq(vb->deflate_vq); 263 vdev->config->del_vqs(vdev);
268 vdev->config->del_vq(vb->inflate_vq);
269 kfree(vb); 264 kfree(vb);
270} 265}
271 266
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index be4047abd5ba..027f13fbe493 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -276,11 +276,7 @@ static void vp_del_vq(struct virtqueue *vq)
276{ 276{
277 struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev); 277 struct virtio_pci_device *vp_dev = to_vp_device(vq->vdev);
278 struct virtio_pci_vq_info *info = vq->priv; 278 struct virtio_pci_vq_info *info = vq->priv;
279 unsigned long flags, size; 279 unsigned long size;
280
281 spin_lock_irqsave(&vp_dev->lock, flags);
282 list_del(&info->node);
283 spin_unlock_irqrestore(&vp_dev->lock, flags);
284 280
285 vring_del_virtqueue(vq); 281 vring_del_virtqueue(vq);
286 282
@@ -293,14 +289,41 @@ static void vp_del_vq(struct virtqueue *vq)
293 kfree(info); 289 kfree(info);
294} 290}
295 291
292static void vp_del_vqs(struct virtio_device *vdev)
293{
294 struct virtqueue *vq, *n;
295
296 list_for_each_entry_safe(vq, n, &vdev->vqs, list)
297 vp_del_vq(vq);
298}
299
300static int vp_find_vqs(struct virtio_device *vdev, unsigned nvqs,
301 struct virtqueue *vqs[],
302 vq_callback_t *callbacks[],
303 const char *names[])
304{
305 int i;
306
307 for (i = 0; i < nvqs; ++i) {
308 vqs[i] = vp_find_vq(vdev, i, callbacks[i], names[i]);
309 if (IS_ERR(vqs[i]))
310 goto error;
311 }
312 return 0;
313
314error:
315 vp_del_vqs(vdev);
316 return PTR_ERR(vqs[i]);
317}
318
296static struct virtio_config_ops virtio_pci_config_ops = { 319static struct virtio_config_ops virtio_pci_config_ops = {
297 .get = vp_get, 320 .get = vp_get,
298 .set = vp_set, 321 .set = vp_set,
299 .get_status = vp_get_status, 322 .get_status = vp_get_status,
300 .set_status = vp_set_status, 323 .set_status = vp_set_status,
301 .reset = vp_reset, 324 .reset = vp_reset,
302 .find_vq = vp_find_vq, 325 .find_vqs = vp_find_vqs,
303 .del_vq = vp_del_vq, 326 .del_vqs = vp_del_vqs,
304 .get_features = vp_get_features, 327 .get_features = vp_get_features,
305 .finalize_features = vp_finalize_features, 328 .finalize_features = vp_finalize_features,
306}; 329};