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

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

File Facts

System
Linux kernel
Corpus path
drivers/dma-buf/st-dma-fence-unwrap.c
Extension
.c
Size
12176 bytes
Lines
607
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 mock_fence {
	struct dma_fence base;
	spinlock_t lock;
};

static const char *mock_name(struct dma_fence *f)
{
	return "mock";
}

static const struct dma_fence_ops mock_ops = {
	.get_driver_name = mock_name,
	.get_timeline_name = mock_name,
};

static struct dma_fence *__mock_fence(u64 context, u64 seqno)
{
	struct mock_fence *f;

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

	spin_lock_init(&f->lock);
	dma_fence_init(&f->base, &mock_ops, &f->lock, context, seqno);

	return &f->base;
}

static struct dma_fence *mock_fence(void)
{
	return __mock_fence(dma_fence_context_alloc(1), 1);
}

static struct dma_fence *mock_array(unsigned int num_fences, ...)
{
	struct dma_fence_array *array;
	struct dma_fence **fences;
	va_list valist;
	int i;

	fences = kzalloc_objs(*fences, num_fences);
	if (!fences)
		goto error_put;

	va_start(valist, num_fences);
	for (i = 0; i < num_fences; ++i)
		fences[i] = va_arg(valist, typeof(*fences));
	va_end(valist);

	array = dma_fence_array_create(num_fences, fences,
				       dma_fence_context_alloc(1),
				       1);
	if (!array)
		goto error_free;
	return &array->base;

error_free:
	kfree(fences);

error_put:
	va_start(valist, num_fences);
	for (i = 0; i < num_fences; ++i)
		dma_fence_put(va_arg(valist, typeof(*fences)));
	va_end(valist);
	return NULL;
}

static struct dma_fence *mock_chain(struct dma_fence *prev,
				    struct dma_fence *fence)
{
	struct dma_fence_chain *f;

	f = dma_fence_chain_alloc();
	if (!f) {
		dma_fence_put(prev);
		dma_fence_put(fence);
		return NULL;
	}

	dma_fence_chain_init(f, prev, fence, 1);
	return &f->base;
}

static void test_sanitycheck(struct kunit *test)
{
	struct dma_fence *f, *chain, *array;

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

Annotation

Implementation Notes