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

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

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/ttm/tests/ttm_pool_test.c
Extension
.c
Size
11441 bytes
Lines
432
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_pool_test_case {
	const char *description;
	unsigned int order;
	unsigned int alloc_flags;
};

struct ttm_pool_test_priv {
	struct ttm_test_devices *devs;

	/* Used to create mock ttm_tts */
	struct ttm_buffer_object *mock_bo;
};

static struct ttm_operation_ctx simple_ctx = {
	.interruptible = true,
	.no_wait_gpu = false,
};

static int ttm_pool_test_init(struct kunit *test)
{
	struct ttm_pool_test_priv *priv;

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

	priv->devs = ttm_test_devices_basic(test);
	test->priv = priv;

	return 0;
}

static void ttm_pool_test_fini(struct kunit *test)
{
	struct ttm_pool_test_priv *priv = test->priv;

	ttm_test_devices_put(test, priv->devs);
}

static struct ttm_tt *ttm_tt_kunit_init(struct kunit *test,
					u32 page_flags,
					enum ttm_caching caching,
					size_t size)
{
	struct ttm_pool_test_priv *priv = test->priv;
	struct ttm_buffer_object *bo;
	struct ttm_tt *tt;
	int err;

	bo = ttm_bo_kunit_init(test, priv->devs, size, NULL);
	KUNIT_ASSERT_NOT_NULL(test, bo);
	priv->mock_bo = bo;

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

	err = ttm_tt_init(tt, priv->mock_bo, page_flags, caching, 0);
	KUNIT_ASSERT_EQ(test, err, 0);

	return tt;
}

static struct ttm_pool *ttm_pool_pre_populated(struct kunit *test,
					       size_t size,
					       enum ttm_caching caching)
{
	struct ttm_pool_test_priv *priv = test->priv;
	struct ttm_test_devices *devs = priv->devs;
	struct ttm_pool *pool;
	struct ttm_tt *tt;
	int err;

	tt = ttm_tt_kunit_init(test, 0, caching, size);
	KUNIT_ASSERT_NOT_NULL(test, tt);

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

	ttm_pool_init(pool, devs->dev, NUMA_NO_NODE, TTM_ALLOCATION_POOL_USE_DMA_ALLOC);

	err = ttm_pool_alloc(pool, tt, &simple_ctx);
	KUNIT_ASSERT_EQ(test, err, 0);

	ttm_pool_free(pool, tt);
	ttm_tt_fini(tt);

	return pool;
}

static const struct ttm_pool_test_case ttm_pool_basic_cases[] = {
	{

Annotation

Implementation Notes