Skip to content

Commit 4538c18

Browse files
larsclausenJonathan Cameron
authored andcommitted
iio: buffer-dmaengine: Report buffer length requirements
The dmaengine buffer has some length alignment requirements that can differ from platform to platform. If the length alignment requirements are not met unexpected behavior like dropping of samples can occur. Currently these requirements are not reported and applications need to know the requirements of the platform by some out-of-band means. Add a new buffer attribute that reports the length alignment requirements called `length_align_bytes`. The reported length alignment is in bytes that means the buffer length alignment in sample sets depends on the number of enabled channels and the bytes per channel. Applications using this attribute to determine the buffer size requirements need to consider this. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 2a4fb4d commit 4538c18

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
What: /sys/bus/iio/devices/iio:deviceX/buffer/length_align_bytes
2+
KernelVersion: 5.4
3+
Contact: linux-iio@vger.kernel.org
4+
Description:
5+
DMA buffers tend to have a alignment requirement for the
6+
buffers. If this alignment requirement is not met samples might
7+
be dropped from the buffer.
8+
9+
This property reports the alignment requirements in bytes.
10+
This means that the buffer size in bytes needs to be a integer
11+
multiple of the number reported by this file.
12+
13+
The alignment requirements in number of sample sets will depend
14+
on the enabled channels and the bytes per channel. This means
15+
that the alignment requirement in samples sets might change
16+
depending on which and how many channels are enabled. Whereas
17+
the alignment requirement reported in bytes by this property
18+
will remain static and does not depend on which channels are
19+
enabled.

‎drivers/iio/buffer/industrialio-buffer-dmaengine.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/module.h>
1414

1515
#include <linux/iio/iio.h>
16+
#include <linux/iio/sysfs.h>
1617
#include <linux/iio/buffer.h>
1718
#include <linux/iio/buffer_impl.h>
1819
#include <linux/iio/buffer-dma.h>
@@ -126,6 +127,24 @@ static const struct iio_dma_buffer_ops iio_dmaengine_default_ops = {
126127
.abort = iio_dmaengine_buffer_abort,
127128
};
128129

130+
static ssize_t iio_dmaengine_buffer_get_length_align(struct device *dev,
131+
struct device_attribute *attr, char *buf)
132+
{
133+
struct iio_dev *indio_dev = dev_to_iio_dev(dev);
134+
struct dmaengine_buffer *dmaengine_buffer =
135+
iio_buffer_to_dmaengine_buffer(indio_dev->buffer);
136+
137+
return sprintf(buf, "%u\n", dmaengine_buffer->align);
138+
}
139+
140+
static IIO_DEVICE_ATTR(length_align_bytes, 0444,
141+
iio_dmaengine_buffer_get_length_align, NULL, 0);
142+
143+
static const struct attribute *iio_dmaengine_buffer_attrs[] = {
144+
&iio_dev_attr_length_align_bytes.dev_attr.attr,
145+
NULL,
146+
};
147+
129148
/**
130149
* iio_dmaengine_buffer_alloc() - Allocate new buffer which uses DMAengine
131150
* @dev: Parent device for the buffer
@@ -179,6 +198,8 @@ struct iio_buffer *iio_dmaengine_buffer_alloc(struct device *dev,
179198

180199
iio_dma_buffer_init(&dmaengine_buffer->queue, chan->device->dev,
181200
&iio_dmaengine_default_ops);
201+
iio_buffer_set_attrs(&dmaengine_buffer->queue.buffer,
202+
iio_dmaengine_buffer_attrs);
182203

183204
dmaengine_buffer->queue.buffer.access = &iio_dmaengine_buffer_ops;
184205

0 commit comments

Comments
 (0)