Skip to contentSkip to conversation

reset: add board reset type

PATCH Superseded [email protected] 2 participants 16 messages May 29 – Jun 2

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover reset: add board reset type

This series introduces convenience functionality for prototype boards where reset is not fully working - for example, where only warm reset is functional, but cold reset must still be enabled for the production variant.

Patch 1 allows per-board default reset override.
Patch 2 adds reset -c support to explicitly trigger cold reset. Patch 3 adds reset type printout on the console.
Patch 4 introduces a small fixup for the x86 reset driver. Patch 5 updates documentation for reset command.
Patch 6 updates reset command tests.

Denis Mukhin (6):
reset: Allow per-board reset type
reset: Add explicit cold reset support
reset: Print reset type on diagnostic console
reset: x86: Use cpu_hlt() in pch_sysreset_power_off()
docs: reset: document cold reset option
tests: reset: add cold/warm reset types

 cmd/boot.c                         |  3 +-
 doc/usage/cmd/reset.rst            |  8 +++++
 drivers/sysreset/Kconfig           | 31 ++++++++++++++++++
 drivers/sysreset/sysreset-uclass.c | 50 +++++++++++++++++++++++++++---
 drivers/sysreset/sysreset_x86.c    |  5 +--
 test/py/tests/test_reset.py        |  8 ++---
 6 files changed, 94 insertions(+), 11 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH v3 1/6 reset: Allow per-board reset type

From: Denis Mukhin <[email protected]>

Some prototype boards may not have (temporarily) all required reset types supported (e.g. only warm reset supported).

Add a Kconfig choice to select the board-specific default reset type used by the reset command, allowing it to work on such boards.

Keep cold reset as the default.

---
Changes since v2:
- n/a

---
 drivers/sysreset/Kconfig           | 31 ++++++++++++++++++++++++++++++
 drivers/sysreset/sysreset-uclass.c | 19 +++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)
drivers/sysreset/Kconfig +31 -0
index 90f740f51d42..2584c2b203e5 100644
@@ -57,6 +57,37 @@ config SYSRESET_CMD_RESET_ARGS
 	  additional arguments for implementing arch/board specific
 	  functionality.
 
+if SYSRESET_CMD_RESET
+choice
+	prompt "Default reset type for reset command"
+	default SYSRESET_CMD_RESET_DEFAULT_COLD
+	help
+	  Select the default reset type used by the reset command when no
+	  explicit reset type is requested.
+
+config SYSRESET_CMD_RESET_DEFAULT_WARM
+	bool "Warm reset"
+	help
+	  Reset CPU while keeping GPIOs active.
+
+config SYSRESET_CMD_RESET_DEFAULT_COLD
+	bool "Cold reset"
+	help
+	  Reset CPU and GPIOs.
+
+config SYSRESET_CMD_RESET_DEFAULT_POWER
+	bool "Power reset"
+	help
+	  Reset PMIC by removing and restoring power.
+
+config SYSRESET_CMD_RESET_DEFAULT_POWER_OFF
+	bool "Power off"
+	help
+	  Turn off power.
+
+endchoice
+endif
+
 if CMD_POWEROFF
 
 config SYSRESET_CMD_POWEROFF
drivers/sysreset/sysreset-uclass.c +18 -1
index f25e09e9cd06..d2fddb470bf1 100644
@@ -150,9 +150,26 @@ void reset_cpu(void)
 }
 
 #if IS_ENABLED(CONFIG_SYSRESET_CMD_RESET)
+static enum sysreset_t sysreset_get_default_type(void)
+{
+	if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_WARM))
+		return SYSRESET_WARM;
+
+	if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_COLD))
+		return SYSRESET_COLD;
+
+	if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_POWER))
+		return SYSRESET_POWER;
+
+	if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_POWER_OFF))
+		return SYSRESET_POWER_OFF;
+
+	return SYSRESET_COLD;
+}
+
 int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
