drivers/gpu/drm/drm_self_refresh_helper.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_self_refresh_helper.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_self_refresh_helper.c- Extension
.c- Size
- 8477 bytes
- Lines
- 283
- Domain
- Driver Families
- Bucket
- drivers/gpu
- 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/average.hlinux/bitops.hlinux/export.hlinux/slab.hlinux/workqueue.hdrm/drm_atomic.hdrm/drm_atomic_helper.hdrm/drm_connector.hdrm/drm_crtc.hdrm/drm_device.hdrm/drm_mode_config.hdrm/drm_modeset_lock.hdrm/drm_print.hdrm/drm_self_refresh_helper.h
Detected Declarations
struct drm_self_refresh_datafunction drm_self_refresh_helper_entry_workfunction for_each_new_connector_in_statefunction drm_self_refresh_helper_update_avg_timesfunction for_each_old_crtc_in_statefunction drm_self_refresh_helper_alter_statefunction for_each_new_crtc_in_statefunction drm_self_refresh_helper_initfunction drm_self_refresh_helper_cleanupexport drm_self_refresh_helper_update_avg_timesexport drm_self_refresh_helper_alter_stateexport drm_self_refresh_helper_initexport drm_self_refresh_helper_cleanup
Annotated Snippet
struct drm_self_refresh_data {
struct drm_crtc *crtc;
struct delayed_work entry_work;
struct mutex avg_mutex;
struct ewma_psr_time entry_avg_ms;
struct ewma_psr_time exit_avg_ms;
};
static void drm_self_refresh_helper_entry_work(struct work_struct *work)
{
struct drm_self_refresh_data *sr_data = container_of(
to_delayed_work(work),
struct drm_self_refresh_data, entry_work);
struct drm_crtc *crtc = sr_data->crtc;
struct drm_device *dev = crtc->dev;
struct drm_modeset_acquire_ctx ctx;
struct drm_atomic_commit *state;
struct drm_connector *conn;
struct drm_connector_state *conn_state;
struct drm_crtc_state *crtc_state;
int i, ret = 0;
drm_modeset_acquire_init(&ctx, 0);
state = drm_atomic_commit_alloc(dev);
if (!state) {
ret = -ENOMEM;
goto out_drop_locks;
}
retry:
state->acquire_ctx = &ctx;
crtc_state = drm_atomic_get_crtc_state(state, crtc);
if (IS_ERR(crtc_state)) {
ret = PTR_ERR(crtc_state);
goto out;
}
if (!crtc_state->enable)
goto out;
ret = drm_atomic_add_affected_connectors(state, crtc);
if (ret)
goto out;
for_each_new_connector_in_state(state, conn, conn_state, i) {
if (!conn_state->self_refresh_aware)
goto out;
}
crtc_state->active = false;
crtc_state->self_refresh_active = true;
ret = drm_atomic_commit(state);
if (ret)
goto out;
out:
if (ret == -EDEADLK) {
drm_atomic_commit_clear(state);
ret = drm_modeset_backoff(&ctx);
if (!ret)
goto retry;
}
drm_atomic_commit_put(state);
out_drop_locks:
drm_modeset_drop_locks(&ctx);
drm_modeset_acquire_fini(&ctx);
}
/**
* drm_self_refresh_helper_update_avg_times - Updates a crtc's SR time averages
* @state: the state which has just been applied to hardware
* @commit_time_ms: the amount of time in ms that this commit took to complete
* @new_self_refresh_mask: bitmask of crtc's that have self_refresh_active in
* new state
*
* Called after &drm_mode_config_funcs.atomic_commit_tail, this function will
* update the average entry/exit self refresh times on self refresh transitions.
* These averages will be used when calculating how long to delay before
* entering self refresh mode after activity.
*/
void
drm_self_refresh_helper_update_avg_times(struct drm_atomic_commit *state,
unsigned int commit_time_ms,
unsigned int new_self_refresh_mask)
Annotation
- Immediate include surface: `linux/average.h`, `linux/bitops.h`, `linux/export.h`, `linux/slab.h`, `linux/workqueue.h`, `drm/drm_atomic.h`, `drm/drm_atomic_helper.h`, `drm/drm_connector.h`.
- Detected declarations: `struct drm_self_refresh_data`, `function drm_self_refresh_helper_entry_work`, `function for_each_new_connector_in_state`, `function drm_self_refresh_helper_update_avg_times`, `function for_each_old_crtc_in_state`, `function drm_self_refresh_helper_alter_state`, `function for_each_new_crtc_in_state`, `function drm_self_refresh_helper_init`, `function drm_self_refresh_helper_cleanup`, `export drm_self_refresh_helper_update_avg_times`.
- Atlas domain: Driver Families / drivers/gpu.
- 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.