drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c- Extension
.c- Size
- 97600 bytes
- Lines
- 3778
- 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/capability.hlinux/device.hlinux/err.hlinux/fs.hlinux/file.hlinux/overflow.hlinux/sched.hlinux/slab.hlinux/uaccess.hlinux/compat.huapi/linux/kfd_ioctl.hlinux/time.hlinux/mm.hlinux/mman.hlinux/ptrace.hlinux/dma-buf.hlinux/processor.hkfd_priv.hkfd_device_queue_manager.hkfd_svm.hamdgpu_amdkfd.hkfd_smi_events.hamdgpu_dma_buf.hkfd_debug.hamdgpu_ptl.h
Detected Declarations
function kfd_dev_unmap_mapping_rangefunction kfd_unlock_pddfunction kfd_chardev_initfunction kfd_chardev_exitfunction kfd_openfunction kfd_releasefunction kfd_ioctl_get_versionfunction set_queue_properties_from_userfunction kfd_ioctl_create_queuefunction kfd_ioctl_destroy_queuefunction kfd_ioctl_update_queuefunction kfd_ioctl_set_cu_maskfunction kfd_ioctl_get_queue_wave_statefunction kfd_ioctl_set_memory_policyfunction kfd_ioctl_set_trap_handlerfunction kfd_ioctl_dbg_registerfunction kfd_ioctl_dbg_unregisterfunction kfd_ioctl_dbg_address_watchfunction kfd_ioctl_dbg_wave_controlfunction kfd_ioctl_get_clock_countersfunction kfd_ioctl_get_process_aperturesfunction kfd_ioctl_get_process_apertures_newfunction kfd_ioctl_create_eventfunction kfd_ioctl_destroy_eventfunction kfd_ioctl_set_eventfunction kfd_ioctl_reset_eventfunction kfd_ioctl_wait_eventsfunction kfd_ioctl_set_scratch_backing_vafunction kfd_ioctl_get_tile_configfunction kfd_ioctl_acquire_vmfunction kfd_dev_is_large_barfunction kfd_ioctl_get_available_memoryfunction kfd_ioctl_alloc_memory_of_gpufunction interval_tree_iter_firstfunction interval_tree_iter_firstfunction kfd_ioctl_free_memory_of_gpufunction kfd_ioctl_map_memory_to_gpufunction kfd_ioctl_unmap_memory_from_gpufunction kfd_ioctl_alloc_queue_gwsfunction kfd_ioctl_get_dmabuf_infofunction kfd_ioctl_import_dmabuffunction kfd_ioctl_export_dmabuffunction kfd_ioctl_smi_eventsfunction kfd_ioctl_svm_validatefunction kfd_ioctl_set_xnack_modefunction kfd_ioctl_svmfunction kfd_ioctl_set_xnack_modefunction kfd_ioctl_svm
Annotated Snippet
static const struct file_operations kfd_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = kfd_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = kfd_open,
.release = kfd_release,
.mmap = kfd_mmap,
};
static int kfd_char_dev_major = -1;
struct device *kfd_device;
static const struct class kfd_class = {
.name = kfd_dev_name,
};
/*
* Cache the address space of the chardev on first open so that the reset
* path can drop all userspace mappings of doorbell and MMIO ranges via
* unmap_mapping_range().
*/
static struct address_space *kfd_dev_mapping;
void kfd_dev_unmap_mapping_range(loff_t const holebegin, loff_t const holelen)
{
struct address_space *mapping = READ_ONCE(kfd_dev_mapping);
if (mapping)
unmap_mapping_range(mapping, holebegin, holelen, 1);
}
static inline struct kfd_process_device *kfd_lock_pdd_by_id(struct kfd_process *p, __u32 gpu_id)
{
struct kfd_process_device *pdd;
mutex_lock(&p->mutex);
pdd = kfd_process_device_data_by_id(p, gpu_id);
if (pdd)
return pdd;
mutex_unlock(&p->mutex);
return NULL;
}
static inline void kfd_unlock_pdd(struct kfd_process_device *pdd)
{
mutex_unlock(&pdd->process->mutex);
}
int kfd_chardev_init(void)
{
int err = 0;
kfd_char_dev_major = register_chrdev(0, kfd_dev_name, &kfd_fops);
err = kfd_char_dev_major;
if (err < 0)
goto err_register_chrdev;
err = class_register(&kfd_class);
if (err)
goto err_class_create;
kfd_device = device_create(&kfd_class, NULL,
MKDEV(kfd_char_dev_major, 0),
NULL, kfd_dev_name);
err = PTR_ERR(kfd_device);
if (IS_ERR(kfd_device))
goto err_device_create;
return 0;
err_device_create:
class_unregister(&kfd_class);
err_class_create:
unregister_chrdev(kfd_char_dev_major, kfd_dev_name);
err_register_chrdev:
return err;
}
void kfd_chardev_exit(void)
{
device_destroy(&kfd_class, MKDEV(kfd_char_dev_major, 0));
class_unregister(&kfd_class);
unregister_chrdev(kfd_char_dev_major, kfd_dev_name);
kfd_device = NULL;
}
static int kfd_open(struct inode *inode, struct file *filep)
{
Annotation
- Immediate include surface: `linux/capability.h`, `linux/device.h`, `linux/err.h`, `linux/fs.h`, `linux/file.h`, `linux/overflow.h`, `linux/sched.h`, `linux/slab.h`.
- Detected declarations: `function kfd_dev_unmap_mapping_range`, `function kfd_unlock_pdd`, `function kfd_chardev_init`, `function kfd_chardev_exit`, `function kfd_open`, `function kfd_release`, `function kfd_ioctl_get_version`, `function set_queue_properties_from_user`, `function kfd_ioctl_create_queue`, `function kfd_ioctl_destroy_queue`.
- 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.