mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ronak Jain <ronak.jain@amd.com>
To: <michal.simek@amd.com>, <gregkh@linuxfoundation.org>,
	<linus.walleij@linaro.org>, <sai.krishna.potthuri@amd.com>,
	<tanmay.shah@amd.com>, <ben.levinsky@amd.com>,
	<nava.kishore.manne@amd.com>, <robh@kernel.org>,
	<dhaval.r.shah@amd.com>, <marex@denx.de>,
	<roman.gushchin@linux.dev>, <mathieu.poirier@linaro.org>,
	<shubhrajyoti.datta@amd.com>, <arnd@arndb.de>
Cc: <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason
Date: Tue, 21 Nov 2023 03:20:56 -0800	[thread overview]
Message-ID: <20231121112056.1762641-3-ronak.jain@amd.com> (raw)
In-Reply-To: <20231121112056.1762641-1-ronak.jain@amd.com>

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


  parent reply	other threads:[~2023-11-21 11:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21 11:20 [PATCH 0/2] Add support for " 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 [this message]
2023-11-21 12:30   ` [PATCH 2/2] xilinx: firmware: Add sysfs to get last reset reason Arnd Bergmann
2023-11-29 11:53     ` Jain, Ronak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231121112056.1762641-3-ronak.jain@amd.com \
    --to=ronak.jain@amd.com \
    --cc=arnd@arndb.de \
    --cc=ben.levinsky@amd.com \
    --cc=dhaval.r.shah@amd.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=mathieu.poirier@linaro.org \
    --cc=michal.simek@amd.com \
    --cc=nava.kishore.manne@amd.com \
    --cc=robh@kernel.org \
    --cc=roman.gushchin@linux.dev \
    --cc=sai.krishna.potthuri@amd.com \
    --cc=shubhrajyoti.datta@amd.com \
    --cc=tanmay.shah@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®