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 Register a notification function to be called when ResetSystem() is called.
21 The RegisterResetNotify() function registers a notification function that is called when
22 ResetSystem()is called and prior to completing the reset of the platform.
23 The registered functions must not perform a platform reset themselves. These
24 notifications are intended only for the notification of components which may need some
25 special-purpose maintenance prior to the platform resetting.
26 The list of registered reset notification functions are processed if ResetSystem()is called
27 before ExitBootServices(). The list of registered reset notification functions is ignored if
28 ResetSystem()is called after ExitBootServices().
30 @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.
31 @param[in] ResetFunction Points to the function to be called when a ResetSystem() is executed.
33 @retval EFI_SUCCESS The reset notification function was successfully registered.
34 @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
35 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to register the reset notification function.
36 @retval EFI_ALREADY_STARTED The reset notification function specified by ResetFunction has already been registered.
42 IN EFI_RESET_NOTIFICATION_PROTOCOL
*This
,
43 IN EFI_RESET_SYSTEM ResetFunction
46 RESET_NOTIFICATION_INSTANCE
*Instance
;
48 RESET_NOTIFY_ENTRY
*Entry
;
50 if (ResetFunction
== NULL
) {
51 return EFI_INVALID_PARAMETER
;
54 Instance
= RESET_NOTIFICATION_INSTANCE_FROM_THIS (This
);
56 for ( Link
= GetFirstNode (&Instance
->ResetNotifies
)
57 ; !IsNull (&Instance
->ResetNotifies
, Link
)
58 ; Link
= GetNextNode (&Instance
->ResetNotifies
, Link
)
60 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
61 if (Entry
->ResetNotify
== ResetFunction
) {
62 return EFI_ALREADY_STARTED
;
66 ASSERT (IsNull (&Instance
->ResetNotifies
, Link
));
67 Entry
= AllocatePool (sizeof (*Entry
));
69 return EFI_OUT_OF_RESOURCES
;
71 Entry
->Signature
= RESET_NOTIFY_ENTRY_SIGNATURE
;
72 Entry
->ResetNotify
= ResetFunction
;
73 InsertTailList (&Instance
->ResetNotifies
, &Entry
->Link
);
78 Unregister a notification function.
80 The UnregisterResetNotify() function removes the previously registered
81 notification using RegisterResetNotify().
83 @param[in] This A pointer to the EFI_RESET_NOTIFICATION_PROTOCOL instance.
84 @param[in] ResetFunction The pointer to the ResetFunction being unregistered.
86 @retval EFI_SUCCESS The reset notification function was unregistered.
87 @retval EFI_INVALID_PARAMETER ResetFunction is NULL.
88 @retval EFI_INVALID_PARAMETER The reset notification function specified by ResetFunction was not previously
89 registered using RegisterResetNotify().
94 UnregisterResetNotify (
95 IN EFI_RESET_NOTIFICATION_PROTOCOL
*This
,
96 IN EFI_RESET_SYSTEM ResetFunction
99 RESET_NOTIFICATION_INSTANCE
*Instance
;
101 RESET_NOTIFY_ENTRY
*Entry
;
103 if (ResetFunction
== NULL
) {
104 return EFI_INVALID_PARAMETER
;
107 Instance
= RESET_NOTIFICATION_INSTANCE_FROM_THIS (This
);
109 for ( Link
= GetFirstNode (&Instance
->ResetNotifies
)
110 ; !IsNull (&Instance
->ResetNotifies
, Link
)
111 ; Link
= GetNextNode (&Instance
->ResetNotifies
, Link
)
113 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
114 if (Entry
->ResetNotify
== ResetFunction
) {
115 RemoveEntryList (&Entry
->Link
);
121 return EFI_INVALID_PARAMETER
;
124 RESET_NOTIFICATION_INSTANCE mResetNotification
= {
125 RESET_NOTIFICATION_INSTANCE_SIGNATURE
,
128 UnregisterResetNotify
130 INITIALIZE_LIST_HEAD_VARIABLE (mResetNotification
.ResetNotifies
)
134 The driver's entry point.
136 It initializes the Reset Architectural Protocol.
138 @param[in] ImageHandle The firmware allocated handle for the EFI image.
139 @param[in] SystemTable A pointer to the EFI System Table.
141 @retval EFI_SUCCESS The entry point is executed successfully.
142 @retval other Cannot install ResetArch protocol.
147 InitializeResetSystem (
148 IN EFI_HANDLE ImageHandle
,
149 IN EFI_SYSTEM_TABLE
*SystemTable
156 // Make sure the Reset Architectural Protocol is not already installed in the system
158 ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL
, &gEfiResetArchProtocolGuid
);
161 // Hook the runtime service table
163 gRT
->ResetSystem
= ResetSystem
;
166 // Now install the Reset RT AP on a new handle
169 Status
= gBS
->InstallMultipleProtocolInterfaces (
171 &gEfiResetArchProtocolGuid
, NULL
,
172 &gEfiResetNotificationProtocolGuid
, &mResetNotification
.ResetNotification
,
175 ASSERT_EFI_ERROR (Status
);
181 Put the system into S3 power state.
188 EnterS3WithImmediateWake ();
197 Resets the entire platform.
199 @param[in] ResetType The type of reset to perform.
200 @param[in] ResetStatus The status code for the reset.
201 @param[in] DataSize The size, in bytes, of ResetData.
202 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
203 EfiResetShutdown the data buffer starts with a Null-terminated
204 string, optionally followed by additional binary data.
205 The string is a description that the caller may use to further
206 indicate the reason for the system reset. ResetData is only
207 valid if ResetStatus is something other than EFI_SUCCESS
208 unless the ResetType is EfiResetPlatformSpecific
209 where a minimum amount of ResetData is always required.
210 For a ResetType of EfiResetPlatformSpecific the data buffer
211 also starts with a Null-terminated string that is followed
212 by an EFI_GUID that describes the specific type of reset to perform.
217 IN EFI_RESET_TYPE ResetType
,
218 IN EFI_STATUS ResetStatus
,
220 IN VOID
*ResetData OPTIONAL
225 UINTN CapsuleDataPtr
;
227 RESET_NOTIFY_ENTRY
*Entry
;
230 // Indicate reset system runtime service is called.
232 REPORT_STATUS_CODE (EFI_PROGRESS_CODE
, (EFI_SOFTWARE_EFI_RUNTIME_SERVICE
| EFI_SW_RS_PC_RESET_SYSTEM
));
234 if (!EfiAtRuntime ()) {
235 for ( Link
= GetFirstNode (&mResetNotification
.ResetNotifies
)
236 ; !IsNull (&mResetNotification
.ResetNotifies
, Link
)
237 ; Link
= GetNextNode (&mResetNotification
.ResetNotifies
, Link
)
239 Entry
= RESET_NOTIFY_ENTRY_FROM_LINK (Link
);
240 Entry
->ResetNotify (ResetType
, ResetStatus
, DataSize
, ResetData
);
248 //Check if there are pending capsules to process
250 Size
= sizeof (CapsuleDataPtr
);
251 Status
= EfiGetVariable (
252 EFI_CAPSULE_VARIABLE_NAME
,
253 &gEfiCapsuleVendorGuid
,
256 (VOID
*) &CapsuleDataPtr
259 if (Status
== EFI_SUCCESS
) {
261 //Process capsules across a system reset.
274 case EfiResetShutdown
:
278 case EfiResetPlatformSpecific
:
279 ResetPlatformSpecific (DataSize
, ResetData
);
287 // Given we should have reset getting here would be bad