kernel/resource.c
Source file repositories/reference/linux-study-clean/kernel/resource.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/resource.c- Extension
.c- Size
- 57799 bytes
- Lines
- 2207
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/errno.hlinux/ioport.hlinux/init.hlinux/slab.hlinux/spinlock.hlinux/fs.hlinux/proc_fs.hlinux/pseudo_fs.hlinux/sched.hlinux/seq_file.hlinux/device.hlinux/pfn.hlinux/mm.hlinux/mount.hlinux/resource_ext.huapi/linux/magic.hlinux/string.hlinux/vmalloc.hasm/io.h
Detected Declarations
struct region_devresfunction r_stopfunction r_showfunction ioresources_initfunction free_resourcefunction __request_resourcefunction __release_resourcefunction __release_child_resourcesfunction release_child_resourcesfunction request_resourcefunction release_resourcefunction is_type_matchfunction find_next_resfunction for_each_resourcefunction find_next_iomem_resfunction walk_res_descfunction __walk_iomem_res_descfunction walk_iomem_res_descfunction walk_soft_reserve_resfunction walk_system_ram_resfunction walk_system_ram_res_revfunction walk_mem_resfunction walk_system_ram_rangefunction __is_ramfunction page_is_ramfunction __region_intersectsfunction for_each_resourcefunction region_intersectsfunction region_intersects_soft_reservefunction arch_remove_reservationsfunction __find_resource_spacefunction find_resource_spacefunction reallocate_resourcefunction allocate_resourcefunction resourcefunction insert_resourcefunction insert_resource_expand_to_fitfunction insert_resourcefunction __adjust_resourcefunction adjust_resourcefunction __reserve_region_with_splitfunction reserve_region_with_splitfunction resource_alignmentfunction revoke_iomemfunction devmem_is_allowedfunction revoke_iomemfunction __request_region_lockedfunction __release_region
Annotated Snippet
struct region_devres {
struct resource *parent;
resource_size_t start;
resource_size_t n;
};
static void devm_region_release(struct device *dev, void *res)
{
struct region_devres *this = res;
__release_region(this->parent, this->start, this->n);
}
static int devm_region_match(struct device *dev, void *res, void *match_data)
{
struct region_devres *this = res, *match = match_data;
return this->parent == match->parent &&
this->start == match->start && this->n == match->n;
}
struct resource *
__devm_request_region(struct device *dev, struct resource *parent,
resource_size_t start, resource_size_t n, const char *name)
{
struct region_devres *dr = NULL;
struct resource *res;
dr = devres_alloc(devm_region_release, sizeof(struct region_devres),
GFP_KERNEL);
if (!dr)
return NULL;
dr->parent = parent;
dr->start = start;
dr->n = n;
res = __request_region(parent, start, n, name, 0);
if (res)
devres_add(dev, dr);
else
devres_free(dr);
return res;
}
EXPORT_SYMBOL(__devm_request_region);
void __devm_release_region(struct device *dev, struct resource *parent,
resource_size_t start, resource_size_t n)
{
struct region_devres match_data = { parent, start, n };
WARN_ON(devres_release(dev, devm_region_release, devm_region_match,
&match_data));
}
EXPORT_SYMBOL(__devm_release_region);
/*
* Reserve I/O ports or memory based on "reserve=" kernel parameter.
*/
#define MAXRESERVE 4
static int __init reserve_setup(char *str)
{
static int reserved;
static struct resource reserve[MAXRESERVE];
for (;;) {
unsigned int io_start, io_num;
int x = reserved;
struct resource *parent;
if (get_option(&str, &io_start) != 2)
break;
if (get_option(&str, &io_num) == 0)
break;
if (x < MAXRESERVE) {
struct resource *res = reserve + x;
/*
* If the region starts below 0x10000, we assume it's
* I/O port space; otherwise assume it's memory.
*/
if (io_start < 0x10000) {
*res = DEFINE_RES_IO_NAMED(io_start, io_num, "reserved");
parent = &ioport_resource;
} else {
*res = DEFINE_RES_MEM_NAMED(io_start, io_num, "reserved");
parent = &iomem_resource;
}
res->flags |= IORESOURCE_BUSY;
Annotation
- Immediate include surface: `linux/export.h`, `linux/errno.h`, `linux/ioport.h`, `linux/init.h`, `linux/slab.h`, `linux/spinlock.h`, `linux/fs.h`, `linux/proc_fs.h`.
- Detected declarations: `struct region_devres`, `function r_stop`, `function r_show`, `function ioresources_init`, `function free_resource`, `function __request_resource`, `function __release_resource`, `function __release_child_resources`, `function release_child_resources`, `function request_resource`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.