[PATCH v8 2/3] clk: stm32mp25: add firewall grant_access ops

Clément Le Goffic posted 3 patches 1 week ago
[PATCH v8 2/3] clk: stm32mp25: add firewall grant_access ops
Posted by Clément Le Goffic 1 week ago
From: Clément Le Goffic <clement.legoffic@foss.st.com>

On STM32MP25, the RCC peripheral manages the secure level of resources
that are used by other devices such as clocks.
Declare this peripheral as a firewall controller.

Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com>
Signed-off-by: Clément Le Goffic <legoffic.clement@gmail.com>
---
 drivers/clk/stm32/clk-stm32mp25.c | 40 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/stm32/clk-stm32mp25.c b/drivers/clk/stm32/clk-stm32mp25.c
index 52f0e8a12926..af4bc06d703a 100644
--- a/drivers/clk/stm32/clk-stm32mp25.c
+++ b/drivers/clk/stm32/clk-stm32mp25.c
@@ -4,8 +4,10 @@
  * Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
  */
 
+#include <linux/bus/stm32_firewall.h>
 #include <linux/bus/stm32_firewall_device.h>
 #include <linux/clk-provider.h>
+#include <linux/device.h>
 #include <linux/io.h>
 #include <linux/platform_device.h>
 
@@ -1602,6 +1604,11 @@ static int stm32_rcc_get_access(void __iomem *base, u32 index)
 	return 0;
 }
 
