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()
496 struct resource res; in __region_intersects()
498 struct resource *p; in __region_intersects()
525 * @flags: flags of resource (in iomem_resource)
526 * @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
529 * resource identified by @flags and @desc (optional with IORES_DESC_NONE).
532 * resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
533 * and no other defined resource. Note that REGION_INTERSECTS is also
539 * through the resource table page by page.
554 void __weak arch_remove_reservations(struct resource *avail) in arch_remove_reservations()
559 const struct resource *avail, in simple_align_resource()
566 static void resource_clip(struct resource *res, resource_size_t min, in resource_clip()
576 * Find empty slot in the resource tree with the given range and
579 static int __find_resource(struct resource *root, struct resource *old, in __find_resource()
580 struct resource *new, in __find_resource()
584 struct resource *this = root->child; in __find_resource()
585 struct resource tmp = *new, avail, alloc; in __find_resource()
589 * Skip past an allocated resource that starts at 0, since the assignment in __find_resource()
636 * Find empty slot in the resource tree given range and alignment.
638 static int find_resource(struct resource *root, struct resource *new, in find_resource()
646 * reallocate_resource - allocate a slot in the resource tree given range & alignment.
647 * The resource will be relocated if the new size cannot be reallocated in the
650 * @root: root resource descriptor
651 * @old: resource descriptor desired by caller
652 * @newsize: new size of the resource descriptor
655 static int reallocate_resource(struct resource *root, struct resource *old, in reallocate_resource()
660 struct resource new = *old; in reallocate_resource()
661 struct resource *conflict; in reallocate_resource()
695 * allocate_resource - allocate empty slot in the resource tree given range & alignment.
696 * The resource will be reallocated with a new size if it was already allocated
697 * @root: root resource descriptor
698 * @new: resource descriptor desired by caller
699 * @size: requested resource region size
706 int allocate_resource(struct resource *root, struct resource *new, in allocate_resource()
710 const struct resource *, in allocate_resource() argument
728 /* resource is already allocated, try reallocating with in allocate_resource()
744 * lookup_resource - find an existing resource by a resource start address
745 * @root: root resource descriptor
746 * @start: resource start address
748 * Returns a pointer to the resource if found, NULL otherwise
750 struct resource *lookup_resource(struct resource *root, resource_size_t start) in lookup_resource()
752 struct resource *res; in lookup_resource()
765 * Insert a resource into the resource tree. If successful, return NULL,
766 * otherwise return the conflicting resource (compare to __request_resource())
768 static struct resource * __insert_resource(struct resource *parent, struct resource *new) in __insert_resource()
770 struct resource *first, *next; in __insert_resource()
818 * insert_resource_conflict - Inserts resource in the resource tree
819 * @parent: parent of the new resource
820 * @new: new resource to insert
822 * Returns 0 on success, conflict resource if the resource can't be inserted.
826 * entirely fit within the range of the new resource, then the new
827 * resource is inserted and the conflicting resources become children of
828 * the new resource.
833 struct resource *insert_resource_conflict(struct resource *parent, struct resource *new) in insert_resource_conflict()
835 struct resource *conflict; in insert_resource_conflict()
844 * insert_resource - Inserts a resource in the resource tree
845 * @parent: parent of the new resource
846 * @new: new resource to insert
848 * Returns 0 on success, -EBUSY if the resource can't be inserted.
853 int insert_resource(struct resource *parent, struct resource *new) in insert_resource()
855 struct resource *conflict; in insert_resource()
863 * insert_resource_expand_to_fit - Insert a resource into the resource tree
864 * @root: root resource descriptor
865 * @new: new resource to insert
867 * Insert a resource into the resource tree, possibly expanding it in order
870 void insert_resource_expand_to_fit(struct resource *root, struct resource *new) in insert_resource_expand_to_fit()
877 struct resource *conflict; in insert_resource_expand_to_fit()
885 /* Ok, expand resource to cover the conflict, then try again .. */ in insert_resource_expand_to_fit()
891 printk("Expanded resource %s due to conflict with %s\n", new->name, conflict->name); in insert_resource_expand_to_fit()
897 * resource discovery, and late discovery of CXL resources are expected
904 * remove_resource - Remove a resource in the resource tree
905 * @old: resource to remove
907 * Returns 0 on success, -EINVAL if the resource is not valid.
909 * This function removes a resource previously inserted by insert_resource()
912 * insert a new resource, and move any conflicting resources down to the
913 * children of the new resource.
918 int remove_resource(struct resource *old) in remove_resource()
929 static int __adjust_resource(struct resource *res, resource_size_t start, in __adjust_resource()
932 struct resource *tmp, *parent = res->parent; in __adjust_resource()
967 * adjust_resource - modify a resource's start and size
968 * @res: resource to modify
972 * Given an existing resource, change its start and size to match the
974 * Existing children of the resource are assumed to be immutable.
976 int adjust_resource(struct resource *res, resource_size_t start, in adjust_resource()
989 __reserve_region_with_split(struct resource *root, resource_size_t start, in __reserve_region_with_split()
992 struct resource *parent = root; in __reserve_region_with_split()
993 struct resource *conflict; in __reserve_region_with_split()
994 struct resource *res = alloc_resource(GFP_ATOMIC); in __reserve_region_with_split()
995 struct resource *next_res = NULL; in __reserve_region_with_split()
1050 reserve_region_with_split(struct resource *root, resource_size_t start, in reserve_region_with_split()
1079 * resource_alignment - calculate resource's alignment
1080 * @res: resource pointer
1084 resource_size_t resource_alignment(struct resource *res) in resource_alignment()
1112 static void revoke_iomem(struct resource *res) in revoke_iomem()
1128 * the resource busy by this point, so devmem_is_allowed() in revoke_iomem()
1130 * does not iterate the entire resource range. in revoke_iomem()
1144 static void revoke_iomem(struct resource *res) {} in revoke_iomem()
1158 static int __request_region_locked(struct resource *res, struct resource *parent, in __request_region_locked()
1169 struct resource *conflict; in __request_region_locked()
1210 * __request_region - create a new busy resource region
1211 * @parent: parent resource descriptor
1212 * @start: resource start address
1213 * @n: resource region size
1215 * @flags: IO resource flags
1217 struct resource *__request_region(struct resource *parent, in __request_region()
1221 struct resource *res = alloc_resource(GFP_KERNEL); in __request_region()
1244 * __release_region - release a previously reserved resource region
1245 * @parent: parent resource descriptor
1246 * @start: resource start address
1247 * @n: resource region size
1249 * The described resource region must match a currently busy region.
1251 void __release_region(struct resource *parent, resource_size_t start, in __release_region()
1254 struct resource **p; in __release_region()
1263 struct resource *res = *p; in __release_region()
1286 printk(KERN_WARNING "Trying to free nonexistent resource " in __release_region()
1295 * @start: resource start address
1296 * @size: resource region size
1299 * is released from a currently busy memory resource. The requested region
1300 * must either match exactly or fit into a single busy resource entry. In
1301 * the latter case, the remaining resource is adjusted accordingly.
1302 * Existing children of the busy memory resource must be immutable in the
1308 * - When a busy memory resource gets split into two entries, the code
1314 struct resource *parent = &iomem_resource; in release_mem_region_adjustable()
1315 struct resource *new_res = NULL; in release_mem_region_adjustable()
1317 struct resource **p; in release_mem_region_adjustable()
1318 struct resource *res; in release_mem_region_adjustable()
1342 /* look for the next resource if it does not fit into */ in release_mem_region_adjustable()
1350 * flag IORESOURCE_SYSTEM_RAM. If the resource does not have in release_mem_region_adjustable()
1351 * this flag, we know that we are dealing with a resource coming in release_mem_region_adjustable()
1353 * a resource. This goes via devm_request_mem_region and in release_mem_region_adjustable()
1370 /* found the target resource; let's adjust accordingly */ in release_mem_region_adjustable()
1384 /* split into two entries - we need a new resource */ in release_mem_region_adjustable()
1418 static bool system_ram_resources_mergeable(struct resource *r1, in system_ram_resources_mergeable()
1419 struct resource *r2) in system_ram_resources_mergeable()
1428 * merge_system_ram_resource - mark the System RAM resource mergeable and try to
1430 * @res: resource descriptor
1434 * the actual resource boundaries are not of interest (e.g., it might be
1441 * marked mergeable are used anymore after this call - the resource might
1445 void merge_system_ram_resource(struct resource *res) in merge_system_ram_resource()
1448 struct resource *cur; in merge_system_ram_resource()
1478 * Managed region resource
1482 struct resource **r = ptr; in devm_resource_release()
1488 * devm_request_resource() - request and reserve an I/O or memory resource
1489 * @dev: device for which to request the resource
1490 * @root: root of the resource tree from which to request the resource
1491 * @new: descriptor of the resource to request
1496 * If for some reason the resource needs to be released explicitly, because
1501 * requested resource, an error message will be printed.
1505 int devm_request_resource(struct device *dev, struct resource *root, in devm_request_resource()
1506 struct resource *new) in devm_request_resource()
1508 struct resource *conflict, **ptr; in devm_request_resource()
1518 dev_err(dev, "resource collision: %pR conflicts with %s %pR\n", in devm_request_resource()
1531 struct resource **ptr = res; in devm_resource_match()
1537 * devm_release_resource() - release a previously requested resource
1538 * @dev: device for which to release the resource
1539 * @new: descriptor of the resource to release
1541 * Releases a resource previously requested using devm_request_resource().
1543 void devm_release_resource(struct device *dev, struct resource *new) in devm_release_resource()
1551 struct resource *parent;
1571 struct resource *
1572 __devm_request_region(struct device *dev, struct resource *parent, in __devm_request_region()
1576 struct resource *res; in __devm_request_region()
1597 void __devm_release_region(struct device *dev, struct resource *parent, in __devm_release_region()
1615 static struct resource reserve[MAXRESERVE]; in reserve_setup()
1620 struct resource *parent; in reserve_setup()
1627 struct resource *res = reserve + x; in reserve_setup()
1656 * iomem resource tree.
1660 struct resource *p = &iomem_resource; in iomem_map_sanity_check()
1678 * if a resource is "BUSY", it's not a hardware resource in iomem_map_sanity_check()
1679 * but a driver mapping of such a resource; we don't want in iomem_map_sanity_check()
1686 …printk(KERN_WARNING "resource sanity check: requesting [mem %#010llx-%#010llx], which spans more t… in iomem_map_sanity_check()
1716 struct resource *p; in iomem_is_exclusive()
1743 * A resource is exclusive if IORESOURCE_EXCLUSIVE is set in iomem_is_exclusive()
1745 * resource is busy. in iomem_is_exclusive()
1760 struct resource_entry *resource_list_create_entry(struct resource *res, in resource_list_create_entry()
1789 static resource_size_t gfr_start(struct resource *base, resource_size_t size, in gfr_start()
1803 static bool gfr_continue(struct resource *base, resource_size_t addr, in gfr_continue()
1827 struct resource *res = _res; in remove_free_mem_region()
1834 static struct resource *
1835 get_free_mem_region(struct device *dev, struct resource *base, in get_free_mem_region()
1841 struct resource *res; in get_free_mem_region()
1899 * Only succeed if the resource hosts an exclusive in get_free_mem_region()
1924 * @dev: device struct to bind the resource to
1926 * @base: resource tree to look in
1929 * contain the new resource, so that it can later be hotplugged as ZONE_DEVICE
1932 struct resource *devm_request_free_mem_region(struct device *dev, in devm_request_free_mem_region()
1933 struct resource *base, unsigned long size) in devm_request_free_mem_region()
1943 struct resource *request_free_mem_region(struct resource *base, in request_free_mem_region()
1955 * @base: resource that will parent the new resource
1958 * @name: resource name
1962 * Allocate and insert a new resource to cover a free, unclaimed by a
1965 struct resource *alloc_free_mem_region(struct resource *base, in alloc_free_mem_region()
1969 /* Default of ascending direction and insert resource */ in alloc_free_mem_region()