drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c

Source file repositories/reference/linux-study-clean/drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/ttm/tests/ttm_bo_validate_test.c
Extension
.c
Size
38599 bytes
Lines
1218
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 ttm_bo_validate_test_case {
	const char *description;
	enum ttm_bo_type bo_type;
	u32 mem_type;
	bool with_ttm;
	bool no_gpu_wait;
};

static struct ttm_placement *ttm_placement_kunit_init(struct kunit *test,
						      struct ttm_place *places,
						      unsigned int num_places)
{
	struct ttm_placement *placement;

	placement = kunit_kzalloc(test, sizeof(*placement), GFP_KERNEL);
	KUNIT_ASSERT_NOT_NULL(test, placement);

	placement->num_placement = num_places;
	placement->placement = places;

	return placement;
}

static const char *fence_name(struct dma_fence *f)
{
	return "ttm-bo-validate-fence";
}

static const struct dma_fence_ops fence_ops = {
	.get_driver_name = fence_name,
	.get_timeline_name = fence_name,
};

static struct dma_fence *alloc_mock_fence(struct kunit *test)
{
	struct dma_fence *fence;

	fence = kunit_kzalloc(test, sizeof(*fence), GFP_KERNEL);
	KUNIT_ASSERT_NOT_NULL(test, fence);

	dma_fence_init(fence, &fence_ops, &fence_lock, 0, 0);

	return fence;
}

static void dma_resv_kunit_active_fence_init(struct kunit *test,
					     struct dma_resv *resv,
					     enum dma_resv_usage usage)
{
	struct dma_fence *fence;

	fence = alloc_mock_fence(test);
	dma_fence_enable_sw_signaling(fence);

	dma_resv_lock(resv, NULL);
	dma_resv_reserve_fences(resv, 1);
	dma_resv_add_fence(resv, fence, usage);
	dma_resv_unlock(resv);
}

static void ttm_bo_validate_case_desc(const struct ttm_bo_validate_test_case *t,
				      char *desc)
{
	strscpy(desc, t->description, KUNIT_PARAM_DESC_SIZE);
}

static const struct ttm_bo_validate_test_case ttm_bo_type_cases[] = {
	{
		.description = "Buffer object for userspace",
		.bo_type = ttm_bo_type_device,
	},
	{
		.description = "Kernel buffer object",
		.bo_type = ttm_bo_type_kernel,
	},
	{
		.description = "Shared buffer object",
		.bo_type = ttm_bo_type_sg,
	},
};

KUNIT_ARRAY_PARAM(ttm_bo_types, ttm_bo_type_cases,
		  ttm_bo_validate_case_desc);

static void ttm_bo_init_reserved_sys_man(struct kunit *test)
{
	const struct ttm_bo_validate_test_case *params = test->param_value;
	struct ttm_test_devices *priv = test->priv;
	enum ttm_bo_type bo_type = params->bo_type;
	u32 size = ALIGN(BO_SIZE, PAGE_SIZE);

Annotation

Implementation Notes