Skip to contentSkip to conversation

system reset rework to list, priority

RFC PATCH New Nikita Shubin 3 participants 8 messages Sep 29, 2021 – Oct 1, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover system reset rework to list, priority

From: Nikita Shubin <[email protected]>

Hi Anup.

I decided to go as separate proposal for system reset, as i don't think da9063 is really connected to this one.

Let's rework our current sbi_system reset to support multiply reset handlers.

However there are some things to discuss. If we want priority handling like in Linux, we need separate lists for each reset type and sort them on insertions.

If we go the way like in the second patch no separate lists are needed but we will lack the ability to call them in chain.

So what are your thoughts ?

Nikita Shubin (2):
lib: sbi: convert reset to list
lib: sbi: add priority for reset handler

 include/sbi/sbi_system.h              | 13 +++++--
 lib/sbi/sbi_init.c                    |  5 ++-
 lib/sbi/sbi_system.c                  | 50 +++++++++++++++++++--------
 lib/utils/reset/fdt_reset_gpio.c      |  2 +-
 lib/utils/reset/fdt_reset_sunxi_wdt.c |  2 +-
 lib/utils/reset/fdt_reset_thead.c     |  2 +-
 lib/utils/sys/htif.c                  |  2 +-
 lib/utils/sys/sifive_test.c           |  2 +-
 platform/kendryte/k210/platform.c     |  2 +-
 platform/nuclei/ux600/platform.c      |  2 +-
 10 files changed, 58 insertions(+), 24 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

RFC PATCH 1/2 lib: sbi: convert reset to list

From: Nikita Shubin <[email protected]>

To support different handlers for different types of resets, we are adding a sbi_list of restart handlers.

Instead of sbi_system_reset_set_device we use sbi_system_reset_add_device to reflect the actual meaning.

---
 include/sbi/sbi_system.h              | 13 +++++++--
 lib/sbi/sbi_init.c                    |  5 +++-
 lib/sbi/sbi_system.c                  | 40 +++++++++++++++++----------
 lib/utils/reset/fdt_reset_gpio.c      |  2 +-
 lib/utils/reset/fdt_reset_sunxi_wdt.c |  2 +-
 lib/utils/reset/fdt_reset_thead.c     |  2 +-
 lib/utils/sys/htif.c                  |  2 +-
 lib/utils/sys/sifive_test.c           |  2 +-
 platform/kendryte/k210/platform.c     |  2 +-
 platform/nuclei/ux600/platform.c      |  2 +-
 10 files changed, 47 insertions(+), 25 deletions(-)
