From: Tomasz Stanislawski <t.stanislaws@samsung.com>
To: Rob Clark <rob.clark@linaro.org>
Cc: 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, patches@linaro.org,
linux@arm.linux.org.uk, arnd@arndb.de, jesse.barker@linaro.org,
m.szyprowski@samsung.com, daniel@ffwll.ch, sumit.semwal@ti.com,
maarten.lankhorst@canonical.com, Rob Clark <rob@ti.com>
Subject: Re: [PATCH 2/2] dma-buf: add helpers for attacher dma-parms
Date: Mon, 06 Aug 2012 12:29:34 +0200 [thread overview]
Message-ID: <501F9C8E.4080002@samsung.com> (raw)
In-Reply-To: <1342715014-5316-3-git-send-email-rob.clark@linaro.org>
Hi Rob,
On 07/19/2012 06:23 PM, Rob Clark wrote:
> From: Rob Clark <rob@ti.com>
>
> Add some helpers to iterate through all attachers and get the most
> restrictive segment size/count/boundary.
>
> Signed-off-by: Rob Clark <rob@ti.com>
> ---
> 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;
Maybe you should change return type to 'int' and return -EINVAL here?
> +
> + 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;
maybe return -EINVAL here?
> +
> + mutex_lock(&dmabuf->lock);
> + list_for_each_entry(attach, &dmabuf->attachments, node)
> + max = min(max, dma_get_max_seg_count(attach->dev));
I think that there is a bug here.
Assume that there are two deices on the list, one using unlimited number of
segments (value 0), the second one needs a contiguous buffer (value 1).
The result of the function is 0 = min(0, 2).
The return value 0 indicates that the unlimited number of sg segments is
accepted what is *wrong* because the correct value should be 1.
I recommend to change the semantics for unlimited number of segments
from 'value 0' to:
#define DMA_SEGMENTS_COUNT_UNLIMITED ((unsigned long)INT_MAX)
Using INT_MAX will allow using safe conversions between signed and
unsigned integers.
> + 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);
Instead of adding an army of new handlers you could provide a single helper:
int dma_buf_get_parameters(struct dma_buf *dmabuf,
struct device_dma_parameters *params);
This function will fill *params with lowest common DMA requirements for
all devices on attachment list. Return value can be used to diagnose
errors like incorrectly initialized dma_buf pointer
(like no attachments on an attachment list).
Moreover, there will be no need to add a new handler every time
device_dma_parameters is extended.
Regards,
Tomasz Stanislawski
> +
> 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)
> {
>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-08-06 10:29 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-19 16:23 [PATCH 0/2] dma-parms and helpers for dma-buf Rob Clark
2012-07-19 16:23 ` [PATCH 1/2] device: add dma_params->max_segment_count Rob Clark
2012-07-20 6:20 ` Marek Szyprowski
2012-07-19 16:23 ` [PATCH 2/2] dma-buf: add helpers for attacher dma-parms Rob Clark
2012-07-20 16:39 ` Rob Clark
2012-08-06 6:37 ` Semwal, Sumit
2012-08-06 10:29 ` Tomasz Stanislawski [this message]
2012-08-06 11:58 ` Michal Nazarewicz
2012-08-06 12:42 ` Tomasz Stanislawski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=501F9C8E.4080002@samsung.com \
--to=t.stanislaws@samsung.com \
--cc=arnd@arndb.de \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=jesse.barker@linaro.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux@arm.linux.org.uk \
--cc=m.szyprowski@samsung.com \
--cc=maarten.lankhorst@canonical.com \
--cc=patches@linaro.org \
--cc=rob.clark@linaro.org \
--cc=rob@ti.com \
--cc=sumit.semwal@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox