From patchwork Fri May 31 08:54:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seung-Woo Kim X-Patchwork-Id: 17397 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 48C8A25CAB for ; Fri, 31 May 2013 14:27:16 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id a41sf1986587yho.2 for ; Fri, 31 May 2013 07:27:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-beenthere:x-forwarded-to:x-forwarded-for:delivered-to:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:x-brightmail-tracker:dlp-filter:x-mtr :x-cfilter-loop: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:errors-to:sender :x-gm-message-state:x-original-sender :x-original-authentication-results:mailing-list:x-google-group-id :content-type:content-transfer-encoding; bh=ahSLTVADw50j7q3EffVZ2/uPk/YDzsxH5LBVikrTE7M=; b=Ls1LhCJk2PzuWDLoBNJPeGJNbZKnl1rLw9tqedtvqhFdYykEbGi3SkTsocMEsrQLI+ lExneyzLeEtGL0q2OsrplIfFsRbzAjTOiG1bF4tBlrPHJ4FwS6Yq+zIqDWJVCUlpEy89 f/7bLipJ9Yl+lZrvkuaSQIhCiCu4GgVnLCgyHwW4ux7khmTbfVKksyLd380uloocA7rx OC4prU1aGfkNceaULu1v6v80FKmlHnN6vuDEaJ0p4qdbs126uzgIc0kspY3ebub6Uomf eM4LiM8TlcB/qr8wu2A9Dd87L+CEqYtolKpVKbggos/dwB0Rwsa8exSxCGtsiLboMYUS CP0A== X-Received: by 10.224.200.202 with SMTP id ex10mr6784354qab.8.1370010436037; Fri, 31 May 2013 07:27:16 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.105.7 with SMTP id gi7ls969655qeb.56.gmail; Fri, 31 May 2013 07:27:15 -0700 (PDT) X-Received: by 10.58.180.196 with SMTP id dq4mr10544538vec.10.1370010435772; Fri, 31 May 2013 07:27:15 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id sy4si28552834vdc.108.2013.05.31.07.27.15 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 May 2013 07:27:15 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id id13so1087211vcb.37 for ; Fri, 31 May 2013 07:27:15 -0700 (PDT) X-Received: by 10.52.233.34 with SMTP id tt2mr8736440vdc.70.1370010435585; Fri, 31 May 2013 07:27:15 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.229.199 with SMTP id jj7csp52385vcb; Fri, 31 May 2013 07:27:14 -0700 (PDT) X-Received: by 10.14.199.2 with SMTP id w2mr13756157een.74.1370010433252; Fri, 31 May 2013 07:27:13 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id z48si30980056een.247.2013.05.31.07.27.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 31 May 2013 07:27:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1UiQGk-0001uN-Ck; Fri, 31 May 2013 14:25:26 +0000 Received: from mailout1.samsung.com ([203.254.224.24]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1UiL56-0000qW-DY for linaro-mm-sig@lists.linaro.org; Fri, 31 May 2013 08:53:04 +0000 Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MNN005MNNESMTH0@mailout1.samsung.com> for linaro-mm-sig@lists.linaro.org; Fri, 31 May 2013 17:54:38 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.112]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id A9.D3.08825.E4568A15; Fri, 31 May 2013 17:54:38 +0900 (KST) X-AuditID: cbfee68e-b7f276d000002279-3b-51a8654e78b1 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id C7.7B.21068.E4568A15; Fri, 31 May 2013 17:54:38 +0900 (KST) Received: from localhost.localdomain ([10.90.8.56]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MNN00BWKNEZZT60@mmp2.samsung.com>; Fri, 31 May 2013 17:54:38 +0900 (KST) From: Seung-Woo Kim To: dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org, sumit.semwal@linaro.org, airlied@linux.ie Date: Fri, 31 May 2013 17:54:47 +0900 Message-id: <1369990487-23510-3-git-send-email-sw0312.kim@samsung.com> X-Mailer: git-send-email 1.7.4.1 In-reply-to: <1369990487-23510-1-git-send-email-sw0312.kim@samsung.com> References: <1369990487-23510-1-git-send-email-sw0312.kim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRmVeSWpSXmKPExsWyRsS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ruj6 hgTB9RgZoIGENYwZ2+beZix4L11x5Ok5lgbGPvEuRk4OCQETiWut85khbDGJC/fWs3UxcnEI CUxnlFhw6BILhNPMJDFnfwsrSBWbgI7E/iW/wWwRgV5GiTX3mECKmAWaGSUeLfsD5HBwCAsE SMxcWQ5SwyKgKtG7YQ0TiM0r4CaxZfNtRohtChIL7r1lA7E5Bdwl1vddZgGxhYBq7s27zz6B kXcBI8MqRtHUguSC4qT0XCO94sTc4tK8dL3k/NxNjODIeya9g3FVg8UhRgEORiUe3oMpywOF WBPLiitzDzFKcDArifDqBq8IFOJNSaysSi3Kjy8qzUktPsSYDHTVRGYp0eR8YFLIK4k3NDYx M7I0Mje0MDI2J01YSZz3YKt1oJBAemJJanZqakFqEcwWJg5OqQbG/pNZOddvrxS0PrLi+k31 y7J5HZlT1wZqXhL+xtmfsn97o4rkc0mVN1snsCyf/dT0zKZtAgF305TLN7dbLXnlMuVec9n7 BW7hvAtibGKcTM5VnOfjZLh7UeGmyTYFwdCIJXucl9/qyz/WdNXo+f0XRm/M53ouUqy893qJ X6HtdMajc8VfrK0JUmIpzkg01GIuKk4EAOntuXQAAwAA DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-Mailman-Approved-At: Fri, 31 May 2013 14:25:24 +0000 Cc: inki.dae@samsung.com, kyungmin.park@samsung.com, sw0312.kim@samsung.com, linux-kernel@vger.kernel.org Subject: [Linaro-mm-sig] [RFC][PATCH 2/2] drm/prime: find gem object from the reimported dma-buf X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: linaro-mm-sig-bounces@lists.linaro.org Sender: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQncUvZbLUDMniOAwUMJ9DYvEYtM5hypLv96ZcDGVpf2kxNg9K1ZABBnvkAxYBARJeIDLFLY X-Original-Sender: sw0312.kim@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Reimported dma-buf can reuse same gem object only when prime import is done with same drm open context. So prime import is done with other drm open context, gem object is newly created and mapped even there is already mapped gem object. To avoid recreating gem object, importer private data can be used at reimport time if it is assigned with drm gem object at first import. This can also remove remapping dma address for the hardware having its own iommu. Signed-off-by: Seung-Woo Kim --- drivers/gpu/drm/drm_prime.c | 19 ++++++++++++++----- drivers/gpu/drm/exynos/exynos_drm_dmabuf.c | 1 + drivers/gpu/drm/i915/i915_gem_dmabuf.c | 1 + drivers/gpu/drm/udl/udl_gem.c | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index dcde352..78a3c7d 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -294,6 +294,7 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, } obj->import_attach = attach; + attach->importer_priv = obj; return obj; @@ -312,6 +313,7 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, { struct dma_buf *dma_buf; struct drm_gem_object *obj; + struct dma_buf_attachment *attach; int ret; dma_buf = dma_buf_get(prime_fd); @@ -327,11 +329,18 @@ int drm_gem_prime_fd_to_handle(struct drm_device *dev, goto out_put; } - /* never seen this one, need to import */ - obj = dev->driver->gem_prime_import(dev, dma_buf); - if (IS_ERR(obj)) { - ret = PTR_ERR(obj); - goto out_put; + attach = dma_buf_get_attachment(dma_buf, dev->dev); + if (IS_ERR(attach)) { + /* never seen this one, need to import */ + obj = dev->driver->gem_prime_import(dev, dma_buf); + if (IS_ERR(obj)) { + ret = PTR_ERR(obj); + goto out_put; + } + } else { + /* found attachment to same device */ + obj = attach->importer_priv; + drm_gem_object_reference(obj); } ret = drm_gem_handle_create(file_priv, obj, handle); diff --git a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c index ff7f2a8..268da36 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c +++ b/drivers/gpu/drm/exynos/exynos_drm_dmabuf.c @@ -285,6 +285,7 @@ struct drm_gem_object *exynos_dmabuf_prime_import(struct drm_device *drm_dev, exynos_gem_obj->buffer = buffer; buffer->sgt = sgt; exynos_gem_obj->base.import_attach = attach; + attach->importer_priv = &exynos_gem_obj->base; DRM_DEBUG_PRIME("dma_addr = 0x%x, size = 0x%lx\n", buffer->dma_addr, buffer->size); diff --git a/drivers/gpu/drm/i915/i915_gem_dmabuf.c b/drivers/gpu/drm/i915/i915_gem_dmabuf.c index dc53a52..75ef28c 100644 --- a/drivers/gpu/drm/i915/i915_gem_dmabuf.c +++ b/drivers/gpu/drm/i915/i915_gem_dmabuf.c @@ -297,6 +297,7 @@ struct drm_gem_object *i915_gem_prime_import(struct drm_device *dev, i915_gem_object_init(obj, &i915_gem_object_dmabuf_ops); obj->base.import_attach = attach; + attach->importer_priv = &obj->base; return &obj->base; diff --git a/drivers/gpu/drm/udl/udl_gem.c b/drivers/gpu/drm/udl/udl_gem.c index ef034fa..0652db1 100644 --- a/drivers/gpu/drm/udl/udl_gem.c +++ b/drivers/gpu/drm/udl/udl_gem.c @@ -317,6 +317,7 @@ struct drm_gem_object *udl_gem_prime_import(struct drm_device *dev, } uobj->base.import_attach = attach; + attach->importer_priv = &uobj->base; return &uobj->base;