Skip to contentSkip to conversation

board: sl28: add basic PSCI implementation

PATCH New Michael Walle 1 participant 6 messages Feb 28, 2022 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

v2 cover board: sl28: add basic PSCI implementation

Add PSCI support to reset and power-off the board. Because this board can be used without TF-A, supply a (mandatory) PSCI implementation.

The armv8 u-boot part already contains most bits for the implementation, it is just, that it isn't compatible with the layerscape parts. Thus, we first need to clean that up and then we can add our three little functions for the PSCI support.

Changes since v1:
- mark psci_update_dt() as __weak
- rebase to latest master

Michael Walle (5):
armv8: include psci_update_dt() unconditionally
armv8: layerscape: get rid of smc_call()
armv8: psci: skip setup code if we are not EL3
armv8: psci: add ARMV8_PSCI_RELOCATE Kconfig option
board: sl28: add basic PSCI implementation

 arch/arm/cpu/armv8/Kconfig                | 30 +++++++++-----
 arch/arm/cpu/armv8/cpu-dt.c               |  9 +++--
 arch/arm/cpu/armv8/cpu.c                  |  3 ++
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  3 ++
 arch/arm/cpu/armv8/fsl-layerscape/cpu.c   | 49 +++++++++--------------
 arch/arm/cpu/armv8/fsl-layerscape/mp.c    | 11 ++---
 arch/arm/cpu/armv8/sec_firmware.c         | 19 ++++-----
 board/freescale/ls1043ardb/Kconfig        |  8 ----
 board/kontron/sl28/Makefile               |  2 +
 board/kontron/sl28/psci.c                 | 42 +++++++++++++++++++
 configs/kontron_sl28_defconfig            |  2 +
 11 files changed, 106 insertions(+), 72 deletions(-)
 create mode 100644 board/kontron/sl28/psci.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH v2 1/5 armv8: include psci_update_dt() unconditionally

psci_update_dt() is also required if CONFIG_ARMV8_PSCI is set, that is, if u-boot is the PSCI provider.
Guard the check which is intended to call into the PSCI implementation in the secure firmware, by the proper macro SEC_FIRMWARE_ARMV8_PSCI.

Mark the function as weak because - unfortunately - there is already a stub of the same function in arch/arm/mach-rmobile/psci-r8a779a0.c which does not the same as the common one.

---
 arch/arm/cpu/armv8/cpu-dt.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
arch/arm/cpu/armv8/cpu-dt.c +5 -4
index 61c38b17cb..9bfe3815e5 100644
@@ -8,9 +8,9 @@
 #include <asm/psci.h>
 #include <asm/system.h>
 #include <asm/armv8/sec_firmware.h>
+#include <linux/libfdt.h>
 
-#if CONFIG_IS_ENABLED(ARMV8_SEC_FIRMWARE_SUPPORT)
-int psci_update_dt(void *fdt)
+__weak int psci_update_dt(void *fdt)
 {
 	/*
 	 * If the PSCI in SEC Firmware didn't work, avoid to update the
@@ -18,8 +18,10 @@ int psci_update_dt(void *fdt)
 	 * number to support detecting PSCI dynamically and then switching
 	 * the SMP boot method between PSCI and spin-table.
 	 */
-	if (sec_firmware_support_psci_version() == PSCI_INVALID_VER)
+	if (CONFIG_IS_ENABLED(SEC_FIRMWARE_ARMV8_PSCI) &&
+	    sec_firmware_support_psci_version() == PSCI_INVALID_VER)
 		return 0;
+
 	fdt_psci(fdt);
 
 #if defined(CONFIG_ARMV8_PSCI) && !defined(CONFIG_ARMV8_SECURE_BASE)
@@ -30,4 +32,3 @@ int psci_update_dt(void *fdt)
 
 	return 0;
 }
-#endif
Signature · 1 line
2.30.2
#2 lore raw

PATCH v2 2/5 armv8: layerscape: get rid of smc_call()

In reply to Michael Walle

There are two different implementations to do a secure monitor call:
smc_call() and arm_smccc_smc(). The former is defined in fwcall.c and seems to be an ad-hoc implementation. The latter is imported from linux.

