From patchwork Thu May 4 18:45:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 9712509 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 282C760362 for ; Thu, 4 May 2017 18:46:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28112286B8 for ; Thu, 4 May 2017 18:46:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C831286BD; Thu, 4 May 2017 18:46:07 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 D00E1286BB for ; Thu, 4 May 2017 18:46:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BBA9E6E5AF; Thu, 4 May 2017 18:46:00 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt0-f177.google.com (mail-qt0-f177.google.com [209.85.216.177]) by gabe.freedesktop.org (Postfix) with ESMTPS id 099756E5AF for ; Thu, 4 May 2017 18:45:59 +0000 (UTC) Received: by mail-qt0-f177.google.com with SMTP id j29so17619110qtj.1 for ; Thu, 04 May 2017 11:45:59 -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=xDQvoBoJDSIHEN7ujnzF6kavZXkNLEavFmG4j2IgXDk=; b=PR1QoGERI/DQ5ANzlrrO/P0rr+lckakZUzHrdBfGoLdVVjm1pcxEf6GCpSv4uv0RlL hfrPYxVVKiZ0dFtL5siEfJ6OBZ79hV8ETK7cgnSuPF1udTwMIm/VkYRgc0H5u3h9QlS1 /PukSsP8J6pZmEjGGqcBIvrZQoCbqBdiUboSECXF3aIbltlM4p1+tynyD2gi2fpbnpLE sN9NI1J600FzS6mWzCpaPKkJwbCLxu6hBguZEI692Mi3oQrGIAPN+xeC19vUwwGRbOTf Wv3x/IdTZyisLHQZ3+SWsmyv+lfz4IGdSE1heZ3nGw7TzCtugV76j8ao75qXIsuF3GEw Xmkw== X-Gm-Message-State: AN3rC/4gD74mCnm00X0Q6TgR0HY4eMrZla8+2daePN0od7OtoR6qbY6z cgXC8NE2naPIS+EU X-Received: by 10.200.50.183 with SMTP id z52mr41852550qta.272.1493923558100; Thu, 04 May 2017 11:45:58 -0700 (PDT) Received: from labbott-redhat-machine.redhat.com ([2601:602:9802:a8dc::7f81]) by smtp.gmail.com with ESMTPSA id g3sm1943961qte.66.2017.05.04.11.45.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 11:45:56 -0700 (PDT) From: Laura Abbott To: Daniel Vetter , Chris Wilson , Sean Paul Subject: [PATCHv4 2/3] drm/prime: Introduce drm_gem_prime_import_dev Date: Thu, 4 May 2017 11:45:47 -0700 Message-Id: <1493923548-20878-3-git-send-email-labbott@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493923548-20878-1-git-send-email-labbott@redhat.com> References: <1493923548-20878-1-git-send-email-labbott@redhat.com> Cc: intel-gfx@lists.freedesktop.org, Joonas Lahtinen , 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 any available device structure. Signed-off-by: Laura Abbott Reviewed-by: Chris Wilson --- v4: Alternate implemntation to take an arbitrary struct dev instead of just a platform device. This was different enough that I dropped the previous Reviewed-by --- drivers/gpu/drm/drm_prime.c | 30 ++++++++++++++++++++++++------ include/drm/drm_prime.h | 5 +++++ 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index 9fb65b7..5ad9a26 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -595,15 +595,18 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev, EXPORT_SYMBOL(drm_gem_prime_handle_to_fd); /** - * drm_gem_prime_import - helper library implementation of the import callback + * drm_gem_prime_import_dev - core implementation of the import callback * @dev: drm_device to import into * @dma_buf: dma-buf object to import + * @attach_dev: struct device to dma_buf attach * - * This is the implementation of the gem_prime_import functions for GEM drivers - * using the PRIME helpers. + * This is the core of drm_gem_prime_import. It's designed to be called by + * drivers who want to use a different device structure than dev->dev for + * attaching via dma_buf. */ -struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, - struct dma_buf *dma_buf) +struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev, + struct dma_buf *dma_buf, + struct device *attach_dev) { struct dma_buf_attachment *attach; struct sg_table *sgt; @@ -625,7 +628,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); @@ -655,6 +658,21 @@ struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, return ERR_PTR(ret); } +EXPORT_SYMBOL(drm_gem_prime_import_dev); + +/** + * drm_gem_prime_import - helper library implementation of the import callback + * @dev: drm_device to import into + * @dma_buf: dma-buf object to import + * + * 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) +{ + return drm_gem_prime_import_dev(dev, dma_buf, dev->dev); +} EXPORT_SYMBOL(drm_gem_prime_import); /** diff --git a/include/drm/drm_prime.h b/include/drm/drm_prime.h index 0b2a235..46fd1fb 100644 --- a/include/drm/drm_prime.h +++ b/include/drm/drm_prime.h @@ -65,6 +65,11 @@ int drm_gem_prime_handle_to_fd(struct drm_device *dev, int *prime_fd); struct drm_gem_object *drm_gem_prime_import(struct drm_device *dev, struct dma_buf *dma_buf); + +struct drm_gem_object *drm_gem_prime_import_dev(struct drm_device *dev, + struct dma_buf *dma_buf, + struct device *attach_dev); + 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,