drivers/cpufreq/scpi-cpufreq.c
Source file repositories/reference/linux-study-clean/drivers/cpufreq/scpi-cpufreq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/cpufreq/scpi-cpufreq.c- Extension
.c- Size
- 5310 bytes
- Lines
- 235
- Domain
- Driver Families
- Bucket
- drivers/cpufreq
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/clk.hlinux/cpu.hlinux/cpufreq.hlinux/cpumask.hlinux/export.hlinux/module.hlinux/platform_device.hlinux/pm_opp.hlinux/scpi_protocol.hlinux/slab.hlinux/types.h
Detected Declarations
struct scpi_datafunction scpi_cpufreq_get_ratefunction scpi_cpufreq_set_targetfunction scpi_get_sharing_cpusfunction for_each_present_cpufunction scpi_cpufreq_initfunction scpi_cpufreq_exitfunction scpi_cpufreq_probefunction scpi_cpufreq_remove
Annotated Snippet
struct scpi_data {
struct clk *clk;
struct device *cpu_dev;
};
static struct scpi_ops *scpi_ops;
static unsigned int scpi_cpufreq_get_rate(unsigned int cpu)
{
struct cpufreq_policy *policy;
struct scpi_data *priv;
unsigned long rate;
policy = cpufreq_cpu_get_raw(cpu);
if (unlikely(!policy))
return 0;
priv = policy->driver_data;
rate = clk_get_rate(priv->clk);
return rate / 1000;
}
static int
scpi_cpufreq_set_target(struct cpufreq_policy *policy, unsigned int index)
{
unsigned long freq_khz = policy->freq_table[index].frequency;
struct scpi_data *priv = policy->driver_data;
unsigned long rate = freq_khz * 1000;
int ret;
ret = clk_set_rate(priv->clk, rate);
if (ret)
return ret;
if (clk_get_rate(priv->clk) / 1000 != freq_khz)
return -EIO;
return 0;
}
static int
scpi_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask)
{
int cpu, domain, tdomain;
struct device *tcpu_dev;
domain = scpi_ops->device_domain_id(cpu_dev);
if (domain < 0)
return domain;
for_each_present_cpu(cpu) {
if (cpu == cpu_dev->id)
continue;
tcpu_dev = get_cpu_device(cpu);
if (!tcpu_dev)
continue;
tdomain = scpi_ops->device_domain_id(tcpu_dev);
if (tdomain == domain)
cpumask_set_cpu(cpu, cpumask);
}
return 0;
}
static int scpi_cpufreq_init(struct cpufreq_policy *policy)
{
int ret;
unsigned int latency;
struct device *cpu_dev;
struct scpi_data *priv;
struct cpufreq_frequency_table *freq_table;
cpu_dev = get_cpu_device(policy->cpu);
if (!cpu_dev) {
pr_err("failed to get cpu%d device\n", policy->cpu);
return -ENODEV;
}
ret = scpi_ops->add_opps_to_device(cpu_dev);
if (ret) {
dev_warn(cpu_dev, "failed to add opps to the device\n");
return ret;
}
ret = scpi_get_sharing_cpus(cpu_dev, policy->cpus);
if (ret) {
Annotation
- Immediate include surface: `linux/clk.h`, `linux/cpu.h`, `linux/cpufreq.h`, `linux/cpumask.h`, `linux/export.h`, `linux/module.h`, `linux/platform_device.h`, `linux/pm_opp.h`.
- Detected declarations: `struct scpi_data`, `function scpi_cpufreq_get_rate`, `function scpi_cpufreq_set_target`, `function scpi_get_sharing_cpus`, `function for_each_present_cpu`, `function scpi_cpufreq_init`, `function scpi_cpufreq_exit`, `function scpi_cpufreq_probe`, `function scpi_cpufreq_remove`.
- Atlas domain: Driver Families / drivers/cpufreq.
- Implementation status: source 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.