[PATCH v11 5/7] se_ctrl.c

Pankaj Gupta pankaj.gupta at nxp.com
Mon Jan 20 01:17:48 PST 2025


Ran "b4 send --reflect"
But it sent to all.
Please ignore.

-----Original Message-----
From: Pankaj Gupta
Sent: Monday, January 20, 2025 2:46 PM
To: Jonathan Corbet <corbet at lwn.net>; Rob Herring <robh at kernel.org>; Krzysztof 
Kozlowski <krzk+dt at kernel.org>; Conor Dooley <conor+dt at kernel.org>; Shawn Guo 
<shawnguo at kernel.org>; Sascha Hauer <s.hauer at pengutronix.de>; Pengutronix 
Kernel Team <kernel at pengutronix.de>; Fabio Estevam <festevam at gmail.com>; 
Pankaj Gupta <pankaj.gupta at nxp.com>
Cc: linux-doc at vger.kernel.org; linux-kernel at vger.kernel.org; 
devicetree at vger.kernel.org; imx at lists.linux.dev; 
linux-arm-kernel at lists.infradead.org
Subject: [PATCH v11 5/7] se_ctrl.c

Signed-off-by: Pankaj Gupta <pankaj.gupta at nxp.com>
---
 drivers/firmware/imx/se_ctrl.c | 62 
++++++++++++++++++++----------------------
 1 file changed, 30 insertions(+), 32 deletions(-)

diff --git a/drivers/firmware/imx/se_ctrl.c b/drivers/firmware/imx/se_ctrl.c 
index 7260a9f93e06..7f6b9199e6ac 100644
--- a/drivers/firmware/imx/se_ctrl.c
+++ b/drivers/firmware/imx/se_ctrl.c
@@ -42,7 +42,7 @@ struct se_fw_img_name {  struct se_fw_load_info {
 	const struct se_fw_img_name *se_fw_img_nm;
 	bool is_fw_loaded;
-	bool handle_susp_resm;
+	bool imem_mgmt;
 	struct se_imem_buf imem;
 };

@@ -73,7 +73,7 @@ static struct se_var_info var_se_info = {
 	.soc_rev = 0,
 	.load_fw = {
 		.is_fw_loaded = true,
-		.handle_susp_resm = false,
+		.imem_mgmt = false,
 	},
 };

@@ -140,10 +140,15 @@ static const struct of_device_id se_match[] = {
 	{},
 };

+static struct se_fw_load_info *get_load_fw_instance(struct se_if_priv
+*priv) {
+	return &var_se_info.load_fw;
+}
+
 static int se_soc_info(struct se_if_priv *priv)  {
-	const struct se_if_node_info_list *info_list
-			= device_get_match_data(priv->dev);
+	const struct se_if_node_info_list *info_list = 
device_get_match_data(priv->dev);
+	struct se_fw_load_info *load_fw = get_load_fw_instance(priv);
 	struct soc_device_attribute *attr;
 	struct ele_dev_info *s_info;
 	struct soc_device *sdev;
@@ -164,6 +169,7 @@ static int se_soc_info(struct se_if_priv *priv)
 		}
 		s_info = (void *)data;
 		var_se_info.soc_rev = s_info->d_info.soc_rev;
+		load_fw->imem.state = s_info->d_addn_info.imem_state;
 	} else {
 		dev_err(priv->dev, "Failed to fetch SoC revision.");
 		if (info_list->soc_register)
@@ -219,11 +225,6 @@ static int se_soc_info(struct se_if_priv *priv)
 	return 0;
 }

-static struct se_fw_load_info *get_load_fw_instance(struct se_if_priv 
*priv) -{
-	return &var_se_info.load_fw;
-}
-
 static int se_load_firmware(struct se_if_priv *priv)  {
 	struct se_fw_load_info *load_fw = get_load_fw_instance(priv); @@ -237,21 
+238,9 @@ static int se_load_firmware(struct se_if_priv *priv)
 		return 0;

 	se_img_file_to_load = load_fw->se_fw_img_nm->seco_fw_nm_in_rfs;
-	if (load_fw->se_fw_img_nm->prim_fw_nm_in_rfs) {
-		/* allocate buffer where SE store encrypted IMEM */
-		load_fw->imem.buf = dmam_alloc_coherent(priv->dev, ELE_IMEM_SIZE,
-							&load_fw->imem.phyaddr,
-							GFP_KERNEL);
-		if (!load_fw->imem.buf) {
-			dev_err(priv->dev,
-				"dmam-alloc-failed: To store encr-IMEM.\n");
-			ret = -ENOMEM;
-			goto exit;
-		}
-		if (load_fw->imem.state == ELE_IMEM_STATE_BAD)
-			se_img_file_to_load
-					= load_fw->se_fw_img_nm->prim_fw_nm_in_rfs;
-	}
+	if (load_fw->se_fw_img_nm->prim_fw_nm_in_rfs &&
+			load_fw->imem.state == ELE_IMEM_STATE_BAD)
+		se_img_file_to_load = load_fw->se_fw_img_nm->prim_fw_nm_in_rfs;

 	do {
 		ret = request_firmware(&fw, se_img_file_to_load, priv->dev); @@ -467,8 
+456,21 @@ static int se_if_probe(struct platform_device *pdev)
 			info_list->se_fw_img_nm.seco_fw_nm_in_rfs) {
 		load_fw = get_load_fw_instance(priv);
 		load_fw->se_fw_img_nm = &info_list->se_fw_img_nm;
-
 		load_fw->is_fw_loaded = false;
+
+		if (info_list->se_fw_img_nm.prim_fw_nm_in_rfs) {
+			/* allocate buffer where SE store encrypted IMEM */
+			load_fw->imem.buf = dmam_alloc_coherent(priv->dev, ELE_IMEM_SIZE,
+								&load_fw->imem.phyaddr,
+								GFP_KERNEL);
+			if (!load_fw->imem.buf) {
+				dev_err(priv->dev,
+					"dmam-alloc-failed: To store encr-IMEM.\n");
+				ret = -ENOMEM;
+				goto exit;
+			}
+			load_fw->imem_mgmt = true;
+		}
 	}
 	dev_info(dev, "i.MX secure-enclave: %s%d interface to firmware, 
configured.\n",
 			SE_TYPE_STR_HSM,
@@ -494,13 +496,9 @@ static int se_suspend(struct device *dev)

 	load_fw = get_load_fw_instance(priv);

-	if (load_fw->handle_susp_resm) {
+	if (load_fw->imem_mgmt)
 		ret = se_save_imem_state(priv, &load_fw->imem);
-		if (ret < 0)
-			goto exit;
-		load_fw->imem.size = ret;
-	}
-exit:
+
 	return ret;
 }

@@ -511,7 +509,7 @@ static int se_resume(struct device *dev)

 	load_fw = get_load_fw_instance(priv);

-	if (load_fw->handle_susp_resm)
+	if (load_fw->imem_mgmt)
 		se_restore_imem_state(priv, &load_fw->imem);

 	return 0;

--
2.34.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 11094 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20250120/ff47b952/attachment.p7s>


More information about the linux-arm-kernel mailing list