include/sbi/sbi_system.h +11 -2
index a9fa546..a0bed1e 100644
@@ -11,6 +11,7 @@
 #define __SBI_SYSTEM_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_list.h>
 
 /** System reset hardware device */
 struct sbi_system_reset_device {
@@ -22,11 +23,19 @@ struct sbi_system_reset_device {
 
 	/** Reset the system */
 	void (*system_reset)(u32 reset_type, u32 reset_reason);
+
+	/** List */
+	struct sbi_dlist node;
 };
 
-const struct sbi_system_reset_device *sbi_system_reset_get_device(void);
+inline struct sbi_system_reset_device *to_system_reset_device(struct sbi_dlist *node)
+{
+	return container_of(node, struct sbi_system_reset_device, node);
+}
+
+const struct sbi_system_reset_device *sbi_system_reset_get_device(u32 reset_type, u32 reset_reason);
 
-void sbi_system_reset_set_device(const struct sbi_system_reset_device *dev);
+void sbi_system_reset_add_device(struct sbi_system_reset_device *dev);
 
 bool sbi_system_reset_supported(u32 reset_type, u32 reset_reason);
 
lib/sbi/sbi_init.c +4 -1
index f0eb365..56a2312 100644
@@ -84,9 +84,12 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
 	hdev = sbi_hsm_get_device();
 	sbi_printf("Platform HSM Device       : %s\n",
 		   (hdev) ? hdev->name : "---");
-	srdev = sbi_system_reset_get_device();
+	srdev = sbi_system_reset_get_device(SBI_SRST_RESET_TYPE_COLD_REBOOT, 0);
 	sbi_printf("Platform SysReset Device  : %s\n",
 		   (srdev) ? srdev->name : "---");
+	srdev = sbi_system_reset_get_device(SBI_SRST_RESET_TYPE_SHUTDOWN, 0);
+	sbi_printf("Platform Shutdown Device  : %s\n",
+		   (srdev) ? srdev->name : "---");
 
 	/* Firmware details */
 	sbi_printf("Firmware Base             : 0x%lx\n", scratch->fw_start);
lib/sbi/sbi_system.c +25 -15
index 479060b..92bc0ac 100644
@@ -18,28 +18,34 @@
 #include <sbi/sbi_ipi.h>
 #include <sbi/sbi_init.h>
 
-static const struct sbi_system_reset_device *reset_dev = NULL;
+static SBI_LIST_HEAD(reset_devices_list);
 
-const struct sbi_system_reset_device *sbi_system_reset_get_device(void)
+const struct sbi_system_reset_device *sbi_system_reset_get_device(u32 reset_type, u32 reset_reason)
 {
-	return reset_dev;
+	struct sbi_system_reset_device *dev = 0;
+	struct sbi_dlist *pos;
+
+	sbi_list_for_each(pos, &(reset_devices_list)) {
+		dev = to_system_reset_device(pos);
+		if (dev->system_reset_check &&
+			dev->system_reset_check(reset_type, reset_reason))
+			break;
+	}
+
+	return dev;
 }
 
-void sbi_system_reset_set_device(const struct sbi_system_reset_device *dev)
+void sbi_system_reset_add_device(struct sbi_system_reset_device *dev)
 {
-	if (!dev || reset_dev)
+	if (!dev || !dev->system_reset_check)
 		return;
 
-	reset_dev = dev;
+	sbi_list_add(&(dev->node), &(reset_devices_list));
 }
 
 bool sbi_system_reset_supported(u32 reset_type, u32 reset_reason)
 {
-	if (reset_dev && reset_dev->system_reset_check &&
-	    reset_dev->system_reset_check(reset_type, reset_reason))
-		return TRUE;
-
-	return FALSE;
+	return !!sbi_system_reset_get_device(reset_type, reset_reason);
 }
 
 void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
@@ -48,6 +54,7 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
 	u32 cur_hartid = current_hartid();
 	struct sbi_domain *dom = sbi_domain_thishart_ptr();
 	struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+	struct sbi_dlist *pos;
 
 	/* Send HALT IPI to every hart other than the current hart */
 	while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &hmask)) {
@@ -61,10 +68,13 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
 	/* Stop current HART */
 	sbi_hsm_hart_stop(scratch, FALSE);
 
-	/* Platform specific reset if domain allowed system reset */
-	if (dom->system_reset_allowed &&
-	    reset_dev && reset_dev->system_reset)
-		reset_dev->system_reset(reset_type, reset_reason);
+	/* Check each reset device registered for supported reset type */
+	sbi_list_for_each(pos, &(reset_devices_list)) {
+		struct sbi_system_reset_device *dev =
+			to_system_reset_device(pos);
+		if (dev->system_reset_check(reset_type, reset_reason))
+			dev->system_reset(reset_type, reset_reason);
+	}
 
 	/* If platform specific reset did not work then do sbi_exit() */
 	sbi_exit(scratch);
lib/utils/reset/fdt_reset_gpio.c +1 -1
index 77e4d0e..4da1450 100644
@@ -115,7 +115,7 @@ static int gpio_reset_init(void *fdt, int nodeoff,
 	if (len > 0)
 		reset->inactive_delay = fdt32_to_cpu(*val);
 
-	sbi_system_reset_set_device(&gpio_reset);
+	sbi_system_reset_add_device(&gpio_reset);
 
 	return 0;
 }
lib/utils/reset/fdt_reset_sunxi_wdt.c +1 -1
index e4f16e3..6d1b5b7 100644
@@ -61,7 +61,7 @@ static int sunxi_wdt_reset_init(void *fdt, int nodeoff,
 
 	sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr;
 
-	sbi_system_reset_set_device(&sunxi_wdt_reset);
+	sbi_system_reset_add_device(&sunxi_wdt_reset);
 
 	return 0;
 }
lib/utils/reset/fdt_reset_thead.c +1 -1
index 9f2fe03..750b7aa 100644
@@ -126,7 +126,7 @@ static int thead_reset_init(void *fdt, int nodeoff,
 		}
 	}
 
-	sbi_system_reset_set_device(&thead_reset);
+	sbi_system_reset_add_device(&thead_reset);
 
 	return 0;
 }
