drivers/gpu/drm/msm/msm_gpu_devfreq.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/msm/msm_gpu_devfreq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/msm/msm_gpu_devfreq.c- Extension
.c- Size
- 8990 bytes
- Lines
- 376
- Domain
- Driver Families
- Bucket
- drivers/gpu
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
msm_gpu.hmsm_gpu_trace.hlinux/devfreq.hlinux/devfreq_cooling.hlinux/math64.hlinux/units.h
Detected Declarations
function Copyrightfunction freqfunction get_freqfunction msm_devfreq_get_dev_statusfunction msm_devfreq_get_cur_freqfunction has_devfreqfunction msm_devfreq_initfunction cancel_idle_workfunction cancel_boost_workfunction msm_devfreq_cleanupfunction msm_devfreq_resumefunction msm_devfreq_suspendfunction msm_devfreq_boost_workfunction msm_devfreq_boostfunction msm_devfreq_activefunction msm_devfreq_idle_workfunction msm_devfreq_idle
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2013 Red Hat
* Author: Rob Clark <robdclark@gmail.com>
*/
#include "msm_gpu.h"
#include "msm_gpu_trace.h"
#include <linux/devfreq.h>
#include <linux/devfreq_cooling.h>
#include <linux/math64.h>
#include <linux/units.h>
/*
* Power Management:
*/
static int msm_devfreq_target(struct device *dev, unsigned long *freq,
u32 flags)
{
struct msm_gpu *gpu = dev_to_gpu(dev);
struct msm_gpu_devfreq *df = &gpu->devfreq;
struct dev_pm_opp *opp;
/*
* Note that devfreq_recommended_opp() can modify the freq
* to something that actually is in the opp table:
*/
opp = devfreq_recommended_opp(dev, freq, flags);
if (IS_ERR(opp))
return PTR_ERR(opp);
trace_msm_gpu_freq_change(dev_pm_opp_get_freq(opp));
/*
* If the GPU is idle, devfreq is not aware, so just stash
* the new target freq (to use when we return to active)
*/
if (df->idle_freq) {
df->idle_freq = *freq;
dev_pm_opp_put(opp);
return 0;
}
if (gpu->funcs->gpu_set_freq) {
mutex_lock(&df->lock);
gpu->funcs->gpu_set_freq(gpu, opp, df->suspended);
mutex_unlock(&df->lock);
} else {
dev_pm_opp_set_rate(dev, *freq);
}
dev_pm_opp_put(opp);
return 0;
}
static unsigned long get_freq(struct msm_gpu *gpu)
{
struct msm_gpu_devfreq *df = &gpu->devfreq;
/*
* If the GPU is idle, use the shadow/saved freq to avoid
* confusing devfreq (which is unaware that we are switching
* to lowest freq until the device is active again)
*/
if (df->idle_freq)
return df->idle_freq;
if (gpu->funcs->gpu_get_freq)
return gpu->funcs->gpu_get_freq(gpu);
return clk_get_rate(gpu->core_clk);
}
static int msm_devfreq_get_dev_status(struct device *dev,
struct devfreq_dev_status *status)
{
struct msm_gpu *gpu = dev_to_gpu(dev);
struct msm_gpu_devfreq *df = &gpu->devfreq;
u64 busy_cycles, busy_time;
unsigned long sample_rate;
ktime_t time;
mutex_lock(&df->lock);
status->current_frequency = get_freq(gpu);
time = ktime_get();
status->total_time = ktime_us_delta(time, df->time);
Annotation
- Immediate include surface: `msm_gpu.h`, `msm_gpu_trace.h`, `linux/devfreq.h`, `linux/devfreq_cooling.h`, `linux/math64.h`, `linux/units.h`.
- Detected declarations: `function Copyright`, `function freq`, `function get_freq`, `function msm_devfreq_get_dev_status`, `function msm_devfreq_get_cur_freq`, `function has_devfreq`, `function msm_devfreq_init`, `function cancel_idle_work`, `function cancel_boost_work`, `function msm_devfreq_cleanup`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.