From patchwork Sat Nov 3 12:21:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Sharma X-Patchwork-Id: 1693571 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 784CA3FCDE for ; Sun, 4 Nov 2012 09:49:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B84AF9E83F for ; Sun, 4 Nov 2012 01:49:34 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by gabe.freedesktop.org (Postfix) with ESMTP id B28579F38D for ; Sat, 3 Nov 2012 05:02:01 -0700 (PDT) Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MCW009EAURCRG60@mailout4.samsung.com> for dri-devel@lists.freedesktop.org; Sat, 03 Nov 2012 21:02:00 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.123]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id CE.71.01231.7B705905; Sat, 03 Nov 2012 21:02:00 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-c6-509507b7100f Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id FD.71.01231.7B705905; Sat, 03 Nov 2012 21:01:59 +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 <0MCW008RQUQYMG60@mmp2.samsung.com> for dri-devel@lists.freedesktop.org; Sat, 03 Nov 2012 21:01:59 +0900 (KST) From: Rahul Sharma To: dri-devel@lists.freedesktop.org Subject: [PATCH v1] drm: exynos: fix for mapping non contig dma buffers Date: Sat, 03 Nov 2012 17:51:43 +0530 Message-id: <1351945304-15084-1-git-send-email-rahul.sharma@samsung.com> X-Mailer: git-send-email 1.7.0.4 DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMLMWRmVeSWpSXmKPExsWyRsSkWncH+9QAgytbmCyufH3P5sDocb/7 OFMAYxSXTUpqTmZZapG+XQJXxovll1kK2gQqvn7rZG5g7OPtYuTgkBAwkZjdkNXFyAlkiklc uLeeDcQWEljKKPF8rRpE3ESie9dJ5i5GLqD4dEaJc41XmCCc1UwS13/OZwWpYhPQlZh98Bkj iC0ioCzxd+IqRpAiZoFbjBLTnq1gAUkIC7hL7D/ayQ5iswioSiz89IQJ5ApeAQ+JJxOcIbYp SLQuOwRVIiDxbfIhFohDZSU2HQA7QkJgD5vEzCfz2SHqJSUOrrjBMoFRcAEjwypG0dSC5ILi pPRcQ73ixNzi0rx0veT83E2MwJA6/e+Z1A7GlQ0WhxgFOBiVeHgv8E0JEGJNLCuuzD3EKMHB rCTCu/gYUIg3JbGyKrUoP76oNCe1+BCjD9AlE5mlRJPzgeGeVxJvaGxibmpsamlkZGZqikNY SZy32SMlQEggPbEkNTs1tSC1CGYcEwenVANjcfV/R3NdiflLVf+33Xq68afmotcRPyYtf/Ay QMX4+w3XA93sm9lDvlYJCrrX7VhbMeXQif6ZGcLrdeSz1e8VaHg5/Inb25jx/wXb3Lfem1be uMBquaVqmebtlk+dk3JUsl7+t83mXhzX3hqfXPxDeWOHIOfrVjnRowvsXj3acURm0aQ2TaOb SizFGYmGWsxFxYkALGQBXFYCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrCLMWRmVeSWpSXmKPExsVy+t9jQd3t7FMDDH580bW48vU9mwOjx/3u 40wBjFENjDYZqYkpqUUKqXnJ+SmZeem2St7B8c7xpmYGhrqGlhbmSgp5ibmptkouPgG6bpk5 QGOVFMoSc0qBQgGJxcVK+naYJoSGuOlawDRG6PqGBMH1GBmggYQ1jBkvll9mKWgTqPj6rZO5 gbGPt4uRk0NCwESie9dJZghbTOLCvfVsXYxcHEIC0xklzjVeYYJwVjNJXP85nxWkik1AV2L2 wWeMILaIgLLE34mrGEGKmAVuMUpMe7aCBSQhLOAusf9oJzuIzSKgKrHw0xOgSRwcvAIeEk8m OENsU5BoXXaIfQIj9wJGhlWMoqkFyQXFSem5hnrFibnFpXnpesn5uZsYwUH7TGoH48oGi0OM AhyMSjy8F/imBAixJpYVV+YeYpTgYFYS4V18DCjEm5JYWZValB9fVJqTWnyI0Qdo+URmKdHk fGBE5ZXEGxqbmJsam1qaWJiYWeIQVhLnbfZICRASSE8sSc1OTS1ILYIZx8TBKdXAqLLRW3v2 Rs+6mx1anJMV5h/0ZD+clV3isIL/1eFDCTu07eVE5eWnyjAZP1VTKHz75Nyd9gfn725OSH+T a9IxpZf9xi0j88legef2FwexpjbnSL75xHZlvc9E45neXRVbbjIv3i44rYJL68vdt3us5ydq f+L9ljSxzGrPY4G3fucOhoTpHny+T4mlOCPRUIu5qDgRAPVKvT2HAgAA X-CFilter-Loop: Reflected X-Mailman-Approved-At: Sun, 04 Nov 2012 01:44:36 -0800 Cc: sw0312.kim@samsung.com, joshi@samsung.com, kyungmin.park@samsung.com, rahul.sharma@samsung.com, prashanth.g@samsung.com, s.shirish@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org This patch fixes the problem of mapping gem objects which are non-contigous dma buffers. These buffers are described using SG table and SG lists. Each valid SG List is pointing to a single page or group of pages which are physically contigous. Current implementation just maps the first page of each SG List and leave the other pages unmapped, leading to a crash. Given solution finds the page struct for the faulting page through parsing SG table and map it. This patch is based on branch exynos-drm-next-iommu at git://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git v1: 1) instead of mapping whole section, mapping single page. Signed-off-by: Rahul Sharma --- drivers/gpu/drm/exynos/exynos_drm_gem.c | 22 ++++++++++++++++++++-- 1 files changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c index 8cb6824..c557ac7 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c @@ -95,13 +95,31 @@ static int exynos_drm_gem_map_buf(struct drm_gem_object *obj, { struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj); struct exynos_drm_gem_buf *buf = exynos_gem_obj->buffer; + struct scatterlist *sgl; unsigned long pfn; + int i; if (exynos_gem_obj->flags & EXYNOS_BO_NONCONTIG) { - if (!buf->pages) + if (!buf->sgt) return -EINTR; - pfn = page_to_pfn(buf->pages[page_offset++]); + sgl = buf->sgt->sgl; + for_each_sg(buf->sgt->sgl, sgl, buf->sgt->nents, i) { + if (!sgl) { + DRM_ERROR("invalid SG table\n"); + return -EINTR; + } + if (page_offset < (sgl->length >> PAGE_SHIFT)) + break; + page_offset -= (sgl->length >> PAGE_SHIFT); + } + + if (i >= buf->sgt->nents) { + DRM_ERROR("invalid page offset\n"); + return -EINVAL; + } + + pfn = __phys_to_pfn(sg_phys(sgl)) + page_offset; } else pfn = (buf->dma_addr >> PAGE_SHIFT) + page_offset;