[PATCH 01/15] firmware: xilinx: Separate TF-A checking

From: Gregory Williams

Date: Wed Nov 18 2026 - 18:32:33 EST


From: Senthil Nathan Thangaraj <senthilnathan.thangaraj@xxxxxxx>

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@xxxxxxx>
Signed-off-by: Michal Simek <michal.simek@xxxxxxx>
Signed-off-by: Senthil Nathan Thangaraj <senthilnathan.thangaraj@xxxxxxx>
---
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