[PATCH 2/3] firmware: xilinx: Add support for GET_LAST_RESET_REASON IOCTL

Amit Sunil Dhamne amit.sunil.dhamne at xilinx.com
Wed Sep 9 20:20:03 EDT 2020


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

Add support to get last reason using IOCTL API. Also validate IOCTL
ID for Versal or ZynqMP platforms before calling
zynqmp_pm_invoke_fn().

Signed-off-by: Tejas Patel <tejas.patel at xilinx.com>
Signed-off-by: Amit Sunil Dhamne <amit.sunil.dhamne at xilinx.com>
---
 drivers/firmware/xilinx/zynqmp.c     | 20 ++++++++++++++++++++
 include/linux/firmware/xlnx-zynqmp.h |  7 +++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/firmware/xilinx/zynqmp.c b/drivers/firmware/xilinx/zynqmp.c
index 8fe0912..c5db34f 100644
--- a/drivers/firmware/xilinx/zynqmp.c
+++ b/drivers/firmware/xilinx/zynqmp.c
@@ -533,6 +533,7 @@ static inline int versal_is_valid_ioctl(u32 ioctl_id)
        case IOCTL_WRITE_PGGS:
        case IOCTL_READ_PGGS:
        case IOCTL_SET_BOOT_HEALTH_STATUS:
+       case IOCTL_GET_LAST_RESET_REASON:
                return 1;
        default:
                return 0;
@@ -772,6 +773,25 @@ int zynqmp_pm_set_boot_health_status(u32 value)
 }

 /**
+ * zynqmp_pm_get_last_reset_reason() - PM API for getting last reset reason
+ *
+ * @reset_reason:      last reset reason
+ *
+ * This function returns last reset reason
+ *
+ * Return: Returns status, either success or error+reason
+ */
+int zynqmp_pm_get_last_reset_reason(u32 *reset_reason)
+{
+       if (!reset_reason)
+               return -EINVAL;
+
+       return zynqmp_pm_ioctl(0, IOCTL_GET_LAST_RESET_REASON, 0, 0,
+                              reset_reason);
+}
+EXPORT_SYMBOL_GPL(zynqmp_pm_get_last_reset_reason);
+
+/**
  * zynqmp_pm_reset_assert - Request setting of reset (1 - assert, 0 - release)
  * @reset:             Reset to be configured
  * @assert_flag:       Flag stating should reset be asserted (1) or
diff --git a/include/linux/firmware/xlnx-zynqmp.h b/include/linux/firmware/xlnx-zynqmp.h
index 5968df8..90c8664 100644
--- a/include/linux/firmware/xlnx-zynqmp.h
+++ b/include/linux/firmware/xlnx-zynqmp.h
@@ -116,6 +116,8 @@ enum pm_ioctl_id {
        IOCTL_READ_PGGS = 15,
        /* Set healthy bit value */
        IOCTL_SET_BOOT_HEALTH_STATUS = 17,
+       /* IOCTL to get last reset reason */
+       IOCTL_GET_LAST_RESET_REASON = 23,
 };

 enum pm_query_id {
@@ -357,6 +359,7 @@ int zynqmp_pm_write_pggs(u32 index, u32 value);
 int zynqmp_pm_read_pggs(u32 index, u32 *value);
 int zynqmp_pm_system_shutdown(const u32 type, const u32 subtype);
 int zynqmp_pm_set_boot_health_status(u32 value);
+int zynqmp_pm_get_last_reset_reason(u32 *reset_reason);
 #else
 static inline struct zynqmp_eemi_ops *zynqmp_pm_get_eemi_ops(void)
 {
@@ -507,6 +510,10 @@ static inline int zynqmp_pm_set_boot_health_status(u32 value)
 {
        return -ENODEV;
 }
+static inline int zynqmp_pm_get_last_reset_reason(u32 *reset_reason)
+{
+       return -ENODEV;
+}
 #endif

 #endif /* __FIRMWARE_ZYNQMP_H__ */
--
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.



More information about the linux-arm-kernel mailing list