2 PI SMM Status Code Protocol on Framework SMM Status Code Protocol Thunk.
4 This thunk driver produces PI SMM Status Code Protocol and SMM Report Status Code Handler Protocol.
5 And it registers a status code handler within itself to route status codes into Framework SMM Status
8 Note that Framework SMM Status Code Protocol and PI SMM Status Code Protocol have identical protocol
9 GUID and interface structure, but they are in different handle databases.
11 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
12 This program and the accompanying materials are licensed and made available under
13 the terms and conditions of the BSD License that accompanies this distribution.
14 The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php.
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include "PiSmmStatusCodeOnFrameworkSmmStatusCodeThunk.h"
24 LIST_ENTRY mCallbackListHead
= INITIALIZE_LIST_HEAD_VARIABLE (mCallbackListHead
);
27 // Report operation nest status.
28 // If it is set, then the report operation has nested.
30 UINT32 mStatusCodeNestStatus
= 0;
32 EFI_SMM_STATUS_CODE_PROTOCOL mSmmStatusCodeProtocol
= {
36 EFI_SMM_RSC_HANDLER_PROTOCOL mSmmRscHandlerProtocol
= {
41 EFI_SMM_STATUS_CODE_PROTOCOL
*mFrameworkSmmStatusCode
;
44 Register the callback function for ReportStatusCode() notification.
46 When this function is called the function pointer is added to an internal list and any future calls to
47 ReportStatusCode() will be forwarded to the Callback function.
49 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is called
50 when a call to ReportStatusCode() occurs.
52 @retval EFI_SUCCESS Function was successfully registered.
53 @retval EFI_INVALID_PARAMETER The callback function was NULL.
54 @retval EFI_OUT_OF_RESOURCES The internal buffer ran out of space. No more functions can be
56 @retval EFI_ALREADY_STARTED The function was already registered. It can't be registered again.
62 IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
66 SMM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
68 if (Callback
== NULL
) {
69 return EFI_INVALID_PARAMETER
;
72 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
73 CallbackEntry
= CR (Link
, SMM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
74 if (CallbackEntry
->RscHandlerCallback
== Callback
) {
76 // If the function was already registered. It can't be registered again.
78 return EFI_ALREADY_STARTED
;
82 CallbackEntry
= (SMM_RSC_HANDLER_CALLBACK_ENTRY
*)AllocatePool (sizeof (SMM_RSC_HANDLER_CALLBACK_ENTRY
));
83 ASSERT (CallbackEntry
!= NULL
);
85 CallbackEntry
->Signature
= SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
;
86 CallbackEntry
->RscHandlerCallback
= Callback
;
88 InsertTailList (&mCallbackListHead
, &CallbackEntry
->Node
);
94 Remove a previously registered callback function from the notification list.
96 ReportStatusCode() messages will no longer be forwarded to the Callback function.
98 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be
101 @retval EFI_SUCCESS The function was successfully unregistered.
102 @retval EFI_INVALID_PARAMETER The callback function was NULL.
103 @retval EFI_NOT_FOUND The callback function was not found to be unregistered.
109 IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
113 SMM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
115 if (Callback
== NULL
) {
116 return EFI_INVALID_PARAMETER
;
119 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
120 CallbackEntry
= CR (Link
, SMM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
121 if (CallbackEntry
->RscHandlerCallback
== Callback
) {
123 // If the function is found in list, delete it and return.
125 RemoveEntryList (&CallbackEntry
->Node
);
126 FreePool (CallbackEntry
);
131 return EFI_NOT_FOUND
;
136 Provides an interface that a software module can call to report a status code.
138 @param This EFI_SMM_STATUS_CODE_PROTOCOL instance.
139 @param Type Indicates the type of status code being reported.
140 @param Value Describes the current status of a hardware or software entity.
141 This included information about the class and subclass that is used to
142 classify the entity as well as an operation.
143 @param Instance The enumeration of a hardware or software entity within
144 the system. Valid instance numbers start with 1.
145 @param CallerId This optional parameter may be used to identify the caller.
146 This parameter allows the status code driver to apply different rules to
148 @param Data This optional parameter may be used to pass additional data.
150 @retval EFI_SUCCESS The function completed successfully
151 @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.
157 IN CONST EFI_SMM_STATUS_CODE_PROTOCOL
*This
,
158 IN EFI_STATUS_CODE_TYPE Type
,
159 IN EFI_STATUS_CODE_VALUE Value
,
161 IN CONST EFI_GUID
*CallerId OPTIONAL
,
162 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
166 SMM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
169 // Use atom operation to avoid the reentant of report.
170 // If current status is not zero, then the function is reentrancy.
172 if (InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 0, 1) == 1) {
173 return EFI_DEVICE_ERROR
;
176 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
177 CallbackEntry
= CR (Link
, SMM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
179 CallbackEntry
->RscHandlerCallback (
190 // Restore the nest status of report
192 InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 1, 0);
198 This SMM Status Code Handler routes status codes to Framework SMM Status Code Protocol.
200 @param CodeType Indicates the type of status code being reported.
201 @param Value Describes the current status of a hardware or software entity.
202 This included information about the class and subclass that is used to
203 classify the entity as well as an operation.
204 @param Instance The enumeration of a hardware or software entity within
205 the system. Valid instance numbers start with 1.
206 @param CallerId This optional parameter may be used to identify the caller.
207 This parameter allows the status code driver to apply different rules to
209 @param Data This optional parameter may be used to pass additional data.
211 @retval EFI_SUCCESS The function completed successfully.
212 @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.
217 SmmStatusCodeHandler (
218 IN EFI_STATUS_CODE_TYPE CodeType
,
219 IN EFI_STATUS_CODE_VALUE Value
,
221 IN EFI_GUID
*CallerId
,
222 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
225 return mFrameworkSmmStatusCode
->ReportStatusCode (
226 mFrameworkSmmStatusCode
,
236 Entry point of PI SMM Status Code Protocol on Framework SMM Status Code Protocol thunk driver.
238 @param ImageHandle The firmware allocated handle for the EFI image.
239 @param SystemTable A pointer to the EFI System Table.
241 @retval EFI_SUCCESS The entry point is executed successfully.
246 SmmStatusCodeThunkMain (
247 IN EFI_HANDLE ImageHandle
,
248 IN EFI_SYSTEM_TABLE
*SystemTable
255 // Locate Framework SMM Status Code Protocol in UEFI handle database.
257 Status
= SystemTable
->BootServices
->LocateProtocol (
258 &gEfiSmmStatusCodeProtocolGuid
,
260 (VOID
**)&mFrameworkSmmStatusCode
262 ASSERT_EFI_ERROR (Status
);
265 // Registers status code handler to route status codes into Framework SMM Status Code Protocol.
267 Register (SmmStatusCodeHandler
);
272 // Install SmmRscHandler Protocol
274 Status
= gSmst
->SmmInstallProtocolInterface (
276 &gEfiSmmRscHandlerProtocolGuid
,
277 EFI_NATIVE_INTERFACE
,
278 &mSmmRscHandlerProtocol
280 ASSERT_EFI_ERROR (Status
);
283 // Install SmmStatusCode Protocol
285 Status
= gSmst
->SmmInstallProtocolInterface (
287 &gEfiSmmStatusCodeProtocolGuid
,
288 EFI_NATIVE_INTERFACE
,
289 &mSmmStatusCodeProtocol
291 ASSERT_EFI_ERROR (Status
);