-	enum sysreset_t reset_type = SYSRESET_COLD;
+	enum sysreset_t reset_type = sysreset_get_default_type();
 
 	if (argc > 2)
 		return CMD_RET_USAGE;
Signature · 1 line
2.54.0
Reviewed-by on v3 1/6
#2 lore raw

Re: [PATCH v3 1/6] reset: Allow per-board reset type

Hi Denis,

Quoted 8 lines · None

reset: Allow per-board reset type

Some prototype boards may not have (temporarily) all required reset types supported (e.g. only warm reset supported).

Add a Kconfig choice to select the board-specific default reset type used by the reset command, allowing it to work on such boards.

Quoted 7 lines

Keep cold reset as the default.

drivers/sysreset/Kconfig | 31 +++++++++++++++++++++++++++++++

 drivers/sysreset/sysreset-uclass.c | 19 ++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

drivers/sysreset/Kconfig config SYSRESET_CMD_RESET_ARGS · line 65

Quoted 11 lines
drivers/sysreset/Kconfig +9 -0
@@ -57,6 +57,37 @@ config SYSRESET_CMD_RESET_ARGS
+config SYSRESET_CMD_RESET_DEFAULT_WARM
+     bool "Warm reset"
+     help
+       Reset CPU while keeping GPIOs active.
+
+config SYSRESET_CMD_RESET_DEFAULT_COLD
+     bool "Cold reset"
+     help
+       Reset CPU and GPIOs.

This is very thin - as is the comment in include/sysreset.h - how about:

"Full cold reset of the machine, including CPU, GPIOs, PMIC and other logic in the machine"

drivers/sysreset/Kconfig config SYSRESET_CMD_RESET_ARGS · line 65

Quoted 11 lines
drivers/sysreset/Kconfig +9 -0
@@ -57,6 +57,37 @@ config SYSRESET_CMD_RESET_ARGS
+config SYSRESET_CMD_RESET_DEFAULT_POWER
+     bool "Power reset"
+     help
+       Reset PMIC by removing and restoring power.
+
+config SYSRESET_CMD_RESET_DEFAULT_POWER_OFF
+     bool "Power off"
+     help
+       Turn off power.

Could we use the 'poweroff' command instead?

Quoted 8 lines
drivers/sysreset/sysreset-uclass.c +6 -0
@@ -150,9 +150,26 @@ void reset_cpu(void)
+static enum sysreset_t sysreset_get_default_type(void)
+{
+     if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_WARM))
+             return SYSRESET_WARM;
+
+     if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_COLD))

drivers/sysreset/sysreset-uclass.c void reset_cpu(void) · line 165

Quoted 10 lines
drivers/sysreset/sysreset-uclass.c +10 -0
+             return SYSRESET_COLD;
+
+     if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_POWER))
+             return SYSRESET_POWER;
+
+     if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_POWER_OFF))
+             return SYSRESET_POWER_OFF;
+
+     return SYSRESET_COLD;
+}

The trailing return SYSRESET_COLD is unreachable, BTW.

Regards,
Simon

#3 lore raw

Re: [PATCH v3 1/6] reset: Allow per-board reset type

Quoted 13 lines · Simon Glass

Hi Denis,

Quoted 10 lines · None

reset: Allow per-board reset type

Some prototype boards may not have (temporarily) all required reset types supported (e.g. only warm reset supported).

Add a Kconfig choice to select the board-specific default reset type used by the reset command, allowing it to work on such boards.

Keep cold reset as the default.

Quoted 7 lines
Quoted 5 lines

drivers/sysreset/Kconfig | 31 +++++++++++++++++++++++++++++++

 drivers/sysreset/sysreset-uclass.c | 19 ++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)

Thanks!

Quoted 18 lines

drivers/sysreset/Kconfig config SYSRESET_CMD_RESET_ARGS · line 65

