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>
12 SPDX-License-Identifier: BSD-2-Clause-Patent
18 #include <Library/BaseLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/ResetSystemLib.h>
21 #include <Library/ArmSmcLib.h>
22 #include <Library/ArmHvcLib.h>
23 #include <Library/UefiBootServicesTableLib.h>
25 #include <IndustryStandard/ArmStdSmc.h>
27 #include <Protocol/FdtClient.h>
29 STATIC UINT32 mArmPsciMethod
;
33 ArmPsciResetSystemLibConstructor (
38 FDT_CLIENT_PROTOCOL
*FdtClient
;
41 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
43 ASSERT_EFI_ERROR (Status
);
45 Status
= FdtClient
->FindCompatibleNodeProperty (FdtClient
, "arm,psci-0.2",
46 "method", &Prop
, NULL
);
47 if (EFI_ERROR (Status
)) {
51 if (AsciiStrnCmp (Prop
, "hvc", 3) == 0) {
53 } else if (AsciiStrnCmp (Prop
, "smc", 3) == 0) {
56 DEBUG ((EFI_D_ERROR
, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__
,
64 This function causes a system-wide reset (cold reset), in which
65 all circuitry within the system returns to its initial state. This type of reset
66 is asynchronous to system operation and operates without regard to
69 If this function returns, it means that the system does not support cold reset.
77 ARM_SMC_ARGS ArmSmcArgs
;
78 ARM_HVC_ARGS ArmHvcArgs
;
80 // Send a PSCI 0.2 SYSTEM_RESET command
81 ArmSmcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_RESET
;
82 ArmHvcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_RESET
;
84 switch (mArmPsciMethod
) {
86 ArmCallHvc (&ArmHvcArgs
);
90 ArmCallSmc (&ArmSmcArgs
);
94 DEBUG ((EFI_D_ERROR
, "%a: no PSCI method defined\n", __FUNCTION__
));
99 This function causes a system-wide initialization (warm reset), in which all processors
100 are set to their initial state. Pending cycles are not corrupted.
102 If this function returns, it means that the system does not support warm reset.
110 // Map a warm reset into a cold reset
115 This function causes the system to enter a power state equivalent
116 to the ACPI G2/S5 or G3 states.
118 If this function returns, it means that the system does not support shutdown reset.
126 ARM_SMC_ARGS ArmSmcArgs
;
127 ARM_HVC_ARGS ArmHvcArgs
;
129 // Send a PSCI 0.2 SYSTEM_OFF command
130 ArmSmcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_OFF
;
131 ArmHvcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_OFF
;
133 switch (mArmPsciMethod
) {
135 ArmCallHvc (&ArmHvcArgs
);
139 ArmCallSmc (&ArmSmcArgs
);
143 DEBUG ((EFI_D_ERROR
, "%a: no PSCI method defined\n", __FUNCTION__
));
148 This function causes the system to enter S3 and then wake up immediately.
150 If this function returns, it means that the system does not support S3 feature.
154 EnterS3WithImmediateWake (
162 This function causes a systemwide reset. The exact type of the reset is
163 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
164 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
165 the platform must pick a supported reset type to perform.The platform may
166 optionally log the parameters from any non-normal reset that occurs.
168 @param[in] DataSize The size, in bytes, of ResetData.
169 @param[in] ResetData The data buffer starts with a Null-terminated string,
170 followed by the EFI_GUID.
174 ResetPlatformSpecific (
179 // Map the platform specific reset as reboot