2 Support ResetSystem Runtime call using PSCI calls
4 Note: A similar library is implemented in
5 ArmPkg/Library/ArmPsciResetSystemLib. Similar issues might
6 exist in this implementation too.
8 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
9 Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
10 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>
11 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
13 SPDX-License-Identifier: BSD-2-Clause-Patent
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/ResetSystemLib.h>
22 #include <Library/ArmSmcLib.h>
23 #include <Library/ArmHvcLib.h>
24 #include <Library/UefiBootServicesTableLib.h>
26 #include <IndustryStandard/ArmStdSmc.h>
28 #include <Protocol/FdtClient.h>
30 STATIC UINT32 mArmPsciMethod
;
34 ArmPsciResetSystemLibConstructor (
39 FDT_CLIENT_PROTOCOL
*FdtClient
;
42 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
44 ASSERT_EFI_ERROR (Status
);
46 Status
= FdtClient
->FindCompatibleNodeProperty (FdtClient
, "arm,psci-0.2",
47 "method", &Prop
, NULL
);
48 if (EFI_ERROR (Status
)) {
52 if (AsciiStrnCmp (Prop
, "hvc", 3) == 0) {
54 } else if (AsciiStrnCmp (Prop
, "smc", 3) == 0) {
57 DEBUG ((EFI_D_ERROR
, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__
,
65 This function causes a system-wide reset (cold reset), in which
66 all circuitry within the system returns to its initial state. This type of reset
67 is asynchronous to system operation and operates without regard to
70 If this function returns, it means that the system does not support cold reset.
78 ARM_SMC_ARGS ArmSmcArgs
;
79 ARM_HVC_ARGS ArmHvcArgs
;
81 // Send a PSCI 0.2 SYSTEM_RESET command
82 ArmSmcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_RESET
;
83 ArmHvcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_RESET
;
85 switch (mArmPsciMethod
) {
87 ArmCallHvc (&ArmHvcArgs
);
91 ArmCallSmc (&ArmSmcArgs
);
95 DEBUG ((EFI_D_ERROR
, "%a: no PSCI method defined\n", __FUNCTION__
));
100 This function causes a system-wide initialization (warm reset), in which all processors
101 are set to their initial state. Pending cycles are not corrupted.
103 If this function returns, it means that the system does not support warm reset.
111 // Map a warm reset into a cold reset
116 This function causes the system to enter a power state equivalent
117 to the ACPI G2/S5 or G3 states.
119 If this function returns, it means that the system does not support shutdown reset.
127 ARM_SMC_ARGS ArmSmcArgs
;
128 ARM_HVC_ARGS ArmHvcArgs
;
130 // Send a PSCI 0.2 SYSTEM_OFF command
131 ArmSmcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_OFF
;
132 ArmHvcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_OFF
;
134 switch (mArmPsciMethod
) {
136 ArmCallHvc (&ArmHvcArgs
);
140 ArmCallSmc (&ArmSmcArgs
);
144 DEBUG ((EFI_D_ERROR
, "%a: no PSCI method defined\n", __FUNCTION__
));
149 This function causes the system to enter S3 and then wake up immediately.
151 If this function returns, it means that the system does not support S3 feature.
155 EnterS3WithImmediateWake (
163 This function causes a systemwide reset. The exact type of the reset is
164 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
165 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
166 the platform must pick a supported reset type to perform.The platform may
167 optionally log the parameters from any non-normal reset that occurs.
169 @param[in] DataSize The size, in bytes, of ResetData.
170 @param[in] ResetData The data buffer starts with a Null-terminated string,
171 followed by the EFI_GUID.
175 ResetPlatformSpecific (
180 // Map the platform specific reset as reboot
185 The ResetSystem function resets the entire platform.
187 @param[in] ResetType The type of reset to perform.
188 @param[in] ResetStatus The status code for the reset.
189 @param[in] DataSize The size, in bytes, of ResetData.
190 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
191 the data buffer starts with a Null-terminated string, optionally
192 followed by additional binary data. The string is a description
193 that the caller may use to further indicate the reason for the
199 IN EFI_RESET_TYPE ResetType
,
200 IN EFI_STATUS ResetStatus
,
202 IN VOID
*ResetData OPTIONAL
214 case EfiResetShutdown
:
218 case EfiResetPlatformSpecific
:
219 ResetPlatformSpecific (DataSize
, ResetData
);