2 Reset System lib using PSCI hypervisor or secure monitor calls
4 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5 Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
6 Copyright (c) 2014-2020, Linaro Ltd. All rights reserved.<BR>
7 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
9 SPDX-License-Identifier: BSD-2-Clause-Patent
16 #include <Library/ArmHvcLib.h>
17 #include <Library/ArmSmcLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/HobLib.h>
21 #include <Library/ResetSystemLib.h>
23 #include <IndustryStandard/ArmStdSmc.h>
40 CONST CHAR8
*Compatible
;
41 CONST CHAR8
*CompatibleItem
;
44 DeviceTreeBase
= (VOID
*)(UINTN
)PcdGet64 (PcdDeviceTreeInitialBaseAddress
);
45 ASSERT (fdt_check_header (DeviceTreeBase
) == 0);
48 // Enumerate all FDT nodes looking for the PSCI node and capture the method
50 for (Prev
= 0;; Prev
= Node
) {
51 Node
= fdt_next_node (DeviceTreeBase
, Prev
, NULL
);
56 Compatible
= fdt_getprop (DeviceTreeBase
, Node
, "compatible", &Len
);
57 if (Compatible
== NULL
) {
62 // Iterate over the NULL-separated items in the compatible string
64 for (CompatibleItem
= Compatible
; CompatibleItem
< Compatible
+ Len
;
65 CompatibleItem
+= 1 + AsciiStrLen (CompatibleItem
)) {
67 if (AsciiStrCmp (CompatibleItem
, "arm,psci-0.2") != 0) {
71 Prop
= fdt_getprop (DeviceTreeBase
, Node
, "method", NULL
);
73 DEBUG ((DEBUG_ERROR
, "%a: Missing PSCI method property\n",
75 return PsciMethodUnknown
;
78 if (AsciiStrnCmp (Prop
, "hvc", 3) == 0) {
80 } else if (AsciiStrnCmp (Prop
, "smc", 3) == 0) {
83 DEBUG ((DEBUG_ERROR
, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__
,
85 return PsciMethodUnknown
;
89 return PsciMethodUnknown
;
98 ARM_SMC_ARGS ArmSmcArgs
;
99 ARM_HVC_ARGS ArmHvcArgs
;
101 ArmSmcArgs
.Arg0
= Arg0
;
102 ArmHvcArgs
.Arg0
= Arg0
;
104 switch (DiscoverPsciMethod ()) {
106 ArmCallHvc (&ArmHvcArgs
);
110 ArmCallSmc (&ArmSmcArgs
);
114 DEBUG ((DEBUG_ERROR
, "%a: no PSCI method defined\n", __FUNCTION__
));
120 This function causes a system-wide reset (cold reset), in which
121 all circuitry within the system returns to its initial state. This type of reset
122 is asynchronous to system operation and operates without regard to
125 If this function returns, it means that the system does not support cold reset.
133 // Send a PSCI 0.2 SYSTEM_RESET command
134 PerformPsciAction (ARM_SMC_ID_PSCI_SYSTEM_RESET
);
138 This function causes a system-wide initialization (warm reset), in which all processors
139 are set to their initial state. Pending cycles are not corrupted.
141 If this function returns, it means that the system does not support warm reset.
149 // Map a warm reset into a cold reset
154 This function causes the system to enter a power state equivalent
155 to the ACPI G2/S5 or G3 states.
157 If this function returns, it means that the system does not support shutdown reset.
165 // Send a PSCI 0.2 SYSTEM_OFF command
166 PerformPsciAction (ARM_SMC_ID_PSCI_SYSTEM_OFF
);
170 This function causes a systemwide reset. The exact type of the reset is
171 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
172 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
173 the platform must pick a supported reset type to perform.The platform may
174 optionally log the parameters from any non-normal reset that occurs.
176 @param[in] DataSize The size, in bytes, of ResetData.
177 @param[in] ResetData The data buffer starts with a Null-terminated string,
178 followed by the EFI_GUID.
182 ResetPlatformSpecific (
187 // Map the platform specific reset as reboot
192 The ResetSystem function resets the entire platform.
194 @param[in] ResetType The type of reset to perform.
195 @param[in] ResetStatus The status code for the reset.
196 @param[in] DataSize The size, in bytes, of ResetData.
197 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
198 the data buffer starts with a Null-terminated string, optionally
199 followed by additional binary data. The string is a description
200 that the caller may use to further indicate the reason for the
206 IN EFI_RESET_TYPE ResetType
,
207 IN EFI_STATUS ResetStatus
,
209 IN VOID
*ResetData OPTIONAL
221 case EfiResetShutdown
:
225 case EfiResetPlatformSpecific
:
226 ResetPlatformSpecific (DataSize
, ResetData
);