Lines Matching full:resource

3  *	linux/kernel/resource.c
8 * Arbitrary resource management.
30 struct resource ioport_resource = {
38 struct resource iomem_resource = {
49 resource_size_t (*alignf)(void *, const struct resource *,
57 * For memory hotplug, there is no way to free resource entries allocated
58 * by boot mem after the system is up. So for reusing the resource entry
59 * we need to remember the resource.
61 static struct resource *bootmem_resource_free;
64 static struct resource *next_resource(struct resource *p, bool sibling_only) in next_resource()
79 struct resource *p = v; in r_next()
91 struct resource *p = PDE_DATA(file_inode(m->file)); in r_start()
107 struct resource *root = PDE_DATA(file_inode(m->file)); in r_show()
108 struct resource *r = v, *p; in r_show()
150 static void free_resource(struct resource *res) in free_resource()
165 static struct resource *alloc_resource(gfp_t flags) in alloc_resource()
167 struct resource *res = NULL; in alloc_resource()
177 memset(res, 0, sizeof(struct resource)); in alloc_resource()
179 res = kzalloc(sizeof(struct resource), flags); in alloc_resource()
185 static struct resource * __request_resource(struct resource *root, struct resource *new) in __request_resource()
189 struct resource *tmp, **p; in __request_resource()
213 static int __release_resource(struct resource *old, bool release_child) in __release_resource()
215 struct resource *tmp, **p, *chd; in __release_resource()
242 static void __release_child_resources(struct resource *r) in __release_child_resources()
244 struct resource *tmp, *p; in __release_child_resources()
257 printk(KERN_DEBUG "release child resource %pR\n", tmp); in __release_child_resources()
265 void release_child_resources(struct resource *r) in release_child_resources()
273 * request_resource_conflict - request and reserve an I/O or memory resource
274 * @root: root resource descriptor
275 * @new: resource descriptor desired by caller
277 * Returns 0 for success, conflict resource on error.
279 struct resource *request_resource_conflict(struct resource *root, struct resource *new) in request_resource_conflict()
281 struct resource *conflict; in request_resource_conflict()
290 * request_resource - request and reserve an I/O or memory resource
291 * @root: root resource descriptor
292 * @new: resource descriptor desired by caller
296 int request_resource(struct resource *root, struct resource *new) in request_resource()
298 struct resource *conflict; in request_resource()
307 * release_resource - release a previously reserved resource
308 * @old: resource pointer
310 int release_resource(struct resource *old) in release_resource()
323 * Finds the lowest iomem resource that covers part of [@start..@end]. The
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
334 * @start: start address of the resource searched for
335 * @end: end address of same resource
336 * @flags: flags which the resource must have
337 * @desc: descriptor the resource must have
339 * @res: return ptr, if resource found
343 bool first_lvl, struct resource *res) in find_next_iomem_res()
346 struct resource *p; in find_next_iomem_res()
357 /* If we passed the resource we are looking for, stop */ in find_next_iomem_res()
385 *res = (struct resource) { in find_next_iomem_res()
401 int (*func)(struct resource *, void *)) in __walk_iomem_res_desc() argument
403 struct resource res; in __walk_iomem_res_desc()
419 * Walks through iomem resources and calls func() with matching resource
424 * @desc: I/O resource descriptor. Use IORES_DESC_NONE to skip @desc check.
425 * @flags: I/O resource flags
429 * @func: callback function that is called for each qualifying resource area
432 * <linux/ioport.h> and set it in 'desc' of a target resource entry.
435 u64 end, void *arg, int (*func)(struct resource *, void *)) in walk_iomem_res_desc() argument
449 int (*func)(struct resource *, void *)) in walk_system_ram_res() argument
462 int (*func)(struct resource *, void *)) in walk_mem_res() argument
483 struct resource res; in walk_system_ram_range()
523 * @flags: flags of resource (in iomem_resource)
524 * @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
527 * resource identified by @flags and @desc (optional with IORES_DESC_NONE).
530 * resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
531 * and no other defined resource. Note that REGION_INTERSECTS is also
537 * through the resource table page by page.
542 struct resource res; in region_intersects()
544 struct resource *p; in region_intersects()
570 void __weak arch_remove_reservations(struct resource *avail) in arch_remove_reservations()
575 const struct resource *avail, in simple_align_resource()
582 static void resource_clip(struct resource *res, resource_size_t min, in resource_clip()
592 * Find empty slot in the resource tree with the given range and
595 static int __find_resource(struct resource *root, struct resource *old, in __find_resource()
596 struct resource *new, in __find_resource()
600 struct resource *this = root->child; in __find_resource()
601 struct resource tmp = *new, avail, alloc; in __find_resource()
605 * Skip past an allocated resource that starts at 0, since the assignment in __find_resource()
652 * Find empty slot in the resource tree given range and alignment.
654 static int find_resource(struct resource *root, struct resource *new, in find_resource()
662 * reallocate_resource - allocate a slot in the resource tree given range & alignment.
663 * The resource will be relocated if the new size cannot be reallocated in the
666 * @root: root resource descriptor
667 * @old: resource descriptor desired by caller
668 * @newsize: new size of the resource descriptor
671 static int reallocate_resource(struct resource *root, struct resource *old, in reallocate_resource()
676 struct resource new = *old; in reallocate_resource()
677 struct resource *conflict; in reallocate_resource()
711 * allocate_resource - allocate empty slot in the resource tree given range & alignment.
712 * The resource will be reallocated with a new size if it was already allocated
713 * @root: root resource descriptor
714 * @new: resource descriptor desired by caller
715 * @size: requested resource region size
722 int allocate_resource(struct resource *root, struct resource *new, in allocate_resource()
726 const struct resource *, in allocate_resource() argument
744 /* resource is already allocated, try reallocating with in allocate_resource()
760 * lookup_resource - find an existing resource by a resource start address
761 * @root: root resource descriptor
762 * @start: resource start address
764 * Returns a pointer to the resource if found, NULL otherwise
766 struct resource *lookup_resource(struct resource *root, resource_size_t start) in lookup_resource()
768 struct resource *res; in lookup_resource()
781 * Insert a resource into the resource tree. If successful, return NULL,
782 * otherwise return the conflicting resource (compare to __request_resource())
784 static struct resource * __insert_resource(struct resource *parent, struct resource *new) in __insert_resource()
786 struct resource *first, *next; in __insert_resource()
834 * insert_resource_conflict - Inserts resource in the resource tree
835 * @parent: parent of the new resource
836 * @new: new resource to insert
838 * Returns 0 on success, conflict resource if the resource can't be inserted.
842 * entirely fit within the range of the new resource, then the new
843 * resource is inserted and the conflicting resources become children of
844 * the new resource.
849 struct resource *insert_resource_conflict(struct resource *parent, struct resource *new) in insert_resource_conflict()
851 struct resource *conflict; in insert_resource_conflict()
860 * insert_resource - Inserts a resource in the resource tree
861 * @parent: parent of the new resource
862 * @new: new resource to insert
864 * Returns 0 on success, -EBUSY if the resource can't be inserted.
869 int insert_resource(struct resource *parent, struct resource *new) in insert_resource()
871 struct resource *conflict; in insert_resource()
879 * insert_resource_expand_to_fit - Insert a resource into the resource tree
880 * @root: root resource descriptor
881 * @new: new resource to insert
883 * Insert a resource into the resource tree, possibly expanding it in order
886 void insert_resource_expand_to_fit(struct resource *root, struct resource *new) in insert_resource_expand_to_fit()
893 struct resource *conflict; in insert_resource_expand_to_fit()
901 /* Ok, expand resource to cover the conflict, then try again .. */ in insert_resource_expand_to_fit()
907 printk("Expanded resource %s due to conflict with %s\n", new->name, conflict->name); in insert_resource_expand_to_fit()
913 * remove_resource - Remove a resource in the resource tree
914 * @old: resource to remove
916 * Returns 0 on success, -EINVAL if the resource is not valid.
918 * This function removes a resource previously inserted by insert_resource()
921 * insert a new resource, and move any conflicting resources down to the
922 * children of the new resource.
927 int remove_resource(struct resource *old) in remove_resource()
938 static int __adjust_resource(struct resource *res, resource_size_t start, in __adjust_resource()
941 struct resource *tmp, *parent = res->parent; in __adjust_resource()
976 * adjust_resource - modify a resource's start and size
977 * @res: resource to modify
981 * Given an existing resource, change its start and size to match the
983 * Existing children of the resource are assumed to be immutable.
985 int adjust_resource(struct resource *res, resource_size_t start, in adjust_resource()
998 __reserve_region_with_split(struct resource *root, resource_size_t start, in __reserve_region_with_split()
1001 struct resource *parent = root; in __reserve_region_with_split()
1002 struct resource *conflict; in __reserve_region_with_split()
1003 struct resource *res = alloc_resource(GFP_ATOMIC); in __reserve_region_with_split()
1004 struct resource *next_res = NULL; in __reserve_region_with_split()
1059 reserve_region_with_split(struct resource *root, resource_size_t start, in reserve_region_with_split()
1088 * resource_alignment - calculate resource's alignment
1089 * @res: resource pointer
1093 resource_size_t resource_alignment(struct resource *res) in resource_alignment()
1119 * __request_region - create a new busy resource region
1120 * @parent: parent resource descriptor
1121 * @start: resource start address
1122 * @n: resource region size
1124 * @flags: IO resource flags
1126 struct resource * __request_region(struct resource *parent, in __request_region()
1131 struct resource *res = alloc_resource(GFP_KERNEL); in __request_region()
1132 struct resource *orig_parent = parent; in __request_region()
1144 struct resource *conflict; in __request_region()
1192 * __release_region - release a previously reserved resource region
1193 * @parent: parent resource descriptor
1194 * @start: resource start address
1195 * @n: resource region size
1197 * The described resource region must match a currently busy region.
1199 void __release_region(struct resource *parent, resource_size_t start, in __release_region()
1202 struct resource **p; in __release_region()
1211 struct resource *res = *p; in __release_region()
1234 printk(KERN_WARNING "Trying to free nonexistent resource " in __release_region()
1243 * @start: resource start address
1244 * @size: resource region size
1247 * is released from a currently busy memory resource. The requested region
1248 * must either match exactly or fit into a single busy resource entry. In
1249 * the latter case, the remaining resource is adjusted accordingly.
1250 * Existing children of the busy memory resource must be immutable in the
1256 * - When a busy memory resource gets split into two entries, the code
1262 struct resource *parent = &iomem_resource; in release_mem_region_adjustable()
1263 struct resource *new_res = NULL; in release_mem_region_adjustable()
1265 struct resource **p; in release_mem_region_adjustable()
1266 struct resource *res; in release_mem_region_adjustable()
1290 /* look for the next resource if it does not fit into */ in release_mem_region_adjustable()
1298 * flag IORESOURCE_SYSTEM_RAM. If the resource does not have in release_mem_region_adjustable()
1299 * this flag, we know that we are dealing with a resource coming in release_mem_region_adjustable()
1301 * a resource. This goes via devm_request_mem_region and in release_mem_region_adjustable()
1318 /* found the target resource; let's adjust accordingly */ in release_mem_region_adjustable()
1332 /* split into two entries - we need a new resource */ in release_mem_region_adjustable()
1366 static bool system_ram_resources_mergeable(struct resource *r1, in system_ram_resources_mergeable()
1367 struct resource *r2) in system_ram_resources_mergeable()
1376 * merge_system_ram_resource - mark the System RAM resource mergeable and try to
1378 * @res: resource descriptor
1382 * the actual resource boundaries are not of interest (e.g., it might be
1389 * marked mergeable are used anymore after this call - the resource might
1393 void merge_system_ram_resource(struct resource *res) in merge_system_ram_resource()
1396 struct resource *cur; in merge_system_ram_resource()
1426 * Managed region resource
1430 struct resource **r = ptr; in devm_resource_release()
1436 * devm_request_resource() - request and reserve an I/O or memory resource
1437 * @dev: device for which to request the resource
1438 * @root: root of the resource tree from which to request the resource
1439 * @new: descriptor of the resource to request
1444 * If for some reason the resource needs to be released explicitly, because
1449 * requested resource, an error message will be printed.
1453 int devm_request_resource(struct device *dev, struct resource *root, in devm_request_resource()
1454 struct resource *new) in devm_request_resource()
1456 struct resource *conflict, **ptr; in devm_request_resource()
1466 dev_err(dev, "resource collision: %pR conflicts with %s %pR\n", in devm_request_resource()
1479 struct resource **ptr = res; in devm_resource_match()
1485 * devm_release_resource() - release a previously requested resource
1486 * @dev: device for which to release the resource
1487 * @new: descriptor of the resource to release
1489 * Releases a resource previously requested using devm_request_resource().
1491 void devm_release_resource(struct device *dev, struct resource *new) in devm_release_resource()
1499 struct resource *parent;
1519 struct resource *
1520 __devm_request_region(struct device *dev, struct resource *parent, in __devm_request_region()
1524 struct resource *res; in __devm_request_region()
1545 void __devm_release_region(struct device *dev, struct resource *parent, in __devm_release_region()
1563 static struct resource reserve[MAXRESERVE]; in reserve_setup()
1568 struct resource *parent; in reserve_setup()
1575 struct resource *res = reserve + x; in reserve_setup()
1604 * iomem resource tree.
1608 struct resource *p = &iomem_resource; in iomem_map_sanity_check()
1626 * if a resource is "BUSY", it's not a hardware resource in iomem_map_sanity_check()
1627 * but a driver mapping of such a resource; we don't want in iomem_map_sanity_check()
1634 …printk(KERN_WARNING "resource sanity check: requesting [mem %#010llx-%#010llx], which spans more t… in iomem_map_sanity_check()
1653 * check if an address is reserved in the iomem resource tree
1658 struct resource *p = &iomem_resource; in iomem_is_exclusive()
1679 * A resource is exclusive if IORESOURCE_EXCLUSIVE is set in iomem_is_exclusive()
1681 * resource is busy. in iomem_is_exclusive()
1696 struct resource_entry *resource_list_create_entry(struct resource *res, in resource_list_create_entry()
1721 static struct resource *__request_free_mem_region(struct device *dev, in __request_free_mem_region()
1722 struct resource *base, unsigned long size, const char *name) in __request_free_mem_region()
1725 struct resource *res; in __request_free_mem_region()
1752 * @dev: device struct to bind the resource to
1754 * @base: resource tree to look in
1757 * contain the new resource, so that it can later be hotplugged as ZONE_DEVICE
1760 struct resource *devm_request_free_mem_region(struct device *dev, in devm_request_free_mem_region()
1761 struct resource *base, unsigned long size) in devm_request_free_mem_region()
1767 struct resource *request_free_mem_region(struct resource *base, in request_free_mem_region()