diff mbox series

[edk2] ArmPkg/ArmSmcPsciResetSystemLib: add support for warm reboot

Message ID 20171006204152.19376-1-ard.biesheuvel@linaro.org
State New
Headers show
Series [edk2] ArmPkg/ArmSmcPsciResetSystemLib: add support for warm reboot | expand

Commit Message

Ard Biesheuvel Oct. 6, 2017, 8:41 p.m. UTC
PSCI SYSTEM_RESET is specified as a cold reboot, which does not
preserve the contents of DRAM. In version 1.1, a new reset method
was introduced that allows a warm reboot to be requested.

This is especially relevant for capsule update, given that it will
invoke a warm reboot before processing the capsule, under the
assumption that the capsule will still be in memory when the PEI
phase is reentered.

So wire up the [rather inaccurately named] EnterS3WithImmediateWake()
entry point that the capsule update runtime uses to the new PSCI 1.1
warm reboot. Note that many PSCI implementations will not support this
yet, so fall back to a cold reboot if warm reboot fails.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---

I don't actually need this code for Synquacer, but given that I had
already wrote it, we may just as well merge it.

 ArmPkg/Include/IndustryStandard/ArmStdSmc.h                        | 10 +++++++---
 ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c | 14 ++++++++++++--
 2 files changed, 19 insertions(+), 5 deletions(-)

-- 
2.11.0

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Leif Lindholm Oct. 9, 2017, 6:22 p.m. UTC | #1
On Fri, Oct 06, 2017 at 09:41:52PM +0100, Ard Biesheuvel wrote:
> PSCI SYSTEM_RESET is specified as a cold reboot, which does not

> preserve the contents of DRAM. In version 1.1, a new reset method

> was introduced that allows a warm reboot to be requested.

> 

> This is especially relevant for capsule update, given that it will

> invoke a warm reboot before processing the capsule, under the

> assumption that the capsule will still be in memory when the PEI

> phase is reentered.

> 

> So wire up the [rather inaccurately named] EnterS3WithImmediateWake()

> entry point that the capsule update runtime uses to the new PSCI 1.1

> warm reboot. Note that many PSCI implementations will not support this

> yet, so fall back to a cold reboot if warm reboot fails.

> 

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> ---

> 

> I don't actually need this code for Synquacer, but given that I had

> already wrote it, we may just as well merge it.

> 

>  ArmPkg/Include/IndustryStandard/ArmStdSmc.h                        | 10 +++++++---

>  ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c | 14 ++++++++++++--

>  2 files changed, 19 insertions(+), 5 deletions(-)

> 

> diff --git a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h

> index 593a3ce729ce..41b086947eaa 100644

> --- a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h

> +++ b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h

> @@ -57,10 +57,12 @@

>  #define ARM_SMC_ID_PSCI_MIGRATE_AARCH32        0x84000005

>  #define ARM_SMC_ID_PSCI_SYSTEM_OFF             0x84000008

>  #define ARM_SMC_ID_PSCI_SYSTEM_RESET           0x84000009

> +#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64  0xc4000012

> +#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH32  0x84000012


If we're starting to add more of these, could we do some macro rather
than duplication?

(see below)

> -/* The current PSCI version is:  0.2 */

> -#define ARM_SMC_PSCI_VERSION_MAJOR  0

> -#define ARM_SMC_PSCI_VERSION_MINOR  2

> +/* The current PSCI version is:  1.1 */

> +#define ARM_SMC_PSCI_VERSION_MAJOR  1

> +#define ARM_SMC_PSCI_VERSION_MINOR  1

>  #define ARM_SMC_PSCI_VERSION  \

>    ((ARM_SMC_PSCI_VERSION_MAJOR << 16) | ARM_SMC_PSCI_VERSION_MINOR)

>  

> @@ -93,4 +95,6 @@

>  #define ARM_SMC_ID_PSCI_AFFINITY_INFO_OFF         1

