All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amit Sunil Dhamne <amit.sunil.dhamne@xilinx.com>
To: ard.biesheuvel@linaro.org, mingo@kernel.org,
	gregkh@linuxfoundation.org, matt@codeblueprint.co.uk,
	sudeep.holla@arm.com, hkallweit1@gmail.com,
	keescook@chromium.org, dmitry.torokhov@gmail.com,
	michal.simek@xilinx.com, rajanv@xilinx.com,
	tejas.patel@xilinx.com, jollys@xilinx.com
Cc: linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, rajan.vaja@xilinx.com,
	jolly.shah@xilinx.com,
	Amit Sunil Dhamne <amit.sunil.dhamne@xilinx.com>
Subject: [PATCH 3/3] firmware: xilinx: Add sysfs to get last reset reason
Date: Wed,  9 Sep 2020 17:20:04 -0700	[thread overview]
Message-ID: <1599697204-32103-4-git-send-email-amit.sunil.dhamne@xilinx.com> (raw)
In-Reply-To: <1599697204-32103-1-git-send-email-amit.sunil.dhamne@xilinx.com>

From: Tejas Patel <tejas.patel@xilinx.com>

Add sysfs to get last reset reason.

Signed-off-by: Tejas Patel <tejas.patel@xilinx.com>
Signed-off-by: Amit Sunil Dhamne <amit.sunil.dhamne@xilinx.com>
---
 .../ABI/stable/sysfs-driver-firmware-zynqmp        | 13 ++++++++
 drivers/firmware/xilinx/zynqmp.c                   | 37 ++++++++++++++++++++++
 include/linux/firmware/xlnx-zynqmp.h               | 11 +++++++
 3 files changed, 61 insertions(+)

diff --git a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
index 00fa04c..96a5760 100644
--- a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
+++ b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
@@ -101,3 +101,16 @@ Description:
                # echo 0 > /sys/devices/platform/firmware\:zynqmp-firmware/health_status

 Users:         Xilinx
+
+What:          /sys/devices/platform/firmware\:zynqmp-firmware/last_reset_reason
+Date:          June 2020
+KernelVersion: 5.9.0
+Contact:       "Tejas Patel" <tejasp@xilinx.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 c5db34f..f590856 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -1266,6 +1266,42 @@ static DEVICE_ATTR_RW(pggs1);
 static DEVICE_ATTR_RW(pggs2);
 static DEVICE_ATTR_RW(pggs3);

