Re: [PATCH v5 07/11] firmware: imx: init-fw api exchange on imx93

From: Krzysztof Kozlowski
Date: Thu Aug 24 2023 - 14:36:52 EST


On 23/08/2023 09:33, Pankaj Gupta wrote:
> On imx93 platforms, exchange init-fw message with enclave's firmware
> is to be done.
>
> Signed-off-by: Pankaj Gupta <pankaj.gupta@xxxxxxx>
> ---
> drivers/firmware/imx/Makefile | 2 +-
> drivers/firmware/imx/ele_fw_api.c | 56 +++++++++++++++++++++++++
> drivers/firmware/imx/se_fw.c | 11 +++++
> include/linux/firmware/imx/ele_fw_api.h | 19 +++++++++
> 4 files changed, 87 insertions(+), 1 deletion(-)
> create mode 100644 drivers/firmware/imx/ele_fw_api.c
> create mode 100644 include/linux/firmware/imx/ele_fw_api.h
>
> diff --git a/drivers/firmware/imx/Makefile b/drivers/firmware/imx/Makefile
> index eab3f03e2e5e..bc6ed5514a19 100644
> --- a/drivers/firmware/imx/Makefile
> +++ b/drivers/firmware/imx/Makefile
> @@ -2,5 +2,5 @@
> 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
> obj-$(CONFIG_IMX_SCU_PD) += scu-pd.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..1df1fbcb6d9e
> --- /dev/null
> +++ b/drivers/firmware/imx/ele_fw_api.c
> @@ -0,0 +1,56 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright 2023 NXP
> + */
> +
> +#include <linux/dma-mapping.h>
> +#include <linux/firmware/imx/ele_fw_api.h>
> +
> +#include "ele_common.h"
> +
> +/* Fill a command message header with a given command ID and length in bytes. */
> +static int plat_fill_cmd_msg_hdr(struct ele_mu_priv *priv,
> + struct mu_hdr *hdr,
> + uint8_t cmd, uint32_t len)
> +{
> + int err = 0;
> +
> + hdr->tag = priv->cmd_tag;
> + hdr->ver = MESSAGING_VERSION_7;
> + hdr->command = cmd;
> + hdr->size = (uint8_t)(len / sizeof(uint32_t));
> +
> + return err;
> +}
> +
> +int ele_init_fw(struct device *dev)
> +{
> + struct ele_mu_priv *priv = dev_get_drvdata(dev);
> + int ret;
> + unsigned int tag, command, size, ver, status;
> +
> + ret = plat_fill_cmd_msg_hdr(priv,
> + (struct mu_hdr *)&priv->tx_msg.header,
> + ELE_INIT_FW_REQ, 4);

This is some weird code. Why do you store TX and RX messages in state
container? This should be local to the function.

> + if (ret)
> + return ret;
> +
> + ret = imx_ele_msg_send_rcv(priv);
> + if (ret < 0)
> + return ret;
> +
> + tag = MSG_TAG(priv->rx_msg.header);
> + command = MSG_COMMAND(priv->rx_msg.header);
> + size = MSG_SIZE(priv->rx_msg.header);
> + ver = MSG_VER(priv->rx_msg.header);
> + status = RES_STATUS(priv->rx_msg.data[0]);
> +
> + if (tag == priv->rsp_tag
> + && command == ELE_INIT_FW_REQ
> + && size == ELE_INIT_FW_RSP_SZ
> + && ver == MESSAGING_VERSION_7
> + && status == priv->success_tag)
> + return 0;

Your coding style here and in all other places like this is unreadable.
Fix alignment.

> +
> + return -EINVAL;
> +}
> diff --git a/drivers/firmware/imx/se_fw.c b/drivers/firmware/imx/se_fw.c
> index 2c97b2adf18b..88300c41d62b 100644
> --- a/drivers/firmware/imx/se_fw.c
> +++ b/drivers/firmware/imx/se_fw.c
> @@ -8,6 +8,7 @@
> #include <linux/dev_printk.h>
> #include <linux/errno.h>
> #include <linux/export.h>
> +#include <linux/firmware/imx/ele_fw_api.h>
> #include <linux/firmware/imx/ele_base_msg.h>
> #include <linux/firmware/imx/ele_mu_ioctl.h>
> #include <linux/genalloc.h>
> @@ -41,6 +42,7 @@ struct imx_info {
> uint8_t *se_name;
> uint8_t *pool_name;
> bool reserved_dma_ranges;
> + bool init_fw;
> };
>
> static LIST_HEAD(priv_data_list);
> @@ -55,6 +57,7 @@ static const struct imx_info imx8ulp_info = {
> .se_name = "ele",
> .pool_name = "sram-pool",
> .reserved_dma_ranges = true,
> + .init_fw = false,
> };
>
> static const struct imx_info imx93_info = {
> @@ -67,6 +70,7 @@ static const struct imx_info imx93_info = {
> .se_name = "ele",
> .pool_name = NULL,
> .reserved_dma_ranges = true,
> + .init_fw = true,
> };
>
> static const struct of_device_id se_fw_match[] = {
> @@ -1120,6 +1124,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) {
> diff --git a/include/linux/firmware/imx/ele_fw_api.h b/include/linux/firmware/imx/ele_fw_api.h
> new file mode 100644
> index 000000000000..36c3f743cb38
> --- /dev/null
> +++ b/include/linux/firmware/imx/ele_fw_api.h

There is no need this to be Linux-wide. Keep it next to the driver.


Best regards,
Krzysztof