Skip to contentSkip to conversation

arm: psci: save context id for cpu_on PSCI command

PATCH New Patrick Delaunay 4 participants 8 messages Apr 16, 2018 – May 8, 2018

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

PATCH v2 1/3 arm: psci: save context id for cpu_on PSCI command

Save and use the 3rd parameter of PSCI CPU_ON request: context_id.

The context_id parameter is only meaningful to the caller. U-Boot PSCI preserves a copy of the value passed in this parameter. Following wakeup from a powerdown state, U-BOOT PSCI places this value in R0 when it first enters the OS.

NB: this context id is not (yet?) used by Linux but it is mandatory
to be PSCI compliant.

update armv7 psci functions:
- psci_save_target_pc(): keep for backward compatibility with current platform (only save PC and force context id to 0) => should be removed when all platform migrate to the new API

- psci_save(): new API to use by ARMv7 platform with PSCI, save pc (= entry_point_address) and context_id

---

Changes in v2: None

 arch/arm/cpu/armv7/psci-common.c | 14 ++++++++++++++
 arch/arm/cpu/armv7/psci.S        |  4 ++++
 arch/arm/include/asm/psci.h      |  4 +++-
 3 files changed, 21 insertions(+), 1 deletion(-)
arch/arm/cpu/armv7/psci-common.c +14 -0
index 8cb4107..73f986b 100644
@@ -25,10 +25,19 @@
 #include <linux/linkage.h>
 
 static u32 psci_target_pc[CONFIG_ARMV7_PSCI_NR_CPUS] __secure_data = { 0 };
+static u32 psci_context_id[CONFIG_ARMV7_PSCI_NR_CPUS] __secure_data = { 0 };
 
 void __secure psci_save_target_pc(int cpu, u32 pc)
 {
 	psci_target_pc[cpu] = pc;
+	psci_context_id[cpu] = 0;
+	dsb();
+}
+
+void __secure psci_save(int cpu, u32 pc, u32 context_id)
+{
+	psci_target_pc[cpu] = pc;
+	psci_context_id[cpu] = context_id;
 	dsb();
 }
 
@@ -37,3 +46,8 @@ u32 __secure psci_get_target_pc(int cpu)
 	return psci_target_pc[cpu];
 }
 
+u32 __secure psci_get_context_id(int cpu)
+{
+	return psci_context_id[cpu];
+}
+
arch/arm/cpu/armv7/psci.S +4 -0
index 95b962d..35fd955 100644
@@ -327,6 +327,10 @@ ENTRY(psci_cpu_entry)
 	bl	_nonsec_init
 
 	bl	psci_get_cpu_id			@ CPU ID => r0
+	mov	r2, r0				@ CPU ID => r2
+	bl	psci_get_context_id		@ context id => r0
+	mov	r1, r0				@ context id => r1
+	mov	r0, r2				@ CPU ID => r0
 	bl	psci_get_target_pc		@ target PC => r0
 	b	_do_nonsec_entry
 ENDPROC(psci_cpu_entry)
arch/arm/include/asm/psci.h +3 -1
index ac8b00d..b415241 100644
@@ -93,9 +93,11 @@
 #ifndef __ASSEMBLY__
 #include <asm/types.h>
 
-/* These 2 helper functions assume cpu < CONFIG_ARMV7_PSCI_NR_CPUS */
+/* These 4 helper functions assume cpu < CONFIG_ARMV7_PSCI_NR_CPUS */
 u32 psci_get_target_pc(int cpu);
+u32 psci_get_context_id(int cpu);
 void psci_save_target_pc(int cpu, u32 pc);
+void psci_save(int cpu, u32 pc, u32 context_id);
 
 void psci_cpu_entry(void);
 u32 psci_get_cpu_id(void);
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 2/3 arm: psci: add a weak function psci_arch_cpu_entry

The added function psci_arch_cpu_entry() is called during psci_cpu_entry() and can be used by arch to handle PSCI state transition from ON_PENDING to ON.

The default weak function is empty: not behavior change.

---

Changes in v2: None

 arch/arm/cpu/armv7/psci.S | 7 +++++++
 1 file changed, 7 insertions(+)
arch/arm/cpu/armv7/psci.S +7 -0
index 35fd955..08b5088 100644
@@ -321,11 +321,18 @@ ENTRY(psci_arch_init)
 ENDPROC(psci_arch_init)
 .weak psci_arch_init
 
