linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: stm32-mdma: check the channel availability (secure or not)
@ 2022-01-17 10:03 Amelie Delaunay
  2022-02-23 10:46 ` Amelie DELAUNAY
  0 siblings, 1 reply; 4+ messages in thread
From: Amelie Delaunay @ 2022-01-17 10:03 UTC (permalink / raw)
  To: Vinod Koul, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel, Amelie Delaunay

STM32_MDMA_CCR bit[8] is used to enable Secure Mode (SM). If this bit is
set, it means that all the channel registers are write-protected. So the
channel is not available for Linux use.

Add stm32_mdma_filter_fn() callback filter and give it to
__dma_request_chan (instead of dma_get_any_slave_channel()), to exclude the
channel if it is marked Secure.

Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
---
 drivers/dma/stm32-mdma.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 6f57ff0e7b37..95e5831e490a 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -73,6 +73,7 @@
 #define STM32_MDMA_CCR_WEX		BIT(14)
 #define STM32_MDMA_CCR_HEX		BIT(13)
 #define STM32_MDMA_CCR_BEX		BIT(12)
+#define STM32_MDMA_CCR_SM		BIT(8)
 #define STM32_MDMA_CCR_PL_MASK		GENMASK(7, 6)
 #define STM32_MDMA_CCR_PL(n)		FIELD_PREP(STM32_MDMA_CCR_PL_MASK, (n))
 #define STM32_MDMA_CCR_TCIE		BIT(5)
@@ -248,6 +249,7 @@ struct stm32_mdma_device {
 	u32 nr_channels;
 	u32 nr_requests;
 	u32 nr_ahb_addr_masks;
+	u32 chan_reserved;
 	struct stm32_mdma_chan chan[STM32_MDMA_MAX_CHANNELS];
 	u32 ahb_addr_masks[];
 };
@@ -1456,10 +1458,23 @@ static void stm32_mdma_free_chan_resources(struct dma_chan *c)
 	chan->desc_pool = NULL;
 }
 
+static bool stm32_mdma_filter_fn(struct dma_chan *c, void *fn_param)
+{
+	struct stm32_mdma_chan *chan = to_stm32_mdma_chan(c);
+	struct stm32_mdma_device *dmadev = stm32_mdma_get_dev(chan);
+
+	/* Check if chan is marked Secure */
+	if (dmadev->chan_reserved & BIT(chan->id))
+		return false;
+
+	return true;
+}
+
 static struct dma_chan *stm32_mdma_of_xlate(struct of_phandle_args *dma_spec,
 					    struct of_dma *ofdma)
 {
 	struct stm32_mdma_device *dmadev = ofdma->of_dma_data;
+	dma_cap_mask_t mask = dmadev->ddev.cap_mask;
 	struct stm32_mdma_chan *chan;
 	struct dma_chan *c;
 	struct stm32_mdma_chan_config config;
@@ -1485,7 +1500,7 @@ static struct dma_chan *stm32_mdma_of_xlate(struct of_phandle_args *dma_spec,
 		return NULL;
 	}
 
-	c = dma_get_any_slave_channel(&dmadev->ddev);
+	c = __dma_request_channel(&mask, stm32_mdma_filter_fn, &config, ofdma->of_node);
 	if (!c) {
 		dev_err(mdma2dev(dmadev), "No more channels available\n");
 		return NULL;
@@ -1615,6 +1630,10 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 	for (i = 0; i < dmadev->nr_channels; i++) {
 		chan = &dmadev->chan[i];
 		chan->id = i;
+
+		if (stm32_mdma_read(dmadev, STM32_MDMA_CCR(i)) & STM32_MDMA_CCR_SM)
+			dmadev->chan_reserved |= BIT(i);
+
 		chan->vchan.desc_free = stm32_mdma_desc_free;
 		vchan_init(&chan->vchan, dd);
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] dmaengine: stm32-mdma: check the channel availability (secure or not)
  2022-01-17 10:03 [PATCH] dmaengine: stm32-mdma: check the channel availability (secure or not) Amelie Delaunay
@ 2022-02-23 10:46 ` Amelie DELAUNAY
  0 siblings, 0 replies; 4+ messages in thread
From: Amelie DELAUNAY @ 2022-02-23 10:46 UTC (permalink / raw)
  To: Vinod Koul, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel

Hi,

Kind reminder.

Regards,
Amelie

