iio: Add DMA buffer support
v2 cover iio: Add DMA buffer support
Changes since v1:
* Typo fixes and some comment rewording
* Dropped the dummy DMA driver until the dummy IIO driver has moved out of staging
Original cover letter below:
This series contains phase 1 of adding DMA buffer support to the IIO framework. It adds the necessary in-kernel infrastructure to support DMA buffers, but does not yet modify the userspace ABI.
The traditional approach used in IIO to implement buffered capture requires the generation of at least one interrupt per sample. In the interrupt handler the driver reads the sample from the device and copies it to a software buffer. This approach has a rather large per sample overhead associated with it. And while it works fine for samplerates in the range of up to 1000 samples per second it starts to consume a rather large share of the available CPU processing time once we go beyond that, this is especially true on an embedded system with limited processing power. The regular interrupt also causes increased power consumption by not allowing the hardware into deeper sleep states, which is something that becomes more and more important on mobile battery powered devices.
And while the recently added watermark support mitigates some of the issues by allowing the device to generate interrupts at a rate lower than the data output rate, this still requires a storage buffer inside the device and even if it exists it is only a few 100 samples deep at most.
DMA support on the other hand allows to capture multiple millions or even more samples without any CPU interaction. This allows the CPU to either go to sleep for longer periods or focus on other tasks which increases overall system performance and power consumption. In addition to that some devices might not even offer a way to read the data other than using DMA, which makes DMA mandatory to use for them.
For the DMA buffer support that is introduced in this series sample data is grouped in so called blocks. A block is the basic unit at which data is exchanged between the application and the hardware. The application is responsible for allocating the memory associated with the block and then passes the block to the hardware. When the hardware has captured the amount of samples equal to size of a block it will notify the application, which can then read the data from the block and process it. The block size can be freely chosen (within the constraints of the hardware). This allows to make a trade-off between latency and management overhead. The larger the block size the lower the per sample overhead but the latency between when the data was captured and when the application will be able to access it increases, in a similar way smaller block sizes have a larger per sample management overhead but a lower latency. The ideal block size thus depends on system and application requirements.
The series starts with some minor modifications to the watermark handling code, primarily for dealing with fixed watermarks. It then adds support for enable()/disable() callbacks to the iio_buffer_access_ops. This allows the DMA buffer support to start and stop the DMA controller when the buffer is enabled and disabled.
The next patch after that contains the core of this series. It adds a generic infrastructure for managing DMA buffers and while this is not a complete buffer implementation on its own it contains support for all the management work that is necessary to support DMA buffers, i.e. implementing the IIO buffer callbacks. The only thing not part of this infrastructure is configuring and setting up the DMA controller hardware itself. This is left to be implemented by a device driver which wants to support DMA buffer support and can be hooked up into the generic infrastructure by two simple callbacks. This minimizes the per driver code that is necessary to implement a DMA buffer.
On top of that the series adds support for DMA buffers to the IIO dummy simple driver. This code can be used as a template for implementing new DMA buffer drivers as well as for testing the generic DMA buffer infrastructure in absence of hardware with DMA capabilities.
Finally this series introduces a fully functional and completely hardware independent DMA buffer implementation which binds the previously introduced generic IIO DMA buffer infrastructure to the DMAengine framework. Which is used setup the actual hardware transfers. This reduces the amount of driver specific code for implementing a DMA buffer to two lines. One for registering the buffer and one for unregistering it. This makes using the DMAengine based buffer implementation the recommended way of implementing a DMA buffer for a device.
The DMA buffer support has been successfully used and tested at Analog Devices for a while now with a wide variety of high speed data acquisition and processing systems with sample rates going up to multiple giga samples per second. Andrey Yurovsky has also successfully added DMA buffer support to the existing AT91 ADC driver allowing faster and more efficient data capture.
The next step after this series and phase 2 is to extend the DMA buffer support with some userspace ABI additions, this includes support for giving userspace a more fine grained control over buffer allocation and management as well as support for mmap() and splice(). mmap() allows to access the buffer data from userspace without having to copy it which additionally reduces the management overhead. While splice() allows to exchange data with other kernel buffers without having to copy it, this can for example be used to send the data to a network or storage disk controller.
For more background information on using IIO for high-speed data acquisition and using the DMA buffer support please also refer to [1] and
[2] as well as [3].
- Lars
[1] http://events.linuxfoundation.org/sites/events/files/slides/iio_high_speed.pdf
[2] https://wiki.analog.com/resources/tools-software/linux-software/libiio_internals#high-speed_mmap_interface
[3] https://wiki.analog.com/resources/tools-software/linux-software/libiio_internals#zerocopy
Lars-Peter Clausen (6):
iio: Set device watermark based on watermark of all attached buffers iio:iio_buffer_init(): Only set watermark if not already set
iio: Add support for indicating fixed watermarks
iio: Add buffer enable/disable callbacks
iio: Add generic DMA buffer infrastructure
iio: Add a DMAengine framework based buffer
drivers/iio/buffer/Kconfig | 20 + drivers/iio/buffer/Makefile | 2 + drivers/iio/buffer/industrialio-buffer-dma.c | 683 +++++++++++++++++++++ drivers/iio/buffer/industrialio-buffer-dmaengine.c | 213 +++++++ drivers/iio/industrialio-buffer.c | 58 +- include/linux/iio/buffer-dma.h | 150 +++++ include/linux/iio/buffer-dmaengine.h | 18 + include/linux/iio/buffer.h | 16 + 8 files changed, 1154 insertions(+), 6 deletions(-) create mode 100644 drivers/iio/buffer/industrialio-buffer-dma.c create mode 100644 drivers/iio/buffer/industrialio-buffer-dmaengine.c create mode 100644 include/linux/iio/buffer-dma.h create mode 100644 include/linux/iio/buffer-dmaengine.h
Signature · 1 line
2.1.4
PATCH v2 1/6 iio: Set device watermark based on watermark of all attached buffers
Currently the watermark of the device is only set based on the watermark that is set for the user space buffer. This doesn't consider the watermarks set on any attached in-kernel buffers.
Change this so that the watermark of the device should be the minimum of the watermarks over all attached buffers.
--- drivers/iio/industrialio-buffer.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/iio/industrialio-buffer.c +10 -4
@@ -610,6 +610,7 @@ static void iio_free_scan_mask(struct iio_dev *indio_dev,struct iio_device_config {unsigned int mode; +unsigned int watermark;const unsigned long *scan_mask;unsigned int scan_bytes;bool scan_timestamp;
@@ -642,10 +643,14 @@ static int iio_verify_update(struct iio_dev *indio_dev,if (buffer == remove_buffer)continue ; modes &= buffer->access->modes; + config->watermark =min (config->watermark, buffer->watermark); } -if (insert_buffer) +if (insert_buffer) { modes &= insert_buffer->access->modes; + config->watermark =min (config->watermark, + insert_buffer->watermark); + }/* Definitely possible for devices to support both of these. */ if ((modes &INDIO_BUFFER_TRIGGERED ) && indio_dev->trig) {
@@ -743,6 +748,10 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, } } +if (indio_dev->info->hwfifo_set_watermark) + indio_dev->info->hwfifo_set_watermark (indio_dev, + config->watermark); + indio_dev->currentmode = config->mode;if (indio_dev->setup_ops->postenable) {
@@ -974,9 +983,6 @@ static ssize_t iio_buffer_store_watermark(struct device *dev, } buffer->watermark = val; - -if (indio_dev->info->hwfifo_set_watermark) - indio_dev->info->hwfifo_set_watermark (indio_dev, val); out:mutex_unlock (&indio_dev->mlock);
Signature · 1 line
2.1.4
PATCH v2 2/6 iio:iio_buffer_init(): Only set watermark if not already set
In reply to Lars-Peter ClausenOnly initialize the watermark field if it is still 0. This allows drivers to provide a custom default watermark value. E.g. some driver might have a fixed watermark or can only support watermarks within a certain range and the initial value for the watermark should be within this range.
--- drivers/iio/industrialio-buffer.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/industrialio-buffer.c +2 -1
@@ -193,7 +193,8 @@ void iio_buffer_init(struct iio_buffer *buffer)INIT_LIST_HEAD (&buffer->buffer_list);init_waitqueue_head (&buffer->pollq);kref_init (&buffer->ref); - buffer->watermark =1 ; +if (!buffer->watermark) + buffer->watermark =1 ; }EXPORT_SYMBOL (iio_buffer_init);
Signature · 1 line
2.1.4
PATCH v2 3/6 iio: Add support for indicating fixed watermarks
In reply to Lars-Peter ClausenFor buffers which have a fixed wake-up watermark the watermark attribute should be read-only. Add a new FIXED_WATERMARK flag to the struct iio_buffer_access_funcs, which can be set by a buffer implementation.
--- drivers/iio/industrialio-buffer.c | 5 +++++ include/linux/iio/buffer.h | 8 ++++++++ 2 files changed, 13 insertions(+)
drivers/iio/industrialio-buffer.c +5 -0
@@ -998,6 +998,8 @@ static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, iio_buffer_show_enable, iio_buffer_store_enable); static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR, iio_buffer_show_watermark, iio_buffer_store_watermark); +static struct device_attribute dev_attr_watermark_ro =__ATTR (watermark, +S_IRUGO , iio_buffer_show_watermark,NULL );static struct attribute *iio_buffer_attrs[] = { &dev_attr_length.attr,
@@ -1040,6 +1042,9 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)if (!buffer->access->set_length) attr[0 ] = &dev_attr_length_ro.attr; +if (buffer->access->flags &INDIO_BUFFER_FLAG_FIXED_WATERMARK ) + attr[2 ] = &dev_attr_watermark_ro.attr; +if (buffer->attrs)memcpy (&attr[ARRAY_SIZE (iio_buffer_attrs)], buffer->attrs,sizeof (struct attribute *) * attrcount);
include/linux/iio/buffer.h +8 -0
@@ -18,6 +18,12 @@struct iio_buffer ;/** +* INDIO_BUFFER_FLAG_FIXED_WATERMARK - Watermark level of the buffer can not be +* configured. It has a fixed value which will be buffer specific. +*/ +#define INDIO_BUFFER_FLAG_FIXED_WATERMARK BIT(0) + +/** * struct iio_buffer_access_funcs - access functions for buffers. * @store_to: actually store stuff to the buffer * @read_first_n: try to get a specified number of bytes (must exist)
@@ -30,6 +36,7 @@ struct iio_buffer;* @release: called when the last reference to the buffer is dropped, * should free all resources allocated by the buffer. * @modes: Supported operating modes by this buffer type +* @flags: A bitmask combination of INDIO_BUFFER_FLAG_* * * The purpose of this structure is to make the buffer element * modular as event for a given driver, different usecases may require
@@ -54,6 +61,7 @@ struct iio_buffer_access_funcs {void (*release)(struct iio_buffer *buffer);unsigned int modes; +unsigned int flags; };/**
Signature · 1 line
2.1.4
Re: [PATCH v2 3/6] iio: Add support for indicating fixed watermarks
Quoted 16 lines · Lars-Peter Clausen
For buffers which have a fixed wake-up watermark the watermark attribute should be read-only. Add a new
FIXED_WATERMARKflag to the structiio_buffer_access_funcs, which can be set by a buffer implementation.Signed-off-by Lars-Peter Clausen <[email protected]>--- drivers/iio/industrialio-buffer.c | 5 +++++ include/linux/iio/buffer.h | 8 ++++++++ 2 files changed, 13 insertions(+)drivers/iio/industrialio-buffer.c +0
-0
drivers/iio/industrialio-buffer.c static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, · line 1002
Quoted 5 lines
drivers/iio/industrialio-buffer.c +2
-0@@ -998,6 +998,8 @@ static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, iio_buffer_show_enable, iio_buffer_store_enable); static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR, iio_buffer_show_watermark, iio_buffer_store_watermark); +static struct device_attribute dev_attr_watermark_ro =__ATTR (watermark, +S_IRUGO , iio_buffer_show_watermark,NULL );
I think we can use DEVICE_ATTR_RO here.
drivers/iio/industrialio-buffer.c int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev) · line 1047
Quoted 10 lines
drivers/iio/industrialio-buffer.c +3
-0static struct attribute *iio_buffer_attrs[] = { &dev_attr_length.attr,@@ -1040,6 +1042,9 @@ int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)if (!buffer->access->set_length) attr[0 ] = &dev_attr_length_ro.attr; +if (buffer->access->flags &INDIO_BUFFER_FLAG_FIXED_WATERMARK ) + attr[2 ] = &dev_attr_watermark_ro.attr; +
Ok, this works :). Let's hope iio_buffer_attrs array new elements will be always added at the end.
Quoted 37 lines
drivers/iio/industrialio-buffer.c +0
-0if (buffer->attrs)memcpy (&attr[ARRAY_SIZE (iio_buffer_attrs)], buffer->attrs,sizeof (struct attribute *) * attrcount);include/linux/iio/buffer.h +8
-1@@ -18,6 +18,12 @@struct iio_buffer ;/** +* INDIO_BUFFER_FLAG_FIXED_WATERMARK - Watermark level of the buffer can not be +* configured. It has a fixed value which will be buffer specific. +*/ +#define INDIO_BUFFER_FLAG_FIXED_WATERMARK BIT(0) + +/** * struct iio_buffer_access_funcs - access functions for buffers. * @store_to: actually store stuff to the buffer * @read_first_n: try to get a specified number of bytes (must exist) @@ -30,6 +36,7 @@ struct iio_buffer;* @release: called when the last reference to the buffer is dropped, * should free all resources allocated by the buffer. * @modes: Supported operating modes by this buffer type +* @flags: A bitmask combination of INDIO_BUFFER_FLAG_* * * The purpose of this structure is to make the buffer element * modular as event for a given driver, different usecases may require @@ -54,6 +61,7 @@ struct iio_buffer_access_funcs {void (*release)(struct iio_buffer *buffer);unsigned int modes; +unsigned int flags; };/** --
Re: [PATCH v2 3/6] iio: Add support for indicating fixed watermarks
Quoted 12 lines · Daniel Baluta
Quoted 11 lines · Lars-Peter Clausen
For buffers which have a fixed wake-up watermark the watermark attribute should be read-only. Add a new
FIXED_WATERMARKflag to the structiio_buffer_access_funcs, which can be set by a buffer implementation.Signed-off-by Lars-Peter Clausen <[email protected]>--- drivers/iio/industrialio-buffer.c | 5 +++++ include/linux/iio/buffer.h | 8 ++++++++ 2 files changed, 13 insertions(+)
Quoted 12 lines
drivers/iio/industrialio-buffer.c static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, · line 1002
Quoted 10 lines
drivers/iio/industrialio-buffer.c +2
-0@@ -998,6 +998,8 @@ static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, iio_buffer_show_enable, iio_buffer_store_enable); static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR, iio_buffer_show_watermark, iio_buffer_store_watermark); +static struct device_attribute dev_attr_watermark_ro =__ATTR (watermark, +S_IRUGO , iio_buffer_show_watermark,NULL );I think we can use
DEVICE_ATTR_ROhere.
The problem is that this will generate a variable with the name dev_attr_watermark, which we already have for the rw version. So there would be a name conflict.
Thanks for the review,
- Lars
Re: [PATCH v2 3/6] iio: Add support for indicating fixed watermarks
Quoted 26 lines · Lars-Peter Clausen
Quoted 12 lines · Daniel Baluta
Quoted 11 lines · Lars-Peter Clausen
For buffers which have a fixed wake-up watermark the watermark attribute should be read-only. Add a new
FIXED_WATERMARKflag to the structiio_buffer_access_funcs, which can be set by a buffer implementation.Signed-off-by Lars-Peter Clausen <[email protected]>--- drivers/iio/industrialio-buffer.c | 5 +++++ include/linux/iio/buffer.h | 8 ++++++++ 2 files changed, 13 insertions(+)Quoted 12 lines
drivers/iio/industrialio-buffer.c static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, · line 1002
Quoted 10 lines
drivers/iio/industrialio-buffer.c +2
-0@@ -998,6 +998,8 @@ static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, iio_buffer_show_enable, iio_buffer_store_enable); static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR, iio_buffer_show_watermark, iio_buffer_store_watermark); +static struct device_attribute dev_attr_watermark_ro =__ATTR (watermark, +S_IRUGO , iio_buffer_show_watermark,NULL );I think we can use
DEVICE_ATTR_ROhere.
Quoted 3 lines
The problem is that this will generate a variable with the name
dev_attr_watermark, which we already have for the rw version. So there would be a name conflict.
I see.
PATCH v2 4/6 iio: Add buffer enable/disable callbacks
In reply to Lars-Peter ClausenThis patch adds a enable and disable callback that is called when the buffer is enabled/disabled. This can be used by buffer implementations that need to do some setup or teardown work. E.g. a DMA based buffer can use this to start/stop the DMA transfer.
--- drivers/iio/industrialio-buffer.c | 36 +++++++++++++++++++++++++++++++++++- include/linux/iio/buffer.h | 8 ++++++++ 2 files changed, 43 insertions(+), 1 deletion(-)
drivers/iio/industrialio-buffer.c +35 -1
@@ -568,6 +568,22 @@ static void iio_buffer_deactivate_all(struct iio_dev *indio_dev)iio_buffer_deactivate (buffer); } +static int iio_buffer_enable (struct iio_buffer *buffer, +struct iio_dev *indio_dev) +{ +if (!buffer->access->enable) +return 0 ; +return buffer->access->enable (buffer, indio_dev); +} + +static int iio_buffer_disable (struct iio_buffer *buffer, +struct iio_dev *indio_dev) +{ +if (!buffer->access->disable) +return 0 ; +return buffer->access->disable (buffer, indio_dev); +} +static void iio_buffer_update_bytes_per_datum (struct iio_dev *indio_dev,struct iio_buffer *buffer) {
@@ -719,6 +735,7 @@ static int iio_verify_update(struct iio_dev *indio_dev,static int iio_enable_buffers (struct iio_dev *indio_dev,struct iio_device_config *config) { +struct iio_buffer *buffer;int ret; indio_dev->active_scan_mask = config->scan_mask;
@@ -753,6 +770,12 @@ static int iio_enable_buffers(struct iio_dev *indio_dev, indio_dev->info->hwfifo_set_watermark (indio_dev, config->watermark); +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + ret =iio_buffer_enable (buffer, indio_dev); +if (ret) + goto err_disable_buffers; + } + indio_dev->currentmode = config->mode;if (indio_dev->setup_ops->postenable) {
@@ -760,12 +783,16 @@ static int iio_enable_buffers(struct iio_dev *indio_dev,if (ret) {dev_dbg (&indio_dev->dev,"Buffer not started: postenable failed (%d)\n" , ret); - goto err_run_postdisable; + goto err_disable_buffers; } }return 0 ; +err_disable_buffers: +list_for_each_entry_continue_reverse (buffer, &indio_dev->buffer_list, + buffer_list) +iio_buffer_disable (buffer, indio_dev); err_run_postdisable: indio_dev->currentmode =INDIO_DIRECT_MODE ;if (indio_dev->setup_ops->postdisable)
@@ -778,6 +805,7 @@ err_undo_config:static int iio_disable_buffers (struct iio_dev *indio_dev) { +struct iio_buffer *buffer;int ret =0 ;int ret2;
@@ -798,6 +826,12 @@ static int iio_disable_buffers(struct iio_dev *indio_dev) ret = ret2; } +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + ret2 =iio_buffer_disable (buffer, indio_dev); +if (ret2 && !ret) + ret = ret2; + } + indio_dev->currentmode =INDIO_DIRECT_MODE ;if (indio_dev->setup_ops->postdisable) {
include/linux/iio/buffer.h +8 -0
@@ -33,6 +33,11 @@ struct iio_buffer;* storage. * @set_bytes_per_datum:set number of bytes per datum * @set_length: set number of datums in buffer +* @enable: called if the buffer is attached to a device and the +* device starts sampling. Calls are balanced with +* @disable. +* @disable: called if the buffer is attached to a device and the +* device stops sampling. Calles are balanced with @enable. * @release: called when the last reference to the buffer is dropped, * should free all resources allocated by the buffer. * @modes: Supported operating modes by this buffer type
@@ -58,6 +63,9 @@ struct iio_buffer_access_funcs {int (*set_bytes_per_datum)(struct iio_buffer *buffer,size_t bpd);int (*set_length)(struct iio_buffer *buffer,int length); +int (*enable)(struct iio_buffer *buffer,struct iio_dev *indio_dev); +int (*disable)(struct iio_buffer *buffer,struct iio_dev *indio_dev); +void (*release)(struct iio_buffer *buffer);unsigned int modes;
Signature · 1 line
2.1.4
PATCH v2 5/6 iio: Add generic DMA buffer infrastructure
In reply to Lars-Peter ClausenThe traditional approach used in IIO to implement buffered capture requires the generation of at least one interrupt per sample. In the interrupt handler the driver reads the sample from the device and copies it to a software buffer. This approach has a rather large per sample overhead associated with it. And while it works fine for samplerates in the range of up to 1000 samples per second it starts to consume a rather large share of the available CPU processing time once we go beyond that, this is especially true on an embedded system with limited processing power. The regular interrupt also causes increased power consumption by not allowing the hardware into deeper sleep states, which is something that becomes more and more important on mobile battery powered devices.
And while the recently added watermark support mitigates some of the issues by allowing the device to generate interrupts at a rate lower than the data output rate, this still requires a storage buffer inside the device and even if it exists it is only a few 100 samples deep at most.
DMA support on the other hand allows to capture multiple millions or even more samples without any CPU interaction. This allows the CPU to either go to sleep for longer periods or focus on other tasks which increases overall system performance and power consumption. In addition to that some devices might not even offer a way to read the data other than using DMA, which makes DMA mandatory to use for them.
The tasks involved in implementing a DMA buffer can be divided into two categories. The first category is memory buffer management (allocation, mapping, etc.) and hooking this up the IIO buffer callbacks like read(), enable(), disable(), etc. The second category of tasks is to setup the DMA hardware and manage the DMA transfers. Tasks from the first category will be very similar for all IIO drivers supporting DMA buffers, while the tasks from the second category will be hardware specific.
This patch implements a generic infrastructure that take care of the former tasks. It provides a set of functions that implement the standard IIO buffer iio_buffer_access_funcs callbacks. These can either be used as is or be overloaded and augmented with driver specific code where necessary.
For the DMA buffer support infrastructure that is introduced in this series sample data is grouped by so called blocks. A block is the basic unit at which data is exchanged between the application and the hardware. The application is responsible for allocating the memory associated with the block and then passes the block to the hardware. When the hardware has captured the amount of samples equal to size of a block it will notify the application, which can then read the data from the block and process it. The block size can freely chosen (within the constraints of the hardware). This allows to make a trade-off between latency and management overhead. The larger the block size the lower the per sample overhead but the latency between when the data was captured and when the application will be able to access it increases, in a similar way smaller block sizes have a larger per sample management overhead but a lower latency. The ideal block size thus depends on system and application requirements.
For the time being the infrastructure only implements a simple double buffered scheme which allocates two blocks each with half the size of the configured buffer size. This provides basic support for capturing continuous uninterrupted data over the existing file-IO ABI. Future extensions to the DMA buffer infrastructure will give applications a more fine grained control over how many blocks are allocated and the size of each block. But this requires userspace ABI additions which are intentionally not part of this patch and will be added separately.
Tasks of the second category need to be implemented by a device specific driver. They can be hooked up into the generic infrastructure using two simple callbacks, submit() and abort().
The submit() callback is used to schedule DMA transfers for blocks. Once a DMA transfer has been completed it is expected that the buffer driver calls iio_dma_buffer_block_done() to notify. The abort() callback is used for stopping all pending and active DMA transfers when the buffer is disabled.
--- drivers/iio/buffer/Kconfig | 9 + drivers/iio/buffer/Makefile | 1 + drivers/iio/buffer/industrialio-buffer-dma.c | 683 +++++++++++++++++++++++++++ include/linux/iio/buffer-dma.h | 150 ++++++ 4 files changed, 843 insertions(+) create mode 100644 drivers/iio/buffer/industrialio-buffer-dma.c create mode 100644 include/linux/iio/buffer-dma.h
drivers/iio/buffer/Kconfig +9 -0
@@ -9,6 +9,15 @@ config IIO_BUFFER_CB Should be selected by any drivers that do in-kernel push usage. That is, those where the data is pushed to the consumer. +config IIO_BUFFER_DMA + tristate + help + Provides the generic IIO DMA buffer infrastructure that can be used by + drivers for devices with DMA support to implement the IIO buffer. + + Should be selected by drivers that want to use the generic DMA buffer + infrastructure. + config IIO_KFIFO_BUF tristate "Industrial I/O buffering based on kfifo" help
drivers/iio/buffer/Makefile +1 -0
@@ -4,5 +4,6 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_IIO_BUFFER_CB) += industrialio-buffer-cb.o +obj-$(CONFIG_IIO_BUFFER_DMA) += industrialio-buffer-dma.o obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
drivers/iio/buffer/industrialio-buffer-dma.c new file +683 -0
683 lines not on this page · raw message
include/linux/iio/buffer-dma.h new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v2 6/6 iio: Add a DMAengine framework based buffer
In reply to Lars-Peter ClausenAdd a generic fully device independent DMA buffer implementation that uses the DMAegnine framework to perform the DMA transfers. This can be used by converter drivers that whish to provide a DMA buffer for converters that are connected to a DMA core that implements the DMAengine API.
Apart from allocating the buffer using iio_dmaengine_buffer_alloc() and freeing it using iio_dmaengine_buffer_free() no additional converter driver specific code is required when using this DMA buffer implementation.
--- drivers/iio/buffer/Kconfig | 11 ++ drivers/iio/buffer/Makefile | 1 + drivers/iio/buffer/industrialio-buffer-dmaengine.c | 213 +++++++++++++++++++++ include/linux/iio/buffer-dmaengine.h | 18 ++ 4 files changed, 243 insertions(+) create mode 100644 drivers/iio/buffer/industrialio-buffer-dmaengine.c create mode 100644 include/linux/iio/buffer-dmaengine.h
drivers/iio/buffer/Kconfig +11 -0
@@ -18,6 +18,17 @@ config IIO_BUFFER_DMA Should be selected by drivers that want to use the generic DMA buffer infrastructure. +config IIO_BUFFER_DMAENGINE + tristate + select IIO_BUFFER_DMA + help + Provides a bonding of the generic IIO DMA buffer infrastructure with the + DMAengine framework. This can be used by converter drivers with a DMA port + connected to an external DMA controller which is supported by the + DMAengine framework. + + Should be selected by drivers that want to use this functionality. + config IIO_KFIFO_BUF tristate "Industrial I/O buffering based on kfifo" help
drivers/iio/buffer/Makefile +1 -0
@@ -5,5 +5,6 @@ # When adding new entries keep the list in alphabetical order obj-$(CONFIG_IIO_BUFFER_CB) += industrialio-buffer-cb.o obj-$(CONFIG_IIO_BUFFER_DMA) += industrialio-buffer-dma.o +obj-$(CONFIG_IIO_BUFFER_DMAENGINE) += industrialio-buffer-dmaengine.o obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
drivers/iio/buffer/industrialio-buffer-dmaengine.c new file +213 -0
213 lines not on this page · raw message
include/linux/iio/buffer-dmaengine.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* Copyright 2014-2015 Analog Devices Inc. +* Author: Lars-Peter Clausen <[email protected]> +* +* Licensed under the GPL-2 or later. +*/ + +#ifndef __IIO_DMAENGINE_H__ +#define __IIO_DMAENGINE_H__ + +struct iio_buffer ; +struct device ; + +struct iio_buffer *iio_dmaengine_buffer_alloc (struct device *dev, +const char *channel); +void iio_dmaengine_buffer_free (struct iio_buffer *buffer); + +#endif
Signature · 1 line
2.1.4