drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c- Extension
.c- Size
- 106247 bytes
- Lines
- 3943
- 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/ratelimit.hlinux/printk.hlinux/slab.hlinux/list.hlinux/types.hlinux/bitops.hlinux/sched.hkfd_priv.hkfd_device_queue_manager.hkfd_mqd_manager.hcik_regs.hkfd_kernel_queue.hamdgpu_amdkfd.hamdgpu_reset.hamdgpu_sdma.hmes_v11_api_def.hkfd_debug.h
Detected Declarations
struct copy_context_work_handler_workareafunction get_mqd_type_from_queue_typefunction is_pipe_enabledfunction get_cp_queues_numfunction get_queues_per_pipefunction get_pipes_per_mecfunction get_num_all_sdma_enginesfunction get_num_sdma_queuesfunction get_num_xgmi_sdma_queuesfunction init_sdma_bitmapsfunction program_sh_mem_settingsfunction kfd_hws_hangfunction list_for_each_entryfunction convert_to_mes_queue_typefunction add_queue_mesfunction remove_queue_mes_on_reset_optionfunction set_perfcountfunction list_for_each_entryfunction remove_queue_mesfunction remove_all_kfd_queues_mesfunction list_for_each_entryfunction list_for_each_entryfunction add_all_kfd_queues_mesfunction list_for_each_entryfunction list_for_each_entryfunction reset_queues_mesfunction suspend_all_queues_mesfunction resume_all_queues_mesfunction increment_queue_countfunction decrement_queue_countfunction allocate_doorbellfunction deallocate_doorbellfunction program_trap_handler_settingsfunction allocate_vmidfunction flush_texture_cache_nocpschfunction deallocate_vmidfunction create_queue_nocpschfunction allocate_hqdfunction deallocate_hqdfunction dbgdev_wave_reset_wavefrontsfunction destroy_queue_nocpsch_lockedfunction destroy_queue_nocpschfunction update_queuefunction suspend_single_queuefunction resume_single_queuefunction evict_process_queues_nocpschfunction evict_process_queues_cpschfunction restore_process_queues_nocpsch
Annotated Snippet
struct copy_context_work_handler_workarea {
struct work_struct copy_context_work;
struct kfd_process *p;
};
static void copy_context_work_handler(struct work_struct *work)
{
struct copy_context_work_handler_workarea *workarea;
struct mqd_manager *mqd_mgr;
struct queue *q;
struct mm_struct *mm;
struct kfd_process *p;
uint32_t tmp_ctl_stack_used_size, tmp_save_area_used_size;
int i;
workarea = container_of(work,
struct copy_context_work_handler_workarea,
copy_context_work);
p = workarea->p;
mm = get_task_mm(p->lead_thread);
if (!mm)
return;
kthread_use_mm(mm);
for (i = 0; i < p->n_pdds; i++) {
struct kfd_process_device *pdd = p->pdds[i];
struct device_queue_manager *dqm = pdd->dev->dqm;
struct qcm_process_device *qpd = &pdd->qpd;
list_for_each_entry(q, &qpd->queues_list, list) {
if (q->properties.type != KFD_QUEUE_TYPE_COMPUTE)
continue;
mqd_mgr = dqm->mqd_mgrs[KFD_MQD_TYPE_CP];
/* We ignore the return value from get_wave_state
* because
* i) right now, it always returns 0, and
* ii) if we hit an error, we would continue to the
* next queue anyway.
*/
mqd_mgr->get_wave_state(mqd_mgr,
q->mqd,
&q->properties,
(void __user *) q->properties.ctx_save_restore_area_address,
&tmp_ctl_stack_used_size,
&tmp_save_area_used_size);
}
}
kthread_unuse_mm(mm);
mmput(mm);
}
static uint32_t *get_queue_ids(uint32_t num_queues, uint32_t *usr_queue_id_array)
{
if (!usr_queue_id_array)
return num_queues ? ERR_PTR(-EINVAL) : NULL;
if (num_queues > KFD_MAX_NUM_OF_QUEUES_PER_PROCESS)
return ERR_PTR(-EINVAL);
return memdup_user(usr_queue_id_array,
array_size(num_queues, sizeof(uint32_t)));
}
int resume_queues(struct kfd_process *p,
uint32_t num_queues,
uint32_t *usr_queue_id_array)
{
uint32_t *queue_ids = NULL;
int total_resumed = 0;
int i;
if (usr_queue_id_array) {
queue_ids = get_queue_ids(num_queues, usr_queue_id_array);
if (IS_ERR(queue_ids))
return PTR_ERR(queue_ids);
/* mask all queues as invalid. unmask per successful request */
q_array_invalidate(num_queues, queue_ids);
}
for (i = 0; i < p->n_pdds; i++) {
struct kfd_process_device *pdd = p->pdds[i];
struct device_queue_manager *dqm = pdd->dev->dqm;
struct device *dev = dqm->dev->adev->dev;
struct qcm_process_device *qpd = &pdd->qpd;
Annotation
- Immediate include surface: `linux/ratelimit.h`, `linux/printk.h`, `linux/slab.h`, `linux/list.h`, `linux/types.h`, `linux/bitops.h`, `linux/sched.h`, `kfd_priv.h`.
- Detected declarations: `struct copy_context_work_handler_workarea`, `function get_mqd_type_from_queue_type`, `function is_pipe_enabled`, `function get_cp_queues_num`, `function get_queues_per_pipe`, `function get_pipes_per_mec`, `function get_num_all_sdma_engines`, `function get_num_sdma_queues`, `function get_num_xgmi_sdma_queues`, `function init_sdma_bitmaps`.
- 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.