From: Prathyush K Subject: [PATCH v2] drm/exynos: create new sgt from existing sgt Date: Mon, 03 Dec 2012 12:30:44 +0530 Message-ID: <1354518044-31990-1-git-send-email-prathyush.k@samsung.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id 8B568E5CC5 for ; Sun, 2 Dec 2012 22:37:45 -0800 (PST) Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MEF001MHZQOKPK0@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Mon, 03 Dec 2012 15:37:43 +0900 (KST) Received: from localhost.localdomain ([107.108.73.106]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MEF00KC5ZQP7C70@mmp2.samsung.com> for dri-devel@lists.freedesktop.org; Mon, 03 Dec 2012 15:37:42 +0900 (KST) List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org Errors-To: dri-devel-bounces+sf-dri-devel=m.gmane.org@lists.freedesktop.org To: dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org Changelog v2: Implement copy sgt code in exynos_get_sgt itself instead of calling sg_clone_table. Changelog v1: During map_dma_buf, a new sgt needs to be created before being mapped to another device's address space. Currently, this sgt is created by calling dma_get_sgtable which creates a sgt from pages. This will be time consuming if the map/unmap calls are done repeatedly for very large buffers. Instead, we can just use the sgt which was already created during buffer allocation and create the new sgt by copying the sgls from the existing sgt. And this patch is based on exynos-drm-next-iommu branch of git://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos Signed-off-by: Prathyush K --- drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c index d9307bd..91c7db1 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +++ b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c @@ -34,19 +34,31 @@ static struct sg_table *exynos_get_sgt(struct drm_device *drm_dev, struct exynos_drm_gem_buf *buf) { struct sg_table *sgt = NULL; + struct scatterlist *s, *s_out; + unsigned int i; int ret; + if (!buf->sgt) { + DRM_ERROR("no sg table.\n"); + goto out; + } + sgt = kzalloc(sizeof(*sgt), GFP_KERNEL); if (!sgt) goto out; - ret = dma_get_sgtable(drm_dev->dev, sgt, buf->kvaddr, - buf->dma_addr, buf->size); + ret = sg_alloc_table(sgt, buf->sgt->orig_nents, GFP_KERNEL); if (ret < 0) { - DRM_ERROR("failed to get sgtable.\n"); + DRM_ERROR("failed to alloc table\n"); goto err_free_sgt; } + s_out = sgt->sgl; + for_each_sg(buf->sgt->sgl, s, buf->sgt->orig_nents, i) { + sg_set_page(s_out, sg_page(s), s->length, s->offset); + s_out = sg_next(s_out); + } + return sgt; err_free_sgt: -- 1.7.0.4