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: 13412 Received: from mail.tu-berlin.de ([130.149.7.33]) by www.linuxtv.org with esmtp (Exim 4.72) (envelope-from ) id 1SrtXf-0007S9-Gb for patchwork@linuxtv.org; Thu, 19 Jul 2012 18:25:31 +0200 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-2) with esmtp for id 1SrtXe-0003O5-IZ; Thu, 19 Jul 2012 18:25:31 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751651Ab2GSQZD (ORCPT ); Thu, 19 Jul 2012 12:25:03 -0400 Received: from mail-ob0-f174.google.com ([209.85.214.174]:65413 "EHLO mail-ob0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750894Ab2GSQY7 (ORCPT ); Thu, 19 Jul 2012 12:24:59 -0400 Received: by obbuo13 with SMTP id uo13so3892600obb.19 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 Cc: patches@linaro.org, linux@arm.linux.org.uk, arnd@arndb.de, jesse.barker@linaro.org, m.szyprowski@samsung.com, daniel@ffwll.ch, t.stanislaws@samsung.com, sumit.semwal@ti.com, maarten.lankhorst@canonical.com, Rob Clark 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> 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: 2012.7.19.161816 X-PMX-Spam: Gauge=IIIIIIII, Probability=8%, Report=' MULTIPLE_RCPTS 0.1, HTML_00_01 0.05, HTML_00_10 0.05, BODY_SIZE_3000_3999 0, BODY_SIZE_5000_LESS 0, BODY_SIZE_7000_LESS 0, DATE_TZ_NA 0, DATE_TZ_NEG_0500 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, __MIME_TEXT_ONLY 0, __MULTIPLE_RCPTS_CC_X2 0, __MULTIPLE_RCPTS_TO_X5 0, __SANE_MSGID 0, __SUBJ_ALPHA_END 0, __TO_MALFORMED_2 0, __TO_NO_NAME 0, __URI_NO_WWW 0, __URI_NS ' 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) {