lib/utils/sys/htif.c +1 -1
index 330a9a6..7c69c7f 100644
@@ -176,7 +176,7 @@ static struct sbi_system_reset_device htif_reset = {
 
 int htif_system_reset_init(void)
 {
-	sbi_system_reset_set_device(&htif_reset);
+	sbi_system_reset_add_device(&htif_reset);
 
 	return 0;
 }
lib/utils/sys/sifive_test.c +1 -1
index 4533954..a9ebb5c 100644
@@ -59,7 +59,7 @@ static struct sbi_system_reset_device sifive_test_reset = {
 int sifive_test_init(unsigned long base)
 {
 	sifive_test_base = (void *)base;
-	sbi_system_reset_set_device(&sifive_test_reset);
+	sbi_system_reset_add_device(&sifive_test_reset);
 
 	return 0;
 }
platform/kendryte/k210/platform.c +1 -1
index 35cec5f..e7caec3 100644
@@ -108,7 +108,7 @@ static struct sbi_system_reset_device k210_reset = {
 static int k210_early_init(bool cold_boot)
 {
 	if (cold_boot)
-		sbi_system_reset_set_device(&k210_reset);
+		sbi_system_reset_add_device(&k210_reset);
 
 	return 0;
 }
platform/nuclei/ux600/platform.c +1 -1
index 6bef4c4..6f87cf8 100644
@@ -148,7 +148,7 @@ static int ux600_early_init(bool cold_boot)
 	u32 regval;
 
 	if (cold_boot)
-		sbi_system_reset_set_device(&ux600_reset);
+		sbi_system_reset_add_device(&ux600_reset);
 
 	/* Measure CPU Frequency using Timer */
 	ux600_clk_freq = ux600_get_clk_freq();
Signature · 1 line
2.31.1
#2 lore raw

RFC PATCH 1/2 lib: sbi: convert reset to list

Quoted 36 lines · Nikita Shubin

From: Nikita Shubin <[email protected]>

To support different handlers for different types of resets, we are adding a sbi_list of restart handlers.

Instead of sbi_system_reset_set_device we use sbi_system_reset_add_device to reflect the actual meaning.

---
 include/sbi/sbi_system.h              | 13 +++++++--
 lib/sbi/sbi_init.c                    |  5 +++-
 lib/sbi/sbi_system.c                  | 40 +++++++++++++++++----------
 lib/utils/reset/fdt_reset_gpio.c      |  2 +-
 lib/utils/reset/fdt_reset_sunxi_wdt.c |  2 +-
 lib/utils/reset/fdt_reset_thead.c     |  2 +-
 lib/utils/sys/htif.c                  |  2 +-
 lib/utils/sys/sifive_test.c           |  2 +-
 platform/kendryte/k210/platform.c     |  2 +-
 platform/nuclei/ux600/platform.c      |  2 +-
 10 files changed, 47 insertions(+), 25 deletions(-)
include/sbi/sbi_system.h +1 -0
index a9fa546..a0bed1e 100644
@@ -11,6 +11,7 @@
 #define __SBI_SYSTEM_H__
 
 #include <sbi/sbi_types.h>
+#include <sbi/sbi_list.h>
 
 /** System reset hardware device */
 struct sbi_system_reset_device {

include/sbi/sbi_system.h struct sbi_system_reset_device { · line 31

Quoted 10 lines
include/sbi/sbi_system.h +4 -1
@@ -22,11 +23,19 @@ struct sbi_system_reset_device {
 
        /** Reset the system */
        void (*system_reset)(u32 reset_type, u32 reset_reason);
+
+       /** List */
+       struct sbi_dlist node;
 };
 
-const struct sbi_system_reset_device *sbi_system_reset_get_device(void);
+inline struct sbi_system_reset_device *to_system_reset_device(struct sbi_dlist *node)

Make this "static inline".

Quoted 16 lines
include/sbi/sbi_system.h +6 -1
+{
+       return container_of(node, struct sbi_system_reset_device, node);
+}
+
+const struct sbi_system_reset_device *sbi_system_reset_get_device(u32 reset_type, u32 reset_reason);
 
-void sbi_system_reset_set_device(const struct sbi_system_reset_device *dev);
+void sbi_system_reset_add_device(struct sbi_system_reset_device *dev);
 
 bool sbi_system_reset_supported(u32 reset_type, u32 reset_reason);
 
lib/sbi/sbi_init.c +0 -0
index f0eb365..56a2312 100644

lib/sbi/sbi_init.c static void sbi_boot_print_general(struct sbi_scratch *scratch) · line 88

Quoted 6 lines
lib/sbi/sbi_init.c +1 -1
@@ -84,9 +84,12 @@ static void sbi_boot_print_general(struct sbi_scratch *scratch)
        hdev = sbi_hsm_get_device();
        sbi_printf("Platform HSM Device       : %s\n",
                   (hdev) ? hdev->name : "---");
-       srdev = sbi_system_reset_get_device();
+       srdev = sbi_system_reset_get_device(SBI_SRST_RESET_TYPE_COLD_REBOOT, 0);
        sbi_printf("Platform SysReset Device  : %s\n",

s/SysReset/Reboot/

Quoted 66 lines
lib/sbi/sbi_init.c +3 -0
                   (srdev) ? srdev->name : "---");
+       srdev = sbi_system_reset_get_device(SBI_SRST_RESET_TYPE_SHUTDOWN, 0);
+       sbi_printf("Platform Shutdown Device  : %s\n",
+                  (srdev) ? srdev->name : "---");
 
        /* Firmware details */
        sbi_printf("Firmware Base             : 0x%lx\n", scratch->fw_start);
lib/sbi/sbi_system.c +18 -11
index 479060b..92bc0ac 100644
@@ -18,28 +18,34 @@
 #include <sbi/sbi_ipi.h>
 #include <sbi/sbi_init.h>
 
-static const struct sbi_system_reset_device *reset_dev = NULL;
+static SBI_LIST_HEAD(reset_devices_list);
 
-const struct sbi_system_reset_device *sbi_system_reset_get_device(void)
+const struct sbi_system_reset_device *sbi_system_reset_get_device(u32 reset_type, u32 reset_reason)
 {
-       return reset_dev;
+       struct sbi_system_reset_device *dev = 0;
+       struct sbi_dlist *pos;
+
+       sbi_list_for_each(pos, &(reset_devices_list)) {
+               dev = to_system_reset_device(pos);
+               if (dev->system_reset_check &&
+                       dev->system_reset_check(reset_type, reset_reason))
+                       break;
+       }
+
+       return dev;
 }
 
-void sbi_system_reset_set_device(const struct sbi_system_reset_device *dev)
+void sbi_system_reset_add_device(struct sbi_system_reset_device *dev)
 {
-       if (!dev || reset_dev)
+       if (!dev || !dev->system_reset_check)
                return;
 
-       reset_dev = dev;
+       sbi_list_add(&(dev->node), &(reset_devices_list));
 }
 
 bool sbi_system_reset_supported(u32 reset_type, u32 reset_reason)
 {
-       if (reset_dev && reset_dev->system_reset_check &&
-           reset_dev->system_reset_check(reset_type, reset_reason))
-               return TRUE;
-
-       return FALSE;
+       return !!sbi_system_reset_get_device(reset_type, reset_reason);
 }
 
 void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
@@ -48,6 +54,7 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
        u32 cur_hartid = current_hartid();
        struct sbi_domain *dom = sbi_domain_thishart_ptr();
        struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
+       struct sbi_dlist *pos;
 
        /* Send HALT IPI to every hart other than the current hart */
        while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &hmask)) {

lib/sbi/sbi_system.c void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason) · line 65

Quoted 5 lines
lib/sbi/sbi_system.c +0 -2
@@ -61,10 +68,13 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
        /* Stop current HART */
        sbi_hsm_hart_stop(scratch, FALSE);
 
-       /* Platform specific reset if domain allowed system reset */
-       if (dom->system_reset_allowed &&

This breaks sbi_domain reset check.

We only allow system reset if the domain assigned to calling HART is allowed to reset the system. This way non-secure domains can't reset the system and in-future system reset request from non-secure domain will be forwarded as notifications to some secure domain.

lib/sbi/sbi_system.c void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason) · line 76

Quoted 8 lines
lib/sbi/sbi_system.c +6 -2
-           reset_dev && reset_dev->system_reset)
-               reset_dev->system_reset(reset_type, reset_reason);
+       /* Check each reset device registered for supported reset type */
+       sbi_list_for_each(pos, &(reset_devices_list)) {
+               struct sbi_system_reset_device *dev =
+                       to_system_reset_device(pos);
+               if (dev->system_reset_check(reset_type, reset_reason))
+                       dev->system_reset(reset_type, reset_reason);

Just add "break;" here.

If the reset did not happen then HART should follow the SBI exit path (i.e. sbi_exit()).

Quoted 99 lines
lib/sbi/sbi_system.c +1 -0
+       }
 
        /* If platform specific reset did not work then do sbi_exit() */
        sbi_exit(scratch);
lib/utils/reset/fdt_reset_gpio.c +1 -1
index 77e4d0e..4da1450 100644
@@ -115,7 +115,7 @@ static int gpio_reset_init(void *fdt, int nodeoff,
        if (len > 0)
                reset->inactive_delay = fdt32_to_cpu(*val);
 
-       sbi_system_reset_set_device(&gpio_reset);
+       sbi_system_reset_add_device(&gpio_reset);
 
        return 0;
 }
lib/utils/reset/fdt_reset_sunxi_wdt.c +1 -1
index e4f16e3..6d1b5b7 100644
@@ -61,7 +61,7 @@ static int sunxi_wdt_reset_init(void *fdt, int nodeoff,
 
        sunxi_wdt_base = (volatile void *)(unsigned long)reg_addr;
 
-       sbi_system_reset_set_device(&sunxi_wdt_reset);
+       sbi_system_reset_add_device(&sunxi_wdt_reset);
 
        return 0;
 }
lib/utils/reset/fdt_reset_thead.c +1 -1
index 9f2fe03..750b7aa 100644
@@ -126,7 +126,7 @@ static int thead_reset_init(void *fdt, int nodeoff,
                }
        }
 
-       sbi_system_reset_set_device(&thead_reset);
+       sbi_system_reset_add_device(&thead_reset);
 
        return 0;
 }
