@@ -269,6 +269,25 @@ EXPORT_SYMBOL(gen_pool_destroy);
269269 * NMI-safe cmpxchg implementation.
270270 */
271271unsigned long gen_pool_alloc (struct gen_pool * pool , size_t size )
272+ {
273+ return gen_pool_alloc_algo (pool , size , pool -> algo , pool -> data );
274+ }
275+ EXPORT_SYMBOL (gen_pool_alloc );
276+
277+ /**
278+ * gen_pool_alloc_algo - allocate special memory from the pool
279+ * @pool: pool to allocate from
280+ * @size: number of bytes to allocate from the pool
281+ * @algo: algorithm passed from caller
282+ * @data: data passed to algorithm
283+ *
284+ * Allocate the requested number of bytes from the specified pool.
285+ * Uses the pool allocation function (with first-fit algorithm by default).
286+ * Can not be used in NMI handler on architectures without
287+ * NMI-safe cmpxchg implementation.
288+ */
289+ unsigned long gen_pool_alloc_algo (struct gen_pool * pool , size_t size ,
290+ genpool_algo_t algo , void * data )
272291{
273292 struct gen_pool_chunk * chunk ;
274293 unsigned long addr = 0 ;
@@ -290,8 +309,8 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
290309
291310 end_bit = chunk_size (chunk ) >> order ;
292311retry :
293- start_bit = pool -> algo (chunk -> bits , end_bit , start_bit , nbits ,
294- pool -> data );
312+ start_bit = algo (chunk -> bits , end_bit , start_bit ,
313+ nbits , data , pool );
295314 if (start_bit >= end_bit )
296315 continue ;
297316 remain = bitmap_set_ll (chunk -> bits , start_bit , nbits );
@@ -310,7 +329,7 @@ unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
310329 rcu_read_unlock ();
311330 return addr ;
312331}
313- EXPORT_SYMBOL (gen_pool_alloc );
332+ EXPORT_SYMBOL (gen_pool_alloc_algo );
314333
315334/**
316335 * gen_pool_dma_alloc - allocate special memory from the pool for DMA usage
@@ -501,14 +520,41 @@ EXPORT_SYMBOL(gen_pool_set_algo);
501520 * @start: The bitnumber to start searching at
502521 * @nr: The number of zeroed bits we're looking for
503522 * @data: additional data - unused
523+ * @pool: pool to find the fit region memory from
504524 */
505525unsigned long gen_pool_first_fit (unsigned long * map , unsigned long size ,
506- unsigned long start , unsigned int nr , void * data )
526+ unsigned long start , unsigned int nr , void * data ,
527+ struct gen_pool * pool )
507528{
508529 return bitmap_find_next_zero_area (map , size , start , nr , 0 );
509530}
510531EXPORT_SYMBOL (gen_pool_first_fit );
511532
533+ /**
534+ * gen_pool_first_fit_align - find the first available region
535+ * of memory matching the size requirement (alignment constraint)
536+ * @map: The address to base the search on
537+ * @size: The bitmap size in bits
538+ * @start: The bitnumber to start searching at
539+ * @nr: The number of zeroed bits we're looking for
540+ * @data: data for alignment
541+ * @pool: pool to get order from
542+ */
543+ unsigned long gen_pool_first_fit_align (unsigned long * map , unsigned long size ,
544+ unsigned long start , unsigned int nr , void * data ,
545+ struct gen_pool * pool )
546+ {
547+ struct genpool_data_align * alignment ;
548+ unsigned long align_mask ;
549+ int order ;
550+
551+ alignment = data ;
552+ order = pool -> min_alloc_order ;
553+ align_mask = ((alignment -> align + (1UL << order ) - 1 ) >> order ) - 1 ;
554+ return bitmap_find_next_zero_area (map , size , start , nr , align_mask );
555+ }
556+ EXPORT_SYMBOL (gen_pool_first_fit_align );
557+
512558/**
513559 * gen_pool_first_fit_order_align - find the first available region
514560 * of memory matching the size requirement. The region will be aligned
@@ -518,10 +564,11 @@ EXPORT_SYMBOL(gen_pool_first_fit);
518564 * @start: The bitnumber to start searching at
519565 * @nr: The number of zeroed bits we're looking for
520566 * @data: additional data - unused
567+ * @pool: pool to find the fit region memory from
521568 */
522569unsigned long gen_pool_first_fit_order_align (unsigned long * map ,
523570 unsigned long size , unsigned long start ,
524- unsigned int nr , void * data )
571+ unsigned int nr , void * data , struct gen_pool * pool )
525572{
526573 unsigned long align_mask = roundup_pow_of_two (nr ) - 1 ;
527574
@@ -537,12 +584,14 @@ EXPORT_SYMBOL(gen_pool_first_fit_order_align);
537584 * @start: The bitnumber to start searching at
538585 * @nr: The number of zeroed bits we're looking for
539586 * @data: additional data - unused
587+ * @pool: pool to find the fit region memory from
540588 *
541589 * Iterate over the bitmap to find the smallest free region
542590 * which we can allocate the memory.
543591 */
544592unsigned long gen_pool_best_fit (unsigned long * map , unsigned long size ,
545- unsigned long start , unsigned int nr , void * data )
593+ unsigned long start , unsigned int nr , void * data ,
594+ struct gen_pool * pool )
546595{
547596 unsigned long start_bit = size ;
548597 unsigned long len = size + 1 ;
0 commit comments