+ENTRY(psci_arch_cpu_entry)
+	mov	pc, lr
+ENDPROC(psci_arch_cpu_entry)
+.weak psci_arch_cpu_entry
+
 ENTRY(psci_cpu_entry)
 	bl	psci_enable_smp
 
 	bl	_nonsec_init
 
+	bl	psci_arch_cpu_entry
+
 	bl	psci_get_cpu_id			@ CPU ID => r0
 	mov	r2, r0				@ CPU ID => r2
 	bl	psci_get_context_id		@ context id => r0
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/3 arm: psci: add a weak function psci_arch_cpu_entry

Quoted 7 lines · Patrick Delaunay

The added function psci_arch_cpu_entry() is called during psci_cpu_entry() and can be used by arch to handle PSCI state transition from ON_PENDING to ON.

The default weak function is empty: not behavior change.

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: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180507/eba19659/attachment.sig>
#3 lore raw

PATCH v2 3/3 arm: stm32mp1: add PSCI support

In reply to Patrick Delaunay

Add PSCI v1.0 support for Linux and manage PSCI state for each CPU (affinity 0 level) with all mandatory functions:
- PSCI_VERSION
- CPU_SUSPEND
- CPU_OFF
- CPU_ON
- AFFINITY_INFO
- SYSTEM_OFF
- SYSTEM_RESET
- PSCI_FEATURES
and 1 optional to avoid Linux warning
- MIGRATE_INFO_TYPE

---
it is the v2 for http://patchwork.ozlabs.org/patch/888210

Linux boot and cpu1 hoot-plug is OK

[    0.000000] psci: probing for conduit method from DT.
[    0.000000] psci: PSCIv1.0 detected in firmware.
[    0.000000] psci: Using standard PSCI v0.2 function IDs
[    0.000000] psci: Trusted OS migration not required
.....
[    0.153066] smp: Bringing up secondary CPUs ...
[    0.203301] CPU1: thread -1, cpu 1, socket 0, mpidr 80000001
[    0.203467] smp: Brought up 1 node, 2 CPUs
[    0.213500] SMP: Total of 2 processors activated (96.00 BogoMIPS).
....
root at stm32mp1:~# echo 0 > /sys/devices/system/cpu/cpu1/online
[   76.498342] Retrying again to check for CPU kill
[   76.501500] CPU1 killed.

root at stm32mp1:~# cat /sys/devices/system/cpu/online 0
root at stm32mp1:~# echo 1 > /sys/devices/system/cpu/cpu1/online root at stm32mp1:~# cat /sys/devices/system/cpu/online 0-1

Changes in v2:
- major update after Mark Rutland review
- add missing mandatory functions (AFFINITY_INFO, SYSTEM_OFF)
- add optional MIGRATE_INFO_TYPE for avoid Linux warning
- manage PSCI states transition
- save and use context_id for CPU_ON
- manage errors for all function

 arch/arm/mach-stm32mp/Kconfig              |   3 +
 arch/arm/mach-stm32mp/Makefile             |   1 +
 arch/arm/mach-stm32mp/include/mach/stm32.h |   5 +
 arch/arm/mach-stm32mp/psci.c               | 181 +++++++++++++++++++++++++++++
 include/configs/stm32mp1.h                 |   5 +
 5 files changed, 195 insertions(+)
 create mode 100644 arch/arm/mach-stm32mp/psci.c
arch/arm/mach-stm32mp/Kconfig +3 -0
index 8c755f8..503bce1 100644
@@ -23,7 +23,10 @@ config SYS_SOC
 
 config TARGET_STM32MP1
 	bool "Support stm32mp1xx"
+	select ARCH_SUPPORT_PSCI
 	select CPU_V7
+	select CPU_V7_HAS_NONSEC
+	select CPU_V7_HAS_VIRT
 	select PINCTRL_STM32
 	select STM32_RESET
 	help
arch/arm/mach-stm32mp/Makefile +1 -0
index 4620869..9aac2da 100644
@@ -8,3 +8,4 @@ obj-y += cpu.o
 obj-y += dram_init.o
 
 obj-$(CONFIG_SPL_BUILD) += spl.o
+obj-$(CONFIG_ARMV7_PSCI) += psci.o
arch/arm/mach-stm32mp/include/mach/stm32.h +5 -0
index ffbe0b1..dd6f030 100644
@@ -24,4 +24,9 @@
 #define STM32_DDR_BASE			0xC0000000
 #define STM32_DDR_SIZE			SZ_1G
 