lib/utils/sys/htif.c +1 -1
index 330a9a6..7c69c7f 100644
@@ -176,7 +176,7 @@ static struct sbi_system_reset_device htif_reset = {
 
 int htif_system_reset_init(void)
 {
-       sbi_system_reset_set_device(&htif_reset);
+       sbi_system_reset_add_device(&htif_reset);
 
        return 0;
 }
lib/utils/sys/sifive_test.c +1 -1
index 4533954..a9ebb5c 100644
@@ -59,7 +59,7 @@ static struct sbi_system_reset_device sifive_test_reset = {
 int sifive_test_init(unsigned long base)
 {
        sifive_test_base = (void *)base;
-       sbi_system_reset_set_device(&sifive_test_reset);
+       sbi_system_reset_add_device(&sifive_test_reset);
 
        return 0;
 }
platform/kendryte/k210/platform.c +1 -1
index 35cec5f..e7caec3 100644
@@ -108,7 +108,7 @@ static struct sbi_system_reset_device k210_reset = {
 static int k210_early_init(bool cold_boot)
 {
        if (cold_boot)
-               sbi_system_reset_set_device(&k210_reset);
+               sbi_system_reset_add_device(&k210_reset);
 
        return 0;
 }
platform/nuclei/ux600/platform.c +1 -2
index 6bef4c4..6f87cf8 100644
@@ -148,7 +148,7 @@ static int ux600_early_init(bool cold_boot)
        u32 regval;
 
        if (cold_boot)
-               sbi_system_reset_set_device(&ux600_reset);
+               sbi_system_reset_add_device(&ux600_reset);
 
        /* Measure CPU Frequency using Timer */
        ux600_clk_freq = ux600_get_clk_freq();
--

2.31.1

Quoted 4 lines

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Regards,
Anup

#3 lore raw

RFC PATCH 2/2 lib: sbi: add priority for reset handler

In reply to Nikita Shubin

From: Nikita Shubin <[email protected]>

Let's make system_reset_check returning priority instead of only true/false. In that case 0 - means not supported, and anything above means priority that makes existing reset handlers being used in first place, unless it is decided to lower their priority.

The handler with the least priority wins.

---
 lib/sbi/sbi_system.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
lib/sbi/sbi_system.c +16 -4
index 92bc0ac..a82c4ef 100644
@@ -55,6 +55,8 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
 	struct sbi_domain *dom = sbi_domain_thishart_ptr();
 	struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
 	struct sbi_dlist *pos;
+	struct sbi_system_reset_device *reset_dev = 0;
+	int priority = 255;
 
 	/* Send HALT IPI to every hart other than the current hart */
 	while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &hmask)) {
@@ -70,12 +72,22 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
 
 	/* Check each reset device registered for supported reset type */
 	sbi_list_for_each(pos, &(reset_devices_list)) {
-		struct sbi_system_reset_device *dev =
-			to_system_reset_device(pos);
-		if (dev->system_reset_check(reset_type, reset_reason))
-			dev->system_reset(reset_type, reset_reason);
+		struct sbi_system_reset_device *dev
+			= to_system_reset_device(pos);
+		int status = dev->system_reset_check(reset_type, reset_reason);
+
+		if (status == 0)
+			continue;
+
+		if (status < priority) {
+			reset_dev = dev;
+			priority = status;
+		}
 	}
 
+	if (reset_dev)
+		reset_dev->system_reset(reset_type, reset_reason);
+
 	/* If platform specific reset did not work then do sbi_exit() */
 	sbi_exit(scratch);
 }
Signature · 1 line
2.31.1
#4 lore raw

RFC PATCH 2/2 lib: sbi: add priority for reset handler

? 2021-09-29???? 12:41 +0300?Nikita Shubin???

Quoted 10 lines

From: Nikita Shubin <[email protected]>

Let's make system_reset_check returning priority instead of only true/false. In that case 0 - means not supported, and anything above means priority that makes existing reset handlers being used in first place, unless it is decided to lower their priority.

The handler with the least priority wins.

Isn't this priority used to control the shutdown sequence of different areas? What is this usage scenario?

Regards,
Xiang W

Quoted 55 lines

---
?lib/sbi/sbi_system.c | 20 ++++++++++++++++----
?1 file changed, 16 insertions(+), 4 deletions(-)

lib/sbi/sbi_system.c +2 -0
index 92bc0ac..a82c4ef 100644
@@ -55,6 +55,8 @@ void __noreturn sbi_system_reset(u32 reset_type,
 u32 reset_reason)
 ????????struct sbi_domain *dom = sbi_domain_thishart_ptr();
 ????????struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
 ????????struct sbi_dlist *pos;
+???????struct sbi_system_reset_device *reset_dev = 0;
+???????int priority = 255;

?
????????/* Send HALT IPI to every hart other than the current hart */ ????????while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &hmask)) {

lib/sbi/sbi_system.c +0 -0
@@ -70,12 +72,22 @@ void __noreturn sbi_system_reset(u32 reset_type,
 u32 reset_reason)

?
????????/* Check each reset device registered for supported reset type */
????????sbi_list_for_each(pos, &(reset_devices_list)) { -???????????????struct sbi_system_reset_device *dev = -???????????????????????to_system_reset_device(pos); -???????????????if (dev->system_reset_check(reset_type, reset_reason)) -???????????????????????dev->system_reset(reset_type, reset_reason); +???????????????struct sbi_system_reset_device *dev +???????????????????????= to_system_reset_device(pos); +???????????????int status = dev->system_reset_check(reset_type, reset_reason);

lib/sbi/sbi_system.c +8 -0
+
+???????????????if (status == 0)
+???????????????????????continue;
+
+???????????????if (status < priority) {
+???????????????????????reset_dev = dev;
+???????????????????????priority = status;
+???????????????}

????????}
?
+???????if (reset_dev) +???????????????reset_dev->system_reset(reset_type, reset_reason); +
????????/* If platform specific reset did not work then do sbi_exit() */
????????sbi_exit(scratch);
?}

