summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Library
diff options
context:
space:
mode:
authorxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>2009-12-31 03:53:06 +0000
committerxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>2009-12-31 03:53:06 +0000
commit4adf000886c2328d8dbbcd00b88e671286e9300f (patch)
treed0ef7aaa6a3c73d69089e70ca71e94a077018d46 /MdeModulePkg/Library
parentff482c5692e4011d7d096442c945b478f1bad40b (diff)
downloadedk2-platforms-4adf000886c2328d8dbbcd00b88e671286e9300f.tar.xz
Refine DxeReportStatusCodeLib and RuntimeDxeReportStatusCodeLib.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9651 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdeModulePkg/Library')
-rw-r--r--MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf3
-rw-r--r--MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c61
-rw-r--r--MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c232
-rw-r--r--MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLibInternal.h85
-rw-r--r--MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf7
-rw-r--r--MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeSupport.c207
6 files changed, 257 insertions, 338 deletions
diff --git a/MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf b/MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
index 65e05fdce2..e1e72797d0 100644
--- a/MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
+++ b/MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
@@ -38,7 +38,6 @@
[LibraryClasses]
PcdLib
BaseMemoryLib
- MemoryAllocationLib
UefiBootServicesTableLib
DebugLib
UefiRuntimeServicesTableLib
@@ -49,7 +48,7 @@
gEfiStatusCodeDataTypeDebugGuid ## CONSUMES
[Protocols]
- gEfiStatusCodeRuntimeProtocolGuid ## SOMETIMES_CONSUMES (Used if revision of the EFI Specification is not less than 0x20000)
+ gEfiStatusCodeRuntimeProtocolGuid ## CONSUMES
[Pcd.common]
gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask
diff --git a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
index f32e167d94..8c456bebf4 100644
--- a/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
@@ -13,53 +13,56 @@
**/
#include <Library/ReportStatusCodeLib.h>
+#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/UefiBootServicesTableLib.h>
-#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
-#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/DevicePathLib.h>
+#include <Protocol/StatusCode.h>
+
#include <Guid/StatusCodeDataTypeId.h>
#include <Guid/StatusCodeDataTypeDebug.h>
-#include <Protocol/StatusCode.h>
-EFI_REPORT_STATUS_CODE mReportStatusCode = NULL;
+EFI_STATUS_CODE_PROTOCOL *mReportStatusCodeLibStatusCodeProtocol = NULL;
/**
Locate the report status code service.
- @return Function pointer to the report status code service.
- NULL is returned if no status code service is available.
+ Retrieve ReportStatusCode() API of Report Status Code Protocol.
**/
-EFI_REPORT_STATUS_CODE
+VOID
InternalGetReportStatusCode (
VOID
)
{
- EFI_STATUS_CODE_PROTOCOL *StatusCodeProtocol;
- EFI_STATUS Status;
+ EFI_STATUS Status;
+
+ if (mReportStatusCodeLibStatusCodeProtocol != NULL) {
+ return;
+ }
+ //
+ // Check gBS just in case ReportStatusCode is called before gBS is initialized.
+ //
if (gBS != NULL && gBS->LocateProtocol != NULL) {
- Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**)&StatusCodeProtocol);
- if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {
- return StatusCodeProtocol->ReportStatusCode;
+ Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**) &mReportStatusCodeLibStatusCodeProtocol);
+ if (EFI_ERROR (Status)) {
+ mReportStatusCodeLibStatusCodeProtocol = NULL;
}
}
-
- return NULL;
}
/**
- Internal worker function that reports a status code through the status code service.
+ Internal worker function that reports a status code through the Report Status Code Protocol.
- If status code service is not cached, then this function checks if status code service is
- available in system. If status code service is not available, then EFI_UNSUPPORTED is
- returned. If status code service is present, then it is cached in mReportStatusCode.
- Finally this function reports status code through the status code service.
+ If status code service is not cached, then this function checks if Report Status Code
+ Protocol is available in system. If Report Status Code Protocol is not available, then
+ EFI_UNSUPPORTED is returned. If Report Status Code Protocol is present, then it is
+ cached in mReportStatusCodeLibStatusCodeProtocol. Finally this function reports status
+ code through the Report Status Code Protocol.
@param Type Status code type.
@param Value Status code value.
@@ -71,7 +74,7 @@ InternalGetReportStatusCode (
optional parameter that may be NULL.
@retval EFI_SUCCESS The status code was reported.
- @retval EFI_UNSUPPORTED Status code service is not available.
+ @retval EFI_UNSUPPORTED Report Status Code Protocol is not available.
@retval EFI_UNSUPPORTED Status code type is not supported.
**/
@@ -88,19 +91,17 @@ InternalReportStatusCode (
(ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||
(ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {
//
- // If mReportStatusCode is NULL, then check if status code service is available in system.
+ // If mReportStatusCodeLibStatusCodeProtocol is NULL, then check if Report Status Code Protocol is available in system.
//
- if (mReportStatusCode == NULL) {
- mReportStatusCode = InternalGetReportStatusCode ();
- if (mReportStatusCode == NULL) {
- return EFI_UNSUPPORTED;
- }
+ InternalGetReportStatusCode ();
+ if (mReportStatusCodeLibStatusCodeProtocol == NULL) {
+ return EFI_UNSUPPORTED;
}
-
+
//
- // A status code service is present in system, so pass in all the parameters to the service.
+ // A Report Status Code Protocol is present in system, so pass in all the parameters to the service.
//
- return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);
+ return mReportStatusCodeLibStatusCodeProtocol->ReportStatusCode (Type, Value, Instance, (EFI_GUID *)CallerId, Data);
}
return EFI_UNSUPPORTED;
diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
index 165fc4abca..db5647276d 100644
--- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
+++ b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLib.c
@@ -12,7 +12,198 @@
**/
-#include "ReportStatusCodeLibInternal.h"
+#include <Library/ReportStatusCodeLib.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PcdLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/UefiRuntimeLib.h>
+
+#include <Protocol/StatusCode.h>
+
+#include <Guid/StatusCodeDataTypeId.h>
+#include <Guid/StatusCodeDataTypeDebug.h>
+#include <Guid/EventGroup.h>
+
+EFI_STATUS_CODE_PROTOCOL *mReportStatusCodeLibStatusCodeProtocol = NULL;
+EFI_EVENT mReportStatusCodeLibVirtualAddressChangeEvent;
+
+/**
+ Locate the report status code service.
+
+ Retrieve ReportStatusCode() API of Report Status Code Protocol.
+
+**/
+VOID
+InternalGetReportStatusCode (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+
+ if (mReportStatusCodeLibStatusCodeProtocol != NULL) {
+ return;
+ }
+
+ if (EfiAtRuntime ()) {
+ return;
+ }
+
+ //
+ // Check gBS just in case ReportStatusCode is called before gBS is initialized.
+ //
+ if (gBS != NULL && gBS->LocateProtocol != NULL) {
+ Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**) &mReportStatusCodeLibStatusCodeProtocol);
+ if (EFI_ERROR (Status)) {
+ mReportStatusCodeLibStatusCodeProtocol = NULL;
+ }
+ }
+}
+
+/**
+ Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
+
+ @param Event Event whose notification function is being invoked.
+ @param Context Pointer to the notification function's context
+
+**/
+VOID
+EFIAPI
+ReportStatusCodeLibVirtualAddressChange (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ if (mReportStatusCodeLibStatusCodeProtocol == NULL) {
+ return;
+ }
+ EfiConvertPointer (0, (VOID **) &mReportStatusCodeLibStatusCodeProtocol);
+}
+
+/**
+ The constructor function of Runtime DXE Report Status Code Lib.
+
+ This function allocates memory for extended status code data, caches
+ the report status code service, and registers events.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+ReportStatusCodeLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // Cache the report status code service
+ //
+ InternalGetReportStatusCode ();
+
+ //
+ // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
+ //
+ Status = gBS->CreateEventEx (
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ ReportStatusCodeLibVirtualAddressChange,
+ NULL,
+ &gEfiEventVirtualAddressChangeGuid,
+ &mReportStatusCodeLibVirtualAddressChangeEvent
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ The destructor function of Runtime DXE Report Status Code Lib.
+
+ The destructor function frees memory allocated by constructor, and closes related events.
+ It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+ReportStatusCodeLibDestructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ ASSERT (gBS != NULL);
+ Status = gBS->CloseEvent (mReportStatusCodeLibVirtualAddressChangeEvent);
+ ASSERT_EFI_ERROR (Status);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Internal worker function that reports a status code through the Report Status Code Protocol.
+
+ If status code service is not cached, then this function checks if Report Status Code
+ Protocol is available in system. If Report Status Code Protocol is not available, then
+ EFI_UNSUPPORTED is returned. If Report Status Code Protocol is present, then it is
+ cached in mReportStatusCodeLibStatusCodeProtocol. Finally this function reports status
+ code through the Report Status Code Protocol.
+
+ @param Type Status code type.
+ @param Value Status code value.
+ @param Instance Status code instance number.
+ @param CallerId Pointer to a GUID that identifies the caller of this
+ function. This is an optional parameter that may be
+ NULL.
+ @param Data Pointer to the extended data buffer. This is an
+ optional parameter that may be NULL.
+
+ @retval EFI_SUCCESS The status code was reported.
+ @retval EFI_UNSUPPORTED Report Status Code Protocol is not available.
+ @retval EFI_UNSUPPORTED Status code type is not supported.
+
+**/
+EFI_STATUS
+InternalReportStatusCode (
+ IN EFI_STATUS_CODE_TYPE Type,
+ IN EFI_STATUS_CODE_VALUE Value,
+ IN UINT32 Instance,
+ IN CONST EFI_GUID *CallerId OPTIONAL,
+ IN EFI_STATUS_CODE_DATA *Data OPTIONAL
+ )
+{
+ if ((ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||
+ (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||
+ (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {
+ //
+ // If mReportStatusCodeLibStatusCodeProtocol is NULL, then check if Report Status Code Protocol is available in system.
+ //
+ InternalGetReportStatusCode ();
+ if (mReportStatusCodeLibStatusCodeProtocol == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // A Report Status Code Protocol is present in system, so pass in all the parameters to the service.
+ //
+ return mReportStatusCodeLibStatusCodeProtocol->ReportStatusCode (Type, Value, Instance, (EFI_GUID *)CallerId, Data);
+ }
+
+ return EFI_UNSUPPORTED;
+}
+
/**
Converts a status code to an 8-bit POST code value.
@@ -389,29 +580,47 @@ ReportStatusCodeEx (
)
{
EFI_STATUS Status;
+ EFI_STATUS_CODE_DATA *StatusCodeData;
+ UINT8 StatusCodeBuffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));
ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));
- if (ExtendedDataSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {
- return EFI_OUT_OF_RESOURCES;
+ if (EfiAtRuntime ()) {
+ if (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+ StatusCodeData = (EFI_STATUS_CODE_DATA *)StatusCodeBuffer;
+ } else {
+ if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Allocate space for the Status Code Header and its buffer
+ //
+ StatusCodeData = NULL;
+ gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);
+ if (StatusCodeData == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
}
//
// Fill in the extended data header
//
- mStatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);
- mStatusCodeData->Size = (UINT16)ExtendedDataSize;
+ StatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);
+ StatusCodeData->Size = (UINT16)ExtendedDataSize;
if (ExtendedDataGuid == NULL) {
ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;
}
- CopyGuid (&mStatusCodeData->Type, ExtendedDataGuid);
+ CopyGuid (&StatusCodeData->Type, ExtendedDataGuid);
//
// Fill in the extended data buffer
//
if (ExtendedData != NULL) {
- CopyMem (mStatusCodeData + 1, ExtendedData, ExtendedDataSize);
+ CopyMem (StatusCodeData + 1, ExtendedData, ExtendedDataSize);
}
//
@@ -420,7 +629,14 @@ ReportStatusCodeEx (
if (CallerId == NULL) {
CallerId = &gEfiCallerIdGuid;
}
- Status = InternalReportStatusCode (Type, Value, Instance, CallerId, mStatusCodeData);
+ Status = InternalReportStatusCode (Type, Value, Instance, CallerId, StatusCodeData);
+
+ //
+ // Free the allocated buffer
+ //
+ if (!EfiAtRuntime()) {
+ gBS->FreePool (StatusCodeData);
+ }
return Status;
}
diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLibInternal.h b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLibInternal.h
deleted file mode 100644
index 2ae0be4fd3..0000000000
--- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/ReportStatusCodeLibInternal.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/** @file
- Internal Header file of Report Status Code Library for RUNTIME
- DXE Phase.
-
- Copyright (c) 2006 - 2009, Intel Corporation<BR>
- All rights reserved. This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-#ifndef __REPORT_STATUS_CODE_LIB_INTERNAL__H__
-#define __REPORT_STATUS_CODE_LIB_INTERNAL__H__
-
-#include <Library/ReportStatusCodeLib.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/PcdLib.h>
-#include <Library/UefiRuntimeServicesTableLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/DevicePathLib.h>
-#include <Library/OemHookStatusCodeLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiRuntimeLib.h>
-
-#include <Guid/StatusCodeDataTypeId.h>
-#include <Guid/StatusCodeDataTypeDebug.h>
-#include <Guid/EventGroup.h>
-
-#include <Protocol/StatusCode.h>
-
-extern EFI_STATUS_CODE_DATA *mStatusCodeData;
-
-/**
- Locate the report status code service.
-
- It first tries to retrieve ReportStatusCode() in Runtime Services Table.
- If not found, it then tries to retrieve ReportStatusCode() API of Report Status Code Protocol.
-
- @return Function pointer to the report status code service.
- NULL is returned if no status code service is available.
-
-**/
-EFI_REPORT_STATUS_CODE
-InternalGetReportStatusCode (
- VOID
- );
-
-/**
- Internal worker function that reports a status code through the status code service.
-
- If status code service is not cached, then this function checks if status code service is
- available in system. If status code service is not available, then EFI_UNSUPPORTED is
- returned. If status code service is present, then it is cached in mReportStatusCode.
- Finally this function reports status code through the status code service.
-
- @param Type Status code type.
- @param Value Status code value.
- @param Instance Status code instance number.
- @param CallerId Pointer to a GUID that identifies the caller of this
- function. This is an optional parameter that may be
- NULL.
- @param Data Pointer to the extended data buffer. This is an
- optional parameter that may be NULL.
-
- @retval EFI_SUCCESS The status code was reported.
- @retval EFI_UNSUPPORTED Status code service is not available.
- @retval EFI_UNSUPPORTED Status code type is not supported.
-
-**/
-EFI_STATUS
-InternalReportStatusCode (
- IN EFI_STATUS_CODE_TYPE Type,
- IN EFI_STATUS_CODE_VALUE Value,
- IN UINT32 Instance,
- IN CONST EFI_GUID *CallerId OPTIONAL,
- IN EFI_STATUS_CODE_DATA *Data OPTIONAL
- );
-
-#endif
-
diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf
index 5ba91064c0..8b77e19136 100644
--- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf
+++ b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeReportStatusCodeLib.inf
@@ -26,13 +26,11 @@
#
# The following information is for reference only and not required by the build tools.
#
-# VALID_ARCHITECTURES = IA32 X64 EBC
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources.common]
ReportStatusCodeLib.c
- RuntimeDxeSupport.c
- ReportStatusCodeLibInternal.h
[Packages]
MdePkg/MdePkg.dec
@@ -43,11 +41,8 @@
BaseMemoryLib
BaseLib
DebugLib
- UefiRuntimeServicesTableLib
UefiBootServicesTableLib
- OemHookStatusCodeLib
DevicePathLib
- MemoryAllocationLib
UefiRuntimeLib
[Guids]
diff --git a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeSupport.c b/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeSupport.c
deleted file mode 100644
index fd9f8f7a2e..0000000000
--- a/MdeModulePkg/Library/RuntimeDxeReportStatusCodeLib/RuntimeDxeSupport.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/** @file
- Library constructor & destructor, event handlers, and other internal worker functions.
-
- Copyright (c) 2006 - 2009, Intel Corporation<BR>
- All rights reserved. This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
-
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-
-#include "ReportStatusCodeLibInternal.h"
-
-EFI_EVENT mStatusCodeVirtualAddressChangeEvent;
-EFI_STATUS_CODE_DATA *mStatusCodeData;
-EFI_RUNTIME_SERVICES *mStatusCodeInternalRT;
-EFI_REPORT_STATUS_CODE mReportStatusCode = NULL;
-
-/**
- Locate the report status code service.
-
- It first tries to retrieve ReportStatusCode() in Runtime Services Table.
- If not found, it then tries to retrieve ReportStatusCode() API of Report Status Code Protocol.
-
- @return Function pointer to the report status code service.
- NULL is returned if no status code service is available.
-
-**/
-EFI_REPORT_STATUS_CODE
-InternalGetReportStatusCode (
- VOID
- )
-{
- EFI_STATUS_CODE_PROTOCOL *StatusCodeProtocol;
- EFI_STATUS Status;
-
- if (!EfiAtRuntime ()) {
- //
- // Check gBS just in case. ReportStatusCode is called before gBS is initialized.
- //
- if (gBS != NULL) {
- Status = gBS->LocateProtocol (&gEfiStatusCodeRuntimeProtocolGuid, NULL, (VOID**) &StatusCodeProtocol);
- if (!EFI_ERROR (Status) && StatusCodeProtocol != NULL) {
- return StatusCodeProtocol->ReportStatusCode;
- }
- }
- }
-
- return NULL;
-}
-
-/**
- Internal worker function that reports a status code through the status code service.
-
- If status code service is not cached, then this function checks if status code service is
- available in system. If status code service is not available, then EFI_UNSUPPORTED is
- returned. If status code service is present, then it is cached in mReportStatusCode.
- Finally this function reports status code through the status code service.
-
- @param Type Status code type.
- @param Value Status code value.
- @param Instance Status code instance number.
- @param CallerId Pointer to a GUID that identifies the caller of this
- function. This is an optional parameter that may be
- NULL.
- @param Data Pointer to the extended data buffer. This is an
- optional parameter that may be NULL.
-
- @retval EFI_SUCCESS The status code was reported.
- @retval EFI_UNSUPPORTED Status code service is not available.
- @retval EFI_UNSUPPORTED Status code type is not supported.
-
-**/
-EFI_STATUS
-InternalReportStatusCode (
- IN EFI_STATUS_CODE_TYPE Type,
- IN EFI_STATUS_CODE_VALUE Value,
- IN UINT32 Instance,
- IN CONST EFI_GUID *CallerId OPTIONAL,
- IN EFI_STATUS_CODE_DATA *Data OPTIONAL
- )
-{
- if ((ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||
- (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||
- (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {
- //
- // If mReportStatusCode is NULL, then check if status code service is available in system.
- //
- if (mReportStatusCode == NULL) {
- mReportStatusCode = InternalGetReportStatusCode ();
- if (mReportStatusCode == NULL) {
- return EFI_UNSUPPORTED;
- }
- }
-
- //
- // A status code service is present in system, so pass in all the parameters to the service.
- //
- return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);
- }
-
- return EFI_UNSUPPORTED;
-}
-
-/**
- Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
-
- @param Event Event whose notification function is being invoked.
- @param Context Pointer to the notification function's context
-
-**/
-VOID
-EFIAPI
-ReportStatusCodeLibVirtualAddressChange (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
-{
- if (mReportStatusCode != NULL) {
- mStatusCodeInternalRT->ConvertPointer (0, (VOID **) &mReportStatusCode);
- }
- mStatusCodeInternalRT->ConvertPointer (0, (VOID **) &mStatusCodeData);
- mStatusCodeInternalRT->ConvertPointer (0, (VOID **) &mStatusCodeInternalRT);
-}
-
-/**
- The constructor function of Runtime DXE Report Status Code Lib.
-
- This function allocates memory for extended status code data, caches
- the report status code service, and registers events.
-
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
-
- @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
-
-**/
-EFI_STATUS
-EFIAPI
-ReportStatusCodeLibConstruct (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- EFI_STATUS Status;
-
- //
- // Library should not use the gRT directly, for it may be converted by other library instance.
- //
- mStatusCodeInternalRT = gRT;
-
- mStatusCodeData = AllocateRuntimePool (sizeof (EFI_STATUS_CODE_DATA) + EFI_STATUS_CODE_DATA_MAX_SIZE);
- ASSERT (mStatusCodeData != NULL);
- //
- // Cache the report status code service
- //
- mReportStatusCode = InternalGetReportStatusCode ();
-
- //
- // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
- //
- Status = gBS->CreateEventEx (
- EVT_NOTIFY_SIGNAL,
- TPL_NOTIFY,
- ReportStatusCodeLibVirtualAddressChange,
- NULL,
- &gEfiEventVirtualAddressChangeGuid,
- &mStatusCodeVirtualAddressChangeEvent
- );
- ASSERT_EFI_ERROR (Status);
-
- return EFI_SUCCESS;
-}
-
-/**
- The destructor function of Runtime DXE Report Status Code Lib.
-
- The destructor function frees memory allocated by constructor, and closes related events.
- It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS.
-
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
-
- @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
-
-**/
-EFI_STATUS
-EFIAPI
-ReportStatusCodeLibDestruct (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- EFI_STATUS Status;
-
- ASSERT (gBS != NULL);
- Status = gBS->CloseEvent (mStatusCodeVirtualAddressChangeEvent);
- ASSERT_EFI_ERROR (Status);
-
- FreePool (mStatusCodeData);
-
- return EFI_SUCCESS;
-}
-