]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Enhance ACPI FPDT DXE and SMM driver to accept the extension boot records.
authorlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 8 May 2012 03:09:54 +0000 (03:09 +0000)
committerlgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 8 May 2012 03:09:54 +0000 (03:09 +0000)
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Eric Jin <eric.jin@intel.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@13292 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Include/Guid/FirmwarePerformance.h
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.c
MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableSmm/FirmwarePerformanceSmm.inf

index 411a03a9d8d1725d3ef1119585ee24e71dd595c6..89e225d505ef9f250b6c6364ee5b8dc85acf2c0d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   ACPI Firmware Performance Data Table (FPDT) implementation specific definitions.\r
 \r
-  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2012, 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
 ///   GUID - gEfiFirmwarePerformanceGuid\r
 ///   Data - FIRMWARE_SEC_PERFORMANCE (defined in <Ppi/SecPerformance.h>)\r
 ///\r
+/// SMI:\r
+///   GUID - gEfiFirmwarePerformanceGuid\r
+///   Data - SMM_BOOT_RECORD_COMMUNICATE\r
+///\r
+/// StatusCodeData:\r
+///   Type - gEfiFirmwarePerformanceGuid\r
+///   Data - One or more boot record\r
+///\r
 #define EFI_FIRMWARE_PERFORMANCE_GUID \\r
   { \\r
     0xc095791a, 0x3001, 0x47b2, {0x80, 0xc9, 0xea, 0xc7, 0x31, 0x9f, 0x2f, 0xa4 } \\r
@@ -72,6 +80,9 @@ typedef struct {
 typedef struct {\r
   EFI_ACPI_5_0_FPDT_PERFORMANCE_TABLE_HEADER   Header;     ///< Common ACPI table header.\r
   EFI_ACPI_5_0_FPDT_FIRMWARE_BASIC_BOOT_RECORD BasicBoot;  ///< Basic Boot Resume performance record.\r
+  //\r
+  // one or more boot performance records.\r
+  //\r
 } BOOT_PERFORMANCE_TABLE;\r
 \r
 ///\r
@@ -93,6 +104,19 @@ typedef struct {
 \r
 #pragma pack()\r
 \r
+//\r
+// Log BOOT RECORD from SMM driver on boot time.\r
+//\r
+#define SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE          1\r
+#define SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA          2\r
+\r
+typedef struct {\r
+  UINTN             Function;\r
+  EFI_STATUS        ReturnStatus;\r
+  UINTN             BootRecordSize;\r
+  VOID              *BootRecordData;\r
+} SMM_BOOT_RECORD_COMMUNICATE;\r
+\r
 extern EFI_GUID gEfiFirmwarePerformanceGuid;\r
 \r
 #endif\r
index 775dfa614dadf0e78e249c0070d069217952a55c..ccba64cd042fdf58b2198f0a87fa78af565ce45d 100644 (file)
 [PcdsPatchableInModule]\r
   ## Specify  memory size with page number for PEI code when \r
   #  the feature of Loading Module at Fixed Address is enabled\r
+  ## This PCD specifies the additional pad size in FPDT Basic Boot Performance Table for \r
+  #  the extension FPDT boot records got after ReadyToBoot and before ExitBootService.\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdExtFpdtBootRecordPadSize|0x0|UINT32|0x0001005F\r
+\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdLoadFixAddressPeiCodePageNumber|0|UINT32|0x00000029\r
   \r
   ## Specify  memory size with page number for DXE boot time code when \r
index fbd0046513eecceb73d27264f2009587010e312a..602968c47146ecd6bdad5ae4cf99e77b4e13d328 100644 (file)
@@ -2,9 +2,10 @@
   This module install ACPI Firmware Performance Data Table (FPDT).\r
 \r
   This module register report status code listener to collect performance data\r
-  for Firmware Basic Boot Performance Record and install FPDT to ACPI table.\r
+  for Firmware Basic Boot Performance Record and other boot performance records, \r
+  and install FPDT to ACPI table.\r
 \r
-  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2012, 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
@@ -21,6 +22,7 @@
 \r
 #include <Protocol/ReportStatusCodeHandler.h>\r
 #include <Protocol/AcpiTable.h>\r
+#include <Protocol/SmmCommunication.h>\r
 \r
 #include <Guid/Acpi.h>\r
 #include <Guid/FirmwarePerformance.h>\r
@@ -46,6 +48,8 @@
 #define EFI_ACPI_OEM_REVISION     0x00000001\r
 #define EFI_ACPI_CREATOR_ID       0x5446534D            // TBD "MSFT"\r
 #define EFI_ACPI_CREATOR_REVISION 0x01000013            // TBD\r
+#define EXTENSION_RECORD_SIZE     0x10000\r
+#define SMM_BOOT_RECORD_COMM_SIZE OFFSET_OF (EFI_SMM_COMMUNICATE_HEADER, Data) + sizeof(SMM_BOOT_RECORD_COMMUNICATE)\r
 \r
 EFI_RSC_HANDLER_PROTOCOL    *mRscHandlerProtocol = NULL;\r
 \r
@@ -53,8 +57,10 @@ EFI_EVENT                   mReadyToBootEvent;
 EFI_EVENT                   mLegacyBootEvent;\r
 EFI_EVENT                   mExitBootServicesEvent;\r
 UINTN                       mFirmwarePerformanceTableTemplateKey  = 0;\r
+UINT32                      mBootRecordSize = 0;\r
+UINT32                      mBootRecordMaxSize = 0;\r
+UINT8                       *mBootRecordBuffer = NULL;\r
 \r
-FIRMWARE_PERFORMANCE_RUNTIME_DATA           *mPerformanceRuntimeData   = NULL;\r
 BOOT_PERFORMANCE_TABLE                      *mAcpiBootPerformanceTable = NULL;\r
 S3_PERFORMANCE_TABLE                        *mAcpiS3PerformanceTable   = NULL;\r
 \r
@@ -232,9 +238,17 @@ InstallFirmwarePerformanceDataTable (
 {\r
   EFI_STATUS                    Status;\r
   EFI_ACPI_TABLE_PROTOCOL       *AcpiTableProtocol;\r
-  FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;\r
   EFI_PHYSICAL_ADDRESS          Address;\r
   UINTN                         Size;\r
+  UINT8                         SmmBootRecordCommBuffer[SMM_BOOT_RECORD_COMM_SIZE];\r
+  EFI_SMM_COMMUNICATE_HEADER    *SmmCommBufferHeader;\r
+  SMM_BOOT_RECORD_COMMUNICATE   *SmmCommData;\r
+  UINTN                         CommSize;\r
+  UINTN                         PerformanceRuntimeDataSize;\r
+  UINT8                         *PerformanceRuntimeData; \r
+  UINT8                         *PerformanceRuntimeDataHead; \r
+  EFI_SMM_COMMUNICATION_PROTOCOL  *Communication;\r
+  FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;\r
 \r
   //\r
   // Get AcpiTable Protocol.\r
@@ -245,14 +259,61 @@ InstallFirmwarePerformanceDataTable (
   }\r
 \r
   //\r
-  // Prepare memory for runtime Performance Record.\r
+  // Collect boot records from SMM drivers.\r
   //\r
-  mPerformanceRuntimeData = NULL;\r
-  ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));\r
+  SmmCommData = NULL;\r
+  Status = gBS->LocateProtocol (&gEfiSmmCommunicationProtocolGuid, NULL, (VOID **) &Communication);\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Initialize communicate buffer \r
+    //\r
+    SmmCommBufferHeader = (EFI_SMM_COMMUNICATE_HEADER*)SmmBootRecordCommBuffer;\r
+    SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE*)SmmCommBufferHeader->Data;\r
+    ZeroMem((UINT8*)SmmCommData, sizeof(SMM_BOOT_RECORD_COMMUNICATE));\r
+\r
+    CopyGuid (&SmmCommBufferHeader->HeaderGuid, &gEfiFirmwarePerformanceGuid);\r
+    SmmCommBufferHeader->MessageLength = sizeof(SMM_BOOT_RECORD_COMMUNICATE);\r
+    CommSize = SMM_BOOT_RECORD_COMM_SIZE;\r
+  \r
+    //\r
+    // Get the size of boot records.\r
+    //\r
+    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
+      //\r
+      // Get all boot records\r
+      //\r
+      SmmCommData->Function       = SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA;\r
+      SmmCommData->BootRecordData = AllocateZeroPool(SmmCommData->BootRecordSize);\r
+      ASSERT (SmmCommData->BootRecordData != NULL);\r
+      \r
+      Status = Communication->Communicate (Communication, SmmBootRecordCommBuffer, &CommSize);\r
+      ASSERT_EFI_ERROR (Status);\r
+      ASSERT_EFI_ERROR(SmmCommData->ReturnStatus);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Prepare memory for runtime Performance Record. \r
+  // Runtime performance records includes two tables S3 performance table and Boot performance table. \r
+  // S3 Performance table includes S3Resume and S3Suspend records. \r
+  // Boot Performance table includes BasicBoot record, and one or more appended Boot Records. \r
+  //\r
+  PerformanceRuntimeData = NULL;\r
+  PerformanceRuntimeDataSize = sizeof (S3_PERFORMANCE_TABLE) + sizeof (BOOT_PERFORMANCE_TABLE) + mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
+  if (SmmCommData != NULL) {\r
+    PerformanceRuntimeDataSize += SmmCommData->BootRecordSize;\r
+  }\r
+\r
   //\r
   // Try to allocate the same runtime buffer as last time boot.\r
   //\r
-  Size = sizeof (FIRMWARE_PERFORMANCE_VARIABLE);\r
+  ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));\r
+  Size = sizeof (PerformanceVariable);\r
   Status = gRT->GetVariable (\r
                   EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
                   &gEfiFirmwarePerformanceGuid,\r
@@ -261,58 +322,47 @@ InstallFirmwarePerformanceDataTable (
                   &PerformanceVariable\r
                   );\r
   if (!EFI_ERROR (Status)) {\r
-    Address = PerformanceVariable.BootPerformanceTablePointer;\r
+    Address = PerformanceVariable.S3PerformanceTablePointer;\r
     Status = gBS->AllocatePages (\r
                     AllocateAddress,\r
                     EfiReservedMemoryType,\r
-                    EFI_SIZE_TO_PAGES (sizeof (FIRMWARE_PERFORMANCE_RUNTIME_DATA)),\r
+                    EFI_SIZE_TO_PAGES (PerformanceRuntimeDataSize),\r
                     &Address\r
                     );\r
     if (!EFI_ERROR (Status)) {\r
-      mPerformanceRuntimeData = (FIRMWARE_PERFORMANCE_RUNTIME_DATA *) (UINTN) Address;\r
+      PerformanceRuntimeData = (UINT8 *) (UINTN) Address;\r
     }\r
   }\r
 \r
-  if (mPerformanceRuntimeData == NULL) {\r
+  if (PerformanceRuntimeData == NULL) {\r
     //\r
     // Fail to allocate at specified address, continue to allocate at any address.\r
     //\r
-    mPerformanceRuntimeData = FpdtAllocateReservedMemoryBelow4G (sizeof (FIRMWARE_PERFORMANCE_RUNTIME_DATA));\r
+    PerformanceRuntimeData = FpdtAllocateReservedMemoryBelow4G (PerformanceRuntimeDataSize);\r
   }\r
-  DEBUG ((EFI_D_INFO, "FPDT: Performance Runtime Data address = 0x%x\n", mPerformanceRuntimeData));\r
+  DEBUG ((EFI_D_INFO, "FPDT: Performance Runtime Data address = 0x%x\n", PerformanceRuntimeData));\r
 \r
-  if (mPerformanceRuntimeData == NULL) {\r
+  if (PerformanceRuntimeData == NULL) {\r
+    if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) {\r
+      FreePool (SmmCommData->BootRecordData);\r
+    }\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
-\r
-  //\r
-  // Prepare Boot Performance Table.\r
-  //\r
-  mAcpiBootPerformanceTable = &mPerformanceRuntimeData->BootPerformance;\r
-  CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));\r
-  DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
-  //\r
-  // Save Boot Performance Table address to Variable for use in S4 resume.\r
-  //\r
-  PerformanceVariable.BootPerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiBootPerformanceTable;\r
-  //\r
-  // Update Boot Performance Table Pointer in template.\r
-  //\r
-  mFirmwarePerformanceTableTemplate.BootPointerRecord.BootPerformanceTablePointer = (UINT64) (UINTN) mAcpiBootPerformanceTable;\r
+  \r
+  PerformanceRuntimeDataHead = PerformanceRuntimeData;\r
 \r
   if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {\r
     //\r
     // Prepare S3 Performance Table.\r
     //\r
-    mAcpiS3PerformanceTable = &mPerformanceRuntimeData->S3Performance;\r
+    mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) PerformanceRuntimeData;\r
     CopyMem (mAcpiS3PerformanceTable, &mS3PerformanceTableTemplate, sizeof (mS3PerformanceTableTemplate));\r
+    PerformanceRuntimeData  = PerformanceRuntimeData + mAcpiS3PerformanceTable->Header.Length;\r
     DEBUG ((EFI_D_INFO, "FPDT: ACPI S3 Performance Table address = 0x%x\n", mAcpiS3PerformanceTable));\r
-\r
     //\r
     // Save S3 Performance Table address to Variable for use in Firmware Performance PEIM.\r
     //\r
     PerformanceVariable.S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiS3PerformanceTable;\r
-\r
     //\r
     // Update S3 Performance Table Pointer in template.\r
     //\r
@@ -321,9 +371,47 @@ InstallFirmwarePerformanceDataTable (
     //\r
     // Exclude S3 Performance Table Pointer from FPDT table template.\r
     //\r
-    mFirmwarePerformanceTableTemplate.Header.Length -= sizeof (EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD);\r
+    mFirmwarePerformanceTableTemplate.Header.Length -= sizeof (EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD);\r
   }\r
 \r
+  //\r
+  // Prepare Boot Performance Table.\r
+  //\r
+  mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) PerformanceRuntimeData;\r
+  //\r
+  // Fill Basic Boot record to Boot Performance Table.\r
+  //\r
+  CopyMem (PerformanceRuntimeData, &mBootPerformanceTableTemplate, sizeof (mBootPerformanceTableTemplate));\r
+  PerformanceRuntimeData = PerformanceRuntimeData + mAcpiBootPerformanceTable->Header.Length;\r
+  //\r
+  // Fill Boot records from boot drivers.\r
+  //\r
+  CopyMem (PerformanceRuntimeData, mBootRecordBuffer, mBootRecordSize);\r
+  mAcpiBootPerformanceTable->Header.Length += mBootRecordSize;\r
+  PerformanceRuntimeData = PerformanceRuntimeData + mBootRecordSize;\r
+  if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) {\r
+    //\r
+    // Fill Boot records from SMM drivers.\r
+    //\r
+    CopyMem (PerformanceRuntimeData, SmmCommData->BootRecordData, SmmCommData->BootRecordSize);\r
+    FreePool (SmmCommData->BootRecordData);\r
+    mAcpiBootPerformanceTable->Header.Length = (UINT32) (mAcpiBootPerformanceTable->Header.Length + SmmCommData->BootRecordSize);\r
+    PerformanceRuntimeData = PerformanceRuntimeData + SmmCommData->BootRecordSize;\r
+  }\r
+  //\r
+  // Reserve space for boot records after ReadyToBoot.\r
+  //\r
+  PerformanceRuntimeData = PerformanceRuntimeData + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
+  DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", mAcpiBootPerformanceTable));\r
+  //\r
+  // Save Boot Performance Table address to Variable for use in S4 resume.\r
+  //\r
+  PerformanceVariable.BootPerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiBootPerformanceTable;\r
+  //\r
+  // Update Boot Performance Table Pointer in template.\r
+  //\r
+  mFirmwarePerformanceTableTemplate.BootPointerRecord.BootPerformanceTablePointer = (UINT64) (UINTN) mAcpiBootPerformanceTable;\r
+\r
   //\r
   // Save Runtime Performance Table pointers to Variable.\r
   //\r
