From patchwork Tue Apr 9 11:37:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 2414611 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id 6CE34DF25A for ; Tue, 9 Apr 2013 11:38:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 55817E60A0 for ; Tue, 9 Apr 2013 04:38:59 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wg0-f46.google.com (mail-wg0-f46.google.com [74.125.82.46]) by gabe.freedesktop.org (Postfix) with ESMTP id DA45BE6036 for ; Tue, 9 Apr 2013 04:37:58 -0700 (PDT) Received: by mail-wg0-f46.google.com with SMTP id l18so6651643wgh.1 for ; Tue, 09 Apr 2013 04:37:58 -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=S8XX584QS/wGJg8sm1M5YYHDUhAgxcZvbjrAWjty9gQ=; b=wAaSd57hwCM9iinVJ8fCpOFlxZUtUXVy1anpXba7dDunmJ7XIgVNut5ORLRRalUAjz JBWLuNFf4zod/xgUnrM2rKAgYdUod/hxxm+CrAO2gK6ySpj0e0O1BOmiZ7qySP2+5cFj KhneUE9Pos5feB2Y1e45TgG5TIWYzcf/7gy6t2hOZdXPS5iOoSEniT5Tp/Ccuf0Jdb3Q 7xXAqmNEuammukZbYecImPuMMiWcI+SRS+iVO+YrDwwj5srA/6ZFEky8gr7N8mvVdiiF 2/oN1aOHA2KeQLAsaX7Bs2g2Rn1XycRCkVHhrbGc6z4NQ7eRzaIk42MWJ9HyU6gV7185 N6QA== X-Received: by 10.194.89.169 with SMTP id bp9mr37899372wjb.57.1365507478100; Tue, 09 Apr 2013 04:37:58 -0700 (PDT) Received: from localhost (5ED48CEF.cm-7-5c.dynamic.ziggo.nl. [94.212.140.239]) by mx.google.com with ESMTPS id bo1sm28288713wib.0.2013.04.09.04.37.55 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 09 Apr 2013 04:37:57 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Tue, 09 Apr 2013 13:37:55 +0200 From: Maarten Lankhorst To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/7] drm: move pinning/unpinning to buffer attach Date: Tue, 9 Apr 2013 13:37:41 +0200 Message-Id: <1365507466-11586-2-git-send-email-maarten.lankhorst@canonical.com> X-Mailer: git-send-email 1.8.2 In-Reply-To: <1365507466-11586-1-git-send-email-maarten.lankhorst@canonical.com> References: <1365507466-11586-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 --- 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);