Lines Matching full:resource
3 * linux/kernel/resource.c
8 * Arbitrary resource management.
35 struct resource ioport_resource = {
43 struct resource iomem_resource = {
59 static struct resource *next_resource(struct resource *p, bool skip_children, in next_resource()
60 struct resource *subtree_root) in next_resource()
73 * Traverse the resource subtree under @_root in pre-order, excluding
90 struct resource *root = pde_data(file_inode(m->file)); in r_start()
91 struct resource *p; in r_start()
105 struct resource *p = v; in r_next()
120 struct resource *root = pde_data(file_inode(m->file)); in r_show()
121 struct resource *r = v, *p; in r_show()
163 static void free_resource(struct resource *res) in free_resource()
166 * If the resource was allocated using memblock early during boot in free_resource()
169 * alloc_resource() overcomplicates resource handling. in free_resource()
175 static struct resource *alloc_resource(gfp_t flags) in alloc_resource()
177 return kzalloc(sizeof(struct resource), flags); in alloc_resource()
181 static struct resource * __request_resource(struct resource *root, struct resource *new) in __request_resource()
185 struct resource *tmp, **p; in __request_resource()
209 static int __release_resource(struct resource *old, bool release_child) in __release_resource()
211 struct resource *tmp, **p, *chd; in __release_resource()
238 static void __release_child_resources(struct resource *r) in __release_child_resources()
240 struct resource *tmp, *p; in __release_child_resources()
253 printk(KERN_DEBUG "release child resource %pR\n", tmp); in __release_child_resources()
261 void release_child_resources(struct resource *r) in release_child_resources()
269 * request_resource_conflict - request and reserve an I/O or memory resource
270 * @root: root resource descriptor
271 * @new: resource descriptor desired by caller
273 * Returns 0 for success, conflict resource on error.
275 struct resource *request_resource_conflict(struct resource *root, struct resource *new) in request_resource_conflict()
277 struct resource *conflict; in request_resource_conflict()
286 * request_resource - request and reserve an I/O or memory resource
287 * @root: root resource descriptor
288 * @new: resource descriptor desired by caller
292 int request_resource(struct resource *root, struct resource *new) in request_resource()
294 struct resource *conflict; in request_resource()
303 * release_resource - release a previously reserved resource
304 * @old: resource pointer
306 int release_resource(struct resource *old) in release_resource()
318 static bool is_type_match(struct resource *p, unsigned long flags, unsigned long desc) in is_type_match()
324 * find_next_iomem_res - Finds the lowest iomem resource that covers part of
327 * If a resource is found, returns 0 and @*res is overwritten with the part
328 * of the resource that's within [@start..@end]; if none is found, returns
331 * @start: start address of the resource searched for
332 * @end: end address of same resource
333 * @flags: flags which the resource must have
334 * @desc: descriptor the resource must have
335 * @res: return ptr, if resource found
342 struct resource *res) in find_next_iomem_res()
344 struct resource *p; in find_next_iomem_res()
355 /* If we passed the resource we are looking for, stop */ in find_next_iomem_res()
372 *res = (struct resource) { in find_next_iomem_res()
388 int (*func)(struct resource *, void *)) in __walk_iomem_res_desc() argument
390 struct resource res; in __walk_iomem_res_desc()
407 * with matching resource ranges.
409 * @desc: I/O resource descriptor. Use IORES_DESC_NONE to skip @desc check.
410 * @flags: I/O resource flags
414 * @func: callback function that is called for each qualifying resource area
420 * <linux/ioport.h> and set it in 'desc' of a target resource entry.
423 u64 end, void *arg, int (*func)(struct resource *, void *)) in walk_iomem_res_desc() argument
437 int (*func)(struct resource *, void *)) in walk_system_ram_res() argument
452 int (*func)(struct resource *, void *)) in walk_system_ram_res_rev() argument
454 struct resource res, *rams; in walk_system_ram_res_rev()
460 rams = kvcalloc(rams_size, sizeof(struct resource), GFP_KERNEL); in walk_system_ram_res_rev()
470 struct resource *rams_new; in walk_system_ram_res_rev()
472 rams_new = kvrealloc(rams, (rams_size + 16) * sizeof(struct resource), in walk_system_ram_res_rev()
502 int (*func)(struct resource *, void *)) in walk_mem_res() argument
520 struct resource res; in walk_system_ram_range()
555 static int __region_intersects(struct resource *parent, resource_size_t start, in __region_intersects()
560 struct resource *p, *dp; in __region_intersects()
561 struct resource res, o; in __region_intersects()
580 * will behave similar as the following fake resource in __region_intersects()
593 * isn't covered by matched resource. in __region_intersects()
622 * @flags: flags of resource (in iomem_resource)
623 * @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
626 * resource identified by @flags and @desc (optional with IORES_DESC_NONE).
629 * resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
630 * and no other defined resource. Note that REGION_INTERSECTS is also
636 * through the resource table page by page.
651 void __weak arch_remove_reservations(struct resource *avail) in arch_remove_reservations()
655 static void resource_clip(struct resource *res, resource_size_t min, in resource_clip()
665 * Find empty space in the resource tree with the given range and
668 static int __find_resource_space(struct resource *root, struct resource *old, in __find_resource_space()
669 struct resource *new, resource_size_t size, in __find_resource_space()
672 struct resource *this = root->child; in __find_resource_space()
673 struct resource tmp = *new, avail, alloc; in __find_resource_space()
678 * Skip past an allocated resource that starts at 0, since the assignment in __find_resource_space()
729 * find_resource_space - Find empty space in the resource tree
730 * @root: Root resource descriptor
731 * @new: Resource descriptor awaiting an empty resource space
735 * Finds an empty space under @root in the resource tree satisfying range and
742 int find_resource_space(struct resource *root, struct resource *new, in find_resource_space()
751 * reallocate_resource - allocate a slot in the resource tree given range & alignment.
752 * The resource will be relocated if the new size cannot be reallocated in the
755 * @root: root resource descriptor
756 * @old: resource descriptor desired by caller
757 * @newsize: new size of the resource descriptor
760 static int reallocate_resource(struct resource *root, struct resource *old, in reallocate_resource()
765 struct resource new = *old; in reallocate_resource()
766 struct resource *conflict; in reallocate_resource()
800 * allocate_resource - allocate empty slot in the resource tree given range & alignment.
801 * The resource will be reallocated with a new size if it was already allocated
802 * @root: root resource descriptor
803 * @new: resource descriptor desired by caller
804 * @size: requested resource region size
811 int allocate_resource(struct resource *root, struct resource *new, in allocate_resource()
827 /* resource is already allocated, try reallocating with in allocate_resource()
843 * lookup_resource - find an existing resource by a resource start address
844 * @root: root resource descriptor
845 * @start: resource start address
847 * Returns a pointer to the resource if found, NULL otherwise
849 struct resource *lookup_resource(struct resource *root, resource_size_t start) in lookup_resource()
851 struct resource *res; in lookup_resource()
864 * Insert a resource into the resource tree. If successful, return NULL,
865 * otherwise return the conflicting resource (compare to __request_resource())
867 static struct resource * __insert_resource(struct resource *parent, struct resource *new) in __insert_resource()
869 struct resource *first, *next; in __insert_resource()
917 * insert_resource_conflict - Inserts resource in the resource tree
918 * @parent: parent of the new resource
919 * @new: new resource to insert
921 * Returns 0 on success, conflict resource if the resource can't be inserted.
925 * entirely fit within the range of the new resource, then the new
926 * resource is inserted and the conflicting resources become children of
927 * the new resource.
932 struct resource *insert_resource_conflict(struct resource *parent, struct resource *new) in insert_resource_conflict()
934 struct resource *conflict; in insert_resource_conflict()
943 * insert_resource - Inserts a resource in the resource tree
944 * @parent: parent of the new resource
945 * @new: new resource to insert
947 * Returns 0 on success, -EBUSY if the resource can't be inserted.
952 int insert_resource(struct resource *parent, struct resource *new) in insert_resource()
954 struct resource *conflict; in insert_resource()
962 * insert_resource_expand_to_fit - Insert a resource into the resource tree
963 * @root: root resource descriptor
964 * @new: new resource to insert
966 * Insert a resource into the resource tree, possibly expanding it in order
969 void insert_resource_expand_to_fit(struct resource *root, struct resource *new) in insert_resource_expand_to_fit()
976 struct resource *conflict; in insert_resource_expand_to_fit()
984 /* Ok, expand resource to cover the conflict, then try again .. */ in insert_resource_expand_to_fit()
990 pr_info("Expanded resource %s due to conflict with %s\n", new->name, conflict->name); in insert_resource_expand_to_fit()
996 * resource discovery, and late discovery of CXL resources are expected
1003 * remove_resource - Remove a resource in the resource tree
1004 * @old: resource to remove
1006 * Returns 0 on success, -EINVAL if the resource is not valid.
1008 * This function removes a resource previously inserted by insert_resource()
1011 * insert a new resource, and move any conflicting resources down to the
1012 * children of the new resource.
1017 int remove_resource(struct resource *old) in remove_resource()
1028 static int __adjust_resource(struct resource *res, resource_size_t start, in __adjust_resource()
1031 struct resource *tmp, *parent = res->parent; in __adjust_resource()
1066 * adjust_resource - modify a resource's start and size
1067 * @res: resource to modify
1071 * Given an existing resource, change its start and size to match the
1073 * Existing children of the resource are assumed to be immutable.
1075 int adjust_resource(struct resource *res, resource_size_t start, in adjust_resource()
1088 __reserve_region_with_split(struct resource *root, resource_size_t start, in __reserve_region_with_split()
1091 struct resource *parent = root; in __reserve_region_with_split()
1092 struct resource *conflict; in __reserve_region_with_split()
1093 struct resource *res = alloc_resource(GFP_ATOMIC); in __reserve_region_with_split()
1094 struct resource *next_res = NULL; in __reserve_region_with_split()
1149 reserve_region_with_split(struct resource *root, resource_size_t start, in reserve_region_with_split()
1178 * resource_alignment - calculate resource's alignment
1179 * @res: resource pointer
1183 resource_size_t resource_alignment(struct resource *res) in resource_alignment()
1211 static void revoke_iomem(struct resource *res) in revoke_iomem()
1227 * the resource busy by this point, so devmem_is_allowed() in revoke_iomem()
1229 * does not iterate the entire resource range. in revoke_iomem()
1243 static void revoke_iomem(struct resource *res) {} in revoke_iomem()
1257 static int __request_region_locked(struct resource *res, struct resource *parent, in __request_region_locked()
1268 struct resource *conflict; in __request_region_locked()
1309 * __request_region - create a new busy resource region
1310 * @parent: parent resource descriptor
1311 * @start: resource start address
1312 * @n: resource region size
1314 * @flags: IO resource flags
1316 struct resource *__request_region(struct resource *parent, in __request_region()
1320 struct resource *res = alloc_resource(GFP_KERNEL); in __request_region()
1343 * __release_region - release a previously reserved resource region
1344 * @parent: parent resource descriptor
1345 * @start: resource start address
1346 * @n: resource region size
1348 * The described resource region must match a currently busy region.
1350 void __release_region(struct resource *parent, resource_size_t start, in __release_region()
1353 struct resource **p; in __release_region()
1362 struct resource *res = *p; in __release_region()
1385 pr_warn("Trying to free nonexistent resource <%pa-%pa>\n", &start, &end); in __release_region()
1392 * @start: resource start address
1393 * @size: resource region size
1396 * is released from a currently busy memory resource. The requested region
1397 * must either match exactly or fit into a single busy resource entry. In
1398 * the latter case, the remaining resource is adjusted accordingly.
1399 * Existing children of the busy memory resource must be immutable in the
1405 * - When a busy memory resource gets split into two entries, the code
1411 struct resource *parent = &iomem_resource; in release_mem_region_adjustable()
1412 struct resource *new_res = NULL; in release_mem_region_adjustable()
1414 struct resource **p; in release_mem_region_adjustable()
1415 struct resource *res; in release_mem_region_adjustable()
1439 /* look for the next resource if it does not fit into */ in release_mem_region_adjustable()
1453 /* found the target resource; let's adjust accordingly */ in release_mem_region_adjustable()
1467 /* split into two entries - we need a new resource */ in release_mem_region_adjustable()
1501 static bool system_ram_resources_mergeable(struct resource *r1, in system_ram_resources_mergeable()
1502 struct resource *r2) in system_ram_resources_mergeable()
1511 * merge_system_ram_resource - mark the System RAM resource mergeable and try to
1513 * @res: resource descriptor
1517 * the actual resource boundaries are not of interest (e.g., it might be
1524 * marked mergeable are used anymore after this call - the resource might
1528 void merge_system_ram_resource(struct resource *res) in merge_system_ram_resource()
1531 struct resource *cur; in merge_system_ram_resource()
1561 * Managed region resource
1565 struct resource **r = ptr; in devm_resource_release()
1571 * devm_request_resource() - request and reserve an I/O or memory resource
1572 * @dev: device for which to request the resource
1573 * @root: root of the resource tree from which to request the resource
1574 * @new: descriptor of the resource to request
1579 * If for some reason the resource needs to be released explicitly, because
1584 * requested resource, an error message will be printed.
1588 int devm_request_resource(struct device *dev, struct resource *root, in devm_request_resource()
1589 struct resource *new) in devm_request_resource()
1591 struct resource *conflict, **ptr; in devm_request_resource()
1601 dev_err(dev, "resource collision: %pR conflicts with %s %pR\n", in devm_request_resource()
1614 struct resource **ptr = res; in devm_resource_match()
1620 * devm_release_resource() - release a previously requested resource
1621 * @dev: device for which to release the resource
1622 * @new: descriptor of the resource to release
1624 * Releases a resource previously requested using devm_request_resource().
1626 void devm_release_resource(struct device *dev, struct resource *new) in devm_release_resource()
1634 struct resource *parent;
1654 struct resource *
1655 __devm_request_region(struct device *dev, struct resource *parent, in __devm_request_region()
1659 struct resource *res; in __devm_request_region()
1680 void __devm_release_region(struct device *dev, struct resource *parent, in __devm_release_region()
1697 static struct resource reserve[MAXRESERVE]; in reserve_setup()
1702 struct resource *parent; in reserve_setup()
1709 struct resource *res = reserve + x; in reserve_setup()
1733 * iomem resource tree.
1738 struct resource *p; in iomem_map_sanity_check()
1755 * if a resource is "BUSY", it's not a hardware resource in iomem_map_sanity_check()
1756 * but a driver mapping of such a resource; we don't want in iomem_map_sanity_check()
1763 pr_warn("resource sanity check: requesting [mem %pa-%pa], which spans more than %s %pR\n", in iomem_map_sanity_check()
1785 bool resource_is_exclusive(struct resource *root, u64 addr, resource_size_t size) in resource_is_exclusive()
1790 struct resource *p; in resource_is_exclusive()
1815 * A resource is exclusive if IORESOURCE_EXCLUSIVE is set in resource_is_exclusive()
1817 * resource is busy. in resource_is_exclusive()
1838 struct resource_entry *resource_list_create_entry(struct resource *res, in resource_list_create_entry()
1871 static resource_size_t gfr_start(struct resource *base, resource_size_t size, in gfr_start()
1884 static bool gfr_continue(struct resource *base, resource_size_t addr, in gfr_continue()
1907 struct resource *res = _res; in remove_free_mem_region()
1914 static struct resource *
1915 get_free_mem_region(struct device *dev, struct resource *base, in get_free_mem_region()
1921 struct resource *res; in get_free_mem_region()
1975 * Only succeed if the resource hosts an exclusive in get_free_mem_region()
2000 * @dev: device struct to bind the resource to
2002 * @base: resource tree to look in
2005 * contain the new resource, so that it can later be hotplugged as ZONE_DEVICE
2008 struct resource *devm_request_free_mem_region(struct device *dev, in devm_request_free_mem_region()
2009 struct resource *base, unsigned long size) in devm_request_free_mem_region()
2019 struct resource *request_free_mem_region(struct resource *base, in request_free_mem_region()
2031 * @base: resource that will parent the new resource
2034 * @name: resource name
2038 * Allocate and insert a new resource to cover a free, unclaimed by a
2041 struct resource *alloc_free_mem_region(struct resource *base, in alloc_free_mem_region()
2045 /* Default of ascending direction and insert resource */ in alloc_free_mem_region()