Lines Matching full:block

22  * For DMA buffers the storage is sub-divided into so called blocks. Each block
23 * has its own memory buffer. The size of the block is the granularity at which
25 * basic unit of data exchange from one sample to one block decreases the
28 * sample the overhead will be x for each sample. Whereas when using a block
36 * them with data. Block on the outgoing queue have been filled with data and
39 * A block can be in one of the following states:
41 * the block.
44 * * Owned by the DMA controller: The DMA controller is processing the block
49 * * Dead: A block that is dead has been marked as to be freed. It might still
52 * incoming or outgoing queue the block will be freed.
55 * with both the block structure as well as the storage memory for the block
56 * will be freed when the last reference to the block is dropped. This means a
57 * block must not be accessed without holding a reference.
65 * converter to the memory region of the block. Once the DMA transfer has been
67 * block.
69 * Prior to this it must set the bytes_used field of the block contains
71 * size of the block, but if the DMA hardware has certain alignment requirements
74 * datum, i.e. the block must not contain partial samples.
76 * The driver must call iio_dma_buffer_block_done() for each block it has
78 * perform a DMA transfer for the block, e.g. because the buffer was disabled
79 * before the block transfer was started. In this case it should set bytes_used
96 struct iio_dma_buffer_block *block = container_of(kref, in iio_buffer_block_release() local
99 WARN_ON(block->state != IIO_BLOCK_STATE_DEAD); in iio_buffer_block_release()
101 dma_free_coherent(block->queue->dev, PAGE_ALIGN(block->size), in iio_buffer_block_release()
102 block->vaddr, block->phys_addr); in iio_buffer_block_release()
104 iio_buffer_put(&block->queue->buffer); in iio_buffer_block_release()
105 kfree(block); in iio_buffer_block_release()
108 static void iio_buffer_block_get(struct iio_dma_buffer_block *block) in iio_buffer_block_get() argument
110 kref_get(&block->kref); in iio_buffer_block_get()
113 static void iio_buffer_block_put(struct iio_dma_buffer_block *block) in iio_buffer_block_put() argument
115 kref_put(&block->kref, iio_buffer_block_release); in iio_buffer_block_put()
127 struct iio_dma_buffer_block *block, *_block; in iio_dma_buffer_cleanup_worker() local
134 list_for_each_entry_safe(block, _block, &block_list, head) in iio_dma_buffer_cleanup_worker()
135 iio_buffer_block_release(&block->kref); in iio_dma_buffer_cleanup_worker()
141 struct iio_dma_buffer_block *block; in iio_buffer_block_release_atomic() local
144 block = container_of(kref, struct iio_dma_buffer_block, kref); in iio_buffer_block_release_atomic()
147 list_add_tail(&block->head, &iio_dma_buffer_dead_blocks); in iio_buffer_block_release_atomic()
156 static void iio_buffer_block_put_atomic(struct iio_dma_buffer_block *block) in iio_buffer_block_put_atomic() argument
158 kref_put(&block->kref, iio_buffer_block_release_atomic); in iio_buffer_block_put_atomic()
169 struct iio_dma_buffer_block *block; in iio_dma_buffer_alloc_block() local
171 block = kzalloc(sizeof(*block), GFP_KERNEL); in iio_dma_buffer_alloc_block()
172 if (!block) in iio_dma_buffer_alloc_block()
175 block->vaddr = dma_alloc_coherent(queue->dev, PAGE_ALIGN(size), in iio_dma_buffer_alloc_block()
176 &block->phys_addr, GFP_KERNEL); in iio_dma_buffer_alloc_block()
177 if (!block->vaddr) { in iio_dma_buffer_alloc_block()
178 kfree(block); in iio_dma_buffer_alloc_block()
182 block->size = size; in iio_dma_buffer_alloc_block()
183 block->state = IIO_BLOCK_STATE_DEQUEUED; in iio_dma_buffer_alloc_block()
184 block->queue = queue; in iio_dma_buffer_alloc_block()
185 INIT_LIST_HEAD(&block->head); in iio_dma_buffer_alloc_block()
186 kref_init(&block->kref); in iio_dma_buffer_alloc_block()
190 return block; in iio_dma_buffer_alloc_block()
193 static void _iio_dma_buffer_block_done(struct iio_dma_buffer_block *block) in _iio_dma_buffer_block_done() argument
195 struct iio_dma_buffer_queue *queue = block->queue; in _iio_dma_buffer_block_done()
201 if (block->state != IIO_BLOCK_STATE_DEAD) { in _iio_dma_buffer_block_done()
202 block->state = IIO_BLOCK_STATE_DONE; in _iio_dma_buffer_block_done()
203 list_add_tail(&block->head, &queue->outgoing); in _iio_dma_buffer_block_done()
208 * iio_dma_buffer_block_done() - Indicate that a block has been completed
209 * @block: The completed block
211 * Should be called when the DMA controller has finished handling the block to
212 * pass back ownership of the block to the queue.
214 void iio_dma_buffer_block_done(struct iio_dma_buffer_block *block) in iio_dma_buffer_block_done() argument
216 struct iio_dma_buffer_queue *queue = block->queue; in iio_dma_buffer_block_done()
220 _iio_dma_buffer_block_done(block); in iio_dma_buffer_block_done()
223 iio_buffer_block_put_atomic(block); in iio_dma_buffer_block_done()
229 * iio_dma_buffer_block_list_abort() - Indicate that a list block has been
235 * stopped. This will set bytes_used to 0 for each block in the list and then
241 struct iio_dma_buffer_block *block, *_block; in iio_dma_buffer_block_list_abort() local
245 list_for_each_entry_safe(block, _block, list, head) { in iio_dma_buffer_block_list_abort()
246 list_del(&block->head); in iio_dma_buffer_block_list_abort()
247 block->bytes_used = 0; in iio_dma_buffer_block_list_abort()
248 _iio_dma_buffer_block_done(block); in iio_dma_buffer_block_list_abort()
249 iio_buffer_block_put_atomic(block); in iio_dma_buffer_block_list_abort()
257 static bool iio_dma_block_reusable(struct iio_dma_buffer_block *block) in iio_dma_block_reusable() argument
260 * If the core owns the block it can be re-used. This should be the in iio_dma_block_reusable()
262 * not support abort and has not given back the block yet. in iio_dma_block_reusable()
264 switch (block->state) { in iio_dma_block_reusable()
284 struct iio_dma_buffer_block *block; in iio_dma_buffer_request_update() local
292 * buffering scheme with usually one block at a time being used by the in iio_dma_buffer_request_update()
309 block = queue->fileio.blocks[i]; in iio_dma_buffer_request_update()
312 if (block && (!iio_dma_block_reusable(block) || !try_reuse)) in iio_dma_buffer_request_update()
313 block->state = IIO_BLOCK_STATE_DEAD; in iio_dma_buffer_request_update()
328 block = queue->fileio.blocks[i]; in iio_dma_buffer_request_update()
329 if (block->state == IIO_BLOCK_STATE_DEAD) { in iio_dma_buffer_request_update()
331 iio_buffer_block_put(block); in iio_dma_buffer_request_update()
332 block = NULL; in iio_dma_buffer_request_update()
334 block->size = size; in iio_dma_buffer_request_update()
337 block = NULL; in iio_dma_buffer_request_update()
340 if (!block) { in iio_dma_buffer_request_update()
341 block = iio_dma_buffer_alloc_block(queue, size); in iio_dma_buffer_request_update()
342 if (!block) { in iio_dma_buffer_request_update()
346 queue->fileio.blocks[i] = block; in iio_dma_buffer_request_update()
349 block->state = IIO_BLOCK_STATE_QUEUED; in iio_dma_buffer_request_update()
350 list_add_tail(&block->head, &queue->incoming); in iio_dma_buffer_request_update()
361 struct iio_dma_buffer_block *block) in iio_dma_buffer_submit_block() argument
366 * If the hardware has already been removed we put the block into in iio_dma_buffer_submit_block()
373 block->state = IIO_BLOCK_STATE_ACTIVE; in iio_dma_buffer_submit_block()
374 iio_buffer_block_get(block); in iio_dma_buffer_submit_block()
375 ret = queue->ops->submit(queue, block); in iio_dma_buffer_submit_block()
387 iio_buffer_block_put(block); in iio_dma_buffer_submit_block()
405 struct iio_dma_buffer_block *block, *_block; in iio_dma_buffer_enable() local
409 list_for_each_entry_safe(block, _block, &queue->incoming, head) { in iio_dma_buffer_enable()
410 list_del(&block->head); in iio_dma_buffer_enable()
411 iio_dma_buffer_submit_block(queue, block); in iio_dma_buffer_enable()
444 struct iio_dma_buffer_block *block) in iio_dma_buffer_enqueue() argument
446 if (block->state == IIO_BLOCK_STATE_DEAD) { in iio_dma_buffer_enqueue()
447 iio_buffer_block_put(block); in iio_dma_buffer_enqueue()
449 iio_dma_buffer_submit_block(queue, block); in iio_dma_buffer_enqueue()
451 block->state = IIO_BLOCK_STATE_QUEUED; in iio_dma_buffer_enqueue()
452 list_add_tail(&block->head, &queue->incoming); in iio_dma_buffer_enqueue()
459 struct iio_dma_buffer_block *block; in iio_dma_buffer_dequeue() local
462 block = list_first_entry_or_null(&queue->outgoing, struct in iio_dma_buffer_dequeue()
464 if (block != NULL) { in iio_dma_buffer_dequeue()
465 list_del(&block->head); in iio_dma_buffer_dequeue()
466 block->state = IIO_BLOCK_STATE_DEQUEUED; in iio_dma_buffer_dequeue()
470 return block; in iio_dma_buffer_dequeue()
486 struct iio_dma_buffer_block *block; in iio_dma_buffer_read() local
495 block = iio_dma_buffer_dequeue(queue); in iio_dma_buffer_read()
496 if (block == NULL) { in iio_dma_buffer_read()
501 queue->fileio.active_block = block; in iio_dma_buffer_read()
503 block = queue->fileio.active_block; in iio_dma_buffer_read()
507 if (n > block->bytes_used - queue->fileio.pos) in iio_dma_buffer_read()
508 n = block->bytes_used - queue->fileio.pos; in iio_dma_buffer_read()
510 if (copy_to_user(user_buffer, block->vaddr + queue->fileio.pos, n)) { in iio_dma_buffer_read()
517 if (queue->fileio.pos == block->bytes_used) { in iio_dma_buffer_read()
519 iio_dma_buffer_enqueue(queue, block); in iio_dma_buffer_read()
541 struct iio_dma_buffer_block *block; in iio_dma_buffer_data_available() local
545 * For counting the available bytes we'll use the size of the block not in iio_dma_buffer_data_available()
546 * the number of actual bytes available in the block. Otherwise it is in iio_dma_buffer_data_available()
556 list_for_each_entry(block, &queue->outgoing, head) in iio_dma_buffer_data_available()
557 data_available += block->size; in iio_dma_buffer_data_available()