drivers/gpu/drm/drm_debugfs_crc.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_debugfs_crc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_debugfs_crc.c- Extension
.c- Size
- 12097 bytes
- Lines
- 440
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/circ_buf.hlinux/ctype.hlinux/debugfs.hlinux/export.hlinux/poll.hlinux/uaccess.hdrm/drm_crtc.hdrm/drm_debugfs_crc.hdrm/drm_drv.hdrm/drm_print.hdrm_internal.h
Detected Declarations
function filesfunction crc_control_openfunction crc_control_writefunction crtc_crc_data_countfunction crtc_crc_cleanupfunction crtc_crc_openfunction crtc_crc_releasefunction crtc_crc_readfunction crtc_crc_pollfunction drm_debugfs_crtc_crc_addfunction drm_crtc_add_crc_entryexport drm_crtc_add_crc_entry
Annotated Snippet
static const struct file_operations drm_crtc_crc_control_fops = {
.owner = THIS_MODULE,
.open = crc_control_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
.write = crc_control_write
};
static int crtc_crc_data_count(struct drm_crtc_crc *crc)
{
assert_spin_locked(&crc->lock);
return CIRC_CNT(crc->head, crc->tail, DRM_CRC_ENTRIES_NR);
}
static void crtc_crc_cleanup(struct drm_crtc_crc *crc)
{
kfree(crc->entries);
crc->overflow = false;
crc->entries = NULL;
crc->head = 0;
crc->tail = 0;
crc->values_cnt = 0;
crc->opened = false;
}
static int crtc_crc_open(struct inode *inode, struct file *filep)
{
struct drm_crtc *crtc = inode->i_private;
struct drm_crtc_crc *crc = &crtc->crc;
struct drm_crtc_crc_entry *entries = NULL;
size_t values_cnt;
int ret = 0;
if (drm_drv_uses_atomic_modeset(crtc->dev)) {
ret = drm_modeset_lock_single_interruptible(&crtc->mutex);
if (ret)
return ret;
if (!crtc->state->active)
ret = -EIO;
drm_modeset_unlock(&crtc->mutex);
if (ret)
return ret;
}
ret = crtc->funcs->verify_crc_source(crtc, crc->source, &values_cnt);
if (ret)
return ret;
if (WARN_ON(values_cnt > DRM_MAX_CRC_NR))
return -EINVAL;
if (WARN_ON(values_cnt == 0))
return -EINVAL;
entries = kzalloc_objs(*entries, DRM_CRC_ENTRIES_NR);
if (!entries)
return -ENOMEM;
spin_lock_irq(&crc->lock);
if (!crc->opened) {
crc->opened = true;
crc->entries = entries;
crc->values_cnt = values_cnt;
} else {
ret = -EBUSY;
}
spin_unlock_irq(&crc->lock);
if (ret) {
kfree(entries);
return ret;
}
ret = crtc->funcs->set_crc_source(crtc, crc->source);
if (ret)
goto err;
return 0;
err:
spin_lock_irq(&crc->lock);
crtc_crc_cleanup(crc);
spin_unlock_irq(&crc->lock);
return ret;
}
static int crtc_crc_release(struct inode *inode, struct file *filep)
Annotation
- Immediate include surface: `linux/circ_buf.h`, `linux/ctype.h`, `linux/debugfs.h`, `linux/export.h`, `linux/poll.h`, `linux/uaccess.h`, `drm/drm_crtc.h`, `drm/drm_debugfs_crc.h`.
- Detected declarations: `function files`, `function crc_control_open`, `function crc_control_write`, `function crtc_crc_data_count`, `function crtc_crc_cleanup`, `function crtc_crc_open`, `function crtc_crc_release`, `function crtc_crc_read`, `function crtc_crc_poll`, `function drm_debugfs_crtc_crc_add`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.