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: 2640951 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 1E2AB3FD4E for ; Fri, 31 May 2013 08:55:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 14D23E6155 for ; Fri, 31 May 2013 01:55:46 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) by gabe.freedesktop.org (Postfix) with ESMTP id A37ABE5C65 for ; Fri, 31 May 2013 01:54:40 -0700 (PDT) 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 dri-devel@lists.freedesktop.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 Subject: [RFC][PATCH 2/2] drm/prime: find gem object from the reimported dma-buf 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+NgFprAIsWRmVeSWpSXmKPExsWyRsSkQNcvdUWgwYePmha9504yWSx8eJfZ 4srX92wWk+5PYLE42/SG3eLLlYdMFpd3zWGz6NmwldXi1N3P7BYzJr9kc+Dy2PttAYvHnWt7 2Dy2f3vA6nG/+ziTx+1/j5k9+rasYvT4vEkugD2KyyYlNSezLLVI3y6BK2Pb3NuMBe+lK448 PcfSwNgn3sXIySEhYCLxq+8cI4QtJnHh3nq2LkYuDiGBpYwS1y6eZoUputY6nxkiMZ1RYsGh SywQTjOTxJz9LWBVbAI6EvuX/AazRQR6GSXW3GMCKWIWaGaUeLTsD5DDwSEsECAxc2U5SA2L gKpE74Y1TCA2r4CbxJbNt6HOUJBYcO8tG4jNKeAusb7vMguILQRUc2/efXaQmRICx9glDix5 zQ4xSEDi2+RDLCDzJQRkJTYdYIaYIylxcMUNlgmMwgsYGVYxiqYWJBcUJ6UXGekVJ+YWl+al 6yXn525iBMbG6X/P+nYw3jxgfYgxGWjcRGYp0eR8YGzllcQbGpsZWZiamBobmVuakSasJM6r 1mIdKCSQnliSmp2aWpBaFF9UmpNafIiRiYNTqoEx54wwr9HNo9m8f7UiYv+bfsmzzl+v89g6 0OoL69079ou0QsslWERzN9xS5uQRPtU1hT1hzUOuxP6+me7VKy3+RrJq2mnOdQyZfIBFW8F6 r6LQpGUzJd3P1i+wXZSfriy2b9l6F3cG+dz0Wb2zv8kGsrQr/hdZbiCQGcq2u+Zy7g+TY/ti HyqxFGckGmoxFxUnAgABD31vowIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLIsWRmVeSWpSXmKPExsVy+t9jQV2/1BWBBteeKVr0njvJZLHw4V1m iytf37NZTLo/gcXibNMbdosvVx4yWVzeNYfNomfDVlaLU3c/s1vMmPySzYHLY++3BSwed67t YfPY/u0Bq8f97uNMHrf/PWb26NuyitHj8ya5APaoBkabjNTElNQihdS85PyUzLx0WyXv4Hjn eFMzA0NdQ0sLcyWFvMTcVFslF58AXbfMHKADlRTKEnNKgUIBicXFSvp2mCaEhrjpWsA0Ruj6 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 Cc: daniel.vetter@ffwll.ch, kyungmin.park@samsung.com, sw0312.kim@samsung.com, linux-kernel@vger.kernel.org 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 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;