Add support for last reset reason
cover Add support for last reset reason
Add support to get the last reset reason using IOCTL API and sysfs usage. Accordingly, the end user can know the reason behind the last system reset by querying the IOCTL API or the sysfs interface.
Ronak Jain (2):
firmware: xilinx: Add support for GET_LAST_RESET_REASON IOCTL
xilinx: firmware: Add sysfs to get last reset reason
.../ABI/stable/sysfs-driver-firmware-zynqmp | 13 ++++++ drivers/firmware/xilinx/zynqmp.c | 43 +++++++++++++++++++ include/linux/firmware/xlnx-zynqmp.h | 19 ++++++++ 3 files changed, 75 insertions(+)
Signature · 1 line
2.25.1
PATCH 1/2 firmware: xilinx: Add support for GET_LAST_RESET_REASON IOCTL
Add GET_LAST_RESET_REASON IOCTL support to check the last reset reason.
As per the current code base in the firmware, the firmware clears all reset reasons, except the latest system reset reason. Also, the reset reason can not be completely cleared as the ROM need to know if the last reset was due to the system reset or not.
Hence, the firmware clears all POR and sys resets except the latest so the next reset reason can be uniquely identified and the same can be checked by the end user by calling the IOCTL API.
The current supported reset reasons as below.
1. PM_RESET_REASON_EXT_POR - The POR button was pressed outside of the system
2. PM_RESET_REASON_SW_POR - An internal POR was caused by software
3. PM_RESET_REASON_SLR_POR - One of the other SSIT slices caused a POR
4. PM_RESET_REASON_ERR_POR - An error caused a POR
5. PM_RESET_REASON_DAP_SRST - JTAG TAP initiated system reset
6. PM_RESET_REASON_ERR_SRST - Error initiated system reset
7. PM_RESET_REASON_SW_SRST - Software initiated system reset
8. PM_RESET_REASON_SLR_SRST - One of the other SSIT slices caused a system reset
--- drivers/firmware/xilinx/zynqmp.c | 7 +++++++ include/linux/firmware/xlnx-zynqmp.h | 8 ++++++++ 2 files changed, 15 insertions(+)
drivers/firmware/xilinx/zynqmp.c +7 -0
@@ -909,6 +909,13 @@ int zynqmp_pm_set_tapdelay_bypass(u32 index, u32 value) }EXPORT_SYMBOL_GPL (zynqmp_pm_set_tapdelay_bypass); +int zynqmp_pm_get_last_reset_reason (u32 *reset_reason) +{ +return zynqmp_pm_invoke_fn (PM_IOCTL ,0 ,IOCTL_GET_LAST_RESET_REASON ,0 , +0 , reset_reason); +} +EXPORT_SYMBOL_GPL (zynqmp_pm_get_last_reset_reason); +/** * zynqmp_pm_set_boot_health_status() - PM API for setting healthy boot status * @value: Status value to be written
include/linux/firmware/xlnx-zynqmp.h +8 -0
@@ -190,6 +190,8 @@ enum pm_ioctl_id {/* Set healthy bit value */ IOCTL_SET_BOOT_HEALTH_STATUS =17 ,IOCTL_OSPI_MUX_SELECT =21 , +/* IOCTL to get last reset reason */ +IOCTL_GET_LAST_RESET_REASON =23 ,/* Register SGI to ATF */ IOCTL_REGISTER_SGI = 25,/* Runtime feature configuration */
@@ -585,6 +587,7 @@ int zynqmp_pm_set_tcm_config(u32 node_id, enum rpu_tcm_comb tcm_mode);int zynqmp_pm_set_sd_config (u32 node,enum pm_sd_config_type config,u32 value);int zynqmp_pm_set_gem_config (u32 node,enum pm_gem_config_type config,u32 value); +int zynqmp_pm_get_last_reset_reason (u32 *reset_reason);#else static inline int zynqmp_pm_get_api_version (u32 *version) {
@@ -909,6 +912,11 @@ static inline int zynqmp_pm_set_gem_config(u32 node,return -ENODEV ; } +static inline int zynqmp_pm_get_last_reset_reason (u32 *reset_reason) +{ +return -ENODEV ; +} +#endif #endif /* __FIRMWARE_ZYNQMP_H__ */
Signature · 1 line
2.25.1
PATCH 2/2 xilinx: firmware: Add sysfs to get last reset reason
In reply to Ronak JainAdd sysfs interface to get the last reset reason of the system from a user space.
When the system reset happens whether intentionally or due to some errors, the firmware used to store the last reset reason and the same be queried by using the IOCTL API or the sysfs entry to know the reason behind the system reset and accordingly, the error can be diagnostic.
--- .../ABI/stable/sysfs-driver-firmware-zynqmp | 13 +++++++ drivers/firmware/xilinx/zynqmp.c | 36 +++++++++++++++++++ include/linux/firmware/xlnx-zynqmp.h | 11 ++++++ 3 files changed, 60 insertions(+)
Documentation/ABI/stable/sysfs-driver-firmware-zynqmp +13 -0
@@ -254,3 +254,16 @@ Description: The expected result is 500. Users: Xilinx + +What: /sys/devices/platform/firmware\:zynqmp-firmware/last_reset_reason +Date: Nov 2023 +KernelVersion: 6.7 +Contact: "Ronak Jain" <[email protected]> +Description: + This sysfs interface allows to get last reset reason. + + Usage: + Get last reset reason + # cat /sys/devices/platform/firmware\:zynqmp-firmware/last_reset_reason + +Users: Xilinx
drivers/firmware/xilinx/zynqmp.c +36 -0
@@ -1902,6 +1902,41 @@ static ssize_t feature_config_value_store(struct device *device,static DEVICE_ATTR_RW (feature_config_value); +static ssize_t last_reset_reason_show (struct device *device, +struct device_attribute *attr, +char *buf) +{ +u32 ret_payload[PAYLOAD_ARG_CNT ]; +int ret; + + ret =zynqmp_pm_get_last_reset_reason (ret_payload); +if (ret) +return ret; + +switch (ret_payload[1 ]) { +case PM_RESET_REASON_EXT_POR : +return sprintf (buf,"ext_por\n" ); +case PM_RESET_REASON_SW_POR : +return sprintf (buf,"sw_por\n" ); +case PM_RESET_REASON_SLR_POR : +return sprintf (buf,"slr_por\n" ); +case PM_RESET_REASON_ERR_POR : +return sprintf (buf,"err_por\n" ); +case PM_RESET_REASON_DAP_SRST : +return sprintf (buf,"dap_srst\n" ); +case PM_RESET_REASON_ERR_SRST : +return sprintf (buf,"err_srst\n" ); +case PM_RESET_REASON_SW_SRST : +return sprintf (buf,"sw_srst\n" ); +case PM_RESET_REASON_SLR_SRST : +return sprintf (buf,"slr_srst\n" ); +default : +return sprintf (buf,"unknown reset\n" ); + } +} + +static DEVICE_ATTR_RO (last_reset_reason); +static struct attribute *zynqmp_firmware_attrs[] = { &dev_attr_ggs0.attr, &dev_attr_ggs1.attr,
@@ -1915,6 +1950,7 @@ static struct attribute *zynqmp_firmware_attrs[] = { &dev_attr_health_status.attr, &dev_attr_feature_config_id.attr, &dev_attr_feature_config_value.attr, + &dev_attr_last_reset_reason.attr, NULL, };
include/linux/firmware/xlnx-zynqmp.h +11 -0
@@ -497,6 +497,17 @@ enum pm_gem_config_type { GEM_CONFIG_FIXED = 2, }; +enum pm_reset_reason { +PM_RESET_REASON_EXT_POR =0 , +PM_RESET_REASON_SW_POR =1 , +PM_RESET_REASON_SLR_POR =2 , +PM_RESET_REASON_ERR_POR =3 , +PM_RESET_REASON_DAP_SRST =7 , +PM_RESET_REASON_ERR_SRST =8 , +PM_RESET_REASON_SW_SRST =9 , +PM_RESET_REASON_SLR_SRST =10 , +}; +/** * struct zynqmp_pm_query_data - PM query data * @qid: query ID
Signature · 1 line
2.25.1
Re: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason
Quoted 10 lines · Ronak Jain
Add sysfs interface to get the last reset reason of the system from a user space.
When the system reset happens whether intentionally or due to some errors, the firmware used to store the last reset reason and the same be queried by using the IOCTL API or the sysfs entry to know the reason behind the system reset and accordingly, the error can be diagnostic.
Signed-off-by Ronak Jain <[email protected]>
I'm fairly sure we already have other interfaces to access the reset reason, please see if you can either reuse one of the existing ones, or come up with a generic one that can be used by others as well.
Arnd
RE: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason
Hi Arnd,
Quoted 26 lines
-----Original Message-----
From: Arnd Bergmann <[email protected]>
Sent: Tuesday, November 21, 2023 6:01 PM
To: Jain, Ronak <[email protected]>; Simek, Michal <[email protected]>; Greg Kroah-Hartman <[email protected]>; Linus Walleij <[email protected]>; Potthuri, Sai Krishna <[email protected]>; Shah, Tanmay <[email protected]>; Levinsky, Ben <[email protected]>; Manne, Nava kishore <[email protected]>; Rob Herring <[email protected]>; [email protected]; Marek Vasut <[email protected]>; Roman Gushchin <[email protected]>; Mathieu Poirier <[email protected]>; Datta, Shubhrajyoti <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reasonQuoted 9 lines · Ronak Jain
Add sysfs interface to get the last reset reason of the system from a user space.
When the system reset happens whether intentionally or due to some errors, the firmware used to store the last reset reason and the same be queried by using the IOCTL API or the sysfs entry to know the reason behind the system reset and accordingly, the error can be diagnostic.
Quoted 6 lines
Quoted 1 line
Signed-off-by Ronak Jain <[email protected]>I'm fairly sure we already have other interfaces to access the reset reason, please see if you can either reuse one of the existing ones, or come up with a generic one that can be used by others as well.
Could you please provide more information regarding the interface you're talking about?
Thanks,
Ronak
Quoted 2 lines
Arnd