Lines Matching refs:axmap
46 struct axmap { struct
61 void axmap_reset(struct axmap *axmap) in axmap_reset() argument
65 for (i = 0; i < axmap->nr_levels; i++) { in axmap_reset()
66 struct axmap_level *al = &axmap->levels[i]; in axmap_reset()
71 axmap->first_free = 0; in axmap_reset()
74 void axmap_free(struct axmap *axmap) in axmap_free() argument
78 if (!axmap) in axmap_free()
81 for (i = 0; i < axmap->nr_levels; i++) in axmap_free()
82 free(axmap->levels[i].map); in axmap_free()
84 free(axmap->levels); in axmap_free()
85 free(axmap); in axmap_free()
88 struct axmap *axmap_new(unsigned long nr_bits) in axmap_new()
90 struct axmap *axmap; in axmap_new() local
93 axmap = malloc(sizeof(*axmap)); in axmap_new()
94 if (!axmap) in axmap_new()
104 axmap->nr_levels = levels; in axmap_new()
105 axmap->levels = malloc(axmap->nr_levels * sizeof(struct axmap_level)); in axmap_new()
106 axmap->nr_bits = nr_bits; in axmap_new()
108 for (i = 0; i < axmap->nr_levels; i++) { in axmap_new()
109 struct axmap_level *al = &axmap->levels[i]; in axmap_new()
120 axmap_reset(axmap); in axmap_new()
121 return axmap; in axmap_new()
123 for (i = 0; i < axmap->nr_levels; i++) in axmap_new()
124 if (axmap->levels[i].map) in axmap_new()
125 free(axmap->levels[i].map); in axmap_new()
127 free(axmap->levels); in axmap_new()
128 free(axmap); in axmap_new()
132 static int axmap_handler(struct axmap *axmap, uint64_t bit_nr, in axmap_handler() argument
139 for (i = 0; i < axmap->nr_levels; i++) { in axmap_handler()
144 al = &axmap->levels[i]; in axmap_handler()
153 static int axmap_handler_topdown(struct axmap *axmap, uint64_t bit_nr, in axmap_handler_topdown() argument
158 int i, level = axmap->nr_levels; in axmap_handler_topdown()
160 for (i = axmap->nr_levels - 1; i >= 0; i--) { in axmap_handler_topdown()
165 al = &axmap->levels[i]; in axmap_handler_topdown()
184 void axmap_clear(struct axmap *axmap, uint64_t bit_nr) in axmap_clear() argument
186 axmap_handler(axmap, bit_nr, axmap_clear_fn, NULL); in axmap_clear()
254 static void __axmap_set(struct axmap *axmap, uint64_t bit_nr, in __axmap_set() argument
259 if (axmap->first_free >= bit_nr && in __axmap_set()
260 axmap->first_free < bit_nr + data->nr_bits) in __axmap_set()
261 axmap->first_free = -1ULL; in __axmap_set()
263 if (bit_nr > axmap->nr_bits) in __axmap_set()
265 else if (bit_nr + nr_bits > axmap->nr_bits) in __axmap_set()
266 nr_bits = axmap->nr_bits - bit_nr; in __axmap_set()
270 axmap_handler(axmap, bit_nr, axmap_set_fn, data); in __axmap_set()
286 void axmap_set(struct axmap *axmap, uint64_t bit_nr) in axmap_set() argument
290 __axmap_set(axmap, bit_nr, &data); in axmap_set()
293 unsigned int axmap_set_nr(struct axmap *axmap, uint64_t bit_nr, unsigned int nr_bits) in axmap_set_nr() argument
306 __axmap_set(axmap, bit_nr, &data); in axmap_set_nr()
324 int axmap_isset(struct axmap *axmap, uint64_t bit_nr) in axmap_isset() argument
326 if (bit_nr <= axmap->nr_bits) in axmap_isset()
327 return axmap_handler_topdown(axmap, bit_nr, axmap_isset_fn, NULL); in axmap_isset()
332 static uint64_t axmap_find_first_free(struct axmap *axmap, unsigned int level, in axmap_find_first_free() argument
343 struct axmap_level *al = &axmap->levels[i]; in axmap_find_first_free()
366 if (ret < axmap->nr_bits) in axmap_find_first_free()
372 static uint64_t axmap_first_free(struct axmap *axmap) in axmap_first_free() argument
374 if (firstfree_valid(axmap)) in axmap_first_free()
375 return axmap->first_free; in axmap_first_free()
377 axmap->first_free = axmap_find_first_free(axmap, axmap->nr_levels - 1, 0); in axmap_first_free()
378 return axmap->first_free; in axmap_first_free()
409 uint64_t axmap_next_free(struct axmap *axmap, uint64_t bit_nr) in axmap_next_free() argument
414 if (firstfree_valid(axmap) && bit_nr < axmap->first_free) in axmap_next_free()
415 return axmap->first_free; in axmap_next_free()
417 if (!axmap_handler(axmap, bit_nr, axmap_next_free_fn, &data)) in axmap_next_free()
418 return axmap_first_free(axmap); in axmap_next_free()
427 ret = axmap_find_first_free(axmap, data.level, data.offset); in axmap_next_free()
431 return axmap_first_free(axmap); in axmap_next_free()