Skip to contentSkip to conversation

dmaengine: Add Synopsys eDMA IP test and sample driver

RFC New Jose Abreu 1 participant 1 message Jan 16, 2019

Subsystems (2)
lore
Share & tools
lore

Jose Abreu

author
#0 lore raw

RFC v3 7/7 dmaengine: Add Synopsys eDMA IP test and sample driver

Hi Gustavo,

Quoted 51 lines · Gustavo Pimentel

Add Synopsys eDMA IP test and sample driver to be use for testing purposes and also as a reference for any developer who needs to implement and use Synopsys eDMA.

This driver can be compile as built-in or external module in kernel.

To enable this driver just select DW_EDMA_TEST option in kernel configuration, however it requires and selects automatically DW_EDMA option too.

Changes:
RFC v1->RFC v2:
- No changes
RFC v2->RFC v3:
- Add test module

Cc Vinod Koul <[email protected]>
Cc Dan Williams <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Andy Shevchenko <[email protected]>
Cc Russell King <[email protected]>
Cc Niklas Cassel <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Luis Oliveira <[email protected]>
Cc Vitor Soares <[email protected]>
Cc Nelson Costa <[email protected]>
Cc Pedro Sousa <[email protected]>
(quoted diff) +21 -0
+static int dw_edma_test_add_channel(struct dw_edma_test_info *info,
+				    struct dma_chan *chan,
+				    u32 channel)
+{
+	struct dw_edma_test_params *params = &info->params;
+	struct dw_edma_test_thread *thread;
+	struct dw_edma_test_chan *tchan;
+
+	tchan = kvmalloc(sizeof(*tchan), GFP_KERNEL);
+	if (!tchan)
+		return -ENOMEM;
+
+	tchan->chan = chan;
+
+	thread = kvzalloc(sizeof(*thread), GFP_KERNEL);
+	if (!thread) {
+		kvfree(tchan);
+		return -ENOMEM;
+	}
+
+	thread->info = info;

Review

Quoted 10 lines
(quoted diff) +10 -0
+	thread->chan = tchan->chan;
+	switch (channel) {
+	case EDMA_CH_WR:
+		thread->direction = DMA_DEV_TO_MEM;
+		break;
+	case EDMA_CH_RD:
+		thread->direction = DMA_MEM_TO_DEV;
+		break;
+	default:
+		kvfree(tchan);

You are leaking thread here.

Quoted 26 lines
(quoted diff) +26 -0
+		return -EPERM;
+	}
+	thread->test_done.wait = &thread->done_wait;
+	init_waitqueue_head(&thread->done_wait);
+
+	if (!params->repetitions)
+		thread->task = kthread_create(dw_edma_test_sg, thread, "%s",
+					      dma_chan_name(chan));
+	else
+		thread->task = kthread_create(dw_edma_test_cyclic, thread, "%s",
+					      dma_chan_name(chan));
+
+	if (IS_ERR(thread->task)) {
+		pr_err("failed to create thread %s\n", dma_chan_name(chan));
+		kvfree(tchan);
+		kvfree(thread);
+		return -EPERM;
+	}
+
+	tchan->thread = thread;
+	dev_dbg(chan->device->dev, "add thread %s\n", dma_chan_name(chan));
+	list_add_tail(&tchan->node, &info->channels);
+
+	return 0;
+}
+