From patchwork Sat Apr 14 11:52:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathyush X-Patchwork-Id: 7874 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id C7EC123E49 for ; Mon, 16 Apr 2012 15:39:30 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 80ADBA18406 for ; Mon, 16 Apr 2012 15:39:30 +0000 (UTC) Received: by yenl4 with SMTP id l4so3097979yen.11 for ; Mon, 16 Apr 2012 08:39:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:x-tm-as-mml:x-mailman-approved-at:cc:subject :x-beenthere:x-mailman-version:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-gm-message-state; bh=bparA58/b/kOgV1sxPJKuSfZ7XmefFpI78BdLV67c+Q=; b=cfdwJOAeYEADNA4daIhaiT1TQyJanFsvkN1+O5haNzX1elygpk8ZtgACIobTJu7FJ8 or6kK/rmzExlltUBeq6fKaP2PMYMR0AmKxfWLpJQ22b3R5XnzePagAEFdulsLgnFTbiF KkQ0mdZRov5iF2lOYckxFO+XoeR1L99Ulr1n8xcNYjOr/575Sp36d3xunSdmj1c+1wR3 TDyx7UREYdrfZqny9+NlZWME1d7349RsEc9HZw2kYYIy1d8tP5GFbKvxKnqrsRfY7EqE KGBITTgy8Oakz06boshFukswBcD1TklGrTgM5e1K0F2Ob5wKTlOLjPfEzJPM5FJTCDvK h1aA== Received: by 10.50.17.201 with SMTP id q9mr4300632igd.19.1334590769763; Mon, 16 Apr 2012 08:39:29 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp84610ibt; Mon, 16 Apr 2012 08:39:27 -0700 (PDT) Received: by 10.180.80.70 with SMTP id p6mr10518774wix.21.1334590766612; Mon, 16 Apr 2012 08:39:26 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id gb7si8642336wib.10.2012.04.16.08.39.25; Mon, 16 Apr 2012 08:39:26 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SJo1R-0002Oc-73; Mon, 16 Apr 2012 15:39:21 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SJ1Hm-0007BF-Pm for linaro-mm-sig@lists.linaro.org; Sat, 14 Apr 2012 11:36:59 +0000 Received: from epcpsbgm1.samsung.com (mailout4.samsung.com [203.254.224.34]) by mailout4.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTP id <0M2G0074HW9H2760@mailout4.samsung.com> for linaro-mm-sig@lists.linaro.org; Sat, 14 Apr 2012 20:36:56 +0900 (KST) X-AuditID: cbfee61a-b7c51ae000004a99-df-4f896158785f Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (MMPCPMTA) with SMTP id CC.90.19097.851698F4; Sat, 14 Apr 2012 20:36:56 +0900 (KST) Received: from localhost.localdomain ([107.108.73.106]) by mmp2.samsung.com (Oracle Communications Messaging Exchange Server 7u4-19.01 64bit (built Sep 7 2010)) with ESMTPA id <0M2G00CFAW941S00@mmp2.samsung.com> for linaro-mm-sig@lists.linaro.org; Sat, 14 Apr 2012 20:36:56 +0900 (KST) From: Prathyush To: dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org Date: Sat, 14 Apr 2012 17:22:11 +0530 Message-id: <1334404333-24592-3-git-send-email-prathyush.k@samsung.com> X-Mailer: git-send-email 1.7.0.4 In-reply-to: <1334404333-24592-1-git-send-email-prathyush.k@samsung.com> References: <1334404333-24592-1-git-send-email-prathyush.k@samsung.com> X-Brightmail-Tracker: AAAAAA== X-TM-AS-MML: No X-Mailman-Approved-At: Mon, 16 Apr 2012 15:39:19 +0000 Cc: inki.dae@samsung.com, sunilm@samsung.com, subash.rp@samsung.com, prashanth.g@samsung.com, prathyush.k@samsung.com Subject: [Linaro-mm-sig] [PATCH 2/4] [RFC] drm/exynos: Mapping of gem objects uses dma_mmap_writecombine X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQnLPgPgHDyNabI7KYMGj5l7j7Bb52aoK9BYKaaQAXdwjUBlI9cHV6sjY+ljEkQvSe0XWpoj GEM objects get mapped to user space in two ways - DIRECT and INDIRECT mapping. DIRECT mapping is by calling an ioctl and it maps all the pages to user space by calling remap-pfn-range. Indirect mapping is done by calling 'mmap'. The actual mapping is done when a page fault gets generated and is handled by exynos_drm_gem_fault function where the required page is mapped. Both the methods assume contiguous memory. With this change, the mapping is done by dma_mmap_writecombine which will support mapping of non-contiguous memory to user space. This works similar to the previous approach for the case of DIRECT mapping. But in the case of mapping when a page fault occurs, dma_mmap_writecombine will map all the pages and not just one page. Signed-off-by: Prathyush K --- drivers/gpu/drm/exynos/exynos_drm_gem.c | 70 ++++++++++++++---------------- 1 files changed, 33 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_gem.c b/drivers/gpu/drm/exynos/exynos_drm_gem.c index 807143e..a57a83a 100755 --- a/drivers/gpu/drm/exynos/exynos_drm_gem.c +++ b/drivers/gpu/drm/exynos/exynos_drm_gem.c @@ -200,40 +200,27 @@ static int exynos_drm_gem_mmap_buffer(struct file *filp, { struct drm_gem_object *obj = filp->private_data; struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj); - struct exynos_drm_gem_buf *buffer; - unsigned long pfn, vm_size; - - DRM_DEBUG_KMS("%s\n", __FILE__); + void *kva; + dma_addr_t dma_address; + unsigned long ret; - vma->vm_flags |= (VM_IO | VM_RESERVED); + kva = exynos_gem_obj->buffer->kvaddr; - /* in case of direct mapping, always having non-cachable attribute */ - vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); - vma->vm_file = filp; - - vm_size = vma->vm_end - vma->vm_start; - /* - * a buffer contains information to physically continuous memory - * allocated by user request or at framebuffer creation. - */ - buffer = exynos_gem_obj->buffer; - - /* check if user-requested size is valid. */ - if (vm_size > buffer->size) - return -EINVAL; + if (kva == NULL) { + DRM_ERROR("No KVA Found\n"); + return -EAGAIN; + } - /* - * get page frame number to physical memory to be mapped - * to user space. - */ - pfn = ((unsigned long)exynos_gem_obj->buffer->dma_addr) >> PAGE_SHIFT; + dma_address = exynos_gem_obj->buffer->dma_addr; + vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; + vma->vm_pgoff = 0; - DRM_DEBUG_KMS("pfn = 0x%lx\n", pfn); + ret = dma_mmap_writecombine(obj->dev->dev, vma, kva, + dma_address, vma->vm_end - vma->vm_start); - if (remap_pfn_range(vma, vma->vm_start, pfn, vm_size, - vma->vm_page_prot)) { - DRM_ERROR("failed to remap pfn range.\n"); - return -EAGAIN; + if (ret) { + DRM_ERROR("Remapping memory failed, error: %ld\n", ret); + return ret; } return 0; @@ -433,19 +420,29 @@ int exynos_drm_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) struct drm_gem_object *obj = vma->vm_private_data; struct exynos_drm_gem_obj *exynos_gem_obj = to_exynos_gem_obj(obj); struct drm_device *dev = obj->dev; - unsigned long pfn; - pgoff_t page_offset; + void *kva; + dma_addr_t dma_address; int ret; - page_offset = ((unsigned long)vmf->virtual_address - - vma->vm_start) >> PAGE_SHIFT; + kva = exynos_gem_obj->buffer->kvaddr; + + if (kva == NULL) { + DRM_ERROR("No KVA Found\n"); + return -EAGAIN; + } mutex_lock(&dev->struct_mutex); - pfn = (((unsigned long)exynos_gem_obj->buffer->dma_addr) >> - PAGE_SHIFT) + page_offset; - ret = vm_insert_mixed(vma, (unsigned long)vmf->virtual_address, pfn); + dma_address = exynos_gem_obj->buffer->dma_addr; + vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; + vma->vm_pgoff = 0; + + ret = dma_mmap_writecombine(obj->dev->dev, vma, kva, + dma_address, vma->vm_end - vma->vm_start); + + if (ret) + DRM_ERROR("Remapping memory failed, error: %d\n", ret); mutex_unlock(&dev->struct_mutex); @@ -457,7 +454,6 @@ int exynos_drm_gem_mmap(struct file *filp, struct vm_area_struct *vma) int ret; DRM_DEBUG_KMS("%s\n", __FILE__); - /* set vm_area_struct. */ ret = drm_gem_mmap(filp, vma); if (ret < 0) {