]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmVirtPsciResetSystemLib/ArmVirtPsciResetSystemLib.c
ArmVirtPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmVirtPkg / Library / ArmVirtPsciResetSystemLib / ArmVirtPsciResetSystemLib.c
CommitLineData
9180ab73
OM
1/** @file\r
2 Support ResetSystem Runtime call using PSCI calls\r
3\r
4 Note: A similar library is implemented in\r
5 ArmPkg/Library/ArmPsciResetSystemLib. Similar issues might\r
6 exist in this implementation too.\r
7\r
8 Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
9 Copyright (c) 2013, ARM Ltd. All rights reserved.<BR>\r
10 Copyright (c) 2014, Linaro Ltd. All rights reserved.<BR>\r
d943e5ad 11 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
9180ab73 12\r
9792fb0e 13 SPDX-License-Identifier: BSD-2-Clause-Patent\r
9180ab73
OM
14\r
15**/\r
16\r
17#include <PiDxe.h>\r
18\r
19#include <Library/BaseLib.h>\r
20#include <Library/DebugLib.h>\r
7b1dc6c5 21#include <Library/ResetSystemLib.h>\r
9180ab73
OM
22#include <Library/ArmSmcLib.h>\r
23#include <Library/ArmHvcLib.h>\r
93f9a23f 24#include <Library/UefiBootServicesTableLib.h>\r
9180ab73
OM
25\r
26#include <IndustryStandard/ArmStdSmc.h>\r
27\r
93f9a23f
AB
28#include <Protocol/FdtClient.h>\r
29\r
2b16a4fb 30STATIC UINT32 mArmPsciMethod;\r
9180ab73
OM
31\r
32RETURN_STATUS\r
33EFIAPI\r
34ArmPsciResetSystemLibConstructor (\r
35 VOID\r
36 )\r
37{\r
2b16a4fb
MK
38 EFI_STATUS Status;\r
39 FDT_CLIENT_PROTOCOL *FdtClient;\r
40 CONST VOID *Prop;\r
41\r
42 Status = gBS->LocateProtocol (\r
43 &gFdtClientProtocolGuid,\r
44 NULL,\r
45 (VOID **)&FdtClient\r
46 );\r
93f9a23f
AB
47 ASSERT_EFI_ERROR (Status);\r
48\r
2b16a4fb
MK
49 Status = FdtClient->FindCompatibleNodeProperty (\r
50 FdtClient,\r
51 "arm,psci-0.2",\r
52 "method",\r
53 &Prop,\r
54 NULL\r
55 );\r
93f9a23f
AB
56 if (EFI_ERROR (Status)) {\r
57 return Status;\r
58 }\r
59\r
60 if (AsciiStrnCmp (Prop, "hvc", 3) == 0) {\r
61 mArmPsciMethod = 1;\r
62 } else if (AsciiStrnCmp (Prop, "smc", 3) == 0) {\r
63 mArmPsciMethod = 2;\r
64 } else {\r
2b16a4fb
MK
65 DEBUG ((\r
66 DEBUG_ERROR,\r
67 "%a: Unknown PSCI method \"%a\"\n",\r
68 __FUNCTION__,\r
69 Prop\r
70 ));\r
93f9a23f
AB
71 return EFI_NOT_FOUND;\r
72 }\r
2b16a4fb 73\r
93f9a23f 74 return EFI_SUCCESS;\r
9180ab73
OM
75}\r
76\r
77/**\r
7b1dc6c5
AB
78 This function causes a system-wide reset (cold reset), in which\r
79 all circuitry within the system returns to its initial state. This type of reset\r
80 is asynchronous to system operation and operates without regard to\r
81 cycle boundaries.\r
9180ab73 82\r
7b1dc6c5 83 If this function returns, it means that the system does not support cold reset.\r
9180ab73 84**/\r
7b1dc6c5 85VOID\r
9180ab73 86EFIAPI\r
7b1dc6c5
AB
87ResetCold (\r
88 VOID\r
9180ab73
OM
89 )\r
90{\r
2b16a4fb
MK
91 ARM_SMC_ARGS ArmSmcArgs;\r
92 ARM_HVC_ARGS ArmHvcArgs;\r
9180ab73 93\r
7b1dc6c5
AB
94 // Send a PSCI 0.2 SYSTEM_RESET command\r
95 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;\r
96 ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;\r
9180ab73 97\r
7b1dc6c5 98 switch (mArmPsciMethod) {\r
2b16a4fb
MK
99 case 1:\r
100 ArmCallHvc (&ArmHvcArgs);\r
101 break;\r
7b1dc6c5 102\r
2b16a4fb
MK
103 case 2:\r
104 ArmCallSmc (&ArmSmcArgs);\r
105 break;\r
7b1dc6c5 106\r
2b16a4fb
MK
107 default:\r
108 DEBUG ((DEBUG_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));\r
9180ab73 109 }\r
7b1dc6c5
AB
110}\r
111\r
112/**\r
113 This function causes a system-wide initialization (warm reset), in which all processors\r
114 are set to their initial state. Pending cycles are not corrupted.\r
115\r
116 If this function returns, it means that the system does not support warm reset.\r
117**/\r
118VOID\r
119EFIAPI\r
120ResetWarm (\r
121 VOID\r
122 )\r
123{\r
124 // Map a warm reset into a cold reset\r
125 ResetCold ();\r
126}\r
127\r
128/**\r
129 This function causes the system to enter a power state equivalent\r
130 to the ACPI G2/S5 or G3 states.\r
131\r
132 If this function returns, it means that the system does not support shutdown reset.\r
133**/\r
134VOID\r
135EFIAPI\r
136ResetShutdown (\r
137 VOID\r
138 )\r
139{\r
2b16a4fb
MK
140 ARM_SMC_ARGS ArmSmcArgs;\r
141 ARM_HVC_ARGS ArmHvcArgs;\r
7b1dc6c5
AB
142\r
143 // Send a PSCI 0.2 SYSTEM_OFF command\r
144 ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;\r
145 ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;\r
9180ab73
OM
146\r
147 switch (mArmPsciMethod) {\r
2b16a4fb
MK
148 case 1:\r
149 ArmCallHvc (&ArmHvcArgs);\r
150 break;\r
9180ab73 151\r
2b16a4fb
MK
152 case 2:\r
153 ArmCallSmc (&ArmSmcArgs);\r
154 break;\r
9180ab73 155\r
2b16a4fb
MK
156 default:\r
157 DEBUG ((DEBUG_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));\r
9180ab73 158 }\r
9180ab73
OM
159}\r
160\r
7b1dc6c5
AB
161/**\r
162 This function causes a systemwide reset. The exact type of the reset is\r
163 defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r
164 into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r
165 the platform must pick a supported reset type to perform.The platform may\r
166 optionally log the parameters from any non-normal reset that occurs.\r
167\r
168 @param[in] DataSize The size, in bytes, of ResetData.\r
169 @param[in] ResetData The data buffer starts with a Null-terminated string,\r
170 followed by the EFI_GUID.\r
9180ab73 171**/\r
7b1dc6c5 172VOID\r
9180ab73 173EFIAPI\r
7b1dc6c5 174ResetPlatformSpecific (\r
2b16a4fb
MK
175 IN UINTN DataSize,\r
176 IN VOID *ResetData\r
9180ab73
OM
177 )\r
178{\r
7b1dc6c5
AB
179 // Map the platform specific reset as reboot\r
180 ResetCold ();\r
9180ab73 181}\r
d943e5ad
ZG
182\r
183/**\r
184 The ResetSystem function resets the entire platform.\r
185\r
186 @param[in] ResetType The type of reset to perform.\r
187 @param[in] ResetStatus The status code for the reset.\r
188 @param[in] DataSize The size, in bytes, of ResetData.\r
189 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown\r
190 the data buffer starts with a Null-terminated string, optionally\r
191 followed by additional binary data. The string is a description\r
192 that the caller may use to further indicate the reason for the\r
193 system reset.\r
194**/\r
195VOID\r
196EFIAPI\r
197ResetSystem (\r
2b16a4fb
MK
198 IN EFI_RESET_TYPE ResetType,\r
199 IN EFI_STATUS ResetStatus,\r
200 IN UINTN DataSize,\r
201 IN VOID *ResetData OPTIONAL\r
d943e5ad
ZG
202 )\r
203{\r
204 switch (ResetType) {\r
2b16a4fb
MK
205 case EfiResetWarm:\r
206 ResetWarm ();\r
207 break;\r
d943e5ad 208\r
2b16a4fb
MK
209 case EfiResetCold:\r
210 ResetCold ();\r
211 break;\r
d943e5ad 212\r
2b16a4fb
MK
213 case EfiResetShutdown:\r
214 ResetShutdown ();\r
215 return;\r
d943e5ad 216\r
2b16a4fb
MK
217 case EfiResetPlatformSpecific:\r
218 ResetPlatformSpecific (DataSize, ResetData);\r
219 return;\r
d943e5ad 220\r
2b16a4fb
MK
221 default:\r
222 return;\r
d943e5ad
ZG
223 }\r
224}\r