Skip to content

Commit 444cd62

Browse files
pcercueinunojsa
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 <paul@crapouillou.net> Co-developed-by: Nuno Sa <nuno.sa@analog.com> Signed-off-by: Nuno Sa <nuno.sa@analog.com> Link: https://lore.kernel.org/r/20240620122726.41232-2-paul@crapouillou.net Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent 331f567 commit 444cd62

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.
@@ -912,6 +922,10 @@ struct dma_device {
912922
struct dma_async_tx_descriptor *(*device_prep_dma_interrupt)(
913923
struct dma_chan *chan, unsigned long flags);
914924

925+
struct dma_async_tx_descriptor *(*device_prep_peripheral_dma_vec)(
926+
struct dma_chan *chan, const struct dma_vec *vecs,
927+
size_t nents, enum dma_transfer_direction direction,
928+
unsigned long flags);
915929
struct dma_async_tx_descriptor *(*device_prep_slave_sg)(
916930
struct dma_chan *chan, struct scatterlist *sgl,
917931
unsigned int sg_len, enum dma_transfer_direction direction,
@@ -974,6 +988,25 @@ static inline struct dma_async_tx_descriptor *dmaengine_prep_slave_single(
974988
dir, flags, NULL);
975989
}
976990

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

0 commit comments

Comments
 (0)