]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.c
MdeModulePkg/DxeCorePerformanceLib: use AllocatePeiAccessiblePages
[mirror_edk2.git] / MdeModulePkg / Library / DxeCorePerformanceLib / DxeCorePerformanceLib.c
index 8363b0e4ed5ceae5acbaabb687a6cd63fefba5d3..68b29ac5a9e291493060ec913bb9468f8652342a 100644 (file)
@@ -115,6 +115,10 @@ IsKnownTokens (
   IN CONST CHAR8  *Token\r
   )\r
 {\r
+  if (Token == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
   if (AsciiStrCmp (Token, SEC_TOK) == 0 ||\r
       AsciiStrCmp (Token, PEI_TOK) == 0 ||\r
       AsciiStrCmp (Token, DXE_TOK) == 0 ||\r
@@ -161,46 +165,6 @@ IsKnownID (
   }\r
 }\r
 \r
-/**\r
-  Allocate EfiReservedMemoryType below 4G memory address.\r
-\r
-  This function allocates EfiReservedMemoryType below 4G memory address.\r
-\r
-  @param[in]  Size   Size of memory to allocate.\r
-\r
-  @return Allocated address for output.\r
-\r
-**/\r
-VOID *\r
-FpdtAllocateReservedMemoryBelow4G (\r
-  IN UINTN       Size\r
-  )\r
-{\r
-  UINTN                 Pages;\r
-  EFI_PHYSICAL_ADDRESS  Address;\r
-  EFI_STATUS            Status;\r
-  VOID                  *Buffer;\r
-\r
-  Buffer  = NULL;\r
-  Pages   = EFI_SIZE_TO_PAGES (Size);\r
-  Address = 0xffffffff;\r
-\r
-  Status = gBS->AllocatePages (\r
-                  AllocateMaxAddress,\r
-                  EfiReservedMemoryType,\r
-                  Pages,\r
-                  &Address\r
-                  );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  if (!EFI_ERROR (Status)) {\r
-    Buffer = (VOID *) (UINTN) Address;\r
-    ZeroMem (Buffer, Size);\r
-  }\r
-\r
-  return Buffer;\r
-}\r
-\r
 /**\r
   Allocate buffer for Boot Performance table.\r
 \r
@@ -279,9 +243,8 @@ AllocateBootPerformanceTable (
         SmmCommData->Function       = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE;\r
         SmmCommData->BootRecordData = NULL;\r
         Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
-        ASSERT_EFI_ERROR (Status);\r
 \r
-        if (!EFI_ERROR (SmmCommData->ReturnStatus) && SmmCommData->BootRecordSize != 0) {\r
+        if (!EFI_ERROR (Status) && !EFI_ERROR (SmmCommData->ReturnStatus) && SmmCommData->BootRecordSize != 0) {\r
           //\r
           // Get all boot records\r
           //\r
@@ -313,7 +276,7 @@ AllocateBootPerformanceTable (
   // Boot Performance table includes BasicBoot record, and one or more appended Boot Records.\r
   //\r
   BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mPerformanceLength + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
-  if (SmmCommData != NULL) {\r
+  if (SmmCommData != NULL && SmmBootRecordData != NULL) {\r
     BootPerformanceDataSize += SmmBootRecordDataSize;\r
   }\r
 \r
@@ -345,7 +308,13 @@ AllocateBootPerformanceTable (
     //\r
     // Fail to allocate at specified address, continue to allocate at any address.\r
     //\r
-    mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) FpdtAllocateReservedMemoryBelow4G (BootPerformanceDataSize);\r
+    mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) AllocatePeiAccessiblePages (\r
+                                                             EfiReservedMemoryType,\r
+                                                             EFI_SIZE_TO_PAGES (BootPerformanceDataSize)\r
+                                                             );\r
+    if (mAcpiBootPerformanceTable != NULL) {\r
+      ZeroMem (mAcpiBootPerformanceTable, BootPerformanceDataSize);\r
+    }\r
   }\r
   DEBUG ((DEBUG_INFO, "DxeCorePerformanceLib: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
 \r
@@ -847,7 +816,7 @@ InsertFpdtMeasurement (
 \r
   //\r
   // If PERF_START()/PERF_END() have specified the ProgressID,it has high priority.\r
-  // !!! Note: If the Pref is not the known Token used in the core but have same\r
+  // !!! Note: If the Perf is not the known Token used in the core but have same\r
   // ID with the core Token, this case will not be supported.\r
   // And in currtnt usage mode, for the unkown ID, there is a general rule:\r
   // If it is start pref: the lower 4 bits of the ID should be 0.\r