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 07/15] firmware: xilinx: Add support for Versal Gen 2
Date: Wed, 18 Nov 2026 15:32:03 -0800	[thread overview]
Message-ID: <20261118233211.4121361-8-gregory.williams@amd.com> (raw)
In-Reply-To: <20261118233211.4121361-1-gregory.williams@amd.com>

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

Until Versal, the extended SMCCC payload was supported only for QUERY_DATA,
while other APIs used the basic SMCCC format.

In Versal Gen 2, all EEMI APIs are supported with extended SMCCC payload
only, enabling a simplified and efficient pass-through implementation.

The TF-A feature check now tries PM_API_FEATURES first and falls back to
PM_FEATURE_CHECK so the same code path works on Versal Gen 2 (where TF-A
only exposes PM_API_FEATURES on the SiP service) and on the older
ZynqMP/Versal/Versal NET platforms (where TF-A exposes PM_FEATURE_CHECK).

Signed-off-by: Michal Simek <michal.simek@amd.com>
Signed-off-by: Senthil Nathan Thangaraj <senthilnathan.thangaraj@amd.com>
---
 drivers/firmware/xilinx/zynqmp.c     | 117 ++++++++++++++++++++++++---
 include/linux/firmware/xlnx-zynqmp.h |   1 +
 2 files changed, 109 insertions(+), 9 deletions(-)

diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index 709370933741..a8c70e775ae3 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -242,12 +242,24 @@ static u64 prep_pm_hdr_feature_check(void)
 	return PM_SIP_SVC | FIELD_PREP(MODULE_ID_MASK, PM_MODULE_ID) | PM_FEATURE_CHECK;
 }
 