Quoted 12 lines
drivers/sysreset/Kconfig +9 -0
@@ -57,6 +57,37 @@ config SYSRESET_CMD_RESET_ARGS
+config SYSRESET_CMD_RESET_DEFAULT_WARM
+     bool "Warm reset"
+     help
+       Reset CPU while keeping GPIOs active.
+
+config SYSRESET_CMD_RESET_DEFAULT_COLD
+     bool "Cold reset"
+     help
+       Reset CPU and GPIOs.

This is very thin - as is the comment in include/sysreset.h - how about:

"Full cold reset of the machine, including CPU, GPIOs, PMIC and other logic in the machine"

Quoted 13 lines

drivers/sysreset/Kconfig config SYSRESET_CMD_RESET_ARGS · line 65

Quoted 11 lines
drivers/sysreset/Kconfig +9 -0
@@ -57,6 +57,37 @@ config SYSRESET_CMD_RESET_ARGS
+config SYSRESET_CMD_RESET_DEFAULT_POWER
+     bool "Power reset"
+     help
+       Reset PMIC by removing and restoring power.
+
+config SYSRESET_CMD_RESET_DEFAULT_POWER_OFF
+     bool "Power off"
+     help
+       Turn off power.

Could we use the 'poweroff' command instead?

Will drop SYSRESET_CMD_RESET_DEFAULT_POWER_OFF in v4 and leave a code commentary to rely on poweroff command.

Quoted 13 lines
Quoted 13 lines
drivers/sysreset/sysreset-uclass.c +10 -0
@@ -150,9 +150,26 @@ void reset_cpu(void)
+static enum sysreset_t sysreset_get_default_type(void)
+{
+     if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_WARM))
+             return SYSRESET_WARM;
+
+     if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_COLD))
+             return SYSRESET_COLD;
+
+     if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_POWER))
+             return SYSRESET_POWER;
Quoted 8 lines

drivers/sysreset/sysreset-uclass.c void reset_cpu(void) · line 168

Quoted 6 lines
drivers/sysreset/sysreset-uclass.c +6 -0
+
+     if (IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_DEFAULT_POWER_OFF))
+             return SYSRESET_POWER_OFF;
+
+     return SYSRESET_COLD;
+}

The trailing return SYSRESET_COLD is unreachable, BTW.

Thanks for the catch!

Quoted 3 lines

Regards,
Simon

#4 lore raw

PATCH v3 2/6 reset: Add explicit cold reset support

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Some prototype boards default to a non-cold reset type, e.g. warm reset.

Add reset -c so users can excplicitly request a cold reset when needed.

---
Changes since v2:
- n/a

Changes since v1:
- corrected args parsing in do_reset()
- updated commit message
- fixup reset command description

---
 cmd/boot.c                         |  3 ++-
 drivers/sysreset/sysreset-uclass.c | 13 +++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
