Lines Matching +full:max +full:- +full:functions

1 // SPDX-License-Identifier: GPL-2.0
21 * struct ioasid_allocator_data - Internal data structure to hold information
24 * - Default allocator always has its own XArray to track the IOASIDs allocated.
25 * - Custom allocators may share allocation helpers with different private data.
26 * Custom allocators that share the same helper functions also share the same
33 * 3. When all custom allocators sharing the same helper functions are
37 * functions, outstanding IOASIDs are preserved.
41 * @ops: allocator helper functions and its data
61 static ioasid_t default_alloc(ioasid_t min, ioasid_t max, void *opaque);
77 static ioasid_t default_alloc(ioasid_t min, ioasid_t max, void *opaque) in default_alloc() argument
81 if (xa_alloc(&default_allocator.xa, &id, opaque, XA_LIMIT(min, max), GFP_ATOMIC)) { in default_alloc()
82 pr_err("Failed to alloc ioasid from %d to %d\n", min, max); in default_alloc()
97 /* Allocate and initialize a new custom allocator with its helper functions */
106 xa_init_flags(&ia_data->xa, XA_FLAGS_ALLOC); in ioasid_alloc_allocator()
107 INIT_LIST_HEAD(&ia_data->slist); in ioasid_alloc_allocator()
108 ia_data->flags |= IOASID_ALLOCATOR_CUSTOM; in ioasid_alloc_allocator()
109 ia_data->ops = ops; in ioasid_alloc_allocator()
112 list_add_tail(&ops->list, &ia_data->slist); in ioasid_alloc_allocator()
119 return (a->free == b->free) && (a->alloc == b->alloc); in use_same_ops()
123 * ioasid_register_allocator - register a custom allocator
148 ret = -ENOMEM; in ioasid_register_allocator()
160 if (xa_empty(&active_allocator->xa)) { in ioasid_register_allocator()
162 list_add_tail(&ia_data->list, &allocators_list); in ioasid_register_allocator()
166 ret = -EAGAIN; in ioasid_register_allocator()
172 if (pallocator->ops == ops) { in ioasid_register_allocator()
174 ret = -EEXIST; in ioasid_register_allocator()
176 } else if (use_same_ops(pallocator->ops, ops)) { in ioasid_register_allocator()
182 list_add_tail(&ops->list, &pallocator->slist); in ioasid_register_allocator()
186 list_add_tail(&ia_data->list, &allocators_list); in ioasid_register_allocator()
199 * ioasid_unregister_allocator - Remove a custom IOASID allocator ops
218 if (!use_same_ops(pallocator->ops, ops)) in ioasid_unregister_allocator()
221 if (list_is_singular(&pallocator->slist)) { in ioasid_unregister_allocator()
222 /* No shared helper functions */ in ioasid_unregister_allocator()
223 list_del(&pallocator->list); in ioasid_unregister_allocator()
229 WARN_ON(!xa_empty(&pallocator->xa)); in ioasid_unregister_allocator()
246 list_for_each_entry(sops, &pallocator->slist, list) { in ioasid_unregister_allocator()
248 list_del(&ops->list); in ioasid_unregister_allocator()
261 * ioasid_set_data - Set private data for an allocated ioasid
274 ioasid_data = xa_load(&active_allocator->xa, ioasid); in ioasid_set_data()
276 rcu_assign_pointer(ioasid_data->private, data); in ioasid_set_data()
278 ret = -ENOENT; in ioasid_set_data()
293 * ioasid_alloc - Allocate an IOASID
296 * @max: the maximum ID (inclusive)
299 * Allocate an ID between @min and @max. The @private pointer is stored
304 ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min, ioasid_t max, in ioasid_alloc() argument
315 data->set = set; in ioasid_alloc()
316 data->private = private; in ioasid_alloc()
323 adata = active_allocator->flags & IOASID_ALLOCATOR_CUSTOM ? active_allocator->ops->pdata : data; in ioasid_alloc()
324 id = active_allocator->ops->alloc(min, max, adata); in ioasid_alloc()
326 pr_err("Failed ASID allocation %lu\n", active_allocator->flags); in ioasid_alloc()
330 if ((active_allocator->flags & IOASID_ALLOCATOR_CUSTOM) && in ioasid_alloc()
331 xa_alloc(&active_allocator->xa, &id, data, XA_LIMIT(id, id), GFP_ATOMIC)) { in ioasid_alloc()
334 active_allocator->ops->free(id, active_allocator->ops->pdata); in ioasid_alloc()
337 data->id = id; in ioasid_alloc()
349 * ioasid_free - Free an ioasid
357 ioasid_data = xa_load(&active_allocator->xa, ioasid); in ioasid_free()
363 active_allocator->ops->free(ioasid, active_allocator->ops->pdata); in ioasid_free()
365 if (active_allocator->flags & IOASID_ALLOCATOR_CUSTOM) { in ioasid_free()
366 ioasid_data = xa_erase(&active_allocator->xa, ioasid); in ioasid_free()
376 * ioasid_find - Find IOASID data
398 ioasid_data = xa_load(&idata->xa, ioasid); in ioasid_find()
400 priv = ERR_PTR(-ENOENT); in ioasid_find()
403 if (set && ioasid_data->set != set) { in ioasid_find()
405 priv = ERR_PTR(-EACCES); in ioasid_find()
409 priv = rcu_dereference(ioasid_data->private); in ioasid_find()
419 MODULE_AUTHOR("Jean-Philippe Brucker <jean-philippe.brucker@arm.com>");