drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c- Extension
.c- Size
- 26606 bytes
- Lines
- 979
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/dma-mapping.hdrm/ttm/ttm_range_manager.hdrm/drm_drv.hdrm/drm_buddy.hamdgpu.hamdgpu_vm.hamdgpu_res_cursor.hatom.h
Detected Declarations
struct amdgpu_vram_reservationfunction to_vram_mgrfunction to_amdgpu_devicefunction amdgpu_vram_mgr_first_blockfunction amdgpu_is_vram_mgr_blocks_contiguousfunction amdgpu_vram_mgr_blocks_sizefunction amdgpu_mem_info_vram_total_showfunction amdgpu_mem_info_vis_vram_total_showfunction amdgpu_mem_info_vram_used_showfunction amdgpu_mem_info_vis_vram_used_showfunction amdgpu_mem_info_vram_vendorfunction amdgpu_vram_attrs_is_visiblefunction amdgpu_vram_mgr_vis_sizefunction amdgpu_vram_mgr_bo_visible_sizefunction amdgpu_vram_mgr_do_reservefunction list_for_each_entry_safefunction amdgpu_vram_mgr_reserve_rangefunction amdgpu_vram_mgr_query_page_statusfunction list_for_each_entryfunction list_for_each_entryfunction amdgpu_vram_mgr_query_address_block_infofunction list_for_each_entryfunction amdgpu_vram_mgr_newfunction amdgpu_vram_mgr_delfunction amdgpu_vram_mgr_alloc_sgtfunction amdgpu_vram_mgr_free_sgtfunction amdgpu_vram_mgr_vis_usagefunction amdgpu_vram_mgr_clear_reset_blocksfunction amdgpu_vram_mgr_intersectsfunction amdgpu_vram_mgr_compatiblefunction amdgpu_vram_mgr_debugfunction amdgpu_vram_mgr_initfunction amdgpu_vram_mgr_finifunction list_for_each_entry_safe
Annotated Snippet
struct amdgpu_vram_reservation {
u64 start;
u64 size;
struct list_head allocated;
struct list_head blocks;
};
static inline struct amdgpu_vram_mgr *
to_vram_mgr(struct ttm_resource_manager *man)
{
return container_of(man, struct amdgpu_vram_mgr, manager);
}
static inline struct amdgpu_device *
to_amdgpu_device(struct amdgpu_vram_mgr *mgr)
{
return container_of(mgr, struct amdgpu_device, mman.vram_mgr);
}
static inline struct gpu_buddy_block *
amdgpu_vram_mgr_first_block(struct list_head *list)
{
return list_first_entry_or_null(list, struct gpu_buddy_block, link);
}
static inline bool amdgpu_is_vram_mgr_blocks_contiguous(struct list_head *head)
{
struct gpu_buddy_block *block;
u64 start, size;
block = amdgpu_vram_mgr_first_block(head);
if (!block)
return false;
while (head != block->link.next) {
start = amdgpu_vram_mgr_block_start(block);
size = amdgpu_vram_mgr_block_size(block);
block = list_entry(block->link.next, struct gpu_buddy_block, link);
if (start + size != amdgpu_vram_mgr_block_start(block))
return false;
}
return true;
}
static inline u64 amdgpu_vram_mgr_blocks_size(struct list_head *head)
{
struct gpu_buddy_block *block;
u64 size = 0;
list_for_each_entry(block, head, link)
size += amdgpu_vram_mgr_block_size(block);
return size;
}
/**
* DOC: mem_info_vram_total
*
* The amdgpu driver provides a sysfs API for reporting current total VRAM
* available on the device
* The file mem_info_vram_total is used for this and returns the total
* amount of VRAM in bytes
*/
static ssize_t amdgpu_mem_info_vram_total_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = drm_to_adev(ddev);
return sysfs_emit(buf, "%llu\n", adev->gmc.real_vram_size);
}
/**
* DOC: mem_info_vis_vram_total
*
* The amdgpu driver provides a sysfs API for reporting current total
* visible VRAM available on the device
* The file mem_info_vis_vram_total is used for this and returns the total
* amount of visible VRAM in bytes
*/
static ssize_t amdgpu_mem_info_vis_vram_total_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct drm_device *ddev = dev_get_drvdata(dev);
struct amdgpu_device *adev = drm_to_adev(ddev);
return sysfs_emit(buf, "%llu\n", adev->gmc.visible_vram_size);
}
Annotation
- Immediate include surface: `linux/dma-mapping.h`, `drm/ttm/ttm_range_manager.h`, `drm/drm_drv.h`, `drm/drm_buddy.h`, `amdgpu.h`, `amdgpu_vm.h`, `amdgpu_res_cursor.h`, `atom.h`.
- Detected declarations: `struct amdgpu_vram_reservation`, `function to_vram_mgr`, `function to_amdgpu_device`, `function amdgpu_vram_mgr_first_block`, `function amdgpu_is_vram_mgr_blocks_contiguous`, `function amdgpu_vram_mgr_blocks_size`, `function amdgpu_mem_info_vram_total_show`, `function amdgpu_mem_info_vis_vram_total_show`, `function amdgpu_mem_info_vram_used_show`, `function amdgpu_mem_info_vis_vram_used_show`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.