diff options
-rw-r--r-- | drivers/virtio/virtio_ring.c | 60 | ||||
-rw-r--r-- | include/linux/virtio.h | 4 |
2 files changed, 52 insertions, 12 deletions
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 6ea92a6d1134..c56bbe799241 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c | |||
@@ -262,19 +262,22 @@ add_head: | |||
262 | EXPORT_SYMBOL_GPL(virtqueue_add_buf); | 262 | EXPORT_SYMBOL_GPL(virtqueue_add_buf); |
263 | 263 | ||
264 | /** | 264 | /** |
265 | * virtqueue_kick - update after add_buf | 265 | * virtqueue_kick_prepare - first half of split virtqueue_kick call. |
266 | * @vq: the struct virtqueue | 266 | * @vq: the struct virtqueue |
267 | * | 267 | * |
268 | * After one or more virtqueue_add_buf calls, invoke this to kick | 268 | * Instead of virtqueue_kick(), you can do: |
269 | * the other side. | 269 | * if (virtqueue_kick_prepare(vq)) |
270 | * virtqueue_notify(vq); | ||
270 | * | 271 | * |
271 | * Caller must ensure we don't call this with other virtqueue | 272 | * This is sometimes useful because the virtqueue_kick_prepare() needs |
272 | * operations at the same time (except where noted). | 273 | * to be serialized, but the actual virtqueue_notify() call does not. |
273 | */ | 274 | */ |
274 | void virtqueue_kick(struct virtqueue *_vq) | 275 | bool virtqueue_kick_prepare(struct virtqueue *_vq) |
275 | { | 276 | { |
276 | struct vring_virtqueue *vq = to_vvq(_vq); | 277 | struct vring_virtqueue *vq = to_vvq(_vq); |
277 | u16 new, old; | 278 | u16 new, old; |
279 | bool needs_kick; | ||
280 | |||
278 | START_USE(vq); | 281 | START_USE(vq); |
279 | /* Descriptors and available array need to be set before we expose the | 282 | /* Descriptors and available array need to be set before we expose the |
280 | * new available array entries. */ | 283 | * new available array entries. */ |
@@ -287,13 +290,46 @@ void virtqueue_kick(struct virtqueue *_vq) | |||
287 | /* Need to update avail index before checking if we should notify */ | 290 | /* Need to update avail index before checking if we should notify */ |
288 | virtio_mb(vq); | 291 | virtio_mb(vq); |
289 | 292 | ||
290 | if (vq->event ? | 293 | if (vq->event) { |
291 | vring_need_event(vring_avail_event(&vq->vring), new, old) : | 294 | needs_kick = vring_need_event(vring_avail_event(&vq->vring), |
292 | !(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY)) | 295 | new, old); |
293 | /* Prod other side to tell it about changes. */ | 296 | } else { |
294 | vq->notify(&vq->vq); | 297 | needs_kick = !(vq->vring.used->flags & VRING_USED_F_NO_NOTIFY); |
295 | 298 | } | |
296 | END_USE(vq); | 299 | END_USE(vq); |
300 | return needs_kick; | ||
301 | } | ||
302 | EXPORT_SYMBOL_GPL(virtqueue_kick_prepare); | ||
303 | |||
304 | /** | ||
305 | * virtqueue_notify - second half of split virtqueue_kick call. | ||
306 | * @vq: the struct virtqueue | ||
307 | * | ||
308 | * This does not need to be serialized. | ||
309 | */ | ||
310 | void virtqueue_notify(struct virtqueue *_vq) | ||
311 | { | ||
312 | struct vring_virtqueue *vq = to_vvq(_vq); | ||
313 | |||
314 | /* Prod other side to tell it about changes. */ | ||
315 | vq->notify(_vq); | ||
316 | } | ||
317 | EXPORT_SYMBOL_GPL(virtqueue_notify); | ||
318 | |||
319 | /** | ||
320 | * virtqueue_kick - update after add_buf | ||
321 | * @vq: the struct virtqueue | ||
322 | * | ||
323 | * After one or more virtqueue_add_buf calls, invoke this to kick | ||
324 | * the other side. | ||
325 | * | ||
326 | * Caller must ensure we don't call this with other virtqueue | ||
327 | * operations at the same time (except where noted). | ||
328 | */ | ||
329 | void virtqueue_kick(struct virtqueue *vq) | ||
330 | { | ||
331 | if (virtqueue_kick_prepare(vq)) | ||
332 | virtqueue_notify(vq); | ||
297 | } | 333 | } |
298 | EXPORT_SYMBOL_GPL(virtqueue_kick); | 334 | EXPORT_SYMBOL_GPL(virtqueue_kick); |
299 | 335 | ||
diff --git a/include/linux/virtio.h b/include/linux/virtio.h index ec1706e7df50..31fe3a62874b 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h | |||
@@ -34,6 +34,10 @@ int virtqueue_add_buf(struct virtqueue *vq, | |||
34 | 34 | ||
35 | void virtqueue_kick(struct virtqueue *vq); | 35 | void virtqueue_kick(struct virtqueue *vq); |
36 | 36 | ||
37 | bool virtqueue_kick_prepare(struct virtqueue *vq); | ||
38 | |||
39 | void virtqueue_notify(struct virtqueue *vq); | ||
40 | |||
37 | void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); | 41 | void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); |
38 | 42 | ||
39 | void virtqueue_disable_cb(struct virtqueue *vq); | 43 | void virtqueue_disable_cb(struct virtqueue *vq); |