Skip to contentSkip to conversation

psci: add support for SYSTEM_RESET2 and PSCI_FEATURES

PATCH New Igor Opaniuk 3 participants 12 messages Mar 31, 2021 – May 5, 2021 Power state coordination interface (psci)

lore
Share & tools
lore
#0 lore raw

v4 cover psci: add support for SYSTEM_RESET2 and PSCI_FEATURES

From: Igor Opaniuk <[email protected]>

1. Adds support for:
* PSCI_FEATURES, introduced in PSCI 1.0. This provides API that allows discovering whether a specific PSCI function is implemented and its features.
* SYSTEM_RESET2, introduced in PSCI 1.1, which extends existing SYSTEM_RESET. It provides support for vendor-specific resets, providing reset_type as an additional param.

2. PSCI sysreset driver is refactored to use new API.
3. do_reset cmd is extended, optional param added for providing type of reset

CI: https://dev.azure.com/igoropaniuk/u-boot/_build/results?buildId=23&view=results

Changes in v4:
- Fix htmldoc build issue

Changes in v3:
- Drop RFC tag
- Add usage doc for reset cmd
- Reimplement param handling for reset cmd
- Droped updates in reset usage string

Changes in v2:
- do_reset cmd updates

Igor Opaniuk (5):
psci: add v1.0/v1.1 definitions from Linux
psci: add features/reset2 support
sysreset: psci: use psci driver exported functions
sysreset: provide type of reset in do_reset cmd
doc: usage: add usage details for reset cmd

 cmd/boot.c                         |  2 +-
 doc/usage/index.rst                |  1 +
 doc/usage/reset.rst                | 26 ++++++++++++
 drivers/firmware/psci.c            | 68 ++++++++++++++++++++++++++++++
 drivers/sysreset/sysreset-uclass.c | 11 ++++-
 drivers/sysreset/sysreset_psci.c   |  8 +---
 include/linux/psci.h               | 31 ++++++++++++++
 7 files changed, 139 insertions(+), 8 deletions(-)
 create mode 100644 doc/usage/reset.rst
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 1/5 psci: add v1.0/v1.1 definitions from Linux

From: Igor Opaniuk <[email protected]>

Sync and add PSCI API versions 1.0/1.1 definitions from Linux.

---

 include/linux/psci.h | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
include/linux/psci.h +28 -0
index 841dbc8da7..38edde3137 100644
@@ -46,6 +46,14 @@
 #define PSCI_0_2_FN64_MIGRATE			PSCI_0_2_FN64(5)
 #define PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU	PSCI_0_2_FN64(7)
 
+#define PSCI_1_0_FN_PSCI_FEATURES		PSCI_0_2_FN(10)
+#define PSCI_1_0_FN_SYSTEM_SUSPEND		PSCI_0_2_FN(14)
+#define PSCI_1_0_FN_SET_SUSPEND_MODE		PSCI_0_2_FN(15)
+#define PSCI_1_1_FN_SYSTEM_RESET2		PSCI_0_2_FN(18)
+
+#define PSCI_1_0_FN64_SYSTEM_SUSPEND		PSCI_0_2_FN64(14)
+#define PSCI_1_1_FN64_SYSTEM_RESET2		PSCI_0_2_FN64(18)
+
 /* PSCI v0.2 power state encoding for CPU_SUSPEND function */
 #define PSCI_0_2_POWER_STATE_ID_MASK		0xffff
 #define PSCI_0_2_POWER_STATE_ID_SHIFT		0
@@ -56,6 +64,13 @@
 #define PSCI_0_2_POWER_STATE_AFFL_MASK		\
 				(0x3 << PSCI_0_2_POWER_STATE_AFFL_SHIFT)
 
+/* PSCI extended power state encoding for CPU_SUSPEND function */
+#define PSCI_1_0_EXT_POWER_STATE_ID_MASK	0xfffffff
+#define PSCI_1_0_EXT_POWER_STATE_ID_SHIFT	0
+#define PSCI_1_0_EXT_POWER_STATE_TYPE_SHIFT	30
+#define PSCI_1_0_EXT_POWER_STATE_TYPE_MASK	\
+				(0x1 << PSCI_1_0_EXT_POWER_STATE_TYPE_SHIFT)
+
 /* PSCI v0.2 affinity level state returned by AFFINITY_INFO */
 #define PSCI_0_2_AFFINITY_LEVEL_ON		0
 #define PSCI_0_2_AFFINITY_LEVEL_OFF		1
