Report Status Code Router Driver which produces Report Stataus Code Handler Protocol\r
and Status Code Runtime Protocol.\r
\r
- Copyright (c) 2009, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
+ Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>\r
+ This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
http://opensource.org/licenses/bsd-license.php\r
Unregister\r
};\r
\r
+/**\r
+ Event callback function to invoke status code handler in list.\r
+\r
+ @param Event Event whose notification function is being invoked.\r
+ @param Context Pointer to the notification function's context, which is\r
+ always zero in current implementation.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+RscHandlerNotification (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ )\r
+{\r
+ RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;\r
+ EFI_PHYSICAL_ADDRESS Address;\r
+ RSC_DATA_ENTRY *RscData;\r
+\r
+ CallbackEntry = (RSC_HANDLER_CALLBACK_ENTRY *) Context;\r
+\r
+ //\r
+ // Traverse the status code data buffer to parse all\r
+ // data to report.\r
+ //\r
+ Address = CallbackEntry->StatusCodeDataBuffer;\r
+ while (Address < CallbackEntry->EndPointer) {\r
+ RscData = (RSC_DATA_ENTRY *) (UINTN) Address;\r
+ CallbackEntry->RscHandlerCallback (\r
+ RscData->Type,\r
+ RscData->Value,\r
+ RscData->Instance,\r
+ &RscData->CallerId,\r
+ &RscData->Data\r
+ );\r
+\r
+ Address += (sizeof (RSC_DATA_ENTRY) + RscData->Data.Size);\r
+ Address = ALIGN_VARIABLE (Address);\r
+ }\r
+\r
+ CallbackEntry->EndPointer = CallbackEntry->StatusCodeDataBuffer;\r
+}\r
+\r
/**\r
Register the callback function for ReportStatusCode() notification.\r
- \r
+\r
When this function is called the function pointer is added to an internal list and any future calls to\r
ReportStatusCode() will be forwarded to the Callback function. During the bootservices,\r
this is the callback for which this service can be invoked. The report status code router\r
2. not unregister at exit boot services so that the router will still have its callback address\r
3. the caller must be self-contained (eg. Not call out into any boot-service interfaces) and be\r
runtime safe, in general.\r
- \r
+\r
@param[in] Callback A pointer to a function of type EFI_RSC_HANDLER_CALLBACK that is called when\r
a call to ReportStatusCode() occurs.\r
- @param[in] Tpl TPL at which callback can be safely invoked. \r
- \r
+ @param[in] Tpl TPL at which callback can be safely invoked.\r
+\r
@retval EFI_SUCCESS Function was successfully registered.\r
@retval EFI_INVALID_PARAMETER The callback function was NULL.\r
@retval EFI_OUT_OF_RESOURCES The internal buffer ran out of space. No more functions can be\r
IN EFI_TPL Tpl\r
)\r
{\r
+ EFI_STATUS Status;\r
LIST_ENTRY *Link;\r
RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;\r
\r
}\r
}\r
\r
- CallbackEntry = AllocatePool (sizeof (RSC_HANDLER_CALLBACK_ENTRY));\r
+ CallbackEntry = AllocateRuntimeZeroPool (sizeof (RSC_HANDLER_CALLBACK_ENTRY));\r
ASSERT (CallbackEntry != NULL);\r
\r
CallbackEntry->Signature = RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE;\r
CallbackEntry->RscHandlerCallback = Callback;\r
CallbackEntry->Tpl = Tpl;\r
\r
+ //\r
+ // If TPL of registered callback funtion is not TPL_HIGH_LEVEL, then event should be created\r
+ // for it, and related buffer for status code data should be prepared.\r
+ // Here the data buffer must be prepared in advance, because Report Status Code Protocol might\r
+ // be invoked under TPL_HIGH_LEVEL and no memory allocation is allowed then.\r
+ // If TPL is TPL_HIGH_LEVEL, then all status code will be reported immediately, without data\r
+ // buffer and event trigger.\r
+ //\r
+ if (Tpl != TPL_HIGH_LEVEL) {\r
+ CallbackEntry->StatusCodeDataBuffer = (EFI_PHYSICAL_ADDRESS) (UINTN) AllocatePool (EFI_PAGE_SIZE);\r
+ CallbackEntry->BufferSize = EFI_PAGE_SIZE;\r
+ CallbackEntry->EndPointer = CallbackEntry->StatusCodeDataBuffer;\r
+ Status = gBS->CreateEvent (\r
+ EVT_NOTIFY_SIGNAL,\r
+ Tpl,\r
+ RscHandlerNotification,\r
+ CallbackEntry,\r
+ &CallbackEntry->Event\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+\r
InsertTailList (&mCallbackListHead, &CallbackEntry->Node);\r
\r
return EFI_SUCCESS;\r
\r
/**\r
Remove a previously registered callback function from the notification list.\r
- \r
+\r
A callback function must be unregistered before it is deallocated. It is important that any registered\r
callbacks that are not runtime complaint be unregistered when ExitBootServices() is called.\r
- \r
+\r
@param[in] Callback A pointer to a function of type EFI_RSC_HANDLER_CALLBACK that is to be\r
unregistered.\r
- \r
+\r
@retval EFI_SUCCESS The function was successfully unregistered.\r
@retval EFI_INVALID_PARAMETER The callback function was NULL.\r
@retval EFI_NOT_FOUND The callback function was not found to be unregistered.\r
//\r
// If the function is found in list, delete it and return.\r
//\r
+ if (CallbackEntry->Tpl != TPL_HIGH_LEVEL) {\r
+ FreePool ((VOID *) (UINTN) CallbackEntry->StatusCodeDataBuffer);\r
+ gBS->CloseEvent (CallbackEntry->Event);\r
+ }\r
RemoveEntryList (&CallbackEntry->Node);\r
FreePool (CallbackEntry);\r
return EFI_SUCCESS;\r
return EFI_NOT_FOUND;\r
}\r
\r
-/**\r
- Event callback function to invoke status code handler in list.\r
-\r
- @param Event Event whose notification function is being invoked.\r
- @param Context Pointer to the notification function's context, which is\r
- always zero in current implementation.\r
-\r
-**/\r
-VOID\r
-EFIAPI\r
-RscHandlerNotification (\r
- IN EFI_EVENT Event,\r
- IN VOID *Context\r
- )\r
-{\r
- RSC_EVENT_CONTEXT *RscContext;\r
-\r
- RscContext = (RSC_EVENT_CONTEXT *) Context;\r
-\r
- RscContext->RscHandlerCallback (\r
- RscContext->Type,\r
- RscContext->Value,\r
- RscContext->Instance,\r
- RscContext->CallerId,\r
- RscContext->Data\r
- );\r
-}\r
-\r
/**\r
Provides an interface that a software module can call to report a status code.\r
\r
{\r
LIST_ENTRY *Link;\r
RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;\r
- RSC_EVENT_CONTEXT Context;\r
- EFI_EVENT Event;\r
+ RSC_DATA_ENTRY *RscData;\r
EFI_STATUS Status;\r
+ VOID *NewBuffer;\r
\r
//\r
// Use atom operation to avoid the reentant of report.\r
return EFI_DEVICE_ERROR;\r
}\r
\r
- for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead, Link); Link = GetNextNode (&mCallbackListHead, Link)) {\r
+ for (Link = GetFirstNode (&mCallbackListHead); !IsNull (&mCallbackListHead, Link);) {\r
CallbackEntry = CR (Link, RSC_HANDLER_CALLBACK_ENTRY, Node, RSC_HANDLER_CALLBACK_ENTRY_SIGNATURE);\r
-\r
+ //\r
+ // The handler may remove itself, so get the next handler in advance.\r
+ //\r
+ Link = GetNextNode (&mCallbackListHead, Link);\r
if ((CallbackEntry->Tpl == TPL_HIGH_LEVEL) || EfiAtRuntime ()) {\r
CallbackEntry->RscHandlerCallback (\r
Type,\r
continue;\r
}\r
\r
- Context.RscHandlerCallback = CallbackEntry->RscHandlerCallback;\r
- Context.Type = Type;\r
- Context.Value = Value;\r
- Context.Instance = Instance;\r
- Context.CallerId = CallerId;\r
- Context.Data = Data;\r
+ //\r
+ // If callback is registered with TPL lower than TPL_HIGH_LEVEL, event must be signaled at boot time to possibly wait for\r
+ // allowed TPL to report status code. Related data should also be stored in data buffer.\r
+ //\r
+ CallbackEntry->EndPointer = ALIGN_VARIABLE (CallbackEntry->EndPointer);\r
+ RscData = (RSC_DATA_ENTRY *) (UINTN) CallbackEntry->EndPointer;\r
+ CallbackEntry->EndPointer += sizeof (RSC_DATA_ENTRY);\r
+ if (Data != NULL) {\r
+ CallbackEntry->EndPointer += Data->Size;\r
+ }\r
\r
- Status = gBS->CreateEvent (\r
- EVT_NOTIFY_SIGNAL,\r
- CallbackEntry->Tpl,\r
- RscHandlerNotification,\r
- &Context,\r
- &Event\r
- );\r
- ASSERT_EFI_ERROR (Status);\r
+ //\r
+ // If data buffer is about to be used up (7/8 here), try to reallocate a buffer with double size, if not at TPL_HIGH_LEVEL.\r
+ //\r
+ if (CallbackEntry->EndPointer > (CallbackEntry->StatusCodeDataBuffer + (CallbackEntry->BufferSize / 8) * 7)) {\r
+ if (EfiGetCurrentTpl () < TPL_HIGH_LEVEL) {\r
+ NewBuffer = ReallocatePool (\r
+ CallbackEntry->BufferSize,\r
+ CallbackEntry->BufferSize * 2,\r
+ (VOID *) (UINTN) CallbackEntry->StatusCodeDataBuffer\r
+ );\r
+ if (NewBuffer != NULL) {\r
+ CallbackEntry->EndPointer = (EFI_PHYSICAL_ADDRESS) (UINTN) NewBuffer + (CallbackEntry->EndPointer - CallbackEntry->StatusCodeDataBuffer);\r
+ CallbackEntry->StatusCodeDataBuffer = (EFI_PHYSICAL_ADDRESS) (UINTN) NewBuffer;\r
+ CallbackEntry->BufferSize *= 2;\r
+ }\r
+ }\r
+ }\r
\r
- Status = gBS->SignalEvent (Event);\r
- ASSERT_EFI_ERROR (Status);\r
+ //\r
+ // If data buffer is used up, do not report for this time.\r
+ //\r
+ if (CallbackEntry->EndPointer > (CallbackEntry->StatusCodeDataBuffer + CallbackEntry->BufferSize)) {\r
+ continue;\r
+ }\r
\r
- Status = gBS->CloseEvent (Event);\r
+ RscData->Type = Type;\r
+ RscData->Value = Value;\r
+ RscData->Instance = Instance;\r
+ if (CallerId != NULL) {\r
+ CopyGuid (&RscData->CallerId, CallerId);\r
+ }\r
+ if (Data != NULL) {\r
+ CopyMem (&RscData->Data, Data, Data->HeaderSize + Data->Size);\r
+ }\r
+\r
+ Status = gBS->SignalEvent (CallbackEntry->Event);\r
ASSERT_EFI_ERROR (Status);\r
}\r
\r
IN VOID *Context\r
)\r
{\r
- EFI_STATUS Status;\r
+ EFI_STATUS Status;\r
LIST_ENTRY *Link;\r
RSC_HANDLER_CALLBACK_ENTRY *CallbackEntry;\r
\r
\r
@param ImageHandle The firmware allocated handle for the EFI image.\r
@param SystemTable A pointer to the EFI System Table.\r
- \r
+\r
@retval EFI_SUCCESS The entry point is executed successfully.\r
\r
**/\r