Revision: 15347
          http://sourceforge.net/p/edk2/code/15347
Author:   vanjeff
Date:     2014-03-20 03:21:39 +0000 (Thu, 20 Mar 2014)
Log Message:
-----------
Sync patches r15333 and r15337 from main trunk.
1. Do not reset system when the MemoryTypeInformation variable cannot be 
written.
   Remove the RT attribute for the MemoryTypeInformation variable because it's 
not necessary.
2. IntelFrameworkModulePkg AcpiS3SaveDxe: Remove ASSERT, add lock and remove RT 
for AcpiGlobalVariable variable.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jeff Fan <[email protected]>

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/15333
    http://sourceforge.net/p/edk2/code/15337

Modified Paths:
--------------
    branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
    
branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiS3SaveDxe.inf
    
branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiVariableThunkPlatform.c

Modified: 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c
===================================================================
--- 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c    
    2014-03-20 03:17:04 UTC (rev 15346)
+++ 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Library/GenericBdsLib/BdsMisc.c    
    2014-03-20 03:21:39 UTC (rev 15347)
@@ -1,7 +1,7 @@
 /** @file
   Misc BDS library function
 
-Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2014, 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
@@ -1428,19 +1428,23 @@
     Status = gRT->SetVariable (
                     EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,
                     &gEfiMemoryTypeInformationGuid,
-                    EFI_VARIABLE_NON_VOLATILE  | 
EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
+                    EFI_VARIABLE_NON_VOLATILE  | 
EFI_VARIABLE_BOOTSERVICE_ACCESS,
                     VariableSize,
                     PreviousMemoryTypeInformation
                     );
 
-    //
-    // If the Memory Type Information settings have been modified, then reset 
the platform
-    // so the new Memory Type Information setting will be used to guarantee 
that an S4
-    // entry/resume cycle will not fail.
-    //
-    if (MemoryTypeInformationModified && PcdGetBool 
(PcdResetOnMemoryTypeInformationChange)) {
-      DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm 
Reset!!!\n"));
-      gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
+    if (!EFI_ERROR (Status)) {
+      //
+      // If the Memory Type Information settings have been modified, then 
reset the platform
+      // so the new Memory Type Information setting will be used to guarantee 
that an S4
+      // entry/resume cycle will not fail.
+      //
+      if (MemoryTypeInformationModified && PcdGetBool 
(PcdResetOnMemoryTypeInformationChange)) {
+        DEBUG ((EFI_D_INFO, "Memory Type Information settings change. Warm 
Reset!!!\n"));
+        gRT->ResetSystem (EfiResetWarm, EFI_SUCCESS, 0, NULL);
+      }
+    } else {
+      DEBUG ((EFI_D_ERROR, "Memory Type Information settings cannot be saved. 
OS S4 may fail!\n"));
     }
   }
 }

Modified: 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiS3SaveDxe.inf
===================================================================
--- 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiS3SaveDxe.inf
 2014-03-20 03:17:04 UTC (rev 15346)
+++ 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiS3SaveDxe.inf
 2014-03-20 03:21:39 UTC (rev 15347)
@@ -2,7 +2,7 @@
 # Component description file for AcpiS3Save module.
 #
 # This is an implementation of the ACPI S3 Save protocol.
-# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2006 - 2014, 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
@@ -64,6 +64,7 @@
   gEfiLegacyBiosProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED
   gEfiLegacyRegion2ProtocolGuid                 # PROTOCOL SOMETIMES_CONSUMED
   gFrameworkEfiMpServiceProtocolGuid            # PROTOCOL SOMETIMES_CONSUMED
+  gEdkiiVariableLockProtocolGuid                ## SOMETIMES_CONSUMES
 
 [FeaturePcd]
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPlatformCsmSupport          ## 
CONSUMES

Modified: 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiVariableThunkPlatform.c
===================================================================
--- 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiVariableThunkPlatform.c
       2014-03-20 03:17:04 UTC (rev 15346)
+++ 
branches/UDK2010.SR1/IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiVariableThunkPlatform.c
       2014-03-20 03:21:39 UTC (rev 15347)
@@ -1,7 +1,7 @@
 /** @file
   This is an implementation of the AcpiVariable platform field for ECP 
platform.
 
-Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
 
 This program and the accompanying materials
 are licensed and made available under the terms and conditions
@@ -39,7 +39,9 @@
 #include <Library/HobLib.h>
 #include <Library/PcdLib.h>
 #include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
 #include <Protocol/FrameworkMpService.h>
+#include <Protocol/VariableLock.h>
 #include <Guid/AcpiVariableCompatibility.h>
 #include <Guid/AcpiS3Context.h>
 
@@ -80,6 +82,10 @@
 
   DEBUG ((EFI_D_INFO, "S3ReadyThunkPlatform\n"));
 
+  if (mAcpiVariableSetCompatibility == NULL) {
+    return;
+  }
+
   //
   // Allocate ACPI reserved memory under 4G
   //
@@ -118,6 +124,32 @@
 }
 
 /**
+  Register callback function upon VariableLockProtocol
+  to lock ACPI_GLOBAL_VARIABLE variable to avoid malicious code to update it.
+
+  @param[in] Event    Event whose notification function is being invoked.
+  @param[in] Context  Pointer to the notification function's context.
+**/
+VOID
+EFIAPI
+VariableLockAcpiGlobalVariable (
+  IN  EFI_EVENT                             Event,
+  IN  VOID                                  *Context
+  )
+{
+  EFI_STATUS                    Status;
+  EDKII_VARIABLE_LOCK_PROTOCOL  *VariableLock;
+  //
+  // Mark ACPI_GLOBAL_VARIABLE variable to read-only if the Variable Lock 
protocol exists
+  //
+  Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID 
**) &VariableLock);
+  if (!EFI_ERROR (Status)) {
+    Status = VariableLock->RequestToLock (VariableLock, ACPI_GLOBAL_VARIABLE, 
&gEfiAcpiVariableCompatiblityGuid);
+    ASSERT_EFI_ERROR (Status);
+  }
+}
+
+/**
   Hook point for AcpiVariableThunkPlatform for InstallAcpiS3Save.
 **/
 VOID
