drivers/of/overlay.c
Source file repositories/reference/linux-study-clean/drivers/of/overlay.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/of/overlay.c- Extension
.c- Size
- 36572 bytes
- Lines
- 1299
- 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/kernel.hlinux/module.hlinux/of.hlinux/of_device.hlinux/of_fdt.hlinux/string.hlinux/ctype.hlinux/errno.hlinux/slab.hlinux/libfdt.hlinux/err.hlinux/idr.hof_private.h
Detected Declarations
struct targetstruct fragmentstruct overlay_changesetfunction of_prop_val_eqfunction devicetree_corruptfunction of_overlay_mutex_lockfunction of_overlay_mutex_unlockfunction of_overlay_notifier_registerfunction of_overlay_notifier_unregisterfunction overlay_notifyfunction overlay_fw_devlink_refreshfunction add_changeset_propertyfunction add_changeset_nodefunction build_changeset_next_levelfunction for_each_property_of_nodefunction for_each_child_of_node_scopedfunction build_changeset_symbols_nodefunction for_each_property_of_nodefunction find_dup_cset_node_entryfunction find_dup_cset_propfunction changeset_dup_entry_checkfunction list_for_each_entryfunction build_changesetfunction init_overlay_changesetfunction free_overlay_changesetfunction of_overlay_applyfunction of_overlay_fdt_applyfunction find_nodefunction for_each_child_of_node_scopedfunction node_overlaps_later_csfunction list_for_each_entry_reversefunction list_for_each_entryfunction overlay_removal_is_okfunction list_for_each_entryfunction of_overlay_removefunction of_overlay_remove_allexport of_overlay_notifier_registerexport of_overlay_notifier_unregisterexport of_overlay_fdt_applyexport of_overlay_removeexport of_overlay_remove_all
Annotated Snippet
struct target {
struct device_node *np;
bool in_livetree;
};
/**
* struct fragment - info about fragment nodes in overlay expanded device tree
* @overlay: pointer to the __overlay__ node
* @target: target of the overlay operation
*/
struct fragment {
struct device_node *overlay;
struct device_node *target;
};
/**
* struct overlay_changeset
* @id: changeset identifier
* @ovcs_list: list on which we are located
* @new_fdt: Memory allocated to hold unflattened aligned FDT
* @overlay_mem: the memory chunk that contains @overlay_root
* @overlay_root: expanded device tree that contains the fragment nodes
* @notify_state: most recent notify action used on overlay
* @count: count of fragment structures
* @fragments: fragment nodes in the overlay expanded device tree
* @symbols_fragment: last element of @fragments[] is the __symbols__ node
* @cset: changeset to apply fragments to live device tree
*/
struct overlay_changeset {
int id;
struct list_head ovcs_list;
const void *new_fdt;
const void *overlay_mem;
struct device_node *overlay_root;
enum of_overlay_notify_action notify_state;
int count;
struct fragment *fragments;
bool symbols_fragment;
struct of_changeset cset;
};
/* flags are sticky - once set, do not reset */
static int devicetree_state_flags;
#define DTSF_APPLY_FAIL 0x01
#define DTSF_REVERT_FAIL 0x02
static int of_prop_val_eq(const struct property *p1, const struct property *p2)
{
return p1->length == p2->length &&
!memcmp(p1->value, p2->value, (size_t)p1->length);
}
/*
* If a changeset apply or revert encounters an error, an attempt will
* be made to undo partial changes, but may fail. If the undo fails
* we do not know the state of the devicetree.
*/
static int devicetree_corrupt(void)
{
return devicetree_state_flags &
(DTSF_APPLY_FAIL | DTSF_REVERT_FAIL);
}
static int build_changeset_next_level(struct overlay_changeset *ovcs,
struct target *target, const struct device_node *overlay_node);
/*
* of_resolve_phandles() finds the largest phandle in the live tree.
* of_overlay_apply() may add a larger phandle to the live tree.
* Do not allow race between two overlays being applied simultaneously:
* mutex_lock(&of_overlay_phandle_mutex)
* of_resolve_phandles()
* of_overlay_apply()
* mutex_unlock(&of_overlay_phandle_mutex)
*/
static DEFINE_MUTEX(of_overlay_phandle_mutex);
void of_overlay_mutex_lock(void)
{
mutex_lock(&of_overlay_phandle_mutex);
}
void of_overlay_mutex_unlock(void)
{
mutex_unlock(&of_overlay_phandle_mutex);
}
static LIST_HEAD(ovcs_list);
static DEFINE_IDR(ovcs_idr);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/of_device.h`, `linux/of_fdt.h`, `linux/string.h`, `linux/ctype.h`, `linux/errno.h`.
- Detected declarations: `struct target`, `struct fragment`, `struct overlay_changeset`, `function of_prop_val_eq`, `function devicetree_corrupt`, `function of_overlay_mutex_lock`, `function of_overlay_mutex_unlock`, `function of_overlay_notifier_register`, `function of_overlay_notifier_unregister`, `function overlay_notify`.
- 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.