mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gregory Williams <gregory.williams@amd.com>
To: Michal Simek <michal.simek@amd.com>
Cc: Senthil Nathan Thangaraj <senthilnathan.thangaraj@amd.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: [PATCH 01/15] firmware: xilinx: Separate TF-A checking
Date: Wed, 18 Nov 2026 15:31:57 -0800	[thread overview]
Message-ID: <20261118233211.4121361-2-gregory.williams@amd.com> (raw)
In-Reply-To: <20261118233211.4121361-1-gregory.williams@amd.com>

From: Senthil Nathan Thangaraj <senthilnathan.thangaraj@amd.com>

Feature check of TF-A APIs has special requirement to fill in specific
module/id and API ID based on the platform requirement.

This separation of TF-A feature checking facilitates a smoother transition
to extended SMCCC format.

Co-developed-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Senthil Nathan Thangaraj <senthilnathan.thangaraj@amd.com>
---
 drivers/firmware/xilinx/zynqmp.c | 105 +++++++++++++++++++++++++------
 1 file changed, 85 insertions(+), 20 deletions(-)

diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index 727a9888a933..940306079a78 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -214,12 +214,65 @@ static noinline int do_fw_call_hvc(u32 *ret_payload, u32 num_args, ...)
 	return zynqmp_pm_ret_code((enum pm_ret_status)res.a0);
 }
 
-static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
+/**
+ * prep_pm_hdr_feature_check - Prepare SMC header for PM_FEATURE_CHECK.
+ *
+ * TF-A expects the module field of arg[0] to be PM_MODULE_ID for its feature
+ * check, independent of the queried API's module; hence no module_id arg.
+ *
+ * Return: SMC arg[0] header value.
+ */
+static u64 prep_pm_hdr_feature_check(void)
+{
+	return PM_SIP_SVC | FIELD_PREP(MODULE_ID_MASK, PM_MODULE_ID) | PM_FEATURE_CHECK;
+}
+
+/**
+ * do_feature_check_for_tfa_apis - Perform feature check for TF-A APIs.
+ * @api_id: API ID to be checked.
+ * @ret_payload: Pointer to store the firmware's response payload.
+ *
+ * Prepares the command header and payload for TF-A APIs and makes the FW call.
+ *
+ * Return:
+ * - Feature status word from ret_payload[1] on success
+ * - -EOPNOTSUPP if the firmware call fails
+ */
+static int do_feature_check_for_tfa_apis(const u32 api_id, u32 *ret_payload)
 {
+	u64 smc_arg[2];
 	int ret;
+
+	smc_arg[0] = prep_pm_hdr_feature_check();
+	smc_arg[1] = api_id;
+
+	ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
+
+	if (ret)
+		return -EOPNOTSUPP;
+
+	return ret_payload[1];
+}
+
+/**
+ * do_feature_check_basic - Perform feature check for an API ID with
+ *			    basic SMC format.
+ * @api_id: API ID to be checked.
+ * @ret_payload: Pointer to store the firmware's response payload.
+ *
+ * Determines the appropriate API (PM_FEATURE_CHECK or PM_API_FEATURES) based on
+ * the module ID in the given API ID. Frames the SMC call arguments in the basic
+ * format, executes the firmware call, and processes the result.
+ *
+ * Return: Feature status word from ret_payload[1] on success; -EOPNOTSUPP if
+ * the firmware call fails.
+ */
+static int do_feature_check_basic(const u32 api_id, u32 *ret_payload)
+{
+	u32 feature_check_api_id;
 	u64 smc_arg[2];
 	u32 module_id;
-	u32 feature_check_api_id;
+	int ret;
 
 	module_id = FIELD_GET(MODULE_ID_MASK, api_id);
 
@@ -232,29 +285,41 @@ static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
 	else
 		feature_check_api_id = PM_API_FEATURES;
 
-	if (module_id == TF_A_MODULE_ID)
-		smc_arg[1] = api_id;
-	else
-		smc_arg[1] = (api_id & API_ID_MASK);
-
 	smc_arg[0] = PM_SIP_SVC | FIELD_PREP(MODULE_ID_MASK, module_id) | feature_check_api_id;
+	smc_arg[1] = (api_id & API_ID_MASK);
 
 	ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
+	if (ret)
+		ret = -EOPNOTSUPP;
+	else
+		ret = ret_payload[1];
 
-	/*
-	 * For TF-A APIs, if the feature check with PM_API_FEATURES fails,
-	 * retry with the legacy PM_FEATURE_CHECK for backward compatibility.
-	 */
-	if (module_id == TF_A_MODULE_ID && ret) {
-		smc_arg[0] = PM_SIP_SVC | FIELD_PREP(MODULE_ID_MASK, PM_MODULE_ID) |
-			     PM_FEATURE_CHECK;
-		ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
-	}
+	return ret;
+}
 
