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: 9712511 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 4F0DB60362 for ; Thu, 4 May 2017 18:46:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FBFF286B5 for ; Thu, 4 May 2017 18:46:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A44F286C0; Thu, 4 May 2017 18:46:08 +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=unavailable 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 30BA3286C1 for ; Thu, 4 May 2017 18:46:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E63596E5B6; Thu, 4 May 2017 18:46:01 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mail-qt0-f172.google.com (mail-qt0-f172.google.com [209.85.216.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0E5636E5B0 for ; Thu, 4 May 2017 18:45:59 +0000 (UTC) Received: by mail-qt0-f172.google.com with SMTP id n4so17566139qte.2 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=mEDhB45NlvHibzuy1m3sCbsEHnzLMZbVbpM2QaWRHnHeEeEiLeQHZv0+r6ou4Ze0HJ gjg6ze7UaQvYZJNQtAiD2TarPqz8Ao4qNM1pL8oJsHb1O3yxK6Vc82xxrs7cDfKnLQ9c hoq5POOPWctcfwJ6Cz6/NuJP3bEt30AMTrubg3nbxvlP8w7K82Fps5rVUO2p4DDP2nPF uqe6Tf3g1HhSafhiCYRpGhIyyNelzjPk7rSbxnSur0d+brVd/uMQ4t/2LBwxgoxXW4Qd wZlp4sU4qqQfH1htvd85Cd30ihKngwUkvUAkRWKjUpop8+/jpsf2lVHNtMJaIYc2DuRy Szdg== X-Gm-Message-State: AN3rC/6cYwx1ObYpT99XXvUdL6wBccYt6k1dDz9W8tJ745W4tRWjJCJR 2zc5hWcJs7Tp5PvX 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 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, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Laura Abbott , Sumit Semwal Subject: [Intel-gfx] [PATCHv4 2/3] drm/prime: Introduce drm_gem_prime_import_dev X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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,