>  #define ARM_SMC_ID_PSCI_AFFINITY_INFO_ON_PENDING  2

>  

> +#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_WARM  0

> +

>  #endif

> diff --git a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c

> index d6d26bce5009..ffd726554c0f 100644

> --- a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c

> +++ b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c

> @@ -55,7 +55,17 @@ ResetWarm (

>    VOID

>    )

>  {

> -  // Map a warm reset into a cold reset

> +  ARM_SMC_ARGS ArmSmcArgs;

> +

> +#if defined(MDE_CPU_AARCH64)

> +  ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64;

> +#else

> +  ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH32;

> +#endif


#define ARM_SMC64_VALUE 0x40000000UL
#define ARM_SMC64(x) ((x) | ARM_SMC64_VALUE)
#define ARM_SMC32(x) ((x) & ~ARM_SMC64_VALUE)

#if defined(MDE_CPU_AARCH64)
#define ARM_SMC(x) ARM_SMC64(x)
#else
#define ARM_SMC(x) ARM_SMC32(x)
#endif

Want me to whip up a mini-set that does that and changes existing
definitiions/invokations?

/
    Leif

> +  ArmSmcArgs.Arg1 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_WARM;

> +  ArmCallSmc (&ArmSmcArgs);

> +

> +  // Fall back to cold reset if unsupported

>    ResetCold ();

>  }

>  

> @@ -89,7 +99,7 @@ EnterS3WithImmediateWake (

>    VOID

>    )

>  {

> -  // Not implemented

> +  ResetWarm ();

>  }

>  

>  /**

> -- 

> 2.11.0

> 

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Ard Biesheuvel Oct. 9, 2017, 6:22 p.m. UTC | #2
On 9 October 2017 at 19:22, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> On Fri, Oct 06, 2017 at 09:41:52PM +0100, Ard Biesheuvel wrote:

>> PSCI SYSTEM_RESET is specified as a cold reboot, which does not

>> preserve the contents of DRAM. In version 1.1, a new reset method

>> was introduced that allows a warm reboot to be requested.

>>

>> This is especially relevant for capsule update, given that it will

>> invoke a warm reboot before processing the capsule, under the

>> assumption that the capsule will still be in memory when the PEI

>> phase is reentered.

>>

>> So wire up the [rather inaccurately named] EnterS3WithImmediateWake()

>> entry point that the capsule update runtime uses to the new PSCI 1.1

>> warm reboot. Note that many PSCI implementations will not support this

>> yet, so fall back to a cold reboot if warm reboot fails.

>>

>> Contributed-under: TianoCore Contribution Agreement 1.1

>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>> ---

>>

>> I don't actually need this code for Synquacer, but given that I had

>> already wrote it, we may just as well merge it.

>>

>>  ArmPkg/Include/IndustryStandard/ArmStdSmc.h                        | 10 +++++++---

>>  ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c | 14 ++++++++++++--

>>  2 files changed, 19 insertions(+), 5 deletions(-)

>>

>> diff --git a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h

>> index 593a3ce729ce..41b086947eaa 100644

>> --- a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h

>> +++ b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h

>> @@ -57,10 +57,12 @@

>>  #define ARM_SMC_ID_PSCI_MIGRATE_AARCH32        0x84000005

>>  #define ARM_SMC_ID_PSCI_SYSTEM_OFF             0x84000008

>>  #define ARM_SMC_ID_PSCI_SYSTEM_RESET           0x84000009

>> +#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64  0xc4000012

>> +#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH32  0x84000012

>

> If we're starting to add more of these, could we do some macro rather

> than duplication?

>

> (see below)

>

>> -/* The current PSCI version is:  0.2 */

>> -#define ARM_SMC_PSCI_VERSION_MAJOR  0

>> -#define ARM_SMC_PSCI_VERSION_MINOR  2

>> +/* The current PSCI version is:  1.1 */

>> +#define ARM_SMC_PSCI_VERSION_MAJOR  1