+/**
+ * prep_pm_hdr_api_features - Prepare SMC header for PM_API_FEATURES.
+ * @module_id: Module ID of the API to be checked.
+ *
+ * Return: SMC arg[0] header value.
+ */
+static u64 prep_pm_hdr_api_features(u32 module_id)
+{
+	return PM_SIP_SVC | FIELD_PREP(MODULE_ID_MASK, module_id) | PM_API_FEATURES;
+}
+
 /**
  * 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.
+ * Tries PM_API_FEATURES first, then falls back to PM_FEATURE_CHECK.
  *
  * Return:
  * - Feature status word from ret_payload[1] on success
@@ -256,13 +268,68 @@ static u64 prep_pm_hdr_feature_check(void)
 static int do_feature_check_for_tfa_apis(const u32 api_id, u32 *ret_payload)
 {
 	u64 smc_arg[2];
+	u32 module_id;
 	int ret;
 
-	smc_arg[0] = prep_pm_hdr_feature_check();
+	module_id = FIELD_GET(MODULE_ID_MASK, api_id);
+
+	smc_arg[0] = prep_pm_hdr_api_features(module_id);
 	smc_arg[1] = api_id;
 
 	ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
 
+	if (ret) {
+		smc_arg[0] = prep_pm_hdr_feature_check();
+		ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
+		if (ret)
+			return -EOPNOTSUPP;
+	}
+
+	return ret_payload[1];
+}
+
+/**
+ * do_feature_check_extended - Perform feature check for an API ID
+ *				 using extended SMCCC 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 arguments in the extended
+ * SMCCC format, executes the firmware call, and processes the result.
+ *
+ * Return:
+ * - 0 on success
+ * - -EOPNOTSUPP if the firmware call fails.
+ */
+static int do_feature_check_extended(const u32 api_id, u32 *ret_payload)
+{
+	u32 feature_check_api_id;
+	u64 smc_arg[2];
+	u32 module_id;
+	int ret;
+
+	module_id = FIELD_GET(MODULE_ID_MASK, api_id);
+
+	/*
+	 * Feature check of APIs belonging to PM and XSEM are handled by calling
+	 * PM_FEATURE_CHECK API. For other modules, call PM_API_FEATURES API.
+	 */
+	if (module_id == PM_MODULE_ID || module_id == XSEM_MODULE_ID)
+		feature_check_api_id = PM_FEATURE_CHECK;
+	else
+		feature_check_api_id = PM_API_FEATURES;
+
+	if (module_id == PM_MODULE_ID)
+		module_id = XPM_MODULE_ID;
+
+	/* Frame extended SMC format */
+	smc_arg[0] = PM_SIP_SVC | PASS_THROUGH_FW_CMD_ID;
+	smc_arg[1] = ((u64)(api_id & API_ID_MASK) << 32) |
+		      FIELD_PREP(MODULE_ID_MASK, module_id) |
+		      feature_check_api_id;
+
+	ret = do_fw_call(ret_payload, 2, smc_arg[0], smc_arg[1]);
 	if (ret)
 		return -EOPNOTSUPP;
 
@@ -440,11 +507,13 @@ int zynqmp_pm_is_function_supported(const u32 api_id, const u32 id)
 EXPORT_SYMBOL_GPL(zynqmp_pm_is_function_supported);
 
 /**
- * zynqmp_pm_fw_call_extended() - Invoke the system-level platform management layer
+ * __zynqmp_pm_fw_call_extended() - Invoke the system-level platform management layer
  *			caller function depending on the configuration
  * @pm_api_id:		Requested PM-API call
  * @ret_payload:	Returned value array
  * @num_args:		Number of arguments to requested PM-API call
+ * @arg_list:		va_list initialized with va_start, containing arguments passed
+ *			to the firmware.
  *
  * Invoke platform management function for SMC or HVC call, depending on
  * configuration.
@@ -461,7 +530,8 @@ EXPORT_SYMBOL_GPL(zynqmp_pm_is_function_supported);
  *
  * Return: Returns status, either success or error+reason
  */
-int zynqmp_pm_fw_call_extended(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)
+static int __zynqmp_pm_fw_call_extended(u32 pm_api_id, u32 *ret_payload,
+					u32 num_args, va_list *arg_list)
 {
 	/*
 	 * Added SIP service call Function Identifier
@@ -469,7 +539,6 @@ int zynqmp_pm_fw_call_extended(u32 pm_api_id, u32 *ret_payload, u32 num_args, ..
 	 */
 	u64 smc_arg[SMC_ARG_CNT_64];
 	int ret, i;
-	va_list arg_list;
 	u32 args[SMC_ARG_CNT_32] = {0};
 	u32 module_id;
 
@@ -485,12 +554,8 @@ int zynqmp_pm_fw_call_extended(u32 pm_api_id, u32 *ret_payload, u32 num_args, ..
 	if (ret < 0)
 		return ret;
 
-	va_start(arg_list, num_args);
-
 	for (i = 0; i < num_args; i++)
-		args[i] = va_arg(arg_list, u32);
-
-	va_end(arg_list);
+		args[i] = va_arg(*arg_list, u32);
 
 	module_id = FIELD_GET(PLM_MODULE_ID_MASK, pm_api_id);
 
@@ -507,6 +572,33 @@ int zynqmp_pm_fw_call_extended(u32 pm_api_id, u32 *ret_payload, u32 num_args, ..
 			  smc_arg[4], smc_arg[5], smc_arg[6], smc_arg[7]);
 }
 
+/**
+ * zynqmp_pm_fw_call_extended - Invoke a PM function with variable arguments
+ * @pm_api_id: ID of the PM API to be called
+ * @ret_payload: Pointer to the buffer for storing the return payload
+ * @num_args: Number of arguments to pass to the PM API function
+ *
+ * This function serves as a wrapper around __zynqmp_pm_fw_call_extended(),
+ * facilitating the invocation of platform management (PM) functions that
+ * require an extended SMC (Secure Monitor Call) format with variable
+ * arguments. Specifically, the PM_QUERY_DATA API necessitates this extended
+ * payload format, making it essential to retain zynqmp_pm_fw_call_extended
+ * with variable arguments.
+ *
+ * Return: 0 on success; a negative error code on failure.
+ */
+int zynqmp_pm_fw_call_extended(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)
+{
+	va_list arg_list;
+	int ret;
+
+	va_start(arg_list, num_args);
+	ret = __zynqmp_pm_fw_call_extended(pm_api_id, ret_payload,
+					   num_args, &arg_list);
+	va_end(arg_list);
+	return ret;
+}
+
 /**
  * __zynqmp_pm_fw_call_basic() - Invoke the system-level platform management layer
  *				 supporting basic SMC format.
@@ -2522,6 +2614,12 @@ static void zynqmp_firmware_sync_state(struct device *dev)
 		dev_warn(dev, "failed to release power management to firmware\n");
 }
 
+static const struct platform_fw_data platform_fw_data_versal2 = {
+	.do_feature_check = do_feature_check_extended,
+	.zynqmp_pm_fw_call = __zynqmp_pm_fw_call_extended,
+	.family_code = PM_VERSAL2_FAMILY_CODE,
+};
+
 static const struct platform_fw_data platform_fw_data_versal = {
 	.do_feature_check = do_feature_check_basic,
 	.zynqmp_pm_fw_call = __zynqmp_pm_fw_call_basic,
@@ -2544,6 +2642,7 @@ static const struct of_device_id zynqmp_firmware_of_match[] = {
 	{.compatible = "xlnx,zynqmp-firmware", .data = &platform_fw_data_zynqmp},
 	{.compatible = "xlnx,versal-firmware", .data = &platform_fw_data_versal},
 	{.compatible = "xlnx,versal-net-firmware", .data = &platform_fw_data_versal_net},
+	{.compatible = "xlnx,versal2-firmware",	.data = &platform_fw_data_versal2},
 	{},
 };
 MODULE_DEVICE_TABLE(of, zynqmp_firmware_of_match);
diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index 58f2e3fddfaf..effa1a2445b3 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -58,6 +58,7 @@
 #define PM_ZYNQMP_FAMILY_CODE 0x1 /* ZynqMP family code */
 #define PM_VERSAL_FAMILY_CODE 0x2 /* Versal family code */
 #define PM_VERSAL_NET_FAMILY_CODE 0x3 /* Versal NET family code */
+#define PM_VERSAL2_FAMILY_CODE 0x4 /* Versal Gen 2 family code */
 
 #define API_ID_MASK		GENMASK(7, 0)
 #define MODULE_ID_MASK		GENMASK(11, 8)
-- 
2.34.1


  parent 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 ` [PATCH 01/15] firmware: xilinx: Separate TF-A checking Gregory Williams
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 ` Gregory Williams [this message]
2026-11-18 23:32 ` [PATCH 08/15] dt-bindings: clock: versal: add " 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-8-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®