mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-03 23:58:05 +00:00
udmabuf: separate out creating/destroying scatter-table
These are nice functions and can be re-used. Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org> Link: http://patchwork.freedesktop.org/patch/msgid/20191203013627.85991-3-gurchetansingh@chromium.org Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
c1bbed6689
commit
17a7ce2034
1 changed files with 19 additions and 7 deletions
|
@ -47,10 +47,10 @@ static int mmap_udmabuf(struct dma_buf *buf, struct vm_area_struct *vma)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sg_table *map_udmabuf(struct dma_buf_attachment *at,
|
static struct sg_table *get_sg_table(struct device *dev, struct dma_buf *buf,
|
||||||
enum dma_data_direction direction)
|
enum dma_data_direction direction)
|
||||||
{
|
{
|
||||||
struct udmabuf *ubuf = at->dmabuf->priv;
|
struct udmabuf *ubuf = buf->priv;
|
||||||
struct sg_table *sg;
|
struct sg_table *sg;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ static struct sg_table *map_udmabuf(struct dma_buf_attachment *at,
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto err;
|
goto err;
|
||||||
if (!dma_map_sg(at->dev, sg->sgl, sg->nents, direction)) {
|
if (!dma_map_sg(dev, sg->sgl, sg->nents, direction)) {
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
@ -74,13 +74,25 @@ static struct sg_table *map_udmabuf(struct dma_buf_attachment *at,
|
||||||
return ERR_PTR(ret);
|
return ERR_PTR(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void put_sg_table(struct device *dev, struct sg_table *sg,
|
||||||
|
enum dma_data_direction direction)
|
||||||
|
{
|
||||||
|
dma_unmap_sg(dev, sg->sgl, sg->nents, direction);
|
||||||
|
sg_free_table(sg);
|
||||||
|
kfree(sg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct sg_table *map_udmabuf(struct dma_buf_attachment *at,
|
||||||
|
enum dma_data_direction direction)
|
||||||
|
{
|
||||||
|
return get_sg_table(at->dev, at->dmabuf, direction);
|
||||||
|
}
|
||||||
|
|
||||||
static void unmap_udmabuf(struct dma_buf_attachment *at,
|
static void unmap_udmabuf(struct dma_buf_attachment *at,
|
||||||
struct sg_table *sg,
|
struct sg_table *sg,
|
||||||
enum dma_data_direction direction)
|
enum dma_data_direction direction)
|
||||||
{
|
{
|
||||||
dma_unmap_sg(at->dev, sg->sgl, sg->nents, direction);
|
return put_sg_table(at->dev, sg, direction);
|
||||||
sg_free_table(sg);
|
|
||||||
kfree(sg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void release_udmabuf(struct dma_buf *buf)
|
static void release_udmabuf(struct dma_buf *buf)
|
||||||
|
|
Loading…
Reference in a new issue