+/* TAMP registers */
+#define TAMP_BACKUP_REGISTER(x)		(STM32_TAMP_BASE + 0x100 + 4 * x)
+#define TAMP_BACKUP_MAGIC_NUMBER	TAMP_BACKUP_REGISTER(4)
+#define TAMP_BACKUP_BRANCH_ADDRESS	TAMP_BACKUP_REGISTER(5)
+
 #endif /* _MACH_STM32_H_ */
arch/arm/mach-stm32mp/psci.c new file +181 -0

181 lines not on this page · raw message

include/configs/stm32mp1.h +5 -0
index aae2cb8..b0aeb86 100644
@@ -20,6 +20,11 @@
 #define CONFIG_SYS_ARCH_TIMER
 #define CONFIG_SYS_HZ_CLOCK			64000000
 
+/* PSCI support */
+#define CONFIG_ARMV7_PSCI_1_0
+#define CONFIG_ARMV7_SECURE_BASE		STM32_SYSRAM_BASE
+#define CONFIG_ARMV7_SECURE_MAX_SIZE		STM32_SYSRAM_SIZE
+
 /*
  * malloc() pool size
  */
Signature · 1 line
2.7.4
#4 lore raw

PATCH v2 3/3 arm: stm32mp1: add PSCI support

Quoted 13 lines · Patrick Delaunay

Add PSCI v1.0 support for Linux and manage PSCI state for each CPU (affinity 0 level) with all mandatory functions:
- PSCI_VERSION
- CPU_SUSPEND
- CPU_OFF
- CPU_ON
- AFFINITY_INFO
- SYSTEM_OFF
- SYSTEM_RESET
- PSCI_FEATURES
and 1 optional to avoid Linux warning
- MIGRATE_INFO_TYPE

Quoted 2 lines

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: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180507/09ac1107/attachment.sig>
#5 lore raw

PATCH v2 1/3 arm: psci: save context id for cpu_on PSCI command

In reply to Patrick Delaunay
Quoted 10 lines · Patrick Delaunay

Save and use the 3rd parameter of PSCI CPU_ON request: context_id.

The context_id parameter is only meaningful to the caller. U-Boot PSCI preserves a copy of the value passed in this parameter. Following wakeup from a powerdown state, U-BOOT PSCI places this value in R0 when it first enters the OS.

NB: this context id is not (yet?) used by Linux but it is mandatory
to be PSCI compliant.

Quoted 7 lines

update armv7 psci functions:
- psci_save_target_pc(): keep for backward compatibility with current platform (only save PC and force context id to 0) => should be removed when all platform migrate to the new API

- psci_save(): new API to use by ARMv7 platform with PSCI, save pc (= entry_point_address) and context_id

#6 lore raw

PATCH v2 1/3 arm: psci: save context id for cpu_on PSCI command

In reply to Patrick Delaunay

2018-04-16 17:13 GMT+09:00 Patrick Delaunay <[email protected]>:

Quoted 15 lines

Save and use the 3rd parameter of PSCI CPU_ON request: context_id.

The context_id parameter is only meaningful to the caller. U-Boot PSCI preserves a copy of the value passed in this parameter. Following wakeup from a powerdown state, U-BOOT PSCI places this value in R0 when it first enters the OS.

NB: this context id is not (yet?) used by Linux but it is mandatory
to be PSCI compliant.

update armv7 psci functions:
- psci_save_target_pc(): keep for backward compatibility with current platform (only save PC and force context id to 0) => should be removed when all platform migrate to the new API

Quoted 7 lines

- psci_save(): new API to use by ARMv7 platform with PSCI, save pc (= entry_point_address) and context_id

---

Changes in v2: None

Signature · 2 lines
Best Regards
Masahiro Yamada
#7 lore raw

PATCH v2 1/3 arm: psci: save context id for cpu_on PSCI command

In reply to Patrick Delaunay
Quoted 15 lines · Patrick Delaunay

Save and use the 3rd parameter of PSCI CPU_ON request: context_id.

The context_id parameter is only meaningful to the caller. U-Boot PSCI preserves a copy of the value passed in this parameter. Following wakeup from a powerdown state, U-BOOT PSCI places this value in R0 when it first enters the OS.

NB: this context id is not (yet?) used by Linux but it is mandatory
to be PSCI compliant.

update armv7 psci functions:
- psci_save_target_pc(): keep for backward compatibility with current platform (only save PC and force context id to 0) => should be removed when all platform migrate to the new API

Quoted 6 lines

- psci_save(): new API to use by ARMv7 platform with PSCI, save pc (= entry_point_address) and context_id

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: 819 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180507/66362ce2/attachment.sig>