Lines Matching +full:dma +full:- +full:safe +full:- +full:map
4 * kmalloc/kfree interface. Uses for this includes on-device special
7 * It is safe to use the allocator in NMI handlers and other special
20 * On architectures that don't have NMI-safe cmpxchg implementation,
25 * Copyright 2005 (C) Jes Sorensen <jes@trained-monkey.org>
42 return chunk->end_addr - chunk->start_addr + 1; in chunk_size()
53 return -EBUSY; in set_bits_ll()
68 return -EBUSY; in clear_bits_ll()
76 * bitmap_set_ll - set the specified number of bits at the specified position
77 * @map: pointer to a bitmap
78 * @start: a bit position in @map
81 * Set @nr bits start from @start in @map lock-lessly. Several users
86 static int bitmap_set_ll(unsigned long *map, int start, int nr) in bitmap_set_ll() argument
88 unsigned long *p = map + BIT_WORD(start); in bitmap_set_ll()
90 int bits_to_set = BITS_PER_LONG - (start % BITS_PER_LONG); in bitmap_set_ll()
93 while (nr - bits_to_set >= 0) { in bitmap_set_ll()
96 nr -= bits_to_set; in bitmap_set_ll()
111 * bitmap_clear_ll - clear the specified number of bits at the specified position
112 * @map: pointer to a bitmap
113 * @start: a bit position in @map
116 * Clear @nr bits start from @start in @map lock-lessly. Several users
121 static int bitmap_clear_ll(unsigned long *map, int start, int nr) in bitmap_clear_ll() argument
123 unsigned long *p = map + BIT_WORD(start); in bitmap_clear_ll()
125 int bits_to_clear = BITS_PER_LONG - (start % BITS_PER_LONG); in bitmap_clear_ll()
128 while (nr - bits_to_clear >= 0) { in bitmap_clear_ll()
131 nr -= bits_to_clear; in bitmap_clear_ll()
146 * gen_pool_create - create a new special memory pool
148 * @nid: node id of the node the pool structure should be allocated on, or -1
159 spin_lock_init(&pool->lock); in gen_pool_create()
160 INIT_LIST_HEAD(&pool->chunks); in gen_pool_create()
161 pool->min_alloc_order = min_alloc_order; in gen_pool_create()
162 pool->algo = gen_pool_first_fit; in gen_pool_create()
163 pool->data = NULL; in gen_pool_create()
164 pool->name = NULL; in gen_pool_create()
171 * gen_pool_add_virt - add a new chunk of special memory to the pool
177 * allocated on, or -1
181 * Returns 0 on success or a -ve errno on failure.
187 int nbits = size >> pool->min_alloc_order; in gen_pool_add_virt()
193 return -ENOMEM; in gen_pool_add_virt()
195 chunk->phys_addr = phys; in gen_pool_add_virt()
196 chunk->start_addr = virt; in gen_pool_add_virt()
197 chunk->end_addr = virt + size - 1; in gen_pool_add_virt()
198 atomic_long_set(&chunk->avail, size); in gen_pool_add_virt()
200 spin_lock(&pool->lock); in gen_pool_add_virt()
201 list_add_rcu(&chunk->next_chunk, &pool->chunks); in gen_pool_add_virt()
202 spin_unlock(&pool->lock); in gen_pool_add_virt()
209 * gen_pool_virt_to_phys - return the physical address of memory
213 * Returns the physical address on success, or -1 on error.
218 phys_addr_t paddr = -1; in gen_pool_virt_to_phys()
221 list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) { in gen_pool_virt_to_phys()
222 if (addr >= chunk->start_addr && addr <= chunk->end_addr) { in gen_pool_virt_to_phys()
223 paddr = chunk->phys_addr + (addr - chunk->start_addr); in gen_pool_virt_to_phys()
234 * gen_pool_destroy - destroy a special memory pool
244 int order = pool->min_alloc_order; in gen_pool_destroy()
247 list_for_each_safe(_chunk, _next_chunk, &pool->chunks) { in gen_pool_destroy()
249 list_del(&chunk->next_chunk); in gen_pool_destroy()
252 bit = find_next_bit(chunk->bits, end_bit, 0); in gen_pool_destroy()
257 kfree_const(pool->name); in gen_pool_destroy()
263 * gen_pool_alloc - allocate special memory from the pool
268 * Uses the pool allocation function (with first-fit algorithm by default).
270 * NMI-safe cmpxchg implementation.
274 return gen_pool_alloc_algo(pool, size, pool->algo, pool->data); in gen_pool_alloc()
279 * gen_pool_alloc_algo - allocate special memory from the pool
286 * Uses the pool allocation function (with first-fit algorithm by default).
288 * NMI-safe cmpxchg implementation.
295 int order = pool->min_alloc_order; in gen_pool_alloc_algo()
305 nbits = (size + (1UL << order) - 1) >> order; in gen_pool_alloc_algo()
307 list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) { in gen_pool_alloc_algo()
308 if (size > atomic_long_read(&chunk->avail)) in gen_pool_alloc_algo()
314 start_bit = algo(chunk->bits, end_bit, start_bit, in gen_pool_alloc_algo()
315 nbits, data, pool, chunk->start_addr); in gen_pool_alloc_algo()
318 remain = bitmap_set_ll(chunk->bits, start_bit, nbits); in gen_pool_alloc_algo()
320 remain = bitmap_clear_ll(chunk->bits, start_bit, in gen_pool_alloc_algo()
321 nbits - remain); in gen_pool_alloc_algo()
326 addr = chunk->start_addr + ((unsigned long)start_bit << order); in gen_pool_alloc_algo()
328 atomic_long_sub(size, &chunk->avail); in gen_pool_alloc_algo()
337 * gen_pool_dma_alloc - allocate special memory from the pool for DMA usage
340 * @dma: dma-view physical address return value. Use NULL if unneeded.
343 * Uses the pool allocation function (with first-fit algorithm by default).
345 * NMI-safe cmpxchg implementation.
347 void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size, dma_addr_t *dma) in gen_pool_dma_alloc() argument
358 if (dma) in gen_pool_dma_alloc()
359 *dma = gen_pool_virt_to_phys(pool, vaddr); in gen_pool_dma_alloc()
366 * gen_pool_free - free allocated special memory back to the pool
373 * NMI-safe cmpxchg implementation.
378 int order = pool->min_alloc_order; in gen_pool_free()
385 nbits = (size + (1UL << order) - 1) >> order; in gen_pool_free()
387 list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) { in gen_pool_free()
388 if (addr >= chunk->start_addr && addr <= chunk->end_addr) { in gen_pool_free()
389 BUG_ON(addr + size - 1 > chunk->end_addr); in gen_pool_free()
390 start_bit = (addr - chunk->start_addr) >> order; in gen_pool_free()
391 remain = bitmap_clear_ll(chunk->bits, start_bit, nbits); in gen_pool_free()
394 atomic_long_add(size, &chunk->avail); in gen_pool_free()
405 * gen_pool_for_each_chunk - call func for every chunk of generic memory pool
420 list_for_each_entry_rcu(chunk, &(pool)->chunks, next_chunk) in gen_pool_for_each_chunk()
427 * addr_in_gen_pool - checks if an address falls within the range of a pool
439 unsigned long end = start + size - 1; in addr_in_gen_pool()
443 list_for_each_entry_rcu(chunk, &(pool)->chunks, next_chunk) { in addr_in_gen_pool()
444 if (start >= chunk->start_addr && start <= chunk->end_addr) { in addr_in_gen_pool()
445 if (end <= chunk->end_addr) { in addr_in_gen_pool()
456 * gen_pool_avail - get available free space of the pool
467 list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) in gen_pool_avail()
468 avail += atomic_long_read(&chunk->avail); in gen_pool_avail()
475 * gen_pool_size - get size in bytes of memory managed by the pool
486 list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) in gen_pool_size()
494 * gen_pool_set_algo - set the allocation algorithm
507 pool->algo = algo; in gen_pool_set_algo()
508 if (!pool->algo) in gen_pool_set_algo()
509 pool->algo = gen_pool_first_fit; in gen_pool_set_algo()
511 pool->data = data; in gen_pool_set_algo()
518 * gen_pool_first_fit - find the first available region
520 * @map: The address to base the search on
524 * @data: additional data - unused
527 unsigned long gen_pool_first_fit(unsigned long *map, unsigned long size, in gen_pool_first_fit() argument
531 return bitmap_find_next_zero_area(map, size, start, nr, 0); in gen_pool_first_fit()
536 * gen_pool_first_fit_align - find the first available region
538 * @map: The address to base the search on
545 unsigned long gen_pool_first_fit_align(unsigned long *map, unsigned long size, in gen_pool_first_fit_align() argument
554 order = pool->min_alloc_order; in gen_pool_first_fit_align()
555 align_mask = ((alignment->align + (1UL << order) - 1) >> order) - 1; in gen_pool_first_fit_align()
556 align_off = (start_addr & (alignment->align - 1)) >> order; in gen_pool_first_fit_align()
558 return bitmap_find_next_zero_area_off(map, size, start, nr, in gen_pool_first_fit_align()
564 * gen_pool_fixed_alloc - reserve a specific region
565 * @map: The address to base the search on
572 unsigned long gen_pool_fixed_alloc(unsigned long *map, unsigned long size, in gen_pool_fixed_alloc() argument
582 order = pool->min_alloc_order; in gen_pool_fixed_alloc()
583 offset_bit = fixed_data->offset >> order; in gen_pool_fixed_alloc()
584 if (WARN_ON(fixed_data->offset & ((1UL << order) - 1))) in gen_pool_fixed_alloc()
587 start_bit = bitmap_find_next_zero_area(map, size, in gen_pool_fixed_alloc()
596 * gen_pool_first_fit_order_align - find the first available region
599 * @map: The address to base the search on
603 * @data: additional data - unused
606 unsigned long gen_pool_first_fit_order_align(unsigned long *map, in gen_pool_first_fit_order_align() argument
611 unsigned long align_mask = roundup_pow_of_two(nr) - 1; in gen_pool_first_fit_order_align()
613 return bitmap_find_next_zero_area(map, size, start, nr, align_mask); in gen_pool_first_fit_order_align()
618 * gen_pool_best_fit - find the best fitting region of memory
620 * @map: The address to base the search on
624 * @data: additional data - unused
630 unsigned long gen_pool_best_fit(unsigned long *map, unsigned long size, in gen_pool_best_fit() argument
638 index = bitmap_find_next_zero_area(map, size, start, nr, 0); in gen_pool_best_fit()
641 int next_bit = find_next_bit(map, size, index + nr); in gen_pool_best_fit()
642 if ((next_bit - index) < len) { in gen_pool_best_fit()
643 len = next_bit - index; in gen_pool_best_fit()
648 index = bitmap_find_next_zero_area(map, size, in gen_pool_best_fit()
666 if (!data && !(*p)->name) in devm_gen_pool_match()
669 if (!data || !(*p)->name) in devm_gen_pool_match()
672 return !strcmp((*p)->name, data); in devm_gen_pool_match()
676 * gen_pool_get - Obtain the gen_pool (if any) for a device
695 * devm_gen_pool_create - managed gen_pool_create
713 return ERR_PTR(-EINVAL); in devm_gen_pool_create()
718 return ERR_PTR(-ENOMEM); in devm_gen_pool_create()
730 pool->name = pool_name; in devm_gen_pool_create()
740 return ERR_PTR(-ENOMEM); in devm_gen_pool_create()
746 * of_gen_pool_get - find a pool by phandle property
776 name = np_pool->name; in of_gen_pool_get()
779 pool = gen_pool_get(&pdev->dev, name); in of_gen_pool_get()