diff mbox series

[boot-wrapper,v3,3/4] aarch64: Implement PSCI for Armv8-R

Message ID 20240731141103.2559706-4-luca.fancellu@arm.com (mailing list archive)
State New, archived
Headers show
Series Add Armv8-R AArch64 support | expand

Commit Message

Luca Fancellu July 31, 2024, 2:11 p.m. UTC
Armv8-R doesn't have EL3, so the PSCI vector needs to be
installed in VBAR_EL2 and the conduit needs to be 'hcv'
instead of 'smc'.

Implement the modifications needed when --with-bw-arch is
'aarch64-r'.

Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
---
Changes from v2:
 - Major rework, reason in the cover letter.
---
 Makefile.am         |  2 +-
 arch/aarch64/init.c | 14 +++++++++++---
 configure.ac        |  3 +++
 3 files changed, 15 insertions(+), 4 deletions(-)

Comments

Mark Rutland Oct. 11, 2024, 10:55 a.m. UTC | #1
On Wed, Jul 31, 2024 at 03:11:02PM +0100, Luca Fancellu wrote:
> Armv8-R doesn't have EL3, so the PSCI vector needs to be
> installed in VBAR_EL2 and the conduit needs to be 'hcv'
> instead of 'smc'.
> 
> Implement the modifications needed when --with-bw-arch is
> 'aarch64-r'.
> 
> Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
> ---
> Changes from v2:
>  - Major rework, reason in the cover letter.
> ---
>  Makefile.am         |  2 +-
>  arch/aarch64/init.c | 14 +++++++++++---
>  configure.ac        |  3 +++
>  3 files changed, 15 insertions(+), 4 deletions(-)
> 
> diff --git a/Makefile.am b/Makefile.am
> index bf97b989d5d7..62e2988c0dd3 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -57,7 +57,7 @@ ARCH_OBJ	+= psci.o
>  COMMON_OBJ	+= psci.o
>  PSCI_NODE	:= psci {				\
>  			compatible = \"arm,psci\";	\
> -			method = \"smc\";		\
> +			method = \"$(PSCI_METHOD)\";	\
>  			cpu_on = <$(PSCI_CPU_ON)>;	\
>  			cpu_off = <$(PSCI_CPU_OFF)>;	\
>  		   };
> diff --git a/arch/aarch64/init.c b/arch/aarch64/init.c
> index b0abde11ebd6..d8cf390dce20 100644
> --- a/arch/aarch64/init.c
> +++ b/arch/aarch64/init.c
> @@ -211,12 +211,20 @@ extern char psci_vectors[];
>  
>  static void cpu_init_psci_arch(unsigned int cpu)
>  {
> -	if (mrs(CurrentEL) != CURRENTEL_EL3) {
> +		switch (mrs(CurrentEL)) {
> +#if !defined(BOOTWRAPPER_64R)
> +	case CURRENTEL_EL3:
> +		msr(VBAR_EL3, (unsigned long)psci_vectors);
> +		break;
> +#else
> +	case CURRENTEL_EL2:
> +		msr(VBAR_EL2, (unsigned long)psci_vectors);
> +		break;
> +#endif
> +	default:
>  		print_cpu_warn(cpu, "PSCI could not be initialized (not booted at EL3).\r\n");
>  		return;
>  	}
> -
> -	msr(VBAR_EL3, (unsigned long)psci_vectors);
>  	isb();

As on the prior patch, I'd like to aovid hte ifdeffery here; can we make
this:

	if (!bootwrapper_is_r_class() && mrs(CurrentEL) == CURRENTEL_EL3) {
		msr(VBAR_EL3, (unsigned long)psci_vectors);
		isb();
		return;
	}

	if (bootwrapper_is_r_class() && mrs(CurrentEL) == CURRENTEL_EL2) {
		msr(VBAR_EL2, (unsigned long)psci_vectors);
		isb();
		return;
	}

	print_cpu_warn(cpu, "PSCI could not be initialized from this EL.\r\n");

Otherwise this looks good to me.

Mark.

>  }
>  #else
> diff --git a/configure.ac b/configure.ac
> index 88dbf9ba4f08..381f82612434 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -107,6 +107,9 @@ AC_ARG_ENABLE([psci],
>  	[USE_PSCI=$enableval], [USE_PSCI="yes"])
>  AM_CONDITIONAL([PSCI], [test "x$USE_PSCI" = "xyes"])
>  AS_IF([test "x$USE_PSCI" = "xyes"], [], [USE_PSCI=no])
> +AS_IF([test "x$USE_ARCH" = "xaarch64-r"],
> +	AC_SUBST([PSCI_METHOD], [hvc]), AC_SUBST([PSCI_METHOD], [smc])
> +)
>  
>  AS_IF([test "x$USE_PSCI" != "xyes" -a "x$KERNEL_ES" = "x32"],
>  	[AC_MSG_ERROR([With an AArch32 kernel, boot method must be PSCI.])]
> -- 
> 2.34.1
>
diff mbox series

Patch

diff --git a/Makefile.am b/Makefile.am
index bf97b989d5d7..62e2988c0dd3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -57,7 +57,7 @@  ARCH_OBJ	+= psci.o
 COMMON_OBJ	+= psci.o
 PSCI_NODE	:= psci {				\
 			compatible = \"arm,psci\";	\
-			method = \"smc\";		\
+			method = \"$(PSCI_METHOD)\";	\
 			cpu_on = <$(PSCI_CPU_ON)>;	\
 			cpu_off = <$(PSCI_CPU_OFF)>;	\
 		   };
diff --git a/arch/aarch64/init.c b/arch/aarch64/init.c
index b0abde11ebd6..d8cf390dce20 100644
--- a/arch/aarch64/init.c
+++ b/arch/aarch64/init.c
@@ -211,12 +211,20 @@  extern char psci_vectors[];
 
 static void cpu_init_psci_arch(unsigned int cpu)
 {
-	if (mrs(CurrentEL) != CURRENTEL_EL3) {
+		switch (mrs(CurrentEL)) {
+#if !defined(BOOTWRAPPER_64R)
+	case CURRENTEL_EL3:
+		msr(VBAR_EL3, (unsigned long)psci_vectors);
+		break;
+#else
+	case CURRENTEL_EL2:
+		msr(VBAR_EL2, (unsigned long)psci_vectors);
+		break;
+#endif
+	default:
 		print_cpu_warn(cpu, "PSCI could not be initialized (not booted at EL3).\r\n");
 		return;
 	}
-
-	msr(VBAR_EL3, (unsigned long)psci_vectors);
 	isb();
 }
 #else
diff --git a/configure.ac b/configure.ac
index 88dbf9ba4f08..381f82612434 100644
--- a/configure.ac
+++ b/configure.ac
@@ -107,6 +107,9 @@  AC_ARG_ENABLE([psci],
 	[USE_PSCI=$enableval], [USE_PSCI="yes"])
 AM_CONDITIONAL([PSCI], [test "x$USE_PSCI" = "xyes"])
 AS_IF([test "x$USE_PSCI" = "xyes"], [], [USE_PSCI=no])
+AS_IF([test "x$USE_ARCH" = "xaarch64-r"],
+	AC_SUBST([PSCI_METHOD], [hvc]), AC_SUBST([PSCI_METHOD], [smc])
+)
 
 AS_IF([test "x$USE_PSCI" != "xyes" -a "x$KERNEL_ES" = "x32"],
 	[AC_MSG_ERROR([With an AArch32 kernel, boot method must be PSCI.])]