drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c- Extension
.c- Size
- 45428 bytes
- Lines
- 1812
- 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/file.hlinux/pagemap.hlinux/sync_file.hlinux/dma-buf.hdrm/amdgpu_drm.hdrm/drm_syncobj.hdrm/ttm/ttm_tt.hamdgpu_cs.hamdgpu.hamdgpu_trace.hamdgpu_gmc.hamdgpu_gem.hamdgpu_ras.hamdgpu_hmm.h
Detected Declarations
function filesfunction amdgpu_cs_job_idxfunction amdgpu_cs_p1_ibfunction amdgpu_cs_p1_user_fencefunction amdgpu_cs_p1_bo_handlesfunction amdgpu_cs_pass1function amdgpu_cs_p2_ibfunction amdgpu_cs_p2_dependenciesfunction amdgpu_syncobj_lookup_and_addfunction amdgpu_cs_p2_syncobj_infunction amdgpu_cs_p2_syncobj_timeline_waitfunction amdgpu_cs_p2_syncobj_outfunction amdgpu_cs_p2_syncobj_timeline_signalfunction amdgpu_cs_p2_shadowfunction amdgpu_cs_pass2function us_to_bytesfunction bytes_to_usfunction sizefunction amdgpu_cs_report_moved_bytesfunction amdgpu_cs_bo_validatefunction list_emptyfunction amdgpu_cs_parser_bosfunction amdgpu_gem_userptr_ioctlfunction drm_exec_until_all_lockedfunction amdgpu_bo_list_for_each_entryfunction amdgpu_bo_list_for_each_userptr_entryfunction drm_exec_for_each_locked_objectfunction trace_amdgpu_cs_ibsfunction amdgpu_cs_patch_ibsfunction amdgpu_cs_patch_jobsfunction amdgpu_cs_vm_handlingfunction amdgpu_cs_sync_ringsfunction drm_exec_for_each_locked_objectfunction amdgpu_cs_post_dependenciesfunction amdgpu_cs_submitfunction amdgpu_cs_parser_finifunction amdgpu_cs_ioctlfunction amdgpu_cs_wait_ioctlfunction amdgpu_cs_fence_to_handle_ioctlfunction amdgpu_cs_wait_all_fencesfunction amdgpu_cs_wait_any_fencefunction amdgpu_cs_wait_fences_ioctlfunction amdgpu_cs_find_mapping
Annotated Snippet
sizeof(struct drm_amdgpu_cs_chunk))) {
ret = -EFAULT;
i--;
goto free_partial_kdata;
}
p->chunks[i].chunk_id = user_chunk.chunk_id;
p->chunks[i].length_dw = user_chunk.length_dw;
size = p->chunks[i].length_dw;
p->chunks[i].kdata = vmemdup_array_user(u64_to_user_ptr(user_chunk.chunk_data),
size,
sizeof(uint32_t));
if (IS_ERR(p->chunks[i].kdata)) {
ret = PTR_ERR(p->chunks[i].kdata);
i--;
goto free_partial_kdata;
}
size *= sizeof(uint32_t);
/* Assume the worst on the following checks */
ret = -EINVAL;
switch (p->chunks[i].chunk_id) {
case AMDGPU_CHUNK_ID_IB:
if (size < sizeof(struct drm_amdgpu_cs_chunk_ib))
goto free_partial_kdata;
ret = amdgpu_cs_p1_ib(p, p->chunks[i].kdata, num_ibs);
if (ret)
goto free_partial_kdata;
break;
case AMDGPU_CHUNK_ID_FENCE:
if (size < sizeof(struct drm_amdgpu_cs_chunk_fence))
goto free_partial_kdata;
ret = amdgpu_cs_p1_user_fence(p, p->chunks[i].kdata,
&uf_offset);
if (ret)
goto free_partial_kdata;
break;
case AMDGPU_CHUNK_ID_BO_HANDLES:
if (size < sizeof(struct drm_amdgpu_bo_list_in))
goto free_partial_kdata;
/* Only a single BO list is allowed to simplify handling. */
if (p->bo_list)
goto free_partial_kdata;
ret = amdgpu_cs_p1_bo_handles(p, p->chunks[i].kdata);
if (ret)
goto free_partial_kdata;
break;
case AMDGPU_CHUNK_ID_DEPENDENCIES:
case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES:
case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
case AMDGPU_CHUNK_ID_CP_GFX_SHADOW:
break;
default:
goto free_partial_kdata;
}
}
if (!p->gang_size || (amdgpu_sriov_vf(p->adev) && p->gang_size > 1)) {
ret = -EINVAL;
goto free_all_kdata;
}
for (i = 0; i < p->gang_size; ++i) {
ret = amdgpu_job_alloc(p->adev, vm, p->entities[i], vm,
num_ibs[i], &p->jobs[i],
p->filp->client_id);
if (ret)
goto free_all_kdata;
switch (p->adev->enforce_isolation[fpriv->xcp_id]) {
case AMDGPU_ENFORCE_ISOLATION_DISABLE:
default:
p->jobs[i]->enforce_isolation = false;
p->jobs[i]->run_cleaner_shader = false;
break;
case AMDGPU_ENFORCE_ISOLATION_ENABLE:
p->jobs[i]->enforce_isolation = true;
p->jobs[i]->run_cleaner_shader = true;
break;
Annotation
- Immediate include surface: `linux/file.h`, `linux/pagemap.h`, `linux/sync_file.h`, `linux/dma-buf.h`, `drm/amdgpu_drm.h`, `drm/drm_syncobj.h`, `drm/ttm/ttm_tt.h`, `amdgpu_cs.h`.
- Detected declarations: `function files`, `function amdgpu_cs_job_idx`, `function amdgpu_cs_p1_ib`, `function amdgpu_cs_p1_user_fence`, `function amdgpu_cs_p1_bo_handles`, `function amdgpu_cs_pass1`, `function amdgpu_cs_p2_ib`, `function amdgpu_cs_p2_dependencies`, `function amdgpu_syncobj_lookup_and_add`, `function amdgpu_cs_p2_syncobj_in`.
- 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.