drivers/of/of_reserved_mem.c
Source file repositories/reference/linux-study-clean/drivers/of/of_reserved_mem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/of/of_reserved_mem.c- Extension
.c- Size
- 24971 bytes
- Lines
- 896
- Domain
- Driver Families
- Bucket
- drivers/of
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/err.hlinux/ioport.hlinux/libfdt.hlinux/of.hlinux/of_fdt.hlinux/of_platform.hlinux/mm.hlinux/sizes.hlinux/of_reserved_mem.hlinux/sort.hlinux/slab.hlinux/memblock.hlinux/kmemleak.hof_private.h
Detected Declarations
struct rmem_assigned_devicefunction early_init_dt_alloc_reserved_memory_archfunction alloc_reserved_mem_arrayfunction early_init_dt_reserve_memoryfunction __reserved_mem_reserve_regfunction __reserved_mem_check_rootfunction __rmem_cmpfunction __rmem_check_for_overlapfunction fdt_scan_reserved_mem_latefunction fdt_for_each_subnodefunction fdt_scan_reserved_memfunction fdt_for_each_subnodefunction __reserved_mem_alloc_in_rangefunction __reserved_mem_alloc_sizefunction fdt_fixup_reserved_mem_nodefunction fdt_validate_reserved_mem_nodefunction __reserved_mem_init_nodefunction fdt_init_reserved_mem_nodefunction of_reserved_mem_device_init_by_idxfunction of_reserved_mem_device_init_by_namefunction of_reserved_mem_device_releasefunction list_for_each_entry_safefunction of_reserved_mem_lookupfunction of_reserved_mem_region_to_resourcefunction of_reserved_mem_region_to_resource_bynamefunction of_reserved_mem_region_countexport of_reserved_mem_device_init_by_idxexport of_reserved_mem_device_init_by_nameexport of_reserved_mem_device_releaseexport of_reserved_mem_lookupexport of_reserved_mem_region_to_resourceexport of_reserved_mem_region_to_resource_bynameexport of_reserved_mem_region_count
Annotated Snippet
struct rmem_assigned_device {
struct device *dev;
struct reserved_mem *rmem;
struct list_head list;
};
static LIST_HEAD(of_rmem_assigned_device_list);
static DEFINE_MUTEX(of_rmem_assigned_device_mutex);
/**
* of_reserved_mem_device_init_by_idx() - assign reserved memory region to
* given device
* @dev: Pointer to the device to configure
* @np: Pointer to the device_node with 'reserved-memory' property
* @idx: Index of selected region
*
* This function assigns respective DMA-mapping operations based on reserved
* memory region specified by 'memory-region' property in @np node to the @dev
* device. When driver needs to use more than one reserved memory region, it
* should allocate child devices and initialize regions by name for each of
* child device.
*
* Returns error code or zero on success.
*/
int of_reserved_mem_device_init_by_idx(struct device *dev,
struct device_node *np, int idx)
{
struct rmem_assigned_device *rd;
struct device_node *target;
struct reserved_mem *rmem;
int ret;
if (!np || !dev)
return -EINVAL;
target = of_parse_phandle(np, "memory-region", idx);
if (!target)
return -ENODEV;
if (!of_device_is_available(target)) {
of_node_put(target);
return 0;
}
rmem = of_reserved_mem_lookup(target);
of_node_put(target);
if (!rmem || !rmem->ops || !rmem->ops->device_init)
return -EINVAL;
rd = kmalloc_obj(struct rmem_assigned_device);
if (!rd)
return -ENOMEM;
ret = rmem->ops->device_init(rmem, dev);
if (ret == 0) {
rd->dev = dev;
rd->rmem = rmem;
mutex_lock(&of_rmem_assigned_device_mutex);
list_add(&rd->list, &of_rmem_assigned_device_list);
mutex_unlock(&of_rmem_assigned_device_mutex);
dev_info(dev, "assigned reserved memory node %s\n", rmem->name);
} else {
kfree(rd);
}
return ret;
}
EXPORT_SYMBOL_GPL(of_reserved_mem_device_init_by_idx);
/**
* of_reserved_mem_device_init_by_name() - assign named reserved memory region
* to given device
* @dev: pointer to the device to configure
* @np: pointer to the device node with 'memory-region' property
* @name: name of the selected memory region
*
* Returns: 0 on success or a negative error-code on failure.
*/
int of_reserved_mem_device_init_by_name(struct device *dev,
struct device_node *np,
const char *name)
{
int idx = of_property_match_string(np, "memory-region-names", name);
return of_reserved_mem_device_init_by_idx(dev, np, idx);
}
EXPORT_SYMBOL_GPL(of_reserved_mem_device_init_by_name);
Annotation
- Immediate include surface: `linux/err.h`, `linux/ioport.h`, `linux/libfdt.h`, `linux/of.h`, `linux/of_fdt.h`, `linux/of_platform.h`, `linux/mm.h`, `linux/sizes.h`.
- Detected declarations: `struct rmem_assigned_device`, `function early_init_dt_alloc_reserved_memory_arch`, `function alloc_reserved_mem_array`, `function early_init_dt_reserve_memory`, `function __reserved_mem_reserve_reg`, `function __reserved_mem_check_root`, `function __rmem_cmp`, `function __rmem_check_for_overlap`, `function fdt_scan_reserved_mem_late`, `function fdt_for_each_subnode`.
- Atlas domain: Driver Families / drivers/of.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.