drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c- Extension
.c- Size
- 12268 bytes
- Lines
- 471
- 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
drm/drm_managed.hdrm/drm_drv.hdrm/drm_buddy.hdrm/ttm/ttm_placement.hdrm/ttm/ttm_range_manager.hxe_bo.hxe_device.hxe_res_cursor.hxe_ttm_vram_mgr.hxe_vram_types.h
Detected Declarations
function Copyrightfunction xe_is_vram_mgr_blocks_contiguousfunction xe_ttm_vram_mgr_newfunction list_for_each_entryfunction xe_ttm_vram_mgr_delfunction xe_ttm_vram_mgr_debugfunction xe_ttm_vram_mgr_intersectsfunction list_for_each_entryfunction xe_ttm_vram_mgr_compatiblefunction list_for_each_entryfunction xe_ttm_vram_mgr_finifunction __xe_ttm_vram_mgr_initfunction xe_ttm_vram_mgr_initfunction xe_ttm_vram_mgr_alloc_sgtfunction xe_ttm_vram_mgr_free_sgtfunction xe_ttm_vram_get_cpu_visible_sizefunction xe_ttm_vram_get_usedfunction xe_ttm_vram_get_avail
Annotated Snippet
list_for_each_entry(block, &vres->blocks, link) {
u64 start = gpu_buddy_block_offset(block);
if (start < mgr->visible_size) {
u64 end = start + gpu_buddy_block_size(mm, block);
vres->used_visible_size +=
min(end, mgr->visible_size) - start;
}
}
}
mgr->visible_avail -= vres->used_visible_size;
mutex_unlock(&mgr->lock);
if (!(vres->base.placement & TTM_PL_FLAG_CONTIGUOUS) &&
xe_is_vram_mgr_blocks_contiguous(mm, &vres->blocks))
vres->base.placement |= TTM_PL_FLAG_CONTIGUOUS;
/*
* For some kernel objects we still rely on the start when io mapping
* the object.
*/
if (vres->base.placement & TTM_PL_FLAG_CONTIGUOUS) {
struct gpu_buddy_block *block = list_first_entry(&vres->blocks,
typeof(*block),
link);
vres->base.start = gpu_buddy_block_offset(block) >> PAGE_SHIFT;
} else {
vres->base.start = XE_BO_INVALID_OFFSET;
}
*res = &vres->base;
return 0;
error_unlock:
mutex_unlock(&mgr->lock);
error_fini:
ttm_resource_fini(man, &vres->base);
kfree(vres);
return err;
}
static void xe_ttm_vram_mgr_del(struct ttm_resource_manager *man,
struct ttm_resource *res)
{
struct xe_ttm_vram_mgr_resource *vres =
to_xe_ttm_vram_mgr_resource(res);
struct xe_ttm_vram_mgr *mgr = to_xe_ttm_vram_mgr(man);
struct gpu_buddy *mm = &mgr->mm;
mutex_lock(&mgr->lock);
gpu_buddy_free_list(mm, &vres->blocks, 0);
mgr->visible_avail += vres->used_visible_size;
mutex_unlock(&mgr->lock);
ttm_resource_fini(man, res);
kfree(vres);
}
static void xe_ttm_vram_mgr_debug(struct ttm_resource_manager *man,
struct drm_printer *printer)
{
struct xe_ttm_vram_mgr *mgr = to_xe_ttm_vram_mgr(man);
struct gpu_buddy *mm = &mgr->mm;
mutex_lock(&mgr->lock);
drm_printf(printer, "default_page_size: %lluKiB\n",
mgr->default_page_size >> 10);
drm_printf(printer, "visible_avail: %lluMiB\n",
(u64)mgr->visible_avail >> 20);
drm_printf(printer, "visible_size: %lluMiB\n",
(u64)mgr->visible_size >> 20);
drm_buddy_print(mm, printer);
mutex_unlock(&mgr->lock);
drm_printf(printer, "man size:%llu\n", man->size);
}
static bool xe_ttm_vram_mgr_intersects(struct ttm_resource_manager *man,
struct ttm_resource *res,
const struct ttm_place *place,
size_t size)
{
struct xe_ttm_vram_mgr *mgr = to_xe_ttm_vram_mgr(man);
struct xe_ttm_vram_mgr_resource *vres =
to_xe_ttm_vram_mgr_resource(res);
struct gpu_buddy *mm = &mgr->mm;
Annotation
- Immediate include surface: `drm/drm_managed.h`, `drm/drm_drv.h`, `drm/drm_buddy.h`, `drm/ttm/ttm_placement.h`, `drm/ttm/ttm_range_manager.h`, `xe_bo.h`, `xe_device.h`, `xe_res_cursor.h`.
- Detected declarations: `function Copyright`, `function xe_is_vram_mgr_blocks_contiguous`, `function xe_ttm_vram_mgr_new`, `function list_for_each_entry`, `function xe_ttm_vram_mgr_del`, `function xe_ttm_vram_mgr_debug`, `function xe_ttm_vram_mgr_intersects`, `function list_for_each_entry`, `function xe_ttm_vram_mgr_compatible`, `function list_for_each_entry`.
- 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.