Signature · 1 line
2.31.1
#5 lore raw

RFC PATCH 2/2 lib: sbi: add priority for reset handler

Quoted 8 lines · On Thu, 30 Sep 2021 10:26:11 +0800 Xiang W <[email protected]> wrote:

? 2021-09-29???? 12:41 +0300?Nikita Shubin???

Quoted 7 lines

From: Nikita Shubin <[email protected]>

Let's make system_reset_check returning priority instead of only true/false. In that case 0 - means not supported, and anything above means priority that makes existing reset handlers being used in first place, unless it is decided to lower their priority.

Quoted 5 lines
Quoted 3 lines

The handler with the least priority wins.

Isn't this priority used to control the shutdown sequence of different areas? What is this usage scenario?

Exactly!

The current situation if following on Sifive Unmatched reset only works via i2c PMIC, shutdown also works via i2c, but shutdown via gpio is preferable, so we end up with 2 reset devices.

To prefer shutdown via gpio priority is desirable.

Yours,
Nikita Shubin

#6 lore raw

RFC PATCH 2/2 lib: sbi: add priority for reset handler

In reply to Nikita Shubin

lib/sbi/sbi_system.c void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)

Quoted 20 lines · Nikita Shubin

From: Nikita Shubin <[email protected]>

Let's make system_reset_check returning priority instead of only true/false. In that case 0 - means not supported, and anything above means priority that makes existing reset handlers being used in first place, unless it is decided to lower their priority.

