]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/ResetSystemRuntimeDxe/ResetSystem.c
MdeModulePkg/ResetSystemRuntimeDxe: Remove DoS3 in warm reset
[mirror_edk2.git] / MdeModulePkg / Universal / ResetSystemRuntimeDxe / ResetSystem.c
CommitLineData
51a0c5f2 1/** @file\r
cf6da556 2 Reset Architectural and Reset Notification protocols implementation.\r
51a0c5f2 3\r
e2531da3 4 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
51a0c5f2 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
4bf95a9f
RN
18GLOBAL_REMOVE_IF_UNREFERENCED CHAR16 *mResetTypeStr[] = {\r
19 L"Cold", L"Warm", L"Shutdown", L"PlatformSpecific"\r
20};\r
21\r
99a6529e
MK
22//\r
23// The current ResetSystem() notification recursion depth\r
24//\r
25UINTN mResetNotifyDepth = 0;\r
26\r
cf6da556
RN
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
99a6529e
MK
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
51a0c5f2 160/**\r
161 The driver's entry point.\r
162\r
163 It initializes the Reset Architectural Protocol.\r
164\r
d1102dba 165 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
51a0c5f2 166 @param[in] SystemTable A pointer to the EFI System Table.\r
d1102dba 167\r
51a0c5f2 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
34861f43 180 EFI_HANDLE Handle;\r
51a0c5f2 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
e2531da3 190 gRT->ResetSystem = RuntimeServiceResetSystem;\r
51a0c5f2 191\r
192 //\r
193 // Now install the Reset RT AP on a new handle\r
194 //\r
34861f43 195 Handle = NULL;\r
51a0c5f2 196 Status = gBS->InstallMultipleProtocolInterfaces (\r
34861f43 197 &Handle,\r
cf6da556
RN
198 &gEfiResetArchProtocolGuid, NULL,\r
199 &gEfiResetNotificationProtocolGuid, &mResetNotification.ResetNotification,\r
99a6529e
MK
200 &gEdkiiPlatformSpecificResetFilterProtocolGuid, &mPlatformSpecificResetFilter.ResetNotification,\r
201 &gEdkiiPlatformSpecificResetHandlerProtocolGuid, &mPlatformSpecificResetHandler.ResetNotification,\r
51a0c5f2 202 NULL\r
203 );\r
204 ASSERT_EFI_ERROR (Status);\r
205\r
206 return Status;\r
207}\r
208\r
51a0c5f2 209/**\r
210 Resets the entire platform.\r
211\r
212 @param[in] ResetType The type of reset to perform.\r
213 @param[in] ResetStatus The status code for the reset.\r
37078045 214 @param[in] DataSize The size, in bytes, of ResetData.\r
51a0c5f2 215 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or\r
216 EfiResetShutdown the data buffer starts with a Null-terminated\r
217 string, optionally followed by additional binary data.\r
37078045
RN
218 The string is a description that the caller may use to further\r
219 indicate the reason for the system reset. ResetData is only\r
220 valid if ResetStatus is something other than EFI_SUCCESS\r
221 unless the ResetType is EfiResetPlatformSpecific\r
222 where a minimum amount of ResetData is always required.\r
eeeabe40
SZ
223 For a ResetType of EfiResetPlatformSpecific the data buffer\r
224 also starts with a Null-terminated string that is followed\r
225 by an EFI_GUID that describes the specific type of reset to perform.\r
51a0c5f2 226**/\r
227VOID\r
228EFIAPI\r
e2531da3 229RuntimeServiceResetSystem (\r
51a0c5f2 230 IN EFI_RESET_TYPE ResetType,\r
231 IN EFI_STATUS ResetStatus,\r
232 IN UINTN DataSize,\r
233 IN VOID *ResetData OPTIONAL\r
234 )\r
235{\r
cf6da556
RN
236 LIST_ENTRY *Link;\r
237 RESET_NOTIFY_ENTRY *Entry;\r
99a6529e 238\r
37623a5c 239 //\r
e2531da3 240 // Only do REPORT_STATUS_CODE() on first call to RuntimeServiceResetSystem()\r
37623a5c 241 //\r
99a6529e
MK
242 if (mResetNotifyDepth == 0) {\r
243 //\r
244 // Indicate reset system runtime service is called.\r
245 //\r
246 REPORT_STATUS_CODE (EFI_PROGRESS_CODE, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE | EFI_SW_RS_PC_RESET_SYSTEM));\r
247 }\r
51a0c5f2 248\r
99a6529e 249 mResetNotifyDepth++;\r
9c227e07
RN
250 DEBUG ((\r
251 DEBUG_INFO, "DXE ResetSystem2: ResetType %s, Call Depth = %d.\n",\r
252 mResetTypeStr[ResetType], mResetNotifyDepth\r
253 ));\r
4bf95a9f
RN
254\r
255 if (mResetNotifyDepth <= MAX_RESET_NOTIFY_DEPTH) {\r
256 if (!EfiAtRuntime ()) {\r
257 //\r
258 // Call reset notification functions registered through the\r
259 // EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PROTOCOL.\r
260 //\r
261 for ( Link = GetFirstNode (&mPlatformSpecificResetFilter.ResetNotifies)\r
262 ; !IsNull (&mPlatformSpecificResetFilter.ResetNotifies, Link)\r
263 ; Link = GetNextNode (&mPlatformSpecificResetFilter.ResetNotifies, Link)\r
264 ) {\r
265 Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
266 Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
267 }\r
268 //\r
269 // Call reset notification functions registered through the\r
270 // EFI_RESET_NOTIFICATION_PROTOCOL.\r
271 //\r
272 for ( Link = GetFirstNode (&mResetNotification.ResetNotifies)\r
273 ; !IsNull (&mResetNotification.ResetNotifies, Link)\r
274 ; Link = GetNextNode (&mResetNotification.ResetNotifies, Link)\r
275 ) {\r
276 Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
277 Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
278 }\r
279 //\r
d1102dba 280 // call reset notification functions registered through the\r
4bf95a9f
RN
281 // EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL.\r
282 //\r
283 for ( Link = GetFirstNode (&mPlatformSpecificResetHandler.ResetNotifies)\r
284 ; !IsNull (&mPlatformSpecificResetHandler.ResetNotifies, Link)\r
285 ; Link = GetNextNode (&mPlatformSpecificResetHandler.ResetNotifies, Link)\r
286 ) {\r
287 Entry = RESET_NOTIFY_ENTRY_FROM_LINK (Link);\r
288 Entry->ResetNotify (ResetType, ResetStatus, DataSize, ResetData);\r
289 }\r
cf6da556 290 }\r
4bf95a9f
RN
291 } else {\r
292 ASSERT (ResetType < ARRAY_SIZE (mResetTypeStr));\r
293 DEBUG ((DEBUG_ERROR, "DXE ResetSystem2: Maximum reset call depth is met. Use the current reset type: %s!\n", mResetTypeStr[ResetType]));\r
cf6da556
RN
294 }\r
295\r
51a0c5f2 296 switch (ResetType) {\r
297 case EfiResetWarm:\r
298\r
51a0c5f2 299 ResetWarm ();\r
51a0c5f2 300 break;\r
301\r
302 case EfiResetCold:\r
303 ResetCold ();\r
304 break;\r
305\r
306 case EfiResetShutdown:\r
307 ResetShutdown ();\r
308 return ;\r
309\r
37078045
RN
310 case EfiResetPlatformSpecific:\r
311 ResetPlatformSpecific (DataSize, ResetData);\r
312 return;\r
313\r
51a0c5f2 314 default:\r
315 return ;\r
316 }\r
317\r
318 //\r
319 // Given we should have reset getting here would be bad\r
320 //\r
321 ASSERT (FALSE);\r
322}\r