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 This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
24 #include <Library/BaseLib.h>
25 #include <Library/DebugLib.h>
26 #include <Library/ResetSystemLib.h>
27 #include <Library/ArmSmcLib.h>
28 #include <Library/ArmHvcLib.h>
29 #include <Library/UefiBootServicesTableLib.h>
31 #include <IndustryStandard/ArmStdSmc.h>
33 #include <Protocol/FdtClient.h>
35 STATIC UINT32 mArmPsciMethod
;
39 ArmPsciResetSystemLibConstructor (
44 FDT_CLIENT_PROTOCOL
*FdtClient
;
47 Status
= gBS
->LocateProtocol (&gFdtClientProtocolGuid
, NULL
,
49 ASSERT_EFI_ERROR (Status
);
51 Status
= FdtClient
->FindCompatibleNodeProperty (FdtClient
, "arm,psci-0.2",
52 "method", &Prop
, NULL
);
53 if (EFI_ERROR (Status
)) {
57 if (AsciiStrnCmp (Prop
, "hvc", 3) == 0) {
59 } else if (AsciiStrnCmp (Prop
, "smc", 3) == 0) {
62 DEBUG ((EFI_D_ERROR
, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__
,
70 This function causes a system-wide reset (cold reset), in which
71 all circuitry within the system returns to its initial state. This type of reset
72 is asynchronous to system operation and operates without regard to
75 If this function returns, it means that the system does not support cold reset.
83 ARM_SMC_ARGS ArmSmcArgs
;
84 ARM_HVC_ARGS ArmHvcArgs
;
86 // Send a PSCI 0.2 SYSTEM_RESET command
87 ArmSmcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_RESET
;
88 ArmHvcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_RESET
;
90 switch (mArmPsciMethod
) {
92 ArmCallHvc (&ArmHvcArgs
);
96 ArmCallSmc (&ArmSmcArgs
);
100 DEBUG ((EFI_D_ERROR
, "%a: no PSCI method defined\n", __FUNCTION__
));
105 This function causes a system-wide initialization (warm reset), in which all processors
106 are set to their initial state. Pending cycles are not corrupted.
108 If this function returns, it means that the system does not support warm reset.
116 // Map a warm reset into a cold reset
121 This function causes the system to enter a power state equivalent
122 to the ACPI G2/S5 or G3 states.
124 If this function returns, it means that the system does not support shutdown reset.
132 ARM_SMC_ARGS ArmSmcArgs
;
133 ARM_HVC_ARGS ArmHvcArgs
;
135 // Send a PSCI 0.2 SYSTEM_OFF command
136 ArmSmcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_OFF
;
137 ArmHvcArgs
.Arg0
= ARM_SMC_ID_PSCI_SYSTEM_OFF
;
139 switch (mArmPsciMethod
) {
141 ArmCallHvc (&ArmHvcArgs
);
145 ArmCallSmc (&ArmSmcArgs
);
149 DEBUG ((EFI_D_ERROR
, "%a: no PSCI method defined\n", __FUNCTION__
));
154 This function causes the system to enter S3 and then wake up immediately.
156 If this function returns, it means that the system does not support S3 feature.
160 EnterS3WithImmediateWake (
168 This function causes a systemwide reset. The exact type of the reset is
169 defined by the EFI_GUID that follows the Null-terminated Unicode string passed
170 into ResetData. If the platform does not recognize the EFI_GUID in ResetData
171 the platform must pick a supported reset type to perform.The platform may
172 optionally log the parameters from any non-normal reset that occurs.
174 @param[in] DataSize The size, in bytes, of ResetData.
175 @param[in] ResetData The data buffer starts with a Null-terminated string,
176 followed by the EFI_GUID.
180 ResetPlatformSpecific (
185 // Map the platform specific reset as reboot