drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c- Extension
.c- Size
- 24544 bytes
- Lines
- 945
- 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.
- 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
amdgpu_amdkfd.hamd_pcie.hamd_shared.hamdgpu.hamdgpu_gfx.hamdgpu_dma_buf.hdrm/ttm/ttm_tt.hlinux/module.hlinux/dma-buf.hamdgpu_xgmi.huapi/linux/kfd_ioctl.hamdgpu_ras.hamdgpu_umc.hamdgpu_reset.hkfd_priv.h
Detected Declarations
function amdgpu_amdkfd_initfunction amdgpu_amdkfd_finifunction amdgpu_amdkfd_device_probefunction amdgpu_doorbell_get_kfd_infofunction amdgpu_amdkfd_reset_workfunction amdgpu_amdkfd_drm_client_createfunction amdgpu_amdkfd_device_initfunction amdgpu_amdkfd_device_fini_swfunction amdgpu_amdkfd_interruptfunction amdgpu_amdkfd_teardown_processesfunction amdgpu_amdkfd_suspendfunction amdgpu_amdkfd_resumefunction amdgpu_amdkfd_suspend_processfunction amdgpu_amdkfd_resume_processfunction amdgpu_amdkfd_pre_resetfunction amdgpu_amdkfd_post_resetfunction amdgpu_amdkfd_gpu_resetfunction amdgpu_amdkfd_clear_kfd_mappingfunction amdgpu_amdkfd_alloc_kernel_memfunction amdgpu_amdkfd_free_kernel_memfunction amdgpu_amdkfd_alloc_gwsfunction amdgpu_amdkfd_free_gwsfunction amdgpu_amdkfd_get_fw_versionfunction amdgpu_amdkfd_get_local_mem_infofunction amdgpu_amdkfd_get_gpu_clock_counterfunction amdgpu_amdkfd_get_max_engine_clock_in_mhzfunction amdgpu_amdkfd_get_dmabuf_infofunction amdgpu_amdkfd_get_pcie_bandwidth_mbytesfunction amdgpu_amdkfd_submit_ibfunction amdgpu_amdkfd_set_compute_idlefunction amdgpu_amdkfd_is_kfd_vmidfunction amdgpu_amdkfd_have_atomics_supportfunction amdgpu_amdkfd_debug_mem_fencefunction amdgpu_amdkfd_is_fedfunction amdgpu_amdkfd_ras_pasid_poison_consumption_handlerfunction amdgpu_amdkfd_ras_poison_consumption_handlerfunction amdgpu_amdkfd_send_close_event_drain_irqfunction amdgpu_amdkfd_check_and_lock_kfdfunction amdgpu_amdkfd_unlock_kfdfunction amdgpu_amdkfd_xcp_memory_sizefunction amdgpu_amdkfd_unmap_hiqfunction amdgpu_amdkfd_stop_schedfunction amdgpu_amdkfd_start_schedfunction amdgpu_amdkfd_compute_activefunction amdgpu_amdkfd_config_sq_perfmon
Annotated Snippet
sizeof(u32)) {
*aperture_base = adev->doorbell.base;
*aperture_size = adev->doorbell.size;
*start_offset = adev->doorbell.num_kernel_doorbells * sizeof(u32);
} else {
*aperture_base = 0;
*aperture_size = 0;
*start_offset = 0;
}
}
static void amdgpu_amdkfd_reset_work(struct work_struct *work)
{
struct amdgpu_device *adev = container_of(work, struct amdgpu_device,
kfd.reset_work);
struct amdgpu_reset_context reset_context;
memset(&reset_context, 0, sizeof(reset_context));
reset_context.method = AMD_RESET_METHOD_NONE;
reset_context.reset_req_dev = adev;
reset_context.src = adev->enable_mes ?
AMDGPU_RESET_SRC_MES :
AMDGPU_RESET_SRC_HWS;
clear_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);
amdgpu_device_gpu_recover(adev, NULL, &reset_context);
}
static const struct drm_client_funcs kfd_client_funcs = {
.unregister = drm_client_release,
};
int amdgpu_amdkfd_drm_client_create(struct amdgpu_device *adev)
{
int ret;
if (!adev->kfd.init_complete || adev->kfd.client.dev)
return 0;
ret = drm_client_init(&adev->ddev, &adev->kfd.client, "kfd",
&kfd_client_funcs);
if (ret) {
dev_err(adev->dev, "Failed to init DRM client: %d\n",
ret);
return ret;
}
drm_client_register(&adev->kfd.client);
return 0;
}
void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
{
int i;
int last_valid_bit;
amdgpu_amdkfd_gpuvm_init_mem_limits();
if (adev->kfd.dev) {
struct kgd2kfd_shared_resources gpu_resources = {
.compute_vmid_bitmap =
((1 << AMDGPU_NUM_VMID) - 1) -
((1 << adev->vm_manager.first_kfd_vmid) - 1),
.num_pipe_per_mec = adev->gfx.mec.num_pipe_per_mec,
.num_queue_per_pipe = adev->gfx.mec.num_queue_per_pipe,
.gpuvm_size = min(adev->vm_manager.max_pfn
<< AMDGPU_GPU_PAGE_SHIFT,
AMDGPU_GMC_HOLE_START),
.drm_render_minor = adev_to_drm(adev)->render->index,
.sdma_doorbell_idx = adev->doorbell_index.sdma_engine,
.enable_mes = adev->enable_mes,
};
/* this is going to have a few of the MSBs set that we need to
* clear
*/
bitmap_complement(gpu_resources.cp_queue_bitmap,
adev->gfx.mec_bitmap[0].queue_bitmap,
AMDGPU_MAX_QUEUES);
/* According to linux/bitmap.h we shouldn't use bitmap_clear if
* nbits is not compile time constant
*/
last_valid_bit = 1 /* only first MEC can have compute queues */
* adev->gfx.mec.num_pipe_per_mec
* adev->gfx.mec.num_queue_per_pipe;
Annotation
- Immediate include surface: `amdgpu_amdkfd.h`, `amd_pcie.h`, `amd_shared.h`, `amdgpu.h`, `amdgpu_gfx.h`, `amdgpu_dma_buf.h`, `drm/ttm/ttm_tt.h`, `linux/module.h`.
- Detected declarations: `function amdgpu_amdkfd_init`, `function amdgpu_amdkfd_fini`, `function amdgpu_amdkfd_device_probe`, `function amdgpu_doorbell_get_kfd_info`, `function amdgpu_amdkfd_reset_work`, `function amdgpu_amdkfd_drm_client_create`, `function amdgpu_amdkfd_device_init`, `function amdgpu_amdkfd_device_fini_sw`, `function amdgpu_amdkfd_interrupt`, `function amdgpu_amdkfd_teardown_processes`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source 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.