Lines Matching refs:info
45 static int grow(rh_info_t * info, int max_blocks) in grow() argument
52 if (max_blocks <= info->max_blocks) in grow()
55 new_blocks = max_blocks - info->max_blocks; in grow()
61 if (info->max_blocks > 0) { in grow()
64 memcpy(block, info->block, in grow()
65 sizeof(rh_block_t) * info->max_blocks); in grow()
67 delta = (char *)block - (char *)info->block; in grow()
70 blks = (unsigned long)info->block; in grow()
71 blke = (unsigned long)(info->block + info->max_blocks); in grow()
73 for (i = 0, blk = block; i < info->max_blocks; i++, blk++) in grow()
76 fixup(blks, blke, delta, &info->empty_list); in grow()
77 fixup(blks, blke, delta, &info->free_list); in grow()
78 fixup(blks, blke, delta, &info->taken_list); in grow()
81 if ((info->flags & RHIF_STATIC_BLOCK) == 0) in grow()
82 kfree(info->block); in grow()
85 info->block = block; in grow()
86 info->empty_slots += new_blocks; in grow()
87 info->max_blocks = max_blocks; in grow()
88 info->flags &= ~RHIF_STATIC_BLOCK; in grow()
91 blk = block + info->max_blocks - new_blocks; in grow()
93 list_add(&blk->list, &info->empty_list); in grow()
103 static int assure_empty(rh_info_t * info, int slots) in assure_empty() argument
112 if (info->empty_slots >= slots) in assure_empty()
116 max_blocks = ((info->max_blocks + slots) + 15) & ~15; in assure_empty()
118 return grow(info, max_blocks); in assure_empty()
121 static rh_block_t *get_slot(rh_info_t * info) in get_slot() argument
127 if (info->empty_slots == 0) { in get_slot()
133 blk = list_entry(info->empty_list.next, rh_block_t, list); in get_slot()
135 info->empty_slots--; in get_slot()
145 static inline void release_slot(rh_info_t * info, rh_block_t * blk) in release_slot() argument
147 list_add(&blk->list, &info->empty_list); in release_slot()
148 info->empty_slots++; in release_slot()
151 static void attach_free_block(rh_info_t * info, rh_block_t * blkn) in attach_free_block() argument
172 list_for_each(l, &info->free_list) { in attach_free_block()
205 list_add(&blkn->list, &info->free_list); in attach_free_block()
211 release_slot(info, blkn); in attach_free_block()
229 release_slot(info, after); in attach_free_block()
232 static void attach_taken_block(rh_info_t * info, rh_block_t * blkn) in attach_taken_block() argument
238 list_for_each(l, &info->taken_list) { in attach_taken_block()
246 list_add_tail(&blkn->list, &info->taken_list); in attach_taken_block()
255 rh_info_t *info; in rh_create() local
261 info = kmalloc(sizeof(*info), GFP_ATOMIC); in rh_create()
262 if (info == NULL) in rh_create()
265 info->alignment = alignment; in rh_create()
268 info->block = NULL; in rh_create()
269 info->max_blocks = 0; in rh_create()
270 info->empty_slots = 0; in rh_create()
271 info->flags = 0; in rh_create()
273 INIT_LIST_HEAD(&info->empty_list); in rh_create()
274 INIT_LIST_HEAD(&info->free_list); in rh_create()
275 INIT_LIST_HEAD(&info->taken_list); in rh_create()
277 return info; in rh_create()
285 void rh_destroy(rh_info_t * info) in rh_destroy() argument
287 if ((info->flags & RHIF_STATIC_BLOCK) == 0) in rh_destroy()
288 kfree(info->block); in rh_destroy()
290 if ((info->flags & RHIF_STATIC_INFO) == 0) in rh_destroy()
291 kfree(info); in rh_destroy()
300 void rh_init(rh_info_t * info, unsigned int alignment, int max_blocks, in rh_init() argument
310 info->alignment = alignment; in rh_init()
313 info->block = block; in rh_init()
314 info->max_blocks = max_blocks; in rh_init()
315 info->empty_slots = max_blocks; in rh_init()
316 info->flags = RHIF_STATIC_INFO | RHIF_STATIC_BLOCK; in rh_init()
318 INIT_LIST_HEAD(&info->empty_list); in rh_init()
319 INIT_LIST_HEAD(&info->free_list); in rh_init()
320 INIT_LIST_HEAD(&info->taken_list); in rh_init()
324 list_add(&blk->list, &info->empty_list); in rh_init()
329 int rh_attach_region(rh_info_t * info, unsigned long start, int size) in rh_attach_region() argument
338 m = info->alignment - 1; in rh_attach_region()
354 r = assure_empty(info, 1); in rh_attach_region()
358 blk = get_slot(info); in rh_attach_region()
363 attach_free_block(info, blk); in rh_attach_region()
370 unsigned long rh_detach_region(rh_info_t * info, unsigned long start, int size) in rh_detach_region() argument
383 m = info->alignment - 1; in rh_detach_region()
391 if (assure_empty(info, 1) < 0) in rh_detach_region()
395 list_for_each(l, &info->free_list) { in rh_detach_region()
412 release_slot(info, blk); in rh_detach_region()
427 newblk = get_slot(info); in rh_detach_region()
442 unsigned long rh_alloc_align(rh_info_t * info, int size, int alignment, const char *owner) in rh_alloc_align() argument
454 size = (size + (info->alignment - 1)) & ~(info->alignment - 1); in rh_alloc_align()
456 if (assure_empty(info, 2) < 0) in rh_alloc_align()
460 list_for_each(l, &info->free_list) { in rh_alloc_align()
485 spblk = get_slot(info); in rh_alloc_align()
491 newblk = get_slot(info); in rh_alloc_align()
502 release_slot(info, blk); in rh_alloc_align()
507 attach_taken_block(info, newblk); in rh_alloc_align()
517 unsigned long rh_alloc(rh_info_t * info, int size, const char *owner) in rh_alloc() argument
519 return rh_alloc_align(info, size, info->alignment, owner); in rh_alloc()
527 unsigned long rh_alloc_fixed(rh_info_t * info, unsigned long start, int size, const char *owner) in rh_alloc_fixed() argument
540 m = info->alignment - 1; in rh_alloc_fixed()
548 if (assure_empty(info, 2) < 0) in rh_alloc_fixed()
552 list_for_each(l, &info->free_list) { in rh_alloc_fixed()
572 attach_taken_block(info, blk); in rh_alloc_fixed()
589 newblk2 = get_slot(info); in rh_alloc_fixed()
596 newblk1 = get_slot(info); in rh_alloc_fixed()
602 attach_taken_block(info, newblk1); in rh_alloc_fixed()
612 int rh_free(rh_info_t * info, unsigned long start) in rh_free() argument
620 list_for_each(l, &info->taken_list) { in rh_free()
635 attach_free_block(info, blk); in rh_free()
641 int rh_get_stats(rh_info_t * info, int what, int max_stats, rh_stats_t * stats) in rh_get_stats() argument
651 h = &info->free_list; in rh_get_stats()
655 h = &info->taken_list; in rh_get_stats()
679 int rh_set_owner(rh_info_t * info, unsigned long start, const char *owner) in rh_set_owner() argument
687 list_for_each(l, &info->taken_list) { in rh_set_owner()
704 void rh_dump(rh_info_t * info) in rh_dump() argument
714 info, info->empty_slots, info->max_blocks); in rh_dump()
717 nr = rh_get_stats(info, RHGS_FREE, maxnr, st); in rh_dump()
728 nr = rh_get_stats(info, RHGS_TAKEN, maxnr, st); in rh_dump()
740 void rh_dump_blk(rh_info_t * info, rh_block_t * blk) in rh_dump_blk() argument