smc_call() is also only available if CONFIG_ARMV8_PSCI is not defined. This makes it impossible to have both PSCI calls and PSCI implementation in one u-boot build. The layerscape SoC code decide at runtime via check_psci() if there is a PSCI support. Therefore, this is a prerequisite patch to add PSCI implementation support for the layerscape SoCs.

Note, for the TFA part, this is only compile time tested with (ls1028ardb_tfa_defconfig).

---
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  1 +
 arch/arm/cpu/armv8/fsl-layerscape/cpu.c   | 49 +++++++++--------------
 arch/arm/cpu/armv8/fsl-layerscape/mp.c    | 11 ++---
 arch/arm/cpu/armv8/sec_firmware.c         | 19 ++++-----
 4 files changed, 31 insertions(+), 49 deletions(-)
arch/arm/cpu/armv8/fsl-layerscape/Kconfig +1 -0
index 9bb870dcd8..74a58e7f03 100644
@@ -335,6 +335,7 @@ menu "Layerscape architecture"
 
 config FSL_LAYERSCAPE
 	bool
+	select ARM_SMCCC
 
 config HAS_FEATURE_GIC64K_ALIGN
 	bool
arch/arm/cpu/armv8/fsl-layerscape/cpu.c +19 -30

107 lines not on this page · raw message

arch/arm/cpu/armv8/fsl-layerscape/mp.c +3 -8
index 2e2688eadc..7222119149 100644
@@ -302,6 +302,7 @@ int cpu_release(u32 nr, int argc, char *const argv[])
 	u64 boot_addr;
 	u64 *table = get_spin_tbl_addr();
 	int pos;
+	int ret;
 
 	boot_addr = simple_strtoull(argv[0], NULL, 16);
 
@@ -326,16 +327,10 @@ int cpu_release(u32 nr, int argc, char *const argv[])
 		asm volatile("sev");
 	} else {
 		/* Use PSCI to kick the core */
-		struct pt_regs regs;
-
 		printf("begin to kick cpu core #%d to address %llx\n",
 		       nr, boot_addr);
-		regs.regs[0] = PSCI_0_2_FN64_CPU_ON;
-		regs.regs[1] = nr;
-		regs.regs[2] = boot_addr;
-		regs.regs[3] = 0;
-		smc_call(&regs);
-		if (regs.regs[0])
+		ret = invoke_psci_fn(PSCI_0_2_FN64_CPU_ON, nr, boot_addr, 0);
+		if (ret)
 			return -1;
 	}
 
arch/arm/cpu/armv8/sec_firmware.c +8 -11
index e62e9dc380..d0ad6eeb0a 100644
@@ -13,6 +13,7 @@
 #include <asm/global_data.h>
 #include <asm/ptrace.h>
 #include <linux/kernel.h>
+#include <linux/arm-smccc.h>
 #include <asm/io.h>
 #include <asm/system.h>
 #include <asm/types.h>
@@ -374,29 +375,25 @@ bool sec_firmware_support_hwrng(void)
  */
 int sec_firmware_get_random(uint8_t *rand, int bytes)
 {
+	struct arm_smccc_res res;
 	unsigned long long num;
-	struct pt_regs regs;
 	int param1;
 
 	if (!bytes || bytes > 8) {
 		printf("Max Random bytes genration supported is 8\n");
 		return -1;
 	}
-#define SIP_RNG_64 0xC200FF11
-	regs.regs[0] = SIP_RNG_64;
-
 	if (bytes <= 4)
 		param1 = 0;
 	else
 		param1 = 1;
-	regs.regs[1] = param1;
-
-	smc_call(&regs);
 
-	if (regs.regs[0])
+#define SIP_RNG_64 0xC200FF11
+	arm_smccc_smc(SIP_RNG_64, param1, 0, 0, 0, 0, 0, 0, &res);
+	if (res.a0)
 		return -1;
 
-	num = regs.regs[1];
+	num = res.a1;
 	memcpy(rand, &num, bytes);
 
 	return 0;
@@ -473,8 +470,8 @@ int fdt_fixup_kaslr(void *fdt)
 		return 1;
 	}
 
