From patchwork Tue Apr 9 11:37:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 2414601 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 772203FD8C for ; Tue, 9 Apr 2013 11:38:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7009EE5C87 for ; Tue, 9 Apr 2013 04:38:12 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-we0-f177.google.com (mail-we0-f177.google.com [74.125.82.177]) by gabe.freedesktop.org (Postfix) with ESMTP id 5792EE5C2B for ; Tue, 9 Apr 2013 04:37:56 -0700 (PDT) Received: by mail-we0-f177.google.com with SMTP id o45so5306634wer.22 for ; Tue, 09 Apr 2013 04:37: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; bh=rBf4g7klvhwVH/uxxXuvtWS65KxEq3QfU9WV7/YBfjo=; b=KXBgjF1h2hppa9lZ/ubCGspWyW2Im/aw6og53Jt2lO7+z8jXqgJDHlhfEJk8EtLAZg ydE/u9m7X7/BF6v7ZgJiv16nyih/VEPtrg/c1FiWblvYAwosDWASXCMt37LUJpqCDIHh wWcR9yAp+sipfoNVoeGqS2h2WGRn5Xu4qiB/jZpDbNLTohIgsYW0jTJIDXE8a1ptXdUs TcDk7vnwU8/ZmT5AQTQyJIS/Mh96Xodrqj4e/01xDcwEBRbdNQv99pSFxydJe/2oYC8M W+VHWiA0a6E4uaQXh1Oc/TzLs069ZbI2h3kvObMrZ9VFZPFpBT7b9g7xPTv0OdF2wMSs IqbA== X-Received: by 10.180.74.67 with SMTP id r3mr18953124wiv.14.1365507475298; Tue, 09 Apr 2013 04:37:55 -0700 (PDT) Received: from localhost (5ED48CEF.cm-7-5c.dynamic.ziggo.nl. [94.212.140.239]) by mx.google.com with ESMTPS id s2sm28254640wib.4.2013.04.09.04.37.52 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 09 Apr 2013 04:37:53 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Tue, 09 Apr 2013 13:37:52 +0200 From: Maarten Lankhorst To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/7] drm: add unpin function to prime helpers Date: Tue, 9 Apr 2013 13:37:40 +0200 Message-Id: <1365507466-11586-1-git-send-email-maarten.lankhorst@canonical.com> X-Mailer: git-send-email 1.8.2 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 Prevents buffers from being pinned forever. Signed-off-by: Maarten Lankhorst Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_prime.c | 13 +++++++++++-- include/drm/drmP.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 366910d..85bbc52 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -91,10 +91,13 @@ 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); } } @@ -184,13 +187,19 @@ 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); } - return dma_buf_export(obj, &drm_gem_prime_dmabuf_ops, obj->size, - 0600); + buf = 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); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 2d94d74..99dc622 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -932,6 +932,7 @@ struct drm_driver { struct dma_buf *dma_buf); /* low-level interface used by drm_gem_prime_{import,export} */ int (*gem_prime_pin)(struct drm_gem_object *obj); + void (*gem_prime_unpin)(struct drm_gem_object *obj); struct sg_table *(*gem_prime_get_sg_table)(struct drm_gem_object *obj); struct drm_gem_object *(*gem_prime_import_sg_table)( struct drm_device *dev, size_t size,