From: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
To: Pankaj Gupta <pankaj.gupta@nxp.com>,
shawnguo@kernel.org, s.hauer@pengutronix.de,
kernel@pengutronix.de, clin@suse.com, conor+dt@kernel.org,
pierre.gondois@arm.com, ping.bai@nxp.com, xiaoning.wang@nxp.com,
wei.fang@nxp.com, peng.fan@nxp.com, haibo.chen@nxp.com,
festevam@gmail.com, linux-imx@nxp.com, davem@davemloft.net,
robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org,
linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, gaurav.jain@nxp.com,
alexander.stein@ew.tq-group.com, sahil.malhotra@nxp.com,
aisheng.dong@nxp.com, V.Sethi@nxp.com
Subject: Re: [PATCH v5 07/11] firmware: imx: init-fw api exchange on imx93
Date: Thu, 24 Aug 2023 20:35:08 +0200 [thread overview]
Message-ID: <b20852ee-068f-5fd0-ad3d-c74e236c1f87@linaro.org> (raw)
In-Reply-To: <20230823073330.1712721-8-pankaj.gupta@nxp.com>
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@nxp.com>
> ---
> 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
next prev parent reply other threads:[~2023-08-24 18:36 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-23 7:33 [PATCH v5 00/11] firmware: imx: NXP Secure-Enclave FW Driver Pankaj Gupta
2023-08-23 7:33 ` [PATCH v5 01/11] dt-bindings: arm: fsl: add imx-se-fw binding doc Pankaj Gupta
2023-08-23 8:28 ` Rob Herring
2023-08-23 10:42 ` [EXT] " Pankaj Gupta
2023-08-23 12:43 ` Rob Herring
2023-08-24 18:45 ` Krzysztof Kozlowski
2023-08-24 19:23 ` Greg Kroah-Hartman
2023-08-28 6:00 ` [EXT] " Varun Sethi
2023-08-28 6:55 ` Krzysztof Kozlowski
2023-08-28 9:14 ` Varun Sethi
[not found] ` <DU2PR04MB86302A2639CA64D8DF08BF0495E3A@DU2PR04MB8630.eurprd04.prod.outlook.com>
2023-08-25 7:56 ` Varun Sethi
2023-08-23 7:33 ` [PATCH v5 02/11] arm64: dts: imx8ulp-evk: added nxp secure enclave firmware Pankaj Gupta
2023-08-23 7:33 ` [PATCH v5 03/11] arm64: dts: imx8ulp-evk: reserved mem-ranges to constrain ele_fw dma-range Pankaj Gupta
2023-08-23 7:33 ` [PATCH v5 04/11] arm64: dts: imx93-11x11-evk: added nxp secure enclave fw Pankaj Gupta
2023-08-23 7:33 ` [PATCH v5 05/11] arm64: dts: imx93-11x11-evk: reserved mem-ranges to constrain ele_fw dma-range Pankaj Gupta
2023-08-23 7:33 ` [PATCH v5 06/11] firmware: imx: add driver for NXP EdgeLock Enclave Pankaj Gupta
2023-08-24 18:31 ` Krzysztof Kozlowski
2023-08-25 10:22 ` Stefan Wahren
2023-08-25 15:16 ` Conor Dooley
2023-08-23 7:33 ` [PATCH v5 07/11] firmware: imx: init-fw api exchange on imx93 Pankaj Gupta
2023-08-24 18:35 ` Krzysztof Kozlowski [this message]
2023-08-23 7:33 ` [PATCH v5 08/11] firmware: imx: enable trng Pankaj Gupta
2023-08-24 18:23 ` Krzysztof Kozlowski
2023-08-23 7:33 ` [PATCH v5 09/11] firmware: imx: enclave-fw: add handling for save/restore IMEM region Pankaj Gupta
2023-08-24 18:37 ` Krzysztof Kozlowski
2023-08-23 7:33 ` [PATCH v5 10/11] firmware: imx: enclave api to read-common-fuses Pankaj Gupta
2023-08-24 18:38 ` Krzysztof Kozlowski
2023-08-23 7:33 ` [PATCH v5 11/11] MAINTAINERS: Added maintainer details Pankaj Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b20852ee-068f-5fd0-ad3d-c74e236c1f87@linaro.org \
--to=krzysztof.kozlowski@linaro.org \
--cc=V.Sethi@nxp.com \
--cc=aisheng.dong@nxp.com \
--cc=alexander.stein@ew.tq-group.com \
--cc=clin@suse.com \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=gaurav.jain@nxp.com \
--cc=haibo.chen@nxp.com \
--cc=kernel@pengutronix.de \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=pankaj.gupta@nxp.com \
--cc=peng.fan@nxp.com \
--cc=pierre.gondois@arm.com \
--cc=ping.bai@nxp.com \
--cc=robh+dt@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=sahil.malhotra@nxp.com \
--cc=shawnguo@kernel.org \
--cc=wei.fang@nxp.com \
--cc=xiaoning.wang@nxp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).