Commit eef5dab8134446dc175f78e569ee2be64bc78afd
1 parent
13d7a146c7
Exists in
ti-lsk-linux-4.1.y
and in
5 other branches
virtio_ring: add virtqueue_add_inbuf/outbuf_rpmsg API
Expose new variants of virtqueue_add_inbuf() & virtqueue_add_outbuf() API specifically to deal with virtio_rpmsg. The virtio core in general expects all the vring buffers to be allocated from linear addresses, but the virtio_rpmsg can have the buffers in non-linear space due to its usage of the dma_alloc_coherent() API. Based on a RFC patch from Edgar E. Iglesias <edgar.iglesias@xilinx.com>, http://marc.info/?l=linux-virtualization&m=143047902512226&w=2 Signed-off-by: Suman Anna <s-anna@ti.com>
Showing 2 changed files with 60 additions and 0 deletions Side-by-side Diff
drivers/virtio/virtio_ring.c
... | ... | @@ -324,6 +324,31 @@ |
324 | 324 | EXPORT_SYMBOL_GPL(virtqueue_add_outbuf); |
325 | 325 | |
326 | 326 | /** |
327 | + * virtqueue_add_outbuf_rpmsg - expose output buffers for virtio_rpmsg | |
328 | + * @vq: the struct virtqueue we're talking about. | |
329 | + * @sg: scatterlist (with dma fields filled in, and terminated properly!) | |
330 | + * @num: the number of entries in @sg readable by other side | |
331 | + * @data: the token identifying the buffer. | |
332 | + * @gfp: how to do memory allocations (if necessary). | |
333 | + * | |
334 | + * Caller must ensure we don't call this with other virtqueue operations | |
335 | + * at the same time (except where noted). Note that the scatterlist is | |
336 | + * non-standard with only the corresponding dma fields filled in, so | |
337 | + * should not be used with any sg operations using traditional buffer | |
338 | + * and length fields. | |
339 | + * | |
340 | + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO). | |
341 | + */ | |
342 | +int virtqueue_add_outbuf_rpmsg(struct virtqueue *vq, | |
343 | + struct scatterlist *sg, unsigned int num, | |
344 | + void *data, | |
345 | + gfp_t gfp) | |
346 | +{ | |
347 | + return virtqueue_add(vq, &sg, num, 1, 0, data, gfp, true); | |
348 | +} | |
349 | +EXPORT_SYMBOL_GPL(virtqueue_add_outbuf_rpmsg); | |
350 | + | |
351 | +/** | |
327 | 352 | * virtqueue_add_inbuf - expose input buffers to other end |
328 | 353 | * @vq: the struct virtqueue we're talking about. |
329 | 354 | * @sg: scatterlist (must be well-formed and terminated!) |
... | ... | @@ -344,6 +369,31 @@ |
344 | 369 | return virtqueue_add(vq, &sg, num, 0, 1, data, gfp, false); |
345 | 370 | } |
346 | 371 | EXPORT_SYMBOL_GPL(virtqueue_add_inbuf); |
372 | + | |
373 | +/** | |
374 | + * virtqueue_add_inbuf_rpmsg - expose input buffers for virtio_rpmsg | |
375 | + * @vq: the struct virtqueue we're talking about. | |
376 | + * @sg: scatterlist (with dma fields filled in, and terminated properly!) | |
377 | + * @num: the number of entries in @sg writable by other side | |
378 | + * @data: the token identifying the buffer. | |
379 | + * @gfp: how to do memory allocations (if necessary). | |
380 | + * | |
381 | + * Caller must ensure we don't call this with other virtqueue operations | |
382 | + * at the same time (except where noted). Note that the scatterlist is | |
383 | + * non-standard with only the corresponding dma fields filled in, so | |
384 | + * should not be used with any sg operations using traditional buffer | |
385 | + * and length fields. | |
386 | + * | |
387 | + * Returns zero or a negative error (ie. ENOSPC, ENOMEM, EIO). | |
388 | + */ | |
389 | +int virtqueue_add_inbuf_rpmsg(struct virtqueue *vq, | |
390 | + struct scatterlist *sg, unsigned int num, | |
391 | + void *data, | |
392 | + gfp_t gfp) | |
393 | +{ | |
394 | + return virtqueue_add(vq, &sg, num, 0, 1, data, gfp, true); | |
395 | +} | |
396 | +EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_rpmsg); | |
347 | 397 | |
348 | 398 | /** |
349 | 399 | * virtqueue_kick_prepare - first half of split virtqueue_kick call. |
include/linux/virtio.h
... | ... | @@ -44,6 +44,16 @@ |
44 | 44 | void *data, |
45 | 45 | gfp_t gfp); |
46 | 46 | |
47 | +int virtqueue_add_outbuf_rpmsg(struct virtqueue *vq, | |
48 | + struct scatterlist sg[], unsigned int num, | |
49 | + void *data, | |
50 | + gfp_t gfp); | |
51 | + | |
52 | +int virtqueue_add_inbuf_rpmsg(struct virtqueue *vq, | |
53 | + struct scatterlist sg[], unsigned int num, | |
54 | + void *data, | |
55 | + gfp_t gfp); | |
56 | + | |
47 | 57 | int virtqueue_add_sgs(struct virtqueue *vq, |
48 | 58 | struct scatterlist *sgs[], |
49 | 59 | unsigned int out_sgs, |