drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c- Extension
.c- Size
- 59741 bytes
- Lines
- 2003
- 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
amdgpu.hdrm/amdgpu_drm.hdrm/drm_drv.hdrm/drm_fb_helper.hamdgpu_uvd.hamdgpu_vce.hatom.hlinux/vga_switcheroo.hlinux/slab.hlinux/uaccess.hlinux/pci.hlinux/pm_runtime.hamdgpu_amdkfd.hamdgpu_gem.hamdgpu_display.hamdgpu_ras.hamdgpu_reset.hamd_pcie.hamdgpu_userq.h
Detected Declarations
function filesfunction KMSfunction amdgpu_register_gpu_instancefunction KMSfunction amdgpu_ip_get_block_typefunction amdgpu_firmware_infofunction amdgpu_userq_metadata_info_gfxfunction amdgpu_userq_metadata_info_computefunction amdgpu_userq_metadata_info_sdmafunction amdgpu_hw_ip_infofunction amdgpu_info_ioctlfunction amdgpu_driver_open_kmsfunction amdgpu_driver_postclose_kmsfunction amdgpu_driver_release_kmsfunction crtcfunction crtcfunction crtcfunction amdgpu_debugfs_firmware_info_showfunction amdgpu_debugfs_firmware_init
Annotated Snippet
if (gpu_instance->adev == adev) {
mgpu_info.gpu_ins[i] =
mgpu_info.gpu_ins[mgpu_info.num_gpu - 1];
mgpu_info.num_gpu--;
if (adev->flags & AMD_IS_APU)
mgpu_info.num_apu--;
else
mgpu_info.num_dgpu--;
break;
}
}
mutex_unlock(&mgpu_info.mutex);
}
/**
* amdgpu_driver_unload_kms - Main unload function for KMS.
*
* @dev: drm dev pointer
*
* This is the main unload function for KMS (all asics).
* Returns 0 on success.
*/
void amdgpu_driver_unload_kms(struct drm_device *dev)
{
struct amdgpu_device *adev = drm_to_adev(dev);
if (adev == NULL || !adev->num_ip_blocks)
return;
amdgpu_unregister_gpu_instance(adev);
if (adev->rmmio == NULL)
return;
if (amdgpu_acpi_smart_shift_update(adev, AMDGPU_SS_DRV_UNLOAD))
drm_warn(dev, "smart shift update failed\n");
amdgpu_acpi_fini(adev);
amdgpu_device_fini_hw(adev);
}
void amdgpu_register_gpu_instance(struct amdgpu_device *adev)
{
struct amdgpu_gpu_instance *gpu_instance;
mutex_lock(&mgpu_info.mutex);
if (mgpu_info.num_gpu >= MAX_GPU_INSTANCE) {
drm_err(adev_to_drm(adev), "Cannot register more gpu instance\n");
mutex_unlock(&mgpu_info.mutex);
return;
}
gpu_instance = &(mgpu_info.gpu_ins[mgpu_info.num_gpu]);
gpu_instance->adev = adev;
gpu_instance->mgpu_fan_enabled = 0;
mgpu_info.num_gpu++;
if (adev->flags & AMD_IS_APU)
mgpu_info.num_apu++;
else
mgpu_info.num_dgpu++;
mutex_unlock(&mgpu_info.mutex);
}
/**
* amdgpu_driver_load_kms - Main load function for KMS.
*
* @adev: pointer to struct amdgpu_device
* @flags: device flags
*
* This is the main load function for KMS (all asics).
* Returns 0 on success, error on failure.
*/
int amdgpu_driver_load_kms(struct amdgpu_device *adev, unsigned long flags)
{
struct drm_device *dev;
int r, acpi_status;
dev = adev_to_drm(adev);
/* amdgpu_device_init should report only fatal error
* like memory allocation failure or iomapping failure,
* or memory manager initialization failure, it must
* properly initialize the GPU MC controller and permit
* VRAM allocation
*/
r = amdgpu_device_init(adev, flags);
Annotation
- Immediate include surface: `amdgpu.h`, `drm/amdgpu_drm.h`, `drm/drm_drv.h`, `drm/drm_fb_helper.h`, `amdgpu_uvd.h`, `amdgpu_vce.h`, `atom.h`, `linux/vga_switcheroo.h`.
- Detected declarations: `function files`, `function KMS`, `function amdgpu_register_gpu_instance`, `function KMS`, `function amdgpu_ip_get_block_type`, `function amdgpu_firmware_info`, `function amdgpu_userq_metadata_info_gfx`, `function amdgpu_userq_metadata_info_compute`, `function amdgpu_userq_metadata_info_sdma`, `function amdgpu_hw_ip_info`.
- 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.