2 Report Status Code Router Driver which produces Report Stataus Code Handler Protocol
3 and Status Code Runtime Protocol.
5 Copyright (c) 2009, Intel Corporation
6 All rights reserved. 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 "ReportStatusCodeRouterRuntimeDxe.h"
18 EFI_HANDLE mHandle
= NULL
;
19 LIST_ENTRY mCallbackListHead
= INITIALIZE_LIST_HEAD_VARIABLE (mCallbackListHead
);
20 EFI_EVENT mVirtualAddressChangeEvent
= NULL
;
23 // Report operation nest status.
24 // If it is set, then the report operation has nested.
26 UINT32 mStatusCodeNestStatus
= 0;
28 EFI_STATUS_CODE_PROTOCOL mStatusCodeProtocol
= {
32 EFI_RSC_HANDLER_PROTOCOL mRscHandlerProtocol
= {
38 Register the callback function for ReportStatusCode() notification.
40 When this function is called the function pointer is added to an internal list and any future calls to
41 ReportStatusCode() will be forwarded to the Callback function. During the bootservices,
42 this is the callback for which this service can be invoked. The report status code router
43 will create an event such that the callback function is only invoked at the TPL for which it was
44 registered. The entity that registers for the callback should also register for an event upon
45 generation of exit boot services and invoke the unregister service.
46 If the handler does not have a TPL dependency, it should register for a callback at TPL high. The
47 router infrastructure will support making callbacks at runtime, but the caller for runtime invocation
48 must meet the following criteria:
49 1. must be a runtime driver type so that its memory is not reclaimed
50 2. not unregister at exit boot services so that the router will still have its callback address
51 3. the caller must be self-contained (eg. Not call out into any boot-service interfaces) and be
52 runtime safe, in general.
54 @param[in] Callback A pointer to a function of type EFI_RSC_HANDLER_CALLBACK that is called when
55 a call to ReportStatusCode() occurs.
56 @param[in] Tpl TPL at which callback can be safely invoked.
58 @retval EFI_SUCCESS Function was successfully registered.
59 @retval EFI_INVALID_PARAMETER The callback function was NULL.
60 @retval EFI_OUT_OF_RESOURCES The internal buffer ran out of space. No more functions can be
62 @retval EFI_ALREADY_STARTED The function was already registered. It can't be registered again.
68 IN EFI_RSC_HANDLER_CALLBACK Callback
,
73 RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
75 if (Callback
== NULL
) {
76 return EFI_INVALID_PARAMETER
;
79 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
80 CallbackEntry
= CR (Link
, RSC_HANDLER_CALLBACK_ENTRY
, Node
, RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
81 if (CallbackEntry
->RscHandlerCallback
== Callback
) {
83 // If the function was already registered. It can't be registered again.
85 return EFI_ALREADY_STARTED
;
89 CallbackEntry
= AllocatePool (sizeof (RSC_HANDLER_CALLBACK_ENTRY
));
90 ASSERT (CallbackEntry
!= NULL
);
92 CallbackEntry
->Signature
= RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
;
93 CallbackEntry
->RscHandlerCallback
= Callback
;
94 CallbackEntry
->Tpl
= Tpl
;
96 InsertTailList (&mCallbackListHead
, &CallbackEntry
->Node
);
102 Remove a previously registered callback function from the notification list.
104 A callback function must be unregistered before it is deallocated. It is important that any registered
105 callbacks that are not runtime complaint be unregistered when ExitBootServices() is called.
107 @param[in] Callback A pointer to a function of type EFI_RSC_HANDLER_CALLBACK that is to be
110 @retval EFI_SUCCESS The function was successfully unregistered.
111 @retval EFI_INVALID_PARAMETER The callback function was NULL.
112 @retval EFI_NOT_FOUND The callback function was not found to be unregistered.
118 IN EFI_RSC_HANDLER_CALLBACK Callback
122 RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
124 if (Callback
== NULL
) {
125 return EFI_INVALID_PARAMETER
;
128 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
129 CallbackEntry
= CR (Link
, RSC_HANDLER_CALLBACK_ENTRY
, Node
, RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
130 if (CallbackEntry
->RscHandlerCallback
== Callback
) {
132 // If the function is found in list, delete it and return.
134 RemoveEntryList (&CallbackEntry
->Node
);
135 FreePool (CallbackEntry
);
140 return EFI_NOT_FOUND
;
144 Event callback function to invoke status code handler in list.
146 @param Event Event whose notification function is being invoked.
147 @param Context Pointer to the notification function's context, which is
148 always zero in current implementation.
153 RscHandlerNotification (
158 RSC_EVENT_CONTEXT
*RscContext
;
160 RscContext
= (RSC_EVENT_CONTEXT
*) Context
;
162 RscContext
->RscHandlerCallback (
165 RscContext
->Instance
,
166 RscContext
->CallerId
,
172 Provides an interface that a software module can call to report a status code.
174 @param Type Indicates the type of status code being reported.
175 @param Value Describes the current status of a hardware or software entity.
176 This included information about the class and subclass that is used to
177 classify the entity as well as an operation.
178 @param Instance The enumeration of a hardware or software entity within
179 the system. Valid instance numbers start with 1.
180 @param CallerId This optional parameter may be used to identify the caller.
181 This parameter allows the status code driver to apply different rules to
183 @param Data This optional parameter may be used to pass additional data.
185 @retval EFI_SUCCESS The function completed successfully
186 @retval EFI_DEVICE_ERROR The function should not be completed due to a device error.
192 IN EFI_STATUS_CODE_TYPE Type
,
193 IN EFI_STATUS_CODE_VALUE Value
,
195 IN EFI_GUID
*CallerId OPTIONAL
,
196 IN EFI_STATUS_CODE_DATA
*Data OPTIONAL
200 RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
201 RSC_EVENT_CONTEXT Context
;
206 // Use atom operation to avoid the reentant of report.
207 // If current status is not zero, then the function is reentrancy.
209 if (InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 0, 1) == 1) {
210 return EFI_DEVICE_ERROR
;
213 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
214 CallbackEntry
= CR (Link
, RSC_HANDLER_CALLBACK_ENTRY
, Node
, RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
216 if ((CallbackEntry
->Tpl
== TPL_HIGH_LEVEL
) || EfiAtRuntime ()) {
217 CallbackEntry
->RscHandlerCallback (
227 Context
.RscHandlerCallback
= CallbackEntry
->RscHandlerCallback
;
229 Context
.Value
= Value
;
230 Context
.Instance
= Instance
;
231 Context
.CallerId
= CallerId
;
234 Status
= gBS
->CreateEvent (
237 RscHandlerNotification
,
241 ASSERT_EFI_ERROR (Status
);
243 Status
= gBS
->SignalEvent (Event
);
244 ASSERT_EFI_ERROR (Status
);
246 Status
= gBS
->CloseEvent (Event
);
247 ASSERT_EFI_ERROR (Status
);
251 // Restore the nest status of report
253 InterlockedCompareExchange32 (&mStatusCodeNestStatus
, 1, 0);
259 Virtual address change notification call back. It converts global pointer
262 @param Event Event whose notification function is being invoked.
263 @param Context Pointer to the notification function's context, which is
264 always zero in current implementation.
269 VirtualAddressChangeCallBack (
276 RSC_HANDLER_CALLBACK_ENTRY
*CallbackEntry
;
278 for (Link
= GetFirstNode (&mCallbackListHead
); !IsNull (&mCallbackListHead
, Link
); Link
= GetNextNode (&mCallbackListHead
, Link
)) {
279 CallbackEntry
= CR (Link
, RSC_HANDLER_CALLBACK_ENTRY
, Node
, RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE
);
280 Status
= EfiConvertFunctionPointer (0, (VOID
**) &CallbackEntry
->RscHandlerCallback
);
281 ASSERT_EFI_ERROR (Status
);
284 Status
= EfiConvertList (
288 ASSERT_EFI_ERROR (Status
);
292 Entry point of Generic Status Code Driver.
294 This function is the entry point of this Generic Status Code Driver.
295 It installs eport Stataus Code Handler Protocol and Status Code Runtime Protocol,
296 and registers event for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
298 @param ImageHandle The firmware allocated handle for the EFI image.
299 @param SystemTable A pointer to the EFI System Table.
301 @retval EFI_SUCCESS The entry point is executed successfully.
306 GenericStatusCodeRuntimeDxeEntry (
307 IN EFI_HANDLE ImageHandle
,
308 IN EFI_SYSTEM_TABLE
*SystemTable
313 Status
= gBS
->InstallMultipleProtocolInterfaces (
315 &gEfiRscHandlerProtocolGuid
,
316 &mRscHandlerProtocol
,
317 &gEfiStatusCodeRuntimeProtocolGuid
,
318 &mStatusCodeProtocol
,
321 ASSERT_EFI_ERROR (Status
);
323 Status
= gBS
->CreateEventEx (
326 VirtualAddressChangeCallBack
,
328 &gEfiEventVirtualAddressChangeGuid
,
329 &mVirtualAddressChangeEvent
331 ASSERT_EFI_ERROR (Status
);