So I will add two func for my use, do you think it is ok? I need to align the address of allocated muram. And I will set algo = gen_pool_first_fit_align.
+unsigned long gen_pool_alloc_align(struct gen_pool *pool, size_t size, + unsigned long align) +{ + struct gen_pool_chunk *chunk; + unsigned long addr = 0; + unsigned long align_mask; + int order = pool->min_alloc_order; + int nbits, start_bit = 0, end_bit, remain; + +#ifndef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG + BUG_ON(in_nmi()); +#endif + + if (size == 0) + return 0; + + align_mask = ((align + (1UL << order) - 1) >> order) - 1; + nbits = (size + (1UL << order) - 1) >> order; + rcu_read_lock(); + list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) { + if (size > atomic_read(&chunk->avail)) + continue; + + end_bit = chunk_size(chunk) >> order; +retry: + start_bit = pool->algo(chunk->bits, end_bit, start_bit, nbits, + pool->data, align_mask); + if (start_bit >= end_bit) + continue; + remain = bitmap_set_ll(chunk->bits, start_bit, nbits); + if (remain) { + remain = bitmap_clear_ll(chunk->bits, start_bit, + nbits - remain); + BUG_ON(remain); + goto retry; + } + + addr = chunk->start_addr + ((unsigned long)start_bit << order); + size = nbits << order; + atomic_sub(size, &chunk->avail); + break; + } + rcu_read_unlock(); + return addr; +} +EXPORT_SYMBOL(gen_pool_alloc); + * gen_pool_first_fit_align - find the first available region + * of memory matching the size requirement. The region will be aligned + * to the order of the size specified. + * @map: The address to base the search on + * @size: The bitmap size in bits + * @start: The bitnumber to start searching at + * @nr: The number of zeroed bits we're looking for + * @data: additional data - unused + */ +unsigned long gen_pool_first_fit_align(unsigned long *map, + unsigned long size, unsigned long start, + unsigned int nr, void *data, unsigned long align_mask) +{ + return bitmap_find_next_zero_area(map, size, start, nr, align_mask); +} +EXPORT_SYMBOL(gen_pool_first_fit_align); + Best Regards Zhao Qiang > -----Original Message----- > From: Wood Scott-B07421 > Sent: Wednesday, July 08, 2015 11:28 AM > To: Zhao Qiang-B45475 > Cc: linuxppc-dev@lists.ozlabs.org; Xie Xiaobo-R63061 > Subject: Re: [PATCH 2/2] rheap: move rheap.c from arch/powerpc/lib/ to > lib/ > > On Tue, 2015-07-07 at 22:26 -0500, Zhao Qiang-B45475 wrote: > > Now the point is, genalloc is not so proper to qe muram while rheap is > > written to manage muram, > > rheap is not specific to muram. > > > if use genalloc instead of rheap, there will be amounts of work to do. > > Not much. I think I've spent more time responding to continual e-mails > on this topic than it would have taken to convert it. :-P > > > I have a suggestion, how about to put rheap under drivers/soc/qe, > > because rheap is To manage muram when it is added to sdk. > > No. > > -Scott _______________________________________________ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.org https://lists.ozlabs.org/listinfo/linuxppc-dev