RFC: changing DMA slave configuration API
Dan, Vinod,
There's a change I would like to do to the DMA slave configuration. It's currently a pain to have the source and destination parameters in the dma_slave_config structure as separate elements; it means when you want to extract them, you end up with code in DMA engine drivers like:
+ if (dir == DMA_DEV_TO_MEM) {
+ dev_addr = c->src_addr;
+ dev_width = c->src_addr_width;
+ burst = c->src_maxburst;
+ } else if (dir == DMA_MEM_TO_DEV) {
+ dev_addr = c->dst_addr;
+ dev_width = c->dst_addr_width;
+ burst = c->dst_maxburst;
+ }
If we redefine the structure as below, this all becomes more simple:
+ if (dir == DMA_DEV_TO_MEM)
+ cfg = &c->dev_src;
+ else if (dir == DMA_MEM_TO_DEV)
+ cfg = &c->dev_dst;
and then we can access the data through cfg->{element} rather than having to cache each individual elements value in a local variable.
Thoughts?
include/linux/dmaengine.h +12 -0
@@ -367,6 +367,18 @@ struct dma_slave_config {bool device_fc; }; +struct dma_dev_cfg { +dma_addr_t addr; +enum dma_slave_buswidth width; +u32 maxburst; +}; + +struct dma_slave_cfg { +struct dma_dev_cfg dev_src; +struct dma_dev_cfg dev_dst; +bool device_fc; +}; +static inline const char *dma_chan_name (struct dma_chan *chan) {return dev_name (&chan->dev->device);
2012/6/10 Russell King - ARM Linux <[email protected]>:
Quoted 17 lines
Dan, Vinod,
There's a change I would like to do to the DMA slave configuration. It's currently a pain to have the source and destination parameters in the
dma_slave_configstructure as separate elements; it means when you want to extract them, you end up with code in DMA engine drivers like:+ ? ? ? if (dir ==
DMA_DEV_TO_MEM) {
+ ? ? ? ? ? ? ?dev_addr=c->src_addr;
+ ? ? ? ? ? ? ?dev_width=c->src_addr_width;
+ ? ? ? ? ? ? ? burst =c->src_maxburst;
+ ? ? ? } else if (dir ==DMA_MEM_TO_DEV) {
+ ? ? ? ? ? ? ?dev_addr=c->dst_addr;
+ ? ? ? ? ? ? ?dev_width=c->dst_addr_width;
+ ? ? ? ? ? ? ? burst =c->dst_maxburst;
+ ? ? ? }
Quoted 6 lines
If we redefine the structure as below, this all becomes more simple:
+ ? ? ? if (dir ==
DMA_DEV_TO_MEM)
+ ? ? ? ? ? ? ? cfg =&c->dev_src;
+ ? ? ? else if (dir ==DMA_MEM_TO_DEV)
+ ? ? ? ? ? ? ? cfg =&c->dev_dst;
it seems that might mean an union in your dma_slave_cfg, but not co-exitense of both?
struct dma_slave_cfg {
+ union {
struct dma_dev_cfg dev_src;
struct dma_dev_cfg dev_dst;
}
bool device_fc;
};Quoted 20 lines
and then we can access the data through cfg->{element} rather than having to cache each individual elements value in a local variable.
Thoughts?
include/linux/dmaengine.h +5
-0@@ -367,6 +367,18 @@ struct dma_slave_config { ? ? ? ?bool device_fc; ?}; +struct dma_dev_cfg { + ? ? ? dma_addr_t addr; + ? ? ? enum dma_slave_buswidth width; + ? ? ? u32 maxburst; +};
include/linux/dmaengine.h struct dma_slave_config { · line 384
Quoted 10 lines
include/linux/dmaengine.h +7
-0+ +struct dma_slave_cfg { + ? ? ? struct dma_dev_cfg dev_src; + ? ? ? struct dma_dev_cfg dev_dst; + ? ? ? bool device_fc; +}; + ?static inline const char *dma_chan_name(struct dma_chan *chan) ?{ ? ? ? ?return dev_name(&chan->dev->device);
Thanks
barry
Quoted 20 lines · Barry Song
2012/6/10 Russell King - ARM Linux <[email protected]>:
Quoted 19 lines
Dan, Vinod,
There's a change I would like to do to the DMA slave configuration. It's currently a pain to have the source and destination parameters in the
dma_slave_configstructure as separate elements; it means when you want to extract them, you end up with code in DMA engine drivers like:+ ? ? ? if (dir ==
DMA_DEV_TO_MEM) {
+ ? ? ? ? ? ? ?dev_addr=c->src_addr;
+ ? ? ? ? ? ? ?dev_width=c->src_addr_width;
+ ? ? ? ? ? ? ? burst =c->src_maxburst;
+ ? ? ? } else if (dir ==DMA_MEM_TO_DEV) {
+ ? ? ? ? ? ? ?dev_addr=c->dst_addr;
+ ? ? ? ? ? ? ?dev_width=c->dst_addr_width;
+ ? ? ? ? ? ? ? burst =c->dst_maxburst;
+ ? ? ? }If we redefine the structure as below, this all becomes more simple:
Quoted 7 lines
Quoted 4 lines
+ ? ? ? if (dir ==
DMA_DEV_TO_MEM)
+ ? ? ? ? ? ? ? cfg =&c->dev_src;
+ ? ? ? else if (dir ==DMA_MEM_TO_DEV)
+ ? ? ? ? ? ? ? cfg =&c->dev_dst;it seems that might mean an union in your
dma_slave_cfg, but not co-exitense of both?
No, I want both so it's possible to select between the two when preparing a DMA slave transfer.
Quoted 7 lines
struct
dma_slave_cfg{+ union { struct dma_dev_cfg dev_src; struct dma_dev_cfg dev_dst; } bool device_fc; };
If you do that, the union becomes pointless, and you might as well have:
struct dma_slave_cfg {
struct dma_dev_cfg dev;
bool device_fc;
};instead.
Quoted 40 lines · Russell King - ARM Linux
Quoted 20 lines · Barry Song
2012/6/10 Russell King - ARM Linux <[email protected]>:
Quoted 19 lines
Dan, Vinod,
There's a change I would like to do to the DMA slave configuration. It's currently a pain to have the source and destination parameters in the
dma_slave_configstructure as separate elements; it means when you want to extract them, you end up with code in DMA engine drivers like:(quoted diff) +9
-0+ if (dir == DMA_DEV_TO_MEM) { + dev_addr = c->src_addr; + dev_width = c->src_addr_width; + burst = c->src_maxburst; + } else if (dir == DMA_MEM_TO_DEV) { + dev_addr = c->dst_addr; + dev_width = c->dst_addr_width; + burst = c->dst_maxburst; + }If we redefine the structure as below, this all becomes more simple:
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (dir == DMA_DEV_TO_MEM) + cfg = &c->dev_src; + else if (dir == DMA_MEM_TO_DEV) + cfg = &c->dev_dst;it seems that might mean an union in your
dma_slave_cfg, but not co-exitense of both?No, I want both so it's possible to select between the two when preparing a DMA slave transfer.
Quoted 7 lines
struct
dma_slave_cfg{+ union { struct dma_dev_cfg dev_src; struct dma_dev_cfg dev_dst; } bool device_fc; };
Quoted 8 lines
If you do that, the union becomes pointless, and you might as well have:
struct dma_slave_cfg { struct dma_dev_cfg dev; bool device_fc; };instead.
Hi Russell,
I think it is a good idea. And I would like to extend it even a little bit. Do we have any users of peripheral to peripheral slave dma? IIRC that is not the case, or does anyone know of existence or plans for such a h/w?
If not, lets junk the src/dst fields and keep burst, length, addr fields which point to the peripheral values.
Alternatively if we need both, then we can't have union and Russell's idea seems good one :)
Signature · 1 line
~Vinod
Quoted 10 lines · Vinod Koul
I think it is a good idea. And I would like to extend it even a little bit. Do we have any users of peripheral to peripheral slave dma? IIRC that is not the case, or does anyone know of existence or plans for such a h/w?
If not, lets junk the src/dst fields and keep burst, length, addr fields which point to the peripheral values.
Alternatively if we need both, then we can't have union and Russell's idea seems good one :)
We don't need the union whatever way that goes.
The question over whether we have the src/dst fields is whether we want to support a different configuration for DMA_DEV_TO_MEM/DMA_MEM_TO_DEV without having to reconfigure the channel each time its direction is switched.
Out of the following users:drivers/mmc/host/mmci.cdrivers/spi/spi-pl022.cdrivers/tty/serial/amba-pl011.c
with amba-pl08x, I don't see any which set a different configuration depending on direction, and sa11x0 and OMAP DMA engine drivers only support one direction per channel.
So, the question really comes down to whether we _want_ to support this, and how painful it would be to re-introduce this if we did need it. Maybe the right answer is to use the control command value to sort that out when we come to it.
Quoted 48 lines · Vinod Koul
Quoted 47 lines · Russell King - ARM Linux
Quoted 20 lines · Barry Song
2012/6/10 Russell King - ARM Linux <[email protected]>:
Quoted 19 lines
Dan, Vinod,
There's a change I would like to do to the DMA slave configuration. It's currently a pain to have the source and destination parameters in the
dma_slave_configstructure as separate elements; it means when you want to extract them, you end up with code in DMA engine drivers like:(quoted diff) +9
-0+ if (dir == DMA_DEV_TO_MEM) { + dev_addr = c->src_addr; + dev_width = c->src_addr_width; + burst = c->src_maxburst; + } else if (dir == DMA_MEM_TO_DEV) { + dev_addr = c->dst_addr; + dev_width = c->dst_addr_width; + burst = c->dst_maxburst; + }If we redefine the structure as below, this all becomes more simple:
Quoted 7 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (dir == DMA_DEV_TO_MEM) + cfg = &c->dev_src; + else if (dir == DMA_MEM_TO_DEV) + cfg = &c->dev_dst;it seems that might mean an union in your
dma_slave_cfg, but not co-exitense of both?No, I want both so it's possible to select between the two when preparing a DMA slave transfer.
Quoted 7 lines
struct
dma_slave_cfg{+ union { struct dma_dev_cfg dev_src; struct dma_dev_cfg dev_dst; } bool device_fc; };If you do that, the union becomes pointless, and you might as well have:
struct dma_slave_cfg { struct dma_dev_cfg dev; bool device_fc; };
Quoted 5 lines
Quoted 1 line
instead.
Hi Russell,
I think it is a good idea. And I would like to extend it even a little bit. Do we have any users of peripheral to peripheral slave dma?
Yes, IMX sdma does support such kind of transfer.
The driver still does not support it currently.
Quoted 3 lines
IIRC that is not the case, or does anyone know of existence or plans for such a h/w?
i.MX5 and i.MX6.
Quoted 6 lines
If not, lets junk the src/dst fields and keep burst, length, addr fields which point to the peripheral values.
Alternatively if we need both, then we can't have union and Russell's idea seems good one :)
Russell's idea seems reasonable and we may want to support peripheral to peripheral in the future.
Regards
Dong Aisheng
Quoted 4 lines · Vinod Koul
I think it is a good idea. And I would like to extend it even a little bit. Do we have any users of peripheral to peripheral slave dma? IIRC that is not the case, or does anyone know of existence or plans for such a h/w?
We have hardware that supports this, and I suspect it will become more common in our future chips.
David
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
Quoted 11 lines · Dong Aisheng
Quoted 1 line
I think it is a good idea. And I would like to extend it even a
little
Quoted 1 line
bit. Do we have any users of peripheral to peripheral slave dma?
Yes, IMX sdma does support such kind of transfer.
The driver still does not support it currently.Quoted 1 line
IIRC that is not the case, or does anyone know of existence or
plans
Quoted 2 lines
for such a h/w?
i.MX5 and i.MX6.
Thanks for confirming, lets keep both.
Signature · 1 line
~Vinod
Quoted 6 lines · Russell King - ARM Linux
Quoted 5 lines · Vinod Koul
I think it is a good idea. And I would like to extend it even a little bit. Do we have any users of peripheral to peripheral slave dma? IIRC that is not the case, or does anyone know of existence or plans for such a h/w?
Quoted 7 lines
Quoted 5 lines
If not, lets junk the src/dst fields and keep burst, length, addr fields which point to the peripheral values.
Alternatively if we need both, then we can't have union and Russell's idea seems good one :)
We don't need the union whatever way that goes.
Based on comment we need to support both.
Quoted 5 lines
The question over whether we have the src/dst fields is whether we want to support a different configuration for DMA_DEV_TO_MEM/DMA_MEM_TO_DEV without having to reconfigure the channel each time its direction is switched.
The biggest issue here is the design of the API. IMO the slave_config should be passed along with respective prepare API for slave and not thru separate slave config. That will remove the unnecessary limitation and allow the same channel to be used for tx for one transfer and rx for subsequent etc.
In the .device_prep_slave_sg() we should add the struct slave_config as an argument. Obviously the slave_config will have _one_ pair of members (not both src/dstn fields then).
For DMA_DEV_TO_DEV, anyway we need a new API, which can have both src and dstn slave_config
Thoughts..?
Signature · 1 line
~Vinod
Quoted 3 lines · Vinod Koul
Do we have any users of peripheral to peripheral slave dma? IIRC that is not the case, or does anyone know of existence or plans for such a h/w?
The U300 (COH901318) device can do this.
The usecase is basically that the modem CPU sets up a PCM stream on the high-speed serial link (called MSL) and the DMA controller reads 16 bit words from this link and routes it directly to a PCM sink on an I2S hardware.
Actually it runs in both directions during a voicecall, you can probably see the gain in power and CPU unload this will gain on a phone.
However this is all out-of-tree code and not that big deal as it's a legacy platform.
Yours,
Linus Walleij