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 *,
60 * For memory hotplug, there is no way to free resource entries allocated
61 * by boot mem after the system is up. So for reusing the resource entry
62 * we need to remember the resource.
64 static struct resource *bootmem_resource_free;
67 static struct resource *next_resource(struct resource *p) in next_resource()
78 struct resource *p = v; in r_next()
90 struct resource *p = PDE_DATA(file_inode(m->file)); in r_start()
106 struct resource *root = PDE_DATA(file_inode(m->file)); in r_show()
107 struct resource *r = v, *p; in r_show()
149 static void free_resource(struct resource *res) in free_resource()
164 static struct resource *alloc_resource(gfp_t flags) in alloc_resource()
166 struct resource *res = NULL; in alloc_resource()
176 memset(res, 0, sizeof(struct resource)); in alloc_resource()
178 res = kzalloc(sizeof(struct resource), flags); in alloc_resource()
184 static struct resource * __request_resource(struct resource *root, struct resource *new) in __request_resource()
188 struct resource *tmp, **p; in __request_resource()
212 static int __release_resource(struct resource *old, bool release_child) in __release_resource()
214 struct resource *tmp, **p, *chd; in __release_resource()
241 static void __release_child_resources(struct resource *r) in __release_child_resources()
243 struct resource *tmp, *p; in __release_child_resources()
256 printk(KERN_DEBUG "release child resource %pR\n", tmp); in __release_child_resources()
264 void release_child_resources(struct resource *r) in release_child_resources()
272 * request_resource_conflict - request and reserve an I/O or memory resource
273 * @root: root resource descriptor
274 * @new: resource descriptor desired by caller
276 * Returns 0 for success, conflict resource on error.
278 struct resource *request_resource_conflict(struct resource *root, struct resource *new) in request_resource_conflict()
280 struct resource *conflict; in request_resource_conflict()
289 * request_resource - request and reserve an I/O or memory resource
290 * @root: root resource descriptor
291 * @new: resource descriptor desired by caller
295 int request_resource(struct resource *root, struct resource *new) in request_resource()
297 struct resource *conflict; in request_resource()
306 * release_resource - release a previously reserved resource
307 * @old: resource pointer
309 int release_resource(struct resource *old) in release_resource()
322 * find_next_iomem_res - Finds the lowest iomem resource that covers part of
325 * If a resource is found, returns 0 and @*res is overwritten with the part
326 * of the resource that's within [@start..@end]; if none is found, returns
329 * @start: start address of the resource searched for
330 * @end: end address of same resource
331 * @flags: flags which the resource must have
332 * @desc: descriptor the resource must have
333 * @res: return ptr, if resource found
340 struct resource *res) in find_next_iomem_res()
342 struct resource *p; in find_next_iomem_res()
353 /* If we passed the resource we are looking for, stop */ in find_next_iomem_res()
374 *res = (struct resource) { in find_next_iomem_res()
390 int (*func)(struct resource *, void *)) in __walk_iomem_res_desc() argument
392 struct resource res; in __walk_iomem_res_desc()
409 * with matching resource ranges.
411 * @desc: I/O resource descriptor. Use IORES_DESC_NONE to skip @desc check.
412 * @flags: I/O resource flags
416 * @func: callback function that is called for each qualifying resource area
422 * <linux/ioport.h> and set it in 'desc' of a target resource entry.
425 u64 end, void *arg, int (*func)(struct resource *, void *)) in walk_iomem_res_desc() argument
439 int (*func)(struct resource *, void *)) in walk_system_ram_res() argument
452 int (*func)(struct resource *, void *)) in walk_mem_res() argument
470 struct resource res; in walk_system_ram_range()
508 struct resource res; in __region_intersects()
510 struct resource *p; in __region_intersects()
537 * @flags: flags of resource (in iomem_resource)
538 * @desc: descriptor of resource (in iomem_resource) or IORES_DESC_NONE
541 * resource identified by @flags and @desc (optional with IORES_DESC_NONE).
544 * resource, and return REGION_INTERSECTS if the region overlaps @flags/@desc
545 * and no other defined resource. Note that REGION_INTERSECTS is also
551 * through the resource table page by page.
566 void __weak arch_remove_reservations(struct resource *avail) in arch_remove_reservations()
571 const struct resource *avail, in simple_align_resource()
578 static void resource_clip(struct resource *res, resource_size_t min, in resource_clip()
588 * Find empty slot in the resource tree with the given range and
591 static int __find_resource(struct resource *root, struct resource *old, in __find_resource()
592 struct resource *new, in __find_resource()
596 struct resource *this = root->child; in __find_resource()
597 struct resource tmp = *new, avail, alloc; in __find_resource()
601 * Skip past an allocated resource that starts at 0, since the assignment in __find_resource()
648 * Find empty slot in the resource tree given range and alignment.
650 static int find_resource(struct resource *root, struct resource *new, in find_resource()
658 * reallocate_resource - allocate a slot in the resource tree given range & alignment.
659 * The resource will be relocated if the new size cannot be reallocated in the
662 * @root: root resource descriptor
663 * @old: resource descriptor desired by caller
664 * @newsize: new size of the resource descriptor
667 static int reallocate_resource(struct resource *root, struct resource *old, in reallocate_resource()
672 struct resource new = *old; in reallocate_resource()
673 struct resource *conflict; in reallocate_resource()
707 * allocate_resource - allocate empty slot in the resource tree given range & alignment.
708 * The resource will be reallocated with a new size if it was already allocated
709 * @root: root resource descriptor
710 * @new: resource descriptor desired by caller
711 * @size: requested resource region size
718 int allocate_resource(struct resource *root, struct resource *new, in allocate_resource()
722 const struct resource *, in allocate_resource() argument
740 /* resource is already allocated, try reallocating with in allocate_resource()
756 * lookup_resource - find an existing resource by a resource start address
757 * @root: root resource descriptor
758 * @start: resource start address
760 * Returns a pointer to the resource if found, NULL otherwise
762 struct resource *lookup_resource(struct resource *root, resource_size_t start) in lookup_resource()
764 struct resource *res; in lookup_resource()
777 * Insert a resource into the resource tree. If successful, return NULL,
778 * otherwise return the conflicting resource (compare to __request_resource())
780 static struct resource * __insert_resource(struct resource *parent, struct resource *new) in __insert_resource()
782 struct resource *first, *next; in __insert_resource()
830 * insert_resource_conflict - Inserts resource in the resource tree
831 * @parent: parent of the new resource
832 * @new: new resource to insert
834 * Returns 0 on success, conflict resource if the resource can't be inserted.
838 * entirely fit within the range of the new resource, then the new
839 * resource is inserted and the conflicting resources become children of
840 * the new resource.
845 struct resource *insert_resource_conflict(struct resource *parent, struct resource *new) in insert_resource_conflict()
847 struct resource *conflict; in insert_resource_conflict()
856 * insert_resource - Inserts a resource in the resource tree
857 * @parent: parent of the new resource
858 * @new: new resource to insert
860 * Returns 0 on success, -EBUSY if the resource can't be inserted.
865 int insert_resource(struct resource *parent, struct resource *new) in insert_resource()
867 struct resource *conflict; in insert_resource()
875 * insert_resource_expand_to_fit - Insert a resource into the resource tree
876 * @root: root resource descriptor
877 * @new: new resource to insert
879 * Insert a resource into the resource tree, possibly expanding it in order
882 void insert_resource_expand_to_fit(struct resource *root, struct resource *new) in insert_resource_expand_to_fit()
889 struct resource *conflict; in insert_resource_expand_to_fit()
897 /* Ok, expand resource to cover the conflict, then try again .. */ in insert_resource_expand_to_fit()
903 printk("Expanded resource %s due to conflict with %s\n", new->name, conflict->name); in insert_resource_expand_to_fit()
909 * remove_resource - Remove a resource in the resource tree
910 * @old: resource to remove
912 * Returns 0 on success, -EINVAL if the resource is not valid.
914 * This function removes a resource previously inserted by insert_resource()
917 * insert a new resource, and move any conflicting resources down to the
918 * children of the new resource.
923 int remove_resource(struct resource *old) in remove_resource()
934 static int __adjust_resource(struct resource *res, resource_size_t start, in __adjust_resource()
937 struct resource *tmp, *parent = res->parent; in __adjust_resource()
972 * adjust_resource - modify a resource's start and size
973 * @res: resource to modify
977 * Given an existing resource, change its start and size to match the
979 * Existing children of the resource are assumed to be immutable.
981 int adjust_resource(struct resource *res, resource_size_t start, in adjust_resource()
994 __reserve_region_with_split(struct resource *root, resource_size_t start, in __reserve_region_with_split()
997 struct resource *parent = root; in __reserve_region_with_split()
998 struct resource *conflict; in __reserve_region_with_split()
999 struct resource *res = alloc_resource(GFP_ATOMIC); in __reserve_region_with_split()
1000 struct resource *next_res = NULL; in __reserve_region_with_split()
1055 reserve_region_with_split(struct resource *root, resource_size_t start, in reserve_region_with_split()
1084 * resource_alignment - calculate resource's alignment
1085 * @res: resource pointer
1089 resource_size_t resource_alignment(struct resource *res) in resource_alignment()
1117 static void revoke_iomem(struct resource *res) in revoke_iomem()
1133 * the resource busy by this point, so devmem_is_allowed() in revoke_iomem()
1135 * does not iterate the entire resource range. in revoke_iomem()
1149 static void revoke_iomem(struct resource *res) {} in revoke_iomem()
1163 static int __request_region_locked(struct resource *res, struct resource *parent, in __request_region_locked()
1174 struct resource *conflict; in __request_region_locked()
1215 * __request_region - create a new busy resource region
1216 * @parent: parent resource descriptor
1217 * @start: resource start address
1218 * @n: resource region size
1220 * @flags: IO resource flags
1222 struct resource *__request_region(struct resource *parent, in __request_region()
1226 struct resource *res = alloc_resource(GFP_KERNEL); in __request_region()
1249 * __release_region - release a previously reserved resource region
1250 * @parent: parent resource descriptor
1251 * @start: resource start address
1252 * @n: resource region size
1254 * The described resource region must match a currently busy region.
1256 void __release_region(struct resource *parent, resource_size_t start, in __release_region()
1259 struct resource **p; in __release_region()
1268 struct resource *res = *p; in __release_region()
1291 printk(KERN_WARNING "Trying to free nonexistent resource " in __release_region()
1300 * @start: resource start address
1301 * @size: resource region size
1304 * is released from a currently busy memory resource. The requested region
1305 * must either match exactly or fit into a single busy resource entry. In
1306 * the latter case, the remaining resource is adjusted accordingly.
1307 * Existing children of the busy memory resource must be immutable in the
1313 * - When a busy memory resource gets split into two entries, the code
1319 struct resource *parent = &iomem_resource; in release_mem_region_adjustable()
1320 struct resource *new_res = NULL; in release_mem_region_adjustable()
1322 struct resource **p; in release_mem_region_adjustable()
1323 struct resource *res; in release_mem_region_adjustable()
1347 /* look for the next resource if it does not fit into */ in release_mem_region_adjustable()
1355 * flag IORESOURCE_SYSTEM_RAM. If the resource does not have in release_mem_region_adjustable()
1356 * this flag, we know that we are dealing with a resource coming in release_mem_region_adjustable()
1358 * a resource. This goes via devm_request_mem_region and in release_mem_region_adjustable()
1375 /* found the target resource; let's adjust accordingly */ in release_mem_region_adjustable()
1389 /* split into two entries - we need a new resource */ in release_mem_region_adjustable()
1423 static bool system_ram_resources_mergeable(struct resource *r1, in system_ram_resources_mergeable()
1424 struct resource *r2) in system_ram_resources_mergeable()
1433 * merge_system_ram_resource - mark the System RAM resource mergeable and try to
1435 * @res: resource descriptor
1439 * the actual resource boundaries are not of interest (e.g., it might be
1446 * marked mergeable are used anymore after this call - the resource might
1450 void merge_system_ram_resource(struct resource *res) in merge_system_ram_resource()
1453 struct resource *cur; in merge_system_ram_resource()
1483 * Managed region resource
1487 struct resource **r = ptr; in devm_resource_release()
1493 * devm_request_resource() - request and reserve an I/O or memory resource
1494 * @dev: device for which to request the resource
1495 * @root: root of the resource tree from which to request the resource
1496 * @new: descriptor of the resource to request
1501 * If for some reason the resource needs to be released explicitly, because
1506 * requested resource, an error message will be printed.
1510 int devm_request_resource(struct device *dev, struct resource *root, in devm_request_resource()
1511 struct resource *new) in devm_request_resource()
1513 struct resource *conflict, **ptr; in devm_request_resource()
1523 dev_err(dev, "resource collision: %pR conflicts with %s %pR\n", in devm_request_resource()
1536 struct resource **ptr = res; in devm_resource_match()
1542 * devm_release_resource() - release a previously requested resource
1543 * @dev: device for which to release the resource
1544 * @new: descriptor of the resource to release
1546 * Releases a resource previously requested using devm_request_resource().
1548 void devm_release_resource(struct device *dev, struct resource *new) in devm_release_resource()
1556 struct resource *parent;
1576 struct resource *
1577 __devm_request_region(struct device *dev, struct resource *parent, in __devm_request_region()
1581 struct resource *res; in __devm_request_region()
1602 void __devm_release_region(struct device *dev, struct resource *parent, in __devm_release_region()
1620 static struct resource reserve[MAXRESERVE]; in reserve_setup()
1625 struct resource *parent; in reserve_setup()
1632 struct resource *res = reserve + x; in reserve_setup()
1661 * iomem resource tree.
1665 struct resource *p = &iomem_resource; in iomem_map_sanity_check()
1683 * if a resource is "BUSY", it's not a hardware resource in iomem_map_sanity_check()
1684 * but a driver mapping of such a resource; we don't want in iomem_map_sanity_check()
1691 …printk(KERN_WARNING "resource sanity check: requesting [mem %#010llx-%#010llx], which spans more t… in iomem_map_sanity_check()
1710 * check if an address is reserved in the iomem resource tree
1715 struct resource *p = &iomem_resource; in iomem_is_exclusive()
1736 * A resource is exclusive if IORESOURCE_EXCLUSIVE is set in iomem_is_exclusive()
1738 * resource is busy. in iomem_is_exclusive()
1753 struct resource_entry *resource_list_create_entry(struct resource *res, in resource_list_create_entry()
1778 static struct resource *__request_free_mem_region(struct device *dev, in __request_free_mem_region()
1779 struct resource *base, unsigned long size, const char *name) in __request_free_mem_region()
1782 struct resource *res; in __request_free_mem_region()
1840 * @dev: device struct to bind the resource to
1842 * @base: resource tree to look in
1845 * contain the new resource, so that it can later be hotplugged as ZONE_DEVICE
1848 struct resource *devm_request_free_mem_region(struct device *dev, in devm_request_free_mem_region()
1849 struct resource *base, unsigned long size) in devm_request_free_mem_region()
1855 struct resource *request_free_mem_region(struct resource *base, in request_free_mem_region()