drivers/of/cpu.c
Source file repositories/reference/linux-study-clean/drivers/of/cpu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/of/cpu.c- Extension
.c- Size
- 6386 bytes
- Lines
- 211
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/cpu.hlinux/kernel.hlinux/of.h
Detected Declarations
function of_get_cpu_hwidfunction arch_match_cpu_phys_idfunction __of_find_n_match_cpu_propertyfunction arch_find_n_match_cpu_physical_idfunction of_node_putfunction for_each_of_cpu_nodefunction of_cpu_node_to_idfunction for_each_possible_cpuexport of_get_cpu_nodeexport of_cpu_device_node_getexport of_cpu_node_to_idexport of_get_cpu_state_node
Annotated Snippet
if (arch_match_cpu_phys_id(cpu, hwid)) {
if (thread)
*thread = tid;
return true;
}
cell += ac;
}
return false;
}
/*
* arch_find_n_match_cpu_physical_id - See if the given device node is
* for the cpu corresponding to logical cpu 'cpu'. Return true if so,
* else false. If 'thread' is non-NULL, the local thread number within the
* core is returned in it.
*/
bool __weak arch_find_n_match_cpu_physical_id(struct device_node *cpun,
int cpu, unsigned int *thread)
{
/* Check for non-standard "ibm,ppc-interrupt-server#s" property
* for thread ids on PowerPC. If it doesn't exist fallback to
* standard "reg" property.
*/
if (IS_ENABLED(CONFIG_PPC) &&
__of_find_n_match_cpu_property(cpun,
"ibm,ppc-interrupt-server#s",
cpu, thread))
return true;
return __of_find_n_match_cpu_property(cpun, "reg", cpu, thread);
}
/**
* of_get_cpu_node - Get device node associated with the given logical CPU
*
* @cpu: CPU number(logical index) for which device node is required
* @thread: if not NULL, local thread number within the physical core is
* returned
*
* The main purpose of this function is to retrieve the device node for the
* given logical CPU index. It should be used to initialize the of_node in
* cpu device. Once of_node in cpu device is populated, all the further
* references can use that instead.
*
* CPU logical to physical index mapping is architecture specific and is built
* before booting secondary cores. This function uses arch_match_cpu_phys_id
* which can be overridden by architecture specific implementation.
*
* Return: A node pointer for the logical cpu with refcount incremented, use
* of_node_put() on it when done. Returns NULL if not found.
*/
struct device_node *of_get_cpu_node(int cpu, unsigned int *thread)
{
struct device_node *cpun;
for_each_of_cpu_node(cpun) {
if (arch_find_n_match_cpu_physical_id(cpun, cpu, thread))
return cpun;
}
return NULL;
}
EXPORT_SYMBOL(of_get_cpu_node);
/**
* of_cpu_device_node_get: Get the CPU device_node for a given logical CPU number
*
* @cpu: The logical CPU number
*
* Return: Pointer to the device_node for CPU with its reference count
* incremented of the given logical CPU number or NULL if the CPU device_node
* is not found.
*/
struct device_node *of_cpu_device_node_get(int cpu)
{
struct device *cpu_dev;
cpu_dev = get_cpu_device(cpu);
if (!cpu_dev)
return of_get_cpu_node(cpu, NULL);
return of_node_get(cpu_dev->of_node);
}
EXPORT_SYMBOL(of_cpu_device_node_get);
/**
* of_cpu_node_to_id: Get the logical CPU number for a given device_node
*
* @cpu_node: Pointer to the device_node for CPU.
*
* Return: The logical CPU number of the given CPU device_node or -ENODEV if the
* CPU is not found.
*/
Annotation
- Immediate include surface: `linux/cpu.h`, `linux/kernel.h`, `linux/of.h`.
- Detected declarations: `function of_get_cpu_hwid`, `function arch_match_cpu_phys_id`, `function __of_find_n_match_cpu_property`, `function arch_find_n_match_cpu_physical_id`, `function of_node_put`, `function for_each_of_cpu_node`, `function of_cpu_node_to_id`, `function for_each_possible_cpu`, `export of_get_cpu_node`, `export of_cpu_device_node_get`.
- Atlas domain: Driver Families / drivers/of.
- 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.