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 "ReportStatusCodeRouterCommon.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_MM_STATUS_CODE_PROTOCOL mSmmStatusCodeProtocol
= {
24 EFI_MM_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_MM_RSC_HANDLER_CALLBACK Callback
52 MM_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
, MM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, MM_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
= (MM_RSC_HANDLER_CALLBACK_ENTRY
*)AllocatePool (sizeof (MM_RSC_HANDLER_CALLBACK_ENTRY
));
69 ASSERT (CallbackEntry
!= NULL
);
71 CallbackEntry
->Signature
= MM_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_MM_RSC_HANDLER_CALLBACK Callback
99 MM_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
, MM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, MM_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
;
121 Provides an interface that a software module can call to report a status code.
123 @param This EFI_MM_STATUS_CODE_PROTOCOL instance.
124 @param CodeType Indicates the type of status code being reported.
125 @param Value Describes the current status of a hardware or software entity.
126 This included information about the class and subclass that is used to
127 classify the entity as well as an operation.
128 @param Instance The enumeration of a hardware or software entity within
129 the system. Valid instance numbers start with 1.
130 @param CallerId This optional parameter may be used to identify the caller.
131 This parameter allows the status code driver to apply different rules to
133 @param Data This optional parameter may be used to pass additional data.
135 @retval EFI_SUCCESS The function completed successfully
136 @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.
142 IN CONST EFI_MM_STATUS_CODE_PROTOCOL
*This
,
143 IN EFI_STATUS_CODE_TYPE CodeType
,
144 IN EFI_STATUS_CODE_VALUE Value
,
146 IN CONST EFI_GUID
*CallerId
,
147 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
151 MM_RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
154 // Use atom operation to avoid the reentant of report.
155 // If current status is not zero, then the function is reentrancy.
157 if (InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 0, 1) == 1) {
158 return EFI_DEVICE_ERROR
;
161 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
);) {
162 CallbackEntry
= CR (Link
, MM_RSC_HANDLER_CALLBACK_ENTRY
, Node
, MM_RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
164 // The handler may remove itself, so get the next handler in advance.
166 Link
= GetNextNode (&mCallbackListHead
, Link
);
167 CallbackEntry
->RscHandlerCallback (
171 (EFI_GUID
*)CallerId
,
177 // Restore the nest status of report
179 InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 1, 0);
185 Entry point of Generic Status Code Driver.
187 This function is the common entry point of MM Status Code Router.
188 It produces MM Report Status Code Handler and Status Code protocol.
190 @retval EFI_SUCCESS The entry point is executed successfully.
194 GenericStatusCodeCommonEntry (
204 // Install SmmRscHandler Protocol
206 Status
= gMmst
->MmInstallProtocolInterface (
208 &gEfiMmRscHandlerProtocolGuid
,
209 EFI_NATIVE_INTERFACE
,
210 &mSmmRscHandlerProtocol
212 ASSERT_EFI_ERROR (Status
);
215 // Install SmmStatusCode Protocol
217 Status
= gMmst
->MmInstallProtocolInterface (
219 &gEfiMmStatusCodeProtocolGuid
,
220 EFI_NATIVE_INTERFACE
,
221 &mSmmStatusCodeProtocol
223 ASSERT_EFI_ERROR (Status
);