>> +#define ARM_SMC_PSCI_VERSION_MINOR  1

>>  #define ARM_SMC_PSCI_VERSION  \

>>    ((ARM_SMC_PSCI_VERSION_MAJOR << 16) | ARM_SMC_PSCI_VERSION_MINOR)

>>

>> @@ -93,4 +95,6 @@

>>  #define ARM_SMC_ID_PSCI_AFFINITY_INFO_OFF         1

>>  #define ARM_SMC_ID_PSCI_AFFINITY_INFO_ON_PENDING  2

>>

>> +#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_WARM  0

>> +

>>  #endif

>> diff --git a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c

>> index d6d26bce5009..ffd726554c0f 100644

>> --- a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c

>> +++ b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c

>> @@ -55,7 +55,17 @@ ResetWarm (

>>    VOID

>>    )

>>  {

>> -  // Map a warm reset into a cold reset

>> +  ARM_SMC_ARGS ArmSmcArgs;

>> +

>> +#if defined(MDE_CPU_AARCH64)

>> +  ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64;

>> +#else

>> +  ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH32;

>> +#endif

>

> #define ARM_SMC64_VALUE 0x40000000UL

> #define ARM_SMC64(x) ((x) | ARM_SMC64_VALUE)

> #define ARM_SMC32(x) ((x) & ~ARM_SMC64_VALUE)

>

> #if defined(MDE_CPU_AARCH64)

> #define ARM_SMC(x) ARM_SMC64(x)

> #else

> #define ARM_SMC(x) ARM_SMC32(x)

> #endif

>

> Want me to whip up a mini-set that does that and changes existing

> definitiions/invokations?

>


Yes please
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Leif Lindholm Dec. 14, 2017, 3:49 p.m. UTC | #3
On Fri, Oct 06, 2017 at 09:41:52PM +0100, Ard Biesheuvel wrote:
> PSCI SYSTEM_RESET is specified as a cold reboot, which does not

> preserve the contents of DRAM. In version 1.1, a new reset method

> was introduced that allows a warm reboot to be requested.

> 

> This is especially relevant for capsule update, given that it will

> invoke a warm reboot before processing the capsule, under the

> assumption that the capsule will still be in memory when the PEI

> phase is reentered.

> 

> So wire up the [rather inaccurately named] EnterS3WithImmediateWake()

> entry point that the capsule update runtime uses to the new PSCI 1.1

> warm reboot. Note that many PSCI implementations will not support this

> yet, so fall back to a cold reboot if warm reboot fails.

> 

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>


Well, I meant to refactor the SMC call macros as an improved
foundation for this, but that is clearly not happening before I leave
on sabbatical.

So:
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>


And I'll look into refactoring this if and when I look into that once
I get back.

> ---

> 

> I don't actually need this code for Synquacer, but given that I had

> already wrote it, we may just as well merge it.

> 

>  ArmPkg/Include/IndustryStandard/ArmStdSmc.h                        | 10 +++++++---

>  ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c | 14 ++++++++++++--

>  2 files changed, 19 insertions(+), 5 deletions(-)

> 

> diff --git a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h

> index 593a3ce729ce..41b086947eaa 100644

> --- a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h

> +++ b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h

> @@ -57,10 +57,12 @@

>  #define ARM_SMC_ID_PSCI_MIGRATE_AARCH32        0x84000005

>  #define ARM_SMC_ID_PSCI_SYSTEM_OFF             0x84000008

>  #define ARM_SMC_ID_PSCI_SYSTEM_RESET           0x84000009

> +#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64  0xc4000012

> +#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH32  0x84000012

>  

> -/* The current PSCI version is:  0.2 */

> -#define ARM_SMC_PSCI_VERSION_MAJOR  0

> -#define ARM_SMC_PSCI_VERSION_MINOR  2

> +/* The current PSCI version is:  1.1 */

> +#define ARM_SMC_PSCI_VERSION_MAJOR  1

> +#define ARM_SMC_PSCI_VERSION_MINOR  1

>  #define ARM_SMC_PSCI_VERSION  \

>    ((ARM_SMC_PSCI_VERSION_MAJOR << 16) | ARM_SMC_PSCI_VERSION_MINOR)

>  

> @@ -93,4 +95,6 @@

>  #define ARM_SMC_ID_PSCI_AFFINITY_INFO_OFF         1

>  #define ARM_SMC_ID_PSCI_AFFINITY_INFO_ON_PENDING  2

>  

> +#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_WARM  0

> +

>  #endif

> diff --git a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c

> index d6d26bce5009..ffd726554c0f 100644

> --- a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c

> +++ b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c

> @@ -55,7 +55,17 @@ ResetWarm (

>    VOID

>    )

>  {

> -  // Map a warm reset into a cold reset

> +  ARM_SMC_ARGS ArmSmcArgs;

> +

> +#if defined(MDE_CPU_AARCH64)

> +  ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64;

> +#else

> +  ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH32;

> +#endif

> +  ArmSmcArgs.Arg1 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_WARM;

> +  ArmCallSmc (&ArmSmcArgs);

> +

> +  // Fall back to cold reset if unsupported

>    ResetCold ();

>  }

>  

> @@ -89,7 +99,7 @@ EnterS3WithImmediateWake (

>    VOID

>    )

>  {

> -  // Not implemented

> +  ResetWarm ();

>  }

>  

>  /**

> -- 

> 2.11.0

> 

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
diff mbox series

Patch

diff --git a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h
index 593a3ce729ce..41b086947eaa 100644
--- a/ArmPkg/Include/IndustryStandard/ArmStdSmc.h
+++ b/ArmPkg/Include/IndustryStandard/ArmStdSmc.h
@@ -57,10 +57,12 @@ 
 #define ARM_SMC_ID_PSCI_MIGRATE_AARCH32        0x84000005
 #define ARM_SMC_ID_PSCI_SYSTEM_OFF             0x84000008
 #define ARM_SMC_ID_PSCI_SYSTEM_RESET           0x84000009
+#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64  0xc4000012
+#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH32  0x84000012
 
-/* The current PSCI version is:  0.2 */
-#define ARM_SMC_PSCI_VERSION_MAJOR  0
-#define ARM_SMC_PSCI_VERSION_MINOR  2
+/* The current PSCI version is:  1.1 */
+#define ARM_SMC_PSCI_VERSION_MAJOR  1
+#define ARM_SMC_PSCI_VERSION_MINOR  1
 #define ARM_SMC_PSCI_VERSION  \
   ((ARM_SMC_PSCI_VERSION_MAJOR << 16) | ARM_SMC_PSCI_VERSION_MINOR)
 
@@ -93,4 +95,6 @@ 
 #define ARM_SMC_ID_PSCI_AFFINITY_INFO_OFF         1
 #define ARM_SMC_ID_PSCI_AFFINITY_INFO_ON_PENDING  2
 
+#define ARM_SMC_ID_PSCI_SYSTEM_RESET2_WARM  0
+
 #endif
diff --git a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c
index d6d26bce5009..ffd726554c0f 100644
--- a/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c
+++ b/ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.c
@@ -55,7 +55,17 @@  ResetWarm (
   VOID
   )
 {
-  // Map a warm reset into a cold reset
+  ARM_SMC_ARGS ArmSmcArgs;
+
+#if defined(MDE_CPU_AARCH64)
+  ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH64;
+#else
+  ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_AARCH32;
+#endif
+  ArmSmcArgs.Arg1 = ARM_SMC_ID_PSCI_SYSTEM_RESET2_WARM;
+  ArmCallSmc (&ArmSmcArgs);
+
+  // Fall back to cold reset if unsupported
   ResetCold ();
 }
 
@@ -89,7 +99,7 @@  EnterS3WithImmediateWake (
   VOID
   )
 {
-  // Not implemented
+  ResetWarm ();
 }
 
 /**