drivers/devfreq/devfreq.c
Source file repositories/reference/linux-study-clean/drivers/devfreq/devfreq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/devfreq/devfreq.c- Extension
.c- Size
- 58911 bytes
- Lines
- 2301
- Domain
- Driver Families
- Bucket
- drivers/devfreq
- 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/kmod.hlinux/sched.hlinux/debugfs.hlinux/devfreq_cooling.hlinux/errno.hlinux/err.hlinux/init.hlinux/export.hlinux/slab.hlinux/stat.hlinux/pm_opp.hlinux/devfreq.hlinux/devfreq-governor.hlinux/workqueue.hlinux/platform_device.hlinux/list.hlinux/printk.hlinux/hrtimer.hlinux/of.hlinux/pm_qos.hlinux/units.htrace/events/devfreq.h
Detected Declarations
struct devfreq_notifier_devresfunction find_device_devfreqfunction list_for_each_entryfunction find_available_min_freqfunction find_available_max_freqfunction devfreq_get_freq_rangefunction devfreq_get_freq_levelfunction set_freq_tablefunction devfreq_update_statusfunction find_devfreq_governorfunction list_for_each_entryfunction try_then_request_governorfunction devfreq_notify_transitionfunction devfreq_set_targetfunction devfreq_update_targetfunction update_devfreqfunction devfreq_monitorfunction devfreq_monitor_startfunction devfreq_monitor_stopfunction devfreq_monitor_suspendfunction devfreq_monitor_resumefunction devfreq_update_intervalfunction devfreq_notifier_callfunction qos_notifier_callfunction qos_min_notifier_callfunction qos_max_notifier_callfunction devfreq_dev_releasefunction devfreq_add_devicefunction devfreq_remove_devicefunction devm_devfreq_dev_matchfunction devm_devfreq_dev_releasefunction devm_devfreq_add_devicefunction devm_devfreq_remove_devicefunction devfreq_suspend_devicefunction devfreq_resume_devicefunction devfreq_suspendfunction devfreq_resumefunction devfreq_add_governorfunction list_for_each_entryfunction devm_devfreq_remove_governorfunction devm_devfreq_add_governorfunction devfreq_remove_governorfunction name_showfunction governor_showfunction governor_storefunction available_governors_showfunction governorfunction list_for_each_entry
Annotated Snippet
* device_add and dev_pm_qos_add_request
*/
if (!dev_pm_qos_request_active(&df->user_min_freq_req))
return -EAGAIN;
ret = sscanf(buf, "%lu", &value);
if (ret != 1)
return -EINVAL;
/* Round down to kHz for PM QoS */
ret = dev_pm_qos_update_request(&df->user_min_freq_req,
value / HZ_PER_KHZ);
if (ret < 0)
return ret;
return count;
}
static ssize_t min_freq_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct devfreq *df = to_devfreq(dev);
unsigned long min_freq, max_freq;
mutex_lock(&df->lock);
devfreq_get_freq_range(df, &min_freq, &max_freq);
mutex_unlock(&df->lock);
return sprintf(buf, "%lu\n", min_freq);
}
static DEVICE_ATTR_RW(min_freq);
static ssize_t max_freq_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
struct devfreq *df = to_devfreq(dev);
unsigned long value;
int ret;
/*
* Protect against theoretical sysfs writes between
* device_add and dev_pm_qos_add_request
*/
if (!dev_pm_qos_request_active(&df->user_max_freq_req))
return -EINVAL;
ret = sscanf(buf, "%lu", &value);
if (ret != 1)
return -EINVAL;
/*
* PM QoS frequencies are in kHz so we need to convert. Convert by
* rounding upwards so that the acceptable interval never shrinks.
*
* For example if the user writes "666666666" to sysfs this value will
* be converted to 666667 kHz and back to 666667000 Hz before an OPP
* lookup, this ensures that an OPP of 666666666Hz is still accepted.
*
* A value of zero means "no limit".
*/
if (value)
value = DIV_ROUND_UP(value, HZ_PER_KHZ);
else
value = PM_QOS_MAX_FREQUENCY_DEFAULT_VALUE;
ret = dev_pm_qos_update_request(&df->user_max_freq_req, value);
if (ret < 0)
return ret;
return count;
}
static ssize_t max_freq_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
struct devfreq *df = to_devfreq(dev);
unsigned long min_freq, max_freq;
mutex_lock(&df->lock);
devfreq_get_freq_range(df, &min_freq, &max_freq);
mutex_unlock(&df->lock);
return sprintf(buf, "%lu\n", max_freq);
}
static DEVICE_ATTR_RW(max_freq);
static ssize_t available_frequencies_show(struct device *d,
struct device_attribute *attr,
char *buf)
{
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/kmod.h`, `linux/sched.h`, `linux/debugfs.h`, `linux/devfreq_cooling.h`, `linux/errno.h`, `linux/err.h`, `linux/init.h`.
- Detected declarations: `struct devfreq_notifier_devres`, `function find_device_devfreq`, `function list_for_each_entry`, `function find_available_min_freq`, `function find_available_max_freq`, `function devfreq_get_freq_range`, `function devfreq_get_freq_level`, `function set_freq_table`, `function devfreq_update_status`, `function find_devfreq_governor`.
- Atlas domain: Driver Families / drivers/devfreq.
- 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.