@@ -75,6 +90,18 @@
 		(((ver) & PSCI_VERSION_MAJOR_MASK) >> PSCI_VERSION_MAJOR_SHIFT)
 #define PSCI_VERSION_MINOR(ver)			\
 		((ver) & PSCI_VERSION_MINOR_MASK)
+#define PSCI_VERSION(maj, min)						\
+	((((maj) << PSCI_VERSION_MAJOR_SHIFT) & PSCI_VERSION_MAJOR_MASK) | \
+	 ((min) & PSCI_VERSION_MINOR_MASK))
+
+/* PSCI features decoding (>=1.0) */
+#define PSCI_1_0_FEATURES_CPU_SUSPEND_PF_SHIFT	1
+#define PSCI_1_0_FEATURES_CPU_SUSPEND_PF_MASK	\
+			(0x1 << PSCI_1_0_FEATURES_CPU_SUSPEND_PF_SHIFT)
+
+#define PSCI_1_0_OS_INITIATED			BIT(0)
+#define PSCI_1_0_SUSPEND_MODE_PC		0
+#define PSCI_1_0_SUSPEND_MODE_OSI		1
 
 /* PSCI return values (inclusive of all PSCI versions) */
 #define PSCI_RET_SUCCESS			0
@@ -86,6 +113,7 @@
 #define PSCI_RET_INTERNAL_FAILURE		-6
 #define PSCI_RET_NOT_PRESENT			-7
 #define PSCI_RET_DISABLED			-8
+#define PSCI_RET_INVALID_ADDRESS		-9
 
 #ifdef CONFIG_ARM_PSCI_FW
 unsigned long invoke_psci_fn(unsigned long a0, unsigned long a1,
Signature · 1 line
2.25.1
#2 lore raw

PATCH v4 1/5 psci: add v1.0/v1.1 definitions from Linux

Quoted 5 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Sync and add PSCI API versions 1.0/1.1 definitions from Linux.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210420/220637dc/attachment.sig>
#3 lore raw

PATCH v4 2/5 psci: add features/reset2 support

In reply to Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Adds support for:
* PSCI_FEATURES, which was introduced in PSCI 1.0. This provides API that allows discovering whether a specific PSCI function is implemented and its features.
* SYSTEM_RESET2, which was introduced in PSCI 1.1, which extends existing SYSTEM_RESET. It provides support for vendor-specific resets, providing reset_type as an additional param.

For additional details visit [1].

Implementations of some functions were borrowed from Linux PSCI driver code [2].

[1] https://developer.arm.com/documentation/den0022/latest/
[2] drivers/firmware/psci/psci.c

---

 drivers/firmware/psci.c | 68 +++++++++++++++++++++++++++++++++++++++++
 include/linux/psci.h    |  3 ++
 2 files changed, 71 insertions(+)
drivers/firmware/psci.c +68 -0
index 68953cc4f4..be57552aba 100644
@@ -13,6 +13,7 @@
 #include <log.h>
 #include <dm/lists.h>
 #include <efi_loader.h>
+#include <sysreset.h>
 #include <linux/delay.h>
 #include <linux/libfdt.h>
 #include <linux/arm-smccc.h>
@@ -26,6 +27,18 @@
 #define PSCI_METHOD_HVC 1
 #define PSCI_METHOD_SMC 2
 
+/*
+ * While a 64-bit OS can make calls with SMC32 calling conventions, for some
+ * calls it is necessary to use SMC64 to pass or return 64-bit values.
+ * For such calls PSCI_FN_NATIVE(version, name) will choose the appropriate
+ * (native-width) function ID.
+ */
+#if defined(CONFIG_ARM64)
+#define PSCI_FN_NATIVE(version, name)	PSCI_##version##_FN64_##name
+#else
+#define PSCI_FN_NATIVE(version, name)	PSCI_##version##_FN_##name
+#endif
+
 #if CONFIG_IS_ENABLED(EFI_LOADER)
 int __efi_runtime_data psci_method;
 #else
@@ -53,6 +66,34 @@ unsigned long __efi_runtime invoke_psci_fn
 	return res.a0;
 }
 
