2 Reset Architectural and Reset Notification protocols implementation.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "ResetSystem.h"
18 GLOBAL_REMOVE_IF_UNREFERENCED CHAR16
*mResetTypeStr
[] = {
19 L
"Cold", L
"Warm", L
"Shutdown", L
"PlatformSpecific"
23 // The current ResetSystem() notification recursion depth
25 UINTN mResetNotifyDepth
= 0;
28 Register a notification function to be called when ResetSystem() is called.
30 The RegisterResetNotify() function registers a notification function that is called when
31 ResetSystem()is called and prior to completing the reset of the platform.
32 The registered functions must not perform a platform reset themselves. These
33 notifications are intended only for the notification of components which may need some
34 special-purpose maintenance prior to the platform resetting.
35 The list of registered reset notification functions are processed if ResetSystem()is called
36 before ExitBootServices(). The list of registered reset notification functions is ignored if
37 ResetSystem()is called after ExitBootServices().
39 @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.
40 @param[in] ResetFunction Points to the function to be called when a ResetSystem() is executed.
42 @retval EFI_SUCCESS The reset notification function was successfully registered.
43 @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
44 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to register the reset notification function.
45 @retval EFI_ALREADY_STARTED The reset notification function specified by ResetFunction has already been registered.
51 IN EFI_RESET_NOTIFICATION_PROTOCOL
*This
,
52 IN EFI_RESET_SYSTEM ResetFunction
55 RESET_NOTIFICATION_INSTANCE
*Instance
;
57 RESET_NOTIFY_ENTRY
*Entry
;
59 if (ResetFunction
== NULL
) {
60 return EFI_INVALID_PARAMETER
;
63 Instance
= RESET_NOTIFICATION_INSTANCE_FROM_THIS (This
);
65 for ( Link
= GetFirstNode (&Instance
->ResetNotifies
)
66 ; !IsNull (&Instance
->ResetNotifies
, Link
)
67 ; Link
= GetNextNode (&Instance
->ResetNotifies
, Link
)
69 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
70 if (Entry
->ResetNotify
== ResetFunction
) {
71 return EFI_ALREADY_STARTED
;
75 ASSERT (IsNull (&Instance
->ResetNotifies
, Link
));
76 Entry
= AllocatePool (sizeof (*Entry
));
78 return EFI_OUT_OF_RESOURCES
;
80 Entry
->Signature
= RESET_NOTIFY_ENTRY_SIGNATURE
;
81 Entry
->ResetNotify
= ResetFunction
;
82 InsertTailList (&Instance
->ResetNotifies
, &Entry
->Link
);
87 Unregister a notification function.
89 The UnregisterResetNotify() function removes the previously registered
90 notification using RegisterResetNotify().
92 @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.
93 @param[in] ResetFunction The pointer to the ResetFunction being unregistered.
95 @retval EFI_SUCCESS The reset notification function was unregistered.
96 @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
97 @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously
98 registered using RegisterResetNotify().
103 UnregisterResetNotify (
104 IN EFI_RESET_NOTIFICATION_PROTOCOL
*This
,
105 IN EFI_RESET_SYSTEM ResetFunction
108 RESET_NOTIFICATION_INSTANCE
*Instance
;
110 RESET_NOTIFY_ENTRY
*Entry
;
112 if (ResetFunction
== NULL
) {
113 return EFI_INVALID_PARAMETER
;
116 Instance
= RESET_NOTIFICATION_INSTANCE_FROM_THIS (This
);
118 for ( Link
= GetFirstNode (&Instance
->ResetNotifies
)
119 ; !IsNull (&Instance
->ResetNotifies
, Link
)
120 ; Link
= GetNextNode (&Instance
->ResetNotifies
, Link
)
122 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
123 if (Entry
->ResetNotify
== ResetFunction
) {
124 RemoveEntryList (&Entry
->Link
);
130 return EFI_INVALID_PARAMETER
;
133 RESET_NOTIFICATION_INSTANCE mResetNotification
= {
134 RESET_NOTIFICATION_INSTANCE_SIGNATURE
,
137 UnregisterResetNotify
139 INITIALIZE_LIST_HEAD_VARIABLE (mResetNotification
.ResetNotifies
)
142 RESET_NOTIFICATION_INSTANCE mPlatformSpecificResetFilter
= {
143 RESET_NOTIFICATION_INSTANCE_SIGNATURE
,
146 UnregisterResetNotify
148 INITIALIZE_LIST_HEAD_VARIABLE (mPlatformSpecificResetFilter
.ResetNotifies
)
151 RESET_NOTIFICATION_INSTANCE mPlatformSpecificResetHandler
= {
152 RESET_NOTIFICATION_INSTANCE_SIGNATURE
,
155 UnregisterResetNotify
157 INITIALIZE_LIST_HEAD_VARIABLE (mPlatformSpecificResetHandler
.ResetNotifies
)
161 The driver's entry point.
163 It initializes the Reset Architectural Protocol.
165 @param[in] ImageHandle The firmware allocated handle for the EFI image.
166 @param[in] SystemTable A pointer to the EFI System Table.
168 @retval EFI_SUCCESS The entry point is executed successfully.
169 @retval other Cannot install ResetArch protocol.
174 InitializeResetSystem (
175 IN EFI_HANDLE ImageHandle
,
176 IN EFI_SYSTEM_TABLE
*SystemTable
183 // Make sure the Reset Architectural Protocol is not already installed in the system
185 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiResetArchProtocolGuid
);
188 // Hook the runtime service table
190 gRT
->ResetSystem
= ResetSystem
;
193 // Now install the Reset RT AP on a new handle
196 Status
= gBS
->InstallMultipleProtocolInterfaces (
198 &gEfiResetArchProtocolGuid
, NULL
,
199 &gEfiResetNotificationProtocolGuid
, &mResetNotification
.ResetNotification
,
200 &gEdkiiPlatformSpecificResetFilterProtocolGuid
, &mPlatformSpecificResetFilter
.ResetNotification
,
201 &gEdkiiPlatformSpecificResetHandlerProtocolGuid
, &mPlatformSpecificResetHandler
.ResetNotification
,
204 ASSERT_EFI_ERROR (Status
);
210 Put the system into S3 power state.
217 EnterS3WithImmediateWake ();
226 Resets the entire platform.
228 @param[in] ResetType The type of reset to perform.
229 @param[in] ResetStatus The status code for the reset.
230 @param[in] DataSize The size, in bytes, of ResetData.
231 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
232 EfiResetShutdown the data buffer starts with a Null-terminated
233 string, optionally followed by additional binary data.
234 The string is a description that the caller may use to further
235 indicate the reason for the system reset. ResetData is only
236 valid if ResetStatus is something other than EFI_SUCCESS
237 unless the ResetType is EfiResetPlatformSpecific
238 where a minimum amount of ResetData is always required.
239 For a ResetType of EfiResetPlatformSpecific the data buffer
240 also starts with a Null-terminated string that is followed
241 by an EFI_GUID that describes the specific type of reset to perform.
246 IN EFI_RESET_TYPE ResetType
,
247 IN EFI_STATUS ResetStatus
,
249 IN VOID
*ResetData OPTIONAL
254 UINTN CapsuleDataPtr
;
256 RESET_NOTIFY_ENTRY
*Entry
;
259 // Only do REPORT_STATUS_CODE() on first call to ResetSystem()
261 if (mResetNotifyDepth
== 0) {
263 // Indicate reset system runtime service is called.
265 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE
| EFI_SW_RS_PC_RESET_SYSTEM
));
270 DEBUG_INFO
, "DXE ResetSystem2: ResetType %s, Call Depth = %d.\n",
271 mResetTypeStr
[ResetType
], mResetNotifyDepth
274 if (mResetNotifyDepth
<= MAX_RESET_NOTIFY_DEPTH
) {
275 if (!EfiAtRuntime ()) {
277 // Call reset notification functions registered through the
278 // EDKII_PLATFORM_SPECIFIC_RESET_FILTER_PROTOCOL.
280 for ( Link
= GetFirstNode (&mPlatformSpecificResetFilter
.ResetNotifies
)
281 ; !IsNull (&mPlatformSpecificResetFilter
.ResetNotifies
, Link
)
282 ; Link
= GetNextNode (&mPlatformSpecificResetFilter
.ResetNotifies
, Link
)
284 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
285 Entry
->ResetNotify (ResetType
, ResetStatus
, DataSize
, ResetData
);
288 // Call reset notification functions registered through the
289 // EFI_RESET_NOTIFICATION_PROTOCOL.
291 for ( Link
= GetFirstNode (&mResetNotification
.ResetNotifies
)
292 ; !IsNull (&mResetNotification
.ResetNotifies
, Link
)
293 ; Link
= GetNextNode (&mResetNotification
.ResetNotifies
, Link
)
295 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
296 Entry
->ResetNotify (ResetType
, ResetStatus
, DataSize
, ResetData
);
299 // call reset notification functions registered through the
300 // EDKII_PLATFORM_SPECIFIC_RESET_HANDLER_PROTOCOL.
302 for ( Link
= GetFirstNode (&mPlatformSpecificResetHandler
.ResetNotifies
)
303 ; !IsNull (&mPlatformSpecificResetHandler
.ResetNotifies
, Link
)
304 ; Link
= GetNextNode (&mPlatformSpecificResetHandler
.ResetNotifies
, Link
)
306 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
307 Entry
->ResetNotify (ResetType
, ResetStatus
, DataSize
, ResetData
);
311 ASSERT (ResetType
< ARRAY_SIZE (mResetTypeStr
));
312 DEBUG ((DEBUG_ERROR
, "DXE ResetSystem2: Maximum reset call depth is met. Use the current reset type: %s!\n", mResetTypeStr
[ResetType
]));
319 //Check if there are pending capsules to process
321 Size
= sizeof (CapsuleDataPtr
);
322 Status
= EfiGetVariable (
323 EFI_CAPSULE_VARIABLE_NAME
,
324 &gEfiCapsuleVendorGuid
,
327 (VOID
*) &CapsuleDataPtr
330 if (Status
== EFI_SUCCESS
) {
332 //Process capsules across a system reset.
344 case EfiResetShutdown
:
348 case EfiResetPlatformSpecific
:
349 ResetPlatformSpecific (DataSize
, ResetData
);
357 // Given we should have reset getting here would be bad