Skip to content

Commit b26981c

Browse files
Zhao QiangScott Wood
authored andcommitted
genalloc:support allocating specific region
Add new algo for genalloc, it reserve a specific region of memory Signed-off-by: Zhao Qiang <[email protected]> Signed-off-by: Scott Wood <[email protected]>
1 parent de2dd0e commit b26981c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

include/linux/genalloc.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ struct genpool_data_align {
8484
int align; /* alignment by bytes for starting address */
8585
};
8686

87+
/*
88+
* gen_pool data descriptor for gen_pool_fixed_alloc.
89+
*/
90+
struct genpool_data_fixed {
91+
unsigned long offset; /* The offset of the specific region */
92+
};
93+
8794
extern struct gen_pool *gen_pool_create(int, int);
8895
extern phys_addr_t gen_pool_virt_to_phys(struct gen_pool *pool, unsigned long);
8996
extern int gen_pool_add_virt(struct gen_pool *, unsigned long, phys_addr_t,
@@ -124,6 +131,10 @@ extern unsigned long gen_pool_first_fit(unsigned long *map, unsigned long size,
124131
unsigned long start, unsigned int nr, void *data,
125132
struct gen_pool *pool);
126133

134+
extern unsigned long gen_pool_fixed_alloc(unsigned long *map,
135+
unsigned long size, unsigned long start, unsigned int nr,
136+
void *data, struct gen_pool *pool);
137+
127138
extern unsigned long gen_pool_first_fit_align(unsigned long *map,
128139
unsigned long size, unsigned long start, unsigned int nr,
129140
void *data, struct gen_pool *pool);

lib/genalloc.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,38 @@ unsigned long gen_pool_first_fit_align(unsigned long *map, unsigned long size,
555555
}
556556
EXPORT_SYMBOL(gen_pool_first_fit_align);
557557

558+
/**
559+
* gen_pool_fixed_alloc - reserve a specific region
560+
* @map: The address to base the search on
561+
* @size: The bitmap size in bits
562+
* @start: The bitnumber to start searching at
563+
* @nr: The number of zeroed bits we're looking for
564+
* @data: data for alignment
565+
* @pool: pool to get order from
566+
*/
567+
unsigned long gen_pool_fixed_alloc(unsigned long *map, unsigned long size,
568+
unsigned long start, unsigned int nr, void *data,
569+
struct gen_pool *pool)
570+
{
571+
struct genpool_data_fixed *fixed_data;
572+
int order;
573+
unsigned long offset_bit;
574+
unsigned long start_bit;
575+
576+
fixed_data = data;
577+
order = pool->min_alloc_order;
578+
offset_bit = fixed_data->offset >> order;
579+
if (WARN_ON(fixed_data->offset & (1UL << order - 1)))
580+
return size;
581+
582+
start_bit = bitmap_find_next_zero_area(map, size,
583+
start + offset_bit, nr, 0);
584+
if (start_bit != offset_bit)
585+
start_bit = size;
586+
return start_bit;
587+
}
588+
EXPORT_SYMBOL(gen_pool_fixed_alloc);
589+
558590
/**
559591
* gen_pool_first_fit_order_align - find the first available region
560592
* of memory matching the size requirement. The region will be aligned

0 commit comments

Comments
 (0)