-	if (ret)
-		return ret;
+/**
+ * dispatch_feature_check - Dispatch feature check based on module ID.
+ * @api_id: API ID to be checked.
+ * @ret_payload: Pointer to store the firmware's response payload.
+ *
+ * Determines the appropriate feature check function to call based on the
+ * module ID extracted from the API ID. If the module ID corresponds to
+ * TF-A, it calls do_feature_check_for_tfa_apis(); otherwise, it calls
+ * do_feature_check_basic() which uses basic SMCCC format.
+ *
+ * Return: Feature status word from ret_payload[1] on success; negative error
+ * code on failure.
+ */
+static int dispatch_feature_check(const u32 api_id, u32 *ret_payload)
+{
+	u32 module_id;
 
-	return ret_payload[1];
+	module_id = FIELD_GET(MODULE_ID_MASK, api_id);
+
+	if (module_id == TF_A_MODULE_ID)
+		return do_feature_check_for_tfa_apis(api_id, ret_payload);
+
+	return do_feature_check_basic(api_id, ret_payload);
 }
 
 static int do_feature_check_call(const u32 api_id)
@@ -276,7 +341,7 @@ static int do_feature_check_call(const u32 api_id)
 		return -ENOMEM;
 
 	feature_data->pm_api_id = api_id;
-	ret = __do_feature_check_call(api_id, ret_payload);
+	ret = dispatch_feature_check(api_id, ret_payload);
 
 	feature_data->feature_status = ret;
 	hash_add(pm_api_features_map, &feature_data->hentry, api_id);
-- 
2.34.1


  reply	other threads:[~2026-11-18 23:32 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:31 [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Gregory Williams
2026-11-18 23:31 ` Gregory Williams [this message]
2026-11-18 23:31 ` [PATCH 02/15] firmware: xilinx: Call va_start after pm feature check Gregory Williams
2026-11-18 23:31 ` [PATCH 03/15] firmware: xilinx: Add comments about number of arguments Gregory Williams
2026-11-18 23:32 ` [PATCH 04/15] firmware: xilinx: Use match data for ZynqMP/Versal Gregory Williams
2026-11-18 23:32 ` [PATCH 05/15] firmware: xilinx: Rename zynqmp_pm_invoke_fw_fn() Gregory Williams
2026-11-18 23:32 ` [PATCH 06/15] dt-bindings: firmware: xilinx: Add Versal Gen 2 compatible string Gregory Williams
2026-11-18 23:32 ` [PATCH 07/15] firmware: xilinx: Add support for Versal Gen 2 Gregory Williams
2026-11-18 23:32 ` [PATCH 08/15] dt-bindings: clock: versal: add Versal Gen 2 compatible string Gregory Williams
2026-11-18 23:32 ` [PATCH 09/15] clk: zynqmp: Add " Gregory Williams
2026-11-18 23:32 ` [PATCH 10/15] drivers: firmware: xilinx: Add IOCTL support for the AIE run time operations Gregory Williams
2026-11-18 23:32 ` [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding Gregory Williams
2026-11-18 23:32 ` [PATCH 12/15] accel/amd-ai-engine: Add AMD AI Engine device driver Gregory Williams
2026-11-18 23:32 ` [PATCH 13/15] accel/amd-ai-engine: Add pm ops for firmware calls Gregory Williams
2026-11-18 23:32 ` [PATCH 14/15] accel/amd-ai-engine: Add support to enable/disable tile clocks Gregory Williams
2026-11-18 23:32 ` [PATCH 15/15] accel/amd-ai-engine: Add reset operations Gregory Williams

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=20261118233211.4121361-2-gregory.williams@amd.com \
    --to=gregory.williams@amd.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.simek@amd.com \
    --cc=senthilnathan.thangaraj@amd.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

all inboxes | Powered by JetHome®