+static ssize_t last_reset_reason_show(struct device *device,
+                                     struct device_attribute *attr, char *buf)
+{
+       int ret;
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+
+       ret = zynqmp_pm_get_last_reset_reason(ret_payload);
+       if (-EINVAL == ret)
+               return sprintf(buf, "Feature not supported\n");
+       else 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, "sl_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,
@@ -1277,6 +1313,7 @@ static struct attribute *zynqmp_firmware_attrs[] = {
        &dev_attr_pggs3.attr,
        &dev_attr_shutdown_scope.attr,
        &dev_attr_health_status.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 90c8664..f7cb0a9 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -302,6 +302,17 @@ enum zynqmp_pm_shutdown_subtype {
        ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM,
 };

+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.7.4

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

WARNING: multiple messages have this Message-ID (diff)
From: Amit Sunil Dhamne <amit.sunil.dhamne@xilinx.com>
To: ard.biesheuvel@linaro.org, mingo@kernel.org,
	gregkh@linuxfoundation.org, matt@codeblueprint.co.uk,
	sudeep.holla@arm.com, hkallweit1@gmail.com,
	keescook@chromium.org, dmitry.torokhov@gmail.com,
	michal.simek@xilinx.com, rajanv@xilinx.com,
	tejas.patel@xilinx.com, jollys@xilinx.com
Cc: jolly.shah@xilinx.com, rajan.vaja@xilinx.com,
	Amit Sunil Dhamne <amit.sunil.dhamne@xilinx.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/3] firmware: xilinx: Add sysfs to get last reset reason
Date: Wed,  9 Sep 2020 17:20:04 -0700	[thread overview]
Message-ID: <1599697204-32103-4-git-send-email-amit.sunil.dhamne@xilinx.com> (raw)
In-Reply-To: <1599697204-32103-1-git-send-email-amit.sunil.dhamne@xilinx.com>

From: Tejas Patel <tejas.patel@xilinx.com>

Add sysfs to get last reset reason.

Signed-off-by: Tejas Patel <tejas.patel@xilinx.com>
Signed-off-by: Amit Sunil Dhamne <amit.sunil.dhamne@xilinx.com>
---
 .../ABI/stable/sysfs-driver-firmware-zynqmp        | 13 ++++++++
 drivers/firmware/xilinx/zynqmp.c                   | 37 ++++++++++++++++++++++
 include/linux/firmware/xlnx-zynqmp.h               | 11 +++++++
 3 files changed, 61 insertions(+)

diff --git a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
index 00fa04c..96a5760 100644
--- a/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
+++ b/Documentation/ABI/stable/sysfs-driver-firmware-zynqmp
@@ -101,3 +101,16 @@ Description:
                # echo 0 > /sys/devices/platform/firmware\:zynqmp-firmware/health_status

 Users:         Xilinx
+
+What:          /sys/devices/platform/firmware\:zynqmp-firmware/last_reset_reason
+Date:          June 2020
+KernelVersion: 5.9.0
+Contact:       "Tejas Patel" <tejasp@xilinx.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 c5db34f..f590856 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -1266,6 +1266,42 @@ static DEVICE_ATTR_RW(pggs1);
 static DEVICE_ATTR_RW(pggs2);
 static DEVICE_ATTR_RW(pggs3);

+static ssize_t last_reset_reason_show(struct device *device,
+                                     struct device_attribute *attr, char *buf)
+{
+       int ret;
+       u32 ret_payload[PAYLOAD_ARG_CNT];
+
+       ret = zynqmp_pm_get_last_reset_reason(ret_payload);
+       if (-EINVAL == ret)
+               return sprintf(buf, "Feature not supported\n");
+       else 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, "sl_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,
@@ -1277,6 +1313,7 @@ static struct attribute *zynqmp_firmware_attrs[] = {
        &dev_attr_pggs3.attr,
        &dev_attr_shutdown_scope.attr,
        &dev_attr_health_status.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 90c8664..f7cb0a9 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -302,6 +302,17 @@ enum zynqmp_pm_shutdown_subtype {
        ZYNQMP_PM_SHUTDOWN_SUBTYPE_SYSTEM,
 };

+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.7.4

This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2020-09-10  2:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10  0:20 [PATCH 0/3] firmware: xilinx: Add support to get last reset reason Amit Sunil Dhamne
2020-09-10  0:20 ` Amit Sunil Dhamne
2020-09-10  0:20 ` [PATCH 1/3] firmware: xilinx: Add validation check for IOCTL Amit Sunil Dhamne
2020-09-10  0:20   ` Amit Sunil Dhamne
2020-09-16 11:33   ` Greg KH
2020-09-16 11:33     ` Greg KH
2020-09-16 16:53     ` Amit Sunil Dhamne
2020-09-16 16:53       ` Amit Sunil Dhamne
2020-09-17  6:45   ` Punit Agrawal
2020-09-17  6:45     ` Punit Agrawal
2020-09-10  0:20 ` [PATCH 2/3] firmware: xilinx: Add support for GET_LAST_RESET_REASON IOCTL Amit Sunil Dhamne
2020-09-10  0:20   ` Amit Sunil Dhamne
2020-09-10  0:20 ` Amit Sunil Dhamne [this message]
2020-09-10  0:20   ` [PATCH 3/3] firmware: xilinx: Add sysfs to get last reset reason Amit Sunil Dhamne

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=1599697204-32103-4-git-send-email-amit.sunil.dhamne@xilinx.com \
    --to=amit.sunil.dhamne@xilinx.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hkallweit1@gmail.com \
    --cc=jolly.shah@xilinx.com \
    --cc=jollys@xilinx.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=michal.simek@xilinx.com \
    --cc=mingo@kernel.org \
    --cc=rajan.vaja@xilinx.com \
    --cc=rajanv@xilinx.com \
    --cc=sudeep.holla@arm.com \
    --cc=tejas.patel@xilinx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.