firmware: xilinx: cleanups and debugfs fixes
Michal Simek
maintainerPATCH 1/6 firmware: xilinx: Use late_initcall for pm_init_finalize
In reply to Michal SimekThe current implementation uses the driver sync_state callback to call zynqmp_pm_init_finalize(). This callback only fires when all consumers of the firmware node have probed their drivers. If any consumer device has its driver disabled or built as a never-loaded module, sync_state never fires and pm_init_finalize is never called.
This causes PMUFW to remain in UNINITIALIZED state, leading to IPI deadlock during CPU idle on ZynqMP platforms.
Replace sync_state with late_initcall to guarantee pm_init_finalize is called. By late_initcall time, all built-in drivers including the console UART have probed and requested their power domains, avoiding any race with early console.
Removing of_genpd_sync_state() from the firmware driver is safe because the genpd framework automatically sets up its own sync_state handler on the firmware driver via dev_set_drv_sync_state() when the PM domain driver registers with of_genpd_add_provider_onecell(). Power domain cleanup continues to work independently without the firmware driver explicitly calling of_genpd_sync_state().
---
drivers/firmware/xilinx/zynqmp.c | 41 ++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 15 deletions(-)
drivers/firmware/xilinx/zynqmp.c +26 -15
@@ -21,7 +21,6 @@#include <linux/of.h> #include <linux/of_platform.h> #include <linux/platform_device.h> -#include <linux/pm_domain.h> #include <linux/slab.h> #include <linux/uaccess.h> #include <linux/hashtable.h>
@@ -2370,19 +2369,6 @@ static void zynqmp_firmware_remove(struct platform_device *pdev)platform_device_unregister (em_dev); } -static void zynqmp_firmware_sync_state (struct device *dev) -{ -struct device_node *np = dev->of_node; - -if (!of_device_is_compatible (np,"xlnx,zynqmp-firmware" )) -return ; - -of_genpd_sync_state (np); - -if (zynqmp_pm_init_finalize ()) -dev_warn (dev,"failed to release power management to firmware\n" ); -} -static const struct platform_fw_data platform_fw_data_versal = { .family_code =PM_VERSAL_FAMILY_CODE , };
@@ -2408,10 +2394,35 @@ static struct platform_driver zynqmp_firmware_driver = { .name = "zynqmp_firmware", .of_match_table = zynqmp_firmware_of_match, .dev_groups = zynqmp_firmware_groups, - .sync_state = zynqmp_firmware_sync_state, }, .probe = zynqmp_firmware_probe, .remove = zynqmp_firmware_remove, .shutdown = zynqmp_firmware_shutdown, };module_platform_driver (zynqmp_firmware_driver); + +/* +* pm_init_finalize was previously called from the firmware driver's +* sync_state callback, but sync_state can be blocked indefinitely if +* any device consumer never probes. Use late_initcall to ensure +* pm_init_finalize is called reliably regardless of consumer +* probe status. +*/ +static int __init zynqmp_pm_init_finalize_late (void ) +{ +u32 pm_family_code; +int ret; + + ret =zynqmp_pm_get_family_info (&pm_family_code); +if (ret) +return ret; + +if (pm_family_code !=PM_ZYNQMP_FAMILY_CODE ) +return 0 ; + +if (zynqmp_pm_init_finalize ()) +pr_warn ("zynqmp: failed to release power management to firmware\n" ); + +return 0 ; +} +late_initcall (zynqmp_pm_init_finalize_late);
Signature · 1 line
2.43.0
Michal Simek
maintainercover firmware: xilinx: cleanups and debugfs fixes
Patches 1-3 are preparatory cleanups of the EEMI call path and of the sysfs registration. Patch 4 fixes pm_init_finalize() never running when a firmware consumer never probes. Patches 5 and 6 fix two debugfs issues: an undersized ret_payload array and an unbounded clock name copy.
Each patch builds individually for arm64 with ZYNQMP_FIRMWARE_DEBUG=y and checkpatch --strict is clean.
Thanks,
Michal
Jay Buddhabhatti (2):
firmware: xilinx: Change debugfs pm_api_ret size to PAYLOAD_ARG_CNT
firmware: xilinx: Bound debugfs clock name formatting
Michal Simek (4):
firmware: xilinx: Use late_initcall for pm_init_finalize
firmware: xilinx: Call va_start after pm feature check
firmware: xilinx: Add comments about number of arguments
firmware: xilinx: Call pm sysfs out of dev_groups
drivers/firmware/xilinx/zynqmp-debug.c | 13 ++-- drivers/firmware/xilinx/zynqmp.c | 90 +++++++++++++++++++------- include/linux/firmware/xlnx-zynqmp.h | 3 + 3 files changed, 78 insertions(+), 28 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
branch: xnext/firmware
Signature · 1 line
2.43.0
Michal Simek
maintainerPATCH 2/6 firmware: xilinx: Call va_start after pm feature check
There is no reason to start to process va_list before calling pm feature check which can still fail. Call it at a time when list can be process.
---
drivers/firmware/xilinx/zynqmp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/firmware/xilinx/zynqmp.c +4 -4
@@ -391,13 +391,13 @@ int zynqmp_pm_invoke_fw_fn(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)if (num_args >SMC_ARG_CNT_32 )return -EINVAL ; -va_start (arg_list, num_args); -/* Check if feature is supported or not */ ret =zynqmp_pm_feature (pm_api_id);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);
@@ -454,13 +454,13 @@ int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)if (num_args >14 )return -EINVAL ; -va_start (arg_list, num_args); -/* Check if feature is supported or not */ ret =zynqmp_pm_feature (pm_api_id);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);
Signature · 1 line
2.43.0
Michal Simek
maintainerPATCH 3/6 firmware: xilinx: Add comments about number of arguments
In reply to Michal SimekThe driver is checking number of arguments where it is not exactly clear what that values are reflecting that's why introduce SMC_ARG_CNT_BASIC_32 macro and add comment to the code.
---
drivers/firmware/xilinx/zynqmp.c | 18 ++++++++++++++++-- include/linux/firmware/xlnx-zynqmp.h | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-)
drivers/firmware/xilinx/zynqmp.c +16 -2
@@ -388,6 +388,13 @@ int zynqmp_pm_invoke_fw_fn(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)u32 args[SMC_ARG_CNT_32 ] = {0 };u32 module_id; +/* +* According to the SMCCC: The total number of registers available for +* arguments is 16. +* +* In the Extended SMC format, 3 registers are used for headers, leaving +* up to 13 registers for arguments. +*/ if (num_args >SMC_ARG_CNT_32 )return -EINVAL ;
@@ -449,9 +456,16 @@ int zynqmp_pm_invoke_fn(u32 pm_api_id, u32 *ret_payload, u32 num_args, ...)u64 smc_arg[8 ];int ret, i;va_list arg_list; -u32 args[14 ] = {0 }; +u32 args[SMC_ARG_CNT_BASIC_32 ] = {0 }; -if (num_args >14 ) +/* +* According to the SMCCC: The total number of registers available for +* arguments is 16. +* +* In the Basic SMC format, 2 registers are used for headers, leaving +* up to 14 registers for arguments. +*/ +if (num_args >SMC_ARG_CNT_BASIC_32 )return -EINVAL ;/* Check if feature is supported or not */
include/linux/firmware/xlnx-zynqmp.h +3 -0
@@ -82,6 +82,9 @@/* Number of 32bits arguments for SMC call */ #define SMC_ARG_CNT_32 13U +/* Number of 32bits arguments for Basic SMC call */ +#define SMC_ARG_CNT_BASIC_32 14U +/* Number of arguments for a callback */ #define CB_ARG_CNT 4
Signature · 1 line
2.43.0
Michal Simek
maintainerPATCH 4/6 firmware: xilinx: Call pm sysfs out of dev_groups
In reply to Michal SimekPM (Power Management) functionality is only one part of firmware interface that's why move sysfs registration to own function and call it separately as preparation for spliting functionality based on service type.
---
drivers/firmware/xilinx/zynqmp.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
drivers/firmware/xilinx/zynqmp.c +20 -3
@@ -2189,7 +2189,7 @@ static ssize_t feature_config_value_store(struct device *device,static DEVICE_ATTR_RW (feature_config_value); -static struct attribute *zynqmp_firmware_attrs[] = { +static const struct attribute *zynqmp_firmware_attrs[] = { &dev_attr_ggs0.attr, &dev_attr_ggs1.attr, &dev_attr_ggs2.attr,
@@ -2205,7 +2205,18 @@ static struct attribute *zynqmp_firmware_attrs[] = { NULL, }; -ATTRIBUTE_GROUPS (zynqmp_firmware); +static int zynqmp_firmware_pm_sysfs_entry (struct platform_device *pdev) +{ +int ret; + + ret =sysfs_create_files (&pdev->dev.kobj, zynqmp_firmware_attrs); +if (ret) { +pr_err ("%s() Failed to create PM firmware attrs, err=%d\n" , + __func__, ret); + } + +return ret; +}/** * zynqmp_clear_pm_state() - Clear subsystem state
@@ -2349,6 +2360,13 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)return ret; } + ret =zynqmp_firmware_pm_sysfs_entry (pdev); +if (ret) { +pr_err ("%s() Failed to create sysfs file with error%d\n" , + __func__, ret); +return ret; + } +zynqmp_pm_api_debugfs_init ();if (pm_family_code !=PM_ZYNQMP_FAMILY_CODE ) {
@@ -2407,7 +2425,6 @@ static struct platform_driver zynqmp_firmware_driver = { .driver = { .name = "zynqmp_firmware", .of_match_table = zynqmp_firmware_of_match, - .dev_groups = zynqmp_firmware_groups, }, .probe = zynqmp_firmware_probe, .remove = zynqmp_firmware_remove,
Signature · 1 line
2.43.0
Michal Simek
maintainerPATCH 6/6 firmware: xilinx: Bound debugfs clock name formatting
In reply to Michal SimekFrom: Jay Buddhabhatti <[email protected]>
PM_QID_CLOCK_GET_NAME returns up to 16 name bytes with no guaranteed NUL terminator. Copy the response into a bounded local buffer before formatting to prevent kernel stack data from leaking via debugfs.
---
drivers/firmware/xilinx/zynqmp-debug.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/firmware/xilinx/zynqmp-debug.c +8 -3
@@ -21,6 +21,7 @@#include "zynqmp-debug.h" #define PM_API_NAME_LEN 50 +#define CLK_GET_NAME_RESP_LEN 16struct pm_api_info {u32 api_id;
@@ -279,10 +280,14 @@ static int process_api_request(u32 pm_id, u64 *pm_api_arg, u32 *pm_api_ret)break ;switch (qdata.qid) { -case PM_QID_CLOCK_GET_NAME : -sprintf (debugfs_buf,"Clock name = %s\n" , - (char *)pm_api_ret); +case PM_QID_CLOCK_GET_NAME : { +char name[CLK_GET_NAME_RESP_LEN +1 ]; + +memcpy (name, pm_api_ret,CLK_GET_NAME_RESP_LEN ); + name[CLK_GET_NAME_RESP_LEN ] ='\0' ; +sprintf (debugfs_buf,"Clock name = %s\n" , name);break ; + }case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS :sprintf (debugfs_buf,"Multiplier = %d, Divider = %d\n" , pm_api_ret[1 ], pm_api_ret[2 ]);
Signature · 1 line
2.43.0
Michal Simek
maintainerPATCH 5/6 firmware: xilinx: Change debugfs pm_api_ret size to PAYLOAD_ARG_CNT
In reply to Michal SimekFrom: Jay Buddhabhatti <[email protected]>
The debugfs PM API handler declared u32 pm_api_ret[4] but passes it as the ret_payload buffer to zynqmp_pm_invoke_fn() and zynqmp_pm_query_data(), which unconditionally write PAYLOAD_ARG_CNT (7) u32 values via the SMC/HVC transport. Size the array to match the firmware call contract.
---
drivers/firmware/xilinx/zynqmp-debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/firmware/xilinx/zynqmp-debug.c +1 -1
@@ -325,7 +325,7 @@ static ssize_t zynqmp_pm_debugfs_api_write(struct file *file,u32 pm_id =0 ;u64 pm_api_arg[5 ] = {0 ,0 ,0 ,0 ,0 };/* Return values from PM APIs calls */ -u32 pm_api_ret[4 ] = {0 ,0 ,0 ,0 }; +u32 pm_api_ret[PAYLOAD_ARG_CNT ] = {0 };int ret;int i =0 ;
Signature · 1 line
2.43.0