From patchwork Wed Apr 26 21:12:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9702021 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A809360245 for ; Wed, 26 Apr 2017 21:12:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 978B928404 for ; Wed, 26 Apr 2017 21:12:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C7C928470; Wed, 26 Apr 2017 21:12:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4985728404 for ; Wed, 26 Apr 2017 21:12:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 808686E5D8; Wed, 26 Apr 2017 21:12:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk0-f179.google.com (mail-qk0-f179.google.com [209.85.220.179]) by gabe.freedesktop.org (Postfix) with ESMTPS id 259A26E5D8 for ; Wed, 26 Apr 2017 21:12:44 +0000 (UTC) Received: by mail-qk0-f179.google.com with SMTP id u75so12254180qka.3 for ; Wed, 26 Apr 2017 14:12:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=j7z63iLgSDpr34WClIWwheAm2TeEAGK7TEntgCRk8ZE=; b=ipPjq8OmiV9bojLbhixEGBDhXgo7C4UUtXRpRpgX+rYmxmtdYd1S6mr6n1erGrP1XF r3qkBUk236NypchkhqhXR1fajk7AvQi5F2ItVYz8lRWETHyzDkRG6geXBeS9GsEFgYY8 AfoWxTBdjD5r1YlKMGU8bXvQccz7uhVh4VvBty+JzmC4tL/MoU0ZjtVBUDW8B+lAI6tR UDzDypqOfiO06lk98G3OJ49WmW3N/SvcH1JX+28GhKDNUhOccNbLVOlSa6kY1JTq6omS 4FtyT6DHACionTxhgTsiCsg3VoCM/HkN8mU4gDEhW1AcjyqlhB0iC/InwLpN2r2HdP8Q ZHiQ== X-Gm-Message-State: AN3rC/6M5PQSizIaE4WHJfoh1vM5nVnI6tKRICkGn16LKLAtrCaV9XOl Nma1X1SapJHeevF9 X-Received: by 10.55.26.27 with SMTP id a27mr1750080qka.73.1493241163244; Wed, 26 Apr 2017 14:12:43 -0700 (PDT) Received: from labbott-redhat-machine.redhat.com ([2601:602:9802:a8dc::736e]) by smtp.gmail.com with ESMTPSA id c21sm290477qkg.64.2017.04.26.14.12.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Apr 2017 14:12:42 -0700 (PDT) From: Laura Abbott To: Daniel Vetter , Chris Wilson , Sean Paul Subject: [RFC PATCHv2 2/3] drm/prime: Introduce drm_gem_prime_import_platform Date: Wed, 26 Apr 2017 14:12:29 -0700 Message-Id: <1493241150-21742-3-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493241150-21742-1-git-send-email-labbott@redhat.com> References: <1493241150-21742-1-git-send-email-labbott@redhat.com> Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The existing drm_gem_prime_import function uses the underlying struct device of a drm_device for attaching to a dma_buf. Some drivers (notably vgem) may not have an underlying device structure. Offer an alternate function to attach using a platform device associated with drm_device. Signed-off-by: Laura Abbott --- New approach for v2 --- drivers/gpu/drm/drm_prime.c | 23 ++++++++++++++++++++--- include/drm/drmP.h | 5 +++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 25aa455..5486248 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -601,8 +601,9 @@ EXPORT_SYMBOL(drm_gem_prime_handle_to_fd); * This is the implementation of the gem_prime_import functions for GEM drivers * using the PRIME helpers. */ -struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, - struct dma_buf *dma_buf) +static struct drm_gem_object *__drm_gem_prime_import(struct drm_device *dev, + struct dma_buf *dma_buf, + struct device *attach_dev) { struct dma_buf_attachment *attach; struct sg_table *sgt; @@ -624,7 +625,7 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, if (!dev->driver->gem_prime_import_sg_table) return ERR_PTR(-EINVAL); - attach = dma_buf_attach(dma_buf, dev->dev); + attach = dma_buf_attach(dma_buf, attach_dev); if (IS_ERR(attach)) return ERR_CAST(attach); @@ -654,8 +655,24 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, return ERR_PTR(ret); } + +struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, + struct dma_buf *dma_buf) +{ + return __drm_gem_prime_import(dev, dma_buf, dev->dev); +} EXPORT_SYMBOL(drm_gem_prime_import); +struct drm_gem_object *drm_gem_prime_import_platform(struct drm_device *dev, + struct dma_buf *dma_buf) +{ + if (WARN_ON_ONCE(!dev->platformdev)) + return NULL; + + return __drm_gem_prime_import(dev, dma_buf, &dev->platformdev->dev); +} +EXPORT_SYMBOL(drm_gem_prime_import_platform); + /** * drm_gem_prime_fd_to_handle - PRIME import function for GEM drivers * @dev: dev to export the buffer from diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 6105c05..f4ac30f 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -769,6 +769,11 @@ extern int drm_gem_prime_handle_to_fd(struct drm_device *dev, int *prime_fd); extern struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf); + +extern struct drm_gem_object *drm_gem_prime_import_platform( + struct drm_device *dev, + struct dma_buf *dma_buf); + extern int drm_gem_prime_fd_to_handle(struct drm_device *dev, struct drm_file *file_priv, int prime_fd, uint32_t *handle); struct dma_buf *drm_gem_dmabuf_export(struct drm_device *dev,