Lines Matching full:resource

3  *	linux/kernel/resource.c
8 * Arbitrary resource management.
33 struct resource ioport_resource = {
41 struct resource iomem_resource = {
52 resource_size_t (*alignf)(void *, const struct resource *,
59 static struct resource *next_resource(struct resource *p) in next_resource()
68 static struct resource *next_resource_skip_children(struct resource *p) in next_resource_skip_children()
82 struct resource *p = v; in r_next()
94 struct resource *p = pde_data(file_inode(m->file)); in r_start()
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
439 int (*func)(struct resource *, void *)) in walk_mem_res() argument
457 struct resource res; in walk_system_ram_range()
492 static int __region_intersects(struct resource *parent, resource_size_t start, in __region_intersects()
498 struct resource *p, *dp; in __region_intersects()
500 struct resource res; in __region_intersects()
521 * will behave similar as the following fake resource in __region_intersects()
538 * isn't covered by matched resource. in __region_intersects()
567 * @flags: flags of resource (in iomem_resource)
568 * @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
571 * resource identified by @flags and @desc (optional with IORES_DESC_NONE).
574 * resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
575 * and no other defined resource. Note that REGION_INTERSECTS is also
581 * through the resource table page by page.
596 void __weak arch_remove_reservations(struct resource *avail) in arch_remove_reservations()
601 const struct resource *avail, in simple_align_resource()
608 static void resource_clip(struct resource *res, resource_size_t min, in resource_clip()
618 * Find empty slot in the resource tree with the given range and
621 static int __find_resource(struct resource *root, struct resource *old, in __find_resource()
622 struct resource *new, in __find_resource()
626 struct resource *this = root->child; in __find_resource()
627 struct resource tmp = *new, avail, alloc; in __find_resource()
631 * Skip past an allocated resource that starts at 0, since the assignment in __find_resource()
678 * Find empty slot in the resource tree given range and alignment.
680 static int find_resource(struct resource *root, struct resource *new, in find_resource()
688 * reallocate_resource - allocate a slot in the resource tree given range & alignment.
689 * The resource will be relocated if the new size cannot be reallocated in the
692 * @root: root resource descriptor
693 * @old: resource descriptor desired by caller
694 * @newsize: new size of the resource descriptor
697 static int reallocate_resource(struct resource *root, struct resource *old, in reallocate_resource()
702 struct resource new = *old; in reallocate_resource()
703 struct resource *conflict; in reallocate_resource()
737 * allocate_resource - allocate empty slot in the resource tree given range & alignment.
738 * The resource will be reallocated with a new size if it was already allocated
739 * @root: root resource descriptor
740 * @new: resource descriptor desired by caller
741 * @size: requested resource region size
748 int allocate_resource(struct resource *root, struct resource *new, in allocate_resource()
752 const struct resource *, in allocate_resource() argument
770 /* resource is already allocated, try reallocating with in allocate_resource()
786 * lookup_resource - find an existing resource by a resource start address
787 * @root: root resource descriptor
788 * @start: resource start address
790 * Returns a pointer to the resource if found, NULL otherwise
792 struct resource *lookup_resource(struct resource *root, resource_size_t start) in lookup_resource()
794 struct resource *res; in lookup_resource()
807 * Insert a resource into the resource tree. If successful, return NULL,
808 * otherwise return the conflicting resource (compare to __request_resource())
810 static struct resource * __insert_resource(struct resource *parent, struct resource *new) in __insert_resource()
812 struct resource *first, *next; in __insert_resource()
860 * insert_resource_conflict - Inserts resource in the resource tree
861 * @parent: parent of the new resource
862 * @new: new resource to insert
864 * Returns 0 on success, conflict resource if the resource can't be inserted.
868 * entirely fit within the range of the new resource, then the new
869 * resource is inserted and the conflicting resources become children of
870 * the new resource.
875 struct resource *insert_resource_conflict(struct resource *parent, struct resource *new) in insert_resource_conflict()
877 struct resource *conflict; in insert_resource_conflict()
886 * insert_resource - Inserts a resource in the resource tree
887 * @parent: parent of the new resource
888 * @new: new resource to insert
890 * Returns 0 on success, -EBUSY if the resource can't be inserted.
895 int insert_resource(struct resource *parent, struct resource *new) in insert_resource()
897 struct resource *conflict; in insert_resource()
905 * insert_resource_expand_to_fit - Insert a resource into the resource tree
906 * @root: root resource descriptor
907 * @new: new resource to insert
909 * Insert a resource into the resource tree, possibly expanding it in order
912 void insert_resource_expand_to_fit(struct resource *root, struct resource *new) in insert_resource_expand_to_fit()
919 struct resource *conflict; in insert_resource_expand_to_fit()
927 /* Ok, expand resource to cover the conflict, then try again .. */ in insert_resource_expand_to_fit()
933 pr_info("Expanded resource %s due to conflict with %s\n", new->name, conflict->name); in insert_resource_expand_to_fit()
939 * resource discovery, and late discovery of CXL resources are expected
946 * remove_resource - Remove a resource in the resource tree
947 * @old: resource to remove
949 * Returns 0 on success, -EINVAL if the resource is not valid.
951 * This function removes a resource previously inserted by insert_resource()
954 * insert a new resource, and move any conflicting resources down to the
955 * children of the new resource.
960 int remove_resource(struct resource *old) in remove_resource()
971 static int __adjust_resource(struct resource *res, resource_size_t start, in __adjust_resource()
974 struct resource *tmp, *parent = res->parent; in __adjust_resource()
1009 * adjust_resource - modify a resource's start and size
1010 * @res: resource to modify
1014 * Given an existing resource, change its start and size to match the
1016 * Existing children of the resource are assumed to be immutable.
1018 int adjust_resource(struct resource *res, resource_size_t start, in adjust_resource()
1031 __reserve_region_with_split(struct resource *root, resource_size_t start, in __reserve_region_with_split()
1034 struct resource *parent = root; in __reserve_region_with_split()
1035 struct resource *conflict; in __reserve_region_with_split()
1036 struct resource *res = alloc_resource(GFP_ATOMIC); in __reserve_region_with_split()
1037 struct resource *next_res = NULL; in __reserve_region_with_split()
1092 reserve_region_with_split(struct resource *root, resource_size_t start, in reserve_region_with_split()
1121 * resource_alignment - calculate resource's alignment
1122 * @res: resource pointer
1126 resource_size_t resource_alignment(struct resource *res) in resource_alignment()
1154 static void revoke_iomem(struct resource *res) in revoke_iomem()
1170 * the resource busy by this point, so devmem_is_allowed() in revoke_iomem()
1172 * does not iterate the entire resource range. in revoke_iomem()
1186 static void revoke_iomem(struct resource *res) {} in revoke_iomem()
1200 static int __request_region_locked(struct resource *res, struct resource *parent, in __request_region_locked()
1211 struct resource *conflict; in __request_region_locked()
1252 * __request_region - create a new busy resource region
1253 * @parent: parent resource descriptor
1254 * @start: resource start address
1255 * @n: resource region size
1257 * @flags: IO resource flags
1259 struct resource *__request_region(struct resource *parent, in __request_region()
1263 struct resource *res = alloc_resource(GFP_KERNEL); in __request_region()
1286 * __release_region - release a previously reserved resource region
1287 * @parent: parent resource descriptor
1288 * @start: resource start address
1289 * @n: resource region size
1291 * The described resource region must match a currently busy region.
1293 void __release_region(struct resource *parent, resource_size_t start, in __release_region()
1296 struct resource **p; in __release_region()
1305 struct resource *res = *p; in __release_region()
1328 pr_warn("Trying to free nonexistent resource <%pa-%pa>\n", &start, &end); in __release_region()
1335 * @start: resource start address
1336 * @size: resource region size
1339 * is released from a currently busy memory resource. The requested region
1340 * must either match exactly or fit into a single busy resource entry. In
1341 * the latter case, the remaining resource is adjusted accordingly.
1342 * Existing children of the busy memory resource must be immutable in the
1348 * - When a busy memory resource gets split into two entries, the code
1354 struct resource *parent = &iomem_resource; in release_mem_region_adjustable()
1355 struct resource *new_res = NULL; in release_mem_region_adjustable()
1357 struct resource **p; in release_mem_region_adjustable()
1358 struct resource *res; in release_mem_region_adjustable()
1382 /* look for the next resource if it does not fit into */ in release_mem_region_adjustable()
1396 /* found the target resource; let's adjust accordingly */ in release_mem_region_adjustable()
1410 /* split into two entries - we need a new resource */ in release_mem_region_adjustable()
1444 static bool system_ram_resources_mergeable(struct resource *r1, in system_ram_resources_mergeable()
1445 struct resource *r2) in system_ram_resources_mergeable()
1454 * merge_system_ram_resource - mark the System RAM resource mergeable and try to
1456 * @res: resource descriptor
1460 * the actual resource boundaries are not of interest (e.g., it might be
1467 * marked mergeable are used anymore after this call - the resource might
1471 void merge_system_ram_resource(struct resource *res) in merge_system_ram_resource()
1474 struct resource *cur; in merge_system_ram_resource()
1504 * Managed region resource
1508 struct resource **r = ptr; in devm_resource_release()
1514 * devm_request_resource() - request and reserve an I/O or memory resource
1515 * @dev: device for which to request the resource
1516 * @root: root of the resource tree from which to request the resource
1517 * @new: descriptor of the resource to request
1522 * If for some reason the resource needs to be released explicitly, because
1527 * requested resource, an error message will be printed.
1531 int devm_request_resource(struct device *dev, struct resource *root, in devm_request_resource()
1532 struct resource *new) in devm_request_resource()
1534 struct resource *conflict, **ptr; in devm_request_resource()
1544 dev_err(dev, "resource collision: %pR conflicts with %s %pR\n", in devm_request_resource()
1557 struct resource **ptr = res; in devm_resource_match()
1563 * devm_release_resource() - release a previously requested resource
1564 * @dev: device for which to release the resource
1565 * @new: descriptor of the resource to release
1567 * Releases a resource previously requested using devm_request_resource().
1569 void devm_release_resource(struct device *dev, struct resource *new) in devm_release_resource()
1577 struct resource *parent;
1597 struct resource *
1598 __devm_request_region(struct device *dev, struct resource *parent, in __devm_request_region()
1602 struct resource *res; in __devm_request_region()
1623 void __devm_release_region(struct device *dev, struct resource *parent, in __devm_release_region()
1641 static struct resource reserve[MAXRESERVE]; in reserve_setup()
1646 struct resource *parent; in reserve_setup()
1653 struct resource *res = reserve + x; in reserve_setup()
1682 * iomem resource tree.
1686 struct resource *p = &iomem_resource; in iomem_map_sanity_check()
1705 * if a resource is "BUSY", it's not a hardware resource in iomem_map_sanity_check()
1706 * but a driver mapping of such a resource; we don't want in iomem_map_sanity_check()
1713 pr_warn("resource sanity check: requesting [mem %pa-%pa], which spans more than %s %pR\n", in iomem_map_sanity_check()
1735 bool resource_is_exclusive(struct resource *root, u64 addr, resource_size_t size) in resource_is_exclusive()
1740 struct resource *p; in resource_is_exclusive()
1765 * A resource is exclusive if IORESOURCE_EXCLUSIVE is set in resource_is_exclusive()
1767 * resource is busy. in resource_is_exclusive()
1788 struct resource_entry *resource_list_create_entry(struct resource *res, in resource_list_create_entry()
1817 static resource_size_t gfr_start(struct resource *base, resource_size_t size, in gfr_start()
1830 static bool gfr_continue(struct resource *base, resource_size_t addr, in gfr_continue()
1853 struct resource *res = _res; in remove_free_mem_region()
1860 static struct resource *
1861 get_free_mem_region(struct device *dev, struct resource *base, in get_free_mem_region()
1867 struct resource *res; in get_free_mem_region()
1925 * Only succeed if the resource hosts an exclusive in get_free_mem_region()
1950 * @dev: device struct to bind the resource to
1952 * @base: resource tree to look in
1955 * contain the new resource, so that it can later be hotplugged as ZONE_DEVICE
1958 struct resource *devm_request_free_mem_region(struct device *dev, in devm_request_free_mem_region()
1959 struct resource *base, unsigned long size) in devm_request_free_mem_region()
1969 struct resource *request_free_mem_region(struct resource *base, in request_free_mem_region()
1981 * @base: resource that will parent the new resource
1984 * @name: resource name
1988 * Allocate and insert a new resource to cover a free, unclaimed by a
1991 struct resource *alloc_free_mem_region(struct resource *base, in alloc_free_mem_region()
1995 /* Default of ascending direction and insert resource */ in alloc_free_mem_region()