drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
Extension
.c
Size
10477 bytes
Lines
375
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

ttm_resource_manager_usage(man) > man->size) {
		r = -ENOSPC;
		goto err_free;
	}

	if (place->lpfn) {
		spin_lock(&mgr->lock);
		r = drm_mm_insert_node_in_range(&mgr->mm, &node->mm_nodes[0],
						num_pages, tbo->page_alignment,
						0, place->fpfn, place->lpfn,
						DRM_MM_INSERT_BEST);
		spin_unlock(&mgr->lock);
		if (unlikely(r))
			goto err_free;

		node->base.start = node->mm_nodes[0].start;
	} else {
		node->mm_nodes[0].start = 0;
		node->mm_nodes[0].size = PFN_UP(node->base.size);
		node->base.start = AMDGPU_BO_INVALID_OFFSET;
	}

	*res = &node->base;
	return 0;

err_free:
	ttm_resource_fini(man, &node->base);
	kfree(node);
	return r;
}

/**
 * amdgpu_gtt_mgr_del - free ranges
 *
 * @man: TTM memory type manager
 * @res: TTM memory object
 *
 * Free the allocated GTT again.
 */
static void amdgpu_gtt_mgr_del(struct ttm_resource_manager *man,
			       struct ttm_resource *res)
{
	struct ttm_range_mgr_node *node = to_ttm_range_mgr_node(res);
	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);

	spin_lock(&mgr->lock);
	if (drm_mm_node_allocated(&node->mm_nodes[0]))
		drm_mm_remove_node(&node->mm_nodes[0]);
	spin_unlock(&mgr->lock);

	ttm_resource_fini(man, res);
	kfree(node);
}

/**
 * amdgpu_gtt_mgr_alloc_entries - alloc GART entries without GTT bo
 *
 * @mgr: The GTT manager object
 * @mm_node: The drm mm node to return the new allocation node information
 * @num_pages: The number of pages for the new allocation
 * @mode: The new allocation mode
 *
 * Helper to dynamic alloc GART entries to map memory not accociated with
 * GTT BO, for example VRAM BO physical memory, remote physical memory.
 */
int amdgpu_gtt_mgr_alloc_entries(struct amdgpu_gtt_mgr *mgr,
				 struct drm_mm_node *mm_node,
				 u64 num_pages,
				 enum drm_mm_insert_mode mode)
{
	struct amdgpu_device *adev = container_of(mgr, typeof(*adev), mman.gtt_mgr);
	u32 alignment = 0;
	int r;

	/* Align to TLB L2 cache entry size to work around "V bit HW bug" */
	if (adev->family == AMDGPU_FAMILY_SI) {
		alignment = 32 * 1024 / AMDGPU_GPU_PAGE_SIZE;
		num_pages = ALIGN(num_pages, alignment);
	}

	spin_lock(&mgr->lock);
	r = drm_mm_insert_node_in_range(&mgr->mm, mm_node, num_pages,
					alignment, GART_ENTRY_WITHOUT_BO_COLOR, 0,
					adev->gmc.gart_size >> PAGE_SHIFT,
					mode);
	spin_unlock(&mgr->lock);
	return r;
}

/**

Annotation

Implementation Notes