]>
Commit | Line | Data |
---|---|---|
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 | |
9180ab73 OM |
30 | STATIC UINT32 mArmPsciMethod;\r |
31 | \r | |
32 | RETURN_STATUS\r | |
33 | EFIAPI\r | |
34 | ArmPsciResetSystemLibConstructor (\r | |
35 | VOID\r | |
36 | )\r | |
37 | {\r | |
93f9a23f AB |
38 | EFI_STATUS Status;\r |
39 | FDT_CLIENT_PROTOCOL *FdtClient;\r | |
40 | CONST VOID *Prop;\r | |
41 | \r | |
42 | Status = gBS->LocateProtocol (&gFdtClientProtocolGuid, NULL,\r | |
43 | (VOID **)&FdtClient);\r | |
44 | ASSERT_EFI_ERROR (Status);\r | |
45 | \r | |
46 | Status = FdtClient->FindCompatibleNodeProperty (FdtClient, "arm,psci-0.2",\r | |
47 | "method", &Prop, NULL);\r | |
48 | if (EFI_ERROR (Status)) {\r | |
49 | return Status;\r | |
50 | }\r | |
51 | \r | |
52 | if (AsciiStrnCmp (Prop, "hvc", 3) == 0) {\r | |
53 | mArmPsciMethod = 1;\r | |
54 | } else if (AsciiStrnCmp (Prop, "smc", 3) == 0) {\r | |
55 | mArmPsciMethod = 2;\r | |
56 | } else {\r | |
c5b3a56e | 57 | DEBUG ((DEBUG_ERROR, "%a: Unknown PSCI method \"%a\"\n", __FUNCTION__,\r |
93f9a23f AB |
58 | Prop));\r |
59 | return EFI_NOT_FOUND;\r | |
60 | }\r | |
61 | return EFI_SUCCESS;\r | |
9180ab73 OM |
62 | }\r |
63 | \r | |
64 | /**\r | |
7b1dc6c5 AB |
65 | This function causes a system-wide reset (cold reset), in which\r |
66 | all circuitry within the system returns to its initial state. This type of reset\r | |
67 | is asynchronous to system operation and operates without regard to\r | |
68 | cycle boundaries.\r | |
9180ab73 | 69 | \r |
7b1dc6c5 | 70 | If this function returns, it means that the system does not support cold reset.\r |
9180ab73 | 71 | **/\r |
7b1dc6c5 | 72 | VOID\r |
9180ab73 | 73 | EFIAPI\r |
7b1dc6c5 AB |
74 | ResetCold (\r |
75 | VOID\r | |
9180ab73 OM |
76 | )\r |
77 | {\r | |
78 | ARM_SMC_ARGS ArmSmcArgs;\r | |
79 | ARM_HVC_ARGS ArmHvcArgs;\r | |
80 | \r | |
7b1dc6c5 AB |
81 | // Send a PSCI 0.2 SYSTEM_RESET command\r |
82 | ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;\r | |
83 | ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_RESET;\r | |
9180ab73 | 84 | \r |
7b1dc6c5 AB |
85 | switch (mArmPsciMethod) {\r |
86 | case 1:\r | |
87 | ArmCallHvc (&ArmHvcArgs);\r | |
9180ab73 | 88 | break;\r |
7b1dc6c5 AB |
89 | \r |
90 | case 2:\r | |
91 | ArmCallSmc (&ArmSmcArgs);\r | |
9180ab73 | 92 | break;\r |
7b1dc6c5 | 93 | \r |
9180ab73 | 94 | default:\r |
c5b3a56e | 95 | DEBUG ((DEBUG_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));\r |
9180ab73 | 96 | }\r |
7b1dc6c5 AB |
97 | }\r |
98 | \r | |
99 | /**\r | |
100 | This function causes a system-wide initialization (warm reset), in which all processors\r | |
101 | are set to their initial state. Pending cycles are not corrupted.\r | |
102 | \r | |
103 | If this function returns, it means that the system does not support warm reset.\r | |
104 | **/\r | |
105 | VOID\r | |
106 | EFIAPI\r | |
107 | ResetWarm (\r | |
108 | VOID\r | |
109 | )\r | |
110 | {\r | |
111 | // Map a warm reset into a cold reset\r | |
112 | ResetCold ();\r | |
113 | }\r | |
114 | \r | |
115 | /**\r | |
116 | This function causes the system to enter a power state equivalent\r | |
117 | to the ACPI G2/S5 or G3 states.\r | |
118 | \r | |
119 | If this function returns, it means that the system does not support shutdown reset.\r | |
120 | **/\r | |
121 | VOID\r | |
122 | EFIAPI\r | |
123 | ResetShutdown (\r | |
124 | VOID\r | |
125 | )\r | |
126 | {\r | |
127 | ARM_SMC_ARGS ArmSmcArgs;\r | |
128 | ARM_HVC_ARGS ArmHvcArgs;\r | |
129 | \r | |
130 | // Send a PSCI 0.2 SYSTEM_OFF command\r | |
131 | ArmSmcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;\r | |
132 | ArmHvcArgs.Arg0 = ARM_SMC_ID_PSCI_SYSTEM_OFF;\r | |
9180ab73 OM |
133 | \r |
134 | switch (mArmPsciMethod) {\r | |
135 | case 1:\r | |
136 | ArmCallHvc (&ArmHvcArgs);\r | |
137 | break;\r | |
138 | \r | |
139 | case 2:\r | |
140 | ArmCallSmc (&ArmSmcArgs);\r | |
141 | break;\r | |
142 | \r | |
143 | default:\r | |
c5b3a56e | 144 | DEBUG ((DEBUG_ERROR, "%a: no PSCI method defined\n", __FUNCTION__));\r |
9180ab73 | 145 | }\r |
9180ab73 OM |
146 | }\r |
147 | \r | |
7b1dc6c5 AB |
148 | /**\r |
149 | This function causes a systemwide reset. The exact type of the reset is\r | |
150 | defined by the EFI_GUID that follows the Null-terminated Unicode string passed\r | |
151 | into ResetData. If the platform does not recognize the EFI_GUID in ResetData\r | |
152 | the platform must pick a supported reset type to perform.The platform may\r | |
153 | optionally log the parameters from any non-normal reset that occurs.\r | |
154 | \r | |
155 | @param[in] DataSize The size, in bytes, of ResetData.\r | |
156 | @param[in] ResetData The data buffer starts with a Null-terminated string,\r | |
157 | followed by the EFI_GUID.\r | |
9180ab73 | 158 | **/\r |
7b1dc6c5 | 159 | VOID\r |
9180ab73 | 160 | EFIAPI\r |
7b1dc6c5 AB |
161 | ResetPlatformSpecific (\r |
162 | IN UINTN DataSize,\r | |
163 | IN VOID *ResetData\r | |
9180ab73 OM |
164 | )\r |
165 | {\r | |
7b1dc6c5 AB |
166 | // Map the platform specific reset as reboot\r |
167 | ResetCold ();\r | |
9180ab73 | 168 | }\r |
d943e5ad ZG |
169 | \r |
170 | /**\r | |
171 | The ResetSystem function resets the entire platform.\r | |
172 | \r | |
173 | @param[in] ResetType The type of reset to perform.\r | |
174 | @param[in] ResetStatus The status code for the reset.\r | |
175 | @param[in] DataSize The size, in bytes, of ResetData.\r | |
176 | @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown\r | |
177 | the data buffer starts with a Null-terminated string, optionally\r | |
178 | followed by additional binary data. The string is a description\r | |
179 | that the caller may use to further indicate the reason for the\r | |
180 | system reset.\r | |
181 | **/\r | |
182 | VOID\r | |
183 | EFIAPI\r | |
184 | ResetSystem (\r | |
185 | IN EFI_RESET_TYPE ResetType,\r | |
186 | IN EFI_STATUS ResetStatus,\r | |
187 | IN UINTN DataSize,\r | |
188 | IN VOID *ResetData OPTIONAL\r | |
189 | )\r | |
190 | {\r | |
191 | switch (ResetType) {\r | |
192 | case EfiResetWarm:\r | |
193 | ResetWarm ();\r | |
194 | break;\r | |
195 | \r | |
196 | case EfiResetCold:\r | |
197 | ResetCold ();\r | |
198 | break;\r | |
199 | \r | |
200 | case EfiResetShutdown:\r | |
201 | ResetShutdown ();\r | |
202 | return;\r | |
203 | \r | |
204 | case EfiResetPlatformSpecific:\r | |
205 | ResetPlatformSpecific (DataSize, ResetData);\r | |
206 | return;\r | |
207 | \r | |
208 | default:\r | |
209 | return;\r | |
210 | }\r | |
211 | }\r |