From patchwork Mon Mar 25 11:20:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 17605 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1UK5Sv-0000SP-MK; Mon, 25 Mar 2013 12:21:25 +0100 X-tubIT-Incoming-IP: 209.132.180.67 Received: from vger.kernel.org ([209.132.180.67]) by mail.tu-berlin.de (exim-4.75/mailfrontend-3) with esmtp id 1UK5Su-0004Hx-Ej; Mon, 25 Mar 2013 12:21:25 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755605Ab3CYLVW (ORCPT + 1 other); Mon, 25 Mar 2013 07:21:22 -0400 Received: from mail-da0-f41.google.com ([209.85.210.41]:57724 "EHLO mail-da0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754827Ab3CYLVW (ORCPT ); Mon, 25 Mar 2013 07:21:22 -0400 Received: by mail-da0-f41.google.com with SMTP id w4so3197400dam.28 for ; Mon, 25 Mar 2013 04:21:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=wYwNrAAKR4k2w7pyeRgzR0ffBb15KLEiy3dtN8+T1tE=; b=OYsIhwJxAD9QqZNCVz+PpUNftr4lEneHKWJDPvQESiAvNYhNEDa9KqFocLk+YB3aZK hy7UyndQojyg4nmYMVEcrWZVGNmJEWdDbeOHUcBkCwu9hC36YKmkw15RMVTUg83qFafg t+gWuqNDBJrGVpp0BRPi6W5XJbSqTSQQaYOaPjIFspaCQKDmsFW2MXQlV99eOvV7VDoi c8ExolE+ybQPCrmsMWMq2juFJYTKpdkQxDEjG34vNGVV67OSDoKjIsACsjytCVHQF2Hh OsXUmqPmBNY78BX3a1vaj6Oim0mK6p/iZaccyMvIQ8gqmnQCwUaRLn+8ii+ZJlza/JKI IEIQ== X-Received: by 10.68.253.230 with SMTP id ad6mr16878877pbd.116.1364210481446; Mon, 25 Mar 2013 04:21:21 -0700 (PDT) Received: from localhost.localdomain ([122.179.30.114]) by mx.google.com with ESMTPS id lb8sm14510367pab.13.2013.03.25.04.21.16 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Mar 2013 04:21:20 -0700 (PDT) From: Sumit Semwal To: linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: patches@linaro.org, linaro-kernel@lists.linaro.org, Sumit Semwal , Daniel Vetter Subject: [PATCH 1/2] dma-buf: replace dma_buf_export() with dma_buf_export_named() Date: Mon, 25 Mar 2013 16:50:45 +0530 Message-Id: <1364210447-8125-2-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1364210447-8125-1-git-send-email-sumit.semwal@linaro.org> References: <1364210447-8125-1-git-send-email-sumit.semwal@linaro.org> X-Gm-Message-State: ALoCoQni9UCsE17X6p7qFIyAL0toqCITiXkSMO2ShzQXeyclQ7S2nnN1e9KY7szCvyyX3tLpy6ay Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-PMX-Version: 5.6.1.2065439, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2013.3.25.111214 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_5000_5999 0, BODY_SIZE_7000_LESS 0, URI_ENDS_IN_HTML 0, __ANY_URI 0, __CP_URI_IN_BODY 0, __HAS_FROM 0, __HAS_MSGID 0, __HAS_X_MAILER 0, __HAS_X_MAILING_LIST 0, __IN_REP_TO 0, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __SANE_MSGID 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS , __YOUTUBE_RCVD 0' For debugging purposes, it is useful to have a name-string added while exporting buffers. Hence, dma_buf_export() is replaced with dma_buf_export_named(), which additionally takes 'exp_name' as a parameter. For backward compatibility, and for lazy exporters who don't wish to name themselves, a #define dma_buf_export() is also made available, which adds a __FILE__ instead of 'exp_name'. Cc: Daniel Vetter [Thanks for the idea!] Signed-off-by: Sumit Semwal Reviewed-by: Daniel Vetter --- Documentation/dma-buf-sharing.txt | 13 +++++++++++-- drivers/base/dma-buf.c | 11 +++++++---- include/linux/dma-buf.h | 11 +++++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Documentation/dma-buf-sharing.txt b/Documentation/dma-buf-sharing.txt index 4966b1b..0b23261 100644 --- a/Documentation/dma-buf-sharing.txt +++ b/Documentation/dma-buf-sharing.txt @@ -52,14 +52,23 @@ The dma_buf buffer sharing API usage contains the following steps: associated with this buffer. Interface: - struct dma_buf *dma_buf_export(void *priv, struct dma_buf_ops *ops, - size_t size, int flags) + struct dma_buf *dma_buf_export_named(void *priv, struct dma_buf_ops *ops, + size_t size, int flags, + const char *exp_name) If this succeeds, dma_buf_export allocates a dma_buf structure, and returns a pointer to the same. It also associates an anonymous file with this buffer, so it can be exported. On failure to allocate the dma_buf object, it returns NULL. + 'exp_name' is the name of exporter - to facilitate information while + debugging. + + Exporting modules which do not wish to provide any specific name may use the + helper define 'dma_buf_export()', with the same arguments as above, but + without the last argument; a __FILE__ pre-processor directive will be + inserted in place of 'exp_name' instead. + 2. Userspace gets a handle to pass around to potential buffer-users Userspace entity requests for a file-descriptor (fd) which is a handle to the diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 2a7cb0d..d89102a 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -77,22 +77,24 @@ static inline int is_dma_buf_file(struct file *file) } /** - * dma_buf_export - Creates a new dma_buf, and associates an anon file + * dma_buf_export_named - Creates a new dma_buf, and associates an anon file * with this buffer, so it can be exported. * Also connect the allocator specific data and ops to the buffer. + * Additionally, provide a name string for exporter; useful in debugging. * * @priv: [in] Attach private data of allocator to this buffer * @ops: [in] Attach allocator-defined dma buf ops to the new buffer. * @size: [in] Size of the buffer * @flags: [in] mode flags for the file. + * @exp_name: [in] name of the exporting module - useful for debugging. * * Returns, on success, a newly created dma_buf object, which wraps the * supplied private data and operations for dma_buf_ops. On either missing * ops, or error in allocating struct dma_buf, will return negative error. * */ -struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, - size_t size, int flags) +struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops, + size_t size, int flags, const char *exp_name) { struct dma_buf *dmabuf; struct file *file; @@ -114,6 +116,7 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, dmabuf->priv = priv; dmabuf->ops = ops; dmabuf->size = size; + dmabuf->exp_name = exp_name; file = anon_inode_getfile("dmabuf", &dma_buf_fops, dmabuf, flags); @@ -124,7 +127,7 @@ struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, return dmabuf; } -EXPORT_SYMBOL_GPL(dma_buf_export); +EXPORT_SYMBOL_GPL(dma_buf_export_named); /** diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index 9978b61..6f55c04 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -112,6 +112,7 @@ struct dma_buf_ops { * @file: file pointer used for sharing buffers across, and for refcounting. * @attachments: list of dma_buf_attachment that denotes all devices attached. * @ops: dma_buf_ops associated with this buffer object. + * @exp_name: name of the exporter; useful for debugging. * @priv: exporter specific private data for this buffer object. */ struct dma_buf { @@ -123,6 +124,7 @@ struct dma_buf { struct mutex lock; unsigned vmapping_counter; void *vmap_ptr; + const char *exp_name; void *priv; }; @@ -162,8 +164,13 @@ struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, struct device *dev); void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *dmabuf_attach); -struct dma_buf *dma_buf_export(void *priv, const struct dma_buf_ops *ops, - size_t size, int flags); + +struct dma_buf *dma_buf_export_named(void *priv, const struct dma_buf_ops *ops, + size_t size, int flags, const char *); + +#define dma_buf_export(priv, ops, size, flags) \ + dma_buf_export_named(priv, ops, size, flags, __FILE__) + int dma_buf_fd(struct dma_buf *dmabuf, int flags); struct dma_buf *dma_buf_get(int fd); void dma_buf_put(struct dma_buf *dmabuf);