On 1/17/22 11:03, Amelie Delaunay wrote:
> STM32_MDMA_CCR bit[8] is used to enable Secure Mode (SM). If this bit is
> set, it means that all the channel registers are write-protected. So the
> channel is not available for Linux use.
> 
> Add stm32_mdma_filter_fn() callback filter and give it to
> __dma_request_chan (instead of dma_get_any_slave_channel()), to exclude the
> channel if it is marked Secure.
> 
> Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
> ---
>   drivers/dma/stm32-mdma.c | 21 ++++++++++++++++++++-
>   1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
> index 6f57ff0e7b37..95e5831e490a 100644
> --- a/drivers/dma/stm32-mdma.c
> +++ b/drivers/dma/stm32-mdma.c
> @@ -73,6 +73,7 @@
>   #define STM32_MDMA_CCR_WEX		BIT(14)
>   #define STM32_MDMA_CCR_HEX		BIT(13)
>   #define STM32_MDMA_CCR_BEX		BIT(12)
> +#define STM32_MDMA_CCR_SM		BIT(8)
>   #define STM32_MDMA_CCR_PL_MASK		GENMASK(7, 6)
>   #define STM32_MDMA_CCR_PL(n)		FIELD_PREP(STM32_MDMA_CCR_PL_MASK, (n))
>   #define STM32_MDMA_CCR_TCIE		BIT(5)
> @@ -248,6 +249,7 @@ struct stm32_mdma_device {
>   	u32 nr_channels;
>   	u32 nr_requests;
>   	u32 nr_ahb_addr_masks;
> +	u32 chan_reserved;
>   	struct stm32_mdma_chan chan[STM32_MDMA_MAX_CHANNELS];
>   	u32 ahb_addr_masks[];
>   };
> @@ -1456,10 +1458,23 @@ static void stm32_mdma_free_chan_resources(struct dma_chan *c)
>   	chan->desc_pool = NULL;
>   }
>   
> +static bool stm32_mdma_filter_fn(struct dma_chan *c, void *fn_param)
> +{
> +	struct stm32_mdma_chan *chan = to_stm32_mdma_chan(c);
> +	struct stm32_mdma_device *dmadev = stm32_mdma_get_dev(chan);
> +
> +	/* Check if chan is marked Secure */
> +	if (dmadev->chan_reserved & BIT(chan->id))
> +		return false;
> +
> +	return true;
> +}
> +
>   static struct dma_chan *stm32_mdma_of_xlate(struct of_phandle_args *dma_spec,
>   					    struct of_dma *ofdma)
>   {
>   	struct stm32_mdma_device *dmadev = ofdma->of_dma_data;
> +	dma_cap_mask_t mask = dmadev->ddev.cap_mask;
>   	struct stm32_mdma_chan *chan;
>   	struct dma_chan *c;
>   	struct stm32_mdma_chan_config config;
> @@ -1485,7 +1500,7 @@ static struct dma_chan *stm32_mdma_of_xlate(struct of_phandle_args *dma_spec,
>   		return NULL;
>   	}
>   
> -	c = dma_get_any_slave_channel(&dmadev->ddev);
> +	c = __dma_request_channel(&mask, stm32_mdma_filter_fn, &config, ofdma->of_node);
>   	if (!c) {
>   		dev_err(mdma2dev(dmadev), "No more channels available\n");
>   		return NULL;
> @@ -1615,6 +1630,10 @@ static int stm32_mdma_probe(struct platform_device *pdev)
>   	for (i = 0; i < dmadev->nr_channels; i++) {
>   		chan = &dmadev->chan[i];
>   		chan->id = i;
> +
> +		if (stm32_mdma_read(dmadev, STM32_MDMA_CCR(i)) & STM32_MDMA_CCR_SM)
> +			dmadev->chan_reserved |= BIT(i);
> +
>   		chan->vchan.desc_free = stm32_mdma_desc_free;
>   		vchan_init(&chan->vchan, dd);
>   	}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] dmaengine: stm32-mdma: check the channel availability (secure or not)
  2022-03-30 10:36 Amelie Delaunay
@ 2022-04-11 13:28 ` Vinod Koul
  0 siblings, 0 replies; 4+ messages in thread
From: Vinod Koul @ 2022-04-11 13:28 UTC (permalink / raw)
  To: Amelie Delaunay
  Cc: Maxime Coquelin, Alexandre Torgue, dmaengine, linux-stm32,
	linux-arm-kernel, linux-kernel

On 30-03-22, 12:36, Amelie Delaunay wrote:
> STM32_MDMA_CCR bit[8] is used to enable Secure Mode (SM). If this bit is
> set, it means that all the channel registers are write-protected. So the
> channel is not available for Linux use.
> 
> Add stm32_mdma_filter_fn() callback filter and give it to
> __dma_request_chan (instead of dma_get_any_slave_channel()), to exclude the
> channel if it is marked Secure.

Applied, thanks

-- 
~Vinod

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] dmaengine: stm32-mdma: check the channel availability (secure or not)
@ 2022-03-30 10:36 Amelie Delaunay
  2022-04-11 13:28 ` Vinod Koul
  0 siblings, 1 reply; 4+ messages in thread
From: Amelie Delaunay @ 2022-03-30 10:36 UTC (permalink / raw)
  To: Vinod Koul, Maxime Coquelin, Alexandre Torgue
  Cc: dmaengine, linux-stm32, linux-arm-kernel, linux-kernel, Amelie Delaunay

STM32_MDMA_CCR bit[8] is used to enable Secure Mode (SM). If this bit is
set, it means that all the channel registers are write-protected. So the
channel is not available for Linux use.

Add stm32_mdma_filter_fn() callback filter and give it to
__dma_request_chan (instead of dma_get_any_slave_channel()), to exclude the
channel if it is marked Secure.

Signed-off-by: Amelie Delaunay <amelie.delaunay@foss.st.com>
---
Already sent few weeks ago. No change since
https://lore.kernel.org/lkml/20220117100300.14150-1-amelie.delaunay@foss.st.com/
---
 drivers/dma/stm32-mdma.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/stm32-mdma.c b/drivers/dma/stm32-mdma.c
index 6f57ff0e7b37..95e5831e490a 100644
--- a/drivers/dma/stm32-mdma.c
+++ b/drivers/dma/stm32-mdma.c
@@ -73,6 +73,7 @@
 #define STM32_MDMA_CCR_WEX		BIT(14)
 #define STM32_MDMA_CCR_HEX		BIT(13)
 #define STM32_MDMA_CCR_BEX		BIT(12)
+#define STM32_MDMA_CCR_SM		BIT(8)
 #define STM32_MDMA_CCR_PL_MASK		GENMASK(7, 6)
 #define STM32_MDMA_CCR_PL(n)		FIELD_PREP(STM32_MDMA_CCR_PL_MASK, (n))
 #define STM32_MDMA_CCR_TCIE		BIT(5)
@@ -248,6 +249,7 @@ struct stm32_mdma_device {
 	u32 nr_channels;
 	u32 nr_requests;
 	u32 nr_ahb_addr_masks;
+	u32 chan_reserved;
 	struct stm32_mdma_chan chan[STM32_MDMA_MAX_CHANNELS];
 	u32 ahb_addr_masks[];
 };
@@ -1456,10 +1458,23 @@ static void stm32_mdma_free_chan_resources(struct dma_chan *c)
 	chan->desc_pool = NULL;
 }
 
