2 ResetSystemLib implementation using PSCI calls
4 Copyright (c) 2017 - 2018, Linaro Ltd. All rights reserved.<BR>
5 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include <Library/ArmMmuLib.h>
14 #include <Library/ArmSmcLib.h>
15 #include <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/ResetSystemLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/UefiRuntimeLib.h>
21 #include <IndustryStandard/ArmStdSmc.h>
24 This function causes a system-wide reset (cold reset), in which
25 all circuitry within the system returns to its initial state. This type of reset
26 is asynchronous to system operation and operates without regard to
29 If this function returns, it means that the system does not support cold reset.
37 ARM_SMC_ARGS ArmSmcArgs
;
39 // Send a PSCI 0.2 SYSTEM_RESET command
40 ArmSmcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_RESET
;
41 ArmCallSmc (&ArmSmcArgs
);
45 This function causes a system-wide initialization (warm reset), in which all processors
46 are set to their initial state. Pending cycles are not corrupted.
48 If this function returns, it means that the system does not support warm reset.
56 // Map a warm reset into a cold reset
61 This function causes the system to enter a power state equivalent
62 to the ACPI G2/S5 or G3 states.
64 If this function returns, it means that the system does not support shutdown reset.
72 ARM_SMC_ARGS ArmSmcArgs
;
74 // Send a PSCI 0.2 SYSTEM_OFF command
75 ArmSmcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_OFF
;
76 ArmCallSmc (&ArmSmcArgs
);
79 VOID
DisableMmuAndReenterPei (VOID
);
82 This function causes the system to enter S3 and then wake up immediately.
84 If this function returns, it means that the system does not support S3 feature.
88 EnterS3WithImmediateWake (
92 EFI_PHYSICAL_ADDRESS Alloc
;
93 EFI_MEMORY_DESCRIPTOR
*MemMap
;
95 UINTN MapKey
, DescriptorSize
;
96 UINT32 DescriptorVersion
;
99 if (FeaturePcdGet (PcdArmReenterPeiForCapsuleWarmReboot
) &&
102 // At boot time, we are the only core running, so we can implement the
103 // immediate wake (which is used by capsule update) by disabling the MMU
104 // and interrupts, and jumping to the PEI entry point.
108 // Obtain the size of the memory map
112 Status
= gBS
->GetMemoryMap (&MemMapSize
, MemMap
, &MapKey
, &DescriptorSize
,
114 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
117 // Add some slack to the allocation to cater for changes in the memory
118 // map if ExitBootServices () fails the first time around.
120 MemMapSize
+= SIZE_4KB
;
121 Status
= gBS
->AllocatePages (AllocateAnyPages
, EfiBootServicesData
,
122 EFI_SIZE_TO_PAGES (MemMapSize
), &Alloc
);
123 ASSERT_EFI_ERROR (Status
);
125 MemMap
= (EFI_MEMORY_DESCRIPTOR
*)(UINTN
)Alloc
;
127 Status
= gBS
->GetMemoryMap (&MemMapSize
, MemMap
, &MapKey
, &DescriptorSize
,
129 ASSERT_EFI_ERROR (Status
);
131 Status
= gBS
->ExitBootServices (gImageHandle
, MapKey
);
132 if (EFI_ERROR (Status
)) {
134 // ExitBootServices () may fail the first time around if an event fired
135 // right after the call to GetMemoryMap() which allocated or freed memory.
136 // Since that first call to ExitBootServices () will disarm the timer,
137 // this is guaranteed not to happen again, so one additional attempt
140 Status
= gBS
->GetMemoryMap (&MemMapSize
, MemMap
, &MapKey
, &DescriptorSize
,
142 ASSERT_EFI_ERROR (Status
);
144 Status
= gBS
->ExitBootServices (gImageHandle
, MapKey
);
145 ASSERT_EFI_ERROR (Status
);
148 DisableMmuAndReenterPei ();
153 This function causes a systemwide reset. The exact type of the reset is
154 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
155 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
156 the platform must pick a supported reset type to perform.The platform may
157 optionally log the parameters from any non-normal reset that occurs.
159 @param[in] DataSize The size, in bytes, of ResetData.
160 @param[in] ResetData The data buffer starts with a Null-terminated string,
161 followed by the EFI_GUID.
165 ResetPlatformSpecific (
170 // Map the platform specific reset as reboot
175 The ResetSystem function resets the entire platform.
177 @param[in] ResetType The type of reset to perform.
178 @param[in] ResetStatus The status code for the reset.
179 @param[in] DataSize The size, in bytes, of ResetData.
180 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
181 the data buffer starts with a Null-terminated string, optionally
182 followed by additional binary data. The string is a description
183 that the caller may use to further indicate the reason for the
189 IN EFI_RESET_TYPE ResetType
,
190 IN EFI_STATUS ResetStatus
,
192 IN VOID
*ResetData OPTIONAL
204 case EfiResetShutdown
:
208 case EfiResetPlatformSpecific
:
209 ResetPlatformSpecific (DataSize
, ResetData
);