firmware: xilinx: Clean up firmware and TF-A state on kexec
cover firmware: xilinx: Clean up firmware and TF-A state on kexec
During a kexec restart, only the kernel is reloaded while the state held in TF-A and the platform firmware persists. This leaves the freshly booted kernel out of sync with the firmware for things like the SGI number, shutdown scope, allocated peripheral devices and registered notifier callbacks, which can lead to unexpected behaviour after a kexec.
Introduce a mechanism to clear the stale firmware/TF-A state so the reloaded kernel starts from a clean baseline:
- Add TF_A_CLEAR_PM_STATE to clear TF-A specific PM state.
- Add PM_DEV_ALL_PERIPH to release all peripheral devices in one call.
- Add PM_ALL_NOTIFIERS to unregister all notifier callbacks in one call.
On a graceful kexec reboot the cleanup is performed from zynqmp_firmware_shutdown(); on a crash (kdump) restart it is performed from zynqmp_firmware_probe() of the reloaded kernel. Each cleanup step is guarded by a feature check so it degrades gracefully on firmware/TF-A versions that do not implement the new APIs.
Also rework the feature-check logic so TF-A specific APIs are validated through PM_API_FEATURES (the dedicated TF-A mechanism) instead of PM_FEATURE_CHECK, falling back to the legacy PM_FEATURE_CHECK for backward compatibility.
Jay Buddhabhatti (4):
firmware: xilinx: Add support to clear TF-A PM state
firmware: xilinx: Release all peripheral devices from firmware
firmware: xilinx: Clear firmware notifiers across kexec transitions
firmware: xilinx: Use TF-A feature check for TF-A specific APIs
drivers/firmware/xilinx/zynqmp.c | 106 +++++++++++++++++++++++---- include/linux/firmware/xlnx-zynqmp.h | 10 ++- 2 files changed, 100 insertions(+), 16 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 firmware: xilinx: Add support to clear TF-A PM state
Currently, during a kexec restart, only the kernel is reloaded, while the TF-A specific data remain unchanged. This leads to a mismatch between the kernel state and the TF-A firmware state like SGI number and shutdown scope variable.
For example, the kernel registers an SGI number with TF-A so that TF-A can notify the kernel of events via that SGI. TF-A stores this SGI number in its internal state. After a kexec, the newly loaded kernel re-registers and may request a different SGI number, but the stale value programmed in TF-A remains, so event notifications are delivered on the old SGI and are missed by the new kernel. The shutdown scope variable has a similar stale state problem.
To resolve this, the TF_A_CLEAR_PM_STATE PM API is introduced to clear TF-A-specific state during kexec. On a graceful reboot, this API is triggered by zynqmp_firmware_shutdown(), while in a crash kernel scenario, it is invoked by zynqmp_firmware_probe() in the reloaded kernel.
--- drivers/firmware/xilinx/zynqmp.c | 48 +++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 3 +- 2 files changed, 49 insertions(+), 2 deletions(-)
drivers/firmware/xilinx/zynqmp.c +47 -1
@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2022 Xilinx, Inc. -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]>
@@ -13,6 +13,7 @@#include <linux/arm-smccc.h> #include <linux/compiler.h> +#include <linux/crash_dump.h> #include <linux/device.h> #include <linux/init.h> #include <linux/mfd/core.h>
@@ -2065,6 +2066,42 @@ static struct attribute *zynqmp_firmware_attrs[] = {ATTRIBUTE_GROUPS (zynqmp_firmware); +/** +* zynqmp_clear_pm_state() - Clear subsystem state +* @dev: Device pointer used for logging +* +* Clears PM specific data in TF-A. +* +* Return: Returns status, either success or error +*/ +static int zynqmp_clear_pm_state (struct device *dev) +{ +u32 pm_family_code; +int ret; + +/* Get the Family code of platform */ + ret =zynqmp_pm_get_family_info (&pm_family_code); +if (ret <0 ) +return ret; + +if (pm_family_code !=PM_ZYNQMP_FAMILY_CODE ) { +/* Check if the TF-A supports the TF_A_CLEAR_PM_STATE */ + ret =do_feature_check_call (TF_A_CLEAR_PM_STATE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_1 )) { +/* Clear PM specific data in TF-A */ + ret =zynqmp_pm_invoke_fn (TF_A_CLEAR_PM_STATE ,NULL ,0 ); +if (ret) +dev_err (dev, +"Failed to clear TF-A specific subsystem state: %d\n" , ret); + }else { +dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); + ret =0 ; + } + } + +return ret; +} +static int zynqmp_firmware_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -2118,6 +2155,9 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)if (ret <0 )return ret; +if (is_kdump_kernel ()) +zynqmp_clear_pm_state (dev); +/* Check trustzone version number */ ret =zynqmp_pm_get_trustzone_version (&pm_tz_version);if (ret)
@@ -2151,6 +2191,11 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)return of_platform_populate (dev->of_node,NULL ,NULL , dev); } +static void zynqmp_firmware_shutdown (struct platform_device *pdev) +{ +zynqmp_clear_pm_state (&pdev->dev); +} +static void zynqmp_firmware_remove (struct platform_device *pdev) {struct pm_api_feature_data *feature_data;
@@ -2210,5 +2255,6 @@ static struct platform_driver zynqmp_firmware_driver = { }, .probe = zynqmp_firmware_probe, .remove = zynqmp_firmware_remove, + .shutdown = zynqmp_firmware_shutdown, };module_platform_driver (zynqmp_firmware_driver);
include/linux/firmware/xlnx-zynqmp.h +2 -1
@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2021 Xilinx -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]>
@@ -66,6 +66,7 @@#define FIRMWARE_VERSION_MASK 0xFFFFU/* ATF only commands */ +#define TF_A_CLEAR_PM_STATE 0xa05#define TF_A_PM_REGISTER_SGI 0xa04#define PM_GET_TRUSTZONE_VERSION 0xa03#define PM_SET_SUSPEND_MODE 0xa02
Signature · 1 line
2.34.1
Re: [PATCH 1/4] firmware: xilinx: Add support to clear TF-A PM state
Quoted 13 lines · Jay Buddhabhatti
Currently, during a kexec restart, only the kernel is reloaded, while the TF-A specific data remain unchanged. This leads to a mismatch between the kernel state and the TF-A firmware state like SGI number and shutdown scope variable.
For example, the kernel registers an SGI number with TF-A so that TF-A can notify the kernel of events via that SGI. TF-A stores this SGI number in its internal state. After a kexec, the newly loaded kernel re-registers and may request a different SGI number, but the stale value programmed in TF-A remains, so event notifications are delivered on the old SGI and are missed by the new kernel. The shutdown scope variable has a similar stale state problem.
Quoted 6 lines
To resolve this, the
TF_A_CLEAR_PM_STATEPM API is introduced to clear TF-A-specific state during kexec. On a graceful reboot, this API is triggered byzynqmp_firmware_shutdown(), while in a crash kernel scenario, it is invoked byzynqmp_firmware_probe()in the reloaded kernel.Signed-off-by Jay Buddhabhatti <[email protected]>
Thanks!
Quoted 119 lines
--- drivers/firmware/xilinx/zynqmp.c | 48 +++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 3 +- 2 files changed, 49 insertions(+), 2 deletions(-)drivers/firmware/xilinx/zynqmp.c +47
-1@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2022 Xilinx, Inc. -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]> @@ -13,6 +13,7 @@#include <linux/arm-smccc.h> #include <linux/compiler.h> +#include <linux/crash_dump.h> #include <linux/device.h> #include <linux/init.h> #include <linux/mfd/core.h> @@ -2065,6 +2066,42 @@ static struct attribute *zynqmp_firmware_attrs[] = {ATTRIBUTE_GROUPS (zynqmp_firmware); +/** +* zynqmp_clear_pm_state() - Clear subsystem state +* @dev: Device pointer used for logging +* +* Clears PM specific data in TF-A. +* +* Return: Returns status, either success or error +*/ +static int zynqmp_clear_pm_state (struct device *dev) +{ +u32 pm_family_code; +int ret; + +/* Get the Family code of platform */ + ret =zynqmp_pm_get_family_info (&pm_family_code); +if (ret <0 ) +return ret; + +if (pm_family_code !=PM_ZYNQMP_FAMILY_CODE ) { +/* Check if the TF-A supports the TF_A_CLEAR_PM_STATE */ + ret =do_feature_check_call (TF_A_CLEAR_PM_STATE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_1 )) { +/* Clear PM specific data in TF-A */ + ret =zynqmp_pm_invoke_fn (TF_A_CLEAR_PM_STATE ,NULL ,0 ); +if (ret) +dev_err (dev, +"Failed to clear TF-A specific subsystem state: %d\n" , ret); + }else { +dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); + ret =0 ; + } + } + +return ret; +} +static int zynqmp_firmware_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;@@ -2118,6 +2155,9 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)if (ret <0 )return ret; +if (is_kdump_kernel ()) +zynqmp_clear_pm_state (dev); +/* Check trustzone version number */ ret =zynqmp_pm_get_trustzone_version (&pm_tz_version);if (ret)@@ -2151,6 +2191,11 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)return of_platform_populate (dev->of_node,NULL ,NULL , dev); } +static void zynqmp_firmware_shutdown (struct platform_device *pdev) +{ +zynqmp_clear_pm_state (&pdev->dev); +} +static void zynqmp_firmware_remove (struct platform_device *pdev) {struct pm_api_feature_data *feature_data;@@ -2210,5 +2255,6 @@ static struct platform_driver zynqmp_firmware_driver = { }, .probe = zynqmp_firmware_probe, .remove = zynqmp_firmware_remove, + .shutdown = zynqmp_firmware_shutdown, };module_platform_driver (zynqmp_firmware_driver);include/linux/firmware/xlnx-zynqmp.h +2
-1@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2021 Xilinx -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]> @@ -66,6 +66,7 @@#define FIRMWARE_VERSION_MASK 0xFFFFU/* ATF only commands */ +#define TF_A_CLEAR_PM_STATE 0xa05#define TF_A_PM_REGISTER_SGI 0xa04#define PM_GET_TRUSTZONE_VERSION 0xa03#define PM_SET_SUSPEND_MODE 0xa02
Re: [PATCH 1/4] firmware: xilinx: Add support to clear TF-A PM state
In reply to Jay BuddhabhattiQuoted 131 lines · Jay Buddhabhatti
Currently, during a kexec restart, only the kernel is reloaded, while the TF-A specific data remain unchanged. This leads to a mismatch between the kernel state and the TF-A firmware state like SGI number and shutdown scope variable.
For example, the kernel registers an SGI number with TF-A so that TF-A can notify the kernel of events via that SGI. TF-A stores this SGI number in its internal state. After a kexec, the newly loaded kernel re-registers and may request a different SGI number, but the stale value programmed in TF-A remains, so event notifications are delivered on the old SGI and are missed by the new kernel. The shutdown scope variable has a similar stale state problem.
To resolve this, the
TF_A_CLEAR_PM_STATEPM API is introduced to clear TF-A-specific state during kexec. On a graceful reboot, this API is triggered byzynqmp_firmware_shutdown(), while in a crash kernel scenario, it is invoked byzynqmp_firmware_probe()in the reloaded kernel.Signed-off-by Jay Buddhabhatti <[email protected]>--- drivers/firmware/xilinx/zynqmp.c | 48 +++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 3 +- 2 files changed, 49 insertions(+), 2 deletions(-)drivers/firmware/xilinx/zynqmp.c +47
-1@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2022 Xilinx, Inc. -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]> @@ -13,6 +13,7 @@#include <linux/arm-smccc.h> #include <linux/compiler.h> +#include <linux/crash_dump.h> #include <linux/device.h> #include <linux/init.h> #include <linux/mfd/core.h> @@ -2065,6 +2066,42 @@ static struct attribute *zynqmp_firmware_attrs[] = {ATTRIBUTE_GROUPS (zynqmp_firmware); +/** +* zynqmp_clear_pm_state() - Clear subsystem state +* @dev: Device pointer used for logging +* +* Clears PM specific data in TF-A. +* +* Return: Returns status, either success or error +*/ +static int zynqmp_clear_pm_state (struct device *dev) +{ +u32 pm_family_code; +int ret; + +/* Get the Family code of platform */ + ret =zynqmp_pm_get_family_info (&pm_family_code); +if (ret <0 ) +return ret; + +if (pm_family_code !=PM_ZYNQMP_FAMILY_CODE ) { +/* Check if the TF-A supports the TF_A_CLEAR_PM_STATE */ + ret =do_feature_check_call (TF_A_CLEAR_PM_STATE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_1 )) { +/* Clear PM specific data in TF-A */ + ret =zynqmp_pm_invoke_fn (TF_A_CLEAR_PM_STATE ,NULL ,0 ); +if (ret) +dev_err (dev, +"Failed to clear TF-A specific subsystem state: %d\n" , ret); + }else { +dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); + ret =0 ; + } + } + +return ret; +} +static int zynqmp_firmware_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;@@ -2118,6 +2155,9 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)if (ret <0 )return ret; +if (is_kdump_kernel ()) +zynqmp_clear_pm_state (dev); +/* Check trustzone version number */ ret =zynqmp_pm_get_trustzone_version (&pm_tz_version);if (ret)@@ -2151,6 +2191,11 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)return of_platform_populate (dev->of_node,NULL ,NULL , dev); } +static void zynqmp_firmware_shutdown (struct platform_device *pdev) +{ +zynqmp_clear_pm_state (&pdev->dev); +} +static void zynqmp_firmware_remove (struct platform_device *pdev) {struct pm_api_feature_data *feature_data;@@ -2210,5 +2255,6 @@ static struct platform_driver zynqmp_firmware_driver = { }, .probe = zynqmp_firmware_probe, .remove = zynqmp_firmware_remove, + .shutdown = zynqmp_firmware_shutdown, };module_platform_driver (zynqmp_firmware_driver);include/linux/firmware/xlnx-zynqmp.h +1
-1@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2021 Xilinx -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]>
include/linux/firmware/xlnx-zynqmp.h line 72
Quoted 7 lines
include/linux/firmware/xlnx-zynqmp.h +1
-0@@ -66,6 +66,7 @@#define FIRMWARE_VERSION_MASK 0xFFFFU/* ATF only commands */ +#define TF_A_CLEAR_PM_STATE 0xa05#define TF_A_PM_REGISTER_SGI 0xa04#define PM_GET_TRUSTZONE_VERSION 0xa03#define PM_SET_SUSPEND_MODE 0xa02
Looks good to me.
PATCH 2/4 firmware: xilinx: Release all peripheral devices from firmware
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded while devices allocated in firmware persist, causing state mismatches between the kernel and firmware.
Introduce PM_DEV_ALL_PERIPH node ID (0x18224FFFU) to release all peripheral devices during kexec. On graceful restarts, this happens in zynqmp_firmware_shutdown(). On crash kernel restarts, it happens in zynqmp_firmware_probe() of the reloaded kernel.
Releasing all peripherals depends on firmware support for the PM_DEV_ALL_PERIPH node ID. On firmware that does not implement it (the feature check reports a version below PM_API_VERSION_3) the release is skipped and a warning such as "Bulk device release is not supported by firmware" is logged, e.g. on Versal NET firmware that predates this API.
--- drivers/firmware/xilinx/zynqmp.c | 15 ++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/firmware/xilinx/zynqmp.c +14 -1
@@ -2070,7 +2070,7 @@ ATTRIBUTE_GROUPS(zynqmp_firmware);* zynqmp_clear_pm_state() - Clear subsystem state * @dev: Device pointer used for logging * -* Clears PM specific data in TF-A. +* Clears PM specific data in TF-A and firmware. * * Return: Returns status, either success or error */
@@ -2097,6 +2097,19 @@ static int zynqmp_clear_pm_state(struct device *dev)dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); ret =0 ; } + +/* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */ + ret =do_feature_check_call (PM_RELEASE_NODE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to release all peripheral devices via firmware */ + ret =zynqmp_pm_release_node (PM_DEV_ALL_PERIPH ); +if (ret) +dev_err (dev,"Failed to release all peripheral devices: %d\n" , ret); + }else { +dev_warn (dev, +"Bulk device release is not supported by firmware: %d\n" , ret); + ret =0 ; + } }return ret;
include/linux/firmware/xlnx-zynqmp.h +4 -0
@@ -50,6 +50,7 @@/* PM API versions */ #define PM_API_VERSION_1 1#define PM_API_VERSION_2 2 +#define PM_API_VERSION_3 3#define PM_PINCTRL_PARAM_SET_VERSION 2
@@ -145,6 +146,9 @@#define XPM_EVENT_ERROR_MASK_NOC_NCR BIT(13)#define XPM_EVENT_ERROR_MASK_NOC_CR BIT(12) +/* Node ID for all peripheral devices */ +#define PM_DEV_ALL_PERIPH 0x18224FFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Signature · 1 line
2.34.1
Re: [PATCH 2/4] firmware: xilinx: Release all peripheral devices from firmware
Quoted 9 lines · Jay Buddhabhatti
During a kexec restart, only the kernel is reloaded while devices allocated in firmware persist, causing state mismatches between the kernel and firmware.
Introduce
PM_DEV_ALL_PERIPHnode ID (0x18224FFFU) to release all peripheral devices during kexec. On graceful restarts, this happens inzynqmp_firmware_shutdown(). On crash kernel restarts, it happens inzynqmp_firmware_probe()of the reloaded kernel.
Quoted 7 lines
Releasing all peripherals depends on firmware support for the
PM_DEV_ALL_PERIPHnode ID. On firmware that does not implement it (the feature check reports a version belowPM_API_VERSION_3) the release is skipped and a warning such as "Bulk device release is not supported by firmware" is logged, e.g. on Versal NET firmware that predates this API.Signed-off-by Jay Buddhabhatti <[email protected]>
Thanks!
Quoted 60 lines
--- drivers/firmware/xilinx/zynqmp.c | 15 ++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-)drivers/firmware/xilinx/zynqmp.c +14
-1@@ -2070,7 +2070,7 @@ ATTRIBUTE_GROUPS(zynqmp_firmware);* zynqmp_clear_pm_state() - Clear subsystem state * @dev: Device pointer used for logging * -* Clears PM specific data in TF-A. +* Clears PM specific data in TF-A and firmware. * * Return: Returns status, either success or error */ @@ -2097,6 +2097,19 @@ static int zynqmp_clear_pm_state(struct device *dev)dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); ret =0 ; } + +/* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */ + ret =do_feature_check_call (PM_RELEASE_NODE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to release all peripheral devices via firmware */ + ret =zynqmp_pm_release_node (PM_DEV_ALL_PERIPH ); +if (ret) +dev_err (dev,"Failed to release all peripheral devices: %d\n" , ret); + }else { +dev_warn (dev, +"Bulk device release is not supported by firmware: %d\n" , ret); + ret =0 ; + } }return ret;include/linux/firmware/xlnx-zynqmp.h +4
-0@@ -50,6 +50,7 @@/* PM API versions */ #define PM_API_VERSION_1 1#define PM_API_VERSION_2 2 +#define PM_API_VERSION_3 3#define PM_PINCTRL_PARAM_SET_VERSION 2@@ -145,6 +146,9 @@#define XPM_EVENT_ERROR_MASK_NOC_NCR BIT(13)#define XPM_EVENT_ERROR_MASK_NOC_CR BIT(12) +/* Node ID for all peripheral devices */ +#define PM_DEV_ALL_PERIPH 0x18224FFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Re: [PATCH 2/4] firmware: xilinx: Release all peripheral devices from firmware
In reply to Jay BuddhabhattiQuoted 67 lines · Jay Buddhabhatti
During a kexec restart, only the kernel is reloaded while devices allocated in firmware persist, causing state mismatches between the kernel and firmware.
Introduce
PM_DEV_ALL_PERIPHnode ID (0x18224FFFU) to release all peripheral devices during kexec. On graceful restarts, this happens inzynqmp_firmware_shutdown(). On crash kernel restarts, it happens inzynqmp_firmware_probe()of the reloaded kernel.Releasing all peripherals depends on firmware support for the
PM_DEV_ALL_PERIPHnode ID. On firmware that does not implement it (the feature check reports a version belowPM_API_VERSION_3) the release is skipped and a warning such as "Bulk device release is not supported by firmware" is logged, e.g. on Versal NET firmware that predates this API.Signed-off-by Jay Buddhabhatti <[email protected]>--- drivers/firmware/xilinx/zynqmp.c | 15 ++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-)drivers/firmware/xilinx/zynqmp.c +14
-1@@ -2070,7 +2070,7 @@ ATTRIBUTE_GROUPS(zynqmp_firmware);* zynqmp_clear_pm_state() - Clear subsystem state * @dev: Device pointer used for logging * -* Clears PM specific data in TF-A. +* Clears PM specific data in TF-A and firmware. * * Return: Returns status, either success or error */ @@ -2097,6 +2097,19 @@ static int zynqmp_clear_pm_state(struct device *dev)dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); ret =0 ; } + +/* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */ + ret =do_feature_check_call (PM_RELEASE_NODE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to release all peripheral devices via firmware */ + ret =zynqmp_pm_release_node (PM_DEV_ALL_PERIPH ); +if (ret) +dev_err (dev,"Failed to release all peripheral devices: %d\n" , ret); + }else { +dev_warn (dev, +"Bulk device release is not supported by firmware: %d\n" , ret); + ret =0 ; + } }return ret;include/linux/firmware/xlnx-zynqmp.h +1
-0@@ -50,6 +50,7 @@/* PM API versions */ #define PM_API_VERSION_1 1#define PM_API_VERSION_2 2 +#define PM_API_VERSION_3 3#define PM_PINCTRL_PARAM_SET_VERSION 2
include/linux/firmware/xlnx-zynqmp.h line 154
Quoted 9 lines
include/linux/firmware/xlnx-zynqmp.h +3
-0@@ -145,6 +146,9 @@#define XPM_EVENT_ERROR_MASK_NOC_NCR BIT(13)#define XPM_EVENT_ERROR_MASK_NOC_CR BIT(12) +/* Node ID for all peripheral devices */ +#define PM_DEV_ALL_PERIPH 0x18224FFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Looks good to me.
PATCH 3/4 firmware: xilinx: Clear firmware notifiers across kexec transitions
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded but notifier callbacks in firmware persist, causing state mismatches between kernel and firmware.
To address this, introduce PM_ALL_NOTIFIERS node ID to unregister all notifier callbacks during kexec. On a graceful kexec restart, this occurs in zynqmp_firmware_shutdown(). On a crash kernel restart, it happens in zynqmp_firmware_probe() in the reloaded kernel.
Unregistering all notifiers depends on firmware support for the PM_ALL_NOTIFIERS node ID. On firmware that does not implement it (the feature check reports a version below PM_API_VERSION_3) the step is skipped and a warning such as "Firmware doesn't support unregister all notifiers at once" is logged, e.g. on Versal NET firmware that predates this API.
--- drivers/firmware/xilinx/zynqmp.c | 14 ++++++++++++++ include/linux/firmware/xlnx-zynqmp.h | 3 +++ 2 files changed, 17 insertions(+)
drivers/firmware/xilinx/zynqmp.c +14 -0
@@ -2110,6 +2110,20 @@ static int zynqmp_clear_pm_state(struct device *dev) "Bulk device release is not supported by firmware: %d\n", ret); ret =0 ; } + +/* Check if the firmware supports the PM_ALL_NOTIFIERS node ID */ + ret =do_feature_check_call (PM_REGISTER_NOTIFIER ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to unregister all notifier callbacks via firmware */ + ret =zynqmp_pm_register_notifier (PM_ALL_NOTIFIERS ,0 ,0 ,0 ); +if (ret) +dev_err (dev,"Failed to unregister all notifiers: %d\n" , ret); + }else { +dev_warn (dev, +"Firmware doesn't support unregister all notifiers at once: %d\n" , + ret); + ret =0 ; + } }return ret;
include/linux/firmware/xlnx-zynqmp.h +3 -0
@@ -149,6 +149,9 @@/* Node ID for all peripheral devices */ #define PM_DEV_ALL_PERIPH 0x18224FFFU +/* Node ID for all notifier callbacks */ +#define PM_ALL_NOTIFIERS 0xFFFFFFFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Signature · 1 line
2.34.1
Re: [PATCH 3/4] firmware: xilinx: Clear firmware notifiers across kexec transitions
Quoted 8 lines · Jay Buddhabhatti
During a kexec restart, only the kernel is reloaded but notifier callbacks in firmware persist, causing state mismatches between kernel and firmware.
To address this, introduce
PM_ALL_NOTIFIERSnode ID to unregister all notifier callbacks during kexec. On a graceful kexec restart, this occurs inzynqmp_firmware_shutdown(). On a crash kernel restart, it happens inzynqmp_firmware_probe()in the reloaded kernel.
Quoted 8 lines
Unregistering all notifiers depends on firmware support for the
PM_ALL_NOTIFIERSnode ID. On firmware that does not implement it (the feature check reports a version belowPM_API_VERSION_3) the step is skipped and a warning such as "Firmware doesn't support unregister all notifiers at once" is logged, e.g. on Versal NET firmware that predates this API.Signed-off-by Jay Buddhabhatti <[email protected]>
Thanks!
Quoted 44 lines
--- drivers/firmware/xilinx/zynqmp.c | 14 ++++++++++++++ include/linux/firmware/xlnx-zynqmp.h | 3 +++ 2 files changed, 17 insertions(+)drivers/firmware/xilinx/zynqmp.c +14
-0@@ -2110,6 +2110,20 @@ static int zynqmp_clear_pm_state(struct device *dev) "Bulk device release is not supported by firmware: %d\n", ret); ret =0 ; } + +/* Check if the firmware supports the PM_ALL_NOTIFIERS node ID */ + ret =do_feature_check_call (PM_REGISTER_NOTIFIER ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to unregister all notifier callbacks via firmware */ + ret =zynqmp_pm_register_notifier (PM_ALL_NOTIFIERS ,0 ,0 ,0 ); +if (ret) +dev_err (dev,"Failed to unregister all notifiers: %d\n" , ret); + }else { +dev_warn (dev, +"Firmware doesn't support unregister all notifiers at once: %d\n" , + ret); + ret =0 ; + } }return ret;include/linux/firmware/xlnx-zynqmp.h +3
-0@@ -149,6 +149,9 @@/* Node ID for all peripheral devices */ #define PM_DEV_ALL_PERIPH 0x18224FFFU +/* Node ID for all notifier callbacks */ +#define PM_ALL_NOTIFIERS 0xFFFFFFFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Re: [PATCH 3/4] firmware: xilinx: Clear firmware notifiers across kexec transitions
In reply to Jay BuddhabhattiQuoted 51 lines · Jay Buddhabhatti
During a kexec restart, only the kernel is reloaded but notifier callbacks in firmware persist, causing state mismatches between kernel and firmware.
To address this, introduce
PM_ALL_NOTIFIERSnode ID to unregister all notifier callbacks during kexec. On a graceful kexec restart, this occurs inzynqmp_firmware_shutdown(). On a crash kernel restart, it happens inzynqmp_firmware_probe()in the reloaded kernel.Unregistering all notifiers depends on firmware support for the
PM_ALL_NOTIFIERSnode ID. On firmware that does not implement it (the feature check reports a version belowPM_API_VERSION_3) the step is skipped and a warning such as "Firmware doesn't support unregister all notifiers at once" is logged, e.g. on Versal NET firmware that predates this API.Signed-off-by Jay Buddhabhatti <[email protected]>--- drivers/firmware/xilinx/zynqmp.c | 14 ++++++++++++++ include/linux/firmware/xlnx-zynqmp.h | 3 +++ 2 files changed, 17 insertions(+)drivers/firmware/xilinx/zynqmp.c +14
-0@@ -2110,6 +2110,20 @@ static int zynqmp_clear_pm_state(struct device *dev) "Bulk device release is not supported by firmware: %d\n", ret); ret =0 ; } + +/* Check if the firmware supports the PM_ALL_NOTIFIERS node ID */ + ret =do_feature_check_call (PM_REGISTER_NOTIFIER ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to unregister all notifier callbacks via firmware */ + ret =zynqmp_pm_register_notifier (PM_ALL_NOTIFIERS ,0 ,0 ,0 ); +if (ret) +dev_err (dev,"Failed to unregister all notifiers: %d\n" , ret); + }else { +dev_warn (dev, +"Firmware doesn't support unregister all notifiers at once: %d\n" , + ret); + ret =0 ; + } }return ret;include/linux/firmware/xlnx-zynqmp.h +0
-0
include/linux/firmware/xlnx-zynqmp.h line 157
Quoted 9 lines
include/linux/firmware/xlnx-zynqmp.h +3
-0@@ -149,6 +149,9 @@/* Node ID for all peripheral devices */ #define PM_DEV_ALL_PERIPH 0x18224FFFU +/* Node ID for all notifier callbacks */ +#define PM_ALL_NOTIFIERS 0xFFFFFFFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Looks good to me.
PATCH 4/4 firmware: xilinx: Use TF-A feature check for TF-A specific APIs
In reply to Jay BuddhabhattiCurrently, TF-A-specific APIs are validated using the firmware PM_FEATURE_CHECK API, even though TF-A provides a dedicated mechanism via PM_API_FEATURES API. Ideally it should use the TF-A feature check (PM_API_FEATURES) for TF-A specific APIs. Update the feature check logic for TF-A specific API calls to ensure it is validated using PM_API_FEATURES. If this check fails, fall back to the legacy PM_FEATURE_CHECK to support backward compatibility.
When do_fw_call() fails, propagate the errno from zynqmp_pm_ret_code() instead of always returning -EOPNOTSUPP. This applies to every module ID, not only TF-A, because the rewrite sat in the common failure path. Existing callers only test ret < 0 and are unchanged.
--- drivers/firmware/xilinx/zynqmp.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)
drivers/firmware/xilinx/zynqmp.c +17 -14
@@ -224,34 +224,37 @@ static int __do_feature_check_call(const u32 api_id, u32 *ret_payload) module_id =FIELD_GET (MODULE_ID_MASK , api_id);/* -* Feature check of APIs belonging to PM, XSEM, and TF-A are handled by calling +* 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 || module_id ==TF_A_MODULE_ID ) +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 ; -/* -* Feature check of TF-A APIs is done in the TF-A layer and it expects for -* MODULE_ID_MASK bits of SMC's arg[0] to be the same as PM_MODULE_ID. -*/ -if (module_id ==TF_A_MODULE_ID ) { - module_id =PM_MODULE_ID ; +if (module_id ==TF_A_MODULE_ID ) smc_arg[1 ] = api_id; - }else { +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; ret =do_fw_call (ret_payload,2 , smc_arg[0 ], smc_arg[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 ]); + } +if (ret) - ret = -EOPNOTSUPP ; -else - ret = ret_payload[1 ]; +return ret; -return ret; +return ret_payload[1 ]; }static int do_feature_check_call (const u32 api_id)
Signature · 1 line
2.34.1
Re: [PATCH 4/4] firmware: xilinx: Use TF-A feature check for TF-A specific APIs
Quoted 8 lines · Jay Buddhabhatti
Currently, TF-A-specific APIs are validated using the firmware
PM_FEATURE_CHECKAPI, even though TF-A provides a dedicated mechanism viaPM_API_FEATURESAPI. Ideally it should use the TF-A feature check (PM_API_FEATURES) for TF-A specific APIs. Update the feature check logic for TF-A specific API calls to ensure it is validated usingPM_API_FEATURES. If this check fails, fall back to the legacyPM_FEATURE_CHECKto support backward compatibility.
Quoted 6 lines
When
do_fw_call()fails, propagate the errno fromzynqmp_pm_ret_code()instead of always returning-EOPNOTSUPP. This applies to every module ID, not only TF-A, because the rewrite sat in the common failure path. Existing callers only test ret < 0 and are unchanged.Signed-off-by Jay Buddhabhatti <[email protected]>
Thanks!
Quoted 60 lines
--- drivers/firmware/xilinx/zynqmp.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)drivers/firmware/xilinx/zynqmp.c +17
-14@@ -224,34 +224,37 @@ static int __do_feature_check_call(const u32 api_id, u32 *ret_payload) module_id =FIELD_GET (MODULE_ID_MASK , api_id);/* -* Feature check of APIs belonging to PM, XSEM, and TF-A are handled by calling +* 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 || module_id ==TF_A_MODULE_ID ) +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 ; -/* -* Feature check of TF-A APIs is done in the TF-A layer and it expects for -* MODULE_ID_MASK bits of SMC's arg[0] to be the same as PM_MODULE_ID. -*/ -if (module_id ==TF_A_MODULE_ID ) { - module_id =PM_MODULE_ID ; +if (module_id ==TF_A_MODULE_ID ) smc_arg[1 ] = api_id; - }else { +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; ret =do_fw_call (ret_payload,2 , smc_arg[0 ], smc_arg[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 ]); + } +if (ret) - ret = -EOPNOTSUPP ; -else - ret = ret_payload[1 ]; +return ret; -return ret; +return ret_payload[1 ]; }static int do_feature_check_call (const u32 api_id)
Re: [PATCH 4/4] firmware: xilinx: Use TF-A feature check for TF-A specific APIs
In reply to Jay BuddhabhattiHi Jay,
Quoted 52 lines · Jay Buddhabhatti
Currently, TF-A-specific APIs are validated using the firmware
PM_FEATURE_CHECKAPI, even though TF-A provides a dedicated mechanism viaPM_API_FEATURESAPI. Ideally it should use the TF-A feature check (PM_API_FEATURES) for TF-A specific APIs. Update the feature check logic for TF-A specific API calls to ensure it is validated usingPM_API_FEATURES. If this check fails, fall back to the legacyPM_FEATURE_CHECKto support backward compatibility.When
do_fw_call()fails, propagate the errno fromzynqmp_pm_ret_code()instead of always returning-EOPNOTSUPP. This applies to every module ID, not only TF-A, because the rewrite sat in the common failure path. Existing callers only test ret < 0 and are unchanged.Signed-off-by Jay Buddhabhatti <[email protected]>--- drivers/firmware/xilinx/zynqmp.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)drivers/firmware/xilinx/zynqmp.c +4
-10@@ -224,34 +224,37 @@ static int __do_feature_check_call(const u32 api_id, u32 *ret_payload) module_id =FIELD_GET (MODULE_ID_MASK , api_id);/* -* Feature check of APIs belonging to PM, XSEM, and TF-A are handled by calling +* 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 || module_id ==TF_A_MODULE_ID ) +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 ; -/* -* Feature check of TF-A APIs is done in the TF-A layer and it expects for -* MODULE_ID_MASK bits of SMC's arg[0] to be the same as PM_MODULE_ID. -*/ -if (module_id ==TF_A_MODULE_ID ) { - module_id =PM_MODULE_ID ; +if (module_id ==TF_A_MODULE_ID ) smc_arg[1 ] = api_id; - }else { +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; ret =do_fw_call (ret_payload,2 , smc_arg[0 ], smc_arg[1 ]);
drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id, u32 *ret_payload) · line 252
Quoted 10 lines
drivers/firmware/xilinx/zynqmp.c +10
-0+ +/* +* 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 ]); + }
This looks like a general improvement unrelated to the other patches in this series. I think this should go as a separate patch (not as a part of this series).
drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id, u32 *ret_payload) · line 260
Quoted 12 lines
drivers/firmware/xilinx/zynqmp.c +3
-4+if (ret) - ret = -EOPNOTSUPP ; -else - ret = ret_payload[1 ]; +return ret; -return ret; +return ret_payload[1 ]; }static int do_feature_check_call (const u32 api_id)
The return value change is separate improvement unrelated to the series or to the PM_API_FEATURES API usage. I think this change can be carved out to a separate patch.
Except for the above nits, code looks good to me.
Regards,
Prasanna Kumar
RE: [PATCH 4/4] firmware: xilinx: Use TF-A feature check for TF-A specific APIs
AMD General
Hi Prasanna,
Thanks for the review and the Reviewed-by tag.
Quoted 99 lines
-----Original Message-----
From: Prasanna Kumar T S M <[email protected]>
Sent: Friday, July 24, 2026 12:01 PM
To: Buddhabhatti, Jay <[email protected]>; Simek, Michal <[email protected]>; git (AMD-Xilinx) <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 4/4] firmware: xilinx: Use TF-A feature check for TF-A specific APIsHi Jay,
drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id,
Quoted 24 lines · Jay Buddhabhatti
Currently, TF-A-specific APIs are validated using the firmware
PM_FEATURE_CHECKAPI, even though TF-A provides a dedicated mechanism viaPM_API_FEATURESAPI. Ideally it should use the TF-A feature check (PM_API_FEATURES) for TF-A specific APIs. Update the feature check logic for TF-A specific API calls to ensure it is validated usingPM_API_FEATURES. If this check fails, fall back to the legacyPM_FEATURE_CHECKto support backward compatibility.When
do_fw_call()fails, propagate the errno fromzynqmp_pm_ret_code()instead of always returning-EOPNOTSUPP. This applies to every module ID, not only TF-A, because the rewrite sat in the common failure path. Existing callers only test ret < 0 and are unchanged.Signed-off-by Jay Buddhabhatti <[email protected]>--- drivers/firmware/xilinx/zynqmp.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-)drivers/firmware/xilinx/zynqmp.c +0
-0@@ -224,34 +224,37 @@ static int __do_feature_check_call(const u32 api_id,u32
*ret_payload)drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
Quoted 4 lines
drivers/firmware/xilinx/zynqmp.c +0
-1module_id =FIELD_GET (MODULE_ID_MASK , api_id);/* -* Feature check of APIs belonging to PM, XSEM, and TF-A are handled by calling
drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id, · line 229
Quoted 3 lines
drivers/firmware/xilinx/zynqmp.c +2
-0+ * Feature check of APIs belonging to PM and XSEM are handled by +calling * PM_FEATURE_CHECK API. For other modules, call PM_API_FEATURESAPI.
drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id, · line 230
Quoted 2 lines
drivers/firmware/xilinx/zynqmp.c +0
-1*/ - if (module_id == PM_MODULE_ID || module_id == XSEM_MODULE_ID ||
module_id==TF_A_MODULE_ID)drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
Quoted 8 lines
drivers/firmware/xilinx/zynqmp.c +1
-3+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 ; -/* -* Feature check of TF-A APIs is done in the TF-A layer and it expects for -* MODULE_ID_MASK bits of SMC's arg[0] to be the same as
PM_MODULE_ID.drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
Quoted 11 lines
drivers/firmware/xilinx/zynqmp.c +2
-5-*/ -if (module_id ==TF_A_MODULE_ID ) { - module_id =PM_MODULE_ID ; +if (module_id ==TF_A_MODULE_ID ) smc_arg[1 ] = api_id; - }else { +else smc_arg[1 ] = (api_id &API_ID_MASK ); - } smc_arg[0 ] =PM_SIP_SVC |FIELD_PREP (MODULE_ID_MASK , module_id)|
drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id, u32 *ret_payload)
Quoted 10 lines
drivers/firmware/xilinx/zynqmp.c +7
-0feature_check_api_id; ret =do_fw_call (ret_payload,2 , smc_arg[0 ], smc_arg[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) |drivers/firmware/xilinx/zynqmp.c static int __do_feature_check_call(const u32 api_id, u32 *ret_payload) · line 252
Quoted 3 lines
drivers/firmware/xilinx/zynqmp.c +3
-0+PM_FEATURE_CHECK ; + ret =do_fw_call (ret_payload,2 , smc_arg[0 ], smc_arg[1 ]); + }This looks like a general improvement unrelated to the other patches in this series. I think this should go as a separate patch (not as a part of this series).
Quoted 11 lines
drivers/firmware/xilinx/zynqmp.c +3
-4+if (ret) - ret = -EOPNOTSUPP ; -else - ret = ret_payload[1 ]; +return ret; -return ret; +return ret_payload[1 ]; }
Quoted 7 lines
Quoted 1 line
static int
do_feature_check_call(const u32 api_id)The return value change is separate improvement unrelated to the series or to the
PM_API_FEATURESAPI usage. I think this change can be carved out to a separate patch.Except for the above nits, code looks good to me.
Good point. I've split the original patch 4/4 into two standalone patches sent as a separate series:
[PATCH 1/2] firmware: xilinx: Use TF-A feature check for TF-A-specific APIs [PATCH 2/2] firmware: xilinx: Propagate actual error from feature check
The kexec series (v2) now contains only the three kexec-related patches (1-3) without any dependency on the feature check improvements.
Thanks,
Jay
Quoted 5 lines
Reviewed-by Prasanna Kumar T S M <[email protected]>Regards,
Prasanna Kumar
v2 cover firmware: xilinx: Clean up firmware and TF-A state on kexec
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded while the state held in TF-A and the platform firmware persists. This leaves the freshly booted kernel out of sync with the firmware for things like the SGI number, shutdown scope, allocated peripheral devices and registered notifier callbacks, which can lead to unexpected behaviour after a kexec.
Introduce a mechanism to clear the stale firmware/TF-A state so the reloaded kernel starts from a clean baseline:
- Add TF_A_CLEAR_PM_STATE to clear TF-A specific PM state.
- Add PM_DEV_ALL_PERIPH to release all peripheral devices in one call.
- Add PM_ALL_NOTIFIERS to unregister all notifier callbacks in one call.
On a graceful kexec reboot the cleanup is performed from zynqmp_firmware_shutdown(); on a crash (kdump) restart it is performed from zynqmp_firmware_probe() of the reloaded kernel. Each cleanup step is guarded by a feature check so it degrades gracefully on firmware/TF-A versions that do not implement the new APIs.
Changes in v2:
- Drop patch 4/4 (feature check improvements) from this series per review feedback. Those changes are sent separately as:
"[PATCH 1/2] firmware: xilinx: Use TF-A feature check for TF-A-specific APIs" and "[PATCH 2/2] firmware: xilinx: Propagate actual error from feature check"
Jay Buddhabhatti (3):
firmware: xilinx: Add support to clear TF-A PM state
firmware: xilinx: Release all peripheral devices from firmware
firmware: xilinx: Clear firmware notifiers across kexec transitions
drivers/firmware/xilinx/zynqmp.c | 77 ++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 10 +++- 2 files changed, 83 insertions(+), 4 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/4 firmware: xilinx: Add support to clear TF-A PM state
Currently, during a kexec restart, only the kernel is reloaded, while the TF-A specific data remain unchanged. This leads to a mismatch between the kernel state and the TF-A firmware state like SGI number and shutdown scope variable.
For example, the kernel registers an SGI number with TF-A so that TF-A can notify the kernel of events via that SGI. TF-A stores this SGI number in its internal state. After a kexec, the newly loaded kernel re-registers and may request a different SGI number, but the stale value programmed in TF-A remains, so event notifications are delivered on the old SGI and are missed by the new kernel. The shutdown scope variable has a similar stale state problem.
To resolve this, the TF_A_CLEAR_PM_STATE PM API is introduced to clear TF-A-specific state during kexec. On a graceful reboot, this API is triggered by zynqmp_firmware_shutdown(), while in a crash kernel scenario, it is invoked by zynqmp_firmware_probe() in the reloaded kernel.
--- drivers/firmware/xilinx/zynqmp.c | 51 +++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 3 +- 2 files changed, 52 insertions(+), 2 deletions(-)
drivers/firmware/xilinx/zynqmp.c +50 -1
@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2022 Xilinx, Inc. -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]>
@@ -13,6 +13,7 @@#include <linux/arm-smccc.h> #include <linux/compiler.h> +#include <linux/crash_dump.h> #include <linux/device.h> #include <linux/init.h> #include <linux/mfd/core.h>
@@ -2065,6 +2066,42 @@ static struct attribute *zynqmp_firmware_attrs[] = {ATTRIBUTE_GROUPS (zynqmp_firmware); +/** +* zynqmp_clear_pm_state() - Clear subsystem state. +* @dev: Device pointer used for logging. +* +* Clears PM specific data in TF-A. +* +* Return: Returns status, either success or error +*/ +static int zynqmp_clear_pm_state (struct device *dev) +{ +int ret; +u32 pm_family_code; + +/* Get the Family code of platform */ + ret =zynqmp_pm_get_family_info (&pm_family_code); +if (ret <0 ) +return ret; + +if (pm_family_code !=PM_ZYNQMP_FAMILY_CODE ) { +/* Check if the TF-A supports the TF_A_CLEAR_PM_STATE */ + ret =do_feature_check_call (TF_A_CLEAR_PM_STATE ); +if ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_1 ) { +/* Clear PM specific data in TF-A */ + ret =zynqmp_pm_invoke_fn (TF_A_CLEAR_PM_STATE ,NULL ,0 ); +if (ret) +dev_err (dev, +"Failed to clear TF-A specific subsystem state: %d\n" , ret); + }else { +dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); + ret =0 ; + } + } + +return ret; +} +static int zynqmp_firmware_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -2118,6 +2155,12 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)if (ret <0 )return ret; +if (is_kdump_kernel ()) { + ret =zynqmp_clear_pm_state (dev); +if (ret) +return ret; + } +/* Check trustzone version number */ ret =zynqmp_pm_get_trustzone_version (&pm_tz_version);if (ret)
@@ -2151,6 +2194,11 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)return of_platform_populate (dev->of_node,NULL ,NULL , dev); } +static void zynqmp_firmware_shutdown (struct platform_device *pdev) +{ +zynqmp_clear_pm_state (&pdev->dev); +} +static void zynqmp_firmware_remove (struct platform_device *pdev) {struct pm_api_feature_data *feature_data;
@@ -2210,5 +2258,6 @@ static struct platform_driver zynqmp_firmware_driver = { }, .probe = zynqmp_firmware_probe, .remove = zynqmp_firmware_remove, + .shutdown = zynqmp_firmware_shutdown, };module_platform_driver (zynqmp_firmware_driver);
include/linux/firmware/xlnx-zynqmp.h +2 -1
@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2021 Xilinx -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]>
@@ -66,6 +66,7 @@#define FIRMWARE_VERSION_MASK 0xFFFFU/* ATF only commands */ +#define TF_A_CLEAR_PM_STATE 0xa05#define TF_A_PM_REGISTER_SGI 0xa04#define PM_GET_TRUSTZONE_VERSION 0xa03#define PM_SET_SUSPEND_MODE 0xa02
Signature · 1 line
2.34.1
PATCH v2 2/4 firmware: xilinx: Release all peripheral devices from firmware
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded while devices allocated in firmware persist, causing state mismatches between the kernel and firmware.
Introduce PM_DEV_ALL_PERIPH node ID (0x18224FFFU) to release all peripheral devices during kexec. On graceful restarts, this happens in zynqmp_firmware_shutdown(). On crash kernel restarts, it happens in zynqmp_firmware_probe() of the reloaded kernel.
Releasing all peripherals depends on firmware support for the PM_DEV_ALL_PERIPH node ID. On firmware that does not implement it (the feature check reports a version below PM_API_VERSION_3) the release is skipped and a warning such as "Bulk device release is not supported by firmware" is logged, e.g. on Versal NET firmware that predates this API.
--- drivers/firmware/xilinx/zynqmp.c | 14 +++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-)
drivers/firmware/xilinx/zynqmp.c +13 -1
@@ -2070,7 +2070,7 @@ ATTRIBUTE_GROUPS(zynqmp_firmware);* zynqmp_clear_pm_state() - Clear subsystem state. * @dev: Device pointer used for logging. * -* Clears PM specific data in TF-A. +* Clears PM specific data in TF-A and firmware. * * Return: Returns status, either success or error */
@@ -2095,6 +2095,18 @@ static int zynqmp_clear_pm_state(struct device *dev) "Failed to clear TF-A specific subsystem state: %d\n", ret); }else {dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); + } + +/* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */ + ret =do_feature_check_call (PM_RELEASE_NODE ); +if ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 ) { +/* Attempt to release all peripheral devices via firmware */ + ret =zynqmp_pm_release_node (PM_DEV_ALL_PERIPH ); +if (ret) +dev_err (dev,"Failed to release all peripheral devices: %d\n" , ret); + }else { +dev_warn (dev, +"Bulk device release is not supported by firmware: %d\n" , ret); ret =0 ; } }
include/linux/firmware/xlnx-zynqmp.h +4 -0
@@ -50,6 +50,7 @@/* PM API versions */ #define PM_API_VERSION_1 1#define PM_API_VERSION_2 2 +#define PM_API_VERSION_3 3#define PM_PINCTRL_PARAM_SET_VERSION 2
@@ -145,6 +146,9 @@#define XPM_EVENT_ERROR_MASK_NOC_NCR BIT(13)#define XPM_EVENT_ERROR_MASK_NOC_CR BIT(12) +/* Node ID for all peripheral devices */ +#define PM_DEV_ALL_PERIPH 0x18224FFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Signature · 1 line
2.34.1
PATCH v2 3/4 firmware: xilinx: Clear firmware notifiers across kexec transitions
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded but notifier callbacks in firmware persist, causing state mismatches between kernel and firmware.
To address this, introduce PM_ALL_NOTIFIERS node ID to unregister all notifier callbacks during kexec. On a graceful kexec restart, this occurs in zynqmp_firmware_shutdown(). On a crash kernel restart, it happens in zynqmp_firmware_probe() in the reloaded kernel.
Unregistering all notifiers depends on firmware support for the PM_ALL_NOTIFIERS node ID. On firmware that does not implement it (the feature check reports a version below PM_API_VERSION_3) the step is skipped and a warning such as "Firmware doesn't support unregister all notifiers at once" is logged, e.g. on Versal NET firmware that predates this API.
--- drivers/firmware/xilinx/zynqmp.c | 13 +++++++++++++ include/linux/firmware/xlnx-zynqmp.h | 3 +++ 2 files changed, 16 insertions(+)
drivers/firmware/xilinx/zynqmp.c +13 -0
@@ -2107,6 +2107,19 @@ static int zynqmp_clear_pm_state(struct device *dev) }else {dev_warn (dev,"Bulk device release is not supported by firmware: %d\n" , ret); + } + +/* Check if the firmware supports the PM_ALL_NOTIFIERS node ID */ + ret =do_feature_check_call (PM_REGISTER_NOTIFIER ); +if ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 ) { +/* Attempt to unregister all notifier callbacks via firmware */ + ret =zynqmp_pm_register_notifier (PM_ALL_NOTIFIERS ,0 ,0 ,0 ); +if (ret) +dev_err (dev,"Failed to unregister all notifiers: %d\n" , ret); + }else { +dev_warn (dev, +"Firmware doesn't support unregister all notifiers at once: %d\n" , + ret); ret =0 ; } }
include/linux/firmware/xlnx-zynqmp.h +3 -0
@@ -149,6 +149,9 @@/* Node ID for all peripheral devices */ #define PM_DEV_ALL_PERIPH 0x18224FFFU +/* Node ID for all notifier callbacks */ +#define PM_ALL_NOTIFIERS 0xFFFFFFFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Signature · 1 line
2.34.1
v3 cover firmware: xilinx: Clean up firmware and TF-A state on kexec
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded while the state held in TF-A and the platform firmware persists. This leaves the freshly booted kernel out of sync with the firmware for things like the SGI number, shutdown scope, allocated peripheral devices and registered notifier callbacks, which can lead to unexpected behaviour after a kexec.
Introduce a mechanism to clear the stale firmware/TF-A state so the reloaded kernel starts from a clean baseline:
- Add TF_A_CLEAR_PM_STATE to clear TF-A specific PM state.
- Add PM_DEV_ALL_PERIPH to release all peripheral devices in one call.
- Add PM_ALL_NOTIFIERS to unregister all notifier callbacks in one call.
On a graceful kexec reboot the cleanup is performed from zynqmp_firmware_shutdown(); on a crash (kdump) restart it is performed from zynqmp_firmware_probe() of the reloaded kernel. Each cleanup step is guarded by a feature check so it degrades gracefully on firmware/TF-A versions that do not implement the new APIs.
Changes in v3:
- Corrected subject prefix
Changes in v2:
- Drop patch 4/4 (feature check improvements) from this series per review feedback. Those changes are sent separately as:
"[PATCH 1/2] firmware: xilinx: Use TF-A feature check for TF-A-specific APIs" and "[PATCH 2/2] firmware: xilinx: Propagate actual error from feature check"
Jay Buddhabhatti (3):
firmware: xilinx: Add support to clear TF-A PM state
firmware: xilinx: Release all peripheral devices from firmware
firmware: xilinx: Clear firmware notifiers across kexec transitions
drivers/firmware/xilinx/zynqmp.c | 75 +++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 10 +++- 2 files changed, 83 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 1/3 firmware: xilinx: Add support to clear TF-A PM state
Currently, during a kexec restart, only the kernel is reloaded, while the TF-A specific data remain unchanged. This leads to a mismatch between the kernel state and the TF-A firmware state like SGI number and shutdown scope variable.
For example, the kernel registers an SGI number with TF-A so that TF-A can notify the kernel of events via that SGI. TF-A stores this SGI number in its internal state. After a kexec, the newly loaded kernel re-registers and may request a different SGI number, but the stale value programmed in TF-A remains, so event notifications are delivered on the old SGI and are missed by the new kernel. The shutdown scope variable has a similar stale state problem.
To resolve this, the TF_A_CLEAR_PM_STATE PM API is introduced to clear TF-A-specific state during kexec. On a graceful reboot, this API is triggered by zynqmp_firmware_shutdown(), while in a crash kernel scenario, it is invoked by zynqmp_firmware_probe() in the reloaded kernel.
--- drivers/firmware/xilinx/zynqmp.c | 48 +++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 3 +- 2 files changed, 49 insertions(+), 2 deletions(-)
drivers/firmware/xilinx/zynqmp.c +47 -1
@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2022 Xilinx, Inc. -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]>
@@ -13,6 +13,7 @@#include <linux/arm-smccc.h> #include <linux/compiler.h> +#include <linux/crash_dump.h> #include <linux/device.h> #include <linux/init.h> #include <linux/mfd/core.h>
@@ -2065,6 +2066,42 @@ static struct attribute *zynqmp_firmware_attrs[] = {ATTRIBUTE_GROUPS (zynqmp_firmware); +/** +* zynqmp_clear_pm_state() - Clear subsystem state +* @dev: Device pointer used for logging +* +* Clears PM specific data in TF-A. +* +* Return: Returns status, either success or error +*/ +static int zynqmp_clear_pm_state (struct device *dev) +{ +u32 pm_family_code; +int ret; + +/* Get the Family code of platform */ + ret =zynqmp_pm_get_family_info (&pm_family_code); +if (ret <0 ) +return ret; + +if (pm_family_code !=PM_ZYNQMP_FAMILY_CODE ) { +/* Check if the TF-A supports the TF_A_CLEAR_PM_STATE */ + ret =do_feature_check_call (TF_A_CLEAR_PM_STATE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_1 )) { +/* Clear PM specific data in TF-A */ + ret =zynqmp_pm_invoke_fn (TF_A_CLEAR_PM_STATE ,NULL ,0 ); +if (ret) +dev_err (dev, +"Failed to clear TF-A specific subsystem state: %d\n" , ret); + }else { +dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); + ret =0 ; + } + } + +return ret; +} +static int zynqmp_firmware_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -2118,6 +2155,9 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)if (ret <0 )return ret; +if (is_kdump_kernel ()) +zynqmp_clear_pm_state (dev); +/* Check trustzone version number */ ret =zynqmp_pm_get_trustzone_version (&pm_tz_version);if (ret)
@@ -2151,6 +2191,11 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)return of_platform_populate (dev->of_node,NULL ,NULL , dev); } +static void zynqmp_firmware_shutdown (struct platform_device *pdev) +{ +zynqmp_clear_pm_state (&pdev->dev); +} +static void zynqmp_firmware_remove (struct platform_device *pdev) {struct pm_api_feature_data *feature_data;
@@ -2210,5 +2255,6 @@ static struct platform_driver zynqmp_firmware_driver = { }, .probe = zynqmp_firmware_probe, .remove = zynqmp_firmware_remove, + .shutdown = zynqmp_firmware_shutdown, };module_platform_driver (zynqmp_firmware_driver);
include/linux/firmware/xlnx-zynqmp.h +2 -1
@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2021 Xilinx -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]>
@@ -66,6 +66,7 @@#define FIRMWARE_VERSION_MASK 0xFFFFU/* ATF only commands */ +#define TF_A_CLEAR_PM_STATE 0xa05#define TF_A_PM_REGISTER_SGI 0xa04#define PM_GET_TRUSTZONE_VERSION 0xa03#define PM_SET_SUSPEND_MODE 0xa02
Signature · 1 line
2.34.1
Re: [PATCH v3 1/3] firmware: xilinx: Add support to clear TF-A PM state
Quoted 5 lines · Jay Buddhabhatti
Currently, during a kexec restart, only the kernel is reloaded, while the TF-A specific data remain unchanged. This leads to a mismatch between the kernel state and the TF-A firmware state like SGI number and shutdown scope variable.
Avoid using TF-A in general as it can be any other firmware as well. You can always generalise as PSCI or EL3 firmware.
Quoted 8 lines
For example, the kernel registers an SGI number with TF-A so that TF-A can notify the kernel of events via that SGI. TF-A stores this SGI number in its internal state. After a kexec, the newly loaded kernel re-registers and may request a different SGI number, but the stale value programmed in TF-A remains, so event notifications are delivered on the old SGI and are missed by the new kernel. The shutdown scope variable has a similar stale state problem.
Doesn't it reset it every time CPU_OFF or CPU_ON is called ?
Quoted 5 lines
To resolve this, the
TF_A_CLEAR_PM_STATEPM API is introduced to clear TF-A-specific state during kexec. On a graceful reboot, this API is triggered byzynqmp_firmware_shutdown(), while in a crash kernel scenario, it is invoked byzynqmp_firmware_probe()in the reloaded kernel.
I don't see the need for such an API just for kexec needs. You must deal with it as part of CPU_ON as it should start with clean slate as SGIs are per CPU, no ?
Signature · 2 lines
Regards, Sudeep
Re: [PATCH v3 1/3] firmware: xilinx: Add support to clear TF-A PM state
Hi Sudeep,
Thanks for the review. Replies inline.
Quoted 9 lines · Sudeep Holla
Quoted 5 lines · Jay Buddhabhatti
Currently, during a kexec restart, only the kernel is reloaded, while the TF-A specific data remain unchanged. This leads to a mismatch between the kernel state and the TF-A firmware state like SGI number and shutdown scope variable.
Avoid using TF-A in general as it can be any other firmware as well. You can always generalise as PSCI or EL3 firmware.
Agreed. Updated the commit message and in-patch comments to refer to "EL3 firmware" / "secure firmware" rather than TF-A.
Quoted 11 lines
Quoted 9 lines
For example, the kernel registers an SGI number with TF-A so that TF-A can notify the kernel of events via that SGI. TF-A stores this SGI number in its internal state. After a kexec, the newly loaded kernel re-registers and may request a different SGI number, but the stale value programmed in TF-A remains, so event notifications are delivered on the old SGI and are missed by the new kernel. The shutdown scope variable has a similar stale state problem.
Doesn't it reset it every time
CPU_OFForCPU_ONis called ?
No. The SGI registration is done once via zynqmp_pm_register_sgi() when the event manager driver probes; it programs the SGI number into EL3 PM state. On CPU hotplug, the kernel only enables/disables the per-CPU IRQ (enable_percpu_irq() / disable_percpu_irq() in xlnx_event_manager.c); it does not re-register the SGI with EL3 on CPU_ON or clear that registration on CPU_OFF.
So while SGI delivery is per-CPU from the GIC side, the SGI number EL3 uses to raise the interrupt is subsystem-global state held in EL3, not per-CPU state that is reset by CPU hotplug.
Quoted 10 lines
Quoted 6 lines
To resolve this, the
TF_A_CLEAR_PM_STATEPM API is introduced to clear TF-A-specific state during kexec. On a graceful reboot, this API is triggered byzynqmp_firmware_shutdown(), while in a crash kernel scenario, it is invoked byzynqmp_firmware_probe()in the reloaded kernel.I don't see the need for such an API just for kexec needs. You must deal with it as part of
CPU_ONas it should start with clean slate as SGIs are per CPU, no ?
Handling this purely in the CPU_ON path would require either EL3 to clear/re-init this PM state on every CPU bring-up, or the kernel to re-register the SGI on every CPU_ON. Neither happens today. CPU_ON is not the point at which this state is established or torn down; driver probe/shutdown is. That is why the platform firmware exposes TF_A_CLEAR_PM_STATE - to reset EL3 PM subsystem state when the OS is replaced without a full firmware reload.
The kexec cleanup is therefore a targeted reset at the OS transition
boundary (zynqmp_firmware_shutdown() on graceful kexec, zynqmp_firmware_probe() on kdump), not a general CPU hotplug hook. Given the above, I believe adding a dedicated API and invoking it at the kexec boundary is the correct approach.
Thanks,
Jay
Quoted 1 line
PATCH v3 2/3 firmware: xilinx: Release all peripheral devices from firmware
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded while devices allocated in firmware persist, causing state mismatches between the kernel and firmware.
Introduce PM_DEV_ALL_PERIPH node ID (0x18224FFFU) to release all peripheral devices during kexec. On graceful restarts, this happens in zynqmp_firmware_shutdown(). On crash kernel restarts, it happens in zynqmp_firmware_probe() of the reloaded kernel.
Releasing all peripherals depends on firmware support for the PM_DEV_ALL_PERIPH node ID. On firmware that does not implement it (the feature check reports a version below PM_API_VERSION_3) the release is skipped and a warning such as "Bulk device release is not supported by firmware" is logged, e.g. on Versal NET firmware that predates this API.
--- drivers/firmware/xilinx/zynqmp.c | 15 ++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/firmware/xilinx/zynqmp.c +14 -1
@@ -2070,7 +2070,7 @@ ATTRIBUTE_GROUPS(zynqmp_firmware);* zynqmp_clear_pm_state() - Clear subsystem state * @dev: Device pointer used for logging * -* Clears PM specific data in TF-A. +* Clears PM specific data in TF-A and firmware. * * Return: Returns status, either success or error */
@@ -2097,6 +2097,19 @@ static int zynqmp_clear_pm_state(struct device *dev)dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported in TF-A: %d\n" , ret); ret =0 ; } + +/* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */ + ret =do_feature_check_call (PM_RELEASE_NODE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to release all peripheral devices via firmware */ + ret =zynqmp_pm_release_node (PM_DEV_ALL_PERIPH ); +if (ret) +dev_err (dev,"Failed to release all peripheral devices: %d\n" , ret); + }else { +dev_warn (dev, +"Bulk device release is not supported by firmware: %d\n" , ret); + ret =0 ; + } }return ret;
include/linux/firmware/xlnx-zynqmp.h +4 -0
@@ -50,6 +50,7 @@/* PM API versions */ #define PM_API_VERSION_1 1#define PM_API_VERSION_2 2 +#define PM_API_VERSION_3 3#define PM_PINCTRL_PARAM_SET_VERSION 2
@@ -145,6 +146,9 @@#define XPM_EVENT_ERROR_MASK_NOC_NCR BIT(13)#define XPM_EVENT_ERROR_MASK_NOC_CR BIT(12) +/* Node ID for all peripheral devices */ +#define PM_DEV_ALL_PERIPH 0x18224FFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Signature · 1 line
2.34.1
PATCH v3 3/3 firmware: xilinx: Clear firmware notifiers across kexec transitions
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded but notifier callbacks in firmware persist, causing state mismatches between kernel and firmware.
To address this, introduce PM_ALL_NOTIFIERS node ID to unregister all notifier callbacks during kexec. On a graceful kexec restart, this occurs in zynqmp_firmware_shutdown(). On a crash kernel restart, it happens in zynqmp_firmware_probe() in the reloaded kernel.
Unregistering all notifiers depends on firmware support for the PM_ALL_NOTIFIERS node ID. On firmware that does not implement it (the feature check reports a version below PM_API_VERSION_3) the step is skipped and a warning such as "Firmware doesn't support unregister all notifiers at once" is logged, e.g. on Versal NET firmware that predates this API.
--- drivers/firmware/xilinx/zynqmp.c | 14 ++++++++++++++ include/linux/firmware/xlnx-zynqmp.h | 3 +++ 2 files changed, 17 insertions(+)
drivers/firmware/xilinx/zynqmp.c +14 -0
@@ -2110,6 +2110,20 @@ static int zynqmp_clear_pm_state(struct device *dev) "Bulk device release is not supported by firmware: %d\n", ret); ret =0 ; } + +/* Check if the firmware supports the PM_ALL_NOTIFIERS node ID */ + ret =do_feature_check_call (PM_REGISTER_NOTIFIER ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to unregister all notifier callbacks via firmware */ + ret =zynqmp_pm_register_notifier (PM_ALL_NOTIFIERS ,0 ,0 ,0 ); +if (ret) +dev_err (dev,"Failed to unregister all notifiers: %d\n" , ret); + }else { +dev_warn (dev, +"Firmware doesn't support unregister all notifiers at once: %d\n" , + ret); + ret =0 ; + } }return ret;
include/linux/firmware/xlnx-zynqmp.h +3 -0
@@ -149,6 +149,9 @@/* Node ID for all peripheral devices */ #define PM_DEV_ALL_PERIPH 0x18224FFFU +/* Node ID for all notifier callbacks */ +#define PM_ALL_NOTIFIERS 0xFFFFFFFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Signature · 1 line
2.34.1
v4 cover firmware: xilinx: Clean up firmware and EL3 state on kexec
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded while the state held in EL3 and platform firmware persists. This leaves the freshly booted kernel out of sync with secure firmware for things like the SGI number, shutdown scope, allocated peripheral devices and registered notifier callbacks, which can lead to unexpected behaviour after a kexec.
Introduce a mechanism to clear the stale EL3 and platform firmware state so the reloaded kernel starts from a clean baseline:
- Add TF_A_CLEAR_PM_STATE to clear EL3 PM subsystem state.
- Add PM_DEV_ALL_PERIPH to release all peripheral devices in one call.
- Add PM_ALL_NOTIFIERS to unregister all notifier callbacks in one call.
On a graceful kexec reboot the cleanup is performed from zynqmp_firmware_shutdown(); on a crash (kdump) restart it is performed from zynqmp_firmware_probe() of the reloaded kernel. Each cleanup step is guarded by a feature check so it degrades gracefully on firmware versions that do not implement the new APIs.
Changes in v4:
- Modified platform check to restrict kexec cleanup to Versal and Versal Net platforms only
- Used EL3 firmware instead of TF-A in descriptions and comments
Changes in v3:
- Corrected subject prefix
Changes in v2:
- Drop patch 4/4 (feature check improvements) from this series per review feedback. Those changes are sent separately as:
"[PATCH 1/2] firmware: xilinx: Use TF-A feature check for TF-A-specific APIs" and "[PATCH 2/2] firmware: xilinx: Propagate actual error from feature check"
Jay Buddhabhatti (3):
firmware: xilinx: Add support to clear EL3 PM state
firmware: xilinx: Release all peripheral devices from firmware
firmware: xilinx: Clear firmware notifiers across kexec transitions
drivers/firmware/xilinx/zynqmp.c | 86 +++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 10 +++- 2 files changed, 94 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH v4 1/3 firmware: xilinx: Add support to clear EL3 PM state
Currently, during a kexec restart, only the kernel is reloaded, while EL3-specific data remain unchanged. This leads to a mismatch between the kernel state and secure firmware state like SGI number and shutdown scope variable.
For example, the kernel registers an SGI number with EL3 firmware so that secure firmware can notify the kernel of events via that SGI. EL3 stores this SGI number in its internal state. After a kexec, the newly loaded kernel re-registers and may request a different SGI number, but the stale value programmed in EL3 remains, so event notifications are delivered on the old SGI and are missed by the new kernel. The shutdown scope variable has a similar stale state problem.
To resolve this, the TF_A_CLEAR_PM_STATE PM API is introduced to clear EL3 PM subsystem state during kexec. On a graceful reboot, this API is triggered by zynqmp_firmware_shutdown(), while in a crash kernel scenario, it is invoked by zynqmp_firmware_probe() in the reloaded kernel.
--- drivers/firmware/xilinx/zynqmp.c | 50 +++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 3 +- 2 files changed, 51 insertions(+), 2 deletions(-)
drivers/firmware/xilinx/zynqmp.c +49 -1
@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2022 Xilinx, Inc. -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]>
@@ -13,6 +13,7 @@#include <linux/arm-smccc.h> #include <linux/compiler.h> +#include <linux/crash_dump.h> #include <linux/device.h> #include <linux/init.h> #include <linux/mfd/core.h>
@@ -2065,6 +2066,44 @@ static struct attribute *zynqmp_firmware_attrs[] = {ATTRIBUTE_GROUPS (zynqmp_firmware); +/** +* zynqmp_clear_pm_state() - Clear subsystem state +* @dev: Device pointer used for logging +* +* Clears PM specific data in EL3 firmware. +* +* Return: Returns status, either success or error +*/ +static int zynqmp_clear_pm_state (struct device *dev) +{ +u32 pm_family_code; +int ret; + +/* Get the Family code of platform */ + ret =zynqmp_pm_get_family_info (&pm_family_code); +if (ret <0 ) +return ret; + +/* Supporting on Versal and Versal Net platforms only */ +if (pm_family_code ==PM_VERSAL_FAMILY_CODE || + pm_family_code ==PM_VERSAL_NET_FAMILY_CODE ) { +/* Check if EL3 firmware supports TF_A_CLEAR_PM_STATE */ + ret =do_feature_check_call (TF_A_CLEAR_PM_STATE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_1 )) { +/* Clear PM specific data in EL3 firmware */ + ret =zynqmp_pm_invoke_fn (TF_A_CLEAR_PM_STATE ,NULL ,0 ); +if (ret) +dev_err (dev, +"Failed to clear EL3 PM subsystem state: %d\n" , ret); + }else { +dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported by EL3 firmware: %d\n" , ret); + ret =0 ; + } + } + +return ret; +} +static int zynqmp_firmware_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev;
@@ -2118,6 +2157,9 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)if (ret <0 )return ret; +if (is_kdump_kernel ()) +zynqmp_clear_pm_state (dev); +/* Check trustzone version number */ ret =zynqmp_pm_get_trustzone_version (&pm_tz_version);if (ret)
@@ -2151,6 +2193,11 @@ static int zynqmp_firmware_probe(struct platform_device *pdev)return of_platform_populate (dev->of_node,NULL ,NULL , dev); } +static void zynqmp_firmware_shutdown (struct platform_device *pdev) +{ +zynqmp_clear_pm_state (&pdev->dev); +} +static void zynqmp_firmware_remove (struct platform_device *pdev) {struct pm_api_feature_data *feature_data;
@@ -2210,5 +2257,6 @@ static struct platform_driver zynqmp_firmware_driver = { }, .probe = zynqmp_firmware_probe, .remove = zynqmp_firmware_remove, + .shutdown = zynqmp_firmware_shutdown, };module_platform_driver (zynqmp_firmware_driver);
include/linux/firmware/xlnx-zynqmp.h +2 -1
@@ -3,7 +3,7 @@* Xilinx Zynq MPSoC Firmware layer * * Copyright (C) 2014-2021 Xilinx -* Copyright (C) 2022 - 2025 Advanced Micro Devices, Inc. +* Copyright (C) 2022 - 2026 Advanced Micro Devices, Inc. * * Michal Simek <[email protected]> * Davorin Mista <[email protected]>
@@ -66,6 +66,7 @@#define FIRMWARE_VERSION_MASK 0xFFFFU/* ATF only commands */ +#define TF_A_CLEAR_PM_STATE 0xa05#define TF_A_PM_REGISTER_SGI 0xa04#define PM_GET_TRUSTZONE_VERSION 0xa03#define PM_SET_SUSPEND_MODE 0xa02
Signature · 1 line
2.34.1
PATCH v4 2/3 firmware: xilinx: Release all peripheral devices from firmware
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded while devices allocated in firmware persist, causing state mismatches between the kernel and firmware.
Introduce PM_DEV_ALL_PERIPH node ID (0x18224FFFU) to release all peripheral devices during kexec. On graceful restarts, this happens in zynqmp_firmware_shutdown(). On crash kernel restarts, it happens in zynqmp_firmware_probe() of the reloaded kernel.
Releasing all peripherals depends on firmware support for the PM_DEV_ALL_PERIPH node ID. On firmware that does not implement it (the feature check reports a version below PM_API_VERSION_3) the release is skipped and a warning such as "Bulk device release is not supported by firmware" is logged, e.g. on Versal NET firmware that predates this API.
--- drivers/firmware/xilinx/zynqmp.c | 15 ++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-)
drivers/firmware/xilinx/zynqmp.c +14 -1
@@ -2070,7 +2070,7 @@ ATTRIBUTE_GROUPS(zynqmp_firmware);* zynqmp_clear_pm_state() - Clear subsystem state * @dev: Device pointer used for logging * -* Clears PM specific data in EL3 firmware. +* Clears PM specific data in EL3 and platform firmware. * * Return: Returns status, either success or error */
@@ -2099,6 +2099,19 @@ static int zynqmp_clear_pm_state(struct device *dev)dev_warn (dev,"TF_A_CLEAR_PM_STATE is not supported by EL3 firmware: %d\n" , ret); ret =0 ; } + +/* Check if the firmware supports the PM_DEV_ALL_PERIPH node ID */ + ret =do_feature_check_call (PM_RELEASE_NODE ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to release all peripheral devices via firmware */ + ret =zynqmp_pm_release_node (PM_DEV_ALL_PERIPH ); +if (ret) +dev_err (dev,"Failed to release all peripheral devices: %d\n" , ret); + }else { +dev_warn (dev, +"Bulk device release is not supported by firmware: %d\n" , ret); + ret =0 ; + } }return ret;
include/linux/firmware/xlnx-zynqmp.h +4 -0
@@ -50,6 +50,7 @@/* PM API versions */ #define PM_API_VERSION_1 1#define PM_API_VERSION_2 2 +#define PM_API_VERSION_3 3#define PM_PINCTRL_PARAM_SET_VERSION 2
@@ -145,6 +146,9 @@#define XPM_EVENT_ERROR_MASK_NOC_NCR BIT(13)#define XPM_EVENT_ERROR_MASK_NOC_CR BIT(12) +/* Node ID for all peripheral devices */ +#define PM_DEV_ALL_PERIPH 0x18224FFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Signature · 1 line
2.34.1
PATCH v4 3/3 firmware: xilinx: Clear firmware notifiers across kexec transitions
In reply to Jay BuddhabhattiDuring a kexec restart, only the kernel is reloaded but notifier callbacks in firmware persist, causing state mismatches between kernel and firmware.
To address this, introduce PM_ALL_NOTIFIERS node ID to unregister all notifier callbacks during kexec. On a graceful kexec restart, this occurs in zynqmp_firmware_shutdown(). On a crash kernel restart, it happens in zynqmp_firmware_probe() in the reloaded kernel.
Unregistering all notifiers depends on firmware support for the PM_ALL_NOTIFIERS node ID. On firmware that does not implement it (the feature check reports a version below PM_API_VERSION_3) the step is skipped and a warning such as "Firmware doesn't support unregister all notifiers at once" is logged, e.g. on Versal NET firmware that predates this API.
--- drivers/firmware/xilinx/zynqmp.c | 14 ++++++++++++++ include/linux/firmware/xlnx-zynqmp.h | 3 +++ 2 files changed, 17 insertions(+)
drivers/firmware/xilinx/zynqmp.c +14 -0
@@ -2112,6 +2112,20 @@ static int zynqmp_clear_pm_state(struct device *dev) "Bulk device release is not supported by firmware: %d\n", ret); ret =0 ; } + +/* Check if the firmware supports the PM_ALL_NOTIFIERS node ID */ + ret =do_feature_check_call (PM_REGISTER_NOTIFIER ); +if (ret >=0 && ((ret &FIRMWARE_VERSION_MASK ) >=PM_API_VERSION_3 )) { +/* Attempt to unregister all notifier callbacks via firmware */ + ret =zynqmp_pm_register_notifier (PM_ALL_NOTIFIERS ,0 ,0 ,0 ); +if (ret) +dev_err (dev,"Failed to unregister all notifiers: %d\n" , ret); + }else { +dev_warn (dev, +"Firmware doesn't support unregister all notifiers at once: %d\n" , + ret); + ret =0 ; + } }return ret;
include/linux/firmware/xlnx-zynqmp.h +3 -0
@@ -149,6 +149,9 @@/* Node ID for all peripheral devices */ #define PM_DEV_ALL_PERIPH 0x18224FFFU +/* Node ID for all notifier callbacks */ +#define PM_ALL_NOTIFIERS 0xFFFFFFFFU +enum pm_module_id {PM_MODULE_ID =0x0 ,XPM_MODULE_ID =0x2 ,
Signature · 1 line
2.34.1
Re: [PATCH v4 0/3] firmware: xilinx: Clean up firmware and EL3 state on kexec
In reply to Jay BuddhabhattiQuoted 34 lines · Jay Buddhabhatti
During a kexec restart, only the kernel is reloaded while the state held in EL3 and platform firmware persists. This leaves the freshly booted kernel out of sync with secure firmware for things like the SGI number, shutdown scope, allocated peripheral devices and registered notifier callbacks, which can lead to unexpected behaviour after a kexec.
Introduce a mechanism to clear the stale EL3 and platform firmware state so the reloaded kernel starts from a clean baseline:
- Add
TF_A_CLEAR_PM_STATEto clear EL3 PM subsystem state.
- AddPM_DEV_ALL_PERIPHto release all peripheral devices in one call.
- AddPM_ALL_NOTIFIERSto unregister all notifier callbacks in one call.On a graceful kexec reboot the cleanup is performed from
zynqmp_firmware_shutdown(); on a crash (kdump) restart it is performed fromzynqmp_firmware_probe()of the reloaded kernel. Each cleanup step is guarded by a feature check so it degrades gracefully on firmware versions that do not implement the new APIs.Changes in v4:
- Modified platform check to restrict kexec cleanup to Versal and Versal Net platforms only
- Used EL3 firmware instead of TF-A in descriptions and commentsChanges in v3:
- Corrected subject prefixChanges in v2:
- Drop patch 4/4 (feature check improvements) from this series per review feedback. Those changes are sent separately as:
"[PATCH 1/2] firmware: xilinx: Use TF-A feature check for TF-A-specific APIs" and "[PATCH 2/2] firmware: xilinx: Propagate actual error from feature check"
Quoted 9 lines
Jay Buddhabhatti (3):
firmware: xilinx: Add support to clear EL3 PM state
firmware: xilinx: Release all peripheral devices from firmware
firmware: xilinx: Clear firmware notifiers across kexec transitionsdrivers/firmware/xilinx/zynqmp.c | 86 +++++++++++++++++++++++++++- include/linux/firmware/xlnx-zynqmp.h | 10 +++- 2 files changed, 94 insertions(+), 2 deletions(-)
Applied.
M