mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] Add support for last reset reason
@ 2023-11-21 11:20 Ronak Jain
  2023-11-21 11:20 ` [PATCH 1/2] firmware: xilinx: Add support for GET_LAST_RESET_REASON IOCTL Ronak Jain
  2023-11-21 11:20 ` [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason Ronak Jain
  0 siblings, 2 replies; 5+ messages in thread
From: Ronak Jain @ 2023-11-21 11:20 UTC (permalink / raw)
  To: michal.simek, gregkh, linus.walleij, sai.krishna.potthuri,
	tanmay.shah, ben.levinsky, nava.kishore.manne, robh,
	dhaval.r.shah, marex, roman.gushchin, mathieu.poirier,
	shubhrajyoti.datta, arnd
  Cc: linux-kernel

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(+)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] firmware: xilinx: Add support for GET_LAST_RESET_REASON IOCTL
  2023-11-21 11:20 [PATCH 0/2] Add support for last reset reason Ronak Jain
@ 2023-11-21 11:20 ` Ronak Jain
  2023-11-21 11:20 ` [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason Ronak Jain
  1 sibling, 0 replies; 5+ messages in thread
From: Ronak Jain @ 2023-11-21 11:20 UTC (permalink / raw)
  To: michal.simek, gregkh, linus.walleij, sai.krishna.potthuri,
	tanmay.shah, ben.levinsky, nava.kishore.manne, robh,
	dhaval.r.shah, marex, roman.gushchin, mathieu.poirier,
	shubhrajyoti.datta, arnd
  Cc: linux-kernel

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

Signed-off-by: Ronak Jain <ronak.jain@amd.com>
---
 drivers/firmware/xilinx/zynqmp.c     | 7 +++++++
 include/linux/firmware/xlnx-zynqmp.h | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index b0d22d4455d9..5815d1e94407 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -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
diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index d1ea3898564c..2d8c5e88391b 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -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__ */
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason
  2023-11-21 11:20 [PATCH 0/2] Add support for last reset reason Ronak Jain
  2023-11-21 11:20 ` [PATCH 1/2] firmware: xilinx: Add support for GET_LAST_RESET_REASON IOCTL Ronak Jain
@ 2023-11-21 11:20 ` Ronak Jain
  2023-11-21 12:30   ` Arnd Bergmann
  1 sibling, 1 reply; 5+ messages in thread
From: Ronak Jain @ 2023-11-21 11:20 UTC (permalink / raw)
  To: michal.simek, gregkh, linus.walleij, sai.krishna.potthuri,
	tanmay.shah, ben.levinsky, nava.kishore.manne, robh,
	dhaval.r.shah, marex, roman.gushchin, mathieu.poirier,
	shubhrajyoti.datta, arnd
  Cc: linux-kernel

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 <ronak.jain@amd.com>
---
 .../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(+)

diff --git a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
index c3fec3c835af..77ae69870767 100644
--- a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
+++ b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
@@ -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" <ronak.jain@amd.com>
+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
diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index 5815d1e94407..8f49861ebbb3 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -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,
 };
 
diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index 2d8c5e88391b..6d4015b6d964 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -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
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason
  2023-11-21 11:20 ` [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason Ronak Jain
@ 2023-11-21 12:30   ` Arnd Bergmann
  2023-11-29 11:53     ` Jain, Ronak
  0 siblings, 1 reply; 5+ messages in thread
From: Arnd Bergmann @ 2023-11-21 12:30 UTC (permalink / raw)
  To: Ronak Jain, Michal Simek, Greg Kroah-Hartman, Linus Walleij,
	sai.krishna.potthuri, Tanmay Shah, Ben Levinsky,
	nava.kishore.manne, Rob Herring, dhaval.r.shah, Marek Vasut,
	Roman Gushchin, Mathieu Poirier, shubhrajyoti.datta
  Cc: linux-kernel

On Tue, Nov 21, 2023, at 12:20, Ronak Jain wrote:
> 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 <ronak.jain@amd.com>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason
  2023-11-21 12:30   ` Arnd Bergmann
@ 2023-11-29 11:53     ` Jain, Ronak
  0 siblings, 0 replies; 5+ messages in thread
From: Jain, Ronak @ 2023-11-29 11:53 UTC (permalink / raw)
  To: Arnd Bergmann, Simek, Michal, Greg Kroah-Hartman, Linus Walleij,
	Potthuri, Sai Krishna, Shah, Tanmay, Levinsky, Ben, Manne,
	Nava kishore, Rob Herring, dhaval.r.shah, Marek Vasut,
	Roman Gushchin, Mathieu Poirier, Datta, Shubhrajyoti
  Cc: linux-kernel

Hi Arnd,

> -----Original Message-----
> From: Arnd Bergmann <arnd@arndb.de>
> Sent: Tuesday, November 21, 2023 6:01 PM
> To: Jain, Ronak <ronak.jain@amd.com>; Simek, Michal
> <michal.simek@amd.com>; Greg Kroah-Hartman
> <gregkh@linuxfoundation.org>; Linus Walleij <linus.walleij@linaro.org>;
> Potthuri, Sai Krishna <sai.krishna.potthuri@amd.com>; Shah, Tanmay
> <tanmay.shah@amd.com>; Levinsky, Ben <ben.levinsky@amd.com>; Manne,
> Nava kishore <nava.kishore.manne@amd.com>; Rob Herring
> <robh@kernel.org>; dhaval.r.shah@amd.com; Marek Vasut
> <marex@denx.de>; Roman Gushchin <roman.gushchin@linux.dev>; Mathieu
> Poirier <mathieu.poirier@linaro.org>; Datta, Shubhrajyoti
> <shubhrajyoti.datta@amd.com>
> Cc: linux-kernel@vger.kernel.org
> Subject: Re: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason
> 
> On Tue, Nov 21, 2023, at 12:20, Ronak Jain wrote:
> > 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 <ronak.jain@amd.com>
> 
> 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
> 
>       Arnd

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-29 11:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-21 11:20 [PATCH 0/2] Add support for last reset reason Ronak Jain
2023-11-21 11:20 ` [PATCH 1/2] firmware: xilinx: Add support for GET_LAST_RESET_REASON IOCTL Ronak Jain
2023-11-21 11:20 ` [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason Ronak Jain
2023-11-21 12:30   ` Arnd Bergmann
2023-11-29 11:53     ` Jain, Ronak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®