diff mbox series

[v6,08/11] firmware: imx: init-fw api exchange on imx93

Message ID 20230927175401.1962733-9-pankaj.gupta@nxp.com (mailing list archive)
State New, archived
Headers show
Series firmware: imx: NXP Secure-Enclave FW Driver | expand

Commit Message

Pankaj Gupta Sept. 27, 2023, 5:53 p.m. UTC
On imx93 platforms, exchange init-fw message with enclave's firmware
is to be done.

Signed-off-by: Pankaj Gupta <pankaj.gupta@nxp.com>
---
 drivers/firmware/imx/Makefile     |  2 +-
 drivers/firmware/imx/ele_fw_api.c | 51 +++++++++++++++++++++++++++++++
 drivers/firmware/imx/ele_fw_api.h | 20 ++++++++++++
 drivers/firmware/imx/se_fw.c      | 13 +++++++-
 4 files changed, 84 insertions(+), 2 deletions(-)
 create mode 100644 drivers/firmware/imx/ele_fw_api.c
 create mode 100644 drivers/firmware/imx/ele_fw_api.h
diff mbox series

Patch

diff --git a/drivers/firmware/imx/Makefile b/drivers/firmware/imx/Makefile
index 77ec0f922788..d61f06a8050a 100644
--- a/drivers/firmware/imx/Makefile
+++ b/drivers/firmware/imx/Makefile
@@ -1,5 +1,5 @@ 
 # SPDX-License-Identifier: GPL-2.0
 obj-$(CONFIG_IMX_DSP)		+= imx-dsp.o
 obj-$(CONFIG_IMX_SCU)		+= imx-scu.o misc.o imx-scu-irq.o rm.o imx-scu-soc.o
-sec_enclave-objs		= se_fw.o ele_common.o ele_base_msg.o
+sec_enclave-objs		= se_fw.o ele_common.o ele_base_msg.o ele_fw_api.o
 obj-${CONFIG_IMX_SEC_ENCLAVE}	+= sec_enclave.o
diff --git a/drivers/firmware/imx/ele_fw_api.c b/drivers/firmware/imx/ele_fw_api.c
new file mode 100644
index 000000000000..55dda9d6531a
--- /dev/null
+++ b/drivers/firmware/imx/ele_fw_api.c
@@ -0,0 +1,51 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright 2023 NXP
+ */
+
+#include <linux/dma-mapping.h>
+
+#include "ele_common.h"
+#include "ele_fw_api.h"
+
+int ele_init_fw(struct device *dev)
+{
+	struct ele_mu_priv *priv = dev_get_drvdata(dev);
+	unsigned int status;
+	int ret;
+
+	ret = imx_se_alloc_tx_rx_buf(priv);
+	if (ret)
+		return ret;
+
+	ret = plat_fill_cmd_msg_hdr(priv,
+				    (struct mu_hdr *)&priv->tx_msg->header,
+				    ELE_INIT_FW_REQ, ELE_INIT_FW_REQ_SZ,
+				    false);
+	if (ret)
+		goto exit;
+
+	ret = imx_ele_msg_send_rcv(priv);
+	if (ret < 0)
+		goto exit;
+
+	ret  = validate_rsp_hdr(priv,
+				priv->rx_msg->header,
+				ELE_INIT_FW_REQ,
+				ELE_INIT_FW_RSP_SZ,
+				false);
+	if (ret)
+		goto exit;
+
+	status = RES_STATUS(priv->rx_msg->data[0]);
+	if (status != priv->success_tag) {
+		dev_err(dev, "Command Id[%d], Response Failure = 0x%x",
+			ELE_INIT_FW_REQ, status);
+		ret = -1;
+	}
+
+exit:
+	imx_se_free_tx_rx_buf(priv);
+
+	return ret;
+}
diff --git a/drivers/firmware/imx/ele_fw_api.h b/drivers/firmware/imx/ele_fw_api.h
new file mode 100644
index 000000000000..21bb35b4041f
--- /dev/null
+++ b/drivers/firmware/imx/ele_fw_api.h
@@ -0,0 +1,20 @@ 
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2023 NXP
+ */
+
+#ifndef ELE_FW_API_H
+#define ELE_FW_API_H
+
+#include <linux/hw_random.h>
+
+#define MESSAGING_VERSION_7		0x7
+
+#define ELE_INIT_FW_REQ                 0x17
+#define ELE_INIT_FW_REQ_SZ              0x04
+#define ELE_INIT_FW_RSP_SZ              0x08
+
+
+int ele_init_fw(struct device *dev);
+
+#endif /* ELE_FW_API_H */
diff --git a/drivers/firmware/imx/se_fw.c b/drivers/firmware/imx/se_fw.c
index e47ad4b6ba54..c225cdc016be 100644
--- a/drivers/firmware/imx/se_fw.c
+++ b/drivers/firmware/imx/se_fw.c
@@ -24,6 +24,7 @@ 
 #include <linux/sys_soc.h>
 
 #include "se_fw.h"
+#include "ele_fw_api.h"
 
 #define SOC_ID_OF_IMX8ULP		0x084D
 #define SOC_ID_OF_IMX93			0x9300
@@ -46,6 +47,7 @@  struct imx_info {
 	uint8_t *mbox_rx_name;
 	uint8_t *pool_name;
 	bool reserved_dma_ranges;
+	bool init_fw;
 };
 
 struct imx_info_list {
@@ -73,6 +75,7 @@  static const struct imx_info_list imx8ulp_info = {
 				.mbox_rx_name = "rx",
 				.pool_name = "fsl,sram",
 				.reserved_dma_ranges = true,
+				.init_fw = false,
 			},
 	},
 };
@@ -95,8 +98,9 @@  static const struct imx_info_list imx93_info = {
 				.mbox_rx_name = "rx",
 				.pool_name = NULL,
 				.reserved_dma_ranges = true,
+				.init_fw = true,
 			},
-		},
+	},
 };
 
 static const struct of_device_id se_fw_match[] = {
@@ -1228,6 +1232,13 @@  static int se_fw_probe(struct platform_device *pdev)
 		priv->flags |= RESERVED_DMA_POOL;
 	}
 
+	if (info->init_fw) {
+		/* start initializing ele fw */
+		ret = ele_init_fw(dev);
+		if (ret)
+			dev_err(dev, "Failed to initialize ele fw.\n");
+	}
+
 	if (info->socdev) {
 		ret = imx_soc_device_register(dev, info);
 		if (ret) {