From patchwork Thu May 17 08:37:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 8705 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 1C43A23EAB for ; Thu, 17 May 2012 08:37:44 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id C9779A186B1 for ; Thu, 17 May 2012 08:37:43 +0000 (UTC) Received: by ggnf1 with SMTP id f1so1901584ggn.11 for ; Thu, 17 May 2012 01:37:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=miyzBygfOwvdXeyMW6kNYJss+p5FQLwvtQ/oQobulpQ=; b=Ywk0uF8z67d20OFAzbNAQftSXqKgDjaa3NOSQRkHYACglFjXmMop9zsB3umwQDMVLO YJh0M0YDnCIMJOhPSEuog+twJRBwMoVv8uwzoMi+WpAQMGkh0pn/fskgC079Xcsm4AHZ 16M9ISZjZEeHoUw1EoaHSpvBjW9aViHe5Irml2LGBP81rWVx1k+hgdB+KID1mLvvOGGs H4WyAW8m9ASuQyPs7AKs8RJNV6OlqkOr2bu3H5M0ZygFb4r/TgiP+fLhG40EraM/uDZk ZaLXmlXo72rkLyG16gittHn65NQ/GdR41dkJTAxeOn1uRzYgcd81xQuSHY7H3/lUW1pg 1SQw== Received: by 10.50.40.193 with SMTP id z1mr4584426igk.0.1337243862618; Thu, 17 May 2012 01:37:42 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp11763ibd; Thu, 17 May 2012 01:37:41 -0700 (PDT) Received: by 10.180.93.38 with SMTP id cr6mr15930752wib.16.1337243861397; Thu, 17 May 2012 01:37:41 -0700 (PDT) Received: from mail-we0-f178.google.com (mail-we0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id m60si6434216wee.64.2012.05.17.01.37.41 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 May 2012 01:37:41 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 74.125.82.178 as permitted sender) client-ip=74.125.82.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 74.125.82.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-we0-f178.google.com with SMTP id e53so1340832wer.37 for ; Thu, 17 May 2012 01:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=miyzBygfOwvdXeyMW6kNYJss+p5FQLwvtQ/oQobulpQ=; b=OlWSVcABBmMqKviPB8PB31X5Eq2zU0xsLswp8x0cXaIGCQWoZ+WIS6QVlSslP3NE3L Mf/f52vt6kkhziOw+9HtGzNHlkfIaGCX4Pumth7xO9fgP2Gm4uJDCO+Muv1AlJBbtEyr xALLfRyOx1OFlHGX0WcsCq7WdItOunPQ24ZsNS85FE3dim5fX4P6ZzPX4bMxxU1Bx1FP M/88ChWXl1y7L4f4BgYqiJbg+QeMxHa2+1fRGLjKVyYFyDIjZ0VOJosRWx3I3aEl/Yk8 SmuwqzU568R04VHjj7kzdpM3z1kAF1BYkz8fBqjThgxTWFQ4FbQ7BOTXB0mGJw4eullA YhRg== Received: by 10.180.107.101 with SMTP id hb5mr16106053wib.7.1337243860878; Thu, 17 May 2012 01:37:40 -0700 (PDT) Received: from localhost (host-92-29-250-134.as13285.net. [92.29.250.134]) by mx.google.com with ESMTPS id ga8sm18774498wib.5.2012.05.17.01.37.39 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 May 2012 01:37:40 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org Cc: patches@linaro.org, Greg KH , Tomi Valkeinen , Andy Gross , Rob Clark Subject: [PATCH 2/2] staging: drm/omap: initial dmabuf/prime import support Date: Thu, 17 May 2012 02:37:26 -0600 Message-Id: <1337243846-27942-3-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1337243846-27942-1-git-send-email-rob.clark@linaro.org> References: <1337243846-27942-1-git-send-email-rob.clark@linaro.org> X-Gm-Message-State: ALoCoQn8nchG/YwjPggK/2NMyM3Ss852I49kzO+ouFfQtdsaWi6mya4qOvpl7QL5d5cKE22gTGhO From: Rob Clark This adds support to re-import omapdrm's own buffers. Importing buffers allocated by other drivers can be added later, but for now is not needed (we don't yet have any other exportering drivers to test with). Signed-off-by: Rob Clark --- drivers/staging/omapdrm/omap_drv.c | 2 ++ drivers/staging/omapdrm/omap_drv.h | 2 ++ drivers/staging/omapdrm/omap_gem_dmabuf.c | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/drivers/staging/omapdrm/omap_drv.c b/drivers/staging/omapdrm/omap_drv.c index 1f559f4..0d2acca 100644 --- a/drivers/staging/omapdrm/omap_drv.c +++ b/drivers/staging/omapdrm/omap_drv.c @@ -767,7 +767,9 @@ static struct drm_driver omap_drm_driver = { .debugfs_cleanup = omap_debugfs_cleanup, #endif .prime_handle_to_fd = drm_gem_prime_handle_to_fd, + .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = omap_gem_prime_export, + .gem_prime_import = omap_gem_prime_import, .gem_init_object = omap_gem_init_object, .gem_free_object = omap_gem_free_object, .gem_vm_ops = &omap_gem_vm_ops, diff --git a/drivers/staging/omapdrm/omap_drv.h b/drivers/staging/omapdrm/omap_drv.h index 73a606e..f238d57 100644 --- a/drivers/staging/omapdrm/omap_drv.h +++ b/drivers/staging/omapdrm/omap_drv.h @@ -162,6 +162,8 @@ size_t omap_gem_mmap_size(struct drm_gem_object *obj); struct dma_buf * omap_gem_prime_export(struct drm_device *dev, struct drm_gem_object *obj, int flags); +struct drm_gem_object * omap_gem_prime_import(struct drm_device *dev, + struct dma_buf *buffer); static inline int align_pitch(int pitch, int width, int bpp) { diff --git a/drivers/staging/omapdrm/omap_gem_dmabuf.c b/drivers/staging/omapdrm/omap_gem_dmabuf.c index aba4b34..42728e0 100644 --- a/drivers/staging/omapdrm/omap_gem_dmabuf.c +++ b/drivers/staging/omapdrm/omap_gem_dmabuf.c @@ -196,3 +196,25 @@ struct dma_buf * omap_gem_prime_export(struct drm_device *dev, { return dma_buf_export(obj, &omap_dmabuf_ops, obj->size, 0600); } + +struct drm_gem_object * omap_gem_prime_import(struct drm_device *dev, + struct dma_buf *buffer) +{ + struct drm_gem_object *obj; + + /* is this one of own objects? */ + if (buffer->ops == &omap_dmabuf_ops) { + obj = buffer->priv; + /* is it from our device? */ + if (obj->dev == dev) { + drm_gem_object_reference(obj); + return obj; + } + } + + /* + * TODO add support for importing buffers from other devices.. + * for now we don't need this but would be nice to add eventually + */ + return ERR_PTR(-EINVAL); +}