drivers/gpu/drm/panthor/panthor_devfreq.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/panthor/panthor_devfreq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/panthor/panthor_devfreq.c- Extension
.c- Size
- 8984 bytes
- Lines
- 335
- 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.
- 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/devfreq.hlinux/devfreq_cooling.hlinux/platform_device.hlinux/pm_opp.hdrm/drm_managed.hdrm/drm_print.hpanthor_devfreq.hpanthor_device.h
Detected Declarations
struct panthor_devfreqfunction panthor_devfreq_update_utilizationfunction panthor_devfreq_targetfunction panthor_devfreq_resetfunction panthor_devfreq_get_dev_statusfunction panthor_devfreq_get_cur_freqfunction panthor_devfreq_initfunction panthor_devfreq_resumefunction panthor_devfreq_suspendfunction panthor_devfreq_record_busyfunction panthor_devfreq_record_idlefunction panthor_devfreq_get_freq
Annotated Snippet
struct panthor_devfreq {
/** @devfreq: devfreq device. */
struct devfreq *devfreq;
/** @gov_data: Governor data. */
struct devfreq_simple_ondemand_data gov_data;
/** @busy_time: Busy time. */
ktime_t busy_time;
/** @idle_time: Idle time. */
ktime_t idle_time;
/** @time_last_update: Last update time. */
ktime_t time_last_update;
/** @last_busy_state: True if the GPU was busy last time we updated the state. */
bool last_busy_state;
/**
* @lock: Lock used to protect busy_time, idle_time, time_last_update and
* last_busy_state.
*
* These fields can be accessed concurrently by panthor_devfreq_get_dev_status()
* and panthor_devfreq_record_{busy,idle}().
*/
spinlock_t lock;
};
static void panthor_devfreq_update_utilization(struct panthor_devfreq *pdevfreq)
{
ktime_t now, last;
now = ktime_get();
last = pdevfreq->time_last_update;
if (pdevfreq->last_busy_state)
pdevfreq->busy_time += ktime_sub(now, last);
else
pdevfreq->idle_time += ktime_sub(now, last);
pdevfreq->time_last_update = now;
}
static int panthor_devfreq_target(struct device *dev, unsigned long *freq,
u32 flags)
{
struct dev_pm_opp *opp;
int err;
opp = devfreq_recommended_opp(dev, freq, flags);
if (IS_ERR(opp))
return PTR_ERR(opp);
dev_pm_opp_put(opp);
err = dev_pm_opp_set_rate(dev, *freq);
return err;
}
static void panthor_devfreq_reset(struct panthor_devfreq *pdevfreq)
{
pdevfreq->busy_time = 0;
pdevfreq->idle_time = 0;
pdevfreq->time_last_update = ktime_get();
}
static int panthor_devfreq_get_dev_status(struct device *dev,
struct devfreq_dev_status *status)
{
struct panthor_device *ptdev = dev_get_drvdata(dev);
struct panthor_devfreq *pdevfreq = ptdev->devfreq;
unsigned long irqflags;
status->current_frequency = clk_get_rate(ptdev->clks.core);
spin_lock_irqsave(&pdevfreq->lock, irqflags);
panthor_devfreq_update_utilization(pdevfreq);
status->total_time = ktime_to_ns(ktime_add(pdevfreq->busy_time,
pdevfreq->idle_time));
status->busy_time = ktime_to_ns(pdevfreq->busy_time);
panthor_devfreq_reset(pdevfreq);
spin_unlock_irqrestore(&pdevfreq->lock, irqflags);
drm_dbg(&ptdev->base, "busy %lu total %lu %lu %% freq %lu MHz\n",
Annotation
- Immediate include surface: `linux/clk.h`, `linux/devfreq.h`, `linux/devfreq_cooling.h`, `linux/platform_device.h`, `linux/pm_opp.h`, `drm/drm_managed.h`, `drm/drm_print.h`, `panthor_devfreq.h`.
- Detected declarations: `struct panthor_devfreq`, `function panthor_devfreq_update_utilization`, `function panthor_devfreq_target`, `function panthor_devfreq_reset`, `function panthor_devfreq_get_dev_status`, `function panthor_devfreq_get_cur_freq`, `function panthor_devfreq_init`, `function panthor_devfreq_resume`, `function panthor_devfreq_suspend`, `function panthor_devfreq_record_busy`.
- 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.