The handler with the least priority wins.

---
 lib/sbi/sbi_system.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
lib/sbi/sbi_system.c +0 -0
index 92bc0ac..a82c4ef 100644
@@ -55,6 +55,8 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)

Instead of changing sbi_system_reset(), the sbi_system_reset_get_device() can return "sbi_system_reset_device *" with highest non-zero priority.

Quoted 14 lines
lib/sbi/sbi_system.c +2 -2
        struct sbi_domain *dom = sbi_domain_thishart_ptr();
        struct sbi_scratch *scratch = sbi_scratch_thishart_ptr();
        struct sbi_dlist *pos;
+       struct sbi_system_reset_device *reset_dev = 0;
+       int priority = 255;
 
        /* Send HALT IPI to every hart other than the current hart */
        while (!sbi_hsm_hart_interruptible_mask(dom, hbase, &hmask)) {
@@ -70,12 +72,22 @@ void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason)
 
        /* Check each reset device registered for supported reset type */
        sbi_list_for_each(pos, &(reset_devices_list)) {
-               struct sbi_system_reset_device *dev =
-                       to_system_reset_device(pos);

lib/sbi/sbi_system.c void __noreturn sbi_system_reset(u32 reset_type, u32 reset_reason) · line 82

Quoted 10 lines
lib/sbi/sbi_system.c +8 -2
-               if (dev->system_reset_check(reset_type, reset_reason))
-                       dev->system_reset(reset_type, reset_reason);
+               struct sbi_system_reset_device *dev
+                       = to_system_reset_device(pos);
+               int status = dev->system_reset_check(reset_type, reset_reason);
+
+               if (status == 0)
+                       continue;
+
+               if (status < priority) {

This is counter intuitive because lower value means higher priority.

Instead, I suggest to have following priority semantics:
1) 0 means not support
2) higher value means higher priority

