]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Universal/StatusCode/Dxe/DataHubStatusCodeWorker.c
Clean up: update "EFI" to "UEFI" if applicable.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / StatusCode / Dxe / DataHubStatusCodeWorker.c
index d72884d73db61727df05aed6e372f0f057aed9cd..0936c093eba2a2fa0f26581370e6c5483e0f7496 100644 (file)
@@ -10,8 +10,6 @@
   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-  Module Name:  DataHubStatusCodeWorker.c\r
-\r
 **/\r
 \r
 #include "DxeStatusCode.h"\r
@@ -24,6 +22,8 @@ LIST_ENTRY                mRecordsFifo          = INITIALIZE_LIST_HEAD_VARIABLE
 STATIC\r
 LIST_ENTRY                mRecordsBuffer        = INITIALIZE_LIST_HEAD_VARIABLE (mRecordsBuffer);\r
 STATIC\r
+UINT32                    mLogDataHubStatus     = 0;\r
+STATIC\r
 EFI_EVENT                 mLogDataHubEvent;\r
 //\r
 // Cache data hub protocol.\r
@@ -61,6 +61,9 @@ AcquireRecordBuffer (
     Record = _CR (Node, DATAHUB_STATUSCODE_RECORD, Node);\r
   } else {\r
     if (CurrentTpl > TPL_NOTIFY) {\r
+      //\r
+      // Memory management should work at <=TPL_NOTIFY\r
+      // \r
       gBS->RestoreTPL (CurrentTpl);\r
       return NULL;\r
     }\r
@@ -110,10 +113,9 @@ RetrieveRecord (
   if (!IsListEmpty (&mRecordsFifo)) {\r
     Node = GetFirstNode (&mRecordsFifo);\r
     Record = CR (Node, DATAHUB_STATUSCODE_RECORD, Node, DATAHUB_STATUS_CODE_SIGNATURE);\r
+    ASSERT (NULL != Record);\r
 \r
     RemoveEntryList (&Record->Node);\r
-    InsertTailList (&mRecordsBuffer, &Record->Node);\r
-    Record->Signature = 0;\r
     RecordData = (DATA_HUB_STATUS_CODE_DATA_RECORD *) Record->Data;\r
   }\r
 \r
@@ -122,6 +124,34 @@ RetrieveRecord (
   return RecordData;\r
 }\r
 \r
+/**\r
+  Release Records to FIFO.\r
+  \r
+  @param RecordData  Point to the record buffer allocated\r
+                     from AcquireRecordBuffer.\r
+\r
+**/\r
+STATIC\r
+VOID\r
+ReleaseRecord (\r
+  DATA_HUB_STATUS_CODE_DATA_RECORD  *RecordData\r
+  )\r
+{\r
+  DATAHUB_STATUSCODE_RECORD         *Record;\r
+  EFI_TPL                           CurrentTpl;\r
+\r
+  Record = CR (RecordData, DATAHUB_STATUSCODE_RECORD, Data[0], DATAHUB_STATUS_CODE_SIGNATURE);\r
+  ASSERT (NULL != Record);\r
+\r
+  CurrentTpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+  InsertTailList (&mRecordsBuffer, &Record->Node);\r
+  Record->Signature = 0;\r
+\r
+  gBS->RestoreTPL (CurrentTpl);\r
+}\r
+\r
+\r
 \r
 /**\r
   Report status code into DataHub.\r
@@ -143,7 +173,7 @@ RetrieveRecord (
 \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
-                        Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.\r
+                        Type EFI_GUID is defined in InstallProtocolInterface() in the UEFI 2.0 Specification.\r
 \r
 \r
   @param  Data          This optional parameter may be used to pass additional data\r
@@ -168,6 +198,15 @@ DataHubStatusCodeReportWorker (
   CHAR8                             *Format;\r
   UINTN                             CharCount;\r
 \r
+\r
+  //\r
+  // Use atom operation to avoid the reentant of report.\r
+  // If current status is not zero, then the function is reentrancy.\r
+  //\r
+  if (1 == InterlockedCompareExchange32 (&mLogDataHubStatus, 0, 0)) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
   //\r
   // See whether in runtime phase or not.\r
   //\r
@@ -247,6 +286,14 @@ LogDataHubEventCallBack (
   UINT32                            Size;\r
   UINT64                            DataRecordClass;\r
 \r
+  //\r
+  // Use atom operation to avoid the reentant of report.\r
+  // If current status is not zero, then the function is reentrancy.\r
+  //\r
+  if (1 == InterlockedCompareExchange32 (&mLogDataHubStatus, 0, 1)) {\r
+    return;\r
+  }\r
+\r
   //\r
   // Log DataRecord in Data Hub.\r
   // Journal records fifo to find all record entry.\r
@@ -283,14 +330,20 @@ LogDataHubEventCallBack (
 \r
     mDataHubProtocol->LogData (\r
                         mDataHubProtocol,\r
-                        &gEfiStatusCodeGuid,\r
+                        &gEfiDataHubStatusCodeRecordGuid,\r
                         &gEfiStatusCodeRuntimeProtocolGuid,\r
                         DataRecordClass,\r
                         Record,\r
                         Size\r
                         );\r
 \r
+    ReleaseRecord (Record);\r
   }\r
+\r
+  //\r
+  // Restore the nest status of report\r
+  //\r
+  InterlockedCompareExchange32 (&mLogDataHubStatus, 1, 0);\r
 }\r
 \r
 \r