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()
581 * will behave similar as the following fake resource in __region_intersects()
594 * isn't covered by matched resource. in __region_intersects()
623 * @flags: flags of resource (in iomem_resource)
624 * @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
627 * resource identified by @flags and @desc (optional with IORES_DESC_NONE).
630 * resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
631 * and no other defined resource. Note that REGION_INTERSECTS is also
637 * through the resource table page by page.
652 void __weak arch_remove_reservations(struct resource *avail) in arch_remove_reservations()
656 static void resource_clip(struct resource *res, resource_size_t min, in resource_clip()
666 * Find empty space in the resource tree with the given range and
669 static int __find_resource_space(struct resource *root, struct resource *old, in __find_resource_space()
670 struct resource *new, resource_size_t size, in __find_resource_space()
673 struct resource *this = root->child; in __find_resource_space()
674 struct resource tmp = *new, avail, alloc; in __find_resource_space()
679 * Skip past an allocated resource that starts at 0, since the assignment in __find_resource_space()
730 * find_resource_space - Find empty space in the resource tree
731 * @root: Root resource descriptor
732 * @new: Resource descriptor awaiting an empty resource space
736 * Finds an empty space under @root in the resource tree satisfying range and
743 int find_resource_space(struct resource *root, struct resource *new, in find_resource_space()
752 * reallocate_resource - allocate a slot in the resource tree given range & alignment.
753 * The resource will be relocated if the new size cannot be reallocated in the
756 * @root: root resource descriptor
757 * @old: resource descriptor desired by caller
758 * @newsize: new size of the resource descriptor
761 static int reallocate_resource(struct resource *root, struct resource *old, in reallocate_resource()
766 struct resource new = *old; in reallocate_resource()
767 struct resource *conflict; in reallocate_resource()
801 * allocate_resource - allocate empty slot in the resource tree given range & alignment.
802 * The resource will be reallocated with a new size if it was already allocated
803 * @root: root resource descriptor
804 * @new: resource descriptor desired by caller
805 * @size: requested resource region size
812 int allocate_resource(struct resource *root, struct resource *new, in allocate_resource()
828 /* resource is already allocated, try reallocating with in allocate_resource()
844 * lookup_resource - find an existing resource by a resource start address
845 * @root: root resource descriptor
846 * @start: resource start address
848 * Returns a pointer to the resource if found, NULL otherwise
850 struct resource *lookup_resource(struct resource *root, resource_size_t start) in lookup_resource()
852 struct resource *res; in lookup_resource()
865 * Insert a resource into the resource tree. If successful, return NULL,
866 * otherwise return the conflicting resource (compare to __request_resource())
868 static struct resource * __insert_resource(struct resource *parent, struct resource *new) in __insert_resource()
870 struct resource *first, *next; in __insert_resource()
918 * insert_resource_conflict - Inserts resource in the resource tree
919 * @parent: parent of the new resource
920 * @new: new resource to insert
922 * Returns 0 on success, conflict resource if the resource can't be inserted.
926 * entirely fit within the range of the new resource, then the new
927 * resource is inserted and the conflicting resources become children of
928 * the new resource.
933 struct resource *insert_resource_conflict(struct resource *parent, struct resource *new) in insert_resource_conflict()
935 struct resource *conflict; in insert_resource_conflict()
944 * insert_resource - Inserts a resource in the resource tree
945 * @parent: parent of the new resource
946 * @new: new resource to insert
948 * Returns 0 on success, -EBUSY if the resource can't be inserted.
953 int insert_resource(struct resource *parent, struct resource *new) in insert_resource()
955 struct resource *conflict; in insert_resource()
963 * insert_resource_expand_to_fit - Insert a resource into the resource tree
964 * @root: root resource descriptor
965 * @new: new resource to insert
967 * Insert a resource into the resource tree, possibly expanding it in order
970 void insert_resource_expand_to_fit(struct resource *root, struct resource *new) in insert_resource_expand_to_fit()
977 struct resource *conflict; in insert_resource_expand_to_fit()
985 /* Ok, expand resource to cover the conflict, then try again .. */ in insert_resource_expand_to_fit()
991 pr_info("Expanded resource %s due to conflict with %s\n", new->name, conflict->name); in insert_resource_expand_to_fit()
997 * resource discovery, and late discovery of CXL resources are expected
1004 * remove_resource - Remove a resource in the resource tree
1005 * @old: resource to remove
1007 * Returns 0 on success, -EINVAL if the resource is not valid.
1009 * This function removes a resource previously inserted by insert_resource()
1012 * insert a new resource, and move any conflicting resources down to the
1013 * children of the new resource.
1018 int remove_resource(struct resource *old) in remove_resource()
1029 static int __adjust_resource(struct resource *res, resource_size_t start, in __adjust_resource()
1032 struct resource *tmp, *parent = res->parent; in __adjust_resource()
1067 * adjust_resource - modify a resource's start and size
1068 * @res: resource to modify
1072 * Given an existing resource, change its start and size to match the
1074 * Existing children of the resource are assumed to be immutable.
1076 int adjust_resource(struct resource *res, resource_size_t start, in adjust_resource()
1089 __reserve_region_with_split(struct resource *root, resource_size_t start, in __reserve_region_with_split()
1092 struct resource *parent = root; in __reserve_region_with_split()
1093 struct resource *conflict; in __reserve_region_with_split()
1094 struct resource *res = alloc_resource(GFP_ATOMIC); in __reserve_region_with_split()
1095 struct resource *next_res = NULL; in __reserve_region_with_split()
1150 reserve_region_with_split(struct resource *root, resource_size_t start, in reserve_region_with_split()
1179 * resource_alignment - calculate resource's alignment
1180 * @res: resource pointer
1184 resource_size_t resource_alignment(struct resource *res) in resource_alignment()
1212 static void revoke_iomem(struct resource *res) in revoke_iomem()
1228 * the resource busy by this point, so devmem_is_allowed() in revoke_iomem()
1230 * does not iterate the entire resource range. in revoke_iomem()
1244 static void revoke_iomem(struct resource *res) {} in revoke_iomem()
1258 static int __request_region_locked(struct resource *res, struct resource *parent, in __request_region_locked()
1269 struct resource *conflict; in __request_region_locked()
1310 * __request_region - create a new busy resource region
1311 * @parent: parent resource descriptor
1312 * @start: resource start address
1313 * @n: resource region size
1315 * @flags: IO resource flags
1317 struct resource *__request_region(struct resource *parent, in __request_region()
1321 struct resource *res = alloc_resource(GFP_KERNEL); in __request_region()
1344 * __release_region - release a previously reserved resource region
1345 * @parent: parent resource descriptor
1346 * @start: resource start address
1347 * @n: resource region size
1349 * The described resource region must match a currently busy region.
1351 void __release_region(struct resource *parent, resource_size_t start, in __release_region()
1354 struct resource **p; in __release_region()
1363 struct resource *res = *p; in __release_region()
1386 pr_warn("Trying to free nonexistent resource <%pa-%pa>\n", &start, &end); in __release_region()
1393 * @start: resource start address
1394 * @size: resource region size
1397 * is released from a currently busy memory resource. The requested region
1398 * must either match exactly or fit into a single busy resource entry. In
1399 * the latter case, the remaining resource is adjusted accordingly.
1400 * Existing children of the busy memory resource must be immutable in the
1406 * - When a busy memory resource gets split into two entries, the code
1412 struct resource *parent = &iomem_resource; in release_mem_region_adjustable()
1413 struct resource *new_res = NULL; in release_mem_region_adjustable()
1415 struct resource **p; in release_mem_region_adjustable()
1416 struct resource *res; in release_mem_region_adjustable()
1440 /* look for the next resource if it does not fit into */ in release_mem_region_adjustable()
1454 /* found the target resource; let's adjust accordingly */ in release_mem_region_adjustable()
1468 /* split into two entries - we need a new resource */ in release_mem_region_adjustable()
1502 static bool system_ram_resources_mergeable(struct resource *r1, in system_ram_resources_mergeable()
1503 struct resource *r2) in system_ram_resources_mergeable()
1512 * merge_system_ram_resource - mark the System RAM resource mergeable and try to
1514 * @res: resource descriptor
1518 * the actual resource boundaries are not of interest (e.g., it might be
1525 * marked mergeable are used anymore after this call - the resource might
1529 void merge_system_ram_resource(struct resource *res) in merge_system_ram_resource()
1532 struct resource *cur; in merge_system_ram_resource()
1562 * Managed region resource
1566 struct resource **r = ptr; in devm_resource_release()
1572 * devm_request_resource() - request and reserve an I/O or memory resource
1573 * @dev: device for which to request the resource
1574 * @root: root of the resource tree from which to request the resource
1575 * @new: descriptor of the resource to request
1580 * If for some reason the resource needs to be released explicitly, because
1585 * requested resource, an error message will be printed.
1589 int devm_request_resource(struct device *dev, struct resource *root, in devm_request_resource()
1590 struct resource *new) in devm_request_resource()
1592 struct resource *conflict, **ptr; in devm_request_resource()
1602 dev_err(dev, "resource collision: %pR conflicts with %s %pR\n", in devm_request_resource()
1615 struct resource **ptr = res; in devm_resource_match()
1621 * devm_release_resource() - release a previously requested resource
1622 * @dev: device for which to release the resource
1623 * @new: descriptor of the resource to release
1625 * Releases a resource previously requested using devm_request_resource().
1627 void devm_release_resource(struct device *dev, struct resource *new) in devm_release_resource()
1635 struct resource *parent;
1655 struct resource *
1656 __devm_request_region(struct device *dev, struct resource *parent, in __devm_request_region()
1660 struct resource *res; in __devm_request_region()
1681 void __devm_release_region(struct device *dev, struct resource *parent, in __devm_release_region()
1698 static struct resource reserve[MAXRESERVE]; in reserve_setup()
1703 struct resource *parent; in reserve_setup()
1710 struct resource *res = reserve + x; in reserve_setup()
1739 * iomem resource tree.
1744 struct resource *p; in iomem_map_sanity_check()
1761 * if a resource is "BUSY", it's not a hardware resource in iomem_map_sanity_check()
1762 * but a driver mapping of such a resource; we don't want in iomem_map_sanity_check()
1769 pr_warn("resource sanity check: requesting [mem %pa-%pa], which spans more than %s %pR\n", in iomem_map_sanity_check()
1791 bool resource_is_exclusive(struct resource *root, u64 addr, resource_size_t size) in resource_is_exclusive()
1796 struct resource *p; in resource_is_exclusive()
1821 * A resource is exclusive if IORESOURCE_EXCLUSIVE is set in resource_is_exclusive()
1823 * resource is busy. in resource_is_exclusive()
1844 struct resource_entry *resource_list_create_entry(struct resource *res, in resource_list_create_entry()
1877 static resource_size_t gfr_start(struct resource *base, resource_size_t size, in gfr_start()
1890 static bool gfr_continue(struct resource *base, resource_size_t addr, in gfr_continue()
1913 struct resource *res = _res; in remove_free_mem_region()
1920 static struct resource *
1921 get_free_mem_region(struct device *dev, struct resource *base, in get_free_mem_region()
1927 struct resource *res; in get_free_mem_region()
1985 * Only succeed if the resource hosts an exclusive in get_free_mem_region()
2010 * @dev: device struct to bind the resource to
2012 * @base: resource tree to look in
2015 * contain the new resource, so that it can later be hotplugged as ZONE_DEVICE
2018 struct resource *devm_request_free_mem_region(struct device *dev, in devm_request_free_mem_region()
2019 struct resource *base, unsigned long size) in devm_request_free_mem_region()
2029 struct resource *request_free_mem_region(struct resource *base, in request_free_mem_region()
2041 * @base: resource that will parent the new resource
2044 * @name: resource name
2048 * Allocate and insert a new resource to cover a free, unclaimed by a
2051 struct resource *alloc_free_mem_region(struct resource *base, in alloc_free_mem_region()
2055 /* Default of ascending direction and insert resource */ in alloc_free_mem_region()