drivers/of/fdt.c
Source file repositories/reference/linux-study-clean/drivers/of/fdt.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/of/fdt.c- Extension
.c- Size
- 33991 bytes
- Lines
- 1350
- 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/crash_dump.hlinux/crc32.hlinux/kernel.hlinux/initrd.hlinux/memblock.hlinux/mutex.hlinux/of.hlinux/of_fdt.hlinux/sizes.hlinux/string.hlinux/errno.hlinux/slab.hlinux/libfdt.hlinux/debugfs.hlinux/serial_core.hlinux/sysfs.hlinux/random.hlinux/kexec_handover.hasm/setup.hasm/page.hof_private.h
Detected Declarations
function of_fdt_limit_memoryfunction of_fdt_device_is_availablefunction populate_propertiesfunction populate_nodefunction reverse_nodesfunction unflatten_dt_nodesfunction fdt_reserve_elfcorehdrfunction early_init_fdt_scan_reserved_memfunction early_init_fdt_reserve_selffunction of_scan_flat_dtfunction of_scan_flat_dt_subnodesfunction fdt_for_each_subnodefunction of_get_flat_dt_subnode_by_namefunction of_get_flat_dt_rootfunction of_get_flat_dt_propfunction of_flat_dt_get_addr_size_propfunction of_flat_dt_get_addr_sizefunction of_flat_dt_read_addr_sizefunction of_fdt_is_compatiblefunction of_flat_dt_is_compatiblefunction of_flat_dt_matchfunction of_get_flat_dt_phandlefunction of_flat_dt_get_machine_namefunction of_flat_dt_match_machinefunction __early_init_dt_declare_initrdfunction early_init_dt_check_for_initrdfunction early_init_dt_check_for_elfcorehdrfunction early_init_dt_check_for_dmcryptkeysfunction early_init_dt_check_for_usable_mem_rangefunction early_init_dt_check_khofunction early_init_dt_scan_chosen_stdoutfunction early_init_dt_scan_rootfunction dt_mem_next_cellfunction early_init_dt_scan_memoryfunction fdt_for_each_subnodefunction early_init_dt_scan_chosenfunction early_init_dt_add_memory_archfunction early_init_dt_alloc_memory_archfunction early_init_dt_verifyfunction early_init_dt_scan_nodesfunction early_init_dt_scanfunction copy_device_treefunction unflatten_device_treefunction unflatten_and_copy_device_treefunction of_fdt_raw_initexport of_fdt_unflatten_tree
Annotated Snippet
if (len > limit*cell_size) {
len = limit*cell_size;
pr_debug("Limiting number of entries to %d\n", limit);
fdt_setprop(initial_boot_params, memory, "reg", val,
len);
}
}
}
bool of_fdt_device_is_available(const void *blob, unsigned long node)
{
const char *status = fdt_stringlist_get(blob, node, "status", 0, NULL);
if (!status)
return true;
if (!strcmp(status, "ok") || !strcmp(status, "okay"))
return true;
return false;
}
static void *unflatten_dt_alloc(void **mem, unsigned long size,
unsigned long align)
{
void *res;
*mem = PTR_ALIGN(*mem, align);
res = *mem;
*mem += size;
return res;
}
static void populate_properties(const void *blob,
int offset,
void **mem,
struct device_node *np,
const char *nodename,
bool dryrun)
{
struct property *pp, **pprev = NULL;
int cur;
bool has_name = false;
pprev = &np->properties;
for (cur = fdt_first_property_offset(blob, offset);
cur >= 0;
cur = fdt_next_property_offset(blob, cur)) {
const __be32 *val;
const char *pname;
u32 sz;
val = fdt_getprop_by_offset(blob, cur, &pname, &sz);
if (!val) {
pr_warn("Cannot locate property at 0x%x\n", cur);
continue;
}
if (!pname) {
pr_warn("Cannot find property name at 0x%x\n", cur);
continue;
}
if (!strcmp(pname, "name"))
has_name = true;
pp = unflatten_dt_alloc(mem, sizeof(struct property),
__alignof__(struct property));
if (dryrun)
continue;
/* We accept flattened tree phandles either in
* ePAPR-style "phandle" properties, or the
* legacy "linux,phandle" properties. If both
* appear and have different values, things
* will get weird. Don't do that.
*/
if (!strcmp(pname, "phandle") ||
!strcmp(pname, "linux,phandle")) {
if (!np->phandle)
np->phandle = be32_to_cpup(val);
}
/* And we process the "ibm,phandle" property
* used in pSeries dynamic device tree
* stuff
*/
if (IS_ENABLED(CONFIG_PPC_PSERIES) && !strcmp(pname, "ibm,phandle"))
np->phandle = be32_to_cpup(val);
Annotation
- Immediate include surface: `linux/crash_dump.h`, `linux/crc32.h`, `linux/kernel.h`, `linux/initrd.h`, `linux/memblock.h`, `linux/mutex.h`, `linux/of.h`, `linux/of_fdt.h`.
- Detected declarations: `function of_fdt_limit_memory`, `function of_fdt_device_is_available`, `function populate_properties`, `function populate_node`, `function reverse_nodes`, `function unflatten_dt_nodes`, `function fdt_reserve_elfcorehdr`, `function early_init_fdt_scan_reserved_mem`, `function early_init_fdt_reserve_self`, `function of_scan_flat_dt`.
- 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.