cmd/boot.c +2 -1
index 29cdf4a9a81a..2cef907e291e 100644
@@ -59,13 +59,14 @@ U_BOOT_CMD(
 U_BOOT_CMD(
 	reset, 2, 0,	do_reset,
 	"Perform RESET of the CPU",
-	"- cold boot without level specifier\n"
+	"- reset without level specifier\n"
 #if IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_ARGS)
 // All options handled by sysreset drivers via their sysreset_ops.request_arg callback
 #ifdef CONFIG_SYSRESET_QCOM_PSCI
 	"reset -edl - Boot to Emergency DownLoad mode\n"
 #endif
 #endif
+	"reset -c - cold reset if implemented\n"
 	"reset -w - warm reset if implemented"
 );
 
drivers/sysreset/sysreset-uclass.c +11 -2
index d2fddb470bf1..df68b5c3f9eb 100644
@@ -174,8 +174,17 @@ int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	if (argc > 2)
 		return CMD_RET_USAGE;
 
-	if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'w') {
-		reset_type = SYSRESET_WARM;
+	if (argc == 2 && argv[1][0] == '-') {
+		switch (argv[1][1]) {
+		case 'c':
+			reset_type = SYSRESET_COLD;
+			break;
+		case 'w':
+			reset_type = SYSRESET_WARM;
+			break;
+		default:
+			return CMD_RET_USAGE;
+		}
 	}
 
 	printf("resetting ...\n");
Signature · 1 line
2.54.0
#5 lore raw

Re: [PATCH v3 2/6] reset: Add explicit cold reset support

Hi Denis,

Quoted 21 lines · None

reset: Add explicit cold reset support

Some prototype boards default to a non-cold reset type, e.g. warm reset.

Add reset -c so users can excplicitly request a cold reset when needed.

cmd/boot.c | 3 ++-

 drivers/sysreset/sysreset-uclass.c | 13 +++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/sysreset/sysreset-uclass.c +2 -2
@@ -174,8 +174,17 @@ int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
      if (argc > 2)
              return CMD_RET_USAGE;
 
-     if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'w') {
-             reset_type = SYSRESET_WARM;
+     if (argc == 2 && argv[1][0] == '-') {
+             switch (argv[1][1]) {

drivers/sysreset/sysreset-uclass.c int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) · line 188

Quoted 10 lines
drivers/sysreset/sysreset-uclass.c +9 -0
+             case 'c':
+                     reset_type = SYSRESET_COLD;
+                     break;
+             case 'w':
+                     reset_type = SYSRESET_WARM;
+                     break;
+             default:
+                     return CMD_RET_USAGE;
+             }
      }

This regresses reset -edl on Qualcomm. Previously, an unknown -x argument fell through to the SYSRESET_CMD_RESET_ARGS path, where qcom_psci_sysreset_request_arg() picks up -edl and returns -EINPROGRESS. With this change, argv[1][1] == 'e' hits the default branch and bails out with CMD_RET_USAGE before sysreset_walk_arg() runs, so reset -edl no longer works.

Please leave reset_type at its default for unrecognised flags (so the arg-dispatch path can still claim them), or call sysreset_walk_arg() first and only complain if nothing handled the argument. Also, matching only argv[1][1] means reset -cx silently behaves like reset -c - please tighten with strcmp() or a length check.

The could be a good usage for getopt() but sadly it increases code size too much [1]

BTW -edl doesn't follow the normal flags approach, so we should probably change that at some point.

