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

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

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/ttm/tests/ttm_resource_test.c
Extension
.c
Size
9307 bytes
Lines
338
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_resource_test_case {
	const char *description;
	u32 mem_type;
	u32 flags;
};

struct ttm_resource_test_priv {
	struct ttm_test_devices *devs;
	struct ttm_buffer_object *bo;
	struct ttm_place *place;
};

static const struct ttm_resource_manager_func ttm_resource_manager_mock_funcs = { };

static int ttm_resource_test_init(struct kunit *test)
{
	struct ttm_resource_test_priv *priv;

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

	priv->devs = ttm_test_devices_all(test);
	KUNIT_ASSERT_NOT_NULL(test, priv->devs);

	test->priv = priv;

	return 0;
}

static void ttm_resource_test_fini(struct kunit *test)
{
	struct ttm_resource_test_priv *priv = test->priv;

	ttm_test_devices_put(test, priv->devs);
}

static void ttm_init_test_mocks(struct kunit *test,
				struct ttm_resource_test_priv *priv,
				u32 mem_type, u32 flags)
{
	size_t size = RES_SIZE;

	/* Make sure we have what we need for a good BO mock */
	KUNIT_ASSERT_NOT_NULL(test, priv->devs->ttm_dev);

	priv->bo = ttm_bo_kunit_init(test, priv->devs, size, NULL);
	priv->place = ttm_place_kunit_init(test, mem_type, flags);
}

static void ttm_init_test_manager(struct kunit *test,
				  struct ttm_resource_test_priv *priv,
				  u32 mem_type)
{
	struct ttm_device *ttm_dev = priv->devs->ttm_dev;
	struct ttm_resource_manager *man;
	size_t size = SZ_16K;

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

	man->use_tt = false;
	man->func = &ttm_resource_manager_mock_funcs;

	ttm_resource_manager_init(man, ttm_dev, size);
	ttm_set_driver_manager(ttm_dev, mem_type, man);
	ttm_resource_manager_set_used(man, true);
}

static const struct ttm_resource_test_case ttm_resource_cases[] = {
	{
		.description = "Init resource in TTM_PL_SYSTEM",
		.mem_type = TTM_PL_SYSTEM,
	},
	{
		.description = "Init resource in TTM_PL_VRAM",
		.mem_type = TTM_PL_VRAM,
	},
	{
		.description = "Init resource in a private placement",
		.mem_type = TTM_PRIV_DUMMY_REG,
	},
	{
		.description = "Init resource in TTM_PL_SYSTEM, set placement flags",
		.mem_type = TTM_PL_SYSTEM,
		.flags = TTM_PL_FLAG_TOPDOWN,
	},
};

static void ttm_resource_case_desc(const struct ttm_resource_test_case *t, char *desc)
{

Annotation

Implementation Notes