Skip to content

Commit 67e93c8

Browse files
Joonyoung Shimdaeinki
authored andcommitted
drm/exynos: stop copying sg table
Already struct exynos_drm_gem_buf has pages of the buffer, so we don't need to copy from sg table of the buffer to sg table of dma-buf attachment, just can make sg table from pages of the buffer. Signed-off-by: Joonyoung Shim <[email protected]> Signed-off-by: Inki Dae <[email protected]>
1 parent 0e9a2ee commit 67e93c8

File tree

3 files changed

+20
-40
lines changed

3 files changed

+20
-40
lines changed

drivers/gpu/drm/exynos/exynos_drm_dmabuf.c

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <linux/dma-buf.h>
1919

2020
struct exynos_drm_dmabuf_attachment {
21-
struct sg_table sgt;
21+
struct sg_table *sgt;
2222
enum dma_data_direction dir;
2323
bool is_mapped;
2424
};
@@ -53,13 +53,15 @@ static void exynos_gem_detach_dma_buf(struct dma_buf *dmabuf,
5353
if (!exynos_attach)
5454
return;
5555

56-
sgt = &exynos_attach->sgt;
57-
58-
if (exynos_attach->dir != DMA_NONE)
59-
dma_unmap_sg(attach->dev, sgt->sgl, sgt->nents,
60-
exynos_attach->dir);
56+
sgt = exynos_attach->sgt;
57+
if (sgt) {
58+
if (exynos_attach->dir != DMA_NONE)
59+
dma_unmap_sg(attach->dev, sgt->sgl, sgt->nents,
60+
exynos_attach->dir);
61+
sg_free_table(sgt);
62+
}
6163

62-
sg_free_table(sgt);
64+
kfree(sgt);
6365
kfree(exynos_attach);
6466
attach->priv = NULL;
6567
}
@@ -70,59 +72,43 @@ static struct sg_table *
7072
{
7173
struct exynos_drm_dmabuf_attachment *exynos_attach = attach->priv;
7274
struct exynos_drm_gem_obj *gem_obj = dma_buf_to_obj(attach->dmabuf);
73-
struct drm_device *dev = gem_obj->base.dev;
7475
struct exynos_drm_gem_buf *buf;
75-
struct scatterlist *rd, *wr;
76-
struct sg_table *sgt = NULL;
77-
unsigned int i;
78-
int nents, ret;
76+
struct sg_table *sgt;
77+
int npages;
7978

8079
/* just return current sgt if already requested. */
8180
if (exynos_attach->dir == dir && exynos_attach->is_mapped)
82-
return &exynos_attach->sgt;
81+
return exynos_attach->sgt;
8382

8483
buf = gem_obj->buffer;
8584
if (!buf) {
8685
DRM_ERROR("buffer is null.\n");
8786
return ERR_PTR(-ENOMEM);
8887
}
8988

90-
sgt = &exynos_attach->sgt;
89+
npages = buf->size >> PAGE_SHIFT;
9190

92-
ret = sg_alloc_table(sgt, buf->sgt->orig_nents, GFP_KERNEL);
93-
if (ret) {
94-
DRM_ERROR("failed to alloc sgt.\n");
95-
return ERR_PTR(-ENOMEM);
96-
}
97-
98-
mutex_lock(&dev->struct_mutex);
99-
100-
rd = buf->sgt->sgl;
101-
wr = sgt->sgl;
102-
for (i = 0; i < sgt->orig_nents; ++i) {
103-
sg_set_page(wr, sg_page(rd), rd->length, rd->offset);
104-
rd = sg_next(rd);
105-
wr = sg_next(wr);
106-
}
91+
sgt = drm_prime_pages_to_sg(buf->pages, npages);
92+
if (IS_ERR(sgt))
93+
goto err;
10794

10895
if (dir != DMA_NONE) {
109-
nents = dma_map_sg(attach->dev, sgt->sgl, sgt->orig_nents, dir);
110-
if (!nents) {
96+
if (!dma_map_sg(attach->dev, sgt->sgl, sgt->orig_nents, dir)) {
11197
DRM_ERROR("failed to map sgl with iommu.\n");
11298
sg_free_table(sgt);
11399
sgt = ERR_PTR(-EIO);
114-
goto err_unlock;
100+
goto err;
115101
}
116102
}
117103

118104
exynos_attach->is_mapped = true;
105+
exynos_attach->sgt = sgt;
119106
exynos_attach->dir = dir;
120107
attach->priv = exynos_attach;
121108

122109
DRM_DEBUG_PRIME("buffer size = 0x%lx\n", buf->size);
123110

124-
err_unlock:
125-
mutex_unlock(&dev->struct_mutex);
111+
err:
126112
return sgt;
127113
}
128114

@@ -280,7 +266,6 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev,
280266
}
281267

282268
exynos_gem_obj->buffer = buffer;
283-
buffer->sgt = sgt;
284269
exynos_gem_obj->base.import_attach = attach;
285270

286271
DRM_DEBUG_PRIME("dma_addr = %pad, size = 0x%lx\n", &buffer->dma_addr,

drivers/gpu/drm/exynos/exynos_drm_gem.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,6 @@ void exynos_drm_gem_free_object(struct drm_gem_object *obj)
455455
exynos_gem_obj = to_exynos_gem_obj(obj);
456456
buf = exynos_gem_obj->buffer;
457457

458-
if (obj->import_attach)
459-
drm_prime_gem_destroy(obj, buf->sgt);
460-
461458
exynos_drm_gem_destroy(to_exynos_gem_obj(obj));
462459
}
463460

drivers/gpu/drm/exynos/exynos_drm_gem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
* device address with IOMMU.
3131
* @write: whether pages will be written to by the caller.
3232
* @pages: Array of backing pages.
33-
* @sgt: sg table to transfer page data.
3433
* @size: size of allocated memory region.
3534
* @pfnmap: indicate whether memory region from userptr is mmaped with
3635
* VM_PFNMAP or not.
@@ -43,7 +42,6 @@ struct exynos_drm_gem_buf {
4342
struct dma_attrs dma_attrs;
4443
unsigned int write;
4544
struct page **pages;
46-
struct sg_table *sgt;
4745
unsigned long size;
4846
bool pfnmap;
4947
};

0 commit comments

Comments
 (0)