cmd/boot.c U_BOOT_CMD( · line 68

Quoted 13 lines
cmd/boot.c +2 -1
@@ -59,10 +59,11 @@ U_BOOT_CMD(
 U_BOOT_CMD(
      reset, 2, 0,    do_reset,
      "Perform RESET of the CPU",
-     "- cold boot without level specifier\n"
+     "- reset without level specifier\n"
 #ifdef CONFIG_SYSRESET_QCOM_PSCI
      "reset -edl - Boot to Emergency DownLoad mode\n"
 #endif
+     "reset -c - cold reset if implemented\n"
      "reset -w - warm reset if implemented"
 );

The '- reset without level specifier' line reads oddly now that the level is no longer guaranteed to be cold - perhaps '- reset using the configured default type'.

Quoted 1 line

Add reset -c so users can excplicitly request a cold reset when needed.

Typo: excplicitly -> explicitly. Also please use single quotes around tokens like 'reset -c' per U-Boot convention.

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/

#6 lore raw

Re: [PATCH v3 2/6] reset: Add explicit cold reset support

Quoted 42 lines · Simon Glass

Hi Denis,

Quoted 21 lines · None

reset: Add explicit cold reset support

Some prototype boards default to a non-cold reset type, e.g. warm reset.

Add reset -c so users can excplicitly request a cold reset when needed.

cmd/boot.c | 3 ++-

 drivers/sysreset/sysreset-uclass.c | 13 +++++++++++--
 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/sysreset/sysreset-uclass.c +2 -2
@@ -174,8 +174,17 @@ int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
      if (argc > 2)
              return CMD_RET_USAGE;
 
-     if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'w') {
-             reset_type = SYSRESET_WARM;
+     if (argc == 2 && argv[1][0] == '-') {
+             switch (argv[1][1]) {

drivers/sysreset/sysreset-uclass.c int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) · line 188

Quoted 10 lines
drivers/sysreset/sysreset-uclass.c +9 -0
+             case 'c':
+                     reset_type = SYSRESET_COLD;
+                     break;
+             case 'w':
+                     reset_type = SYSRESET_WARM;
+                     break;
+             default:
+                     return CMD_RET_USAGE;
+             }
      }

This regresses reset -edl on Qualcomm. Previously, an unknown -x argument fell through to the SYSRESET_CMD_RESET_ARGS path, where qcom_psci_sysreset_request_arg() picks up -edl and returns -EINPROGRESS. With this change, argv[1][1] == 'e' hits the default branch and bails out with CMD_RET_USAGE before sysreset_walk_arg() runs, so reset -edl no longer works.

Quoted 5 lines

Please leave reset_type at its default for unrecognised flags (so the arg-dispatch path can still claim them), or call sysreset_walk_arg() first and only complain if nothing handled the argument. Also, matching only argv[1][1] means reset -cx silently behaves like reset -c - please tighten with strcmp() or a length check.

Yes, will do; thanks for catching this!

Quoted 34 lines

The could be a good usage for getopt() but sadly it increases code size too much [1]

BTW -edl doesn't follow the normal flags approach, so we should probably change that at some point.

cmd/boot.c U_BOOT_CMD( · line 68

Quoted 13 lines
cmd/boot.c +2 -1
@@ -59,10 +59,11 @@ U_BOOT_CMD(
 U_BOOT_CMD(
      reset, 2, 0,    do_reset,
      "Perform RESET of the CPU",
-     "- cold boot without level specifier\n"
+     "- reset without level specifier\n"
 #ifdef CONFIG_SYSRESET_QCOM_PSCI
      "reset -edl - Boot to Emergency DownLoad mode\n"
 #endif
+     "reset -c - cold reset if implemented\n"
      "reset -w - warm reset if implemented"
 );

The '- reset without level specifier' line reads oddly now that the level is no longer guaranteed to be cold - perhaps '- reset using the configured default type'.

Quoted 1 line

Add reset -c so users can excplicitly request a cold reset when needed.

Typo: excplicitly -> explicitly. Also please use single quotes around tokens like 'reset -c' per U-Boot convention.

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/

#7 lore raw

PATCH v3 3/6 reset: Print reset type on diagnostic console

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Add a diagnostic console trace indicating the reset type.

---
Changes since v2:
- n/a

Changes since v1:
- corrected the string representation for SYSRESET_POWER

---
 drivers/sysreset/sysreset-uclass.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/sysreset/sysreset-uclass.c +17 -1
index df68b5c3f9eb..8f49a6093d49 100644
@@ -22,6 +22,22 @@
 #include <linux/err.h>
 #include <asm/global_data.h>
 
+static const char *get_reset_type_str(enum sysreset_t reset_type)
+{
+	switch (reset_type) {
+	case SYSRESET_WARM:
+		return "warm";
+	case SYSRESET_COLD:
+		return "cold";
+	case SYSRESET_POWER:
+		return "power";
+	case SYSRESET_POWER_OFF:
+		return "power off";
+	default:
+		return "unknown";
+	}
+}
+
 int sysreset_request(struct udevice *dev, enum sysreset_t type)
 {
 	struct sysreset_ops *ops = sysreset_get_ops(dev);
@@ -187,7 +203,7 @@ int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 		}
 	}
 
-	printf("resetting ...\n");
+	printf("resetting (%s)...\n", get_reset_type_str(reset_type));
 	mdelay(100);
 
 #if IS_ENABLED(CONFIG_SYSRESET_CMD_RESET_ARGS)
Signature · 1 line
2.54.0
#8 lore raw

Re: [PATCH v3 3/6] reset: Print reset type on diagnostic console

Hi Denis,

Quoted 20 lines · None

reset: Print reset type on diagnostic console

Add a diagnostic console trace indicating the reset type.

drivers/sysreset/sysreset-uclass.c | 18 +++++++++++++++++-

 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/sysreset/sysreset-uclass.c +6 -0
@@ -22,6 +22,22 @@
 #include <linux/err.h>
 #include <asm/global_data.h>
 
+static const char *get_reset_type_str(enum sysreset_t reset_type)
+{
+     switch (reset_type) {
+     case SYSRESET_WARM:
+             return 'warm';
+     case SYSRESET_COLD:

drivers/sysreset/sysreset-uclass.c line 40

Quoted 10 lines
drivers/sysreset/sysreset-uclass.c +10 -0
+             return 'cold';
+     case SYSRESET_POWER:
+             return 'power';
+     case SYSRESET_POWER_OFF:
+             return "power off";
+     default:
+             return 'unknown';
+     }
+}
+

This is placed outside the #if IS_ENABLED(CONFIG_SYSRESET_CMD_RESET) block, but its only caller (do_reset()) is inside it. With CONFIG_SYSRESET_CMD_RESET=n the static function becomes unused and triggers -Wunused-function. Please move it inside the guard, next to do_reset()

Regards,
Simon

#9 lore raw

PATCH v3 4/6 reset: x86: Use cpu_hlt() in pch_sysreset_power_off()

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Use cpu_hlt() instead of open-coded "hlt" in pch_sysreset_power_off().

Also, replace the open-coded busy loop in efi_reset_system() and use cpu_hlt().

---
Changes since v2:
- n/a

Changes since v1:
- dropped unneeded #include
- corrected the commit message

---
 drivers/sysreset/sysreset_x86.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/sysreset/sysreset_x86.c +3 -2
index c2f28c65280f..afb77d9c5c21 100644
@@ -65,7 +65,7 @@ int pch_sysreset_power_off(struct udevice *dev)
 	outl(reg32, pm.base + pm.pm1_cnt_ofs);
 
 	for (;;)
-		asm("hlt");
+		cpu_hlt();
 }
 
 static int x86_sysreset_request(struct udevice *dev, enum sysreset_t type)
@@ -120,7 +120,8 @@ void __efi_runtime EFIAPI efi_reset_system(
 
 	/* TODO EFI_RESET_SHUTDOWN */
 
-	while (1) { }
+	for (;;)
+		cpu_hlt();
 }
 #endif
 
Signature · 1 line
2.54.0
Reviewed-by on v3 4/6
#10 lore raw

Re: [PATCH v3 4/6] reset: x86: Use cpu_hlt() in pch_sysreset_power_off()

Hi Denis,

Quoted 11 lines · None

reset: x86: Use cpu_hlt() in pch_sysreset_power_off()

Use cpu_hlt() instead of open-coded 'hlt' in pch_sysreset_power_off().

Also, replace the open-coded busy loop in efi_reset_system() and use cpu_hlt().

drivers/sysreset/sysreset_x86.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)

