drivers/gpu/drm/xe/xe_mem_pool.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_mem_pool.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/xe/xe_mem_pool.c- Extension
.c- Size
- 11181 bytes
- Lines
- 404
- 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.
- 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/kernel.hdrm/drm_managed.hinstructions/xe_mi_commands.hxe_bo.hxe_device_types.hxe_map.hxe_mem_pool.hxe_mem_pool_types.hxe_tile_printk.h
Detected Declarations
struct xe_mem_poolfunction fini_pool_actionfunction pool_shadow_initfunction xe_mem_pool_initfunction xe_mem_pool_syncfunction xe_mem_pool_swap_shadow_lockedfunction xe_mem_pool_sync_shadow_lockedfunction xe_mem_pool_gpu_addrfunction xe_mem_pool_cpu_addrfunction xe_mem_pool_bo_swap_guardfunction xe_mem_pool_bo_flush_writefunction xe_mem_pool_bo_sync_readfunction xe_mem_pool_alloc_nodefunction xe_mem_pool_insert_nodefunction xe_mem_pool_free_nodefunction xe_mem_pool_node_cpu_addrfunction xe_mem_pool_dump
Annotated Snippet
struct xe_mem_pool {
/** @base: Range allocator over [0, @size) in bytes */
struct drm_mm base;
/** @bo: Active pool BO (GGTT-pinned, CPU-mapped). */
struct xe_bo *bo;
/** @shadow: Shadow BO for atomic command updates. */
struct xe_bo *shadow;
/** @swap_guard: Timeline guard updating @bo and @shadow */
struct mutex swap_guard;
/** @cpu_addr: CPU virtual address of the active BO. */
void *cpu_addr;
/** @is_iomem: Indicates if the BO mapping is I/O memory. */
bool is_iomem;
};
static struct xe_mem_pool *node_to_pool(struct xe_mem_pool_node *node)
{
return container_of(node->sa_node.mm, struct xe_mem_pool, base);
}
static struct xe_tile *pool_to_tile(struct xe_mem_pool *pool)
{
return pool->bo->tile;
}
static void fini_pool_action(struct drm_device *drm, void *arg)
{
struct xe_mem_pool *pool = arg;
if (pool->is_iomem)
kvfree(pool->cpu_addr);
drm_mm_takedown(&pool->base);
}
static int pool_shadow_init(struct xe_mem_pool *pool)
{
struct xe_tile *tile = pool->bo->tile;
struct xe_device *xe = tile_to_xe(tile);
struct xe_bo *shadow;
int ret;
xe_assert(xe, !pool->shadow);
ret = drmm_mutex_init(&xe->drm, &pool->swap_guard);
if (ret)
return ret;
if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
fs_reclaim_acquire(GFP_KERNEL);
might_lock(&pool->swap_guard);
fs_reclaim_release(GFP_KERNEL);
}
shadow = xe_managed_bo_create_pin_map(xe, tile,
xe_bo_size(pool->bo),
XE_BO_FLAG_VRAM_IF_DGFX(tile) |
XE_BO_FLAG_GGTT |
XE_BO_FLAG_GGTT_INVALIDATE |
XE_BO_FLAG_PINNED_NORESTORE);
if (IS_ERR(shadow))
return PTR_ERR(shadow);
pool->shadow = shadow;
return 0;
}
/**
* xe_mem_pool_init() - Initialize memory pool.
* @tile: the &xe_tile where allocate.
* @size: number of bytes to allocate.
* @guard: the size of the guard region at the end of the BO that is not
* sub-allocated, in bytes.
* @flags: flags to use to create shadow pool.
*
* Initializes a memory pool for sub-allocating memory from a backing BO on the
* specified XE tile. The backing BO is pinned in the GGTT and mapped into
* the CPU address space for direct access. Optionally, a shadow BO can also be
* initialized for atomic updates to the primary BO's contents.
*
* Returns: a pointer to the &xe_mem_pool, or an error pointer on failure.
*/
struct xe_mem_pool *xe_mem_pool_init(struct xe_tile *tile, u32 size,
u32 guard, int flags)
{
struct xe_device *xe = tile_to_xe(tile);
struct xe_mem_pool *pool;
struct xe_bo *bo;
u32 managed_size;
int ret;
Annotation
- Immediate include surface: `linux/kernel.h`, `drm/drm_managed.h`, `instructions/xe_mi_commands.h`, `xe_bo.h`, `xe_device_types.h`, `xe_map.h`, `xe_mem_pool.h`, `xe_mem_pool_types.h`.
- Detected declarations: `struct xe_mem_pool`, `function fini_pool_action`, `function pool_shadow_init`, `function xe_mem_pool_init`, `function xe_mem_pool_sync`, `function xe_mem_pool_swap_shadow_locked`, `function xe_mem_pool_sync_shadow_locked`, `function xe_mem_pool_gpu_addr`, `function xe_mem_pool_cpu_addr`, `function xe_mem_pool_bo_swap_guard`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: source implementation candidate.
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.