From patchwork Thu Jul 19 16:23:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 1218061 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id C4C4F3FC5A for ; Thu, 19 Jul 2012 16:33:03 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1SrtYM-0005B0-V9; Thu, 19 Jul 2012 16:26:15 +0000 Received: from mail-ob0-f177.google.com ([209.85.214.177]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1SrtXA-00058J-Ak for linux-arm-kernel@lists.infradead.org; Thu, 19 Jul 2012 16:25:02 +0000 Received: by obbta17 with SMTP id ta17so4102332obb.36 for ; Thu, 19 Jul 2012 09:24:58 -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=y2LGSu+ZZFZHdHtTe6RO0OTUmHtpDvQAD5xM8kyeoYg=; b=qcd15a+6OonT+v0HAYHchXWOik38xgUSm4gM+gLSR33OpXiPwUhN/6mCmGPAbmHILG 7Y4Mp5rEsSbThUkE8uuwWKQK6/GE6trlG45B8uvOpk7Sj0h1Mkpfrz+QnNAgPpl/TQYn 8zHfYVQv7MOiBXIBvvEGAXyi1GmRbX+kcIMSwe60OAeTOxgM2Mzc374xACc7jHzmvHYq SDsqHa4W1vUo1orfxILZAcapTLcuoOcnWIGtGfsBz5uh4yhAWM8Rs6Vd1OuhTZw9p7Fg ouJg5X5EQ0LP2Kie7vncYP3OszbFvlZX5Ty8LDKLb81kX/ZdS7hI2qnIYJ1j96lKD0S3 o6ww== Received: by 10.182.207.39 with SMTP id lt7mr3594710obc.67.1342715098324; Thu, 19 Jul 2012 09:24:58 -0700 (PDT) Received: from localhost (dragon.ti.com. [192.94.94.33]) by mx.google.com with ESMTPS id qd7sm2110921obc.5.2012.07.19.09.24.57 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 Jul 2012 09:24:57 -0700 (PDT) From: Rob Clark To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linaro-mm-sig@lists.linaro.org, dri-devel@lists.freedesktop.org, linux-media@vger.kernel.org Subject: [PATCH 2/2] dma-buf: add helpers for attacher dma-parms Date: Thu, 19 Jul 2012 11:23:34 -0500 Message-Id: <1342715014-5316-3-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1342715014-5316-1-git-send-email-rob.clark@linaro.org> References: <1342715014-5316-1-git-send-email-rob.clark@linaro.org> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.177 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (robdclark[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: t.stanislaws@samsung.com, linux@arm.linux.org.uk, sumit.semwal@ti.com, arnd@arndb.de, patches@linaro.org, jesse.barker@linaro.org, daniel@ffwll.ch, maarten.lankhorst@canonical.com, Rob Clark , m.szyprowski@samsung.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org From: Rob Clark Add some helpers to iterate through all attachers and get the most restrictive segment size/count/boundary. Signed-off-by: Rob Clark --- drivers/base/dma-buf.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/dma-buf.h | 19 ++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/drivers/base/dma-buf.c b/drivers/base/dma-buf.c index 24e88fe..757ee20 100644 --- a/drivers/base/dma-buf.c +++ b/drivers/base/dma-buf.c @@ -192,6 +192,69 @@ void dma_buf_put(struct dma_buf *dmabuf) EXPORT_SYMBOL_GPL(dma_buf_put); /** + * dma_buf_max_seg_size - helper for exporters to get the minimum of + * all attached device's max segment size + */ +unsigned int dma_buf_max_seg_size(struct dma_buf *dmabuf) +{ + struct dma_buf_attachment *attach; + unsigned int max = (unsigned int)-1; + + if (WARN_ON(!dmabuf)) + return 0; + + mutex_lock(&dmabuf->lock); + list_for_each_entry(attach, &dmabuf->attachments, node) + max = min(max, dma_get_max_seg_size(attach->dev)); + mutex_unlock(&dmabuf->lock); + + return max; +} +EXPORT_SYMBOL_GPL(dma_buf_max_seg_size); + +/** + * dma_buf_max_seg_count - helper for exporters to get the minimum of + * all attached device's max segment count + */ +unsigned int dma_buf_max_seg_count(struct dma_buf *dmabuf) +{ + struct dma_buf_attachment *attach; + unsigned int max = (unsigned int)-1; + + if (WARN_ON(!dmabuf)) + return 0; + + mutex_lock(&dmabuf->lock); + list_for_each_entry(attach, &dmabuf->attachments, node) + max = min(max, dma_get_max_seg_count(attach->dev)); + mutex_unlock(&dmabuf->lock); + + return max; +} +EXPORT_SYMBOL_GPL(dma_buf_max_seg_count); + +/** + * dma_buf_get_seg_boundary - helper for exporters to get the most + * restrictive segment alignment of all the attached devices + */ +unsigned int dma_buf_get_seg_boundary(struct dma_buf *dmabuf) +{ + struct dma_buf_attachment *attach; + unsigned int mask = (unsigned int)-1; + + if (WARN_ON(!dmabuf)) + return 0; + + mutex_lock(&dmabuf->lock); + list_for_each_entry(attach, &dmabuf->attachments, node) + mask &= dma_get_seg_boundary(attach->dev); + mutex_unlock(&dmabuf->lock); + + return mask; +} +EXPORT_SYMBOL_GPL(dma_buf_get_seg_boundary); + +/** * dma_buf_attach - Add the device to dma_buf's attachments list; optionally, * calls attach() of dma_buf_ops to allow device-specific attach functionality * @dmabuf: [in] buffer to attach device to. diff --git a/include/linux/dma-buf.h b/include/linux/dma-buf.h index eb48f38..9533b9b 100644 --- a/include/linux/dma-buf.h +++ b/include/linux/dma-buf.h @@ -167,6 +167,10 @@ 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); +unsigned int dma_buf_max_seg_size(struct dma_buf *dmabuf); +unsigned int dma_buf_max_seg_count(struct dma_buf *dmabuf); +unsigned int dma_buf_get_seg_boundary(struct dma_buf *dmabuf); + struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *, enum dma_data_direction); void dma_buf_unmap_attachment(struct dma_buf_attachment *, struct sg_table *, @@ -220,6 +224,21 @@ static inline void dma_buf_put(struct dma_buf *dmabuf) return; } +static inline unsigned int dma_buf_max_seg_size(struct dma_buf *dmabuf) +{ + return 0; +} + +static inline unsigned int dma_buf_max_seg_count(struct dma_buf *dmabuf) +{ + return 0; +} + +static inline unsigned int dma_buf_get_seg_boundary(struct dma_buf *dmabuf) +{ + return 0; +} + static inline struct sg_table *dma_buf_map_attachment( struct dma_buf_attachment *attach, enum dma_data_direction write) {