Revision: 14371
          http://edk2.svn.sourceforge.net/edk2/?rev=14371&view=rev
Author:   vanjeff
Date:     2013-05-17 01:12:34 +0000 (Fri, 17 May 2013)
Log Message:
-----------
Sync patches r14369 and r14370 from main trunk.
1. Separate memory allocation for FPDT S3 performance table and boot 
performance table, save S3 performance table pointer to LockBox in 
FirmwarePerformanceDxe. Then FirmwarePerformancePei can use the pointer in 
LockBox.
2. Update the logic about get initial value for one storage.

Revision Links:
--------------
    http://edk2.svn.sourceforge.net/edk2/?rev=14369&view=rev
    http://edk2.svn.sourceforge.net/edk2/?rev=14370&view=rev

Modified Paths:
--------------
    branches/UDK2010.SR1/MdeModulePkg/Include/Guid/FirmwarePerformance.h
    branches/UDK2010.SR1/MdeModulePkg/MdeModulePkg.dec
    
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
    
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf
    
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.c
    
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.inf
    branches/UDK2010.SR1/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
    branches/UDK2010.SR1/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h

Modified: branches/UDK2010.SR1/MdeModulePkg/Include/Guid/FirmwarePerformance.h
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Include/Guid/FirmwarePerformance.h        
2013-05-16 08:41:39 UTC (rev 14370)
+++ branches/UDK2010.SR1/MdeModulePkg/Include/Guid/FirmwarePerformance.h        
2013-05-17 01:12:34 UTC (rev 14371)
@@ -1,7 +1,7 @@
 /** @file
   ACPI Firmware Performance Data Table (FPDT) implementation specific 
definitions.
 
-  Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -50,6 +50,15 @@
 
 #define EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME  L"FirmwarePerformance"
 
+/// LockBox:
+///   GUID - gFirmwarePerformanceS3PointerGuid
+///   Data - S3 performance table pointer
+///
+#define FIRMWARE_PERFORMANCE_S3_POINTER_GUID \
+  { \
+    0xdc65adc, 0xa973, 0x4130, { 0x8d, 0xf0, 0x2a, 0xdb, 0xeb, 0x9e, 0x4a, 
0x31 } \
+  }
+
 #pragma pack(1)
 
 ///
@@ -95,7 +104,7 @@
 
 ///
 /// Variable defined for FPDT implementation.
-/// This Variable is produced by FPDT DXE module and consumed by FPDT PEIM.
+/// This Variable is produced by FPDT DXE module.
 ///
 typedef struct {
   EFI_PHYSICAL_ADDRESS  BootPerformanceTablePointer; ///< Pointer to Boot 
Performance Table.
@@ -118,5 +127,6 @@
 } SMM_BOOT_RECORD_COMMUNICATE;
 
 extern EFI_GUID gEfiFirmwarePerformanceGuid;
+extern EFI_GUID gFirmwarePerformanceS3PointerGuid;
 
 #endif

Modified: branches/UDK2010.SR1/MdeModulePkg/MdeModulePkg.dec
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/MdeModulePkg.dec  2013-05-16 08:41:39 UTC 
(rev 14370)
+++ branches/UDK2010.SR1/MdeModulePkg/MdeModulePkg.dec  2013-05-17 01:12:34 UTC 
(rev 14371)
@@ -242,6 +242,7 @@
   ## Guid for Firmware Performance Data Table (FPDT) implementation.
   #  Include/Guid/FirmwarePerformance.h
   gEfiFirmwarePerformanceGuid        = { 0xc095791a, 0x3001, 0x47b2, { 0x80, 
0xc9, 0xea, 0xc7, 0x31, 0x9f, 0x2f, 0xa4 }}
+  gFirmwarePerformanceS3PointerGuid  = { 0xdc65adc,  0xa973, 0x4130, { 0x8d, 
0xf0, 0x2a, 0xdb, 0xeb, 0x9e, 0x4a, 0x31 }}
 
   ## Include/Guid/ExitBootServiceFailed.h
   gEventExitBootServicesFailedGuid   = { 0x4f6c5507, 0x232f, 0x4787, { 0xb9, 
0x5e, 0x72, 0xf8, 0x62, 0x49, 0xc, 0xb1 } }

Modified: 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
===================================================================
--- 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
   2013-05-16 08:41:39 UTC (rev 14370)
+++ 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.c
   2013-05-17 01:12:34 UTC (rev 14371)
@@ -5,7 +5,7 @@
   for Firmware Basic Boot Performance Record and other boot performance 
records, 
   and install FPDT to ACPI table.
 
-  Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -23,6 +23,8 @@
 #include <Protocol/ReportStatusCodeHandler.h>
 #include <Protocol/AcpiTable.h>
 #include <Protocol/SmmCommunication.h>
+#include <Protocol/LockBox.h>
+#include <Protocol/Variable.h>
 
 #include <Guid/Acpi.h>
 #include <Guid/FirmwarePerformance.h>
@@ -38,7 +40,8 @@
 #include <Library/MemoryAllocationLib.h>
 #include <Library/PcdLib.h>
 #include <Library/HobLib.h>
-#include <Library/PcdLib.h>
+#include <Library/LockBoxLib.h>
+#include <Library/UefiLib.h>
 
 //
 // ACPI table information used to initialize tables.
@@ -53,6 +56,7 @@
 
 EFI_RSC_HANDLER_PROTOCOL    *mRscHandlerProtocol = NULL;
 
+BOOLEAN                     mLockBoxReady = FALSE;
 EFI_EVENT                   mReadyToBootEvent;
 EFI_EVENT                   mLegacyBootEvent;
 EFI_EVENT                   mExitBootServicesEvent;
@@ -208,6 +212,7 @@
   EFI_STATUS            Status;
   VOID                  *Buffer;
 
+  Buffer  = NULL;
   Pages   = EFI_SIZE_TO_PAGES (Size);
   Address = 0xffffffff;
 
@@ -219,13 +224,107 @@
                   );
   ASSERT_EFI_ERROR (Status);
 
-  Buffer = (VOID *) (UINTN) Address;
-  ZeroMem (Buffer, Size);
+  if (!EFI_ERROR (Status)) {
+    Buffer = (VOID *) (UINTN) Address;
+    ZeroMem (Buffer, Size);
+  }
 
   return Buffer;
 }
 
 /**
+  Callback function upon VariableArchProtocol and LockBoxProtocol
+  to allocate S3 performance table memory and save the pointer to LockBox.
+
+  @param[in] Event    Event whose notification function is being invoked.
+  @param[in] Context  Pointer to the notification function's context.
+**/
+VOID
+EFIAPI
+FpdtAllocateS3PerformanceTableMemory (
+  IN  EFI_EVENT                             Event,
+  IN  VOID                                  *Context
+  )
+{
+  EFI_STATUS                    Status;
+  VOID                          *Interface;
+  FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;
+  UINTN                         Size;
+  EFI_PHYSICAL_ADDRESS          S3PerformanceTablePointer;
+
+  if (mLockBoxReady && (mAcpiS3PerformanceTable != NULL)) {
+    //
+    // The memory for S3 performance table should have been ready,
+    // and the pointer should have been saved to LockBox, just return.
+    //
+    return;
+  }
+
+  if (!mLockBoxReady) {
+    Status = gBS->LocateProtocol (&gEfiLockBoxProtocolGuid, NULL, &Interface);
+    if (!EFI_ERROR (Status)) {
+      //
+      // LockBox services has been ready.
+      //
+      mLockBoxReady = TRUE;
+    }
+  }
+
+  if (mAcpiS3PerformanceTable == NULL) {
+    Status = gBS->LocateProtocol (&gEfiVariableArchProtocolGuid, NULL, 
&Interface);
+    if (!EFI_ERROR (Status)) {
+      //
+      // Try to allocate the same runtime buffer as last time boot.
+      //
+      ZeroMem (&PerformanceVariable, sizeof (PerformanceVariable));
+      Size = sizeof (PerformanceVariable);
+      Status = gRT->GetVariable (
+                      EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
+                      &gEfiFirmwarePerformanceGuid,
+                      NULL,
+                      &Size,
+                      &PerformanceVariable
+                      );
+      if (!EFI_ERROR (Status)) {
+        Status = gBS->AllocatePages (
+                        AllocateAddress,
+                        EfiReservedMemoryType,
+                        EFI_SIZE_TO_PAGES (sizeof (S3_PERFORMANCE_TABLE)),
+                        &PerformanceVariable.S3PerformanceTablePointer
+                        );
+        if (!EFI_ERROR (Status)) {
+          mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) (UINTN) 
PerformanceVariable.S3PerformanceTablePointer;
+        }
+      }
+      if (mAcpiS3PerformanceTable == NULL) {
+        //
+        // Fail to allocate at specified address, continue to allocate at any 
address.
+        //
+        mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) 
FpdtAllocateReservedMemoryBelow4G (sizeof (S3_PERFORMANCE_TABLE));
+      }
+      DEBUG ((EFI_D_INFO, "FPDT: ACPI S3 Performance Table address = 0x%x\n", 
mAcpiS3PerformanceTable));
+      if (mAcpiS3PerformanceTable != NULL) {
+        CopyMem (mAcpiS3PerformanceTable, &mS3PerformanceTableTemplate, sizeof 
(mS3PerformanceTableTemplate));
+      }
+    }
+  }
+
+  if (mLockBoxReady && (mAcpiS3PerformanceTable != NULL)) {
+    //
+    // If LockBox services has been ready and memory for FPDT S3 performance 
table has been allocated,
+    // save the pointer to LockBox for use in S3 resume.
+    //
+    S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) (UINTN) 
mAcpiS3PerformanceTable;
+    Status = SaveLockBox (
+               &gFirmwarePerformanceS3PointerGuid,
+               &S3PerformanceTablePointer,
+               sizeof (EFI_PHYSICAL_ADDRESS)
+               );
+    ASSERT_EFI_ERROR (Status);
+  }
+}
+
+/**
   Install ACPI Firmware Performance Data Table (FPDT).
 
   @return Status code.
@@ -238,15 +337,13 @@
 {
   EFI_STATUS                    Status;
   EFI_ACPI_TABLE_PROTOCOL       *AcpiTableProtocol;
-  EFI_PHYSICAL_ADDRESS          Address;
   UINTN                         Size;
   UINT8                         
SmmBootRecordCommBuffer[SMM_BOOT_RECORD_COMM_SIZE];
   EFI_SMM_COMMUNICATE_HEADER    *SmmCommBufferHeader;
   SMM_BOOT_RECORD_COMMUNICATE   *SmmCommData;
   UINTN                         CommSize;
-  UINTN                         PerformanceRuntimeDataSize;
-  UINT8                         *PerformanceRuntimeData; 
-  UINT8                         *PerformanceRuntimeDataHead; 
+  UINTN                         BootPerformanceDataSize;
+  UINT8                         *BootPerformanceData; 
   EFI_SMM_COMMUNICATION_PROTOCOL  *Communication;
   FIRMWARE_PERFORMANCE_VARIABLE PerformanceVariable;
 
@@ -298,15 +395,12 @@
   }
 
   //
-  // Prepare memory for runtime Performance Record. 
-  // Runtime performance records includes two tables S3 performance table and 
Boot performance table. 
-  // S3 Performance table includes S3Resume and S3Suspend records. 
+  // Prepare memory for Boot Performance table.
   // Boot Performance table includes BasicBoot record, and one or more 
appended Boot Records. 
   //
-  PerformanceRuntimeData = NULL;
-  PerformanceRuntimeDataSize = sizeof (S3_PERFORMANCE_TABLE) + sizeof 
(BOOT_PERFORMANCE_TABLE) + mBootRecordSize + PcdGet32 
(PcdExtFpdtBootRecordPadSize);
+  BootPerformanceDataSize = sizeof (BOOT_PERFORMANCE_TABLE) + mBootRecordSize 
+ PcdGet32 (PcdExtFpdtBootRecordPadSize);
   if (SmmCommData != NULL) {
-    PerformanceRuntimeDataSize += SmmCommData->BootRecordSize;
+    BootPerformanceDataSize += SmmCommData->BootRecordSize;
   }
 
   //
@@ -322,88 +416,60 @@
                   &PerformanceVariable
                   );
   if (!EFI_ERROR (Status)) {
-    Address = PerformanceVariable.S3PerformanceTablePointer;
     Status = gBS->AllocatePages (
                     AllocateAddress,
                     EfiReservedMemoryType,
-                    EFI_SIZE_TO_PAGES (PerformanceRuntimeDataSize),
-                    &Address
+                    EFI_SIZE_TO_PAGES (BootPerformanceDataSize),
+                    &PerformanceVariable.BootPerformanceTablePointer
                     );
     if (!EFI_ERROR (Status)) {
-      PerformanceRuntimeData = (UINT8 *) (UINTN) Address;
+      mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) (UINTN) 
PerformanceVariable.BootPerformanceTablePointer;
     }
   }
 
-  if (PerformanceRuntimeData == NULL) {
+  if (mAcpiBootPerformanceTable == NULL) {
     //
     // Fail to allocate at specified address, continue to allocate at any 
address.
     //
-    PerformanceRuntimeData = FpdtAllocateReservedMemoryBelow4G 
(PerformanceRuntimeDataSize);
+    mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) 
FpdtAllocateReservedMemoryBelow4G (BootPerformanceDataSize);
   }
-  DEBUG ((EFI_D_INFO, "FPDT: Performance Runtime Data address = 0x%x\n", 
PerformanceRuntimeData));
+  DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", 
mAcpiBootPerformanceTable));
 
-  if (PerformanceRuntimeData == NULL) {
+  if (mAcpiBootPerformanceTable == NULL) {
     if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) {
       FreePool (SmmCommData->BootRecordData);
     }
+    if (mAcpiS3PerformanceTable != NULL) {
+      FreePages (mAcpiS3PerformanceTable, EFI_SIZE_TO_PAGES (sizeof 
(S3_PERFORMANCE_TABLE)));
+    }
     return EFI_OUT_OF_RESOURCES;
   }
-  
-  PerformanceRuntimeDataHead = PerformanceRuntimeData;
 
-  if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {
-    //
-    // Prepare S3 Performance Table.
-    //
-    mAcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) PerformanceRuntimeData;
-    CopyMem (mAcpiS3PerformanceTable, &mS3PerformanceTableTemplate, sizeof 
(mS3PerformanceTableTemplate));
-    PerformanceRuntimeData  = PerformanceRuntimeData + 
mAcpiS3PerformanceTable->Header.Length;
-    DEBUG ((EFI_D_INFO, "FPDT: ACPI S3 Performance Table address = 0x%x\n", 
mAcpiS3PerformanceTable));
-    //
-    // Save S3 Performance Table address to Variable for use in Firmware 
Performance PEIM.
-    //
-    PerformanceVariable.S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) 
(UINTN) mAcpiS3PerformanceTable;
-    //
-    // Update S3 Performance Table Pointer in template.
-    //
-    
mFirmwarePerformanceTableTemplate.S3PointerRecord.S3PerformanceTablePointer = 
(UINT64) PerformanceVariable.S3PerformanceTablePointer;
-  } else {
-    //
-    // Exclude S3 Performance Table Pointer from FPDT table template.
-    //
-    mFirmwarePerformanceTableTemplate.Header.Length -= sizeof 
(EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD);
-  }
-
   //
   // Prepare Boot Performance Table.
   //
-  mAcpiBootPerformanceTable = (BOOT_PERFORMANCE_TABLE *) 
PerformanceRuntimeData;
+  BootPerformanceData = (UINT8 *) mAcpiBootPerformanceTable;
   //
   // Fill Basic Boot record to Boot Performance Table.
   //
-  CopyMem (PerformanceRuntimeData, &mBootPerformanceTableTemplate, sizeof 
(mBootPerformanceTableTemplate));
-  PerformanceRuntimeData = PerformanceRuntimeData + 
mAcpiBootPerformanceTable->Header.Length;
+  CopyMem (mAcpiBootPerformanceTable, &mBootPerformanceTableTemplate, sizeof 
(mBootPerformanceTableTemplate));
+  BootPerformanceData = BootPerformanceData + 
mAcpiBootPerformanceTable->Header.Length;
   //
   // Fill Boot records from boot drivers.
   //
-  CopyMem (PerformanceRuntimeData, mBootRecordBuffer, mBootRecordSize);
+  CopyMem (BootPerformanceData, mBootRecordBuffer, mBootRecordSize);
   mAcpiBootPerformanceTable->Header.Length += mBootRecordSize;
-  PerformanceRuntimeData = PerformanceRuntimeData + mBootRecordSize;
+  BootPerformanceData = BootPerformanceData + mBootRecordSize;
   if (SmmCommData != NULL && SmmCommData->BootRecordData != NULL) {
     //
     // Fill Boot records from SMM drivers.
     //
-    CopyMem (PerformanceRuntimeData, SmmCommData->BootRecordData, 
SmmCommData->BootRecordSize);
+    CopyMem (BootPerformanceData, SmmCommData->BootRecordData, 
SmmCommData->BootRecordSize);
     FreePool (SmmCommData->BootRecordData);
     mAcpiBootPerformanceTable->Header.Length = (UINT32) 
(mAcpiBootPerformanceTable->Header.Length + SmmCommData->BootRecordSize);
-    PerformanceRuntimeData = PerformanceRuntimeData + 
SmmCommData->BootRecordSize;
+    BootPerformanceData = BootPerformanceData + SmmCommData->BootRecordSize;
   }
   //
-  // Reserve space for boot records after ReadyToBoot.
-  //
-  PerformanceRuntimeData = PerformanceRuntimeData + PcdGet32 
(PcdExtFpdtBootRecordPadSize);
-  DEBUG ((EFI_D_INFO, "FPDT: ACPI Boot Performance Table address = 0x%x\n", 
mAcpiBootPerformanceTable));
-  //
   // Save Boot Performance Table address to Variable for use in S4 resume.
   //
   PerformanceVariable.BootPerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) 
(UINTN) mAcpiBootPerformanceTable;
@@ -413,12 +479,20 @@
   
mFirmwarePerformanceTableTemplate.BootPointerRecord.BootPerformanceTablePointer 
= (UINT64) (UINTN) mAcpiBootPerformanceTable;
 
   //
+  // Save S3 Performance Table address to Variable for use in S4 resume.
+  //
+  PerformanceVariable.S3PerformanceTablePointer = (EFI_PHYSICAL_ADDRESS) 
(UINTN) mAcpiS3PerformanceTable;
+  //
+  // Update S3 Performance Table Pointer in template.
+  //
+  mFirmwarePerformanceTableTemplate.S3PointerRecord.S3PerformanceTablePointer 
= (UINT64) (UINTN) mAcpiS3PerformanceTable;
+  //
   // Save Runtime Performance Table pointers to Variable.
   //
   Status = gRT->SetVariable (
                   EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
                   &gEfiFirmwarePerformanceGuid,
-                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS 
| EFI_VARIABLE_RUNTIME_ACCESS,
+                  EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
                   sizeof (PerformanceVariable),
                   &PerformanceVariable
                   );
@@ -435,7 +509,10 @@
                                 &mFirmwarePerformanceTableTemplateKey
                                 );
   if (EFI_ERROR (Status)) {
-    FreePool (PerformanceRuntimeDataHead);
+    FreePages (mAcpiBootPerformanceTable, EFI_SIZE_TO_PAGES 
(BootPerformanceDataSize));
+    if (mAcpiS3PerformanceTable != NULL) {
+      FreePages (mAcpiS3PerformanceTable, EFI_SIZE_TO_PAGES (sizeof 
(S3_PERFORMANCE_TABLE)));
+    }
     mAcpiBootPerformanceTable = NULL;
     mAcpiS3PerformanceTable = NULL;
     return Status;
@@ -702,6 +779,7 @@
   EFI_STATUS               Status;
   EFI_HOB_GUID_TYPE        *GuidHob;
   FIRMWARE_SEC_PERFORMANCE *Performance;
+  VOID                     *Registration;
 
   //
   // Get Report Status Code Handler Protocol.
@@ -768,5 +846,31 @@
     DEBUG ((EFI_D_ERROR, "FPDT: WARNING: SEC Performance Data Hob not found, 
ResetEnd will be set to 0!\n"));
   }
 
+  if (FeaturePcdGet (PcdFirmwarePerformanceDataTableS3Support)) {
+    //
+    // Register callback function upon VariableArchProtocol and LockBoxProtocol
+    // to allocate S3 performance table memory and save the pointer to LockBox.
+    //
+    EfiCreateProtocolNotifyEvent (
+      &gEfiVariableArchProtocolGuid,
+      TPL_CALLBACK,
+      FpdtAllocateS3PerformanceTableMemory,
+      NULL,
+      &Registration
+      );
+    EfiCreateProtocolNotifyEvent (
+      &gEfiLockBoxProtocolGuid,
+      TPL_CALLBACK,
+      FpdtAllocateS3PerformanceTableMemory,
+      NULL,
+      &Registration
+      );
+  } else {
+    //
+    // Exclude S3 Performance Table Pointer from FPDT table template.
+    //
+    mFirmwarePerformanceTableTemplate.Header.Length -= sizeof 
(EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_POINTER_RECORD);
+  }
+
   return EFI_SUCCESS;
 }

Modified: 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf
===================================================================
--- 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf
 2013-05-16 08:41:39 UTC (rev 14370)
+++ 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTableDxe/FirmwarePerformanceDxe.inf
 2013-05-17 01:12:34 UTC (rev 14371)
@@ -5,7 +5,7 @@
 #  for Firmware Basic Boot Performance Record and other boot performance 
records, 
 #  and install FPDT to ACPI table.
 #
-#  Copyright (c) 2011 - 2012, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
 #  which accompanies this distribution.  The full text of the license may be 
found at
@@ -48,11 +48,15 @@
   MemoryAllocationLib
   PcdLib
   HobLib
+  LockBoxLib
+  UefiLib
 
 [Protocols]
   gEfiAcpiTableProtocolGuid                     ## SOMETIMES_CONSUMES
   gEfiRscHandlerProtocolGuid                    ## CONSUMES
   gEfiSmmCommunicationProtocolGuid              ## SOMETIMES_CONSUMES
+  gEfiVariableArchProtocolGuid                  ## SOMETIMES_CONSUMES
+  gEfiLockBoxProtocolGuid                       ## SOMETIMES_CONSUMES
 
 [Guids]
   gEfiEventExitBootServicesGuid                 ## CONSUMES
@@ -65,6 +69,7 @@
   gEfiFirmwarePerformanceGuid                   ## SOMETIMES_CONSUMES ## Hob
   gEfiFirmwarePerformanceGuid                   ## SOMETIMES_CONSUMES ## 
SmiHandler
   gEfiFirmwarePerformanceGuid                   ## SOMETIMES_CONSUMES ## 
StatusCode Data
+  gFirmwarePerformanceS3PointerGuid             ## SOMETIMES_PRODUCES # 
SaveLockBox
 
 [Pcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdProgressCodeOsLoaderLoad

Modified: 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.c
===================================================================
--- 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.c
   2013-05-16 08:41:39 UTC (rev 14370)
+++ 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.c
   2013-05-17 01:12:34 UTC (rev 14371)
@@ -7,7 +7,7 @@
   This module register report status code listener to collect performance data
   for S3 Resume Performance Record on S3 resume boot path.
 
-  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD 
License
   which accompanies this distribution.  The full text of the license may be 
found at
@@ -22,7 +22,6 @@
 
 #include <IndustryStandard/Acpi50.h>
 
-#include <Ppi/ReadOnlyVariable2.h>
 #include <Ppi/ReportStatusCodeHandler.h>
 #include <Ppi/SecPerformance.h>
 
@@ -70,9 +69,8 @@
 {
   EFI_STATUS                           Status;
   UINT64                               CurrentTime;
-  EFI_PEI_READ_ONLY_VARIABLE2_PPI      *VariableServices;
   UINTN                                VarSize;
-  FIRMWARE_PERFORMANCE_VARIABLE        PerformanceVariable;
+  EFI_PHYSICAL_ADDRESS                 S3PerformanceTablePointer;
   S3_PERFORMANCE_TABLE                 *AcpiS3PerformanceTable;
   EFI_ACPI_5_0_FPDT_S3_RESUME_RECORD   *AcpiS3ResumeRecord;
   UINT64                               S3ResumeTotal;
@@ -92,33 +90,20 @@
   //
   CurrentTime = GetTimeInNanoSecond (GetPerformanceCounter ());
 
-  Status = PeiServicesLocatePpi (
-             &gEfiPeiReadOnlyVariable2PpiGuid,
-             0,
-             NULL,
-             (VOID **) &VariableServices
-             );
-  ASSERT_EFI_ERROR (Status);
-
   //
   // Update S3 Resume Performance Record.
   //
-  VarSize = sizeof (FIRMWARE_PERFORMANCE_VARIABLE);
-  Status = VariableServices->GetVariable (
-                               VariableServices,
-                               EFI_FIRMWARE_PERFORMANCE_VARIABLE_NAME,
-                               &gEfiFirmwarePerformanceGuid,
-                               NULL,
-                               &VarSize,
-                               &PerformanceVariable
-                               );
-  if (EFI_ERROR (Status)) {
-    return Status;
-  }
+  S3PerformanceTablePointer = 0;
+  VarSize = sizeof (EFI_PHYSICAL_ADDRESS);
+  Status = RestoreLockBox (&gFirmwarePerformanceS3PointerGuid, 
&S3PerformanceTablePointer, &VarSize);
+  ASSERT_EFI_ERROR (Status);
 
-  AcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) (UINTN) 
PerformanceVariable.S3PerformanceTablePointer;
+  AcpiS3PerformanceTable = (S3_PERFORMANCE_TABLE *) (UINTN) 
S3PerformanceTablePointer;
   ASSERT (AcpiS3PerformanceTable != NULL);
-  ASSERT (AcpiS3PerformanceTable->Header.Signature == 
EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE);
+  if (AcpiS3PerformanceTable->Header.Signature != 
EFI_ACPI_5_0_FPDT_S3_PERFORMANCE_TABLE_SIGNATURE) {
+    DEBUG ((EFI_D_ERROR, "FPDT S3 performance data in ACPI memory get 
corrupted\n"));
+    return EFI_ABORTED;
+  }
   AcpiS3ResumeRecord = &AcpiS3PerformanceTable->S3Resume;
   AcpiS3ResumeRecord->FullResume = CurrentTime;
   //

Modified: 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.inf
===================================================================
--- 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.inf
 2013-05-16 08:41:39 UTC (rev 14370)
+++ 
branches/UDK2010.SR1/MdeModulePkg/Universal/Acpi/FirmwarePerformanceDataTablePei/FirmwarePerformancePei.inf
 2013-05-17 01:12:34 UTC (rev 14371)
@@ -7,7 +7,7 @@
 #  This module register report status code listener to collect performance data
 #  for S3 Resume Performance Record on S3 resume boot path.
 #
-#  Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+#  Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD 
License
 #  which accompanies this distribution.  The full text of the license may be 
found at
@@ -52,11 +52,11 @@
 
 [Ppis]
   gEfiPeiRscHandlerPpiGuid                      ## CONSUMES
-  gEfiPeiReadOnlyVariable2PpiGuid               ## SOMETIMES_CONSUMES
   gPeiSecPerformancePpiGuid                     ## CONSUMES
 
 [Guids]
   gEfiFirmwarePerformanceGuid                   ## CONSUMES
+  gFirmwarePerformanceS3PointerGuid             ## CONSUMES
 
 [FeaturePcd]
   gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwarePerformanceDataTableS3Support

Modified: branches/UDK2010.SR1/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c 
2013-05-16 08:41:39 UTC (rev 14370)
+++ branches/UDK2010.SR1/MdeModulePkg/Universal/SetupBrowserDxe/Setup.c 
2013-05-17 01:12:34 UTC (rev 14371)
@@ -3417,6 +3417,175 @@
 }
 
 /**
+  Check whether current element in the ConfigReqeust string.
+
+  @param  BrowserStorage                Storage which includes ConfigReqeust.
+  @param  RequestElement                New element need to check.
+
+  @retval TRUE        The Element is in the ConfigReqeust string.
+  @retval FALSE       The Element not in the configReqeust String.
+
+**/
+BOOLEAN 
+ElementValidation (
+  BROWSER_STORAGE   *BrowserStorage,
+  CHAR16            *RequestElement
+  )
+{
+  return StrStr (BrowserStorage->ConfigRequest, RequestElement) != NULL ? TRUE 
: FALSE;
+}
+
+/**
+  Append the Request element to the Config Request.
+
+  @param  ConfigRequest          Current ConfigRequest info.
+  @param  SpareStrLen            Current remain free buffer for config reqeust.
+  @param  RequestElement         New Request element.
+
+**/
+VOID
+AppendConfigRequest (
+  IN OUT CHAR16               **ConfigRequest,
+  IN OUT UINTN                *SpareStrLen,
+  IN     CHAR16               *RequestElement
+  )
+{
+  CHAR16   *NewStr;
+  UINTN    StringSize;
+  UINTN    StrLength;
+
+  StrLength = StrLen (RequestElement) * sizeof (CHAR16);
+
+  //
+  // Append <RequestElement> to <ConfigRequest>
+  //
+  if (StrLength > *SpareStrLen) {
+    //
+    // Old String buffer is not sufficient for RequestElement, allocate a new 
one
+    //
+    StringSize = (*ConfigRequest != NULL) ? StrSize (*ConfigRequest) : sizeof 
(CHAR16);
+    NewStr = AllocateZeroPool (StringSize + CONFIG_REQUEST_STRING_INCREMENTAL 
* sizeof (CHAR16));
+    ASSERT (NewStr != NULL);
+
+    if (*ConfigRequest != NULL) {
+      CopyMem (NewStr, *ConfigRequest, StringSize);
+      FreePool (*ConfigRequest);
+    }
+    *ConfigRequest = NewStr;
+    *SpareStrLen   = CONFIG_REQUEST_STRING_INCREMENTAL;
+  }
+
+  StrCat (*ConfigRequest, RequestElement);
+  *SpareStrLen -= StrLength;
+}
+
+/**
+  Adjust the config request info, remove the request elements which already in 
AllConfigRequest string.
+
+  @param  Storage                Form set Storage.
+  @param  ConfigRequest          Return the ConfigRequest info.
+
+  @retval TRUE                   Has element not covered by current used 
elements, need to continue to call ExtractConfig
+  @retval FALSE                  All elements covered by current used elements.
+
+**/
+BOOLEAN 
+ConfigRequestAdjust (
+  IN  FORMSET_STORAGE         *Storage,
+  OUT CHAR16                  **ConfigRequest
+  )
+{
+  CHAR16       *RequestElement;
+  CHAR16       *NextRequestElement;
+  CHAR16       *RetBuf;
+  UINTN        SpareBufLen;
+  CHAR16       *SearchKey;
+  BOOLEAN      RetVal;
+
+  SpareBufLen    = 0;
+  RetBuf         = NULL;
+  RetVal         = FALSE;
+
+  if (Storage->BrowserStorage->ConfigRequest == NULL) {
+    Storage->BrowserStorage->ConfigRequest = AllocateCopyPool (StrSize 
(Storage->ConfigRequest), Storage->ConfigRequest);
+    *ConfigRequest = AllocateCopyPool (StrSize (Storage->ConfigRequest), 
Storage->ConfigRequest);
+    return TRUE;
+  }
+
+  if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) {
+    //
+    // "&Name1&Name2" section for EFI_HII_VARSTORE_NAME_VALUE storage
+    //
+    SearchKey = L"&";
+  } else {
+    //
+    // "&OFFSET=####&WIDTH=####" section for EFI_HII_VARSTORE_BUFFER storage
+    //
+    SearchKey = L"&OFFSET";
+  }
+
+  //
+  // Prepare the config header.
+  // 
+  RetBuf = AllocateCopyPool(StrSize (Storage->BrowserStorage->ConfigHdr), 
Storage->BrowserStorage->ConfigHdr);
+  ASSERT (RetBuf != NULL);
+
+  //
+  // Find SearchKey storage
+  //
+  if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_NAME_VALUE) {
+    RequestElement = StrStr (Storage->ConfigRequest, L"PATH");
+    ASSERT (RequestElement != NULL);
+    RequestElement = StrStr (RequestElement, SearchKey);    
+  } else {
+    RequestElement = StrStr (Storage->ConfigRequest, SearchKey);
+  }
+
+  while (RequestElement != NULL) {
+    //
+    // +1 to avoid find header itself.
+    //
+    NextRequestElement = StrStr (RequestElement + 1, SearchKey);
+
+    //
+    // The last Request element in configRequest string.
+    //
+    if (NextRequestElement != NULL) {
+      //
+      // Replace "&" with '\0'.
+      //
+      *NextRequestElement = L'\0';
+    }
+ 
+    if (!ElementValidation (Storage->BrowserStorage, RequestElement)) {
+      //
+      // Add this element to the Storage->BrowserStorage->AllRequestElement.
+      //
+      AppendConfigRequest(&Storage->BrowserStorage->ConfigRequest, 
&Storage->BrowserStorage->SpareStrLen, RequestElement);
+      AppendConfigRequest (&RetBuf, &SpareBufLen, RequestElement);
+      RetVal = TRUE;
+    }
+
+    if (NextRequestElement != NULL) {
+      //
+      // Restore '&' with '\0' for later used.
+      //
+      *NextRequestElement = L'&';
+    }
+
+    RequestElement = NextRequestElement;
+  }
+
+  if (RetVal) {
+    *ConfigRequest = RetBuf;
+  } else {
+    FreePool (RetBuf);
+  }
+
+  return RetVal;
+}
+
+/**
   Fill storage's edit copy with settings requested from Configuration Driver.
 
   @param  FormSet                FormSet data structure.
@@ -3435,19 +3604,26 @@
   EFI_STRING  Progress;
   EFI_STRING  Result;
   CHAR16      *StrPtr;
+  CHAR16      *ConfigRequest;
 
   if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE) {
     return EFI_SUCCESS;
   }
 
   if (Storage->BrowserStorage->Type == EFI_HII_VARSTORE_EFI_VARIABLE_BUFFER) {
-    Status = gRT->GetVariable (
-                     Storage->BrowserStorage->Name,
-                     &Storage->BrowserStorage->Guid,
-                     NULL,
-                     (UINTN*)&Storage->BrowserStorage->Size,
-                     Storage->BrowserStorage->EditBuffer
-                     );
+    Status = EFI_SUCCESS;
+    //
+    // EFI varstore data all get from variable, so no need to get again.
+    //
+    if (Storage->BrowserStorage->ReferenceCount == 1) {
+      Status = gRT->GetVariable (
+                       Storage->BrowserStorage->Name,
+                       &Storage->BrowserStorage->Guid,
+                       NULL,
+                       (UINTN*)&Storage->BrowserStorage->Size,
+                       Storage->BrowserStorage->EditBuffer
+                       );
+    }
     return Status;
   }
 
@@ -3463,14 +3639,24 @@
   }
 
   //
+  // Adjust the ConfigRequest string, only the field not saved in 
BrowserStorage->AllConfig
+  // will used to call ExtractConfig.
+  //
+  if (!ConfigRequestAdjust(Storage, &ConfigRequest)) {
+    return EFI_SUCCESS;
+  }
+
+  //
   // Request current settings from Configuration Driver
   //
   Status = FormSet->ConfigAccess->ExtractConfig (
                                     FormSet->ConfigAccess,
-                                    Storage->ConfigRequest,
+                                    ConfigRequest,
                                     &Progress,
                                     &Result
                                     );
+  FreePool (ConfigRequest);
+
   if (EFI_ERROR (Status)) {
     return Status;
   }
@@ -3544,7 +3730,7 @@
     // Storage is not found in backup formset and current global storage not 
has other driver used,
     // request it from ConfigDriver
     //
-    if (OldStorage == NULL && Storage->BrowserStorage->ReferenceCount == 1) {
+    if (OldStorage == NULL) {
       Status = LoadStorage (FormSet, Storage);
 
       if (EFI_ERROR (Status)) {

Modified: branches/UDK2010.SR1/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h
===================================================================
--- branches/UDK2010.SR1/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h 
2013-05-16 08:41:39 UTC (rev 14370)
+++ branches/UDK2010.SR1/MdeModulePkg/Universal/SetupBrowserDxe/Setup.h 
2013-05-17 01:12:34 UTC (rev 14371)
@@ -236,6 +236,9 @@
   UINT32           Attributes;     // For EFI_IFR_VARSTORE_EFI: EFI Variable 
attribute
 
   CHAR16           *ConfigHdr;     // <ConfigHdr>
+  CHAR16           *ConfigRequest; // <ConfigRequest> = <ConfigHdr> + 
<RequestElement>
+                                   // <RequestElement> includes all fields 
which is used by current form sets.
+  UINTN            SpareStrLen;    // Spare length of ConfigRequest string 
buffer
   UINT8            ReferenceCount; // How many form set storage refrence this 
storage.
 } BROWSER_STORAGE;
 

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
AlienVault Unified Security Management (USM) platform delivers complete
security visibility with the essential security capabilities. Easily and
efficiently configure, manage, and operate all of your security controls
from a single console and one unified framework. Download a free trial.
http://p.sf.net/sfu/alienvault_d2d
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to