drivers/sysreset/sysreset_x86.c void __efi_runtime EFIAPI efi_reset_system( · line 125

Quoted 9 lines
drivers/sysreset/sysreset_x86.c +2 -1
@@ -120,7 +120,8 @@ void __efi_runtime EFIAPI efi_reset_system(
 
      /* TODO EFI_RESET_SHUTDOWN */
 
-     while (1) { }
+     for (;;)
+             cpu_hlt();
 }

Just to check - this is an __efi_runtime function, so the body must not call outside the runtime section after SetVirtualAddressMap(). cpu_hlt() is static inline __always_inline in asm/processor.h so it expands to a bare hlt here, which is fine. Worth mentioning in the commit message so the runtime-safety is explicit.

Regards,
Simon

#11 lore raw

Re: [PATCH v3 4/6] reset: x86: Use cpu_hlt() in pch_sysreset_power_off()

Quoted 22 lines · Simon Glass

Hi Denis,

Quoted 11 lines · None

reset: x86: Use cpu_hlt() in pch_sysreset_power_off()

Use cpu_hlt() instead of open-coded 'hlt' in pch_sysreset_power_off().

Also, replace the open-coded busy loop in efi_reset_system() and use cpu_hlt().

drivers/sysreset/sysreset_x86.c | 5 +++--

 1 file changed, 3 insertions(+), 2 deletions(-)
Quoted 5 lines
drivers/sysreset/sysreset_x86.c +0 -0
@@ -120,7 +120,8 @@ void __efi_runtime EFIAPI efi_reset_system(
 
      /* TODO EFI_RESET_SHUTDOWN */
 
Quoted 10 lines

drivers/sysreset/sysreset_x86.c void __efi_runtime EFIAPI efi_reset_system( · line 125

Quoted 4 lines
drivers/sysreset/sysreset_x86.c +2 -1
-     while (1) { }
+     for (;;)
+             cpu_hlt();
 }

Just to check - this is an __efi_runtime function, so the body must not call outside the runtime section after SetVirtualAddressMap(). cpu_hlt() is static inline __always_inline in asm/processor.h so it expands to a bare hlt here, which is fine. Worth mentioning in the commit message so the runtime-safety is explicit.

I think I will move that efi_reset_system() fixup to a separate patch with a proper description.

Quoted 3 lines

Regards,
Simon

#12 lore raw

PATCH v3 5/6 docs: reset: document cold reset option

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Update the reset command documentation to cover reset -c and explain that the default reset type can be overridden through the relevant Kconfig choice.

---
Changes since v2:
- n/a

Changes since v1:
- new patch

---
 doc/usage/cmd/reset.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
doc/usage/cmd/reset.rst +8 -0
index 79bc8b9deca5..e319d2146caa 100644
@@ -12,6 +12,7 @@ Synopsis
 ::
 
     reset
+    reset -c
     reset -w
     reset -edl
 
@@ -21,6 +22,13 @@ Description
 Perform reset of the CPU. By default does COLD reset, which resets CPU,
 DDR and peripherals, on some boards also resets external PMIC.
 
+The default behavior may be overridden via
+CONFIG_SYSRESET_CMD_RESET_DEFAULT_{COLD,WARM,POWER,POWER_OFF}.
+
+-c
+    Do COLD reset: reset CPU and peripheral/DDR; on some boards also resets
+    external PMIC.
+
 -w
     Do WARM reset: reset CPU but keep peripheral/DDR/PMIC active.
 
Signature · 1 line
2.54.0
#13 lore raw

Re: [PATCH v3 5/6] docs: reset: document cold reset option

Hi Denis,

Quoted 13 lines · None

docs: reset: document cold reset option

Update the reset command documentation to cover reset -c and explain that the default reset type can be overridden through the relevant Kconfig choice.

doc/usage/cmd/reset.rst | 9 ++++++++-

 1 file changed, 8 insertions(+), 1 deletion(-)

doc/usage/cmd/reset.rst Description · line 23

Quoted 5 lines
doc/usage/cmd/reset.rst +2 -0
@@ -19,6 +19,13 @@ Description
 Perform reset of the CPU. By default does COLD reset, which resets CPU,
 DDR and peripherals, on some boards also resets external PMIC.
 
+The default behavior may be overridden via
+CONFIG_SYSRESET_CMD_RESET_DEFAULT_{COLD,WARM,POWER,POWER_OFF}.

The two sentences contradict each other - the line above says the default is always COLD, the new line says it can be anything. Please rework as 'the default is COLD reset unless overridden by ...'.

doc/usage/cmd/reset.rst Description · line 24

Quoted 8 lines
doc/usage/cmd/reset.rst +4 -0
@@ -19,6 +19,13 @@ Description
+-c
+    Do COLD reset: reset CPU and peripheral/DDR; on some boards also resets
+    external PMIC.
+
 -w
     Do warm WARM, reset CPU but keep peripheral/DDR/PMIC active.

While here, please fix the pre-existing 'Do warm WARM,' typo on -w and use a consistent form for both entries (e.g. 'Do WARM reset:' / 'Do COLD reset:'). The new -c text also duplicates the Description paragraph; a short 'Do COLD reset (same as the default when CONFIG_SYSRESET_CMD_RESET_DEFAULT_COLD=y)' would avoid the repetition.

doc/usage/cmd/reset.rst Synopsis · line 14

Quoted 7 lines
doc/usage/cmd/reset.rst +1 -1
@@ -11,7 +11,7 @@ Synopsis
 
 ::
 
-    reset [-w]
+    reset [-c|-w]

While here, -edl is documented further down but missing from the synopsis. Please list it too so the synopsis matches the option list.

Regards,
Simon

#14 lore raw

PATCH v3 6/6 tests: reset: add cold/warm reset types

In reply to [email protected]

From: Denis Mukhin <[email protected]>

Extend reset tests to cover both -c/-w reset command flags. Make sure sandbox reset tests are passing.

---
Changes since v2:
- dropped sandbox condig for pytests

Changes since v1:
- new patch

Test for sandbox:
./test/py/test.py --bd sandbox --build -k test_reset -v

---
 test/py/tests/test_reset.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
test/py/tests/test_reset.py +4 -4
index af079a706647..e1037c963f77 100644
@@ -52,12 +52,12 @@ def test_reset(ubman):
     test_000_version.test_version(ubman)
 
 @pytest.mark.buildconfigspec('hush_parser')
-def test_reset_w(ubman):
-    """Test the reset -w command in non-JTAG bootmode.
-    It does WARM reset, which resets CPU but keep DDR/peripherals active.
[email protected]("reset_type", ["c", "w"])
+def test_reset_type(ubman, reset_type):
+    """Test the reset -{c,w} command in non-JTAG bootmode.
     """
     setup_reset_env(ubman)
-    ubman.run_command('reset -w', wait_for_reboot=True)
+    ubman.run_command(f"reset -{reset_type}", wait_for_reboot=True)
 
     # Checks the u-boot command prompt's functionality after reset
     test_000_version.test_version(ubman)
Signature · 1 line
2.54.0
#15 lore raw

Re: [PATCH v3 6/6] tests: reset: add cold/warm reset types

Hi Denis,

Quoted 12 lines · None

tests: reset: add cold/warm reset types

Extend reset tests to cover both -c/-w reset command flags. Make sure sandbox reset tests are passing.

test/py/tests/test_reset.py | 8 ++++----

 1 file changed, 4 insertions(+), 4 deletions(-)

test/py/tests/test_reset.py def test_reset(ubman): · line 57

Quoted 7 lines
test/py/tests/test_reset.py +4 -1
@@ -52,12 +52,12 @@ def test_reset(ubman):
[email protected]('reset_type', ['c', 'w'])
+def test_reset_type(ubman, reset_type):
+    """Test the reset -{c,w} command in non-JTAG bootmode.
     """
     setup_reset_env(ubman)
-    ubman.run_command('reset -w', wait_for_reboot=True)
+    ubman.run_command(f"reset -{reset_type}", wait_for_reboot=True)

U-Boot uses single quotes throughout ('hush_parser', 'reset -w', etc.). Please keep that style - @pytest.mark.parametrize('reset_type', ['c', 'w']) and f'reset -{reset_type}'.

Regards,
Simon