Lines Matching full:resource

3  *	linux/kernel/resource.c
8 * Arbitrary resource management.
35 struct resource ioport_resource = {
43 struct resource iomem_resource = {
54 resource_size_t (*alignf)(void *, const struct resource *,
61 static struct resource *next_resource(struct resource *p, bool skip_children) in next_resource()
80 struct resource *root = pde_data(file_inode(m->file)); in r_start()
81 struct resource *p; in r_start()
95 struct resource *p = v; in r_next()
110 struct resource *root = pde_data(file_inode(m->file)); in r_show()
111 struct resource *r = v, *p; in r_show()
153 static void free_resource(struct resource *res) in free_resource()
156 * If the resource was allocated using memblock early during boot in free_resource()
159 * alloc_resource() overcomplicates resource handling. in free_resource()
165 static struct resource *alloc_resource(gfp_t flags) in alloc_resource()
167 return kzalloc(sizeof(struct resource), flags); in alloc_resource()
171 static struct resource * __request_resource(struct resource *root, struct resource *new) in __request_resource()
175 struct resource *tmp, **p; in __request_resource()
199 static int __release_resource(struct resource *old, bool release_child) in __release_resource()
201 struct resource *tmp, **p, *chd; in __release_resource()
228 static void __release_child_resources(struct resource *r) in __release_child_resources()
230 struct resource *tmp, *p; in __release_child_resources()
243 printk(KERN_DEBUG "release child resource %pR\n", tmp); in __release_child_resources()
251 void release_child_resources(struct resource *r) in release_child_resources()
259 * request_resource_conflict - request and reserve an I/O or memory resource
260 * @root: root resource descriptor
261 * @new: resource descriptor desired by caller
263 * Returns 0 for success, conflict resource on error.
265 struct resource *request_resource_conflict(struct resource *root, struct resource *new) in request_resource_conflict()
267 struct resource *conflict; in request_resource_conflict()
276 * request_resource - request and reserve an I/O or memory resource
277 * @root: root resource descriptor
278 * @new: resource descriptor desired by caller
282 int request_resource(struct resource *root, struct resource *new) in request_resource()
284 struct resource *conflict; in request_resource()
293 * release_resource - release a previously reserved resource
294 * @old: resource pointer
296 int release_resource(struct resource *old) in release_resource()
309 * find_next_iomem_res - Finds the lowest iomem resource that covers part of
312 * If a resource is found, returns 0 and @*res is overwritten with the part
313 * of the resource that's within [@start..@end]; if none is found, returns
316 * @start: start address of the resource searched for
317 * @end: end address of same resource
318 * @flags: flags which the resource must have
319 * @desc: descriptor the resource must have
320 * @res: return ptr, if resource found
327 struct resource *res) in find_next_iomem_res()
329 struct resource *p; in find_next_iomem_res()
340 /* If we passed the resource we are looking for, stop */ in find_next_iomem_res()
361 *res = (struct resource) { in find_next_iomem_res()
377 int (*func)(struct resource *, void *)) in __walk_iomem_res_desc() argument
379 struct resource res; in __walk_iomem_res_desc()
396 * with matching resource ranges.
398 * @desc: I/O resource descriptor. Use IORES_DESC_NONE to skip @desc check.
399 * @flags: I/O resource flags
403 * @func: callback function that is called for each qualifying resource area
409 * <linux/ioport.h> and set it in 'desc' of a target resource entry.
412 u64 end, void *arg, int (*func)(struct resource *, void *)) in walk_iomem_res_desc() argument
426 int (*func)(struct resource *, void *)) in walk_system_ram_res() argument
441 int (*func)(struct resource *, void *)) in walk_system_ram_res_rev() argument
443 struct resource res, *rams; in walk_system_ram_res_rev()
449 rams = kvcalloc(rams_size, sizeof(struct resource), GFP_KERNEL); in walk_system_ram_res_rev()
459 struct resource *rams_new; in walk_system_ram_res_rev()
461 rams_new = kvrealloc(rams, rams_size * sizeof(struct resource), in walk_system_ram_res_rev()
462 (rams_size + 16) * sizeof(struct resource), in walk_system_ram_res_rev()
494 int (*func)(struct resource *, void *)) in walk_mem_res() argument
512 struct resource res; in walk_system_ram_range()
547 static int __region_intersects(struct resource *parent, resource_size_t start, in __region_intersects()
551 struct resource res; in __region_intersects()
553 struct resource *p; in __region_intersects()
580 * @flags: flags of resource (in iomem_resource)
581 * @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
584 * resource identified by @flags and @desc (optional with IORES_DESC_NONE).
587 * resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
588 * and no other defined resource. Note that REGION_INTERSECTS is also
594 * through the resource table page by page.
609 void __weak arch_remove_reservations(struct resource *avail) in arch_remove_reservations()
614 const struct resource *avail, in simple_align_resource()
621 static void resource_clip(struct resource *res, resource_size_t min, in resource_clip()
631 * Find empty slot in the resource tree with the given range and
634 static int __find_resource(struct resource *root, struct resource *old, in __find_resource()
635 struct resource *new, in __find_resource()
639 struct resource *this = root->child; in __find_resource()
640 struct resource tmp = *new, avail, alloc; in __find_resource()
644 * Skip past an allocated resource that starts at 0, since the assignment in __find_resource()
691 * Find empty slot in the resource tree given range and alignment.
693 static int find_resource(struct resource *root, struct resource *new, in find_resource()
701 * reallocate_resource - allocate a slot in the resource tree given range & alignment.
702 * The resource will be relocated if the new size cannot be reallocated in the
705 * @root: root resource descriptor
706 * @old: resource descriptor desired by caller
707 * @newsize: new size of the resource descriptor
710 static int reallocate_resource(struct resource *root, struct resource *old, in reallocate_resource()
715 struct resource new = *old; in reallocate_resource()
716 struct resource *conflict; in reallocate_resource()
750 * allocate_resource - allocate empty slot in the resource tree given range & alignment.
751 * The resource will be reallocated with a new size if it was already allocated
752 * @root: root resource descriptor
753 * @new: resource descriptor desired by caller
754 * @size: requested resource region size
761 int allocate_resource(struct resource *root, struct resource *new, in allocate_resource()
765 const struct resource *, in allocate_resource() argument
783 /* resource is already allocated, try reallocating with in allocate_resource()
799 * lookup_resource - find an existing resource by a resource start address
800 * @root: root resource descriptor
801 * @start: resource start address
803 * Returns a pointer to the resource if found, NULL otherwise
805 struct resource *lookup_resource(struct resource *root, resource_size_t start) in lookup_resource()
807 struct resource *res; in lookup_resource()
820 * Insert a resource into the resource tree. If successful, return NULL,
821 * otherwise return the conflicting resource (compare to __request_resource())
823 static struct resource * __insert_resource(struct resource *parent, struct resource *new) in __insert_resource()
825 struct resource *first, *next; in __insert_resource()
873 * insert_resource_conflict - Inserts resource in the resource tree
874 * @parent: parent of the new resource
875 * @new: new resource to insert
877 * Returns 0 on success, conflict resource if the resource can't be inserted.
881 * entirely fit within the range of the new resource, then the new
882 * resource is inserted and the conflicting resources become children of
883 * the new resource.
888 struct resource *insert_resource_conflict(struct resource *parent, struct resource *new) in insert_resource_conflict()
890 struct resource *conflict; in insert_resource_conflict()
899 * insert_resource - Inserts a resource in the resource tree
900 * @parent: parent of the new resource
901 * @new: new resource to insert
903 * Returns 0 on success, -EBUSY if the resource can't be inserted.
908 int insert_resource(struct resource *parent, struct resource *new) in insert_resource()
910 struct resource *conflict; in insert_resource()
918 * insert_resource_expand_to_fit - Insert a resource into the resource tree
919 * @root: root resource descriptor
920 * @new: new resource to insert
922 * Insert a resource into the resource tree, possibly expanding it in order
925 void insert_resource_expand_to_fit(struct resource *root, struct resource *new) in insert_resource_expand_to_fit()
932 struct resource *conflict; in insert_resource_expand_to_fit()
940 /* Ok, expand resource to cover the conflict, then try again .. */ in insert_resource_expand_to_fit()
946 pr_info("Expanded resource %s due to conflict with %s\n", new->name, conflict->name); in insert_resource_expand_to_fit()
952 * resource discovery, and late discovery of CXL resources are expected
959 * remove_resource - Remove a resource in the resource tree
960 * @old: resource to remove
962 * Returns 0 on success, -EINVAL if the resource is not valid.
964 * This function removes a resource previously inserted by insert_resource()
967 * insert a new resource, and move any conflicting resources down to the
968 * children of the new resource.
973 int remove_resource(struct resource *old) in remove_resource()
984 static int __adjust_resource(struct resource *res, resource_size_t start, in __adjust_resource()
987 struct resource *tmp, *parent = res->parent; in __adjust_resource()
1022 * adjust_resource - modify a resource's start and size
1023 * @res: resource to modify
1027 * Given an existing resource, change its start and size to match the
1029 * Existing children of the resource are assumed to be immutable.
1031 int adjust_resource(struct resource *res, resource_size_t start, in adjust_resource()
1044 __reserve_region_with_split(struct resource *root, resource_size_t start, in __reserve_region_with_split()
1047 struct resource *parent = root; in __reserve_region_with_split()
1048 struct resource *conflict; in __reserve_region_with_split()
1049 struct resource *res = alloc_resource(GFP_ATOMIC); in __reserve_region_with_split()
1050 struct resource *next_res = NULL; in __reserve_region_with_split()
1105 reserve_region_with_split(struct resource *root, resource_size_t start, in reserve_region_with_split()
1134 * resource_alignment - calculate resource's alignment
1135 * @res: resource pointer
1139 resource_size_t resource_alignment(struct resource *res) in resource_alignment()
1167 static void revoke_iomem(struct resource *res) in revoke_iomem()
1183 * the resource busy by this point, so devmem_is_allowed() in revoke_iomem()
1185 * does not iterate the entire resource range. in revoke_iomem()
1199 static void revoke_iomem(struct resource *res) {} in revoke_iomem()
1213 static int __request_region_locked(struct resource *res, struct resource *parent, in __request_region_locked()
1224 struct resource *conflict; in __request_region_locked()
1265 * __request_region - create a new busy resource region
1266 * @parent: parent resource descriptor
1267 * @start: resource start address
1268 * @n: resource region size
1270 * @flags: IO resource flags
1272 struct resource *__request_region(struct resource *parent, in __request_region()
1276 struct resource *res = alloc_resource(GFP_KERNEL); in __request_region()
1299 * __release_region - release a previously reserved resource region
1300 * @parent: parent resource descriptor
1301 * @start: resource start address
1302 * @n: resource region size
1304 * The described resource region must match a currently busy region.
1306 void __release_region(struct resource *parent, resource_size_t start, in __release_region()
1309 struct resource **p; in __release_region()
1318 struct resource *res = *p; in __release_region()
1341 pr_warn("Trying to free nonexistent resource <%pa-%pa>\n", &start, &end); in __release_region()
1348 * @start: resource start address
1349 * @size: resource region size
1352 * is released from a currently busy memory resource. The requested region
1353 * must either match exactly or fit into a single busy resource entry. In
1354 * the latter case, the remaining resource is adjusted accordingly.
1355 * Existing children of the busy memory resource must be immutable in the
1361 * - When a busy memory resource gets split into two entries, the code
1367 struct resource *parent = &iomem_resource; in release_mem_region_adjustable()
1368 struct resource *new_res = NULL; in release_mem_region_adjustable()
1370 struct resource **p; in release_mem_region_adjustable()
1371 struct resource *res; in release_mem_region_adjustable()
1395 /* look for the next resource if it does not fit into */ in release_mem_region_adjustable()
1409 /* found the target resource; let's adjust accordingly */ in release_mem_region_adjustable()
1423 /* split into two entries - we need a new resource */ in release_mem_region_adjustable()
1457 static bool system_ram_resources_mergeable(struct resource *r1, in system_ram_resources_mergeable()
1458 struct resource *r2) in system_ram_resources_mergeable()
1467 * merge_system_ram_resource - mark the System RAM resource mergeable and try to
1469 * @res: resource descriptor
1473 * the actual resource boundaries are not of interest (e.g., it might be
1480 * marked mergeable are used anymore after this call - the resource might
1484 void merge_system_ram_resource(struct resource *res) in merge_system_ram_resource()
1487 struct resource *cur; in merge_system_ram_resource()
1517 * Managed region resource
1521 struct resource **r = ptr; in devm_resource_release()
1527 * devm_request_resource() - request and reserve an I/O or memory resource
1528 * @dev: device for which to request the resource
1529 * @root: root of the resource tree from which to request the resource
1530 * @new: descriptor of the resource to request
1535 * If for some reason the resource needs to be released explicitly, because
1540 * requested resource, an error message will be printed.
1544 int devm_request_resource(struct device *dev, struct resource *root, in devm_request_resource()
1545 struct resource *new) in devm_request_resource()
1547 struct resource *conflict, **ptr; in devm_request_resource()
1557 dev_err(dev, "resource collision: %pR conflicts with %s %pR\n", in devm_request_resource()
1570 struct resource **ptr = res; in devm_resource_match()
1576 * devm_release_resource() - release a previously requested resource
1577 * @dev: device for which to release the resource
1578 * @new: descriptor of the resource to release
1580 * Releases a resource previously requested using devm_request_resource().
1582 void devm_release_resource(struct device *dev, struct resource *new) in devm_release_resource()
1590 struct resource *parent;
1610 struct resource *
1611 __devm_request_region(struct device *dev, struct resource *parent, in __devm_request_region()
1615 struct resource *res; in __devm_request_region()
1636 void __devm_release_region(struct device *dev, struct resource *parent, in __devm_release_region()
1654 static struct resource reserve[MAXRESERVE]; in reserve_setup()
1659 struct resource *parent; in reserve_setup()
1666 struct resource *res = reserve + x; in reserve_setup()
1695 * iomem resource tree.
1700 struct resource *p; in iomem_map_sanity_check()
1717 * if a resource is "BUSY", it's not a hardware resource in iomem_map_sanity_check()
1718 * but a driver mapping of such a resource; we don't want in iomem_map_sanity_check()
1725 pr_warn("resource sanity check: requesting [mem %pa-%pa], which spans more than %s %pR\n", in iomem_map_sanity_check()
1747 bool resource_is_exclusive(struct resource *root, u64 addr, resource_size_t size) in resource_is_exclusive()
1752 struct resource *p; in resource_is_exclusive()
1777 * A resource is exclusive if IORESOURCE_EXCLUSIVE is set in resource_is_exclusive()
1779 * resource is busy. in resource_is_exclusive()
1800 struct resource_entry *resource_list_create_entry(struct resource *res, in resource_list_create_entry()
1829 static resource_size_t gfr_start(struct resource *base, resource_size_t size, in gfr_start()
1843 static bool gfr_continue(struct resource *base, resource_size_t addr, in gfr_continue()
1867 struct resource *res = _res; in remove_free_mem_region()
1874 static struct resource *
1875 get_free_mem_region(struct device *dev, struct resource *base, in get_free_mem_region()
1881 struct resource *res; in get_free_mem_region()
1939 * Only succeed if the resource hosts an exclusive in get_free_mem_region()
1964 * @dev: device struct to bind the resource to
1966 * @base: resource tree to look in
1969 * contain the new resource, so that it can later be hotplugged as ZONE_DEVICE
1972 struct resource *devm_request_free_mem_region(struct device *dev, in devm_request_free_mem_region()
1973 struct resource *base, unsigned long size) in devm_request_free_mem_region()
1983 struct resource *request_free_mem_region(struct resource *base, in request_free_mem_region()
1995 * @base: resource that will parent the new resource
1998 * @name: resource name
2002 * Allocate and insert a new resource to cover a free, unclaimed by a
2005 struct resource *alloc_free_mem_region(struct resource *base, in alloc_free_mem_region()
2009 /* Default of ascending direction and insert resource */ in alloc_free_mem_region()