@@ -331,7 +419,7 @@ InstallFirmwarePerformanceDataTable (
                   EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,\r
                   &gEfiFirmwarePerformanceGuid,\r
                   EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-                  sizeof (FIRMWARE_PERFORMANCE_VARIABLE),\r
+                  sizeof (PerformanceVariable),\r
                   &PerformanceVariable\r
                   );\r
   ASSERT_EFI_ERROR (Status);\r
@@ -347,12 +435,22 @@ InstallFirmwarePerformanceDataTable (
                                 &mFirmwarePerformanceTableTemplateKey\r
                                 );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (mPerformanceRuntimeData);\r
+    FreePool (PerformanceRuntimeDataHead);\r
     mAcpiBootPerformanceTable = NULL;\r
     mAcpiS3PerformanceTable = NULL;\r
     return Status;\r
   }\r
-\r
+  \r
+  //\r
+  // Free temp Boot record, and update Boot Record to point to Basic Boot performance table.\r
+  //\r
+  if (mBootRecordBuffer != NULL) {\r
+    FreePool (mBootRecordBuffer);\r
+  }\r
+  mBootRecordBuffer  = (UINT8 *) mAcpiBootPerformanceTable;\r
+  mBootRecordSize    = mAcpiBootPerformanceTable->Header.Length;\r
+  mBootRecordMaxSize = mBootRecordSize + PcdGet32 (PcdExtFpdtBootRecordPadSize);\r
+  \r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -538,6 +636,42 @@ FpdtStatusCodeListenerDxe (
     // Unregister boot time report status code listener.\r
     //\r
     mRscHandlerProtocol->Unregister (FpdtStatusCodeListenerDxe);\r
+  } else if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {\r
+    //\r
+    // Append one or more Boot records\r
+    //\r
+    if (mAcpiBootPerformanceTable == NULL) {\r
+      //\r
+      // Append Boot records before FPDT ACPI table is installed. \r
+      //\r
+      if (mBootRecordSize + Data->Size > mBootRecordMaxSize) {\r
+        mBootRecordBuffer = ReallocatePool (mBootRecordSize, mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE, mBootRecordBuffer);\r
+        ASSERT (mBootRecordBuffer != NULL);\r
+        mBootRecordMaxSize = mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE;\r
+      }\r
+      //\r
+      // Save boot record into the temp memory space.\r
+      //\r
+      CopyMem (mBootRecordBuffer + mBootRecordSize, Data + 1, Data->Size);\r
+      mBootRecordSize += Data->Size;\r
+    } else {\r
+      //\r
+      // Append Boot records after FPDT ACPI table is installed. \r
+      //\r
+      if (mBootRecordSize + Data->Size > mBootRecordMaxSize) {\r
+        //\r
+        // No enough space to save boot record.\r
+        //\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+      } else {\r
+        //\r
+        // Save boot record into BootPerformance table\r
+        //\r
+        CopyMem (mBootRecordBuffer + mBootRecordSize, Data + 1, Data->Size);\r
+        mBootRecordSize += Data->Size;\r
+        mAcpiBootPerformanceTable->Header.Length = mBootRecordSize;\r
+      }\r
+    }\r
   } else {\r
     //\r
     // Ignore else progress code.\r
index 14b4e1b9faee0a2c987a59a02073a42626dd3bd9..9cb878189d42b924374c85dfc526a512505a54d7 100644 (file)
@@ -1,10 +1,11 @@
 ## @file\r
-#  This module install ACPI Firmware Performance Data Table (FPDT).\r
+#  This module installs ACPI Firmware Performance Data Table (FPDT).\r
 #\r
-#  This module register report status code listener to collect performance data\r
-#  for Firmware Basic Boot Performance Record and install FPDT to ACPI table.\r
+#  This module registers report status code listener to collect performance data\r
+#  for Firmware Basic Boot Performance Record and other boot performance records, \r
+#  and install FPDT to ACPI table.\r
 #\r
-#  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2011 - 2012, 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
@@ -52,6 +53,7 @@
 [Protocols]\r
   gEfiAcpiTableProtocolGuid                     ## SOMETIMES_CONSUMES\r
   gEfiRscHandlerProtocolGuid                    ## CONSUMES\r
+  gEfiSmmCommunicationProtocolGuid              ## SOMETIMES_CONSUMES\r
 \r
 [Guids]\r
   gEfiEventExitBootServicesGuid                 ## CONSUMES\r
   gEfiAcpiTableGuid                             ## SOMETIMES_CONSUMES\r
   gEfiAcpi10TableGuid                           ## SOMETIMES_CONSUMES\r
   gEfiAcpi20TableGuid                           ## SOMETIMES_CONSUMES\r
-  gEfiFirmwarePerformanceGuid                   ## CONSUMES\r
+  gEfiFirmwarePerformanceGuid                   ## PRODUCES  ## Variable:L"FirmwarePerformance"\r
+  gEfiFirmwarePerformanceGuid                   ## SOMETIMES_CONSUMES ## Hob\r
+  gEfiFirmwarePerformanceGuid                   ## SOMETIMES_CONSUMES ## SmiHandler\r
+  gEfiFirmwarePerformanceGuid                   ## SOMETIMES_CONSUMES ## StatusCode Data\r
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderStart\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdExtFpdtBootRecordPadSize\r
 \r
 [FeaturePcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwarePerformanceDataTableS3Support\r
index 19a2fe68a95c221c7996f1754aa1d7a3c8686467..6de22d4a1cd2ff3384011985b71ec05bfbb81fb3 100644 (file)
@@ -1,10 +1,10 @@
 /** @file\r
-  This module update S3 Suspend Performance Record in ACPI Firmware Performance Data Table.\r
+  This module collects performance data for SMM driver boot records and S3 Suspend Performance Record.\r
 \r
-  This module register report status code listener to collect performance data\r
-  for S3 Suspend Performance Record.\r
+  This module registers report status code listener to collect performance data\r
+  for SMM driver boot records and S3 Suspend Performance Record.\r
 \r
-  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2011 - 2012, 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
@@ -20,6 +20,7 @@
 #include <IndustryStandard/Acpi50.h>\r
 \r
 #include <Protocol/SmmReportStatusCodeHandler.h>\r
+#include <Protocol/SmmAccess2.h>\r
 \r
 #include <Guid/FirmwarePerformance.h>\r
 \r
 #include <Library/TimerLib.h>\r
 #include <Library/LockBoxLib.h>\r
 #include <Library/PcdLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/SynchronizationLib.h>\r
+\r
+#define EXTENSION_RECORD_SIZE     0x1000\r
 \r
 EFI_SMM_RSC_HANDLER_PROTOCOL  *mRscHandlerProtocol    = NULL;\r
 UINT64                        mSuspendStartTime       = 0;\r
 BOOLEAN                       mS3SuspendLockBoxSaved  = FALSE;\r
+UINT32                        mBootRecordSize = 0;\r
+UINT32                        mBootRecordMaxSize = 0;\r
+UINT8                         *mBootRecordBuffer = NULL;\r
+\r
+EFI_SMRAM_DESCRIPTOR          *mSmramRanges;\r
+UINTN                         mSmramRangeCount;\r
+SPIN_LOCK                     mSmmFpdtLock;\r
+BOOLEAN                       mSmramIsOutOfResource = FALSE;\r
 \r
 /**\r
   Report status code listener for SMM. This is used to record the performance\r
@@ -66,6 +81,7 @@ FpdtStatusCodeListenerSmm (
   EFI_STATUS                           Status;\r
   UINT64                               CurrentTime;\r
   EFI_ACPI_5_0_FPDT_S3_SUSPEND_RECORD  S3SuspendRecord;\r
+  UINT8                                *NewRecordBuffer;\r
 \r
   //\r
   // Check whether status code is what we are interested in.\r
@@ -73,6 +89,39 @@ FpdtStatusCodeListenerSmm (
   if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) != EFI_PROGRESS_CODE) {\r
     return EFI_UNSUPPORTED;\r
   }\r
+  \r
+  //\r
+  // Collect one or more Boot records in boot time\r
+  //\r
+  if (Data != NULL && CompareGuid (&Data->Type, &gEfiFirmwarePerformanceGuid)) {\r
+    AcquireSpinLock (&mSmmFpdtLock);\r
+    \r
+    if (mBootRecordSize + Data->Size > mBootRecordMaxSize) {\r
+      //\r
+      // Try to allocate big SMRAM data to store Boot record. \r
+      //\r
+      if (mSmramIsOutOfResource) {\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      NewRecordBuffer = AllocatePool (mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE); \r
+      if (NewRecordBuffer == NULL) {\r
+        mSmramIsOutOfResource = TRUE;\r
+        return EFI_OUT_OF_RESOURCES;\r
+      }\r
+      CopyMem (NewRecordBuffer, mBootRecordBuffer, mBootRecordSize);\r
+      mBootRecordBuffer  = NewRecordBuffer;\r
+      mBootRecordMaxSize = mBootRecordSize + Data->Size + EXTENSION_RECORD_SIZE;\r
+    }\r
+    //\r
+    // Save boot record into the temp memory space.\r
+    //\r
+    CopyMem (mBootRecordBuffer + mBootRecordSize, Data + 1, Data->Size);\r
+    mBootRecordSize += Data->Size;\r
+    \r
+    ReleaseSpinLock (&mSmmFpdtLock);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
   if ((Value != PcdGet32 (PcdProgressCodeS3SuspendStart)) &&\r
       (Value != PcdGet32 (PcdProgressCodeS3SuspendEnd))) {\r
     return EFI_UNSUPPORTED;\r
@@ -122,6 +171,107 @@ FpdtStatusCodeListenerSmm (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  This function check if the address is in SMRAM.\r
+\r
+  @param Buffer  the buffer address to be checked.\r
+  @param Length  the buffer length to be checked.\r
+\r
+  @retval TRUE  this address is in SMRAM.\r
+  @retval FALSE this address is NOT in SMRAM.\r
+**/\r
+BOOLEAN\r
+InternalIsAddressInSmram (\r
+  IN EFI_PHYSICAL_ADDRESS  Buffer,\r
+  IN UINT64                Length\r
+  )\r
+{\r
+  UINTN  Index;\r
+\r
+  for (Index = 0; Index < mSmramRangeCount; Index ++) {\r
+    if (((Buffer >= mSmramRanges[Index].CpuStart) && (Buffer < mSmramRanges[Index].CpuStart + mSmramRanges[Index].PhysicalSize)) ||\r
+        ((mSmramRanges[Index].CpuStart >= Buffer) && (mSmramRanges[Index].CpuStart < Buffer + Length))) {\r
+      return TRUE;\r
+    }\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+/**\r
+  Communication service SMI Handler entry.\r
+\r
+  This SMI handler provides services for report SMM boot records. \r
+\r
+  @param[in]     DispatchHandle  The unique handle assigned to this handler by SmiHandlerRegister().\r
+  @param[in]     RegisterContext Points to an optional handler context which was specified when the\r
+                                 handler was registered.\r
+  @param[in, out] CommBuffer     A pointer to a collection of data in memory that will\r
+                                 be conveyed from a non-SMM environment into an SMM environment.\r
+  @param[in, out] CommBufferSize The size of the CommBuffer.\r
+\r
+  @retval EFI_SUCCESS            The interrupt was handled and quiesced. No other handlers should still be called.\r
+  @retval EFI_INVALID_PARAMETER  The interrupt parameter is not valid. \r
+  @retval EFI_ACCESS_DENIED      The interrupt buffer can't be written. \r
+  @retval EFI_UNSUPPORTED        The interrupt is not supported. \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FpdtSmiHandler (\r
+  IN     EFI_HANDLE                   DispatchHandle,\r
+  IN     CONST VOID                   *RegisterContext,\r
+  IN OUT VOID                         *CommBuffer,\r
+  IN OUT UINTN                        *CommBufferSize\r
+  )\r
+{\r
+  EFI_STATUS                   Status;\r
+  SMM_BOOT_RECORD_COMMUNICATE  *SmmCommData;\r
+  \r
+  ASSERT (CommBuffer != NULL);\r
+  if (CommBuffer == NULL || *CommBufferSize < sizeof (SMM_BOOT_RECORD_COMMUNICATE)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+  SmmCommData = (SMM_BOOT_RECORD_COMMUNICATE*)CommBuffer;\r
+\r
+  switch (SmmCommData->Function) {\r
+    case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_SIZE :\r
+       SmmCommData->BootRecordSize = mBootRecordSize;\r
+       break;\r
+\r
+    case SMM_FPDT_FUNCTION_GET_BOOT_RECORD_DATA :\r
+       if (SmmCommData->BootRecordData == NULL || SmmCommData->BootRecordSize < mBootRecordSize) {\r
+         Status = EFI_INVALID_PARAMETER;\r
+         break;\r
+       } \r
+          \r
+       //\r
+       // Sanity check\r
+       //\r
+       SmmCommData->BootRecordSize = mBootRecordSize;\r
+       if (InternalIsAddressInSmram ((EFI_PHYSICAL_ADDRESS)(UINTN)SmmCommData->BootRecordData, mBootRecordSize)) {\r
+         DEBUG ((EFI_D_ERROR, "Smm Data buffer is in SMRAM!\n"));\r
+         Status = EFI_ACCESS_DENIED;\r
+         break;\r
+       }\r
+\r
+       CopyMem (\r
+         (UINT8*)SmmCommData->BootRecordData, \r
+         mBootRecordBuffer, \r
+         mBootRecordSize\r
+         );\r
+       break;\r
+\r
+    default:\r
+       ASSERT (FALSE);\r
+       Status = EFI_UNSUPPORTED;\r
+  }\r
+\r
+  SmmCommData->ReturnStatus = Status;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 /**\r
   The module Entry Point of the Firmware Performance Data Table SMM driver.\r
 \r
@@ -139,27 +289,60 @@ FirmwarePerformanceSmmEntryPoint (
   IN EFI_SYSTEM_TABLE    *SystemTable\r
   )\r
 {\r
-  if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {\r
-    EFI_STATUS  Status;\r
+  EFI_STATUS                Status;\r
+  EFI_HANDLE                Handle;\r
+  EFI_SMM_ACCESS2_PROTOCOL  *SmmAccess;\r
+  UINTN                     Size;\r
 \r
-    //\r
-    // Get SMM Report Status Code Handler Protocol.\r
-    //\r
-    Status = gSmst->SmmLocateProtocol (\r
-                      &gEfiSmmRscHandlerProtocolGuid,\r
-                      NULL,\r
-                      (VOID **) &mRscHandlerProtocol\r
-                      );\r
-    ASSERT_EFI_ERROR (Status);\r
+  //\r
+  // Initialize spin lock\r
+  //\r
+  InitializeSpinLock (&mSmmFpdtLock); \r
+   \r
+  //\r
+  // Get SMM Report Status Code Handler Protocol.\r
+  //\r
+  Status = gSmst->SmmLocateProtocol (\r
+                    &gEfiSmmRscHandlerProtocolGuid,\r
+                    NULL,\r
+                    (VOID **) &mRscHandlerProtocol\r
+                    );\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
-    //\r
-    // Register report status code listener for S3 Suspend Start and End.\r
-    //\r
-    Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerSmm);\r
-    ASSERT_EFI_ERROR (Status);\r
+  //\r
+  // Register report status code listener for BootRecords and S3 Suspend Start and End.\r
+  //\r
+  Status = mRscHandlerProtocol->Register (FpdtStatusCodeListenerSmm);\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
-    return Status;\r
-  } else {\r
-    return EFI_UNSUPPORTED;\r
-  }\r
+  //\r
+  // Get SMRAM information\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiSmmAccess2ProtocolGuid, NULL, (VOID **)&SmmAccess);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Size = 0;\r
+  Status = SmmAccess->GetCapabilities (SmmAccess, &Size, NULL);\r
+  ASSERT (Status == EFI_BUFFER_TOO_SMALL);\r
+\r
+  Status = gSmst->SmmAllocatePool (\r
+                    EfiRuntimeServicesData,\r
+                    Size,\r
+                    (VOID **)&mSmramRanges\r
+                    );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = SmmAccess->GetCapabilities (SmmAccess, &Size, mSmramRanges);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  mSmramRangeCount = Size / sizeof (EFI_SMRAM_DESCRIPTOR);\r
+\r
+  //\r
+  // Register SMI handler.\r
+  //\r
+  Handle = NULL;\r
+  Status = gSmst->SmiHandlerRegister (FpdtSmiHandler, &gEfiFirmwarePerformanceGuid, &Handle);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
 }\r
index 277319edc529d4ac96a8ac8bb078efd51e991484..312a78d1c060f5c3c0aeab70d84ae78464bf16fe 100644 (file)
@@ -1,10 +1,10 @@
 ## @file\r
-#  This module update S3 Suspend Performance Record in ACPI Firmware Performance Data Table.\r
+#  This module collects performance data for SMM driver boot records and S3 Suspend Performance Record.\r
 #\r
-#  This module register report status code listener to collect performance data\r
-#  for S3 Suspend Performance Record.\r
+#  This module registers report status code listener to collect performance data\r
+#  for SMM boot performance records and S3 Suspend Performance Record.\r
 #\r
-#  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2011 - 2012, 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
   TimerLib\r
   LockBoxLib\r
   PcdLib\r
+  BaseMemoryLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  SynchronizationLib\r
 \r
 [Protocols]\r
   gEfiSmmRscHandlerProtocolGuid                 ## CONSUMES\r
+  gEfiSmmAccess2ProtocolGuid                    ## CONSUMES\r
 \r
 [Guids]\r
-  gEfiFirmwarePerformanceGuid                   ## CONSUMES\r
-\r
-[FeaturePcd]\r
-  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwarePerformanceDataTableS3Support\r
+  gEfiFirmwarePerformanceGuid                   ## CONSUMES  ## LockBox\r
+  gEfiFirmwarePerformanceGuid                   ## PRODUCES  ## SmiHandler\r
+  gEfiFirmwarePerformanceGuid                   ## SOMETIMES_CONSUMES ## StatusCode Data\r
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeS3SuspendStart\r