2 Report Status Code Router Driver which produces SMM Report Stataus Code Handler Protocol
3 and SMM Status Code Protocol.
5 Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "ReportStatusCodeRouterSmm.h"
12 LIST_ENTRY mCallbackListHead
= INITIALIZE_LIST_HEAD_VARIABLE (mCallbackListHead
);
15 // Report operation nest status.
16 // If it is set, then the report operation has nested.
18 UINT32 mStatusCodeNestStatus
= 0;
20 EFI_SMM_STATUS_CODE_PROTOCOL mSmmStatusCodeProtocol
= {
24 EFI_SMM_RSC_HANDLER_PROTOCOL mSmmRscHandlerProtocol
= {
30 Register the callback function for ReportStatusCode() notification.
32 When this function is called the function pointer is added to an internal list and any future calls to
33 ReportStatusCode() will be forwarded to the Callback function.
35 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is called
36 when a call to ReportStatusCode() occurs.
38 @retval EFI_SUCCESS Function was successfully registered.
39 @retval EFI_INVALID_PARAMETER The callback function was NULL.
40 @retval EFI_OUT_OF_RESOURCES The internal buffer ran out of space. No more functions can be
42 @retval EFI_ALREADY_STARTED The function was already registered. It can't be registered again.
48 IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
52 SMM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
54 if (Callback
== NULL
) {
55 return EFI_INVALID_PARAMETER
;
58 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
59 CallbackEntry
= CR (Link
, SMM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
60 if (CallbackEntry
->RscHandlerCallback
== Callback
) {
62 // If the function was already registered. It can't be registered again.
64 return EFI_ALREADY_STARTED
;
68 CallbackEntry
= (SMM_RSC_HANDLER_CALLBACK_ENTRY
*)AllocatePool (sizeof (SMM_RSC_HANDLER_CALLBACK_ENTRY
));
69 ASSERT (CallbackEntry
!= NULL
);
71 CallbackEntry
->Signature
= SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
;
72 CallbackEntry
->RscHandlerCallback
= Callback
;
74 InsertTailList (&mCallbackListHead
, &CallbackEntry
->Node
);
80 Remove a previously registered callback function from the notification list.
82 ReportStatusCode() messages will no longer be forwarded to the Callback function.
84 @param[in] Callback A pointer to a function of type EFI_PEI_RSC_HANDLER_CALLBACK that is to be
87 @retval EFI_SUCCESS The function was successfully unregistered.
88 @retval EFI_INVALID_PARAMETER The callback function was NULL.
89 @retval EFI_NOT_FOUND The callback function was not found to be unregistered.
95 IN EFI_SMM_RSC_HANDLER_CALLBACK Callback
99 SMM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
101 if (Callback
== NULL
) {
102 return EFI_INVALID_PARAMETER
;
105 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
106 CallbackEntry
= CR (Link
, SMM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
107 if (CallbackEntry
->RscHandlerCallback
== Callback
) {
109 // If the function is found in list, delete it and return.
111 RemoveEntryList (&CallbackEntry
->Node
);
112 FreePool (CallbackEntry
);
117 return EFI_NOT_FOUND
;
122 Provides an interface that a software module can call to report a status code.
124 @param This EFI_SMM_STATUS_CODE_PROTOCOL instance.
125 @param Type Indicates the type of status code being reported.
126 @param Value Describes the current status of a hardware or software entity.
127 This included information about the class and subclass that is used to
128 classify the entity as well as an operation.
129 @param Instance The enumeration of a hardware or software entity within
130 the system. Valid instance numbers start with 1.
131 @param CallerId This optional parameter may be used to identify the caller.
132 This parameter allows the status code driver to apply different rules to
134 @param Data This optional parameter may be used to pass additional data.
136 @retval EFI_SUCCESS The function completed successfully
137 @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.
143 IN CONST EFI_SMM_STATUS_CODE_PROTOCOL
*This
,
144 IN EFI_STATUS_CODE_TYPE Type
,
145 IN EFI_STATUS_CODE_VALUE Value
,
147 IN CONST EFI_GUID
*CallerId OPTIONAL
,
148 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
152 SMM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
155 // Use atom operation to avoid the reentant of report.
156 // If current status is not zero, then the function is reentrancy.
158 if (InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 0, 1) == 1) {
159 return EFI_DEVICE_ERROR
;
162 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
);) {
163 CallbackEntry
= CR (Link
, SMM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, SMM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
165 // The handler may remove itself, so get the next handler in advance.
167 Link
= GetNextNode (&mCallbackListHead
, Link
);
168 CallbackEntry
->RscHandlerCallback (
179 // Restore the nest status of report
181 InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 1, 0);
187 Entry point of Generic Status Code Driver.
189 This function is the entry point of SMM Status Code Router .
190 It produces SMM Report Stataus Code Handler and Status Code protocol.
192 @param ImageHandle The firmware allocated handle for the EFI image.
193 @param SystemTable A pointer to the EFI System Table.
195 @retval EFI_SUCCESS The entry point is executed successfully.
200 GenericStatusCodeSmmEntry (
201 IN EFI_HANDLE ImageHandle
,
202 IN EFI_SYSTEM_TABLE
*SystemTable
211 // Install SmmRscHandler Protocol
213 Status
= gSmst
->SmmInstallProtocolInterface (
215 &gEfiSmmRscHandlerProtocolGuid
,
216 EFI_NATIVE_INTERFACE
,
217 &mSmmRscHandlerProtocol
219 ASSERT_EFI_ERROR (Status
);
222 // Install SmmStatusCode Protocol
224 Status
= gSmst
->SmmInstallProtocolInterface (
226 &gEfiSmmStatusCodeProtocolGuid
,
227 EFI_NATIVE_INTERFACE
,
228 &mSmmStatusCodeProtocol
230 ASSERT_EFI_ERROR (Status
);