]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystem.c
MdeModulePkg: Clean up source files
[mirror_edk2.git] / MdeModulePkg / Universal / ResetSystemRuntimeDxe / ResetSystem.c
... / ...
CommitLineData
1/** @file\r
2 Reset Architectural and Reset Notification protocols implementation.\r
3\r
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
5\r
6 This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include "ResetSystem.h"\r
17\r
18GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mResetTypeStr[] = {\r
19 L"Cold", L"Warm", L"Shutdown", L"PlatformSpecific"\r
20};\r
21\r
22//\r
23// The current ResetSystem() notification recursion depth\r
24//\r
25UINTN mResetNotifyDepth = 0;\r
26\r
27/**\r
28 Register a notification function to be called when ResetSystem() is called.\r
29\r
30 The RegisterResetNotify() function registers a notification function that is called when\r
31 ResetSystem()is called and prior to completing the reset of the platform.\r
32 The registered functions must not perform a platform reset themselves. These\r
33 notifications are intended only for the notification of components which may need some\r
34 special-purpose maintenance prior to the platform resetting.\r
35 The list of registered reset notification functions are processed if ResetSystem()is called\r
36 before ExitBootServices(). The list of registered reset notification functions is ignored if\r
37 ResetSystem()is called after ExitBootServices().\r
38\r
39 @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.\r
40 @param[in] ResetFunction Points to the function to be called when a ResetSystem() is executed.\r
41\r
42 @retval EFI_SUCCESS The reset notification function was successfully registered.\r
43 @retval EFI_INVALID_PARAMETER ResetFunction is NULL.\r
44 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to register the reset notification function.\r
45 @retval EFI_ALREADY_STARTED The reset notification function specified by ResetFunction has already been registered.\r
46\r
47**/\r
48EFI_STATUS\r
49EFIAPI\r
50RegisterResetNotify (\r
51 IN EFI_RESET_NOTIFICATION_PROTOCOL *This,\r
52 IN EFI_RESET_SYSTEM ResetFunction\r
53 )\r
54{\r
55 RESET_NOTIFICATION_INSTANCE *Instance;\r
56 LIST_ENTRY *Link;\r
57 RESET_NOTIFY_ENTRY *Entry;\r
58\r
59 if (ResetFunction == NULL) {\r
60 return EFI_INVALID_PARAMETER;\r
61 }\r
62\r
63 Instance = RESET_NOTIFICATION_INSTANCE_FROM_THIS (This);\r
64\r
65 for ( Link = GetFirstNode (&Instance->ResetNotifies)\r
66 ; !IsNull (&Instance->ResetNotifies, Link)\r
67 ; Link = GetNextNode (&Instance->ResetNotifies, Link)\r
68 ) {\r
69 Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
70 if (Entry->ResetNotify == ResetFunction) {\r
71 return EFI_ALREADY_STARTED;\r
72 }\r
73 }\r
74\r
75 ASSERT (IsNull (&Instance->ResetNotifies, Link));\r
76 Entry = AllocatePool (sizeof (*Entry));\r
77 if (Entry == NULL) {\r
78 return EFI_OUT_OF_RESOURCES;\r
79 }\r
80 Entry->Signature = RESET_NOTIFY_ENTRY_SIGNATURE;\r
81 Entry->ResetNotify = ResetFunction;\r
82 InsertTailList (&Instance->ResetNotifies, &Entry->Link);\r
83 return EFI_SUCCESS;\r
84}\r
85\r
86/**\r
87 Unregister a notification function.\r
88\r
89 The UnregisterResetNotify() function removes the previously registered\r
90 notification using RegisterResetNotify().\r
91\r
92 @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.\r
93 @param[in] ResetFunction The pointer to the ResetFunction being unregistered.\r
94\r
95 @retval EFI_SUCCESS The reset notification function was unregistered.\r
96 @retval EFI_INVALID_PARAMETER ResetFunction is NULL.\r
97 @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously\r
98 registered using RegisterResetNotify().\r
99\r
100**/\r
101EFI_STATUS\r
102EFIAPI\r
103UnregisterResetNotify (\r
104 IN EFI_RESET_NOTIFICATION_PROTOCOL *This,\r
105 IN EFI_RESET_SYSTEM ResetFunction\r
106 )\r
107{\r
108 RESET_NOTIFICATION_INSTANCE *Instance;\r
109 LIST_ENTRY *Link;\r
110 RESET_NOTIFY_ENTRY *Entry;\r
111\r
112 if (ResetFunction == NULL) {\r
113 return EFI_INVALID_PARAMETER;\r
114 }\r
115\r
116 Instance = RESET_NOTIFICATION_INSTANCE_FROM_THIS (This);\r
117\r
118 for ( Link = GetFirstNode (&Instance->ResetNotifies)\r
119 ; !IsNull (&Instance->ResetNotifies, Link)\r
120 ; Link = GetNextNode (&Instance->ResetNotifies, Link)\r
121 ) {\r
122 Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
123 if (Entry->ResetNotify == ResetFunction) {\r
124 RemoveEntryList (&Entry->Link);\r
125 FreePool (Entry);\r
126 return EFI_SUCCESS;\r
127 }\r
128 }\r
129\r
130 return EFI_INVALID_PARAMETER;\r
131}\r
132\r
133RESET_NOTIFICATION_INSTANCE mResetNotification = {\r
134 RESET_NOTIFICATION_INSTANCE_SIGNATURE,\r
135 {\r
136 RegisterResetNotify,\r
137 UnregisterResetNotify\r
138 },\r
139 INITIALIZE_LIST_HEAD_VARIABLE (mResetNotification.ResetNotifies)\r
140};\r
141\r
142RESET_NOTIFICATION_INSTANCE mPlatformSpecificResetFilter = {\r
143 RESET_NOTIFICATION_INSTANCE_SIGNATURE,\r
144 {\r
145 RegisterResetNotify,\r
146 UnregisterResetNotify\r
147 },\r
148 INITIALIZE_LIST_HEAD_VARIABLE (mPlatformSpecificResetFilter.ResetNotifies)\r
149};\r
150\r
151RESET_NOTIFICATION_INSTANCE mPlatformSpecificResetHandler = {\r
152 RESET_NOTIFICATION_INSTANCE_SIGNATURE,\r
153 {\r
154 RegisterResetNotify,\r
155 UnregisterResetNotify\r
156 },\r
157 INITIALIZE_LIST_HEAD_VARIABLE (mPlatformSpecificResetHandler.ResetNotifies)\r
158};\r
159\r
160/**\r
161 The driver's entry point.\r
162\r
163 It initializes the Reset Architectural Protocol.\r
164\r
165 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
166 @param[in] SystemTable A pointer to the EFI System Table.\r
167\r
168 @retval EFI_SUCCESS The entry point is executed successfully.\r
169 @retval other Cannot install ResetArch protocol.\r
170\r
171**/\r
172EFI_STATUS\r
173EFIAPI\r
174InitializeResetSystem (\r
175 IN EFI_HANDLE ImageHandle,\r
176 IN EFI_SYSTEM_TABLE *SystemTable\r
177 )\r
178{\r
179 EFI_STATUS Status;\r
180 EFI_HANDLE Handle;\r
181\r
182 //\r
183 // Make sure the Reset Architectural Protocol is not already installed in the system\r
184 //\r
185 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiResetArchProtocolGuid);\r
186\r
187 //\r
188 // Hook the runtime service table\r
189 //\r
190 gRT->ResetSystem = ResetSystem;\r
191\r
192 //\r
193 // Now install the Reset RT AP on a new handle\r
194 //\r
195 Handle = NULL;\r
196 Status = gBS->InstallMultipleProtocolInterfaces (\r
197 &Handle,\r
198 &gEfiResetArchProtocolGuid, NULL,\r
199 &gEfiResetNotificationProtocolGuid, &mResetNotification.ResetNotification,\r
200 &gEdkiiPlatformSpecificResetFilterProtocolGuid, &mPlatformSpecificResetFilter.ResetNotification,\r
201 &gEdkiiPlatformSpecificResetHandlerProtocolGuid, &mPlatformSpecificResetHandler.ResetNotification,\r
202 NULL\r
203 );\r
204 ASSERT_EFI_ERROR (Status);\r
205\r
206 return Status;\r
207}\r
208\r
209/**\r
210 Put the system into S3 power state.\r
211**/\r
212VOID\r
213DoS3 (\r
214 VOID\r
215 )\r
216{\r
217 EnterS3WithImmediateWake ();\r
218\r
219 //\r
220 // Should not return\r
221 //\r
222 CpuDeadLoop ();\r
223}\r
224\r
225/**\r
226 Resets the entire platform.\r
227\r
228 @param[in] ResetType The type of reset to perform.\r
229 @param[in] ResetStatus The status code for the reset.\r
230 @param[in] DataSize The size, in bytes, of ResetData.\r
231 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or\r
232 EfiResetShutdown the data buffer starts with a Null-terminated\r
233 string, optionally followed by additional binary data.\r
234 The string is a description that the caller may use to further\r
235 indicate the reason for the system reset. ResetData is only\r
236 valid if ResetStatus is something other than EFI_SUCCESS\r
237 unless the ResetType is EfiResetPlatformSpecific\r
238 where a minimum amount of ResetData is always required.\r
239 For a ResetType of EfiResetPlatformSpecific the data buffer\r
240 also starts with a Null-terminated string that is followed\r
241 by an EFI_GUID that describes the specific type of reset to perform.\r
242**/\r
243VOID\r
244EFIAPI\r
245ResetSystem (\r
246 IN EFI_RESET_TYPE ResetType,\r
247 IN EFI_STATUS ResetStatus,\r
248 IN UINTN DataSize,\r
249 IN VOID *ResetData OPTIONAL\r
250 )\r
251{\r
252 EFI_STATUS Status;\r
253 UINTN Size;\r
254 UINTN CapsuleDataPtr;\r
255 LIST_ENTRY *Link;\r
256 RESET_NOTIFY_ENTRY *Entry;\r
257\r
258 //\r
259 // Only do REPORT_STATUS_CODE() on first call to ResetSystem()\r
260 //\r
261 if (mResetNotifyDepth == 0) {\r
262 //\r
263 // Indicate reset system runtime service is called.\r
264 //\r
265 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM));\r
266 }\r
267\r
268 mResetNotifyDepth++;\r
269 DEBUG ((DEBUG_INFO, "DXE ResetSystem2: Reset call depth = %d.\n", mResetNotifyDepth));\r
270\r
271 if (mResetNotifyDepth <= MAX_RESET_NOTIFY_DEPTH) {\r
272 if (!EfiAtRuntime ()) {\r
273 //\r
274 // Call reset notification functions registered through the\r
275 // EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PROTOCOL.\r
276 //\r
277 for ( Link = GetFirstNode (&mPlatformSpecificResetFilter.ResetNotifies)\r
278 ; !IsNull (&mPlatformSpecificResetFilter.ResetNotifies, Link)\r
279 ; Link = GetNextNode (&mPlatformSpecificResetFilter.ResetNotifies, Link)\r
280 ) {\r
281 Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
282 Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
283 }\r
284 //\r
285 // Call reset notification functions registered through the\r
286 // EFI_RESET_NOTIFICATION_PROTOCOL.\r
287 //\r
288 for ( Link = GetFirstNode (&mResetNotification.ResetNotifies)\r
289 ; !IsNull (&mResetNotification.ResetNotifies, Link)\r
290 ; Link = GetNextNode (&mResetNotification.ResetNotifies, Link)\r
291 ) {\r
292 Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
293 Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
294 }\r
295 //\r
296 // call reset notification functions registered through the\r
297 // EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL.\r
298 //\r
299 for ( Link = GetFirstNode (&mPlatformSpecificResetHandler.ResetNotifies)\r
300 ; !IsNull (&mPlatformSpecificResetHandler.ResetNotifies, Link)\r
301 ; Link = GetNextNode (&mPlatformSpecificResetHandler.ResetNotifies, Link)\r
302 ) {\r
303 Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
304 Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
305 }\r
306 }\r
307 } else {\r
308 ASSERT (ResetType < ARRAY_SIZE (mResetTypeStr));\r
309 DEBUG ((DEBUG_ERROR, "DXE ResetSystem2: Maximum reset call depth is met. Use the current reset type: %s!\n", mResetTypeStr[ResetType]));\r
310 }\r
311\r
312 switch (ResetType) {\r
313 case EfiResetWarm:\r
314\r
315 //\r
316 //Check if there are pending capsules to process\r
317 //\r
318 Size = sizeof (CapsuleDataPtr);\r
319 Status = EfiGetVariable (\r
320 EFI_CAPSULE_VARIABLE_NAME,\r
321 &gEfiCapsuleVendorGuid,\r
322 NULL,\r
323 &Size,\r
324 (VOID *) &CapsuleDataPtr\r
325 );\r
326\r
327 if (Status == EFI_SUCCESS) {\r
328 //\r
329 //Process capsules across a system reset.\r
330 //\r
331 DoS3();\r
332 }\r
333\r
334 ResetWarm ();\r
335 break;\r
336\r
337 case EfiResetCold:\r
338 ResetCold ();\r
339 break;\r
340\r
341 case EfiResetShutdown:\r
342 ResetShutdown ();\r
343 return ;\r
344\r
345 case EfiResetPlatformSpecific:\r
346 ResetPlatformSpecific (DataSize, ResetData);\r
347 return;\r
348\r
349 default:\r
350 return ;\r
351 }\r
352\r
353 //\r
354 // Given we should have reset getting here would be bad\r
355 //\r
356 ASSERT (FALSE);\r
357}\r