From patchwork Thu Apr 4 06:28:32 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Semwal X-Patchwork-Id: 15893 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 AF2DF23DEE for ; Thu, 4 Apr 2013 06:29:12 +0000 (UTC) Received: from mail-ye0-f197.google.com (mail-ye0-f197.google.com [209.85.213.197]) by fiordland.canonical.com (Postfix) with ESMTP id 5539DA18CAD for ; Thu, 4 Apr 2013 06:29:12 +0000 (UTC) Received: by mail-ye0-f197.google.com with SMTP id q1sf3063816yen.0 for ; Wed, 03 Apr 2013 23:29:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:x-beenthere:x-received:received-spf :x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=OpRuc978ZnaHs5Az3mIU1x0j73jqgnyIXxu45wg9yVc=; b=d/SWZB9lupnCqAX8dc828203u0KGf23WP7Zz2Beb3LHVct4M+XR+FRFzq6FJpfoasx ES1RP1M7ioieO/P8wPEek8D9EKRjJlvvT4Bmtj2drZoWoOx6dsx97o7BpmHh/tYfPPJT MFeCI3niwFhy+xtJC3HammmvQ/wM47yIdESu46LO+NR5gw7aIctqpnv05Nvk6akbfKyj UmWgMU3G8H8L6D33h+6FVvg46BsKWwH+OMbtpyFF2lkdclIfSEODYTRGlYIT/vz6GIQz Kidex1DfqSk0U9G3RtV3aW9u/deU3Inukpxz2Wd8mIYDZxtpZDXcB1rvQIZ0M4dcIEGC 1zMw== X-Received: by 10.224.157.1 with SMTP id z1mr2709550qaw.8.1365056951891; Wed, 03 Apr 2013 23:29:11 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.4.67 with SMTP id i3ls1199970qei.92.gmail; Wed, 03 Apr 2013 23:29:11 -0700 (PDT) X-Received: by 10.58.45.71 with SMTP id k7mr3809816vem.0.1365056951784; Wed, 03 Apr 2013 23:29:11 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id tt5si7411400vec.13.2013.04.03.23.29.11 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 23:29:11 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id m16so311741vca.14 for ; Wed, 03 Apr 2013 23:29:11 -0700 (PDT) X-Received: by 10.220.192.3 with SMTP id do3mr3757330vcb.16.1365056951641; Wed, 03 Apr 2013 23:29:11 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.85.136 with SMTP id h8csp202458vez; Wed, 3 Apr 2013 23:29:11 -0700 (PDT) X-Received: by 10.68.136.197 with SMTP id qc5mr7051734pbb.28.1365056950385; Wed, 03 Apr 2013 23:29:10 -0700 (PDT) Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by mx.google.com with ESMTPS id iw4si10075862pac.95.2013.04.03.23.29.10 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 23:29:10 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.45 is neither permitted nor denied by best guess record for domain of sumit.semwal@linaro.org) client-ip=209.85.220.45; Received: by mail-pa0-f45.google.com with SMTP id kl13so1314445pab.32 for ; Wed, 03 Apr 2013 23:29:10 -0700 (PDT) X-Received: by 10.68.252.136 with SMTP id zs8mr2231484pbc.36.1365056949972; Wed, 03 Apr 2013 23:29:09 -0700 (PDT) Received: from localhost.localdomain ([122.172.176.105]) by mx.google.com with ESMTPS id pl10sm5353036pbc.1.2013.04.03.23.29.06 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Apr 2013 23:29:09 -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 v3 1/2] dma-buf: replace dma_buf_export() with dma_buf_export_named() Date: Thu, 4 Apr 2013 11:58:32 +0530 Message-Id: <1365056913-25772-2-git-send-email-sumit.semwal@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1365056913-25772-1-git-send-email-sumit.semwal@linaro.org> References: <1365056913-25772-1-git-send-email-sumit.semwal@linaro.org> X-Gm-Message-State: ALoCoQn6UG7UQB0McD3vP5eSHl59Hbduo1E2bR/p9P3tGOFCdLuZcHwc9ugeDL63+j+kW3IW56PY X-Original-Sender: sumit.semwal@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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!] Reviewed-by: Daniel Vetter Signed-off-by: Sumit Semwal --- 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);