Lines Matching +full:power +full:- +full:managed
1 // SPDX-License-Identifier: GPL-2.0-only
9 * This allocator returns small blocks of a given size which are DMA-able by
15 * represented by the 'struct dma_pool' which keeps a doubly-linked list of
17 * least 'size' bytes. Free blocks are tracked in an unsorted singly-linked
23 #include <linux/dma-mapping.h>
77 size = sysfs_emit(buf, "poolinfo - 0.1\n"); in pools_show()
80 list_for_each_entry(pool, &dev->dma_pools, pools) { in pools_show()
81 /* per-pool info, no real statistics yet */ in pools_show()
82 size += sysfs_emit_at(buf, size, "%-16s %4zu %4zu %4u %2zu\n", in pools_show()
83 pool->name, pool->nr_active, in pools_show()
84 pool->nr_blocks, pool->size, in pools_show()
85 pool->nr_pages); in pools_show()
101 for (i = sizeof(struct dma_block); i < pool->size; i++) { in pool_check_block()
104 dev_err(pool->dev, "%s %s, %p (corrupted)\n", __func__, in pool_check_block()
105 pool->name, block); in pool_check_block()
112 data, pool->size, 1); in pool_check_block()
117 memset(block, POOL_POISON_ALLOCATED, pool->size); in pool_check_block()
124 list_for_each_entry(page, &pool->page_list, page_list) { in pool_find_page()
125 if (dma < page->dma) in pool_find_page()
127 if ((dma - page->dma) < pool->allocation) in pool_find_page()
135 struct dma_block *block = pool->next_block; in pool_block_err()
140 dev_err(pool->dev, "%s %s, %p/%pad (bad dma)\n", in pool_block_err()
141 __func__, pool->name, vaddr, &dma); in pool_block_err()
147 block = block->next_block; in pool_block_err()
150 dev_err(pool->dev, "%s %s, dma %pad already free\n", in pool_block_err()
151 __func__, pool->name, &dma); in pool_block_err()
155 memset(vaddr, POOL_POISON_FREED, pool->size); in pool_block_err()
161 memset(page->vaddr, POOL_POISON_FREED, pool->allocation); in pool_init_page()
172 memset(vaddr, 0, pool->size); in pool_block_err()
183 struct dma_block *block = pool->next_block; in pool_block_pop()
186 pool->next_block = block->next_block; in pool_block_pop()
187 pool->nr_active++; in pool_block_pop()
195 block->dma = dma; in pool_block_push()
196 block->next_block = pool->next_block; in pool_block_push()
197 pool->next_block = block; in pool_block_push()
202 * dma_pool_create - Creates a pool of consistent memory blocks, for dma.
206 * @align: alignment requirement for blocks; must be a power of two
207 * @boundary: returned blocks won't cross this power of two boundary
236 else if (align & (align - 1)) in dma_pool_create()
249 else if ((boundary < size) || (boundary & (boundary - 1))) in dma_pool_create()
258 strscpy(retval->name, name, sizeof(retval->name)); in dma_pool_create()
260 retval->dev = dev; in dma_pool_create()
262 INIT_LIST_HEAD(&retval->page_list); in dma_pool_create()
263 spin_lock_init(&retval->lock); in dma_pool_create()
264 retval->size = size; in dma_pool_create()
265 retval->boundary = boundary; in dma_pool_create()
266 retval->allocation = allocation; in dma_pool_create()
267 INIT_LIST_HEAD(&retval->pools); in dma_pool_create()
270 * pools_lock ensures that the ->dma_pools list does not get corrupted. in dma_pool_create()
279 empty = list_empty(&dev->dma_pools); in dma_pool_create()
280 list_add(&retval->pools, &dev->dma_pools); in dma_pool_create()
288 list_del(&retval->pools); in dma_pool_create()
302 unsigned int next_boundary = pool->boundary, offset = 0; in pool_initialise_page()
306 while (offset + pool->size <= pool->allocation) { in pool_initialise_page()
307 if (offset + pool->size > next_boundary) { in pool_initialise_page()
309 next_boundary += pool->boundary; in pool_initialise_page()
313 block = page->vaddr + offset; in pool_initialise_page()
314 block->dma = page->dma + offset; in pool_initialise_page()
315 block->next_block = NULL; in pool_initialise_page()
318 last->next_block = block; in pool_initialise_page()
323 offset += pool->size; in pool_initialise_page()
324 pool->nr_blocks++; in pool_initialise_page()
327 last->next_block = pool->next_block; in pool_initialise_page()
328 pool->next_block = first; in pool_initialise_page()
330 list_add(&page->page_list, &pool->page_list); in pool_initialise_page()
331 pool->nr_pages++; in pool_initialise_page()
342 page->vaddr = dma_alloc_coherent(pool->dev, pool->allocation, in pool_alloc_page()
343 &page->dma, mem_flags); in pool_alloc_page()
344 if (!page->vaddr) { in pool_alloc_page()
353 * dma_pool_destroy - destroys a pool of dma memory blocks.
370 list_del(&pool->pools); in dma_pool_destroy()
371 empty = list_empty(&pool->dev->dma_pools); in dma_pool_destroy()
374 device_remove_file(pool->dev, &dev_attr_pools); in dma_pool_destroy()
377 if (pool->nr_active) { in dma_pool_destroy()
378 dev_err(pool->dev, "%s %s busy\n", __func__, pool->name); in dma_pool_destroy()
382 list_for_each_entry_safe(page, tmp, &pool->page_list, page_list) { in dma_pool_destroy()
384 dma_free_coherent(pool->dev, pool->allocation, in dma_pool_destroy()
385 page->vaddr, page->dma); in dma_pool_destroy()
386 list_del(&page->page_list); in dma_pool_destroy()
395 * dma_pool_alloc - get a block of consistent memory
413 spin_lock_irqsave(&pool->lock, flags); in dma_pool_alloc()
418 * &pool->lock in dma_pool_alloc()
420 spin_unlock_irqrestore(&pool->lock, flags); in dma_pool_alloc()
426 spin_lock_irqsave(&pool->lock, flags); in dma_pool_alloc()
430 spin_unlock_irqrestore(&pool->lock, flags); in dma_pool_alloc()
432 *handle = block->dma; in dma_pool_alloc()
435 memset(block, 0, pool->size); in dma_pool_alloc()
442 * dma_pool_free - put block back into dma pool
448 * unless it is first re-allocated.
455 spin_lock_irqsave(&pool->lock, flags); in dma_pool_free()
458 pool->nr_active--; in dma_pool_free()
460 spin_unlock_irqrestore(&pool->lock, flags); in dma_pool_free()
465 * Managed DMA pool
480 * dmam_pool_create - Managed dma_pool_create()
484 * @align: alignment requirement for blocks; must be a power of two
487 * Managed dma_pool_create(). DMA pool created with this function is
490 * Return: a managed dma allocation pool with the requested
513 * dmam_pool_destroy - Managed dma_pool_destroy()
516 * Managed dma_pool_destroy().
520 struct device *dev = pool->dev; in dmam_pool_destroy()