]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Code scrub for SmmRuntimeDxeReportStatusCodeLibFramework.
authorxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 19 Jun 2009 05:29:50 +0000 (05:29 +0000)
committerxli24 <xli24@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 19 Jun 2009 05:29:50 +0000 (05:29 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8602 6f19259b-4bc3-4df7-8a09-765794883524

IntelFrameworkModulePkg/Library/SmmRuntimeDxeReportStatusCodeLibFramework/ReportStatusCodeLib.c
IntelFrameworkModulePkg/Library/SmmRuntimeDxeReportStatusCodeLibFramework/ReportStatusCodeLibInternal.h
IntelFrameworkModulePkg/Library/SmmRuntimeDxeReportStatusCodeLibFramework/SmmRuntimeDxeReportStatusCodeLibFramework.inf
IntelFrameworkModulePkg/Library/SmmRuntimeDxeReportStatusCodeLibFramework/SmmRuntimeDxeSupport.c

index b4d677ef4181f334bb60a31b32a1218e47893c18..165fc4abca53e5573868e0f9dfc0ea690c4cd486 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  Report Status Code Library for SMM Runtime driver.\r
+  API implementation for instance of Report Status Code Library.\r
 \r
-  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
   All rights reserved. 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
 \r
 #include "ReportStatusCodeLibInternal.h"\r
 \r
-\r
\r
-EFI_REPORT_STATUS_CODE  mReportStatusCode = NULL;\r
-\r
-/**\r
-  Internal worker function that reports a status code through the Status Code Protocol\r
-\r
-  This function checks to see if a Status Code Protocol is present in the handle\r
-  database.  If a Status Code Protocol is not present, then EFI_UNSUPPORTED is\r
-  returned.  If a Status Code Protocol is present, then it is cached in gStatusCode,\r
-  and the ReportStatusCode() service of the Status Code Protocol is called passing in\r
-  Type, Value, Instance, CallerId, and Data.  The result of this call is returned.\r
-\r
-  @param  Type              Status code type.\r
-  @param  Value             Status code value.\r
-  @param  Instance          Status code instance number.\r
-  @param  CallerId          Pointer to a GUID that identifies the caller of this\r
-                            function.  This is an optional parameter that may be\r
-                            NULL.\r
-  @param  Data              Pointer to the extended data buffer.  This is an\r
-                            optional parameter that may be NULL.\r
-\r
-  @retval  EFI_SUCCESS           The status code was reported.\r
-  @retval  EFI_OUT_OF_RESOURCES  There were not enough resources to report the status code.\r
-  @retval  EFI_UNSUPPORTED       Status Code Protocol is not available.\r
-\r
-**/\r
-EFI_STATUS\r
-InternalReportStatusCode (\r
-  IN EFI_STATUS_CODE_TYPE     Type,\r
-  IN EFI_STATUS_CODE_VALUE    Value,\r
-  IN UINT32                   Instance,\r
-  IN CONST EFI_GUID           *CallerId OPTIONAL,\r
-  IN EFI_STATUS_CODE_DATA     *Data     OPTIONAL\r
-  )\r
-{\r
-  //\r
-  // If gStatusCode is NULL, then see if a Status Code Protocol instance is present\r
-  // in the handle database.\r
-  //\r
-  if (mReportStatusCode == NULL) {\r
-    mReportStatusCode = InternalGetReportStatusCode ();\r
-    if (mReportStatusCode == NULL) {\r
-      return EFI_UNSUPPORTED;\r
-    }\r
-  }\r
-\r
-  //\r
-  // A Status Code Protocol is present in the handle database, so pass in all the\r
-  // parameters to the ReportStatusCode() service of the Status Code Protocol\r
-  //\r
-  return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r
-}\r
-\r
-\r
-/**\r
-  Computes and returns the size, in bytes, of a device path.\r
-\r
-  @param  DevicePath  A pointer to a device path.\r
-\r
-  @return  The size, in bytes, of DevicePath.\r
-\r
-**/\r
-UINTN\r
-InternalReportStatusCodeDevicePathSize (\r
-  IN CONST EFI_DEVICE_PATH_PROTOCOL  *DevicePath\r
-  )\r
-{\r
-  CONST EFI_DEVICE_PATH_PROTOCOL  *Start;\r
-\r
-  //\r
-  // Search for the end of the device path structure\r
-  //\r
-  Start = DevicePath;\r
-  while (!IsDevicePathEnd (DevicePath)) {\r
-    DevicePath = NextDevicePathNode (DevicePath);\r
-  }\r
-\r
-  //\r
-  // Subtract the start node from the end node and add in the size of the end node\r
-  //\r
-  return ((UINTN) DevicePath - (UINTN) Start) + DevicePathNodeLength (DevicePath);\r
-}\r
-\r
-\r
 /**\r
   Converts a status code to an 8-bit POST code value.\r
 \r
@@ -250,8 +165,8 @@ ReportStatusCodeExtractDebugInfo (
 {\r
   EFI_DEBUG_INFO  *DebugInfo;\r
 \r
-  ASSERT (Data          != NULL);\r
-  ASSERT (ErrorLevel    != NULL);\r
+  ASSERT (Data       != NULL);\r
+  ASSERT (ErrorLevel != NULL);\r
   ASSERT (Marker     != NULL);\r
   ASSERT (Format     != NULL);\r
 \r
@@ -270,8 +185,13 @@ ReportStatusCodeExtractDebugInfo (
   *ErrorLevel = DebugInfo->ErrorLevel;\r
 \r
   //\r
-  // The first 12 * UINTN bytes of the string are really an\r
-  // argument stack to support varargs on the Format string.\r
+  // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r
+  // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.\r
+  // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is\r
+  // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker\r
+  // returned is 64-bit aligned.\r
+  // 64-bit aligned is a must, otherwise retrieving 64-bit parameter from BASE_LIST will\r
+  // cause unalignment exception.\r
   //\r
   *Marker = (BASE_LIST) (DebugInfo + 1);\r
   *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r
@@ -353,7 +273,7 @@ ReportStatusCodeWithDevicePath (
            Type,\r
            Value,\r
            (VOID *)DevicePath,\r
-           InternalReportStatusCodeDevicePathSize (DevicePath)\r
+           GetDevicePathSize (DevicePath)\r
            );\r
 }\r
 \r
@@ -424,7 +344,7 @@ ReportStatusCodeWithExtendedData (
   is responsible for allocating a buffer large enough for the standard header and\r
   the extended data passed into this function.  The standard header is filled in\r
   with a GUID specified by ExtendedDataGuid.  If ExtendedDataGuid is NULL, then a\r
-  GUID of gEfiStatusCodeSpecificDatauid is used.  The status code is reported with\r
+  GUID of gEfiStatusCodeSpecificDataGuid is used.  The status code is reported with\r
   an instance specified by Instance and a caller ID specified by CallerId.  If\r
   CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
 \r
@@ -468,17 +388,39 @@ ReportStatusCodeEx (
   IN UINTN                  ExtendedDataSize\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-  Status = InternalReportStatusCodeEx (\r
-             Type,\r
-             Value,\r
-             Instance,\r
-             CallerId,\r
-             ExtendedDataGuid,\r
-             ExtendedData,\r
-             ExtendedDataSize\r
-             );\r
+  EFI_STATUS            Status;\r
+\r
+  ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
+  ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
+\r
+  if (ExtendedDataSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Fill in the extended data header\r
+  //\r
+  mStatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r
+  mStatusCodeData->Size = (UINT16)ExtendedDataSize;\r
+  if (ExtendedDataGuid == NULL) {\r
+    ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
+  }\r
+  CopyGuid (&mStatusCodeData->Type, ExtendedDataGuid);\r
+\r
+  //\r
+  // Fill in the extended data buffer\r
+  //\r
+  if (ExtendedData != NULL) {\r
+    CopyMem (mStatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
+  }\r
+\r
+  //\r
+  // Report the status code\r
+  //\r
+  if (CallerId == NULL) {\r
+    CallerId = &gEfiCallerIdGuid;\r
+  }\r
+  Status = InternalReportStatusCode (Type, Value, Instance, CallerId, mStatusCodeData);\r
 \r
   return Status;\r
 }\r
@@ -502,7 +444,7 @@ ReportProgressCodeEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r
+  return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_PROGRESS_CODE_ENABLED) != 0);\r
 }\r
 \r
 \r
@@ -524,7 +466,7 @@ ReportErrorCodeEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r
+  return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_ERROR_CODE_ENABLED) != 0);\r
 }\r
 \r
 \r
@@ -546,5 +488,5 @@ ReportDebugCodeEnabled (
   VOID\r
   )\r
 {\r
-  return (BOOLEAN) ((PcdGet8(PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
+  return (BOOLEAN) ((PcdGet8 (PcdReportStatusCodePropertyMask) & REPORT_STATUS_CODE_PROPERTY_DEBUG_CODE_ENABLED) != 0);\r
 }\r
index f85d0bf114ca025256308d31663e7090c5711ebd..7faff0bcec45ec1de62cceb487a9b891b9210d4d 100644 (file)
@@ -2,7 +2,7 @@
   Internal Header file of Report Status Code Library for RUNTIME\r
   DXE Phase.\r
 \r
-  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
   All rights reserved. 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
@@ -12,8 +12,8 @@
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
-#ifndef __REPORT_STATUS_CODE_LIB_INTERNAL__H\r
-#define __REPORT_STATUS_CODE_LIB_INTERNAL__H\r
+#ifndef __REPORT_STATUS_CODE_LIB_INTERNAL__H__\r
+#define __REPORT_STATUS_CODE_LIB_INTERNAL__H__\r
 \r
 #include <FrameworkDxe.h>\r
 \r
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
 #include <Library/DevicePathLib.h>\r
+#include <Library/OemHookStatusCodeLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
 \r
 #include <Guid/StatusCodeDataTypeId.h>\r
 #include <Guid/StatusCodeDataTypeDebug.h>\r
 #include <Guid/EventGroup.h>\r
+\r
 #include <Protocol/StatusCode.h>\r
+#include <Protocol/SmmBase.h>\r
+\r
 \r
-extern EFI_REPORT_STATUS_CODE  mReportStatusCode;\r
+extern EFI_STATUS_CODE_DATA    *mStatusCodeData;\r
 \r
 /**\r
-  Locatet he report status code service.\r
+  Locate the report status code service.\r
+\r
+  In SMM, it retrieves OemHookStatusCodeReport() from customized OEM Hook Status Code Lib.\r
+  Otherwise, it first tries to retrieve ReportStatusCode() in Runtime Services Table.\r
+  If not found, it then tries to retrieve ReportStatusCode() API of Report Status Code Protocol.\r
+\r
+  @return   Function pointer to the report status code service.\r
+            NULL is returned if no status code service is available.\r
 \r
-  @return     EFI_REPORT_STATUS_CODE    function point to\r
-              ReportStatusCode.\r
 **/\r
 EFI_REPORT_STATUS_CODE\r
 InternalGetReportStatusCode (\r
@@ -45,13 +55,12 @@ InternalGetReportStatusCode (
   );\r
 \r
 /**\r
-  Internal worker function that reports a status code through the Status Code Protocol\r
+  Internal worker function that reports a status code through the status code service.\r
 \r
-  This function checks to see if a Status Code Protocol is present in the handle\r
-  database.  If a Status Code Protocol is not present, then EFI_UNSUPPORTED is\r
-  returned.  If a Status Code Protocol is present, then it is cached in gStatusCode,\r
-  and the ReportStatusCode() service of the Status Code Protocol is called passing in\r
-  Type, Value, Instance, CallerId, and Data.  The result of this call is returned.\r
+  If status code service is not cached, then this function checks if status code service is\r
+  available in system.  If status code service is not available, then EFI_UNSUPPORTED is\r
+  returned.  If status code service is present, then it is cached in mReportStatusCode.\r
+  Finally this function reports status code through the status code service.\r
 \r
   @param  Type              Status code type.\r
   @param  Value             Status code value.\r
@@ -62,9 +71,9 @@ InternalGetReportStatusCode (
   @param  Data              Pointer to the extended data buffer.  This is an\r
                             optional parameter that may be NULL.\r
 \r
-  @retval  EFI_SUCCESS           The status code was reported.\r
-  @retval  EFI_OUT_OF_RESOURCES  There were not enough resources to report the status code.\r
-  @retval  EFI_UNSUPPORTED       Status Code Protocol is not available.\r
+  @retval EFI_SUCCESS       The status code was reported.\r
+  @retval EFI_UNSUPPORTED   Status code service is not available.\r
+  @retval EFI_UNSUPPORTED   Status code type is not supported.\r
 \r
 **/\r
 EFI_STATUS\r
@@ -76,60 +85,5 @@ InternalReportStatusCode (
   IN EFI_STATUS_CODE_DATA     *Data     OPTIONAL\r
   );\r
 \r
-/**\r
-  Reports a status code with full parameters.\r
-\r
-  The function reports a status code.  If ExtendedData is NULL and ExtendedDataSize\r
-  is 0, then an extended data buffer is not reported.  If ExtendedData is not\r
-  NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r
-  ExtendedData is assumed not have the standard status code header, so this function\r
-  is responsible for allocating a buffer large enough for the standard header and\r
-  the extended data passed into this function.  The standard header is filled in\r
-  with a GUID specified by ExtendedDataGuid.  If ExtendedDataGuid is NULL, then a\r
-  GUID of gEfiStatusCodeSpecificDatauid is used.  The status code is reported with\r
-  an instance specified by Instance and a caller ID specified by CallerId.  If\r
-  CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
-\r
-  ReportStatusCodeEx()must actively prevent recursion.  If ReportStatusCodeEx()\r
-  is called while processing another any other Report Status Code Library function,\r
-  then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
-\r
-  If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
-  If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
-\r
-  @param  Type              Status code type.\r
-  @param  Value             Status code value.\r
-  @param  Instance          Status code instance number.\r
-  @param  CallerId          Pointer to a GUID that identifies the caller of this\r
-                            function.  If this parameter is NULL, then a caller\r
-                            ID of gEfiCallerIdGuid is used.\r
-  @param  ExtendedDataGuid  Pointer to the GUID for the extended data buffer.\r
-                            If this parameter is NULL, then a the status code\r
-                            standard header is filled in with\r
-                            gEfiStatusCodeSpecificDataGuid.\r
-  @param  ExtendedData      Pointer to the extended data buffer.  This is an\r
-                            optional parameter that may be NULL.\r
-  @param  ExtendedDataSize  The size, in bytes, of the extended data buffer.\r
-\r
-  @retval  EFI_SUCCESS           The status code was reported.\r
-  @retval  EFI_OUT_OF_RESOURCES  There were not enough resources to allocate\r
-                                 the extended data section if it was specified.\r
-  @retval  EFI_UNSUPPORTED       Report status code is not supported\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InternalReportStatusCodeEx (\r
-  IN EFI_STATUS_CODE_TYPE   Type,\r
-  IN EFI_STATUS_CODE_VALUE  Value,\r
-  IN UINT32                 Instance,\r
-  IN CONST EFI_GUID         *CallerId          OPTIONAL,\r
-  IN CONST EFI_GUID         *ExtendedDataGuid  OPTIONAL,\r
-  IN CONST VOID             *ExtendedData      OPTIONAL,\r
-  IN UINTN                  ExtendedDataSize\r
-  );\r
-\r
-\r
-\r
-#endif // __REPORT_STATUS_CODE_LIB_INTERNAL__H\r
+#endif\r
 \r
index bd8006db1c84f7adbe5c7500a56dacb4c9ffe97c..28a5a0f4171045fff4602890f57963f18b055aef 100644 (file)
@@ -1,7 +1,10 @@
 #/** @file\r
-#  DXE report status code library\r
+#  Report status code library instance which supports logging message in SMM, as well as DXE & runtime phase.\r
+#\r
+#  This library instance supports status code report in SMM, as well as DXE & runtime phase.\r
+#  In SMM, it logs message via customized OemHookStatusCodeLib.\r
+#  Otherwise, it logs message to ReportStatusCode() in framework runtime services table or runtime report status code protocol.\r
 #\r
-#  Retrieve status code and report status code in DXE phase\r
 #  Copyright (c) 2006 - 2009, Intel Corporation.\r
 #\r
 #  All rights reserved. This program and the accompanying materials\r
@@ -21,7 +24,6 @@
   MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
   VERSION_STRING                 = 1.0\r
   LIBRARY_CLASS                  = ReportStatusCodeLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER UEFI_APPLICATION UEFI_DRIVER DXE_SMM_DRIVER\r
-  EFI_SPECIFICATION_VERSION      = 0x00020000\r
   \r
   CONSTRUCTOR                    = ReportStatusCodeLibConstruct\r
   DESTRUCTOR                     = ReportStatusCodeLibDestruct\r
@@ -34,7 +36,7 @@
 [Sources.common]\r
   ReportStatusCodeLib.c\r
   SmmRuntimeDxeSupport.c\r
-\r
+  ReportStatusCodeLibInternal.h\r
 \r
 \r
 [Packages]\r
   UefiBootServicesTableLib\r
   OemHookStatusCodeLib\r
   DevicePathLib\r
+  MemoryAllocationLib\r
 \r
 [Guids]\r
-  gEfiStatusCodeSpecificDataGuid                # ALWAYS_CONSUMED\r
-  gEfiStatusCodeDataTypeDebugGuid               # ALWAYS_CONSUMED\r
-  gEfiEventExitBootServicesGuid\r
-  gEfiEventVirtualAddressChangeGuid\r
+  gEfiStatusCodeSpecificDataGuid                ## CONSUMES\r
+  gEfiStatusCodeDataTypeDebugGuid               ## CONSUMES\r
+  gEfiEventExitBootServicesGuid                 ## CONSUMES ## Event\r
+  gEfiEventVirtualAddressChangeGuid             ## CONSUMES ## Event\r
 \r
 \r
 [Protocols]\r
-  gEfiStatusCodeRuntimeProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
-  gEfiSmmBaseProtocolGuid                       # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiStatusCodeRuntimeProtocolGuid             ## CONSUMES\r
+  gEfiSmmBaseProtocolGuid                       ## CONSUMES\r
 \r
 \r
 [Pcd.common]\r
index e176ecc36b01bb021ca05d0453432e9554547015..089b9c5db2a1d143503a5f5b99f95ecfaf0e8b2a 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  Report Status Code Library for DXE Phase.\r
+  Library constructor & destructor, event handlers, and other internal worker functions.\r
 \r
-  Copyright (c) 2006 - 2007, Intel Corporation<BR>\r
+  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
   All rights reserved. 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
 \r
 #include "ReportStatusCodeLibInternal.h"\r
 \r
-//\r
-// Resources need by SMM runtime instance\r
-// \r
-#include <Library/OemHookStatusCodeLib.h>\r
-#include <Protocol/SmmBase.h>\r
+EFI_EVENT               mVirtualAddressChangeEvent;\r
+EFI_EVENT               mExitBootServicesEvent;\r
+EFI_STATUS_CODE_DATA    *mStatusCodeData;\r
+BOOLEAN                 mInSmm;\r
+EFI_SMM_BASE_PROTOCOL   *mSmmBase;\r
+EFI_RUNTIME_SERVICES    *mInternalRT;\r
+BOOLEAN                 mHaveExitedBootServices = FALSE;\r
+EFI_REPORT_STATUS_CODE  mReportStatusCode = NULL;\r
 \r
-EFI_EVENT             mVirtualAddressChangeEvent;\r
-\r
-EFI_EVENT             mExitBootServicesEvent;\r
-\r
-EFI_STATUS_CODE_DATA  *mStatusCodeData;\r
-\r
-BOOLEAN               mInSmm;\r
-\r
-EFI_SMM_BASE_PROTOCOL *mSmmBase;\r
-\r
-EFI_RUNTIME_SERVICES  *mRT;\r
+/**\r
+  Locate the report status code service.\r
 \r
-BOOLEAN               mHaveExitedBootServices = FALSE;\r
+  In SMM, it retrieves OemHookStatusCodeReport() from customized OEM Hook Status Code Lib.\r
+  Otherwise, it first tries to retrieve ReportStatusCode() in Runtime Services Table.\r
+  If not found, it then tries to retrieve ReportStatusCode() API of Report Status Code Protocol.\r
 \r
-/**\r
-  Locate he report status code service.\r
+  @return   Function pointer to the report status code service.\r
+            NULL is returned if no status code service is available.\r
 \r
-  @return     EFI_REPORT_STATUS_CODE    function point to\r
-              ReportStatusCode.\r
 **/\r
 EFI_REPORT_STATUS_CODE\r
 InternalGetReportStatusCode (\r
@@ -50,8 +44,8 @@ InternalGetReportStatusCode (
 \r
   if (mInSmm) {\r
     return (EFI_REPORT_STATUS_CODE) OemHookStatusCodeReport;\r
-  } else if (mRT != NULL && mRT->Hdr.Revision < 0x20000) {\r
-    return ((FRAMEWORK_EFI_RUNTIME_SERVICES*)mRT)->ReportStatusCode;\r
+  } else if (mInternalRT != NULL && mInternalRT->Hdr.Revision < 0x20000) {\r
+    return ((FRAMEWORK_EFI_RUNTIME_SERVICES*)mInternalRT)->ReportStatusCode;\r
   } else if (!mHaveExitedBootServices) {\r
        //\r
        // Check gBS just in case. ReportStatusCode is called before gBS is initialized.\r
@@ -67,12 +61,65 @@ InternalGetReportStatusCode (
   return NULL;\r
 }\r
 \r
+/**\r
+  Internal worker function that reports a status code through the status code service.\r
+\r
+  If status code service is not cached, then this function checks if status code service is\r
+  available in system.  If status code service is not available, then EFI_UNSUPPORTED is\r
+  returned.  If status code service is present, then it is cached in mReportStatusCode.\r
+  Finally this function reports status code through the status code service.\r
+\r
+  @param  Type              Status code type.\r
+  @param  Value             Status code value.\r
+  @param  Instance          Status code instance number.\r
+  @param  CallerId          Pointer to a GUID that identifies the caller of this\r
+                            function.  This is an optional parameter that may be\r
+                            NULL.\r
+  @param  Data              Pointer to the extended data buffer.  This is an\r
+                            optional parameter that may be NULL.\r
+\r
+  @retval EFI_SUCCESS       The status code was reported.\r
+  @retval EFI_UNSUPPORTED   Status code service is not available.\r
+  @retval EFI_UNSUPPORTED   Status code type is not supported.\r
+\r
+**/\r
+EFI_STATUS\r
+InternalReportStatusCode (\r
+  IN EFI_STATUS_CODE_TYPE     Type,\r
+  IN EFI_STATUS_CODE_VALUE    Value,\r
+  IN UINT32                   Instance,\r
+  IN CONST EFI_GUID           *CallerId OPTIONAL,\r
+  IN EFI_STATUS_CODE_DATA     *Data     OPTIONAL\r
+  )\r
+{\r
+  if ((ReportProgressCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) ||\r
+      (ReportErrorCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) ||\r
+      (ReportDebugCodeEnabled() && ((Type) & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE)) {\r
+    //\r
+    // If mReportStatusCode is NULL, then check if status code service is available in system.\r
+    //\r
+    if (mReportStatusCode == NULL) {\r
+      mReportStatusCode = InternalGetReportStatusCode ();\r
+      if (mReportStatusCode == NULL) {\r
+        return EFI_UNSUPPORTED;\r
+      }\r
+    }\r
+  \r
+    //\r
+    // A status code service is present in system, so pass in all the parameters to the service.\r
+    //\r
+    return (*mReportStatusCode) (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r
+  }\r
+  \r
+  return EFI_UNSUPPORTED;\r
+}\r
 \r
 /**\r
-  Fixup internal report status code protocol interface.\r
+  Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.\r
+\r
+  @param  Event        Event whose notification function is being invoked.\r
+  @param  Context      Pointer to the notification function's context\r
 \r
-  @param[in]    Event   The Event that is being processed\r
-  @param[in]    Context Event Context\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -81,18 +128,19 @@ ReportStatusCodeLibVirtualAddressChange (
   IN VOID             *Context\r
   )\r
 {\r
-  if (NULL != mReportStatusCode) {\r
-    mRT->ConvertPointer (0, (VOID **) &mReportStatusCode);\r
+  if (mReportStatusCode != NULL) {\r
+    mInternalRT->ConvertPointer (0, (VOID **) &mReportStatusCode);\r
   }\r
-  mRT->ConvertPointer (0, (VOID **) &mStatusCodeData);\r
-  mRT->ConvertPointer (0, (VOID **) &mRT);\r
+  mInternalRT->ConvertPointer (0, (VOID **) &mStatusCodeData);\r
+  mInternalRT->ConvertPointer (0, (VOID **) &mInternalRT);\r
 }\r
 \r
 /**\r
-  Update the In Runtime Indicator.\r
+  Notification function of EVT_SIGNAL_EXIT_BOOT_SERVICES.\r
+\r
+  @param  Event        Event whose notification function is being invoked.\r
+  @param  Context      Pointer to the notification function's context\r
 \r
-  @param[in]    Event   The Event that is being processed\r
-  @param[in]    Context Event Context\r
 **/\r
 VOID\r
 EFIAPI\r
@@ -105,12 +153,16 @@ ReportStatusCodeLibExitBootServices (
 }\r
 \r
 /**\r
-  Intialize Report Status Code Lib.\r
+  The constructor function of SMM Runtime DXE Report Status Code Lib.\r
 \r
-  @param[in]  ImageHandle   The firmware allocated handle for the EFI image.\r
-  @param[in]  SystemTable   A pointer to the EFI System Table.\r
+  This function allocates memory for extended status code data, caches\r
+  the report status code service, and registers events.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
 \r
-  @return     EFI_STATUS    always returns EFI_SUCCESS.\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -119,12 +171,11 @@ ReportStatusCodeLibConstruct (
   IN EFI_SYSTEM_TABLE     *SystemTable\r
   )\r
 {\r
-  EFI_STATUS            Status;\r
+  EFI_STATUS     Status;\r
 \r
   //\r
-  // SMM driver depends on the SMM BASE protocol.\r
-  // the SMM driver must be success to locate protocol.\r
-  // \r
+  // If in SMM mode, then allocates memory from SMRAM for extended status code data.\r
+  //\r
   Status = gBS->LocateProtocol (&gEfiSmmBaseProtocolGuid, NULL, (VOID **) &mSmmBase);\r
   if (!EFI_ERROR (Status)) {\r
     mSmmBase->InSmm (mSmmBase, &mInSmm);\r
@@ -141,22 +192,24 @@ ReportStatusCodeLibConstruct (
     }\r
   }\r
 \r
+\r
   //\r
-  // Library should not use the gRT directly, since it\r
-  // may be converted by other library instance.\r
+  // If not in SMM mode, then allocate runtime memory for extended status code data.\r
+  //\r
+  // Library should not use the gRT directly, for it may be converted by other library instance.\r
   // \r
-  mRT     = gRT;\r
-  mInSmm  = FALSE;\r
+  mInternalRT = gRT;\r
+  mInSmm      = FALSE;\r
 \r
-  gBS->AllocatePool (EfiRuntimeServicesData, sizeof (EFI_STATUS_CODE_DATA) + EFI_STATUS_CODE_DATA_MAX_SIZE, (VOID **)&mStatusCodeData);\r
-  ASSERT (NULL != mStatusCodeData);\r
+  mStatusCodeData = AllocateRuntimePool (sizeof (EFI_STATUS_CODE_DATA) + EFI_STATUS_CODE_DATA_MAX_SIZE);\r
+  ASSERT (mStatusCodeData != NULL);\r
   //\r
   // Cache the report status code service\r
   // \r
   mReportStatusCode = InternalGetReportStatusCode ();\r
 \r
   //\r
-  // Register the call back of virtual address change\r
+  // Register notify function for EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE\r
   // \r
   Status = gBS->CreateEventEx (\r
                   EVT_NOTIFY_SIGNAL,\r
@@ -168,9 +221,8 @@ ReportStatusCodeLibConstruct (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-\r
   //\r
-  // Register the call back of virtual address change\r
+  // Register notify function for EVT_SIGNAL_EXIT_BOOT_SERVICES\r
   // \r
   Status = gBS->CreateEventEx (\r
                   EVT_NOTIFY_SIGNAL,\r
@@ -182,15 +234,20 @@ ReportStatusCodeLibConstruct (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  Desctructor of library will close events.\r
+  The destructor function of SMM Runtime DXE Report Status Code Lib.\r
+  \r
+  The destructor function frees memory allocated by constructor, and closes related events.\r
+  It will ASSERT() if that related operation fails and it will always return EFI_SUCCESS. \r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
   \r
-  @param ImageHandle callder module's image handle\r
-  @param SystemTable pointer to EFI system table.\r
-  @return the status of close event.\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
 **/\r
 EFI_STATUS\r
 EFIAPI\r
@@ -202,16 +259,13 @@ ReportStatusCodeLibDestruct (
   EFI_STATUS  Status;\r
 \r
   if (!mInSmm) {\r
-    //\r
-    // Close SetVirtualAddressMap () notify function\r
-    //\r
     ASSERT (gBS != NULL);\r
     Status = gBS->CloseEvent (mVirtualAddressChangeEvent);\r
     ASSERT_EFI_ERROR (Status);\r
     Status = gBS->CloseEvent (mExitBootServicesEvent);\r
     ASSERT_EFI_ERROR (Status);\r
 \r
-    gBS->FreePool (mStatusCodeData);\r
+    FreePool (mStatusCodeData);\r
   } else {\r
     mSmmBase->SmmFreePool (mSmmBase, mStatusCodeData);\r
   }\r
@@ -219,89 +273,3 @@ ReportStatusCodeLibDestruct (
   return EFI_SUCCESS;\r
 }\r
 \r
-/**\r
-  Reports a status code with full parameters.\r
-\r
-  The function reports a status code.  If ExtendedData is NULL and ExtendedDataSize\r
-  is 0, then an extended data buffer is not reported.  If ExtendedData is not\r
-  NULL and ExtendedDataSize is not 0, then an extended data buffer is allocated.\r
-  ExtendedData is assumed not have the standard status code header, so this function\r
-  is responsible for allocating a buffer large enough for the standard header and\r
-  the extended data passed into this function.  The standard header is filled in\r
-  with a GUID specified by ExtendedDataGuid.  If ExtendedDataGuid is NULL, then a\r
-  GUID of gEfiStatusCodeSpecificDatauid is used.  The status code is reported with\r
-  an instance specified by Instance and a caller ID specified by CallerId.  If\r
-  CallerId is NULL, then a caller ID of gEfiCallerIdGuid is used.\r
-\r
-  ReportStatusCodeEx()must actively prevent recursion.  If ReportStatusCodeEx()\r
-  is called while processing another any other Report Status Code Library function,\r
-  then ReportStatusCodeEx() must return EFI_DEVICE_ERROR immediately.\r
-\r
-  If ExtendedData is NULL and ExtendedDataSize is not zero, then ASSERT().\r
-  If ExtendedData is not NULL and ExtendedDataSize is zero, then ASSERT().\r
-\r
-  @param  Type              Status code type.\r
-  @param  Value             Status code value.\r
-  @param  Instance          Status code instance number.\r
-  @param  CallerId          Pointer to a GUID that identifies the caller of this\r
-                            function.  If this parameter is NULL, then a caller\r
-                            ID of gEfiCallerIdGuid is used.\r
-  @param  ExtendedDataGuid  Pointer to the GUID for the extended data buffer.\r
-                            If this parameter is NULL, then a the status code\r
-                            standard header is filled in with\r
-                            gEfiStatusCodeSpecificDataGuid.\r
-  @param  ExtendedData      Pointer to the extended data buffer.  This is an\r
-                            optional parameter that may be NULL.\r
-  @param  ExtendedDataSize  The size, in bytes, of the extended data buffer.\r
-\r
-  @retval  EFI_SUCCESS           The status code was reported.\r
-  @retval  EFI_OUT_OF_RESOURCES  There were not enough resources to allocate\r
-                                 the extended data section if it was specified.\r
-  @retval  EFI_UNSUPPORTED       Report status code is not supported\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-InternalReportStatusCodeEx (\r
-  IN EFI_STATUS_CODE_TYPE   Type,\r
-  IN EFI_STATUS_CODE_VALUE  Value,\r
-  IN UINT32                 Instance,\r
-  IN CONST EFI_GUID         *CallerId          OPTIONAL,\r
-  IN CONST EFI_GUID         *ExtendedDataGuid  OPTIONAL,\r
-  IN CONST VOID             *ExtendedData      OPTIONAL,\r
-  IN UINTN                  ExtendedDataSize\r
-  )\r
-{\r
-  ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
-  ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
-\r
-  if (ExtendedDataSize > EFI_STATUS_CODE_DATA_MAX_SIZE) {\r
-    return EFI_OUT_OF_RESOURCES;\r
-  }\r
-\r
-  //\r
-  // Fill in the extended data header\r
-  //\r
-  mStatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r
-  mStatusCodeData->Size = (UINT16)ExtendedDataSize;\r
-  if (ExtendedDataGuid == NULL) {\r
-    ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
-  }\r
-  CopyGuid (&mStatusCodeData->Type, ExtendedDataGuid);\r
-\r
-  //\r
-  // Fill in the extended data buffer\r
-  //\r
-  if (ExtendedData != NULL) {\r
-    CopyMem (mStatusCodeData + 1, ExtendedData, ExtendedDataSize);\r
-  }\r
-\r
-  //\r
-  // Report the status code\r
-  //\r
-  if (CallerId == NULL) {\r
-    CallerId = &gEfiCallerIdGuid;\r
-  }\r
-  return  InternalReportStatusCode (Type, Value, Instance, CallerId, mStatusCodeData);\r
-}\r
-\r