lkml.org 
[lkml]   [2007]   [Dec]   [20]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [PATCH 2/5] dma_map_sg_ring() helper
From
Date
On Thu, 20 Dec 2007 16:49:30 +1100
Rusty Russell <rusty@rustcorp.com.au> wrote:

> Obvious counterpart to dma_map_sg. Note that this is arch-independent
> code; sg_rings are backwards compatible with simple sg arrays.
>
> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
> ---
> drivers/base/dma-mapping.c | 13 +++++++++++++
> include/linux/dma-mapping.h | 4 ++++
> 2 files changed, 17 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c
> --- a/drivers/base/dma-mapping.c
> +++ b/drivers/base/dma-mapping.c
> @@ -8,6 +8,7 @@
> */
>
> #include <linux/dma-mapping.h>
> +#include <linux/sg_ring.h>
>
> /*
> * Managed DMA API
> @@ -162,6 +163,59 @@ void dmam_free_noncoherent(struct device
> }
> EXPORT_SYMBOL(dmam_free_noncoherent);
>
> +/**
> + * dma_map_sg_ring - Map an entire sg ring
> + * @dev: Device to free noncoherent memory for
> + * @sg: The sg_ring
> + * @direction: DMA_TO_DEVICE, DMA_FROM_DEVICE or DMA_BIDIRECTIONAL.
> + *
> + * This returns -ENOMEM if mapping fails. It's not clear that telling you
> + * it failed is useful though.
> + */
> +int dma_map_sg_ring(struct device *dev, struct sg_ring *sg,
> + enum dma_data_direction direction)
> +{
> + struct sg_ring *i;
> + unsigned int num;
> +
> + for (i = sg; i; i = sg_ring_next(i, sg)) {
> + BUG_ON(i->num > i->max);
> + num = dma_map_sg(dev, i->sg, i->num, direction);
> + if (num == 0 && i->num != 0)
> + goto unmap;
> + }
> + return 0;

I don't think that this works for IOMMUs that could merge sg entries.


\
 
 \ /
  Last update: 2007-12-20 08:09    [W:0.076 / U:0.384 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site