Re: [PATCH 5/8 v5] dma: k3dma: Add support for dma-channel-mask

2019-02-04 Thread Vinod Koul
On 24-01-19, 12:24, John Stultz wrote:
> From: Li Yu 
> 
> Add dma-channel-mask as a property for k3dma, it defines
> available dma channels which a non-secure mode driver can use.
> 
> One sample usage of this is in Hi3660 SoC. DMA channel 0 is
> reserved to lpm3, which is a coprocessor for power management. So
> as a result, any request in kernel (which runs on main processor
> and in non-secure mode) should start from at least channel 1.
> 
> Cc: Dan Williams 
> Cc: Vinod Koul 
> Cc: Tanglei Han 
> Cc: Zhuangluan Su 
> Cc: Ryan Grachek 
> Cc: Manivannan Sadhasivam 
> Cc: Guodong Xu 
> Cc: dmaeng...@vger.kernel.org
> Signed-off-by: Li Yu 
> [jstultz: Reworked to use a channel mask]
> Signed-off-by: John Stultz 
> ---
> v3: Rename to hisi-dma-avail-chan
> v4: Rename to dma-channel-mask
> v5: Use BIT(i) instead of (1< ---
>  drivers/dma/k3dma.c | 20 +++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/k3dma.c b/drivers/dma/k3dma.c
> index e415c85..294ec64 100644
> --- a/drivers/dma/k3dma.c
> +++ b/drivers/dma/k3dma.c
> @@ -111,6 +111,7 @@ struct k3_dma_dev {
>   struct dma_pool *pool;
>   u32 dma_channels;
>   u32 dma_requests;
> + u32 dma_channel_mask;
>   unsigned intirq;
>  };
>  
> @@ -319,6 +320,9 @@ static void k3_dma_tasklet(unsigned long arg)
>   /* check new channel request in d->chan_pending */
>   spin_lock_irq(>lock);
>   for (pch = 0; pch < d->dma_channels; pch++) {
> + if (!(d->dma_channel_mask & (1< + continue;
> +
>   p = >phy[pch];
>  
>   if (p->vchan == NULL && !list_empty(>chan_pending)) {
> @@ -336,6 +340,9 @@ static void k3_dma_tasklet(unsigned long arg)
>   spin_unlock_irq(>lock);
>  
>   for (pch = 0; pch < d->dma_channels; pch++) {
> + if (!(d->dma_channel_mask & (1< + continue;
> +
>   if (pch_alloc & (1 << pch)) {
>   p = >phy[pch];
>   c = p->vchan;
> @@ -856,6 +863,13 @@ static int k3_dma_probe(struct platform_device *op)
>   "dma-channels", >dma_channels);
>   of_property_read_u32((>dev)->of_node,
>   "dma-requests", >dma_requests);
> + ret = of_property_read_u32((>dev)->of_node,
> + "dma-channel-mask", >dma_channel_mask);
> + if (ret) {
> + dev_warn(>dev,
> +  "dma-channel-mask doesn't exist, considering 
> all as available.\n");
> + d->dma_channel_mask = (u32)~0UL;
> + }
>   }
>  
>   if (!(soc_data->flags & K3_FLAG_NOCLK)) {
> @@ -887,8 +901,12 @@ static int k3_dma_probe(struct platform_device *op)
>   return -ENOMEM;
>  
>   for (i = 0; i < d->dma_channels; i++) {
> - struct k3_dma_phy *p = >phy[i];
> + struct k3_dma_phy *p;
> +
> + if (!(d->dma_channel_mask & BIT(i)))
> + continue;
>  
> + p = >phy[i];
>   p->idx = i;
>   p->base = d->base + i * 0x40;
>   }
> -- 
> 2.7.4

-- 
~Vinod


[PATCH 5/8 v5] dma: k3dma: Add support for dma-channel-mask

2019-01-24 Thread John Stultz
From: Li Yu 

Add dma-channel-mask as a property for k3dma, it defines
available dma channels which a non-secure mode driver can use.

One sample usage of this is in Hi3660 SoC. DMA channel 0 is
reserved to lpm3, which is a coprocessor for power management. So
as a result, any request in kernel (which runs on main processor
and in non-secure mode) should start from at least channel 1.

Cc: Dan Williams 
Cc: Vinod Koul 
Cc: Tanglei Han 
Cc: Zhuangluan Su 
Cc: Ryan Grachek 
Cc: Manivannan Sadhasivam 
Cc: Guodong Xu 
Cc: dmaeng...@vger.kernel.org
Signed-off-by: Li Yu 
[jstultz: Reworked to use a channel mask]
Signed-off-by: John Stultz 
---
v3: Rename to hisi-dma-avail-chan
v4: Rename to dma-channel-mask
v5: Use BIT(i) instead of (1lock);
for (pch = 0; pch < d->dma_channels; pch++) {
+   if (!(d->dma_channel_mask & (1vchan == NULL && !list_empty(>chan_pending)) {
@@ -336,6 +340,9 @@ static void k3_dma_tasklet(unsigned long arg)
spin_unlock_irq(>lock);
 
for (pch = 0; pch < d->dma_channels; pch++) {
+   if (!(d->dma_channel_mask & (1vchan;
@@ -856,6 +863,13 @@ static int k3_dma_probe(struct platform_device *op)
"dma-channels", >dma_channels);
of_property_read_u32((>dev)->of_node,
"dma-requests", >dma_requests);
+   ret = of_property_read_u32((>dev)->of_node,
+   "dma-channel-mask", >dma_channel_mask);
+   if (ret) {
+   dev_warn(>dev,
+"dma-channel-mask doesn't exist, considering 
all as available.\n");
+   d->dma_channel_mask = (u32)~0UL;
+   }
}
 
if (!(soc_data->flags & K3_FLAG_NOCLK)) {
@@ -887,8 +901,12 @@ static int k3_dma_probe(struct platform_device *op)
return -ENOMEM;
 
for (i = 0; i < d->dma_channels; i++) {
-   struct k3_dma_phy *p = >phy[i];
+   struct k3_dma_phy *p;
+
+   if (!(d->dma_channel_mask & BIT(i)))
+   continue;
 
+   p = >phy[i];
p->idx = i;
p->base = d->base + i * 0x40;
}
-- 
2.7.4