buffer.h cleanup and split
Subsystems (4)
Jonathan Cameron
maintainercover buffer.h cleanup and split
This series came out of the mess that became apparant when looking at the autogenerated docs. As we pull the kernel-doc from buffer.h in when describing the API the drivers use to access it we were pulling in a lot of documentation that was irrelevant to that use case.
Hence, this series does two things:
1) Splits the buffer.h header into two parts:
* buffer.h which just contains the stuff that drivers using buffers need.
* buffer_impl.h which just contains the stuff related to the implementation of buffers
This makes struct iio_buffer opaque to the drivers (with a few extra access functions and a bit of code reorganization)
2) Takes the documentation of struct iio_buffer inline, allowing fairly sensible use of the private: label within docs rather than our local iio specific tagging of documentation. There is an oddity here in that I have deliberately 'broken' the kernel-doc for elements that are private in order to avoid lots of warnings about excess documentation.
Along the way various drivers gained additional includes that should probably have been there in the first place. This was needed to cleanup the includes within the includes. Most drivers did it 'right' anyway so this wasn't too bad.
I'll probably follow this up with similar cleanups elsewhere at some point.
This was against 4.10-rc1 as that's where I'm working on docs, but should go in reasonably cleanly on iio/togreg or iio/testing.
Jonathan Cameron (11):
iio:buffer: Stop exporting iio_update_demux
iio:buffer.h Reformat structure comments to be inline. iio:buffer: Introduced a function to assign the buffer specific attrs. iio:buffer: Stop exporting iio_scan_mask_query iio:buffers: Push some docs down into the .c file. iio:buffer:iio_push_to_buffers_with_timestamp fix kernel-doc. iio:kfifo_buf header include push down.
iio:buffer.h include pushdown into buffer implementations iio:buffer: Push implementation of iio_device_attach_buffer into .c
file
iio:dummy: Stop enabling timestamp by default. iio:buffer.h - split into buffer.h and buffer_impl.h
drivers/iio/accel/bmc150-accel-core.c | 3 +- drivers/iio/accel/ssp_accel_sensor.c | 1 + drivers/iio/adc/ina2xx-adc.c | 2 + drivers/iio/buffer/industrialio-buffer-cb.c | 3 +- drivers/iio/buffer/kfifo_buf.c | 2 + drivers/iio/common/ssp_sensors/ssp_iio.c | 1 + drivers/iio/dummy/iio_simple_dummy_buffer.c | 4 +- drivers/iio/gyro/ssp_gyro_sensor.c | 1 + drivers/iio/industrialio-buffer.c | 321 +++++++++++++++------------- drivers/iio/industrialio-core.c | 1 + drivers/staging/iio/meter/ade7758_ring.c | 1 + include/linux/iio/buffer.h | 160 +------------- include/linux/iio/buffer_impl.h | 162 ++++++++++++++ include/linux/iio/kfifo_buf.h | 5 +- 14 files changed, 360 insertions(+), 307 deletions(-) create mode 100644 include/linux/iio/buffer_impl.h
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerPATCH 1/11 iio:buffer: Stop exporting iio_update_demux
Nothing outside of indiustrialio-buffer.c should be using this. Requires a large amount of juggling of functions to avoid a forward definition.
--- drivers/iio/industrialio-buffer.c | 260 +++++++++++++++++++------------------- include/linux/iio/buffer.h | 2 - 2 files changed, 129 insertions(+), 133 deletions(-)
drivers/iio/industrialio-buffer.c +129 -131
@@ -751,6 +751,135 @@ static int iio_verify_update(struct iio_dev *indio_dev,return 0 ; } +/** +* struct iio_demux_table - table describing demux memcpy ops +* @from: index to copy from +* @to: index to copy to +* @length: how many bytes to copy +* @l: list head used for management +*/ +struct iio_demux_table { +unsigned from; +unsigned to; +unsigned length; +struct list_head l; +}; + +static void iio_buffer_demux_free (struct iio_buffer *buffer) +{ +struct iio_demux_table *p, *q; +list_for_each_entry_safe (p, q, &buffer->demux_list, l) { +list_del (&p->l); +kfree (p); + } +} + +static int iio_buffer_add_demux (struct iio_buffer *buffer, +struct iio_demux_table **p,unsigned int in_loc,unsigned int out_loc, +unsigned int length) +{ + +if (*p && (*p)->from + (*p)->length == in_loc && + (*p)->to + (*p)->length == out_loc) { + (*p)->length += length; + }else { + *p =kmalloc (sizeof (**p),GFP_KERNEL ); +if (*p ==NULL ) +return -ENOMEM ; + (*p)->from = in_loc; + (*p)->to = out_loc; + (*p)->length = length; +list_add_tail (&(*p)->l, &buffer->demux_list); + } + +return 0 ; +} + +static int iio_buffer_update_demux (struct iio_dev *indio_dev, +struct iio_buffer *buffer) +{ +int ret, in_ind =-1 , out_ind, length; +unsigned in_loc =0 , out_loc =0 ; +struct iio_demux_table *p =NULL ; + +/* Clear out any old demux */ +iio_buffer_demux_free (buffer); +kfree (buffer->demux_bounce); + buffer->demux_bounce =NULL ; + +/* First work out which scan mode we will actually have */ +if (bitmap_equal (indio_dev->active_scan_mask, + buffer->scan_mask, + indio_dev->masklength)) +return 0 ; + +/* Now we have the two masks, work from least sig and build up sizes */ +for_each_set_bit (out_ind, + buffer->scan_mask, + indio_dev->masklength) { + in_ind =find_next_bit (indio_dev->active_scan_mask, + indio_dev->masklength, + in_ind +1 ); +while (in_ind != out_ind) { + in_ind =find_next_bit (indio_dev->active_scan_mask, + indio_dev->masklength, + in_ind +1 ); + length =iio_storage_bytes_for_si (indio_dev, in_ind); +/* Make sure we are aligned */ + in_loc =roundup (in_loc, length) + length; + } + length =iio_storage_bytes_for_si (indio_dev, in_ind); + out_loc =roundup (out_loc, length); + in_loc =roundup (in_loc, length); + ret =iio_buffer_add_demux (buffer, &p, in_loc, out_loc, length); +if (ret) + goto error_clear_mux_table; + out_loc += length; + in_loc += length; + } +/* Relies on scan_timestamp being last */ +if (buffer->scan_timestamp) { + length =iio_storage_bytes_for_timestamp (indio_dev); + out_loc =roundup (out_loc, length); + in_loc =roundup (in_loc, length); + ret =iio_buffer_add_demux (buffer, &p, in_loc, out_loc, length); +if (ret) + goto error_clear_mux_table; + out_loc += length; + in_loc += length; + } + buffer->demux_bounce =kzalloc (out_loc,GFP_KERNEL ); +if (buffer->demux_bounce ==NULL ) { + ret = -ENOMEM ; + goto error_clear_mux_table; + } +return 0 ; + +error_clear_mux_table: +iio_buffer_demux_free (buffer); + +return ret; +} + +static int iio_update_demux (struct iio_dev *indio_dev) +{ +struct iio_buffer *buffer; +int ret; + +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { + ret =iio_buffer_update_demux (indio_dev, buffer); +if (ret <0 ) + goto error_clear_mux_table; + } +return 0 ; + +error_clear_mux_table: +list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) +iio_buffer_demux_free (buffer); + +return ret; +} +static int iio_enable_buffers (struct iio_dev *indio_dev,struct iio_device_config *config) {
@@ -1213,20 +1342,6 @@ int iio_scan_mask_query(struct iio_dev *indio_dev, };EXPORT_SYMBOL_GPL (iio_scan_mask_query); -/** -* struct iio_demux_table - table describing demux memcpy ops -* @from: index to copy from -* @to: index to copy to -* @length: how many bytes to copy -* @l: list head used for management -*/ -struct iio_demux_table { -unsigned from; -unsigned to; -unsigned length; -struct list_head l; -}; -static const void *iio_demux (struct iio_buffer *buffer,const void *datain) {
@@ -1258,16 +1373,6 @@ static int iio_push_to_buffer(struct iio_buffer *buffer, const void *data)return 0 ; } -static void iio_buffer_demux_free (struct iio_buffer *buffer) -{ -struct iio_demux_table *p, *q; -list_for_each_entry_safe (p, q, &buffer->demux_list, l) { -list_del (&p->l); -kfree (p); - } -} - -int iio_push_to_buffers (struct iio_dev *indio_dev,const void *data) {int ret;
@@ -1283,113 +1388,6 @@ int iio_push_to_buffers(struct iio_dev *indio_dev, const void *data) }EXPORT_SYMBOL_GPL (iio_push_to_buffers); -static int iio_buffer_add_demux (struct iio_buffer *buffer, -struct iio_demux_table **p,unsigned int in_loc,unsigned int out_loc, -unsigned int length) -{ - -if (*p && (*p)->from + (*p)->length == in_loc && - (*p)->to + (*p)->length == out_loc) { - (*p)->length += length; - }else { - *p =kmalloc (sizeof (**p),GFP_KERNEL ); -if (*p ==NULL ) -return -ENOMEM ; - (*p)->from = in_loc; - (*p)->to = out_loc; - (*p)->length = length; -list_add_tail (&(*p)->l, &buffer->demux_list); - } - -return 0 ; -} - -static int iio_buffer_update_demux (struct iio_dev *indio_dev, -struct iio_buffer *buffer) -{ -int ret, in_ind =-1 , out_ind, length; -unsigned in_loc =0 , out_loc =0 ; -struct iio_demux_table *p =NULL ; - -/* Clear out any old demux */ -iio_buffer_demux_free (buffer); -kfree (buffer->demux_bounce); - buffer->demux_bounce =NULL ; - -/* First work out which scan mode we will actually have */ -if (bitmap_equal (indio_dev->active_scan_mask, - buffer->scan_mask, - indio_dev->masklength)) -return 0 ; - -/* Now we have the two masks, work from least sig and build up sizes */ -for_each_set_bit (out_ind, - buffer->scan_mask, - indio_dev->masklength) { - in_ind =find_next_bit (indio_dev->active_scan_mask, - indio_dev->masklength, - in_ind +1 ); -while (in_ind != out_ind) { - in_ind =find_next_bit (indio_dev->active_scan_mask, - indio_dev->masklength, - in_ind +1 ); - length =iio_storage_bytes_for_si (indio_dev, in_ind); -/* Make sure we are aligned */ - in_loc =roundup (in_loc, length) + length; - } - length =iio_storage_bytes_for_si (indio_dev, in_ind); - out_loc =roundup (out_loc, length); - in_loc =roundup (in_loc, length); - ret =iio_buffer_add_demux (buffer, &p, in_loc, out_loc, length); -if (ret) - goto error_clear_mux_table; - out_loc += length; - in_loc += length; - } -/* Relies on scan_timestamp being last */ -if (buffer->scan_timestamp) { - length =iio_storage_bytes_for_timestamp (indio_dev); - out_loc =roundup (out_loc, length); - in_loc =roundup (in_loc, length); - ret =iio_buffer_add_demux (buffer, &p, in_loc, out_loc, length); -if (ret) - goto error_clear_mux_table; - out_loc += length; - in_loc += length; - } - buffer->demux_bounce =kzalloc (out_loc,GFP_KERNEL ); -if (buffer->demux_bounce ==NULL ) { - ret = -ENOMEM ; - goto error_clear_mux_table; - } -return 0 ; - -error_clear_mux_table: -iio_buffer_demux_free (buffer); - -return ret; -} - -int iio_update_demux (struct iio_dev *indio_dev) -{ -struct iio_buffer *buffer; -int ret; - -list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) { - ret =iio_buffer_update_demux (indio_dev, buffer); -if (ret <0 ) - goto error_clear_mux_table; - } -return 0 ; - -error_clear_mux_table: -list_for_each_entry (buffer, &indio_dev->buffer_list, buffer_list) -iio_buffer_demux_free (buffer); - -return ret; -} -EXPORT_SYMBOL_GPL (iio_update_demux); -/** * iio_buffer_release() - Free a buffer's resources * @ref: Pointer to the kref embedded in the iio_buffer struct
include/linux/iio/buffer.h +0 -2
@@ -168,8 +168,6 @@ static inline int iio_push_to_buffers_with_timestamp(struct iio_dev *indio_dev,return iio_push_to_buffers (indio_dev, data); } -int iio_update_demux (struct iio_dev *indio_dev); -bool iio_validate_scan_mask_onehot (struct iio_dev *indio_dev,const unsigned long *mask);
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerPATCH 2/11 iio:buffer.h Reformat structure comments to be inline.
In reply to Jonathan CameronThis should make it easier to see how the structure is split into public and private parts - reflected in the generated documentation.
Deliberately use /* instead of /** for the private elements to avoid warnings when kernel-doc script runs.
--- include/linux/iio/buffer.h | 100 ++++++++++++++++++++++++++++----------------- 1 file changed, 63 insertions(+), 37 deletions(-)
include/linux/iio/buffer.h +63 -37
@@ -74,45 +74,71 @@ struct iio_buffer_access_funcs {/** * struct iio_buffer - general buffer structure -* @length: [DEVICE] number of datums in buffer -* @bytes_per_datum: [DEVICE] size of individual datum including timestamp -* @scan_el_attrs: [DRIVER] control of scan elements if that scan mode -* control method is used -* @scan_mask: [INTERN] bitmask used in masking scan mode elements -* @scan_timestamp: [INTERN] does the scan mode include a timestamp -* @access: [DRIVER] buffer access functions associated with the -* implementation. -* @scan_el_dev_attr_list:[INTERN] list of scan element related attributes. -* @buffer_group: [INTERN] attributes of the buffer group -* @scan_el_group: [DRIVER] attribute group for those attributes not -* created from the iio_chan_info array. -* @pollq: [INTERN] wait queue to allow for polling on the buffer. -* @stufftoread: [INTERN] flag to indicate new data. -* @attrs: [INTERN] standard attributes of the buffer -* @demux_list: [INTERN] list of operations required to demux the scan. -* @demux_bounce: [INTERN] buffer for doing gather from incoming scan. -* @buffer_list: [INTERN] entry in the devices list of current buffers. -* @ref: [INTERN] reference count of the buffer. -* @watermark: [INTERN] number of datums to wait for poll/read. +* +* Note that the internals of this structure should only be of interest to +* those writing new buffer implementations. */ struct iio_buffer { -int length; -int bytes_per_datum; -struct attribute_group *scan_el_attrs; -long *scan_mask; -bool scan_timestamp; -const struct iio_buffer_access_funcs *access; -struct list_head scan_el_dev_attr_list; -struct attribute_group buffer_group; -struct attribute_group scan_el_group; -wait_queue_head_t pollq; -bool stufftoread; -const struct attribute **attrs; -struct list_head demux_list; -void *demux_bounce; -struct list_head buffer_list; -struct kref ref; -unsigned int watermark; +/** @length: Number of datums in buffer. */ +int length; + +/** @bytes_per_datum: Size of individual datum including timestamp. */ +int bytes_per_datum; + +/** +* @access: Buffer access functions associated with the +* implementation. +*/ +const struct iio_buffer_access_funcs *access; + +/** @scan_mask: Bitmask used in masking scan mode elements. */ +long *scan_mask; + +/** @demux_list: List of operations required to demux the scan. */ +struct list_head demux_list; + +/** @pollq: Wait queue to allow for polling on the buffer. */ +wait_queue_head_t pollq; + +/** @watermark: Number of datums to wait for poll/read. */ +unsigned int watermark; + +/* private: */ +/* +* @scan_el_attrs: Control of scan elements if that scan mode +* control method is used. +*/ +struct attribute_group *scan_el_attrs; + +/* @scan_timestamp: Does the scan mode include a timestamp. */ +bool scan_timestamp; + +/* @scan_el_dev_attr_list: List of scan element related attributes. */ +struct list_head scan_el_dev_attr_list; + +/* @buffer_group: Attributes of the buffer group. */ +struct attribute_group buffer_group; + +/* +* @scan_el_group: Attribute group for those attributes not +* created from the iio_chan_info array. +*/ +struct attribute_group scan_el_group; + +/* @stufftoread: Flag to indicate new data. */ +bool stufftoread; + +/* @attrs: Standard attributes of the buffer. */ +const struct attribute **attrs; + +/* @demux_bounce: Buffer for doing gather from incoming scan. */ +void *demux_bounce; + +/* @buffer_list: Entry in the devices list of current buffers. */ +struct list_head buffer_list; + +/* @ref: Reference count of the buffer. */ +struct kref ref; };/**
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerPATCH 3/11 iio:buffer: Introduced a function to assign the buffer specific attrs.
In reply to Jonathan CameronThis is a necessary step in taking the buffer implementation opaque.
--- drivers/iio/accel/bmc150-accel-core.c | 3 ++- drivers/iio/industrialio-buffer.c | 12 ++++++++++++ include/linux/iio/buffer.h | 2 ++ 3 files changed, 16 insertions(+), 1 deletion(-)
drivers/iio/accel/bmc150-accel-core.c +2 -1
@@ -1638,7 +1638,8 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,if (block_supported) { indio_dev->modes |=INDIO_BUFFER_SOFTWARE ; indio_dev->info = &bmc150_accel_info_fifo; - indio_dev->buffer->attrs = bmc150_accel_fifo_attributes; +iio_buffer_set_attrs (indio_dev->buffer, + bmc150_accel_fifo_attributes); } }
drivers/iio/industrialio-buffer.c +12 -0
@@ -209,6 +209,18 @@ void iio_buffer_init(struct iio_buffer *buffer) }EXPORT_SYMBOL (iio_buffer_init); +/** +* iio_buffer_set_attrs - Set buffer specific attributes +* @buffer: The buffer for which we are setting attributes +* @attrs: Pointer to a null terminated list of pointers to attributes +*/ +void iio_buffer_set_attrs (struct iio_buffer *buffer, +const struct attribute **attrs) +{ + buffer->attrs = attrs; +} +EXPORT_SYMBOL_GPL (iio_buffer_set_attrs); +static ssize_t iio_show_scan_index (struct device *dev,struct device_attribute *attr,char *buf)
include/linux/iio/buffer.h +2 -0
@@ -17,6 +17,8 @@struct iio_buffer ; +void iio_buffer_set_attrs (struct iio_buffer *buffer, +const struct attribute **attrs);/** * INDIO_BUFFER_FLAG_FIXED_WATERMARK - Watermark level of the buffer can not be * configured. It has a fixed value which will be buffer specific.
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerPATCH 4/11 iio:buffer: Stop exporting iio_scan_mask_query
In reply to Jonathan CameronNothing uses it outside of core code.
--- drivers/iio/industrialio-buffer.c | 27 +++++++++++++-------------- include/linux/iio/buffer.h | 3 --- 2 files changed, 13 insertions(+), 17 deletions(-)
drivers/iio/industrialio-buffer.c +13 -14
@@ -358,6 +358,19 @@ static int iio_scan_mask_clear(struct iio_buffer *buffer, int bit)return 0 ; } +static int iio_scan_mask_query (struct iio_dev *indio_dev, +struct iio_buffer *buffer,int bit) +{ +if (bit > indio_dev->masklength) +return -EINVAL ; + +if (!buffer->scan_mask) +return 0 ; + +/* Ensure return value is 0 or 1. */ +return !!test_bit (bit, buffer->scan_mask); +}; + static ssize_t iio_scan_el_store(struct device *dev, struct device_attribute *attr, const char *buf,
@@ -1340,20 +1353,6 @@ bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, }EXPORT_SYMBOL_GPL (iio_validate_scan_mask_onehot); -int iio_scan_mask_query (struct iio_dev *indio_dev, -struct iio_buffer *buffer,int bit) -{ -if (bit > indio_dev->masklength) -return -EINVAL ; - -if (!buffer->scan_mask) -return 0 ; - -/* Ensure return value is 0 or 1. */ -return !!test_bit (bit, buffer->scan_mask); -}; -EXPORT_SYMBOL_GPL (iio_scan_mask_query); -static const void *iio_demux (struct iio_buffer *buffer,const void *datain) {
include/linux/iio/buffer.h +0 -3
@@ -161,9 +161,6 @@ int iio_update_buffers(struct iio_dev *indio_dev,**/ void iio_buffer_init (struct iio_buffer *buffer); -int iio_scan_mask_query (struct iio_dev *indio_dev, -struct iio_buffer *buffer,int bit); -/** * iio_push_to_buffers() - push to a registered buffer. * @indio_dev: iio_dev structure for device.
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerPATCH 5/11 iio:buffers: Push some docs down into the .c file.
In reply to Jonathan CameronAncient legacy of me doing it wrong which it is nice to clear up whilst we are here.
--- drivers/iio/industrialio-buffer.c | 5 +++++ include/linux/iio/buffer.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/iio/industrialio-buffer.c +5 -0
@@ -1384,6 +1384,11 @@ static int iio_push_to_buffer(struct iio_buffer *buffer, const void *data)return 0 ; } +/** +* iio_push_to_buffers() - push to a registered buffer. +* @indio_dev: iio_dev structure for device. +* @data: Full scan. +*/ int iio_push_to_buffers (struct iio_dev *indio_dev,const void *data) {int ret;
include/linux/iio/buffer.h +0 -5
@@ -161,11 +161,6 @@ int iio_update_buffers(struct iio_dev *indio_dev,**/ void iio_buffer_init (struct iio_buffer *buffer); -/** -* iio_push_to_buffers() - push to a registered buffer. -* @indio_dev: iio_dev structure for device. -* @data: Full scan. -*/ int iio_push_to_buffers (struct iio_dev *indio_dev,const void *data);/*
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerPATCH 6/11 iio:buffer:iio_push_to_buffers_with_timestamp fix kernel-doc.
In reply to Jonathan CameronWrong start of kernel doc comment /* -> /**
--- include/linux/iio/buffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/iio/buffer.h +1 -1
@@ -163,7 +163,7 @@ void iio_buffer_init(struct iio_buffer *buffer);int iio_push_to_buffers (struct iio_dev *indio_dev,const void *data); -/* +/** * iio_push_to_buffers_with_timestamp() - push data and timestamp to buffers * @indio_dev: iio_dev structure for device. * @data: sample data
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerPATCH 7/11 iio:kfifo_buf header include push down.
In reply to Jonathan CameronAs a precursor to splitting buffer.h, lets make sure all drivers include the relevant headers rather than relying on picking them up from kfifo_buf.h.
--- drivers/iio/accel/ssp_accel_sensor.c | 1 + drivers/iio/adc/ina2xx-adc.c | 2 ++ drivers/iio/common/ssp_sensors/ssp_iio.c | 1 + drivers/iio/dummy/iio_simple_dummy_buffer.c | 1 + drivers/iio/gyro/ssp_gyro_sensor.c | 1 + drivers/staging/iio/meter/ade7758_ring.c | 1 + include/linux/iio/kfifo_buf.h | 5 ++--- 7 files changed, 9 insertions(+), 3 deletions(-)
drivers/iio/accel/ssp_accel_sensor.c +1 -0
@@ -15,6 +15,7 @@#include <linux/iio/common/ssp_sensors.h> #include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/module.h> #include <linux/platform_device.h>
drivers/iio/adc/ina2xx-adc.c +2 -0
@@ -22,6 +22,8 @@#include <linux/delay.h> #include <linux/i2c.h> +#include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/iio/sysfs.h> #include <linux/kthread.h>
drivers/iio/common/ssp_sensors/ssp_iio.c +1 -0
@@ -14,6 +14,7 @@*/ #include <linux/iio/common/ssp_sensors.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/module.h> #include <linux/slab.h>
drivers/iio/dummy/iio_simple_dummy_buffer.c +1 -0
@@ -20,6 +20,7 @@#include <linux/iio/iio.h> #include <linux/iio/trigger_consumer.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include "iio_simple_dummy.h"
drivers/iio/gyro/ssp_gyro_sensor.c +1 -0
@@ -15,6 +15,7 @@#include <linux/iio/common/ssp_sensors.h> #include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/module.h> #include <linux/platform_device.h>
drivers/staging/iio/meter/ade7758_ring.c +1 -0
@@ -13,6 +13,7 @@#include <asm/unaligned.h> #include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/iio/trigger_consumer.h> #include "ade7758.h"
include/linux/iio/kfifo_buf.h +2 -3
@@ -1,9 +1,8 @@#ifndef __LINUX_IIO_KFIFO_BUF_H__#define __LINUX_IIO_KFIFO_BUF_H__ -#include <linux/kfifo.h> -#include <linux/iio/iio.h> -#include <linux/iio/buffer.h> +struct iio_buffer ; +struct device ;struct iio_buffer *iio_kfifo_allocate (void );void iio_kfifo_free (struct iio_buffer *r);
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerRe: [PATCH 07/11] iio:kfifo_buf header include push down.
Quoted 5 lines · Jonathan Cameron
As a precursor to splitting
buffer.h, lets make sure all drivers include the relevant headers rather than relying on picking them up fromkfifo_buf.h.Signed-off-by Jonathan Cameron <[email protected]>
slight mess up in this one. Kfifo_buf.c needs to include buffer.h for now or it won't build.
Fixed up during applying.
Quoted 100 lines
--- drivers/iio/accel/ssp_accel_sensor.c | 1 + drivers/iio/adc/ina2xx-adc.c | 2 ++ drivers/iio/common/ssp_sensors/ssp_iio.c | 1 + drivers/iio/dummy/iio_simple_dummy_buffer.c | 1 + drivers/iio/gyro/ssp_gyro_sensor.c | 1 + drivers/staging/iio/meter/ade7758_ring.c | 1 + include/linux/iio/kfifo_buf.h | 5 ++--- 7 files changed, 9 insertions(+), 3 deletions(-)drivers/iio/accel/ssp_accel_sensor.c +1
-0@@ -15,6 +15,7 @@#include <linux/iio/common/ssp_sensors.h> #include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/module.h> #include <linux/platform_device.h> drivers/iio/adc/ina2xx-adc.c +2
-0@@ -22,6 +22,8 @@#include <linux/delay.h> #include <linux/i2c.h> +#include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/iio/sysfs.h> #include <linux/kthread.h> drivers/iio/common/ssp_sensors/ssp_iio.c +1
-0@@ -14,6 +14,7 @@*/ #include <linux/iio/common/ssp_sensors.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/module.h> #include <linux/slab.h> drivers/iio/dummy/iio_simple_dummy_buffer.c +1
-0@@ -20,6 +20,7 @@#include <linux/iio/iio.h> #include <linux/iio/trigger_consumer.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include "iio_simple_dummy.h" drivers/iio/gyro/ssp_gyro_sensor.c +1
-0@@ -15,6 +15,7 @@#include <linux/iio/common/ssp_sensors.h> #include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/module.h> #include <linux/platform_device.h> drivers/staging/iio/meter/ade7758_ring.c +1
-0@@ -13,6 +13,7 @@#include <asm/unaligned.h> #include <linux/iio/iio.h> +#include <linux/iio/buffer.h> #include <linux/iio/kfifo_buf.h> #include <linux/iio/trigger_consumer.h> #include "ade7758.h" include/linux/iio/kfifo_buf.h +2
-3@@ -1,9 +1,8 @@#ifndef __LINUX_IIO_KFIFO_BUF_H__#define __LINUX_IIO_KFIFO_BUF_H__ -#include <linux/kfifo.h> -#include <linux/iio/iio.h> -#include <linux/iio/buffer.h> +struct iio_buffer ; +struct device ;struct iio_buffer *iio_kfifo_allocate (void );void iio_kfifo_free (struct iio_buffer *r);
Jonathan Cameron
maintainerPATCH 8/11 iio:buffer.h include pushdown into buffer implementations
In reply to Jonathan CameronThese were only getting access to the internals of struct iio_dev via the include of iio.h within buffer.h. This should always have been explicitly included by the buffer implementations themselves.
--- drivers/iio/buffer/industrialio-buffer-cb.c | 1 + drivers/iio/buffer/kfifo_buf.c | 1 + 2 files changed, 2 insertions(+)
drivers/iio/buffer/industrialio-buffer-cb.c +1 -0
@@ -10,6 +10,7 @@#include <linux/slab.h> #include <linux/err.h> #include <linux/export.h> +#include <linux/iio/iio.h> #include <linux/iio/buffer.h> #include <linux/iio/consumer.h>
drivers/iio/buffer/kfifo_buf.c +1 -0
@@ -5,6 +5,7 @@#include <linux/workqueue.h> #include <linux/kfifo.h> #include <linux/mutex.h> +#include <linux/iio/iio.h> #include <linux/iio/kfifo_buf.h> #include <linux/sched.h> #include <linux/poll.h>
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerPATCH 9/11 iio:buffer: Push implementation of iio_device_attach_buffer into .c file
In reply to Jonathan CameronThis is a precursor to the splitting of buffer.h into parts relevant to buffer implementation vs those for devices using buffers. struct buffer is about to become opaque as far as the header is concerned.
--- drivers/iio/industrialio-buffer.c | 16 ++++++++++++++++ include/linux/iio/buffer.h | 17 ++--------------- 2 files changed, 18 insertions(+), 15 deletions(-)
drivers/iio/industrialio-buffer.c +16 -0
@@ -1445,3 +1445,19 @@ void iio_buffer_put(struct iio_buffer *buffer)kref_put (&buffer->ref, iio_buffer_release); }EXPORT_SYMBOL_GPL (iio_buffer_put); + +/** +* iio_device_attach_buffer - Attach a buffer to a IIO device +* @indio_dev: The device the buffer should be attached to +* @buffer: The buffer to attach to the device +* +* This function attaches a buffer to a IIO device. The buffer stays attached to +* the device until the device is freed. The function should only be called at +* most once per device. +*/ +void iio_device_attach_buffer (struct iio_dev *indio_dev, +struct iio_buffer *buffer) +{ + indio_dev->buffer =iio_buffer_get (buffer); +} +EXPORT_SYMBOL_GPL (iio_device_attach_buffer);
include/linux/iio/buffer.h +2 -15
@@ -194,26 +194,13 @@ bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,struct iio_buffer *iio_buffer_get (struct iio_buffer *buffer);void iio_buffer_put (struct iio_buffer *buffer); -/** -* iio_device_attach_buffer - Attach a buffer to a IIO device -* @indio_dev: The device the buffer should be attached to -* @buffer: The buffer to attach to the device -* -* This function attaches a buffer to a IIO device. The buffer stays attached to -* the device until the device is freed. The function should only be called at -* most once per device. -*/ -static inline void iio_device_attach_buffer (struct iio_dev *indio_dev, -struct iio_buffer *buffer) -{ - indio_dev->buffer =iio_buffer_get (buffer); -} -#else /* CONFIG_IIO_BUFFER */ static inline void iio_buffer_get (struct iio_buffer *buffer) {}static inline void iio_buffer_put (struct iio_buffer *buffer) {} +void iio_device_attach_buffer (struct iio_dev *indio_dev, +struct iio_buffer *buffer);#endif /* CONFIG_IIO_BUFFER */ #endif /* _IIO_BUFFER_GENERIC_H_ */
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerRe: [PATCH 09/11] iio:buffer: Push implementation of iio_device_attach_buffer into .c file
Quoted 55 lines · Jonathan Cameron
This is a precursor to the splitting of
buffer.hinto parts relevant to buffer implementation vs those for devices using buffers. struct buffer is about to become opaque as far as the header is concerned.Signed-off-by Jonathan Cameron <[email protected]>--- drivers/iio/industrialio-buffer.c | 16 ++++++++++++++++ include/linux/iio/buffer.h | 17 ++--------------- 2 files changed, 18 insertions(+), 15 deletions(-)drivers/iio/industrialio-buffer.c +16
-0@@ -1445,3 +1445,19 @@ void iio_buffer_put(struct iio_buffer *buffer)kref_put (&buffer->ref, iio_buffer_release); }EXPORT_SYMBOL_GPL (iio_buffer_put); + +/** +* iio_device_attach_buffer - Attach a buffer to a IIO device +* @indio_dev: The device the buffer should be attached to +* @buffer: The buffer to attach to the device +* +* This function attaches a buffer to a IIO device. The buffer stays attached to +* the device until the device is freed. The function should only be called at +* most once per device. +*/ +void iio_device_attach_buffer (struct iio_dev *indio_dev, +struct iio_buffer *buffer) +{ + indio_dev->buffer =iio_buffer_get (buffer); +} +EXPORT_SYMBOL_GPL (iio_device_attach_buffer);include/linux/iio/buffer.h +0
-12@@ -194,26 +194,13 @@ bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,struct iio_buffer *iio_buffer_get (struct iio_buffer *buffer);void iio_buffer_put (struct iio_buffer *buffer); -/** -* iio_device_attach_buffer - Attach a buffer to a IIO device -* @indio_dev: The device the buffer should be attached to -* @buffer: The buffer to attach to the device -* -* This function attaches a buffer to a IIO device. The buffer stays attached to -* the device until the device is freed. The function should only be called at -* most once per device. -*/ -static inline void iio_device_attach_buffer (struct iio_dev *indio_dev, -struct iio_buffer *buffer) -{
include/linux/iio/buffer.h bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, · line 203
Quoted 10 lines
include/linux/iio/buffer.h +2
-3- indio_dev->buffer = iio_buffer_get(buffer); -} -#else /* CONFIG_IIO_BUFFER */ static inline void iio_buffer_get (struct iio_buffer *buffer) {}static inline void iio_buffer_put (struct iio_buffer *buffer) {} +void iio_device_attach_buffer (struct iio_dev *indio_dev, +struct iio_buffer *buffer);
Hmm. I made a mess of splitting up these changes into patches. This should be in the other branch of the ifdef. Fixed up.
Quoted 4 lines
include/linux/iio/buffer.h +0
-0#endif /* CONFIG_IIO_BUFFER */ #endif /* _IIO_BUFFER_GENERIC_H_ */
Jonathan Cameron
maintainerPATCH 10/11 iio:dummy: Stop enabling timestamp by default.
In reply to Jonathan CameronIt's bad practice and only done in this fake driver + it breaks my attempt to take struct buffer opaque. Not worth an access function as it shouldn't be done anyway.
--- drivers/iio/dummy/iio_simple_dummy_buffer.c | 3 --- 1 file changed, 3 deletions(-)
drivers/iio/dummy/iio_simple_dummy_buffer.c +0 -3
@@ -132,9 +132,6 @@ int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)iio_device_attach_buffer (indio_dev, buffer); -/* Enable timestamps by default */ - buffer->scan_timestamp = true; -/* * Tell the core what device type specific functions should * be run on either side of buffer capture enable / disable.
Signature · 1 line
2.11.0
Jonathan Cameron
maintainerPATCH 11/11 iio:buffer.h - split into buffer.h and buffer_impl.h
In reply to Jonathan Cameronbuffer.h supplies everything needed for devices using buffers. buffer_impl.h supplies access to the internals as needed to write a buffer implementation.
This was really motivated by the mess that turned up in the kernel-doc documentation pulled in by the new sphinx docs. It made it clear that our logical separations in headers were generally terrible. The buffer case was easy to sort out without greatly effecting drivers so here it is.
--- drivers/iio/buffer/industrialio-buffer-cb.c | 2 +- drivers/iio/buffer/kfifo_buf.c | 1 + drivers/iio/industrialio-buffer.c | 1 + drivers/iio/industrialio-core.c | 1 + include/linux/iio/buffer.h | 155 +------------------------- include/linux/iio/buffer_impl.h | 162 ++++++++++++++++++++++++++++ 6 files changed, 167 insertions(+), 155 deletions(-)
drivers/iio/buffer/industrialio-buffer-cb.c +1 -1
@@ -11,7 +11,7 @@#include <linux/err.h> #include <linux/export.h> #include <linux/iio/iio.h> -#include <linux/iio/buffer.h> +#include <linux/iio/buffer_impl.h> #include <linux/iio/consumer.h> struct iio_cb_buffer {
drivers/iio/buffer/kfifo_buf.c +1 -0
@@ -7,6 +7,7 @@#include <linux/mutex.h> #include <linux/iio/iio.h> #include <linux/iio/kfifo_buf.h> +#include <linux/iio/buffer_impl.h> #include <linux/sched.h> #include <linux/poll.h>
drivers/iio/industrialio-buffer.c +1 -0
@@ -26,6 +26,7 @@#include "iio_core.h" #include <linux/iio/sysfs.h> #include <linux/iio/buffer.h> +#include <linux/iio/buffer_impl.h> static const char *const iio_endian_prefix[] = { [IIO_BE ] ="be" ,
drivers/iio/industrialio-core.c +1 -0
@@ -32,6 +32,7 @@#include <linux/iio/sysfs.h> #include <linux/iio/events.h> #include <linux/iio/buffer.h> +#include <linux/iio/buffer_impl.h> /* IDA to assign each registered device a unique id */ static DEFINE_IDA (iio_ida);
include/linux/iio/buffer.h +1 -154
174 lines not on this page · raw message
include/linux/iio/buffer_impl.h new file +162 -0
162 lines not on this page · raw message
Signature · 1 line
2.11.0
Quoted 23 lines · Jonathan Cameron
This series came out of the mess that became apparant when looking at the autogenerated docs. As we pull the kernel-doc from
buffer.hin when describing the API the drivers use to access it we were pulling in a lot of documentation that was irrelevant to that use case.Hence, this series does two things:
1) Splits thebuffer.hheader into two parts:
*buffer.hwhich just contains the stuff that drivers using buffers need.
*buffer_impl.hwhich just contains the stuff related to the implementation of buffers
This makes structiio_bufferopaque to the drivers (with a few extra access functions and a bit of code reorganization)
2) Takes the documentation of structiio_bufferinline, allowing fairly sensible use of the private: label within docs rather than our local iio specific tagging of documentation. There is an oddity here in that I have deliberately 'broken' the kernel-doc for elements that are private in order to avoid lots of warnings about excess documentation.Along the way various drivers gained additional includes that should probably have been there in the first place. This was needed to cleanup the includes within the includes. Most drivers did it 'right' anyway so this wasn't too bad.
Quoted 4 lines
I'll probably follow this up with similar cleanups elsewhere at some point.
This was against 4.10-rc1 as that's where I'm working on docs, but should go in reasonably cleanly on iio/togreg or iio/testing.
Looks good. I'm not convinced the split is necessary, but it doesn't hurt either. Full series:
Jonathan Cameron
maintainerQuoted 24 lines · Lars-Peter Clausen
Quoted 23 lines · Jonathan Cameron
This series came out of the mess that became apparant when looking at the autogenerated docs. As we pull the kernel-doc from
buffer.hin when describing the API the drivers use to access it we were pulling in a lot of documentation that was irrelevant to that use case.Hence, this series does two things:
1) Splits thebuffer.hheader into two parts:
*buffer.hwhich just contains the stuff that drivers using buffers need.
*buffer_impl.hwhich just contains the stuff related to the implementation of buffers
This makes structiio_bufferopaque to the drivers (with a few extra access functions and a bit of code reorganization)
2) Takes the documentation of structiio_bufferinline, allowing fairly sensible use of the private: label within docs rather than our local iio specific tagging of documentation. There is an oddity here in that I have deliberately 'broken' the kernel-doc for elements that are private in order to avoid lots of warnings about excess documentation.Along the way various drivers gained additional includes that should probably have been there in the first place. This was needed to cleanup the includes within the includes. Most drivers did it 'right' anyway so this wasn't too bad.
Quoted 7 lines
Quoted 4 lines
I'll probably follow this up with similar cleanups elsewhere at some point.
This was against 4.10-rc1 as that's where I'm working on docs, but should go in reasonably cleanly on iio/togreg or iio/testing.
Looks good. I'm not convinced the split is necessary, but it doesn't hurt either. Full series:
Yeah, bit marginal on necessity but will make the docs rather nice when I (or someone else) gets around to documenting how to write a buffer driver. In the meantime means a lot of irrelevant stuff goes from the driver api docs on using a buffer.
Quoted 3 lines
Reviewed-by Lars-Peter Clausen <[email protected]>
Thanks,
Series applied to the togreg branch of iio.git which will get pushed out as testing at somepoint soonish.
Jonathan