drivers/gpu/drm/drm_damage_helper.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_damage_helper.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_damage_helper.c- Extension
.c- Size
- 10285 bytes
- Lines
- 337
- 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/export.hdrm/drm_atomic.hdrm/drm_damage_helper.hdrm/drm_device.hdrm/drm_framebuffer.h
Detected Declarations
function Copyrightfunction drm_atomic_helper_check_plane_damagefunction drm_atomic_helper_dirtyfbfunction drm_atomic_helper_check_plane_statefunction drm_atomic_helper_damage_iter_nextfunction drm_atomic_helper_damage_iter_nextexport drm_atomic_helper_check_plane_damageexport drm_atomic_helper_dirtyfbexport drm_atomic_helper_damage_iter_initexport drm_atomic_helper_damage_iter_nextexport drm_atomic_helper_damage_merged
Annotated Snippet
if (drm_atomic_crtc_needs_modeset(crtc_state)) {
drm_property_blob_put(plane_state->fb_damage_clips);
plane_state->fb_damage_clips = NULL;
}
}
}
EXPORT_SYMBOL(drm_atomic_helper_check_plane_damage);
/**
* drm_atomic_helper_dirtyfb - Helper for dirtyfb.
* @fb: DRM framebuffer.
* @file_priv: Drm file for the ioctl call.
* @flags: Dirty fb annotate flags.
* @color: Color for annotate fill.
* @clips: Dirty region.
* @num_clips: Count of clip in clips.
*
* A helper to implement &drm_framebuffer_funcs.dirty using damage interface
* during plane update. If num_clips is 0 then this helper will do a full plane
* update. This is the same behaviour expected by DIRTFB IOCTL.
*
* Note that this helper is blocking implementation. This is what current
* drivers and userspace expect in their DIRTYFB IOCTL implementation, as a way
* to rate-limit userspace and make sure its rendering doesn't get ahead of
* uploading new data too much.
*
* Return: Zero on success, negative errno on failure.
*/
int drm_atomic_helper_dirtyfb(struct drm_framebuffer *fb,
struct drm_file *file_priv, unsigned int flags,
unsigned int color, struct drm_clip_rect *clips,
unsigned int num_clips)
{
struct drm_modeset_acquire_ctx ctx;
struct drm_property_blob *damage = NULL;
struct drm_mode_rect *rects = NULL;
struct drm_atomic_commit *state;
struct drm_plane *plane;
int ret = 0;
/*
* When called from ioctl, we are interruptible, but not when called
* internally (ie. defio worker)
*/
drm_modeset_acquire_init(&ctx,
file_priv ? DRM_MODESET_ACQUIRE_INTERRUPTIBLE : 0);
state = drm_atomic_commit_alloc(fb->dev);
if (!state) {
ret = -ENOMEM;
goto out_drop_locks;
}
state->acquire_ctx = &ctx;
if (clips) {
uint32_t inc = 1;
if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY) {
inc = 2;
num_clips /= 2;
}
rects = kzalloc_objs(*rects, num_clips);
if (!rects) {
ret = -ENOMEM;
goto out;
}
convert_clip_rect_to_rect(clips, rects, num_clips, inc);
damage = drm_property_create_blob(fb->dev,
num_clips * sizeof(*rects),
rects);
if (IS_ERR(damage)) {
ret = PTR_ERR(damage);
damage = NULL;
goto out;
}
}
retry:
drm_for_each_plane(plane, fb->dev) {
struct drm_plane_state *plane_state;
ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
if (ret)
goto out;
if (plane->state->fb != fb) {
drm_modeset_unlock(&plane->mutex);
continue;
Annotation
- Immediate include surface: `linux/export.h`, `drm/drm_atomic.h`, `drm/drm_damage_helper.h`, `drm/drm_device.h`, `drm/drm_framebuffer.h`.
- Detected declarations: `function Copyright`, `function drm_atomic_helper_check_plane_damage`, `function drm_atomic_helper_dirtyfb`, `function drm_atomic_helper_check_plane_state`, `function drm_atomic_helper_damage_iter_next`, `function drm_atomic_helper_damage_iter_next`, `export drm_atomic_helper_check_plane_damage`, `export drm_atomic_helper_dirtyfb`, `export drm_atomic_helper_damage_iter_init`, `export drm_atomic_helper_damage_iter_next`.
- 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.