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

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

File Facts

System
Linux kernel
Corpus path
drivers/gpu/drm/ttm/tests/ttm_bo_test.c
Extension
.c
Size
16585 bytes
Lines
638
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_test_case {
	const char *description;
	bool interruptible;
	bool no_wait;
};

static const struct ttm_bo_test_case ttm_bo_reserved_cases[] = {
	{
		.description = "Cannot be interrupted and sleeps",
		.interruptible = false,
		.no_wait = false,
	},
	{
		.description = "Cannot be interrupted, locks straight away",
		.interruptible = false,
		.no_wait = true,
	},
	{
		.description = "Can be interrupted, sleeps",
		.interruptible = true,
		.no_wait = false,
	},
};

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

KUNIT_ARRAY_PARAM(ttm_bo_reserve, ttm_bo_reserved_cases, ttm_bo_init_case_desc);

static void ttm_bo_reserve_optimistic_no_ticket(struct kunit *test)
{
	const struct ttm_bo_test_case *params = test->param_value;
	struct ttm_buffer_object *bo;
	int err;

	bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);

	err = ttm_bo_reserve(bo, params->interruptible, params->no_wait, NULL);
	KUNIT_ASSERT_EQ(test, err, 0);

	dma_resv_unlock(bo->base.resv);
}

static void ttm_bo_reserve_locked_no_sleep(struct kunit *test)
{
	struct ttm_buffer_object *bo;
	bool interruptible = false;
	bool no_wait = true;
	int err;

	bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);

	/* Let's lock it beforehand */
	dma_resv_lock(bo->base.resv, NULL);

	err = ttm_bo_reserve(bo, interruptible, no_wait, NULL);
	dma_resv_unlock(bo->base.resv);

	KUNIT_ASSERT_EQ(test, err, -EBUSY);
}

static void ttm_bo_reserve_no_wait_ticket(struct kunit *test)
{
	struct ttm_buffer_object *bo;
	struct ww_acquire_ctx ctx;
	bool interruptible = false;
	bool no_wait = true;
	int err;

	ww_acquire_init(&ctx, &reservation_ww_class);

	bo = ttm_bo_kunit_init(test, test->priv, BO_SIZE, NULL);

	err = ttm_bo_reserve(bo, interruptible, no_wait, &ctx);
	KUNIT_ASSERT_EQ(test, err, -EBUSY);

	ww_acquire_fini(&ctx);
}

static void ttm_bo_reserve_double_resv(struct kunit *test)
{
	struct ttm_buffer_object *bo;
	struct ww_acquire_ctx ctx;
	bool interruptible = false;
	bool no_wait = false;
	int err;

Annotation

Implementation Notes