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: 10152 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 1EDC423E56 for ; Thu, 19 Jul 2012 16:25:00 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id DFD6FA182B6 for ; Thu, 19 Jul 2012 16:24:59 +0000 (UTC) Received: by mail-gh0-f180.google.com with SMTP id z12so3183260ghb.11 for ; Thu, 19 Jul 2012 09:24:59 -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=y2LGSu+ZZFZHdHtTe6RO0OTUmHtpDvQAD5xM8kyeoYg=; b=GxumiRoVFz9iyNFGYvvpxeAU3pksJbYTmuAfUFOCiOa7eAbdpJv/dgcBfJXQf9Kfad Zk01phAopQMr0v91+f0A0tA/EhKhZc8/GwcKQ/Un2YhrfDEot5vuzRRKgSHbUgBK5wdP t/1cy5ud18OB+7O+8UL/Sj6xZUAePKH5AkixyiQvwAs8sTT+H/2Tje4HiDvaKxaldNfp kgXiyaHYMu9tupHaxIkqD58uVn5he/uZeKhdvaAOqs/D8hosO8gl++9OiwEVls1qbRkj 1gtJQ7qmVKr0hbPxmuen1O2ZMVlkdsWygN1GmMedVcVSGQ6tnt7LzrAhaYJA8XJEF625 ANXg== Received: by 10.50.160.198 with SMTP id xm6mr6126434igb.0.1342715099567; Thu, 19 Jul 2012 09:24:59 -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.153.7 with SMTP id i7csp13159ibw; Thu, 19 Jul 2012 09:24:59 -0700 (PDT) Received: by 10.182.31.102 with SMTP id z6mr3527501obh.66.1342715098723; Thu, 19 Jul 2012 09:24:58 -0700 (PDT) Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by mx.google.com with ESMTPS id qd10si2388306obc.86.2012.07.19.09.24.58 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 19 Jul 2012 09:24:58 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.214.178 as permitted sender) client-ip=209.85.214.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.214.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by obbwd20 with SMTP id wd20so5353256obb.37 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) Sender: Rob Clark 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> X-Gm-Message-State: ALoCoQnRFxGofuYQjc48DJQUyhq79ZrzWdg433eT6tLGpYxp5aBMyJxEEDEqqCKpPrsOVot6xF4u 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) {