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

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

File Facts

System
Linux kernel
Corpus path
drivers/dma-buf/st-dma-fence.c
Extension
.c
Size
10192 bytes
Lines
509
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 simple_cb {
	struct dma_fence_cb cb;
	bool seen;
};

static void simple_callback(struct dma_fence *f, struct dma_fence_cb *cb)
{
	smp_store_mb(container_of(cb, struct simple_cb, cb)->seen, true);
}

static void test_add_callback(struct kunit *test)
{
	struct simple_cb cb = {};
	struct dma_fence *f;

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

	if (dma_fence_add_callback(f, &cb.cb, simple_callback)) {
		KUNIT_FAIL(test, "Failed to add callback, fence already signaled!");
		goto err_free;
	}

	dma_fence_signal(f);
	if (!cb.seen) {
		KUNIT_FAIL(test, "Callback failed!");
		goto err_free;
	}

err_free:
	dma_fence_put(f);
}

static void test_late_add_callback(struct kunit *test)
{
	struct simple_cb cb = {};
	struct dma_fence *f;

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

	dma_fence_enable_sw_signaling(f);

	dma_fence_signal(f);

	if (!dma_fence_add_callback(f, &cb.cb, simple_callback)) {
		KUNIT_FAIL(test, "Added callback, but fence was already signaled!");
		goto err_free;
	}

	dma_fence_signal(f);
	if (cb.seen) {
		KUNIT_FAIL(test, "Callback called after failed attachment!");
		goto err_free;
	}

err_free:
	dma_fence_put(f);
}

static void test_rm_callback(struct kunit *test)
{
	struct simple_cb cb = {};
	struct dma_fence *f;

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

	if (dma_fence_add_callback(f, &cb.cb, simple_callback)) {
		KUNIT_FAIL(test, "Failed to add callback, fence already signaled!");
		goto err_free;
	}

	if (!dma_fence_remove_callback(f, &cb.cb)) {
		KUNIT_FAIL(test, "Failed to remove callback!");
		goto err_free;
	}

	dma_fence_signal(f);
	if (cb.seen) {
		KUNIT_FAIL(test, "Callback still signaled after removal!");
		goto err_free;
	}

err_free:
	dma_fence_put(f);
}

static void test_late_rm_callback(struct kunit *test)
{

Annotation

Implementation Notes