Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions linux-user-space-dma/Software/Kernel/dma-proxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,16 @@ static void start_transfer(struct dma_proxy_channel *pchannel_p)
/* A single entry scatter gather list is used as it's not clear how to do it with a simpler method.
* Get a descriptor for the transfer ready to submit
*/
sg_init_one(
&pchannel_p->bdtable[bdindex].sglist,
(void*)pchannel_p->bdtable[bdindex].dma_handle,
pchannel_p->buffer_table_p[bdindex].length
);
sg_init_one(&pchannel_p->bdtable[bdindex].sglist,
(void*)pchannel_p->bdtable[baindex].dma_handle,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg_init_one() according to scatterlist.c takes in a virtual address to the memory to write to.

Suggested change
(void*)pchannel_p->bdtable[baindex].dma_handle,
(void*)pchannel_p->buffer_table_p[bdindex].buffer,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yes. Not sure why dma_handle has been introduced here. In that case it's probably better to drop the dma_handle completely instead of just ignoring it.

pchannel_p->buffer_table_p[bdindex].length);

n = dma_map_sg(dma_device->dev, &pchannel_p->bdtable[bdindex].sglist,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we allocated in create_channel() with dmam_alloc_coherent() we probably don't need to map anymore.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem that I addressed here was not the mapping of the memory pointers. It was about the length. In scatterlist.h there is

#ifdef CONFIG_NEED_SG_DMA_LENGTH
#define sg_dma_len(sg)		((sg)->dma_length)
#else
#define sg_dma_len(sg)		((sg)->length)
#endif

so with IOMMU a different length field is accessed. Those field values are harmonized with dma_map_sg() and that makes the transfer work, otherwise the length field will be read with 0.

1, DMA_FROM_DEVICE);
if (n != 1) {
printk(KERN_ERR "DMA mapping failed\n");
return;
}

chan_desc = dma_device->device_prep_slave_sg(pchannel_p->channel_p, &pchannel_p->bdtable[bdindex].sglist, 1,
pchannel_p->direction, flags, NULL);
Expand Down