]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/SmmCorePerformanceLib/SmmCorePerformanceLib.c
MdeModulePkg PerformanceLib: Fix GCC build failure caused by cfb0aba
[mirror_edk2.git] / MdeModulePkg / Library / SmmCorePerformanceLib / SmmCorePerformanceLib.c
index f28b657c94ddba3fb012296f8721b44b264f8c76..cd1f1a5d5f6627e0f182238265d3dbe874a2edd5 100644 (file)
@@ -16,7 +16,7 @@
 \r
  SmmPerformanceHandlerEx(), SmmPerformanceHandler() will receive untrusted input and do basic validation.\r
 \r
-Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2017, 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
@@ -69,6 +69,8 @@ PERFORMANCE_EX_PROTOCOL mPerformanceExInterface = {
   GetGaugeEx\r
 };\r
 \r
+PERFORMANCE_PROPERTY mPerformanceProperty;\r
+\r
 /**\r
   Searches in the gauge array with keyword Handle, Token, Module and Identfier.\r
 \r
@@ -118,8 +120,7 @@ SmmSearchForGaugeEntry (
     if (GaugeEntryExArray[Index2].EndTimeStamp == 0 &&\r
         (GaugeEntryExArray[Index2].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
         AsciiStrnCmp (GaugeEntryExArray[Index2].Token, Token, SMM_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-        AsciiStrnCmp (GaugeEntryExArray[Index2].Module, Module, SMM_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-        (GaugeEntryExArray[Index2].Identifier == Identifier)) {\r
+        AsciiStrnCmp (GaugeEntryExArray[Index2].Module, Module, SMM_PERFORMANCE_STRING_LENGTH) == 0) {\r
       Index = Index2;\r
       break;\r
     }\r
@@ -229,7 +230,7 @@ StartGaugeEx (
   for the first matching record that contains a zero end time and fills in a valid end time.\r
 \r
   Searches the performance measurement log from the beginning of the log\r
-  for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\r
+  for the first record that matches Handle, Token and Module and has an end time value of zero.\r
   If the record can not be found then return EFI_NOT_FOUND.\r
   If the record is found and TimeStamp is not zero,\r
   then the end time in the record is filled in with the value specified by TimeStamp.\r
@@ -482,7 +483,8 @@ SmmPerformanceHandlerEx (
   EFI_STATUS                Status;\r
   SMM_PERF_COMMUNICATE_EX   *SmmPerfCommData;\r
   GAUGE_DATA_ENTRY_EX       *GaugeEntryExArray;\r
-  UINTN                     DataSize;\r
+  UINT64                    DataSize;\r
+  UINTN                     Index;\r
   GAUGE_DATA_ENTRY_EX       *GaugeDataEx;\r
   UINTN                     NumberOfEntries;\r
   UINTN                     LogEntryKey;\r
@@ -521,7 +523,7 @@ SmmPerformanceHandlerEx (
       NumberOfEntries = SmmPerfCommData->NumberOfEntries;\r
       LogEntryKey = SmmPerfCommData->LogEntryKey;\r
        if (GaugeDataEx == NULL || NumberOfEntries == 0 || LogEntryKey > mGaugeData->NumberOfEntries ||\r
-           NumberOfEntries > mGaugeData->NumberOfEntries || (LogEntryKey + NumberOfEntries) > mGaugeData->NumberOfEntries) {\r
+           NumberOfEntries > mGaugeData->NumberOfEntries || LogEntryKey > (mGaugeData->NumberOfEntries - NumberOfEntries)) {\r
          Status = EFI_INVALID_PARAMETER;\r
          break;\r
        }\r
@@ -529,19 +531,22 @@ SmmPerformanceHandlerEx (
        //\r
        // Sanity check\r
        //\r
-       DataSize = NumberOfEntries * sizeof(GAUGE_DATA_ENTRY_EX);\r
-       if (!SmmIsBufferOutsideSmmValid ((UINTN)GaugeDataEx, DataSize)) {\r
+       DataSize = MultU64x32 (NumberOfEntries, sizeof(GAUGE_DATA_ENTRY_EX));\r
+       if (!SmmIsBufferOutsideSmmValid ((UINTN) GaugeDataEx, DataSize)) {\r
          DEBUG ((EFI_D_ERROR, "SmmPerformanceHandlerEx: SMM Performance Data buffer in SMRAM or overflow!\n"));\r
          Status = EFI_ACCESS_DENIED;\r
          break;\r
        }\r
 \r
        GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
-       CopyMem(\r
-         (UINT8 *) GaugeDataEx,\r
-         (UINT8 *) &GaugeEntryExArray[LogEntryKey],\r
-         DataSize\r
-         );\r
+\r
+       for (Index = 0; Index < NumberOfEntries; Index++) {\r
+         CopyMem (\r
+           (UINT8 *) &GaugeDataEx[Index],\r
+           (UINT8 *) &GaugeEntryExArray[LogEntryKey++],\r
+           sizeof (GAUGE_DATA_ENTRY_EX)\r
+           );\r
+       }\r
        Status = EFI_SUCCESS;\r
        break;\r
 \r
@@ -590,7 +595,7 @@ SmmPerformanceHandler (
   EFI_STATUS            Status;\r
   SMM_PERF_COMMUNICATE  *SmmPerfCommData;\r
   GAUGE_DATA_ENTRY_EX   *GaugeEntryExArray;\r
-  UINT                DataSize;\r
+  UINT64                DataSize;\r
   UINTN                 Index;\r
   GAUGE_DATA_ENTRY      *GaugeData;\r
   UINTN                 NumberOfEntries;\r
@@ -630,7 +635,7 @@ SmmPerformanceHandler (
        NumberOfEntries = SmmPerfCommData->NumberOfEntries;\r
        LogEntryKey = SmmPerfCommData->LogEntryKey;\r
        if (GaugeData == NULL || NumberOfEntries == 0 || LogEntryKey > mGaugeData->NumberOfEntries ||\r
-           NumberOfEntries > mGaugeData->NumberOfEntries || (LogEntryKey + NumberOfEntries) > mGaugeData->NumberOfEntries) {\r
+           NumberOfEntries > mGaugeData->NumberOfEntries || LogEntryKey > (mGaugeData->NumberOfEntries - NumberOfEntries)) {\r
          Status = EFI_INVALID_PARAMETER;\r
          break;\r
        }\r
@@ -638,8 +643,8 @@ SmmPerformanceHandler (
        //\r
        // Sanity check\r
        //\r
-       DataSize = NumberOfEntries * sizeof(GAUGE_DATA_ENTRY);\r
-       if (!SmmIsBufferOutsideSmmValid ((UINTN)GaugeData, DataSize)) {\r
+       DataSize = MultU64x32 (NumberOfEntries, sizeof(GAUGE_DATA_ENTRY));\r
+       if (!SmmIsBufferOutsideSmmValid ((UINTN) GaugeData, DataSize)) {\r
          DEBUG ((EFI_D_ERROR, "SmmPerformanceHandler: SMM Performance Data buffer in SMRAM or overflow!\n"));\r
          Status = EFI_ACCESS_DENIED;\r
          break;\r
@@ -648,7 +653,7 @@ SmmPerformanceHandler (
        GaugeEntryExArray = (GAUGE_DATA_ENTRY_EX *) (mGaugeData + 1);\r
 \r
        for (Index = 0; Index < NumberOfEntries; Index++) {\r
-         CopyMem(\r
+         CopyMem (\r
            (UINT8 *) &GaugeData[Index],\r
            (UINT8 *) &GaugeEntryExArray[LogEntryKey++],\r
            sizeof (GAUGE_DATA_ENTRY)\r
@@ -684,6 +689,7 @@ InitializeSmmCorePerformanceLib (
 {\r
   EFI_STATUS                Status;\r
   EFI_HANDLE                Handle;\r
+  PERFORMANCE_PROPERTY      *PerformanceProperty;\r
 \r
   //\r
   // Initialize spin lock\r
@@ -722,6 +728,21 @@ InitializeSmmCorePerformanceLib (
   ASSERT_EFI_ERROR (Status);\r
   Status = gSmst->SmiHandlerRegister (SmmPerformanceHandlerEx, &gSmmPerformanceExProtocolGuid, &Handle);\r
   ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = EfiGetSystemConfigurationTable (&gPerformanceProtocolGuid, (VOID **) &PerformanceProperty);\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // Install configuration table for performance property.\r
+    //\r
+    mPerformanceProperty.Revision  = PERFORMANCE_PROPERTY_REVISION;\r
+    mPerformanceProperty.Reserved  = 0;\r
+    mPerformanceProperty.Frequency = GetPerformanceCounterProperties (\r
+                                       &mPerformanceProperty.TimerStartValue,\r
+                                       &mPerformanceProperty.TimerEndValue\r
+                                       );\r
+    Status = gBS->InstallConfigurationTable (&gPerformanceProtocolGuid, &mPerformanceProperty);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
 }\r
 \r
 /**\r
@@ -823,7 +844,7 @@ StartPerformanceMeasurementEx (
   for the first matching record that contains a zero end time and fills in a valid end time.\r
 \r
   Searches the performance measurement log from the beginning of the log\r
-  for the first record that matches Handle, Token, Module and Identifier and has an end time value of zero.\r
+  for the first record that matches Handle, Token and Module and has an end time value of zero.\r
   If the record can not be found then return RETURN_NOT_FOUND.\r
   If the record is found and TimeStamp is not zero,\r
   then the end time in the record is filled in with the value specified by TimeStamp.\r