ArmPkg/ArmSmcPsciResetSystemLib: implement fallback for warm reboot
[mirror_edk2.git] / ArmPkg / Library / ArmSmcPsciResetSystemLib / ArmSmcPsciResetSystemLib.c
1 /** @file
2 ResetSystemLib implementation using PSCI calls
3
4 Copyright (c) 2017, Linaro Ltd. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include <PiDxe.h>
17
18 #include <Library/ArmMmuLib.h>
19 #include <Library/ArmSmcLib.h>
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/ResetSystemLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/UefiRuntimeLib.h>
25
26 #include <IndustryStandard/ArmStdSmc.h>
27
28 /**
29 This function causes a system-wide reset (cold reset), in which
30 all circuitry within the system returns to its initial state. This type of reset
31 is asynchronous to system operation and operates without regard to
32 cycle boundaries.
33
34 If this function returns, it means that the system does not support cold reset.
35 **/
36 VOID
37 EFIAPI
38 ResetCold (
39 VOID
40 )
41 {
42 ARM_SMC_ARGS ArmSmcArgs;
43
44 // Send a PSCI 0.2 SYSTEM_RESET command
45 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;
46 ArmCallSmc (&ArmSmcArgs);
47 }
48
49 /**
50 This function causes a system-wide initialization (warm reset), in which all processors
51 are set to their initial state. Pending cycles are not corrupted.
52
53 If this function returns, it means that the system does not support warm reset.
54 **/
55 VOID
56 EFIAPI
57 ResetWarm (
58 VOID
59 )
60 {
61 // Map a warm reset into a cold reset
62 ResetCold ();
63 }
64
65 /**
66 This function causes the system to enter a power state equivalent
67 to the ACPI G2/S5 or G3 states.
68
69 If this function returns, it means that the system does not support shutdown reset.
70 **/
71 VOID
72 EFIAPI
73 ResetShutdown (
74 VOID
75 )
76 {
77 ARM_SMC_ARGS ArmSmcArgs;
78
79 // Send a PSCI 0.2 SYSTEM_OFF command
80 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;
81 ArmCallSmc (&ArmSmcArgs);
82 }
83
84 /**
85 This function causes the system to enter S3 and then wake up immediately.
86
87 If this function returns, it means that the system does not support S3 feature.
88 **/
89 VOID
90 EFIAPI
91 EnterS3WithImmediateWake (
92 VOID
93 )
94 {
95 VOID (*Reset)(VOID);
96
97 if (FeaturePcdGet (PcdArmReenterPeiForCapsuleWarmReboot) &&
98 !EfiAtRuntime ()) {
99 //
100 // At boot time, we are the only core running, so we can implement the
101 // immediate wake (which is used by capsule update) by disabling the MMU
102 // and interrupts, and jumping to the PEI entry point.
103 //
104 Reset = (VOID (*)(VOID))(UINTN)FixedPcdGet64 (PcdFvBaseAddress);
105
106 gBS->RaiseTPL (TPL_HIGH_LEVEL);
107 ArmDisableMmu ();
108 Reset ();
109 }
110 }
111
112 /**
113 This function causes a systemwide reset. The exact type of the reset is
114 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
115 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
116 the platform must pick a supported reset type to perform.The platform may
117 optionally log the parameters from any non-normal reset that occurs.
118
119 @param[in] DataSize The size, in bytes, of ResetData.
120 @param[in] ResetData The data buffer starts with a Null-terminated string,
121 followed by the EFI_GUID.
122 **/
123 VOID
124 EFIAPI
125 ResetPlatformSpecific (
126 IN UINTN DataSize,
127 IN VOID *ResetData
128 )
129 {
130 // Map the platform specific reset as reboot
131 ResetCold ();
132 }