+static int stm32mp25_rcc_grant_access(struct stm32_firewall_controller *ctrl, u32 firewall_id)
+{
+	return stm32_rcc_get_access(ctrl->mmio, firewall_id);
+}
+
 static int stm32mp25_check_security(struct device_node *np, void __iomem *base,
 				    const struct clock_config *cfg)
 {
@@ -1970,6 +1977,7 @@ MODULE_DEVICE_TABLE(of, stm32mp25_match_data);
 
 static int stm32mp25_rcc_clocks_probe(struct platform_device *pdev)
 {
+	struct stm32_firewall_controller *rcc_controller;
 	struct device *dev = &pdev->dev;
 	void __iomem *base;
 	int ret;
@@ -1982,7 +1990,36 @@ static int stm32mp25_rcc_clocks_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	return stm32_rcc_init(dev, stm32mp25_match_data, base);
+	ret = stm32_rcc_init(dev, stm32mp25_match_data, base);
+	if (ret)
+		return ret;
+
+	rcc_controller = devm_kzalloc(&pdev->dev, sizeof(*rcc_controller), GFP_KERNEL);
+	if (!rcc_controller)
+		return -ENOMEM;
+
+	rcc_controller->dev = dev;
+	rcc_controller->mmio = base;
+	rcc_controller->name = dev_driver_string(dev);
+	rcc_controller->type = STM32_PERIPHERAL_FIREWALL;
+	rcc_controller->grant_access = stm32mp25_rcc_grant_access;
+
+	platform_set_drvdata(pdev, rcc_controller);
+
+	ret = stm32_firewall_controller_register(rcc_controller);
+	if (ret) {
+		dev_err(dev, "Couldn't register as a firewall controller: %d\n", ret);
+		return ret;
+	}
+
+	return 0;
+}
+
+static void stm32mp25_rcc_clocks_remove(struct platform_device *pdev)
+{
+	struct stm32_firewall_controller *rcc_controller = platform_get_drvdata(pdev);
+
+	stm32_firewall_controller_unregister(rcc_controller);
 }
 
 static struct platform_driver stm32mp25_rcc_clocks_driver = {
@@ -1991,6 +2028,7 @@ static struct platform_driver stm32mp25_rcc_clocks_driver = {
 		.of_match_table = stm32mp25_match_data,
 	},
 	.probe = stm32mp25_rcc_clocks_probe,
+	.remove = stm32mp25_rcc_clocks_remove,
 };
 
 static int __init stm32mp25_clocks_init(void)

-- 
2.43.0

Re: [PATCH v8 2/3] clk: stm32mp25: add firewall grant_access ops
Posted by Gabriel FERNANDEZ 1 day, 18 hours ago
On 9/24/25 11:44, Clément Le Goffic wrote:
> From: Clément Le Goffic <clement.legoffic@foss.st.com>
>
> On STM32MP25, the RCC peripheral manages the secure level of resources
> that are used by other devices such as clocks.
> Declare this peripheral as a firewall controller.
>
> Signed-off-by: Clément Le Goffic <clement.legoffic@foss.st.com>
> Signed-off-by: Clément Le Goffic <legoffic.clement@gmail.com>
> ---

Hi Clément,

You can add

Reviewed-by: Gabriel Fernandez <gabriel.fernandez@foss.st.com>

Many Thanks!


>   drivers/clk/stm32/clk-stm32mp25.c | 40 ++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 39 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/clk/stm32/clk-stm32mp25.c b/drivers/clk/stm32/clk-stm32mp25.c
> index 52f0e8a12926..af4bc06d703a 100644
> --- a/drivers/clk/stm32/clk-stm32mp25.c
> +++ b/drivers/clk/stm32/clk-stm32mp25.c
> @@ -4,8 +4,10 @@
>    * Author: Gabriel Fernandez <gabriel.fernandez@foss.st.com> for STMicroelectronics.
>    */
>   
> +#include <linux/bus/stm32_firewall.h>
>   #include <linux/bus/stm32_firewall_device.h>
>   #include <linux/clk-provider.h>
> +#include <linux/device.h>
>   #include <linux/io.h>
>   #include <linux/platform_device.h>
>   
> @@ -1602,6 +1604,11 @@ static int stm32_rcc_get_access(void __iomem *base, u32 index)
>   	return 0;
>   }
>   
> +static int stm32mp25_rcc_grant_access(struct stm32_firewall_controller *ctrl, u32 firewall_id)
> +{
> +	return stm32_rcc_get_access(ctrl->mmio, firewall_id);
> +}
> +
>   static int stm32mp25_check_security(struct device_node *np, void __iomem *base,
>   				    const struct clock_config *cfg)
>   {
> @@ -1970,6 +1977,7 @@ MODULE_DEVICE_TABLE(of, stm32mp25_match_data);
>   
>   static int stm32mp25_rcc_clocks_probe(struct platform_device *pdev)
>   {
> +	struct stm32_firewall_controller *rcc_controller;
>   	struct device *dev = &pdev->dev;
>   	void __iomem *base;
>   	int ret;
> @@ -1982,7 +1990,36 @@ static int stm32mp25_rcc_clocks_probe(struct platform_device *pdev)
>   	if (ret)
>   		return ret;
>   
> -	return stm32_rcc_init(dev, stm32mp25_match_data, base);
> +	ret = stm32_rcc_init(dev, stm32mp25_match_data, base);
> +	if (ret)
> +		return ret;
> +
> +	rcc_controller = devm_kzalloc(&pdev->dev, sizeof(*rcc_controller), GFP_KERNEL);
> +	if (!rcc_controller)
> +		return -ENOMEM;
> +
> +	rcc_controller->dev = dev;
> +	rcc_controller->mmio = base;
> +	rcc_controller->name = dev_driver_string(dev);
> +	rcc_controller->type = STM32_PERIPHERAL_FIREWALL;
> +	rcc_controller->grant_access = stm32mp25_rcc_grant_access;
> +
> +	platform_set_drvdata(pdev, rcc_controller);
> +
> +	ret = stm32_firewall_controller_register(rcc_controller);
> +	if (ret) {
> +		dev_err(dev, "Couldn't register as a firewall controller: %d\n", ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static void stm32mp25_rcc_clocks_remove(struct platform_device *pdev)
> +{
> +	struct stm32_firewall_controller *rcc_controller = platform_get_drvdata(pdev);
> +
> +	stm32_firewall_controller_unregister(rcc_controller);
>   }
>   
>   static struct platform_driver stm32mp25_rcc_clocks_driver = {
> @@ -1991,6 +2028,7 @@ static struct platform_driver stm32mp25_rcc_clocks_driver = {
>   		.of_match_table = stm32mp25_match_data,
>   	},
>   	.probe = stm32mp25_rcc_clocks_probe,
> +	.remove = stm32mp25_rcc_clocks_remove,
>   };
>   
>   static int __init stm32mp25_clocks_init(void)
>