Skip to content

Commit 5878853

Browse files
pcercueivinodkoul
authored andcommitted
dmaengine: Add API function dmaengine_prep_peripheral_dma_vec()
This function can be used to initiate a scatter-gather DMA transfer, where the address and size of each segment is located in one entry of the dma_vec array. The major difference with dmaengine_prep_slave_sg() is that it supports specifying the lengths of each DMA transfer; as trying to override the length of the transfer with dmaengine_prep_slave_sg() is a very tedious process. The introduction of a new API function is also justified by the fact that scatterlists are on their way out. Note that dmaengine_prep_interleaved_dma() is not helpful either in that case, as it assumes that the address of each segment will be higher than the one of the previous segment, which we just cannot guarantee in case of a scatter-gather transfer. Signed-off-by: Paul Cercueil <[email protected]> Co-developed-by: Nuno Sa <[email protected]> Signed-off-by: Nuno Sa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 1613e60 commit 5878853

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

include/linux/dmaengine.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ struct dma_interleaved_template {
160160
struct data_chunk sgl[];
161161
};
162162

163+
/**
164+
* struct dma_vec - DMA vector
165+
* @addr: Bus address of the start of the vector
166+
* @len: Length in bytes of the DMA vector
167+
*/
168+
struct dma_vec {
169+
dma_addr_t addr;
170+
size_t len;
171+
};
172+
163173
/**
164174
* enum dma_ctrl_flags - DMA flags to augment operation preparation,
165175
* control completion, and communicate status.
@@ -910,6 +920,10 @@ struct dma_device {
910920
struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)(
911921
struct dma_chan *chan, unsigned long flags);
912922

923+
struct dma_async_tx_descriptor *(*device_prep_peripheral_dma_vec)(
924+
struct dma_chan *chan, const struct dma_vec *vecs,
925+
size_t nents, enum dma_transfer_direction direction,
926+
unsigned long flags);
913927
struct dma_async_tx_descriptor *(*device_prep_slave_sg)(
914928
struct dma_chan *chan, struct scatterlist *sgl,
915929
unsigned int sg_len, enum dma_transfer_direction direction,
@@ -973,6 +987,25 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single(
973987
dir, flags, NULL);
974988
}
975989

990+
/**
991+
* dmaengine_prep_peripheral_dma_vec() - Prepare a DMA scatter-gather descriptor
992+
* @chan: The channel to be used for this descriptor
993+
* @vecs: The array of DMA vectors that should be transferred
994+
* @nents: The number of DMA vectors in the array
995+
* @dir: Specifies the direction of the data transfer
996+
* @flags: DMA engine flags
997+
*/
998+
static inline struct dma_async_tx_descriptor *dmaengine_prep_peripheral_dma_vec(
999+
struct dma_chan *chan, const struct dma_vec *vecs, size_t nents,
1000+
enum dma_transfer_direction dir, unsigned long flags)
1001+
{
1002+
if (!chan || !chan->device || !chan->device->device_prep_peripheral_dma_vec)
1003+
return NULL;
1004+
1005+
return chan->device->device_prep_peripheral_dma_vec(chan, vecs, nents,
1006+
dir, flags);
1007+
}
1008+
9761009
static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_sg(
9771010
struct dma_chan *chan, struct scatterlist *sgl, unsigned int sg_len,
9781011
enum dma_transfer_direction dir, unsigned long flags)

0 commit comments

Comments
 (0)