From patchwork Wed Aug 23 07:33:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pankaj Gupta X-Patchwork-Id: 13361740 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62DEEEE49AF for ; Wed, 23 Aug 2023 07:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kNaAwrtwvD+MzZpmveysgiaek6kRHPbBl21qNb/qQN8=; b=bKW0RXrZ7x+LWu oW0LF40nn2NfYAFsEEyz9GMwq/KIl5iOtaSDbeeRW9NWisXcd/s7OKJrm4Y/iz98F5PJWtKeUir/M z39U+/BRzOOt1WN721VsvpTipNTysSthy5HfJtPaC6AOAUHzeG1cABfXMZnUck3x1MuYgyLG52MmM Z9INWy5rU0bVnn2aZi5sRtfNZ8uQtbIDmE4KmN6MwT5P0I9SAlDoZn1qmUGcLtmOdtzZpKDoFawFs 0cNDIzVCpIpYKXH9+VYItUMVShvbzFDddZhxoe85cdzmcgNO5Nvwar3+jTlRcZ8wkvnZf/AA83v2m XqcHjbkph7fgJm8nYdmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qYiP3-00HTcA-1h; Wed, 23 Aug 2023 07:35:45 +0000 Received: from mail-ve1eur01on0624.outbound.protection.outlook.com ([2a01:111:f400:fe1f::624] helo=EUR01-VE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qYiOu-00HTX2-2L for linux-arm-kernel@lists.infradead.org; Wed, 23 Aug 2023 07:35:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GK4tL0lburemcdD0nPoJzZuuBdc0DqnkV3cS4ZF5tXkMda8NhfeOjAydNTurlE7B3N35I8ikeHtrJlozTV52qnWPK0WhvntRH9Z/awNApW8VFEpXEH5n3uoofAXmG850DCfe+Y69PEOzQvLkZxajkacWYZ4v6EnpKZsLRieMoeruM6oP81hZi9lY0jSUZnOlv6j8JYreBPWwfSOhWVMyi/sNT+jevwjkP2k6OdvHmPpmT+p6rUIo//B9vDsPOc3BVLOUdfJYwu5ZlfsLDbPE1bHZfBNeBklSC8/uQQBy2OZVBzQLomwzl77go7QX1viHCOfXa4ilVIxUwt/xV2+Ohw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xc2XJjUg6W5tOR6FJYggWrdO33WOdDHbAyHsk8aRNCI=; b=aB1e0M2ARkcqVr2bAODYtqAd+9a7Wbz6qGm9IeYyIo/Urw2d4kEa38IzYIvBbEhpMvX80Xwn1OIILMRN3uurEOXEZVH01ioXcR6MbJZZNNS27J+LjoL06p5rsgZZ+cevxcSe0WaqSAPcsvhbYgzQdHZXr9vUVCoCKZWPi1F/7T7qAQn3UYdLmnWoz0oD9106xLLtlNdl7hxTENVhOMiopS5bdo9GW/qzT6WnLtjB5BtYxlKIW/+fqLa0MmfbI6tm9ubwBHItxKqwUcANaYgCdPP3PIM39ej1JCjdILUvg+wNnXFa6wDxY79WZwRAKY1D6HY35zEvJrK43dkSATwsdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xc2XJjUg6W5tOR6FJYggWrdO33WOdDHbAyHsk8aRNCI=; b=iw/krKuYuXUvejxK23y8FpuYaaMbFotH1bKwZm5md1u284NFlraDwBiLm+1dJQSE+3bJ8fSOWbFBhPqgJTZO4bMGAgcnU1r9yxqx9fkBJqRAMiIgnFZLTalepofSRGcsI8Tp60gkegWYZaopBrvp7/Yu30Y94dX4GvVSB5OKh/0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DU2PR04MB8630.eurprd04.prod.outlook.com (2603:10a6:10:2dd::15) by AS1PR04MB9504.eurprd04.prod.outlook.com (2603:10a6:20b:4c6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Wed, 23 Aug 2023 07:35:33 +0000 Received: from DU2PR04MB8630.eurprd04.prod.outlook.com ([fe80::175:d311:2cb4:7915]) by DU2PR04MB8630.eurprd04.prod.outlook.com ([fe80::175:d311:2cb4:7915%7]) with mapi id 15.20.6699.026; Wed, 23 Aug 2023 07:35:33 +0000 From: Pankaj Gupta To: 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 Cc: Pankaj Gupta Subject: [PATCH v5 07/11] firmware: imx: init-fw api exchange on imx93 Date: Wed, 23 Aug 2023 13:03:26 +0530 Message-Id: <20230823073330.1712721-8-pankaj.gupta@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230823073330.1712721-1-pankaj.gupta@nxp.com> References: <20230823073330.1712721-1-pankaj.gupta@nxp.com> X-ClientProxiedBy: SI2PR01CA0036.apcprd01.prod.exchangelabs.com (2603:1096:4:192::22) To DU2PR04MB8630.eurprd04.prod.outlook.com (2603:10a6:10:2dd::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DU2PR04MB8630:EE_|AS1PR04MB9504:EE_ X-MS-Office365-Filtering-Correlation-Id: 18bf9faa-40bc-4a27-5705-08dba3ab88f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 38b0aQeWmDqi+WaYN9jEYYMLwQJOpPyqZE2aa7Pk9NvMVXhd+JmFcuqgCpCYWOuNviQr7XyI06Uqj3QBaszrtn2KYwvVEmTIzJ5G13aI9kRv39e4hEo+OG76j4BHmUyhMRBhgmoq3m/to85k+bBPukxC53L5+tAIG5zP2NTYR4XLn5auTGaSgnXVTdR8CDF/Egz3gWnL+pRRxuFPnB7HjvmRMKuRf0qLZl2AQxSBgxLq0j7BlFGv0uJ5VLtlmTonjdZELZlPf2YVDteNDFU81lhD0M3kSmDYKkq9k1CGVK+irWaOlJrnStn2LokW81eRK6OFk9yzFydsylzigIR0R7UQFhM3yoq4Dmw6HMParCDqvr+LG73Wl/PxHCkZfN1YC/7nDroqtgYZjozSXrdBi+ueaIFi8PckE76S+siuGBwm7+XiuxaO3PuAJgjTGE3QF5r5uYTB1OofVf6Sn2/Awb94W9+tYHtdhoMHBVpFJl8Dfpn2zlrD084S52UBzY2o7Zu+5yJaSYzvQnBMpwzlblCeKtPryhI9KHxOiyhjHQpRmhArQiDHWsW2U6VZESABXrdaTmkIJFVbtY3+ZOqhX+R+veJOPRQUjiXnKH+bf5U7AOwapVbn55o6wmjkI5JZ1lgSLfah6HrCeAfmc+u+Hg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU2PR04MB8630.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366004)(39860400002)(396003)(376002)(346002)(136003)(1800799009)(186009)(451199024)(36756003)(86362001)(921005)(66476007)(66946007)(66556008)(316002)(41300700001)(6636002)(478600001)(38100700002)(38350700002)(6486002)(6512007)(6666004)(6506007)(52116002)(26005)(1076003)(8676002)(2616005)(2906002)(5660300002)(7416002)(44832011)(4326008)(8936002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 33mLJ1VGzGGlxnbD2oOLKgoE7a9jYyq1ge3n9XGMfddHqAmRr7MomgnlmiWITcV3dnm3aVnyypMEeSD1OvXExDGa47F1wgbzUwtD8n969esMrytUi5UmMIetjY5W2oY93xFiZrzvrhxe9iFm+RsJoAa657TvsP9Imrf3jpfuoCKl9Kn7aRfRPF6XcNWdnobTqENStEBZWCLthIHlS2LLGl8k8csZLHyPhvJcywYU7iKv3dycuXV4zhTOCxR6KtunmJHyrqE/dTOE7vlezYtLTmddgE+bm5Um+EVOcEAB8rJauNWliEeQeeAAu0LMyUndzFdSef/fcuJ3aQYWEb2LEu4XSkV4XqhzJVZKtSk0fxjld0DEC4qfowWEJNQu7n9lySNZ4ksi7nN2DlTAYguV9yH00hGSpnj/6nHaDMhpw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pweqZAeAv0v+3QSqB8Ik7DgUq/SFy3qdyg/BryPf5hadU35Dv76m/7fquzNc6Gn+1K+9R1eEPNTymUpNe8P0/siJdDqMHYKnr7zweDnR X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 18bf9faa-40bc-4a27-5705-08dba3ab88f0 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8630.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2023 07:35:33.7491 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: KzMHZyDGhgKU57NRCRu0SKHsoiIxXinSFa8dUuSbt/vBXOF0FHLN7Zu39bxD0TCOiTFsrAcg5U2Z6FoD9Va2WA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS1PR04MB9504 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230823_003537_111387_88C970D7 X-CRM114-Status: GOOD ( 23.01 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On imx93 platforms, exchange init-fw message with enclave's firmware is to be done. Signed-off-by: Pankaj Gupta --- 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 +#include + +#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); + 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; + + 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 #include #include +#include #include #include #include @@ -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 @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2023 NXP + */ + +#ifndef ELE_FW_API_H +#define ELE_FW_API_H + +#include + +#define MESSAGING_VERSION_7 0x7 + +#define ELE_INIT_FW_REQ 0x17 +#define ELE_INIT_FW_RSP_SZ 0x2 + + +int ele_init_fw(struct device *dev); + +#endif /* ELE_FW_API_H */