+static bool stm32_mdma_filter_fn(struct dma_chan *c, void *fn_param)
+{
+	struct stm32_mdma_chan *chan = to_stm32_mdma_chan(c);
+	struct stm32_mdma_device *dmadev = stm32_mdma_get_dev(chan);
+
+	/* Check if chan is marked Secure */
+	if (dmadev->chan_reserved & BIT(chan->id))
+		return false;
+
+	return true;
+}
+
 static struct dma_chan *stm32_mdma_of_xlate(struct of_phandle_args *dma_spec,
 					    struct of_dma *ofdma)
 {
 	struct stm32_mdma_device *dmadev = ofdma->of_dma_data;
+	dma_cap_mask_t mask = dmadev->ddev.cap_mask;
 	struct stm32_mdma_chan *chan;
 	struct dma_chan *c;
 	struct stm32_mdma_chan_config config;
@@ -1485,7 +1500,7 @@ static struct dma_chan *stm32_mdma_of_xlate(struct of_phandle_args *dma_spec,
 		return NULL;
 	}
 
-	c = dma_get_any_slave_channel(&dmadev->ddev);
+	c = __dma_request_channel(&mask, stm32_mdma_filter_fn, &config, ofdma->of_node);
 	if (!c) {
 		dev_err(mdma2dev(dmadev), "No more channels available\n");
 		return NULL;
@@ -1615,6 +1630,10 @@ static int stm32_mdma_probe(struct platform_device *pdev)
 	for (i = 0; i < dmadev->nr_channels; i++) {
 		chan = &dmadev->chan[i];
 		chan->id = i;
+
+		if (stm32_mdma_read(dmadev, STM32_MDMA_CCR(i)) & STM32_MDMA_CCR_SM)
+			dmadev->chan_reserved |= BIT(i);
+
 		chan->vchan.desc_free = stm32_mdma_desc_free;
 		vchan_init(&chan->vchan, dd);
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-11 13:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17 10:03 [PATCH] dmaengine: stm32-mdma: check the channel availability (secure or not) Amelie Delaunay
2022-02-23 10:46 ` Amelie DELAUNAY
2022-03-30 10:36 Amelie Delaunay
2022-04-11 13:28 ` Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).