]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/SmmRuntimeDxeReportStatusCodeLibFramework/SmmRuntimeDxeSupport.c
Update the copyright notice format
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / SmmRuntimeDxeReportStatusCodeLibFramework / SmmRuntimeDxeSupport.c
index c68016083137bea2a26a27bca4154f8fb0f01993..1197e7c6166c1b542ebed9008ded1a4d53fc51c2 100644 (file)
@@ -1,8 +1,8 @@
 /** @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
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2006 - 2010, 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
 \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
+EFI_SMM_STATUS_CODE_PROTOCOL  *mSmmStatusCodeProtocol;\r
 \r
-EFI_EVENT             mVirtualAddressChangeEvent;\r
-\r
-EFI_EVENT             mExitBootServicesEvent;\r
+/**\r
+  Locates and caches SMM Status Code Protocol.\r
\r
+**/\r
+VOID\r
+SmmStatusCodeInitialize (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
 \r
-EFI_STATUS_CODE_DATA  *mStatusCodeData;\r
+  Status = gBS->LocateProtocol (&gEfiSmmStatusCodeProtocolGuid, NULL, (VOID **) &mSmmStatusCodeProtocol);\r
+  if (EFI_ERROR (Status)) {\r
+    mSmmStatusCodeProtocol = NULL;\r
+  }\r
+}\r
 \r
-BOOLEAN               mInSmm;\r
+/**\r
+  Report status code via SMM Status Code Protocol.\r
\r
+  @param  Type          Indicates the type of status code being reported.\r
+  @param  Value         Describes the current status of a hardware or software entity.  \r
+                        This included information about the class and subclass that is used to classify the entity \r
+                        as well as an operation.  For progress codes, the operation is the current activity. \r
+                        For error codes, it is the exception.  For debug codes, it is not defined at this time. \r
+  @param  Instance      The enumeration of a hardware or software entity within the system.  \r
+                        A system may contain multiple entities that match a class/subclass pairing. \r
+                        The instance differentiates between them.  An instance of 0 indicates that instance information is unavailable, \r
+                        not meaningful, or not relevant.  Valid instance numbers start with 1.\r
+  @param  CallerId      This optional parameter may be used to identify the caller. \r
+                        This parameter allows the status code driver to apply different rules to different callers. \r
+  @param  Data          This optional parameter may be used to pass additional data\r
\r
+  @retval EFI_SUCCESS   Always return EFI_SUCCESS.\r
 \r
-EFI_SMM_BASE_PROTOCOL *mSmmBase;\r
+**/\r
+EFI_STATUS\r
+SmmStatusCodeReport (\r
+  IN EFI_STATUS_CODE_TYPE     Type,\r
+  IN EFI_STATUS_CODE_VALUE    Value,\r
+  IN UINT32                   Instance,\r
+  IN EFI_GUID                 *CallerId OPTIONAL,\r
+  IN EFI_STATUS_CODE_DATA     *Data     OPTIONAL\r
+  )\r
+{\r
+  if (mSmmStatusCodeProtocol != NULL) {\r
+    (mSmmStatusCodeProtocol->ReportStatusCode) (mSmmStatusCodeProtocol, Type, Value, Instance, CallerId, Data);\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
 \r
-EFI_RUNTIME_SERVICES  *mRT;\r
+/**\r
+  Locate the report status code service.\r
 \r
-BOOLEAN               mHaveExitedBootServices = FALSE;\r
+  In SMM, it tries to retrieve SMM Status Code Protocol.\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
@@ -49,9 +95,9 @@ InternalGetReportStatusCode (
   EFI_STATUS                Status;\r
 \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
+    return (EFI_REPORT_STATUS_CODE) SmmStatusCodeReport;\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 +113,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 +180,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 +205,16 @@ ReportStatusCodeLibExitBootServices (
 }\r
 \r
 /**\r
-  Intialize Report Status Code Lib.\r
+  The constructor function of SMM Runtime DXE Report Status Code Lib.\r
+\r
+  This function allocates memory for extended status code data, caches\r
+  the report status code service, and registers events.\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
+  @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 +223,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
@@ -136,27 +239,29 @@ ReportStatusCodeLibConstruct (
                            (VOID **) &mStatusCodeData\r
                            );\r
       ASSERT_EFI_ERROR (Status);\r
-      OemHookStatusCodeInitialize ();\r
+      SmmStatusCodeInitialize ();\r
       return EFI_SUCCESS;\r
     }\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 +273,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 +286,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 +311,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,87 +325,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
-  CopyMem (mStatusCodeData + 1, ExtendedData, ExtendedDataSize);\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