Quoted 15 lines
lib/sbi/sbi_system.c +6 -1
+                       reset_dev = dev;
+                       priority = status;
+               }
        }
 
+       if (reset_dev)
+               reset_dev->system_reset(reset_type, reset_reason);
+
        /* If platform specific reset did not work then do sbi_exit() */
        sbi_exit(scratch);
 }
--

2.31.1

Quoted 4 lines

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Regards,
Anup

#7 lore raw

cover system reset rework to list, priority

In reply to Nikita Shubin
Quoted 7 lines · Nikita Shubin

From: Nikita Shubin <[email protected]>

Hi Anup.

I decided to go as separate proposal for system reset, as i don't think da9063 is really connected to this one.

Overall the approach taken by this series is in right direction but need to address some comments.

Quoted 6 lines

Let's rework our current sbi_system reset to support multiply reset handlers.

However there are some things to discuss. If we want priority handling like in Linux, we need separate lists for each reset type and sort them on insertions.

We don't need to have priority for each reset_type. I think priority per-device is sufficient. This way will have just one list of reset devices.

Quoted 22 lines

If we go the way like in the second patch no separate lists are needed but we will lack the ability to call them in chain.

So what are your thoughts ?

Nikita Shubin (2):
lib: sbi: convert reset to list
lib: sbi: add priority for reset handler

 include/sbi/sbi_system.h              | 13 +++++--
 lib/sbi/sbi_init.c                    |  5 ++-
 lib/sbi/sbi_system.c                  | 50 +++++++++++++++++++--------
 lib/utils/reset/fdt_reset_gpio.c      |  2 +-
 lib/utils/reset/fdt_reset_sunxi_wdt.c |  2 +-
 lib/utils/reset/fdt_reset_thead.c     |  2 +-
 lib/utils/sys/htif.c                  |  2 +-
 lib/utils/sys/sifive_test.c           |  2 +-
 platform/kendryte/k210/platform.c     |  2 +-
 platform/nuclei/ux600/platform.c      |  2 +-
 10 files changed, 58 insertions(+), 24 deletions(-)
Quoted 8 lines

--
2.31.1

--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi

Regards,
Anup