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.
216 SmmStatusCodeHandler (
217 IN EFI_STATUS_CODE_TYPE CodeType
,
218 IN EFI_STATUS_CODE_VALUE Value
,
220 IN EFI_GUID
*CallerId
,
221 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
224 return mFrameworkSmmStatusCode
->ReportStatusCode (
225 mFrameworkSmmStatusCode
,
235 Entry point of PI SMM Status Code Protocol on Framework SMM Status Code Protocol thunk driver.
237 @param ImageHandle The firmware allocated handle for the EFI image.
238 @param SystemTable A pointer to the EFI System Table.
240 @retval EFI_SUCCESS The entry point is executed successfully.
245 SmmStatusCodeThunkMain (
246 IN EFI_HANDLE ImageHandle
,
247 IN EFI_SYSTEM_TABLE
*SystemTable
254 // Locate Framework SMM Status Code Protocol in UEFI handle database.
256 Status
= SystemTable
->BootServices
->LocateProtocol (
257 &gEfiSmmStatusCodeProtocolGuid
,
259 (VOID
**)&mFrameworkSmmStatusCode
261 ASSERT_EFI_ERROR (Status
);
264 // Registers status code handler to route status codes into Framework SMM Status Code Protocol.
266 Register (SmmStatusCodeHandler
);
271 // Install SmmRscHandler Protocol
273 Status
= gSmst
->SmmInstallProtocolInterface (
275 &gEfiSmmRscHandlerProtocolGuid
,
276 EFI_NATIVE_INTERFACE
,
277 &mSmmRscHandlerProtocol
279 ASSERT_EFI_ERROR (Status
);
282 // Install SmmStatusCode Protocol
284 Status
= gSmst
->SmmInstallProtocolInterface (
286 &gEfiSmmStatusCodeProtocolGuid
,
287 EFI_NATIVE_INTERFACE
,
288 &mSmmStatusCodeProtocol
290 ASSERT_EFI_ERROR (Status
);
295 PI SMM Status Code Protocol on Framework SMM Status Code Protocol Thunk.
297 This thunk driver produces PI SMM Status Code Protocol and SMM Report Status Code Handler Protocol.
298 And it registers a status code handler within itself to route status codes into Framework SMM Status
301 Note that Framework SMM Status Code Protocol and PI SMM Status Code Protocol have identical protocol
302 GUID and interface structure, but they are in different handle databases.
304 Copyright (c) 2010, Intel Corporation. All rights reserved<BR>
305 This program and the accompanying materials are licensed and made available under
306 the terms and conditions of the BSD License that accompanies this distribution.
307 The full text of the license may be found at
308 http://opensource.org/licenses/bsd-license.php.
310 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
311 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
315 #include "PiSmmStatusCodeOnFrameworkSmmStatusCodeThunk.h"
317 LIST_ENTRY mCallbackListHead
= INITIALIZE_LIST_HEAD_VARIABLE (mCallbackListHead
);
320 // Report operation nest status.
321 // If it is set, then the report operation has nested.
323 UINT32 mStatusCodeNestStatus
= 0;
325 EFI_SMM_STATUS_CODE_PROTOCOL mSmmStatusCodeProtocol
= {
329 EFI_SMM_RSC_HANDLER_PROTOCOL mSmmRscHandlerProtocol
= {
334 EFI_SMM_STATUS_CODE_PROTOCOL
*mFrameworkSmmStatusCode
;
337 Register the callback function for ReportStatusCode() notification.
339 When this function is called the function pointer is added to an internal list and any future calls to
340 ReportStatusCode() will be forwarded to the Callback function.
342 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is called
343 when a call to ReportStatusCode() occurs.
345 @retval EFI_SUCCESS Function was successfully registered.
346 @retval EFI_INVALID_PARAMETER The callback function was NULL.
347 @retval EFI_OUT_OF_RESOURCES The internal buffer ran out of space. No more functions can be
349 @retval EFI_ALREADY_STARTED The function was already registered. It can't be registered again.
355 IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
359 SMM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
361 if (Callback
== NULL
) {
362 return EFI_INVALID_PARAMETER
;
365 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
366 CallbackEntry
= CR (Link
, SMM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
367 if (CallbackEntry
->RscHandlerCallback
== Callback
) {
369 // If the function was already registered. It can't be registered again.
371 return EFI_ALREADY_STARTED
;
375 CallbackEntry
= (SMM_RSC_HANDLER_CALLBACK_ENTRY
*)AllocatePool (sizeof (SMM_RSC_HANDLER_CALLBACK_ENTRY
));
376 ASSERT (CallbackEntry
!= NULL
);
378 CallbackEntry
->Signature
= SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
;
379 CallbackEntry
->RscHandlerCallback
= Callback
;
381 InsertTailList (&mCallbackListHead
, &CallbackEntry
->Node
);
387 Remove a previously registered callback function from the notification list.
389 ReportStatusCode() messages will no longer be forwarded to the Callback function.
391 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be
394 @retval EFI_SUCCESS The function was successfully unregistered.
395 @retval EFI_INVALID_PARAMETER The callback function was NULL.
396 @retval EFI_NOT_FOUND The callback function was not found to be unregistered.
402 IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
406 SMM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
408 if (Callback
== NULL
) {
409 return EFI_INVALID_PARAMETER
;
412 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
413 CallbackEntry
= CR (Link
, SMM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
414 if (CallbackEntry
->RscHandlerCallback
== Callback
) {
416 // If the function is found in list, delete it and return.
418 RemoveEntryList (&CallbackEntry
->Node
);
419 FreePool (CallbackEntry
);
424 return EFI_NOT_FOUND
;
429 Provides an interface that a software module can call to report a status code.
431 @param This EFI_SMM_STATUS_CODE_PROTOCOL instance.
432 @param Type Indicates the type of status code being reported.
433 @param Value Describes the current status of a hardware or software entity.
434 This included information about the class and subclass that is used to
435 classify the entity as well as an operation.
436 @param Instance The enumeration of a hardware or software entity within
437 the system. Valid instance numbers start with 1.
438 @param CallerId This optional parameter may be used to identify the caller.
439 This parameter allows the status code driver to apply different rules to
441 @param Data This optional parameter may be used to pass additional data.
443 @retval EFI_SUCCESS The function completed successfully
444 @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.
450 IN CONST EFI_SMM_STATUS_CODE_PROTOCOL
*This
,
451 IN EFI_STATUS_CODE_TYPE Type
,
452 IN EFI_STATUS_CODE_VALUE Value
,
454 IN CONST EFI_GUID
*CallerId OPTIONAL
,
455 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
459 SMM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
462 // Use atom operation to avoid the reentant of report.
463 // If current status is not zero, then the function is reentrancy.
465 if (InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 0, 1) == 1) {
466 return EFI_DEVICE_ERROR
;
469 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
470 CallbackEntry
= CR (Link
, SMM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
472 CallbackEntry
->RscHandlerCallback (
483 // Restore the nest status of report
485 InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 1, 0);
491 This SMM Status Code Handler routes status codes to Framework SMM Status Code Protocol.
493 @param CodeType Indicates the type of status code being reported.
494 @param Value Describes the current status of a hardware or software entity.
495 This included information about the class and subclass that is used to
496 classify the entity as well as an operation.
497 @param Instance The enumeration of a hardware or software entity within
498 the system. Valid instance numbers start with 1.
499 @param CallerId This optional parameter may be used to identify the caller.
500 This parameter allows the status code driver to apply different rules to
502 @param Data This optional parameter may be used to pass additional data.
504 @retval EFI_SUCCESS The function completed successfully.
505 @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.
509 SmmStatusCodeHandler (
510 IN EFI_STATUS_CODE_TYPE CodeType
,
511 IN EFI_STATUS_CODE_VALUE Value
,
513 IN EFI_GUID
*CallerId
,
514 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
517 return mFrameworkSmmStatusCode
->ReportStatusCode (
518 mFrameworkSmmStatusCode
,
528 Entry point of PI SMM Status Code Protocol on Framework SMM Status Code Protocol thunk driver.
530 @param ImageHandle The firmware allocated handle for the EFI image.
531 @param SystemTable A pointer to the EFI System Table.
533 @retval EFI_SUCCESS The entry point is executed successfully.
538 SmmStatusCodeThunkMain (
539 IN EFI_HANDLE ImageHandle
,
540 IN EFI_SYSTEM_TABLE
*SystemTable
547 // Locate Framework SMM Status Code Protocol in UEFI handle database.
549 Status
= SystemTable
->BootServices
->LocateProtocol (
550 &gEfiSmmStatusCodeProtocolGuid
,
552 (VOID
**)&mFrameworkSmmStatusCode
554 ASSERT_EFI_ERROR (Status
);
557 // Registers status code handler to route status codes into Framework SMM Status Code Protocol.
559 Register (SmmStatusCodeHandler
);
564 // Install SmmRscHandler Protocol
566 Status
= gSmst
->SmmInstallProtocolInterface (
568 &gEfiSmmRscHandlerProtocolGuid
,
569 EFI_NATIVE_INTERFACE
,
570 &mSmmRscHandlerProtocol
572 ASSERT_EFI_ERROR (Status
);
575 // Install SmmStatusCode Protocol
577 Status
= gSmst
->SmmInstallProtocolInterface (
579 &gEfiSmmStatusCodeProtocolGuid
,
580 EFI_NATIVE_INTERFACE
,
581 &mSmmStatusCodeProtocol
583 ASSERT_EFI_ERROR (Status
);