drivers/gpu/drm/vc4/vc4_gem.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/vc4/vc4_gem.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/vc4/vc4_gem.c- Extension
.c- Size
- 32766 bytes
- Lines
- 1295
- 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.
- 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/module.hlinux/platform_device.hlinux/pm_runtime.hlinux/device.hlinux/io.hlinux/sched/signal.hlinux/dma-fence-array.hdrm/drm_exec.hdrm/drm_print.hdrm/drm_syncobj.hvc4_drv.hvc4_regs.hvc4_trace.h
Detected Declarations
struct vc4_hang_statefunction filesfunction vc4_free_hang_statefunction vc4_get_hang_state_ioctlfunction vc4_save_hang_statefunction list_for_each_entryfunction vc4_resetfunction vc4_reset_workfunction vc4_hangcheck_elapsedfunction submit_clfunction vc4_wait_for_seqnofunction vc4_flush_cachesfunction vc4_flush_texture_cachesfunction vc4_submit_next_bin_jobfunction vc4_submit_next_render_jobfunction vc4_move_job_to_renderfunction vc4_attach_fencesfunction vc4_lock_bo_reservationsfunction vc4_queue_submitfunction vc4_cl_lookup_bosfunction vc4_get_bclfunction vc4_complete_execfunction vc4_job_handle_completedfunction vc4_job_done_workfunction vc4_wait_for_seqno_ioctl_helperfunction vc4_wait_seqno_ioctlfunction vc4_wait_bo_ioctlfunction vc4_submit_cl_ioctlfunction vc4_gem_initfunction vc4_gem_destroyfunction vc4_gem_madvise_ioctl
Annotated Snippet
struct vc4_hang_state {
struct drm_vc4_get_hang_state user_state;
u32 bo_count;
struct drm_gem_object **bo;
};
static void
vc4_free_hang_state(struct drm_device *dev, struct vc4_hang_state *state)
{
unsigned int i;
for (i = 0; i < state->user_state.bo_count; i++)
drm_gem_object_put(state->bo[i]);
kfree(state->bo);
kfree(state);
}
int
vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_vc4_get_hang_state *get_state = data;
struct drm_vc4_get_hang_state_bo *bo_state;
struct vc4_hang_state *kernel_state;
struct drm_vc4_get_hang_state *state;
struct vc4_dev *vc4 = to_vc4_dev(dev);
unsigned long irqflags;
u32 i;
int ret = 0;
if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
return -ENODEV;
if (!vc4->v3d) {
DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n");
return -ENODEV;
}
spin_lock_irqsave(&vc4->job_lock, irqflags);
kernel_state = vc4->hang_state;
if (!kernel_state) {
spin_unlock_irqrestore(&vc4->job_lock, irqflags);
return -ENOENT;
}
state = &kernel_state->user_state;
/* If the user's array isn't big enough, just return the
* required array size.
*/
if (get_state->bo_count < state->bo_count) {
get_state->bo_count = state->bo_count;
spin_unlock_irqrestore(&vc4->job_lock, irqflags);
return 0;
}
vc4->hang_state = NULL;
spin_unlock_irqrestore(&vc4->job_lock, irqflags);
/* Save the user's BO pointer, so we don't stomp it with the memcpy. */
state->bo = get_state->bo;
memcpy(get_state, state, sizeof(*state));
bo_state = kzalloc_objs(*bo_state, state->bo_count);
if (!bo_state) {
ret = -ENOMEM;
goto err_free;
}
for (i = 0; i < state->bo_count; i++) {
struct vc4_bo *vc4_bo = to_vc4_bo(kernel_state->bo[i]);
u32 handle;
ret = drm_gem_handle_create(file_priv, kernel_state->bo[i],
&handle);
if (ret) {
state->bo_count = i;
goto err_delete_handle;
}
bo_state[i].handle = handle;
bo_state[i].paddr = vc4_bo->base.dma_addr;
bo_state[i].size = vc4_bo->base.base.size;
}
if (copy_to_user(u64_to_user_ptr(get_state->bo),
bo_state,
state->bo_count * sizeof(*bo_state)))
ret = -EFAULT;
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_device.h`, `linux/pm_runtime.h`, `linux/device.h`, `linux/io.h`, `linux/sched/signal.h`, `linux/dma-fence-array.h`, `drm/drm_exec.h`.
- Detected declarations: `struct vc4_hang_state`, `function files`, `function vc4_free_hang_state`, `function vc4_get_hang_state_ioctl`, `function vc4_save_hang_state`, `function list_for_each_entry`, `function vc4_reset`, `function vc4_reset_work`, `function vc4_hangcheck_elapsed`, `function submit_cl`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.