@@ -128,6 +160,7 @@
   EFI_STATUS                           Status;
   FRAMEWORK_EFI_MP_SERVICES_PROTOCOL   *FrameworkMpService;
   UINTN                                VarSize;
+  VOID                                 *Registration;
 
   Status = gBS->LocateProtocol (
                   &gFrameworkEfiMpServiceProtocolGuid,
@@ -147,21 +180,44 @@
                     &VarSize,
                     &mAcpiVariableSetCompatibility
                     );
-    ASSERT_EFI_ERROR (Status);
+    if (EFI_ERROR (Status) || (VarSize != sizeof 
(mAcpiVariableSetCompatibility))) {
+      DEBUG ((EFI_D_ERROR, "FATAL ERROR: AcpiVariableSetCompatibility was not 
saved by CPU driver correctly. OS S3 may fail!\n"));
+      mAcpiVariableSetCompatibility = NULL;
+    }
   } else {
     //
     // Allocate/initialize the compatible version of Acpi Variable Set since 
Framework chipset/platform 
-    // driver need this variable
+    // driver need this variable. ACPI_GLOBAL_VARIABLE variable is not used in 
runtime phase,
+    // so RT attribute is not needed for it.
     //
     mAcpiVariableSetCompatibility = AllocateMemoryBelow4G (EfiACPIMemoryNVS, 
sizeof(ACPI_VARIABLE_SET_COMPATIBILITY));
     Status = gRT->SetVariable (
                     ACPI_GLOBAL_VARIABLE,
                     &gEfiAcpiVariableCompatiblityGuid,
-                    EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+                    EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_NON_VOLATILE,
                     sizeof(mAcpiVariableSetCompatibility),
                     &mAcpiVariableSetCompatibility
                     );
-    ASSERT_EFI_ERROR (Status);
+    if (!EFI_ERROR (Status)) {
+      //
+      // Register callback function upon VariableLockProtocol
+      // to lock ACPI_GLOBAL_VARIABLE variable to avoid malicious code to 
update it.
+      //
+      EfiCreateProtocolNotifyEvent (
+        &gEdkiiVariableLockProtocolGuid,
+        TPL_CALLBACK,
+        VariableLockAcpiGlobalVariable,
+        NULL,
+        &Registration
+        );
+    } else {
+      DEBUG ((EFI_D_ERROR, "FATAL ERROR: AcpiVariableSetCompatibility cannot 
be saved: %r. OS S3 may fail!\n", Status));
+      gBS->FreePages (
+             (EFI_PHYSICAL_ADDRESS) (UINTN) mAcpiVariableSetCompatibility,
+             EFI_SIZE_TO_PAGES (sizeof (ACPI_VARIABLE_SET_COMPATIBILITY))
+             );
+      mAcpiVariableSetCompatibility = NULL;
+    }
   }
 
   DEBUG((EFI_D_INFO, "AcpiVariableSetCompatibility is 0x%8x\n", 
mAcpiVariableSetCompatibility));

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


------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to