drivers/gpu/drm/xe/xe_res_cursor.h

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/xe/xe_res_cursor.h

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/xe/xe_res_cursor.h
Extension
.h
Size
9152 bytes
Lines
369
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct xe_res_cursor {
	/** @start: Start of cursor */
	u64 start;
	/** @size: Size of the current segment. */
	u64 size;
	/** @remaining: Remaining bytes in cursor */
	u64 remaining;
	/** @node: Opaque point current node cursor */
	void *node;
	/** @mem_type: Memory type */
	u32 mem_type;
	/** @sgl: Scatterlist for cursor */
	struct scatterlist *sgl;
	/** @dma_addr: Current element in a struct drm_pagemap_addr array */
	const struct drm_pagemap_addr *dma_addr;
	/** @mm: Buddy allocator for VRAM cursor */
	struct gpu_buddy *mm;
	/**
	 * @dma_start: DMA start address for the current segment.
	 * This may be different to @dma_addr.addr since elements in
	 * the array may be coalesced to a single segment.
	 */
	u64 dma_start;
	/** @dma_seg_size: Size of the current DMA segment. */
	u64 dma_seg_size;
};

static struct gpu_buddy *xe_res_get_buddy(struct ttm_resource *res)
{
	struct ttm_resource_manager *mgr;

	mgr = ttm_manager_type(res->bo->bdev, res->mem_type);
	return &to_xe_ttm_vram_mgr(mgr)->mm;
}

/**
 * xe_res_first - initialize a xe_res_cursor
 *
 * @res: TTM resource object to walk
 * @start: Start of the range
 * @size: Size of the range
 * @cur: cursor object to initialize
 *
 * Start walking over the range of allocations between @start and @size.
 */
static inline void xe_res_first(struct ttm_resource *res,
				u64 start, u64 size,
				struct xe_res_cursor *cur)
{
	cur->sgl = NULL;
	cur->dma_addr = NULL;
	if (!res)
		goto fallback;

	XE_WARN_ON(start + size > res->size);

	cur->mem_type = res->mem_type;

	switch (cur->mem_type) {
	case XE_PL_STOLEN: {
		/* res->start is in pages (ttm_range_manager). */
		cur->start = (res->start << PAGE_SHIFT) + start;
		cur->size = size;
		cur->remaining = size;
		cur->node = NULL;
		cur->mm = NULL;
		break;
	}
	case XE_PL_VRAM0:
	case XE_PL_VRAM1: {
		struct gpu_buddy_block *block;
		struct list_head *head, *next;
		struct gpu_buddy *mm = xe_res_get_buddy(res);

		head = &to_xe_ttm_vram_mgr_resource(res)->blocks;

		block = list_first_entry_or_null(head,
						 struct gpu_buddy_block,
						 link);
		if (!block)
			goto fallback;

		while (start >= gpu_buddy_block_size(mm, block)) {
			start -= gpu_buddy_block_size(mm, block);

			next = block->link.next;
			if (next != head)
				block = list_entry(next, struct gpu_buddy_block,
						   link);
		}

Annotation

Implementation Notes