+static int psci_features(u32 psci_func_id)
+{
+	return invoke_psci_fn(PSCI_1_0_FN_PSCI_FEATURES,
+			      psci_func_id, 0, 0);
+}
+
+static u32 psci_0_2_get_version(void)
+{
+	return invoke_psci_fn(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0);
+}
+
+static bool psci_is_system_reset2_supported(void)
+{
+	int ret;
+	u32 ver;
+
+	ver = psci_0_2_get_version();
+
+	if (PSCI_VERSION_MAJOR(ver) >= 1) {
+		ret = psci_features(PSCI_FN_NATIVE(1_1, SYSTEM_RESET2));
+
+		if (ret != PSCI_RET_NOT_SUPPORTED)
+			return true;
+	}
+
+	return false;
+}
+
 static int psci_bind(struct udevice *dev)
 {
 	/* No SYSTEM_RESET support for PSCI 0.1 */
@@ -141,6 +182,33 @@ void reset_misc(void)
 }
 #endif /* CONFIG_PSCI_RESET */
 
+void psci_sys_reset(u32 type)
+{
+	bool reset2_supported;
+
+	do_psci_probe();
+
+	reset2_supported = psci_is_system_reset2_supported();
+
+	if (type == SYSRESET_WARM && reset2_supported) {
+		/*
+		 * reset_type[31] = 0 (architectural)
+		 * reset_type[30:0] = 0 (SYSTEM_WARM_RESET)
+		 * cookie = 0 (ignored by the implementation)
+		 */
+		invoke_psci_fn(PSCI_FN_NATIVE(1_1, SYSTEM_RESET2), 0, 0, 0);
+	} else {
+		invoke_psci_fn(PSCI_0_2_FN_SYSTEM_RESET, 0, 0, 0);
+	}
+}
+
+void psci_sys_poweroff(void)
+{
+	do_psci_probe();
+
+	invoke_psci_fn(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
+}
+
 #ifdef CONFIG_CMD_POWEROFF
 int do_poweroff(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
include/linux/psci.h +3 -0
index 38edde3137..c78c1079a8 100644
@@ -118,6 +118,9 @@
 #ifdef CONFIG_ARM_PSCI_FW
 unsigned long invoke_psci_fn(unsigned long a0, unsigned long a1,
 			     unsigned long a2, unsigned long a3);
+void psci_sys_reset(u32 type);
+void psci_sys_poweroff(void);
+
 #else
 static inline unsigned long invoke_psci_fn(unsigned long a0, unsigned long a1,
 					   unsigned long a2, unsigned long a3)
Signature · 1 line
2.25.1
#4 lore raw

PATCH v4 2/5 psci: add features/reset2 support

Quoted 12 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Adds support for:
* PSCI_FEATURES, which was introduced in PSCI 1.0. This provides API that allows discovering whether a specific PSCI function is implemented and its features.
* SYSTEM_RESET2, which was introduced in PSCI 1.1, which extends existing SYSTEM_RESET. It provides support for vendor-specific resets, providing reset_type as an additional param.

For additional details visit [1].

Quoted 7 lines

Implementations of some functions were borrowed from Linux PSCI driver code [2].

[1] https://developer.arm.com/documentation/den0022/latest/
[2] drivers/firmware/psci/psci.c

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210420/b5b4146b/attachment.sig>
#5 lore raw

PATCH v4 2/5 psci: add features/reset2 support

Quoted 17 lines · Tom Rini
Quoted 15 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Adds support for:
* PSCI_FEATURES, which was introduced in PSCI 1.0. This provides API that allows discovering whether a specific PSCI function is implemented and its features.
* SYSTEM_RESET2, which was introduced in PSCI 1.1, which extends existing SYSTEM_RESET. It provides support for vendor-specific resets, providing reset_type as an additional param.

For additional details visit [1].

Implementations of some functions were borrowed from Linux PSCI driver code [2].

Quoted 6 lines
Quoted 4 lines

[1] https://developer.arm.com/documentation/den0022/latest/
[2] drivers/firmware/psci/psci.c

Applied to u-boot/master, thanks!

I'm seeing a build failure on stm32mp1 from this patch:

drivers/firmware/psci.c:69:12: error: conflicting types for 'psci_features'
69 | static int psci_features(u32 psci_func_id)
| ^~~~~~~~~~~~~
In file included from drivers/firmware/psci.c:23:
./arch/arm/include/asm/system.h:548:5: note: previous declaration of 'psci_features' was here

   548 | s32 psci_features(u32 function_id, u32 psci_fid);
       |     ^~~~~~~~~~~~~

make[2]: *** [scripts/Makefile.build:266: drivers/firmware/psci.o] Error 1 make[1]: *** [scripts/Makefile.build:419: drivers/firmware] Error 2

#6 lore raw

PATCH v4 3/5 sysreset: psci: use psci driver exported functions

In reply to Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Use psci driver exported functions for reset/poweroff, instead of invoking directly invoke_psci_fn.

---

 drivers/sysreset/sysreset_psci.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/sysreset/sysreset_psci.c +2 -6
index c7907b3226..83ecbcb9d2 100644
@@ -11,22 +11,18 @@
 
 static int psci_sysreset_request(struct udevice *dev, enum sysreset_t type)
 {
-	unsigned long function_id;
-
 	switch (type) {
 	case SYSRESET_WARM:
 	case SYSRESET_COLD:
-		function_id = PSCI_0_2_FN_SYSTEM_RESET;
+		psci_sys_reset(type);
 		break;
 	case SYSRESET_POWER_OFF:
-		function_id = PSCI_0_2_FN_SYSTEM_OFF;
+		psci_sys_poweroff();
 		break;
 	default:
 		return -ENOSYS;
 	}
 
-	invoke_psci_fn(function_id, 0, 0, 0);
-
 	return -EINPROGRESS;
 }
 
Signature · 1 line
2.25.1
#7 lore raw

PATCH v4 3/5 sysreset: psci: use psci driver exported functions

Quoted 6 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Use psci driver exported functions for reset/poweroff, instead of invoking directly invoke_psci_fn.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210420/c38b1ca4/attachment.sig>
#8 lore raw

PATCH v4 4/5 sysreset: provide type of reset in do_reset cmd

In reply to Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Add additional param for reset cmd, which provides type of reset.

---

 cmd/boot.c                         |  2 +-
 drivers/sysreset/sysreset-uclass.c | 11 ++++++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)
cmd/boot.c +1 -1
index 36aba22b30..b84c0ed89e 100644
@@ -56,7 +56,7 @@ U_BOOT_CMD(
 #endif
 
 U_BOOT_CMD(
-	reset, 1, 0,	do_reset,
+	reset, 2, 0,	do_reset,
 	"Perform RESET of the CPU",
 	""
 );
drivers/sysreset/sysreset-uclass.c +10 -1
index 6c9dc7a384..0412c4a29b 100644
@@ -122,10 +122,19 @@ void reset_cpu(ulong addr)
 #if IS_ENABLED(CONFIG_SYSRESET_CMD_RESET)
 int do_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 {
+	enum sysreset_t reset_type = SYSRESET_COLD;
+
+	if (argc > 2)
+		return CMD_RET_USAGE;
+
+	if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'w') {
+		reset_type = SYSRESET_WARM;
+	}
+
 	printf("resetting ...\n");
 	mdelay(100);
 
-	sysreset_walk_halt(SYSRESET_COLD);
+	sysreset_walk_halt(reset_type);
 
 	return 0;
 }
Signature · 1 line
2.25.1
#9 lore raw

PATCH v4 4/5 sysreset: provide type of reset in do_reset cmd

Quoted 5 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Add additional param for reset cmd, which provides type of reset.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210420/eb76d443/attachment.sig>
#10 lore raw

PATCH v4 5/5 doc: usage: add usage details for reset cmd

In reply to Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Add usage details for reset command.

---

 doc/usage/index.rst |  1 +
 doc/usage/reset.rst | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 doc/usage/reset.rst
doc/usage/index.rst +1 -0
index 6c59bbadab..b1181011ae 100644
@@ -34,3 +34,4 @@ Shell commands
    qfw
    sbi
    true
+   reset
doc/usage/reset.rst new file +26 -0
new file mode 100644
index 0000000000..384d5d60f8
@@ -0,0 +1,26 @@
+.. SPDX-License-Identifier: GPL-2.0+
+
+reset command
+=============
+
+Synopsis
+--------
+
+::
+
+    reset [-w]
+
+Description
+-----------
+
+Perform reset of the CPU. By default does COLD reset, which resets CPU,
+DDR and peripherals, on some boards also resets external PMIC.
+
+-w
+    Do warm WARM, reset CPU but keep peripheral/DDR/PMIC active.
+
+
+Return value
+------------
+
+The return value $? is always set to 0 (true).
Signature · 1 line
2.25.1
#11 lore raw

PATCH v4 5/5 doc: usage: add usage details for reset cmd

Quoted 5 lines · Igor Opaniuk

From: Igor Opaniuk <[email protected]>

Add usage details for reset command.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210420/565ad7af/attachment.sig>