• Home
  • Raw
  • Download

Lines Matching full:buffer

6  * Handling of buffer allocation / resizing.
26 #include <linux/iio/buffer.h>
63 /* drain the buffer if it was disabled */ in iio_buffer_ready()
92 * iio_buffer_read_outer() - chrdev read for buffer access
94 * @buf: Destination buffer for iio buffer read
98 * This function relies on all buffer implementations having an
108 struct iio_buffer *rb = indio_dev->buffer; in iio_buffer_read_outer()
124 * buffer, so signal end of file now. in iio_buffer_read_outer()
162 * iio_buffer_poll() - poll the buffer to find out if it has data
174 struct iio_buffer *rb = indio_dev->buffer; in iio_buffer_poll()
186 * iio_buffer_wakeup_poll - Wakes up the buffer waitqueue
194 struct iio_buffer *buffer = indio_dev->buffer; in iio_buffer_wakeup_poll() local
196 if (!buffer) in iio_buffer_wakeup_poll()
199 wake_up(&buffer->pollq); in iio_buffer_wakeup_poll()
202 void iio_buffer_init(struct iio_buffer *buffer) in iio_buffer_init() argument
204 INIT_LIST_HEAD(&buffer->demux_list); in iio_buffer_init()
205 INIT_LIST_HEAD(&buffer->buffer_list); in iio_buffer_init()
206 init_waitqueue_head(&buffer->pollq); in iio_buffer_init()
207 kref_init(&buffer->ref); in iio_buffer_init()
208 if (!buffer->watermark) in iio_buffer_init()
209 buffer->watermark = 1; in iio_buffer_init()
214 * iio_buffer_set_attrs - Set buffer specific attributes
215 * @buffer: The buffer for which we are setting attributes
218 void iio_buffer_set_attrs(struct iio_buffer *buffer, in iio_buffer_set_attrs() argument
221 buffer->attrs = attrs; in iio_buffer_set_attrs()
269 struct iio_buffer *buffer = indio_dev->buffer; in iio_scan_el_show() local
273 buffer->scan_mask); in iio_scan_el_show()
311 * @buffer: the buffer whose scan mask we are interested in
319 struct iio_buffer *buffer, int bit) in iio_scan_mask_set() argument
328 WARN(1, "Trying to set scanmask prior to registering buffer\n"); in iio_scan_mask_set()
331 bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength); in iio_scan_mask_set()
344 bitmap_copy(buffer->scan_mask, trialmask, indio_dev->masklength); in iio_scan_mask_set()
355 static int iio_scan_mask_clear(struct iio_buffer *buffer, int bit) in iio_scan_mask_clear() argument
357 clear_bit(bit, buffer->scan_mask); in iio_scan_mask_clear()
362 struct iio_buffer *buffer, int bit) in iio_scan_mask_query() argument
367 if (!buffer->scan_mask) in iio_scan_mask_query()
371 return !!test_bit(bit, buffer->scan_mask); in iio_scan_mask_query()
382 struct iio_buffer *buffer = indio_dev->buffer; in iio_scan_el_store() local
389 if (iio_buffer_is_active(buffer)) { in iio_scan_el_store()
393 ret = iio_scan_mask_query(indio_dev, buffer, this_attr->address); in iio_scan_el_store()
397 ret = iio_scan_mask_clear(buffer, this_attr->address); in iio_scan_el_store()
401 ret = iio_scan_mask_set(indio_dev, buffer, this_attr->address); in iio_scan_el_store()
418 struct iio_buffer *buffer = indio_dev->buffer; in iio_scan_el_ts_show() local
420 return sprintf(buf, "%d\n", buffer->scan_timestamp); in iio_scan_el_ts_show()
430 struct iio_buffer *buffer = indio_dev->buffer; in iio_scan_el_ts_store() local
438 if (iio_buffer_is_active(buffer)) { in iio_scan_el_ts_store()
442 buffer->scan_timestamp = state; in iio_scan_el_ts_store()
450 struct iio_buffer *buffer, in iio_buffer_add_channel_sysfs() argument
462 &buffer->scan_el_dev_attr_list); in iio_buffer_add_channel_sysfs()
473 &buffer->scan_el_dev_attr_list); in iio_buffer_add_channel_sysfs()
485 &buffer->scan_el_dev_attr_list); in iio_buffer_add_channel_sysfs()
494 &buffer->scan_el_dev_attr_list); in iio_buffer_add_channel_sysfs()
507 struct iio_buffer *buffer = indio_dev->buffer; in iio_buffer_read_length() local
509 return sprintf(buf, "%d\n", buffer->length); in iio_buffer_read_length()
517 struct iio_buffer *buffer = indio_dev->buffer; in iio_buffer_write_length() local
525 if (val == buffer->length) in iio_buffer_write_length()
529 if (iio_buffer_is_active(buffer)) { in iio_buffer_write_length()
532 buffer->access->set_length(buffer, val); in iio_buffer_write_length()
537 if (buffer->length && buffer->length < buffer->watermark) in iio_buffer_write_length()
538 buffer->watermark = buffer->length; in iio_buffer_write_length()
550 struct iio_buffer *buffer = indio_dev->buffer; in iio_buffer_show_enable() local
552 return sprintf(buf, "%d\n", iio_buffer_is_active(buffer)); in iio_buffer_show_enable()
601 struct iio_buffer *buffer) in iio_buffer_activate() argument
605 iio_buffer_get(buffer); in iio_buffer_activate()
606 list_add(&buffer->buffer_list, &iio_dev_opaque->buffer_list); in iio_buffer_activate()
609 static void iio_buffer_deactivate(struct iio_buffer *buffer) in iio_buffer_deactivate() argument
611 list_del_init(&buffer->buffer_list); in iio_buffer_deactivate()
612 wake_up_interruptible(&buffer->pollq); in iio_buffer_deactivate()
613 iio_buffer_put(buffer); in iio_buffer_deactivate()
619 struct iio_buffer *buffer, *_buffer; in iio_buffer_deactivate_all() local
621 list_for_each_entry_safe(buffer, _buffer, in iio_buffer_deactivate_all()
623 iio_buffer_deactivate(buffer); in iio_buffer_deactivate_all()
626 static int iio_buffer_enable(struct iio_buffer *buffer, in iio_buffer_enable() argument
629 if (!buffer->access->enable) in iio_buffer_enable()
631 return buffer->access->enable(buffer, indio_dev); in iio_buffer_enable()
634 static int iio_buffer_disable(struct iio_buffer *buffer, in iio_buffer_disable() argument
637 if (!buffer->access->disable) in iio_buffer_disable()
639 return buffer->access->disable(buffer, indio_dev); in iio_buffer_disable()
643 struct iio_buffer *buffer) in iio_buffer_update_bytes_per_datum() argument
647 if (!buffer->access->set_bytes_per_datum) in iio_buffer_update_bytes_per_datum()
650 bytes = iio_compute_scan_bytes(indio_dev, buffer->scan_mask, in iio_buffer_update_bytes_per_datum()
651 buffer->scan_timestamp); in iio_buffer_update_bytes_per_datum()
653 buffer->access->set_bytes_per_datum(buffer, bytes); in iio_buffer_update_bytes_per_datum()
657 struct iio_buffer *buffer) in iio_buffer_request_update() argument
661 iio_buffer_update_bytes_per_datum(indio_dev, buffer); in iio_buffer_request_update()
662 if (buffer->access->request_update) { in iio_buffer_request_update()
663 ret = buffer->access->request_update(buffer); in iio_buffer_request_update()
666 "Buffer not started: buffer parameter update failed (%d)\n", in iio_buffer_request_update()
699 struct iio_buffer *buffer; in iio_verify_update() local
714 * If there is just one buffer and we are removing it there is nothing in iio_verify_update()
723 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_verify_update()
724 if (buffer == remove_buffer) in iio_verify_update()
726 modes &= buffer->access->modes; in iio_verify_update()
727 config->watermark = min(config->watermark, buffer->watermark); in iio_verify_update()
741 * Keep things simple for now and only allow a single buffer to in iio_verify_update()
751 /* Can only occur on first buffer */ in iio_verify_update()
753 dev_dbg(&indio_dev->dev, "Buffer not started: no trigger\n"); in iio_verify_update()
764 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_verify_update()
765 if (buffer == remove_buffer) in iio_verify_update()
767 bitmap_or(compound_mask, compound_mask, buffer->scan_mask, in iio_verify_update()
769 scan_timestamp |= buffer->scan_timestamp; in iio_verify_update()
812 static void iio_buffer_demux_free(struct iio_buffer *buffer) in iio_buffer_demux_free() argument
815 list_for_each_entry_safe(p, q, &buffer->demux_list, l) { in iio_buffer_demux_free()
821 static int iio_buffer_add_demux(struct iio_buffer *buffer, in iio_buffer_add_demux() argument
836 list_add_tail(&(*p)->l, &buffer->demux_list); in iio_buffer_add_demux()
843 struct iio_buffer *buffer) in iio_buffer_update_demux() argument
850 iio_buffer_demux_free(buffer); in iio_buffer_update_demux()
851 kfree(buffer->demux_bounce); in iio_buffer_update_demux()
852 buffer->demux_bounce = NULL; in iio_buffer_update_demux()
856 buffer->scan_mask, in iio_buffer_update_demux()
862 buffer->scan_mask, in iio_buffer_update_demux()
878 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length); in iio_buffer_update_demux()
885 if (buffer->scan_timestamp) { in iio_buffer_update_demux()
889 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length); in iio_buffer_update_demux()
895 buffer->demux_bounce = kzalloc(out_loc, GFP_KERNEL); in iio_buffer_update_demux()
896 if (buffer->demux_bounce == NULL) { in iio_buffer_update_demux()
903 iio_buffer_demux_free(buffer); in iio_buffer_update_demux()
911 struct iio_buffer *buffer; in iio_update_demux() local
914 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_update_demux()
915 ret = iio_buffer_update_demux(indio_dev, buffer); in iio_update_demux()
922 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) in iio_update_demux()
923 iio_buffer_demux_free(buffer); in iio_update_demux()
932 struct iio_buffer *buffer; in iio_enable_buffers() local
947 "Buffer not started: buffer preenable failed (%d)\n", ret); in iio_enable_buffers()
958 "Buffer not started: update scan mode failed (%d)\n", in iio_enable_buffers()
968 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_enable_buffers()
969 ret = iio_buffer_enable(buffer, indio_dev); in iio_enable_buffers()
985 "Buffer not started: postenable failed (%d)\n", ret); in iio_enable_buffers()
998 list_for_each_entry_continue_reverse(buffer, &iio_dev_opaque->buffer_list, in iio_enable_buffers()
1000 iio_buffer_disable(buffer, indio_dev); in iio_enable_buffers()
1014 struct iio_buffer *buffer; in iio_disable_buffers() local
1040 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_disable_buffers()
1041 ret2 = iio_buffer_disable(buffer, indio_dev); in iio_disable_buffers()
1165 struct iio_buffer *buffer = indio_dev->buffer; in iio_buffer_store_enable() local
1175 inlist = iio_buffer_is_active(buffer); in iio_buffer_store_enable()
1181 ret = __iio_update_buffers(indio_dev, buffer, NULL); in iio_buffer_store_enable()
1183 ret = __iio_update_buffers(indio_dev, NULL, buffer); in iio_buffer_store_enable()
1197 struct iio_buffer *buffer = indio_dev->buffer; in iio_buffer_show_watermark() local
1199 return sprintf(buf, "%u\n", buffer->watermark); in iio_buffer_show_watermark()
1208 struct iio_buffer *buffer = indio_dev->buffer; in iio_buffer_store_watermark() local
1220 if (val > buffer->length) { in iio_buffer_store_watermark()
1225 if (iio_buffer_is_active(buffer)) { in iio_buffer_store_watermark()
1230 buffer->watermark = val; in iio_buffer_store_watermark()
1242 struct iio_buffer *buffer = indio_dev->buffer; in iio_dma_show_data_available() local
1244 return sprintf(buf, "%zu\n", iio_buffer_data_available(buffer)); in iio_dma_show_data_available()
1267 static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, in __iio_buffer_alloc_sysfs_and_mask() argument
1276 if (buffer->attrs) { in __iio_buffer_alloc_sysfs_and_mask()
1277 while (buffer->attrs[attrcount] != NULL) in __iio_buffer_alloc_sysfs_and_mask()
1287 if (!buffer->access->set_length) in __iio_buffer_alloc_sysfs_and_mask()
1290 if (buffer->access->flags & INDIO_BUFFER_FLAG_FIXED_WATERMARK) in __iio_buffer_alloc_sysfs_and_mask()
1293 if (buffer->attrs) in __iio_buffer_alloc_sysfs_and_mask()
1294 memcpy(&attr[ARRAY_SIZE(iio_buffer_attrs)], buffer->attrs, in __iio_buffer_alloc_sysfs_and_mask()
1299 buffer->buffer_group.name = "buffer"; in __iio_buffer_alloc_sysfs_and_mask()
1300 buffer->buffer_group.attrs = attr; in __iio_buffer_alloc_sysfs_and_mask()
1302 indio_dev->groups[indio_dev->groupcounter++] = &buffer->buffer_group; in __iio_buffer_alloc_sysfs_and_mask()
1305 INIT_LIST_HEAD(&buffer->scan_el_dev_attr_list); in __iio_buffer_alloc_sysfs_and_mask()
1313 ret = iio_buffer_add_channel_sysfs(indio_dev, buffer, in __iio_buffer_alloc_sysfs_and_mask()
1322 if (indio_dev->masklength && buffer->scan_mask == NULL) { in __iio_buffer_alloc_sysfs_and_mask()
1323 buffer->scan_mask = bitmap_zalloc(indio_dev->masklength, in __iio_buffer_alloc_sysfs_and_mask()
1325 if (buffer->scan_mask == NULL) { in __iio_buffer_alloc_sysfs_and_mask()
1332 buffer->scan_el_group.name = iio_scan_elements_group_name; in __iio_buffer_alloc_sysfs_and_mask()
1334 buffer->scan_el_group.attrs = kcalloc(attrcount + 1, in __iio_buffer_alloc_sysfs_and_mask()
1335 sizeof(buffer->scan_el_group.attrs[0]), in __iio_buffer_alloc_sysfs_and_mask()
1337 if (buffer->scan_el_group.attrs == NULL) { in __iio_buffer_alloc_sysfs_and_mask()
1343 list_for_each_entry(p, &buffer->scan_el_dev_attr_list, l) in __iio_buffer_alloc_sysfs_and_mask()
1344 buffer->scan_el_group.attrs[attrn++] = &p->dev_attr.attr; in __iio_buffer_alloc_sysfs_and_mask()
1345 indio_dev->groups[indio_dev->groupcounter++] = &buffer->scan_el_group; in __iio_buffer_alloc_sysfs_and_mask()
1350 bitmap_free(buffer->scan_mask); in __iio_buffer_alloc_sysfs_and_mask()
1352 iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list); in __iio_buffer_alloc_sysfs_and_mask()
1353 kfree(buffer->buffer_group.attrs); in __iio_buffer_alloc_sysfs_and_mask()
1360 struct iio_buffer *buffer = indio_dev->buffer; in iio_buffer_alloc_sysfs_and_mask() local
1373 if (!buffer) in iio_buffer_alloc_sysfs_and_mask()
1376 return __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev); in iio_buffer_alloc_sysfs_and_mask()
1379 static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer) in __iio_buffer_free_sysfs_and_mask() argument
1381 bitmap_free(buffer->scan_mask); in __iio_buffer_free_sysfs_and_mask()
1382 kfree(buffer->buffer_group.attrs); in __iio_buffer_free_sysfs_and_mask()
1383 kfree(buffer->scan_el_group.attrs); in __iio_buffer_free_sysfs_and_mask()
1384 iio_free_chan_devattr_list(&buffer->scan_el_dev_attr_list); in __iio_buffer_free_sysfs_and_mask()
1389 struct iio_buffer *buffer = indio_dev->buffer; in iio_buffer_free_sysfs_and_mask() local
1391 if (!buffer) in iio_buffer_free_sysfs_and_mask()
1394 __iio_buffer_free_sysfs_and_mask(buffer); in iio_buffer_free_sysfs_and_mask()
1413 static const void *iio_demux(struct iio_buffer *buffer, in iio_demux() argument
1418 if (list_empty(&buffer->demux_list)) in iio_demux()
1420 list_for_each_entry(t, &buffer->demux_list, l) in iio_demux()
1421 memcpy(buffer->demux_bounce + t->to, in iio_demux()
1424 return buffer->demux_bounce; in iio_demux()
1427 static int iio_push_to_buffer(struct iio_buffer *buffer, const void *data) in iio_push_to_buffer() argument
1429 const void *dataout = iio_demux(buffer, data); in iio_push_to_buffer()
1432 ret = buffer->access->store_to(buffer, dataout); in iio_push_to_buffer()
1440 wake_up_interruptible_poll(&buffer->pollq, EPOLLIN | EPOLLRDNORM); in iio_push_to_buffer()
1445 * iio_push_to_buffers() - push to a registered buffer.
1466 * iio_buffer_release() - Free a buffer's resources
1469 * This function is called when the last reference to the buffer has been
1470 * dropped. It will typically free all resources allocated by the buffer. Do not
1472 * buffer.
1476 struct iio_buffer *buffer = container_of(ref, struct iio_buffer, ref); in iio_buffer_release() local
1478 buffer->access->release(buffer); in iio_buffer_release()
1482 * iio_buffer_get() - Grab a reference to the buffer
1483 * @buffer: The buffer to grab a reference for, may be NULL
1485 * Returns the pointer to the buffer that was passed into the function.
1487 struct iio_buffer *iio_buffer_get(struct iio_buffer *buffer) in iio_buffer_get() argument
1489 if (buffer) in iio_buffer_get()
1490 kref_get(&buffer->ref); in iio_buffer_get()
1492 return buffer; in iio_buffer_get()
1497 * iio_buffer_put() - Release the reference to the buffer
1498 * @buffer: The buffer to release the reference for, may be NULL
1500 void iio_buffer_put(struct iio_buffer *buffer) in iio_buffer_put() argument
1502 if (buffer) in iio_buffer_put()
1503 kref_put(&buffer->ref, iio_buffer_release); in iio_buffer_put()
1508 * iio_device_attach_buffer - Attach a buffer to a IIO device
1509 * @indio_dev: The device the buffer should be attached to
1510 * @buffer: The buffer to attach to the device
1512 * This function attaches a buffer to a IIO device. The buffer stays attached to
1517 struct iio_buffer *buffer) in iio_device_attach_buffer() argument
1519 indio_dev->buffer = iio_buffer_get(buffer); in iio_device_attach_buffer()