Lines Matching refs:buffer

45 	struct iio_buffer *buffer;  member
144 struct iio_buffer *rb = ib->buffer; in iio_buffer_read()
213 struct iio_buffer *rb = ib->buffer; in iio_buffer_write()
276 struct iio_buffer *rb = ib->buffer; in iio_buffer_poll()
302 struct iio_buffer *rb = ib->buffer; in iio_buffer_read_wrapper()
315 struct iio_buffer *rb = ib->buffer; in iio_buffer_write_wrapper()
328 struct iio_buffer *rb = ib->buffer; in iio_buffer_poll_wrapper()
347 struct iio_buffer *buffer; in iio_buffer_wakeup_poll() local
351 buffer = iio_dev_opaque->attached_buffers[i]; in iio_buffer_wakeup_poll()
352 wake_up(&buffer->pollq); in iio_buffer_wakeup_poll()
356 int iio_pop_from_buffer(struct iio_buffer *buffer, void *data) in iio_pop_from_buffer() argument
358 if (!buffer || !buffer->access || !buffer->access->remove_from) in iio_pop_from_buffer()
361 return buffer->access->remove_from(buffer, data); in iio_pop_from_buffer()
365 void iio_buffer_init(struct iio_buffer *buffer) in iio_buffer_init() argument
367 INIT_LIST_HEAD(&buffer->demux_list); in iio_buffer_init()
368 INIT_LIST_HEAD(&buffer->buffer_list); in iio_buffer_init()
369 INIT_LIST_HEAD(&buffer->dmabufs); in iio_buffer_init()
370 mutex_init(&buffer->dmabufs_mutex); in iio_buffer_init()
371 init_waitqueue_head(&buffer->pollq); in iio_buffer_init()
372 kref_init(&buffer->ref); in iio_buffer_init()
373 if (!buffer->watermark) in iio_buffer_init()
374 buffer->watermark = 1; in iio_buffer_init()
381 struct iio_buffer *buffer; in iio_device_detach_buffers() local
385 buffer = iio_dev_opaque->attached_buffers[i]; in iio_device_detach_buffers()
386 iio_buffer_put(buffer); in iio_device_detach_buffers()
443 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in iio_scan_el_show() local
447 buffer->scan_mask); in iio_scan_el_show()
509 struct iio_buffer *buffer, int bit) in iio_scan_mask_set() argument
523 bitmap_copy(trialmask, buffer->scan_mask, masklength); in iio_scan_mask_set()
535 bitmap_copy(buffer->scan_mask, trialmask, masklength); in iio_scan_mask_set()
546 static int iio_scan_mask_clear(struct iio_buffer *buffer, int bit) in iio_scan_mask_clear() argument
548 clear_bit(bit, buffer->scan_mask); in iio_scan_mask_clear()
553 struct iio_buffer *buffer, int bit) in iio_scan_mask_query() argument
558 if (!buffer->scan_mask) in iio_scan_mask_query()
562 return !!test_bit(bit, buffer->scan_mask); in iio_scan_mask_query()
575 struct iio_buffer *buffer = this_attr->buffer; in iio_scan_el_store() local
582 if (iio_buffer_is_active(buffer)) in iio_scan_el_store()
585 ret = iio_scan_mask_query(indio_dev, buffer, this_attr->address); in iio_scan_el_store()
593 ret = iio_scan_mask_set(indio_dev, buffer, this_attr->address); in iio_scan_el_store()
595 ret = iio_scan_mask_clear(buffer, this_attr->address); in iio_scan_el_store()
606 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in iio_scan_el_ts_show() local
608 return sysfs_emit(buf, "%d\n", buffer->scan_timestamp); in iio_scan_el_ts_show()
619 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in iio_scan_el_ts_store() local
627 if (iio_buffer_is_active(buffer)) in iio_scan_el_ts_store()
630 buffer->scan_timestamp = state; in iio_scan_el_ts_store()
636 struct iio_buffer *buffer, in iio_buffer_add_channel_sysfs() argument
648 buffer, in iio_buffer_add_channel_sysfs()
649 &buffer->buffer_attr_list); in iio_buffer_add_channel_sysfs()
660 buffer, in iio_buffer_add_channel_sysfs()
661 &buffer->buffer_attr_list); in iio_buffer_add_channel_sysfs()
673 buffer, in iio_buffer_add_channel_sysfs()
674 &buffer->buffer_attr_list); in iio_buffer_add_channel_sysfs()
683 buffer, in iio_buffer_add_channel_sysfs()
684 &buffer->buffer_attr_list); in iio_buffer_add_channel_sysfs()
695 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in length_show() local
697 return sysfs_emit(buf, "%d\n", buffer->length); in length_show()
705 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in length_store() local
713 if (val == buffer->length) in length_store()
717 if (iio_buffer_is_active(buffer)) in length_store()
720 buffer->access->set_length(buffer, val); in length_store()
722 if (buffer->length && buffer->length < buffer->watermark) in length_store()
723 buffer->watermark = buffer->length; in length_store()
731 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in enable_show() local
733 return sysfs_emit(buf, "%d\n", iio_buffer_is_active(buffer)); in enable_show()
796 struct iio_buffer *buffer) in iio_buffer_activate() argument
800 iio_buffer_get(buffer); in iio_buffer_activate()
801 list_add(&buffer->buffer_list, &iio_dev_opaque->buffer_list); in iio_buffer_activate()
804 static void iio_buffer_deactivate(struct iio_buffer *buffer) in iio_buffer_deactivate() argument
806 list_del_init(&buffer->buffer_list); in iio_buffer_deactivate()
807 wake_up_interruptible(&buffer->pollq); in iio_buffer_deactivate()
808 iio_buffer_put(buffer); in iio_buffer_deactivate()
814 struct iio_buffer *buffer, *_buffer; in iio_buffer_deactivate_all() local
816 list_for_each_entry_safe(buffer, _buffer, in iio_buffer_deactivate_all()
818 iio_buffer_deactivate(buffer); in iio_buffer_deactivate_all()
821 static int iio_buffer_enable(struct iio_buffer *buffer, in iio_buffer_enable() argument
824 if (!buffer->access->enable) in iio_buffer_enable()
826 return buffer->access->enable(buffer, indio_dev); in iio_buffer_enable()
829 static int iio_buffer_disable(struct iio_buffer *buffer, in iio_buffer_disable() argument
832 if (!buffer->access->disable) in iio_buffer_disable()
834 return buffer->access->disable(buffer, indio_dev); in iio_buffer_disable()
838 struct iio_buffer *buffer) in iio_buffer_update_bytes_per_datum() argument
842 if (!buffer->access->set_bytes_per_datum) in iio_buffer_update_bytes_per_datum()
845 bytes = iio_compute_scan_bytes(indio_dev, buffer->scan_mask, in iio_buffer_update_bytes_per_datum()
846 buffer->scan_timestamp); in iio_buffer_update_bytes_per_datum()
848 buffer->access->set_bytes_per_datum(buffer, bytes); in iio_buffer_update_bytes_per_datum()
852 struct iio_buffer *buffer) in iio_buffer_request_update() argument
856 iio_buffer_update_bytes_per_datum(indio_dev, buffer); in iio_buffer_request_update()
857 if (buffer->access->request_update) { in iio_buffer_request_update()
858 ret = buffer->access->request_update(buffer); in iio_buffer_request_update()
896 struct iio_buffer *buffer; in iio_verify_update() local
920 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_verify_update()
921 if (buffer == remove_buffer) in iio_verify_update()
923 modes &= buffer->access->modes; in iio_verify_update()
924 config->watermark = min(config->watermark, buffer->watermark); in iio_verify_update()
961 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_verify_update()
962 if (buffer == remove_buffer) in iio_verify_update()
964 bitmap_or(compound_mask, compound_mask, buffer->scan_mask, in iio_verify_update()
966 scan_timestamp |= buffer->scan_timestamp; in iio_verify_update()
1008 static void iio_buffer_demux_free(struct iio_buffer *buffer) in iio_buffer_demux_free() argument
1012 list_for_each_entry_safe(p, q, &buffer->demux_list, l) { in iio_buffer_demux_free()
1018 static int iio_buffer_add_demux(struct iio_buffer *buffer, in iio_buffer_add_demux() argument
1033 list_add_tail(&(*p)->l, &buffer->demux_list); in iio_buffer_add_demux()
1040 struct iio_buffer *buffer) in iio_buffer_update_demux() argument
1048 iio_buffer_demux_free(buffer); in iio_buffer_update_demux()
1049 kfree(buffer->demux_bounce); in iio_buffer_update_demux()
1050 buffer->demux_bounce = NULL; in iio_buffer_update_demux()
1054 buffer->scan_mask, masklength)) in iio_buffer_update_demux()
1058 for_each_set_bit(out_ind, buffer->scan_mask, masklength) { in iio_buffer_update_demux()
1079 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length); in iio_buffer_update_demux()
1086 if (buffer->scan_timestamp) { in iio_buffer_update_demux()
1094 ret = iio_buffer_add_demux(buffer, &p, in_loc, out_loc, length); in iio_buffer_update_demux()
1099 buffer->demux_bounce = kzalloc(out_loc, GFP_KERNEL); in iio_buffer_update_demux()
1100 if (!buffer->demux_bounce) { in iio_buffer_update_demux()
1107 iio_buffer_demux_free(buffer); in iio_buffer_update_demux()
1115 struct iio_buffer *buffer; in iio_update_demux() local
1118 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_update_demux()
1119 ret = iio_buffer_update_demux(indio_dev, buffer); in iio_update_demux()
1126 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) in iio_update_demux()
1127 iio_buffer_demux_free(buffer); in iio_update_demux()
1136 struct iio_buffer *buffer, *tmp = NULL; in iio_enable_buffers() local
1172 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_enable_buffers()
1173 ret = iio_buffer_enable(buffer, indio_dev); in iio_enable_buffers()
1175 tmp = buffer; in iio_enable_buffers()
1204 buffer = list_prepare_entry(tmp, &iio_dev_opaque->buffer_list, buffer_list); in iio_enable_buffers()
1205 list_for_each_entry_continue_reverse(buffer, &iio_dev_opaque->buffer_list, in iio_enable_buffers()
1207 iio_buffer_disable(buffer, indio_dev); in iio_enable_buffers()
1221 struct iio_buffer *buffer; in iio_disable_buffers() local
1247 list_for_each_entry(buffer, &iio_dev_opaque->buffer_list, buffer_list) { in iio_disable_buffers()
1248 ret2 = iio_buffer_disable(buffer, indio_dev); in iio_disable_buffers()
1365 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in enable_store() local
1375 inlist = iio_buffer_is_active(buffer); in enable_store()
1381 ret = __iio_update_buffers(indio_dev, buffer, NULL); in enable_store()
1383 ret = __iio_update_buffers(indio_dev, NULL, buffer); in enable_store()
1393 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in watermark_show() local
1395 return sysfs_emit(buf, "%u\n", buffer->watermark); in watermark_show()
1404 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in watermark_store() local
1416 if (val > buffer->length) in watermark_store()
1419 if (iio_buffer_is_active(buffer)) in watermark_store()
1422 buffer->watermark = val; in watermark_store()
1430 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in data_available_show() local
1432 return sysfs_emit(buf, "%zu\n", iio_buffer_data_available(buffer)); in data_available_show()
1439 struct iio_buffer *buffer = to_iio_dev_attr(attr)->buffer; in direction_show() local
1441 switch (buffer->direction) { in direction_show()
1475 static struct attribute *iio_buffer_wrap_attr(struct iio_buffer *buffer, in iio_buffer_wrap_attr() argument
1485 iio_attr->buffer = buffer; in iio_buffer_wrap_attr()
1495 list_add(&iio_attr->l, &buffer->buffer_attr_list); in iio_buffer_wrap_attr()
1563 struct iio_buffer *buffer = priv->buffer; in iio_buffer_dmabuf_release() local
1570 buffer->access->detach_dmabuf(buffer, priv->block); in iio_buffer_dmabuf_release()
1595 struct iio_buffer *buffer = ib->buffer; in iio_buffer_chrdev_release() local
1598 wake_up(&buffer->pollq); in iio_buffer_chrdev_release()
1600 guard(mutex)(&buffer->dmabufs_mutex); in iio_buffer_chrdev_release()
1603 list_for_each_entry_safe(priv, tmp, &buffer->dmabufs, entry) { in iio_buffer_chrdev_release()
1609 clear_bit(IIO_BUSY_BIT_POS, &buffer->flags); in iio_buffer_chrdev_release()
1631 struct iio_buffer *buffer = ib->buffer; in iio_buffer_find_attachment() local
1635 guard(mutex)(&buffer->dmabufs_mutex); in iio_buffer_find_attachment()
1637 list_for_each_entry(priv, &buffer->dmabufs, entry) { in iio_buffer_find_attachment()
1655 struct iio_buffer *buffer = ib->buffer; in iio_buffer_attach_dmabuf() local
1661 if (!buffer->access->attach_dmabuf in iio_buffer_attach_dmabuf()
1662 || !buffer->access->detach_dmabuf in iio_buffer_attach_dmabuf()
1663 || !buffer->access->enqueue_dmabuf) in iio_buffer_attach_dmabuf()
1692 priv->dir = buffer->direction == IIO_BUFFER_DIRECTION_IN in iio_buffer_attach_dmabuf()
1703 priv->buffer = buffer; in iio_buffer_attach_dmabuf()
1707 priv->block = buffer->access->attach_dmabuf(buffer, attach); in iio_buffer_attach_dmabuf()
1715 mutex_lock(&buffer->dmabufs_mutex); in iio_buffer_attach_dmabuf()
1721 list_for_each_entry(each, &buffer->dmabufs, entry) { in iio_buffer_attach_dmabuf()
1730 mutex_unlock(&buffer->dmabufs_mutex); in iio_buffer_attach_dmabuf()
1737 list_add(&priv->entry, &buffer->dmabufs); in iio_buffer_attach_dmabuf()
1738 mutex_unlock(&buffer->dmabufs_mutex); in iio_buffer_attach_dmabuf()
1759 struct iio_buffer *buffer = ib->buffer; in iio_buffer_detach_dmabuf() local
1772 guard(mutex)(&buffer->dmabufs_mutex); in iio_buffer_detach_dmabuf()
1774 list_for_each_entry(priv, &buffer->dmabufs, entry) { in iio_buffer_detach_dmabuf()
1815 struct iio_buffer *buffer = ib->buffer; in iio_buffer_enqueue_dmabuf() local
1836 if (cyclic && buffer->direction != IIO_BUFFER_DIRECTION_OUT) in iio_buffer_enqueue_dmabuf()
1879 dma_to_ram = buffer->direction == IIO_BUFFER_DIRECTION_IN; in iio_buffer_enqueue_dmabuf()
1892 if (buffer->access->lock_queue) in iio_buffer_enqueue_dmabuf()
1893 buffer->access->lock_queue(buffer); in iio_buffer_enqueue_dmabuf()
1905 ret = buffer->access->enqueue_dmabuf(buffer, priv->block, &fence->base, in iio_buffer_enqueue_dmabuf()
1916 if (buffer->access->unlock_queue) in iio_buffer_enqueue_dmabuf()
1917 buffer->access->unlock_queue(buffer); in iio_buffer_enqueue_dmabuf()
1925 if (buffer->access->unlock_queue) in iio_buffer_enqueue_dmabuf()
1926 buffer->access->unlock_queue(buffer); in iio_buffer_enqueue_dmabuf()
2011 struct iio_buffer *buffer; in iio_device_buffer_getfd() local
2022 buffer = iio_dev_opaque->attached_buffers[idx]; in iio_device_buffer_getfd()
2024 if (test_and_set_bit(IIO_BUSY_BIT_POS, &buffer->flags)) { in iio_device_buffer_getfd()
2036 ib->buffer = buffer; in iio_device_buffer_getfd()
2064 clear_bit(IIO_BUSY_BIT_POS, &buffer->flags); in iio_device_buffer_getfd()
2097 static int __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer, in __iio_buffer_alloc_sysfs_and_mask() argument
2110 if (buffer->attrs) { in __iio_buffer_alloc_sysfs_and_mask()
2111 while (buffer->attrs[buffer_attrcount]) in __iio_buffer_alloc_sysfs_and_mask()
2117 INIT_LIST_HEAD(&buffer->buffer_attr_list); in __iio_buffer_alloc_sysfs_and_mask()
2156 ret = iio_buffer_add_channel_sysfs(indio_dev, buffer, in __iio_buffer_alloc_sysfs_and_mask()
2165 if (masklength && !buffer->scan_mask) { in __iio_buffer_alloc_sysfs_and_mask()
2166 buffer->scan_mask = bitmap_zalloc(masklength, in __iio_buffer_alloc_sysfs_and_mask()
2168 if (!buffer->scan_mask) { in __iio_buffer_alloc_sysfs_and_mask()
2183 if (!buffer->access->set_length) in __iio_buffer_alloc_sysfs_and_mask()
2186 if (buffer->access->flags & INDIO_BUFFER_FLAG_FIXED_WATERMARK) in __iio_buffer_alloc_sysfs_and_mask()
2189 if (buffer->attrs) in __iio_buffer_alloc_sysfs_and_mask()
2190 for (i = 0, id_attr = buffer->attrs[i]; in __iio_buffer_alloc_sysfs_and_mask()
2191 (id_attr = buffer->attrs[i]); i++) in __iio_buffer_alloc_sysfs_and_mask()
2195 buffer->buffer_group.attrs = attr; in __iio_buffer_alloc_sysfs_and_mask()
2200 wrapped = iio_buffer_wrap_attr(buffer, attr[i]); in __iio_buffer_alloc_sysfs_and_mask()
2209 list_for_each_entry(p, &buffer->buffer_attr_list, l) in __iio_buffer_alloc_sysfs_and_mask()
2212 buffer->buffer_group.name = kasprintf(GFP_KERNEL, "buffer%d", index); in __iio_buffer_alloc_sysfs_and_mask()
2213 if (!buffer->buffer_group.name) { in __iio_buffer_alloc_sysfs_and_mask()
2218 ret = iio_device_register_sysfs_group(indio_dev, &buffer->buffer_group); in __iio_buffer_alloc_sysfs_and_mask()
2235 kfree(buffer->buffer_group.name); in __iio_buffer_alloc_sysfs_and_mask()
2237 kfree(buffer->buffer_group.attrs); in __iio_buffer_alloc_sysfs_and_mask()
2239 bitmap_free(buffer->scan_mask); in __iio_buffer_alloc_sysfs_and_mask()
2241 iio_free_chan_devattr_list(&buffer->buffer_attr_list); in __iio_buffer_alloc_sysfs_and_mask()
2246 static void __iio_buffer_free_sysfs_and_mask(struct iio_buffer *buffer, in __iio_buffer_free_sysfs_and_mask() argument
2252 bitmap_free(buffer->scan_mask); in __iio_buffer_free_sysfs_and_mask()
2253 kfree(buffer->buffer_group.name); in __iio_buffer_free_sysfs_and_mask()
2254 kfree(buffer->buffer_group.attrs); in __iio_buffer_free_sysfs_and_mask()
2255 iio_free_chan_devattr_list(&buffer->buffer_attr_list); in __iio_buffer_free_sysfs_and_mask()
2262 struct iio_buffer *buffer; in iio_buffers_alloc_sysfs_and_mask() local
2279 buffer = iio_dev_opaque->attached_buffers[idx]; in iio_buffers_alloc_sysfs_and_mask()
2280 ret = __iio_buffer_alloc_sysfs_and_mask(buffer, indio_dev, idx); in iio_buffers_alloc_sysfs_and_mask()
2300 buffer = iio_dev_opaque->attached_buffers[idx]; in iio_buffers_alloc_sysfs_and_mask()
2301 __iio_buffer_free_sysfs_and_mask(buffer, indio_dev, idx); in iio_buffers_alloc_sysfs_and_mask()
2309 struct iio_buffer *buffer; in iio_buffers_free_sysfs_and_mask() local
2319 buffer = iio_dev_opaque->attached_buffers[i]; in iio_buffers_free_sysfs_and_mask()
2320 __iio_buffer_free_sysfs_and_mask(buffer, indio_dev, i); in iio_buffers_free_sysfs_and_mask()
2340 static const void *iio_demux(struct iio_buffer *buffer, in iio_demux() argument
2345 if (list_empty(&buffer->demux_list)) in iio_demux()
2347 list_for_each_entry(t, &buffer->demux_list, l) in iio_demux()
2348 memcpy(buffer->demux_bounce + t->to, in iio_demux()
2351 return buffer->demux_bounce; in iio_demux()
2354 static int iio_push_to_buffer(struct iio_buffer *buffer, const void *data) in iio_push_to_buffer() argument
2356 const void *dataout = iio_demux(buffer, data); in iio_push_to_buffer()
2359 ret = buffer->access->store_to(buffer, dataout); in iio_push_to_buffer()
2367 wake_up_interruptible_poll(&buffer->pollq, EPOLLIN | EPOLLRDNORM); in iio_push_to_buffer()
2449 struct iio_buffer *buffer = container_of(ref, struct iio_buffer, ref); in iio_buffer_release() local
2451 mutex_destroy(&buffer->dmabufs_mutex); in iio_buffer_release()
2452 buffer->access->release(buffer); in iio_buffer_release()
2461 struct iio_buffer *iio_buffer_get(struct iio_buffer *buffer) in iio_buffer_get() argument
2463 if (buffer) in iio_buffer_get()
2464 kref_get(&buffer->ref); in iio_buffer_get()
2466 return buffer; in iio_buffer_get()
2474 void iio_buffer_put(struct iio_buffer *buffer) in iio_buffer_put() argument
2476 if (buffer) in iio_buffer_put()
2477 kref_put(&buffer->ref, iio_buffer_release); in iio_buffer_put()
2495 struct iio_buffer *buffer) in iio_device_attach_buffer() argument
2508 buffer = iio_buffer_get(buffer); in iio_device_attach_buffer()
2511 if (!indio_dev->buffer) in iio_device_attach_buffer()
2512 indio_dev->buffer = buffer; in iio_device_attach_buffer()
2514 iio_dev_opaque->attached_buffers[cnt - 1] = buffer; in iio_device_attach_buffer()