-	ret = sec_firmware_get_random(rand, 8);
-	if (ret < 0) {
+	err = sec_firmware_get_random(rand, 8);
+	if (err < 0) {
 		printf("WARNING: No random number to set kaslr-seed\n");
 		return 1;
 	}
Signature · 1 line
2.30.2
#3 lore raw

PATCH v2 3/5 armv8: psci: skip setup code if we are not EL3

In reply to Michael Walle

If we are running in EL2 skip PSCI implementation setup. This avoids an exception if CONFIG_ARMV8_PSCI is set, but u-boot is started by TF-A.

---
 arch/arm/cpu/armv8/cpu.c | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/cpu/armv8/cpu.c +3 -0
index ea40c55dd2..db5d460eb4 100644
@@ -79,6 +79,9 @@ static void relocate_secure_section(void)
 
 void armv8_setup_psci(void)
 {
+	if (current_el() != 3)
+		return;
+
 	relocate_secure_section();
 	secure_ram_addr(psci_setup_vectors)();
 	secure_ram_addr(psci_arch_init)();
Signature · 1 line
2.30.2
#4 lore raw

PATCH v2 4/5 armv8: psci: add ARMV8_PSCI_RELOCATE Kconfig option

In reply to Michael Walle

There is an user-selectable SYS_HAS_ARMV8_SECURE_BASE, which has the same meaning but is just for the ls1043ardb board. As no in-tree config uses this, drop it and replace it with something more sophiticated:
ARMV8_PSCI_RELOCATE. This option will then enable the ARMV8_SECURE_BASE option which is used as the base to relocate the PSCI code (or any code in the secure region, but that is only PSCI). A SoC (or board) can now opt-in into having such a secure region by enabling SYS_HAS_ARMV8_SECURE_BASE. Enable it for the LS1043A SoC, where it was possible to relocate the PSCI code before as well as on the LS1028A SoC where there will be PSCI support soon.

Additionally, make ARMV8_PSCI and SEC_FIRMWARE_ARMV8_PSCI exclusive.

---
 arch/arm/cpu/armv8/Kconfig                | 30 ++++++++++++++---------
 arch/arm/cpu/armv8/fsl-layerscape/Kconfig |  2 ++
 board/freescale/ls1043ardb/Kconfig        |  8 ------
 3 files changed, 21 insertions(+), 19 deletions(-)
arch/arm/cpu/armv8/Kconfig +19 -11
index 9967376eca..a7741fadc1 100644
@@ -84,6 +84,7 @@ config SPL_RECOVER_DATA_SECTION
 config SEC_FIRMWARE_ARMV8_PSCI
 	bool "PSCI implementation in secure monitor firmware"
 	depends on ARMV8_SEC_FIRMWARE_SUPPORT || SPL_ARMV8_SEC_FIRMWARE_SUPPORT
+	depends on ARMV8_PSCI=n
 	help
 	  This config enables the ARMv8 PSCI implementation in secure monitor
 	  firmware. This is a private PSCI implementation and different from
@@ -125,6 +126,9 @@ config PSCI_RESET
 
 	  Select Y here to make use of PSCI calls for system reset
 
+config SYS_HAS_ARMV8_SECURE_BASE
+	bool
+
 config ARMV8_PSCI
 	bool "Enable PSCI support" if EXPERT
 	help
@@ -152,23 +156,27 @@ config ARMV8_PSCI_CPUS_PER_CLUSTER
 	  A value 0 or no definition of it works for single cluster system.
 	  System with multi-cluster should difine their own exact value.
 
-config ARMV8_EA_EL3_FIRST
-	bool "External aborts and SError interrupt exception are taken in EL3"
+config ARMV8_PSCI_RELOCATE
+	bool "Relocate PSCI code"
+	depends on ARMV8_PSCI
+	depends on SYS_HAS_ARMV8_SECURE_BASE
 	help
-	  Exception handling at all exception levels for External Abort and
-	  SError interrupt exception are taken in EL3.
-
-if SYS_HAS_ARMV8_SECURE_BASE
+	  Relocate PSCI code, for example to a secure memory on the SoC. If not
+	  set, the PSCI sections are placed together with the u-boot and the
+	  regions will be marked as reserved before linux is started.
 
 config ARMV8_SECURE_BASE
 	hex "Secure address for PSCI image"
-	depends on ARMV8_PSCI
+	depends on ARMV8_PSCI_RELOCATE
+	default 0x18000000 if ARCH_LS1028A
 	help
 	  Address for placing the PSCI text, data and stack sections.
-	  If not defined, the PSCI sections are placed together with the u-boot
-	  but platform can choose to place PSCI code image separately in other
-	  places such as some secure RAM built-in SOC etc.
 
-endif
+
+config ARMV8_EA_EL3_FIRST
+	bool "External aborts and SError interrupt exception are taken in EL3"
+	help
+	  Exception handling at all exception levels for External Abort and
+	  SError interrupt exception are taken in EL3.
 
 endif
arch/arm/cpu/armv8/fsl-layerscape/Kconfig +2 -0
index 74a58e7f03..80829620da 100644
@@ -55,6 +55,7 @@ config ARCH_LS1028A
 	select SYS_FSL_ERRATUM_A011334
 	select SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND
 	select RESV_RAM if GIC_V3_ITS
+	select SYS_HAS_ARMV8_SECURE_BASE
 	imply PANIC_HANG
 
 config ARCH_LS1043A
@@ -91,6 +92,7 @@ config ARCH_LS1043A
 	select SYS_I2C_MXC_I2C2 if !DM_I2C
 	select SYS_I2C_MXC_I2C3 if !DM_I2C
 	select SYS_I2C_MXC_I2C4 if !DM_I2C
+	select SYS_HAS_ARMV8_SECURE_BASE
 	imply CMD_PCI
 	imply ID_EEPROM
 
board/freescale/ls1043ardb/Kconfig +0 -8
index 778b8d8d5a..d66c7804b1 100644
@@ -13,14 +13,6 @@ config SYS_SOC
 config SYS_CONFIG_NAME
 	default "ls1043ardb"
 
-config SYS_HAS_ARMV8_SECURE_BASE
-	bool "Enable secure address for PSCI image"
-	depends on ARMV8_PSCI
-	help
-	  PSCI image can be re-located to secure RAM.
-	  If enabled, please also define the value for ARMV8_SECURE_BASE,
-	  for LS1043ARDB, it could be some address in OCRAM.
-
 if FSL_LS_PPA
 config SYS_LS_PPA_FW_ADDR
 	hex "PPA Firmware Addr"
Signature · 1 line
2.30.2
#5 lore raw

PATCH v2 5/5 board: sl28: add basic PSCI implementation

In reply to Michael Walle

For now, this only provides reset and poweroff functions.

---
 board/kontron/sl28/Makefile    |  2 ++
 board/kontron/sl28/psci.c      | 42 ++++++++++++++++++++++++++++++++++
 configs/kontron_sl28_defconfig |  2 ++
 3 files changed, 46 insertions(+)
 create mode 100644 board/kontron/sl28/psci.c
board/kontron/sl28/Makefile +2 -0
index 5d220f0744..084c11da37 100644
@@ -6,6 +6,8 @@ endif
 
 obj-y += common.o ddr.o
 
+obj-$(CONFIG_ARMV8_PSCI) += psci.o
+
 ifdef CONFIG_SPL_BUILD
 obj-y += spl.o
 obj-$(CONFIG_SPL_ATF) += spl_atf.o
board/kontron/sl28/psci.c new file +42 -0

42 lines not on this page · raw message

configs/kontron_sl28_defconfig +2 -0
index cf8aedfdfd..260d99af15 100644
@@ -19,6 +19,8 @@ CONFIG_ENV_OFFSET_REDUND=0x3f0000
 CONFIG_SPL_SPI_FLASH_SUPPORT=y
 CONFIG_SPL_SPI=y
 # CONFIG_PSCI_RESET is not set
+CONFIG_ARMV8_PSCI=y
+CONFIG_ARMV8_PSCI_RELOCATE=y
 CONFIG_AHCI=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_SYS_LOAD_ADDR=0x82000000
Signature · 1 line
2.30.2