From patchwork Thu Nov 1 12:34:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rahul Sharma X-Patchwork-Id: 1687601 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 4A7EB3FE20 for ; Fri, 2 Nov 2012 09:43:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 372019E7E7 for ; Fri, 2 Nov 2012 02:43:22 -0700 (PDT) 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 BFA209E798 for ; Thu, 1 Nov 2012 05:16:31 -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 <0MCT0095063HUBH0@mailout4.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 01 Nov 2012 21:16:29 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.125]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id B3.A4.01231.D1862905; Thu, 01 Nov 2012 21:16:29 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-05-5092681db13b Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id D2.A4.01231.D1862905; Thu, 01 Nov 2012 21:16:29 +0900 (KST) Received: from localhost.localdomain ([107.108.73.106]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MCT00EYP6113Z90@mmp1.samsung.com> for dri-devel@lists.freedesktop.org; Thu, 01 Nov 2012 21:16:29 +0900 (KST) From: Rahul Sharma To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm: exynos: fix for mapping non contig dma buffers Date: Thu, 01 Nov 2012 18:04:32 +0530 Message-id: <1351773272-1179-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+NgFjrMLMWRmVeSWpSXmKPExsWyRsSkVlc2Y1KAwZ0fhhZXvr5nc2D0uN99 nCmAMYrLJiU1J7MstUjfLoEr4+yUuIJfwhU9a64xNzD2C3QxcnJICJhIvHxykg3CFpO4cG89 kM3FISSwlFHi1cVORpiibdsfs0AkFjFK3P2xGSwhJLCaSeLszkoQm01AV2L2wWdgcREBZYm/ E1cxgjQwC9xilJj2bAULSEJYwEXiyJHbYEUsAqoSbe+usXYxcnDwCrhL7JwPdZGCROuyQ+wQ JQIS3yYfYgEpkRCQldh0gBlkpITADjaJFQvesEDUS0ocXHGDZQKj4AJGhlWMoqkFyQXFSem5 hnrFibnFpXnpesn5uZsYgSF1+t8zqR2MKxssDjEKcDAq8fAalk4MEGJNLCuuzD3EKMHBrCTC +7gbKMSbklhZlVqUH19UmpNafIjRB+iSicxSosn5wHDPK4k3NDYxNzU2tTQyMjM1xSGsJM7b 7JESICSQnliSmp2aWpBaBDOOiYNTqoGR9fDxLUntUnbXk8ucLh/zvS/+Q24ax8l1PW/17l6d a2hZLvU++Kapevy153e5xOrf7ruQHHVTXJXTTG/tB9dZibedws6vPNSz9Vfvs/bZzSvNNr0w qJ9XLPDV+pYTQ/j3qx/MPscv2cg4QXxy7JrzTDGv41LTfXd1523549MTO1cjpulLgdtKJZbi jERDLeai4kQAB3CLEFYCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrELMWRmVeSWpSXmKPExsVy+t9jAV3ZjEkBBvvPKFhc+fqezYHR4373 caYAxqgGRpuM1MSU1CKF1Lzk/JTMvHRbJe/geOd4UzMDQ11DSwtzJYW8xNxUWyUXnwBdt8wc oLFKCmWJOaVAoYDE4mIlfTtME0JD3HQtYBojdH1DguB6jAzQQMIaxoyzU+IKfglX9Ky5xtzA 2C/QxcjJISFgIrFt+2MWCFtM4sK99WxdjFwcQgKLGCXu/tjMCJIQEljNJHF2ZyWIzSagKzH7 4DOwuIiAssTfiasYQRqYBW4xSkx7tgJskrCAi8SRI7fBilgEVCXa3l1j7WLk4OAVcJfYOR9q sYJE67JD7BMYuRcwMqxiFE0tSC4oTkrPNdQrTswtLs1L10vOz93ECA7YZ1I7GFc2WBxiFOBg VOLhNSydGCDEmlhWXJl7iFGCg1lJhPdxN1CINyWxsiq1KD++qDQntfgQow/Q8onMUqLJ+cBo yiuJNzQ2MTc1NrU0sTAxs8QhrCTO2+yREiAkkJ5YkpqdmlqQWgQzjomDU6qBcVOrrPnu+zek PT2MGi49fLm1K5k9uPJo8aVVp/7xPnL89EvhvNNvjZgXU81zXgU0sO/u+WfO6hxcmBvz9Y28 xHuhSy9XZhelqU378cf827L72RIHs+I6lDrd729KY3K/V8iYPLsiVH+p1gTdzG9JN9YJf+ES Z8hOrdmQdOWusuv5idr7s9/9VGIpzkg01GIuKk4EAG6XemaFAgAA X-CFilter-Loop: Reflected X-Mailman-Approved-At: Fri, 02 Nov 2012 02:18:07 -0700 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 all the pages in the SG list and map them one by one. This ensures all the pages of current SG list are mapped. Next SG list of the same buffer will be mapped when page fault occurs for the offset belongs to that list. This patch is based on branch exynos-drm-next-iommu at git://git.kernel.org/pub/scm/linux/kernel/git/daeinki/drm-exynos.git Signed-off-by: Rahul Sharma --- drivers/gpu/drm/exynos/exynos_drm_gem.c | 34 +++++++++++++++++++++++++++--- 1 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c index 7057729..d2d6188 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c @@ -95,17 +95,43 @@ 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; + unsigned int phys_addr; + int ret, i; if (exynos_gem_obj->flags & EXYNOS_BO_NONCONTIG) { if (!buf->pages) return -EINTR; - pfn = page_to_pfn(buf->pages[page_offset++]); - } else + sgl = buf->sgt->sgl; + for_each_sg(buf->sgt->sgl, sgl, buf->sgt->nents, i) { + 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; + } + + phys_addr = sg_phys(sgl); + + for (i = 0; i < (sgl->length >> PAGE_SHIFT); i++) { + pfn = __phys_to_pfn(phys_addr + (i << PAGE_SHIFT)); + ret = vm_insert_mixed(vma, f_vaddr + (i << PAGE_SHIFT), + pfn); + if (ret < 0) { + DRM_ERROR("failed to map page.\n"); + return ret; + } + } + return 0; + } else { pfn = (buf->dma_addr >> PAGE_SHIFT) + page_offset; - - return vm_insert_mixed(vma, f_vaddr, pfn); + return vm_insert_mixed(vma, f_vaddr, pfn); + } } static int exynos_drm_gem_handle_create(struct drm_gem_object *obj,