2 Reset Architectural and Reset Notification protocols implementation.
4 Copyright (c) 2006 - 2017, 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"
19 // The current ResetSystem() notification recursion depth
21 UINTN mResetNotifyDepth
= 0;
24 Register a notification function to be called when ResetSystem() is called.
26 The RegisterResetNotify() function registers a notification function that is called when
27 ResetSystem()is called and prior to completing the reset of the platform.
28 The registered functions must not perform a platform reset themselves. These
29 notifications are intended only for the notification of components which may need some
30 special-purpose maintenance prior to the platform resetting.
31 The list of registered reset notification functions are processed if ResetSystem()is called
32 before ExitBootServices(). The list of registered reset notification functions is ignored if
33 ResetSystem()is called after ExitBootServices().
35 @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.
36 @param[in] ResetFunction Points to the function to be called when a ResetSystem() is executed.
38 @retval EFI_SUCCESS The reset notification function was successfully registered.
39 @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
40 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to register the reset notification function.
41 @retval EFI_ALREADY_STARTED The reset notification function specified by ResetFunction has already been registered.
47 IN EFI_RESET_NOTIFICATION_PROTOCOL
*This
,
48 IN EFI_RESET_SYSTEM ResetFunction
51 RESET_NOTIFICATION_INSTANCE
*Instance
;
53 RESET_NOTIFY_ENTRY
*Entry
;
55 if (ResetFunction
== NULL
) {
56 return EFI_INVALID_PARAMETER
;
59 Instance
= RESET_NOTIFICATION_INSTANCE_FROM_THIS (This
);
61 for ( Link
= GetFirstNode (&Instance
->ResetNotifies
)
62 ; !IsNull (&Instance
->ResetNotifies
, Link
)
63 ; Link
= GetNextNode (&Instance
->ResetNotifies
, Link
)
65 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
66 if (Entry
->ResetNotify
== ResetFunction
) {
67 return EFI_ALREADY_STARTED
;
71 ASSERT (IsNull (&Instance
->ResetNotifies
, Link
));
72 Entry
= AllocatePool (sizeof (*Entry
));
74 return EFI_OUT_OF_RESOURCES
;
76 Entry
->Signature
= RESET_NOTIFY_ENTRY_SIGNATURE
;
77 Entry
->ResetNotify
= ResetFunction
;
78 InsertTailList (&Instance
->ResetNotifies
, &Entry
->Link
);
83 Unregister a notification function.
85 The UnregisterResetNotify() function removes the previously registered
86 notification using RegisterResetNotify().
88 @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.
89 @param[in] ResetFunction The pointer to the ResetFunction being unregistered.
91 @retval EFI_SUCCESS The reset notification function was unregistered.
92 @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
93 @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously
94 registered using RegisterResetNotify().
99 UnregisterResetNotify (
100 IN EFI_RESET_NOTIFICATION_PROTOCOL
*This
,
101 IN EFI_RESET_SYSTEM ResetFunction
104 RESET_NOTIFICATION_INSTANCE
*Instance
;
106 RESET_NOTIFY_ENTRY
*Entry
;
108 if (ResetFunction
== NULL
) {
109 return EFI_INVALID_PARAMETER
;
112 Instance
= RESET_NOTIFICATION_INSTANCE_FROM_THIS (This
);
114 for ( Link
= GetFirstNode (&Instance
->ResetNotifies
)
115 ; !IsNull (&Instance
->ResetNotifies
, Link
)
116 ; Link
= GetNextNode (&Instance
->ResetNotifies
, Link
)
118 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
119 if (Entry
->ResetNotify
== ResetFunction
) {
120 RemoveEntryList (&Entry
->Link
);
126 return EFI_INVALID_PARAMETER
;
129 RESET_NOTIFICATION_INSTANCE mResetNotification
= {
130 RESET_NOTIFICATION_INSTANCE_SIGNATURE
,
133 UnregisterResetNotify
135 INITIALIZE_LIST_HEAD_VARIABLE (mResetNotification
.ResetNotifies
)
138 RESET_NOTIFICATION_INSTANCE mPlatformSpecificResetFilter
= {
139 RESET_NOTIFICATION_INSTANCE_SIGNATURE
,
142 UnregisterResetNotify
144 INITIALIZE_LIST_HEAD_VARIABLE (mPlatformSpecificResetFilter
.ResetNotifies
)
147 RESET_NOTIFICATION_INSTANCE mPlatformSpecificResetHandler
= {
148 RESET_NOTIFICATION_INSTANCE_SIGNATURE
,
151 UnregisterResetNotify
153 INITIALIZE_LIST_HEAD_VARIABLE (mPlatformSpecificResetHandler
.ResetNotifies
)
157 The driver's entry point.
159 It initializes the Reset Architectural Protocol.
161 @param[in] ImageHandle The firmware allocated handle for the EFI image.
162 @param[in] SystemTable A pointer to the EFI System Table.
164 @retval EFI_SUCCESS The entry point is executed successfully.
165 @retval other Cannot install ResetArch protocol.
170 InitializeResetSystem (
171 IN EFI_HANDLE ImageHandle
,
172 IN EFI_SYSTEM_TABLE
*SystemTable
179 // Make sure the Reset Architectural Protocol is not already installed in the system
181 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiResetArchProtocolGuid
);
184 // Hook the runtime service table
186 gRT
->ResetSystem
= ResetSystem
;
189 // Now install the Reset RT AP on a new handle
192 Status
= gBS
->InstallMultipleProtocolInterfaces (
194 &gEfiResetArchProtocolGuid
, NULL
,
195 &gEfiResetNotificationProtocolGuid
, &mResetNotification
.ResetNotification
,
196 &gEdkiiPlatformSpecificResetFilterProtocolGuid
, &mPlatformSpecificResetFilter
.ResetNotification
,
197 &gEdkiiPlatformSpecificResetHandlerProtocolGuid
, &mPlatformSpecificResetHandler
.ResetNotification
,
200 ASSERT_EFI_ERROR (Status
);
206 Put the system into S3 power state.
213 EnterS3WithImmediateWake ();
222 Resets the entire platform.
224 @param[in] ResetType The type of reset to perform.
225 @param[in] ResetStatus The status code for the reset.
226 @param[in] DataSize The size, in bytes, of ResetData.
227 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
228 EfiResetShutdown the data buffer starts with a Null-terminated
229 string, optionally followed by additional binary data.
230 The string is a description that the caller may use to further
231 indicate the reason for the system reset. ResetData is only
232 valid if ResetStatus is something other than EFI_SUCCESS
233 unless the ResetType is EfiResetPlatformSpecific
234 where a minimum amount of ResetData is always required.
235 For a ResetType of EfiResetPlatformSpecific the data buffer
236 also starts with a Null-terminated string that is followed
237 by an EFI_GUID that describes the specific type of reset to perform.
242 IN EFI_RESET_TYPE ResetType
,
243 IN EFI_STATUS ResetStatus
,
245 IN VOID
*ResetData OPTIONAL
250 UINTN CapsuleDataPtr
;
252 RESET_NOTIFY_ENTRY
*Entry
;
255 // Above the maximum recursion depth, so do the smallest amount of
256 // work to perform a cold reset.
258 if (mResetNotifyDepth
>= MAX_RESET_NOTIFY_DEPTH
) {
265 // Only do REPORT_STATUS_CODE() on first call to ResetSystem()
267 if (mResetNotifyDepth
== 0) {
269 // Indicate reset system runtime service is called.
271 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE
| EFI_SW_RS_PC_RESET_SYSTEM
));
275 if (!EfiAtRuntime () && mResetNotifyDepth
< MAX_RESET_NOTIFY_DEPTH
) {
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
);
315 //Check if there are pending capsules to process
317 Size
= sizeof (CapsuleDataPtr
);
318 Status
= EfiGetVariable (
319 EFI_CAPSULE_VARIABLE_NAME
,
320 &gEfiCapsuleVendorGuid
,
323 (VOID
*) &CapsuleDataPtr
326 if (Status
== EFI_SUCCESS
) {
328 //Process capsules across a system reset.
341 case EfiResetShutdown
:
345 case EfiResetPlatformSpecific
:
346 ResetPlatformSpecific (DataSize
, ResetData
);
354 // Given we should have reset getting here would be bad