drivers/cpuidle/dt_idle_states.c
Source file repositories/reference/linux-study-clean/drivers/cpuidle/dt_idle_states.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cpuidle/dt_idle_states.c- Extension
.c- Size
- 6305 bytes
- Lines
- 221
- Domain
- Driver Families
- Bucket
- drivers/cpuidle
- 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/cpuidle.hlinux/cpumask.hlinux/errno.hlinux/kernel.hlinux/module.hlinux/of.hdt_idle_states.h
Detected Declarations
function Copyrightfunction idle_state_validfunction dt_init_idle_driverexport dt_init_idle_driver
Annotated Snippet
if (err) {
pr_debug(" * %pOF missing entry-latency-us property\n",
state_node);
return -EINVAL;
}
err = of_property_read_u32(state_node, "exit-latency-us",
&exit_latency);
if (err) {
pr_debug(" * %pOF missing exit-latency-us property\n",
state_node);
return -EINVAL;
}
/*
* If wakeup-latency-us is missing, default to entry+exit
* latencies as defined in idle states bindings
*/
idle_state->exit_latency = entry_latency + exit_latency;
}
err = of_property_read_u32(state_node, "min-residency-us",
&idle_state->target_residency);
if (err) {
pr_debug(" * %pOF missing min-residency-us property\n",
state_node);
return -EINVAL;
}
err = of_property_read_string(state_node, "idle-state-name", &desc);
if (err)
desc = state_node->name;
idle_state->flags = CPUIDLE_FLAG_RCU_IDLE;
if (of_property_read_bool(state_node, "local-timer-stop"))
idle_state->flags |= CPUIDLE_FLAG_TIMER_STOP;
/*
* TODO:
* replace with kstrdup and pointer assignment when name
* and desc become string pointers
*/
strscpy(idle_state->name, state_node->name, CPUIDLE_NAME_LEN);
strscpy(idle_state->desc, desc, CPUIDLE_DESC_LEN);
return 0;
}
/*
* Check that the idle state is uniform across all CPUs in the CPUidle driver
* cpumask
*/
static bool idle_state_valid(struct device_node *state_node, unsigned int idx,
const cpumask_t *cpumask)
{
int cpu;
struct device_node *cpu_node, *curr_state_node;
/*
* Compare idle state phandles for index idx on all CPUs in the
* CPUidle driver cpumask. Start from next logical cpu following
* cpumask_first(cpumask) since that's the CPU state_node was
* retrieved from. If a mismatch is found bail out straight
* away since we certainly hit a firmware misconfiguration.
*/
cpu = cpumask_first(cpumask) + 1;
for_each_cpu_from(cpu, cpumask) {
cpu_node = of_cpu_device_node_get(cpu);
curr_state_node = of_get_cpu_state_node(cpu_node, idx);
of_node_put(curr_state_node);
of_node_put(cpu_node);
if (state_node != curr_state_node)
return false;
}
return true;
}
/**
* dt_init_idle_driver() - Parse the DT idle states and initialize the
* idle driver states array
* @drv: Pointer to CPU idle driver to be initialized
* @matches: Array of of_device_id match structures to search in for
* compatible idle state nodes. The data pointer for each valid
* struct of_device_id entry in the matches array must point to
* a function with the following signature, that corresponds to
* the CPUidle state enter function signature:
*
* int (*)(struct cpuidle_device *dev,
* struct cpuidle_driver *drv,
* int index);
*
* @start_idx: First idle state index to be initialized
Annotation
- Immediate include surface: `linux/cpuidle.h`, `linux/cpumask.h`, `linux/errno.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `dt_idle_states.h`.
- Detected declarations: `function Copyright`, `function idle_state_valid`, `function dt_init_idle_driver`, `export dt_init_idle_driver`.
- Atlas domain: Driver Families / drivers/cpuidle.
- 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.