From patchwork Wed May 1 08:52:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 2507211 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 C71853FD85 for ; Wed, 1 May 2013 08:56:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DC2B9E6161 for ; Wed, 1 May 2013 01:56:59 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-we0-f178.google.com (mail-we0-f178.google.com [74.125.82.178]) by gabe.freedesktop.org (Postfix) with ESMTP id ABF32E61C7 for ; Wed, 1 May 2013 01:52:56 -0700 (PDT) Received: by mail-we0-f178.google.com with SMTP id t11so1049080wey.23 for ; Wed, 01 May 2013 01:52:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=ncr8wCvWwzJIqDLWV3YEKvVYNHqZWhM447iXhFZsjzg=; b=PkP3gFfCZTiOPCvNITxL/zLHnwVNOa//rF4tBRTBd3d225w30IWdUx5gwYoNiFSWBU iFhmV0RSllwFEb6E08SsCtpSs61w7gxhfJCaum3Nm/iqNV+QA2IHCzku12mTJpWlKkAG JGrzyytDZuPcPqkuJM2ndNjsxSZWxgC7dIontZGxoM5ili5YWbi5Y1LaEsJUUDcF82Y8 GmMsLoKZ/8DNXK1okRZfHS344xdvmuZEqr7N9niLHYaPA4X3sw5i1kFQ8s8vYcdYzkv0 RhS/RL7fRJpg/NwzvC/T23/+vjScCxjYD3uzLHECjODtniGACvKH3pSZuNYKw3UpYx57 NztQ== X-Received: by 10.194.62.174 with SMTP id z14mr1890410wjr.20.1367398375807; Wed, 01 May 2013 01:52:55 -0700 (PDT) Received: from localhost (5ED49945.cm-7-5c.dynamic.ziggo.nl. [94.212.153.69]) by mx.google.com with ESMTPSA id q18sm30811878wiw.8.2013.05.01.01.52.54 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 01 May 2013 01:52:55 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Wed, 01 May 2013 10:52:53 +0200 From: Maarten Lankhorst To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/7] drm: move pinning/unpinning to buffer attach Date: Wed, 1 May 2013 10:52:39 +0200 Message-Id: <1367398364-28997-2-git-send-email-maarten.lankhorst@canonical.com> X-Mailer: git-send-email 1.8.2.2 In-Reply-To: <1367398364-28997-1-git-send-email-maarten.lankhorst@canonical.com> References: <1367398364-28997-1-git-send-email-maarten.lankhorst@canonical.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 allows importing bo's to own device to work without requiring that the buffer is pinned in GART. Signed-off-by: Maarten Lankhorst Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_prime.c | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 85bbc52..16b302a 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -63,6 +63,29 @@ struct drm_prime_member { uint32_t handle; }; +static int drm_gem_map_attach(struct dma_buf *dma_buf, + struct device *target_dev, + struct dma_buf_attachment *attach) +{ + struct drm_gem_object *obj = dma_buf->priv; + struct drm_device *dev = obj->dev; + + if (!dev->driver->gem_prime_pin) + return 0; + + return dev->driver->gem_prime_pin(obj); +} + +static void drm_gem_map_detach(struct dma_buf *dma_buf, + struct dma_buf_attachment *attach) +{ + struct drm_gem_object *obj = dma_buf->priv; + struct drm_device *dev = obj->dev; + + if (dev->driver->gem_prime_unpin) + dev->driver->gem_prime_unpin(obj); +} + static struct sg_table *drm_gem_map_dma_buf(struct dma_buf_attachment *attach, enum dma_data_direction dir) { @@ -91,13 +114,10 @@ static void drm_gem_unmap_dma_buf(struct dma_buf_attachment *attach, static void drm_gem_dmabuf_release(struct dma_buf *dma_buf) { struct drm_gem_object *obj = dma_buf->priv; - struct drm_device *dev = obj->dev; if (obj->export_dma_buf == dma_buf) { /* drop the reference on the export fd holds */ obj->export_dma_buf = NULL; - if (dev->driver->gem_prime_unpin) - dev->driver->gem_prime_unpin(obj); drm_gem_object_unreference_unlocked(obj); } } @@ -148,6 +168,8 @@ static int drm_gem_dmabuf_mmap(struct dma_buf *dma_buf, } static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = { + .attach = drm_gem_map_attach, + .detach = drm_gem_map_detach, .map_dma_buf = drm_gem_map_dma_buf, .unmap_dma_buf = drm_gem_unmap_dma_buf, .release = drm_gem_dmabuf_release, @@ -187,19 +209,8 @@ static const struct dma_buf_ops drm_gem_prime_dmabuf_ops = { struct dma_buf *drm_gem_prime_export(struct drm_device *dev, struct drm_gem_object *obj, int flags) { - struct dma_buf *buf; - - if (dev->driver->gem_prime_pin) { - int ret = dev->driver->gem_prime_pin(obj); - if (ret) - return ERR_PTR(ret); - } - buf = dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size, + return dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size, 0600); - - if (IS_ERR(buf) && dev->driver->gem_prime_unpin) - dev->driver->gem_prime_unpin(obj); - return buf; } EXPORT_SYMBOL(drm_gem_prime_export);