drivers/dma-buf/st-dma-resv.c

Source file repositories/reference/linux-study-clean/drivers/dma-buf/st-dma-resv.c

File Facts

System
Linux kernel
Corpus path
drivers/dma-buf/st-dma-resv.c
Extension
.c
Size
6789 bytes
Lines
316
Domain
Driver Families
Bucket
drivers/dma-buf
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 dma_resv_usage_param {
	enum dma_resv_usage usage;
	const char *desc;
};

static const char *fence_name(struct dma_fence *f)
{
	return "selftest";
}

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

static struct dma_fence *alloc_fence(void)
{
	struct dma_fence *f;

	f = kmalloc_obj(*f);
	if (!f)
		return NULL;

	dma_fence_init(f, &fence_ops, &fence_lock, 0, 0);
	return f;
}

static void test_sanitycheck(struct kunit *test)
{
	struct dma_resv resv;
	struct dma_fence *f;
	int r;

	f = alloc_fence();
	KUNIT_ASSERT_NOT_NULL(test, f);

	dma_fence_enable_sw_signaling(f);

	dma_fence_signal(f);
	dma_fence_put(f);

	dma_resv_init(&resv);
	r = dma_resv_lock(&resv, NULL);
	if (r)
		KUNIT_FAIL(test, "Resv locking failed\n");
	else
		dma_resv_unlock(&resv);
	dma_resv_fini(&resv);
}

static void test_signaling(struct kunit *test)
{
	const struct dma_resv_usage_param *param = test->param_value;
	enum dma_resv_usage usage = param->usage;
	struct dma_resv resv;
	struct dma_fence *f;
	int r;

	f = alloc_fence();
	KUNIT_ASSERT_NOT_NULL(test, f);

	dma_fence_enable_sw_signaling(f);

	dma_resv_init(&resv);
	r = dma_resv_lock(&resv, NULL);
	if (r) {
		KUNIT_FAIL(test, "Resv locking failed");
		goto err_free;
	}

	r = dma_resv_reserve_fences(&resv, 1);
	if (r) {
		KUNIT_FAIL(test, "Resv shared slot allocation failed");
		goto err_unlock;
	}

	dma_resv_add_fence(&resv, f, usage);
	if (dma_resv_test_signaled(&resv, usage)) {
		KUNIT_FAIL(test, "Resv unexpectedly signaled");
		goto err_unlock;
	}
	dma_fence_signal(f);
	if (!dma_resv_test_signaled(&resv, usage)) {
		KUNIT_FAIL(test, "Resv not reporting signaled");
		goto err_unlock;
	}
err_unlock:
	dma_resv_unlock(&resv);
err_free:
	dma_resv_fini(&resv);

Annotation

Implementation Notes