Blame SOURCES/edk2-MdeModulePkg-Enable-Disable-S3BootScript-dynamically.patch

6009e6
From 4ef57a1e6b9411e785e00e8874bd5c67235e9134 Mon Sep 17 00:00:00 2001
6009e6
From: Laszlo Ersek <lersek@redhat.com>
6009e6
Date: Tue, 11 Feb 2020 17:01:59 +0100
6009e6
Subject: [PATCH 1/2] MdeModulePkg: Enable/Disable S3BootScript dynamically.
6009e6
MIME-Version: 1.0
6009e6
Content-Type: text/plain; charset=UTF-8
6009e6
Content-Transfer-Encoding: 8bit
6009e6
6009e6
RH-Author: Laszlo Ersek <lersek@redhat.com>
6009e6
Message-id: <20200211170200.12389-2-lersek@redhat.com>
6009e6
Patchwork-id: 93776
6009e6
O-Subject: [RHEL-8.2.0 edk2 PATCH 1/2] MdeModulePkg: Enable/Disable S3BootScript dynamically.
6009e6
Bugzilla: 1801274
6009e6
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
6009e6
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
6009e6
6009e6
From: Chasel Chiu <chasel.chiu@intel.com>
6009e6
6009e6
--v-- RHEL8 note start --v--
6009e6
6009e6
This patch is cherry-picked from upstream as a contextual (not semantic /
6009e6
functional) pre-requisite for the next patch.
6009e6
6009e6
Functionally, this patch makes no difference in OVMF, for two reasons:
6009e6
6009e6
- Downstream, we don't enable S3 anyway (per QEMU default).
6009e6
6009e6
- The S3-related modules that are built into OVMF (S3SaveStateDxe,
6009e6
  BootScriptExecutorDxe) already consider PcdAcpiS3Enable, and exit their
6009e6
  entry point functions with EFI_UNSUPPORTED when the PCD is FALSE. As a
6009e6
  consequence, the DESTRUCTOR function of the PiDxeS3BootScriptLib library
6009e6
  instance (which is linked into those binaries) will undo whatever the
6009e6
  CONSTRUCTOR function did; no resources will be leaked.
6009e6
6009e6
  https://edk2.groups.io/g/devel/message/47996
6009e6
  http://mid.mail-archive.com/e43e3f56-d2db-7989-b6f1-03e1c810d908@redhat.com
6009e6
6009e6
--^-- RHEL8 note end --^--
6009e6
6009e6
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2212
6009e6
6009e6
In binary model the same binary may have to support both
6009e6
S3 enabled and disabled scenarios, however not all DXE
6009e6
drivers linking PiDxeS3BootScriptLib can return error to
6009e6
invoke library DESTRUCTOR for releasing resource.
6009e6
6009e6
To support this usage model below PCD is used to skip
6009e6
S3BootScript functions when PCD set to FALSE:
6009e6
  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable
6009e6
6009e6
Test: Verified on internal platform and S3BootScript
6009e6
      functions can be skipped by PCD during boot time.
6009e6
6009e6
Cc: Hao A Wu <hao.a.wu@intel.com>
6009e6
Cc: Eric Dong <eric.dong@intel.com>
6009e6
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
6009e6
Cc: Liming Gao <liming.gao@intel.com>
6009e6
Cc: Laszlo Ersek <lersek@redhat.com>
6009e6
Signed-off-by: Chasel Chiu <chasel.chiu@intel.com>
6009e6
Reviewed-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
6009e6
Reviewed-by: Eric Dong <eric.dong@intel.com>
6009e6
Acked-by: Laszlo Ersek <lersek@redhat.com>
6009e6
(cherry picked from commit ed9db1b91ceba7d3a24743d4d9314c6fbe11c4b3)
6009e6
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
6009e6
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
6009e6
---
6009e6
 .../Library/PiDxeS3BootScriptLib/BootScriptSave.c       | 17 ++++++++++++++++-
6009e6
 .../Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf |  4 ++--
6009e6
 2 files changed, 18 insertions(+), 3 deletions(-)
6009e6
6009e6
diff --git a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
6009e6
index c116727..9106e7d 100644
6009e6
--- a/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
6009e6
+++ b/MdeModulePkg/Library/PiDxeS3BootScriptLib/BootScriptSave.c
6009e6
@@ -1,7 +1,7 @@
6009e6
 /** @file
6009e6
   Save the S3 data to S3 boot script.
6009e6
 
6009e6
-  Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
6009e6
+  Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
6009e6
 
6009e6
   SPDX-License-Identifier: BSD-2-Clause-Patent
6009e6
 
6009e6
@@ -124,6 +124,7 @@ VOID                             *mRegistrationSmmReadyToLock = NULL;
6009e6
 BOOLEAN                          mS3BootScriptTableAllocated = FALSE;
6009e6
 BOOLEAN                          mS3BootScriptTableSmmAllocated = FALSE;
6009e6
 EFI_SMM_SYSTEM_TABLE2            *mBootScriptSmst = NULL;
6009e6
+BOOLEAN                          mAcpiS3Enable = TRUE;
6009e6
 
6009e6
 /**
6009e6
   This is an internal function to add a terminate node the entry, recalculate the table
6009e6
@@ -436,6 +437,12 @@ S3BootScriptLibInitialize (
6009e6
   BOOLEAN                        InSmm;
6009e6
   EFI_PHYSICAL_ADDRESS           Buffer;
6009e6
 
6009e6
+  if (!PcdGetBool (PcdAcpiS3Enable)) {
6009e6
+    mAcpiS3Enable = FALSE;
6009e6
+    DEBUG ((DEBUG_INFO, "%a: Skip S3BootScript because ACPI S3 disabled.\n", gEfiCallerBaseName));
6009e6
+    return RETURN_SUCCESS;
6009e6
+  }
6009e6
+
6009e6
   S3TablePtr = (SCRIPT_TABLE_PRIVATE_DATA*)(UINTN)PcdGet64(PcdS3BootScriptTablePrivateDataPtr);
6009e6
   //
6009e6
   // The Boot script private data is not be initialized. create it
6009e6
@@ -562,6 +569,10 @@ S3BootScriptLibDeinitialize (
6009e6
 {
6009e6
   EFI_STATUS                Status;
6009e6
 
6009e6
+  if (!mAcpiS3Enable) {
6009e6
+    return RETURN_SUCCESS;
6009e6
+  }
6009e6
+
6009e6
   DEBUG ((EFI_D_INFO, "%a() in %a module\n", __FUNCTION__, gEfiCallerBaseName));
6009e6
 
6009e6
   if (mEventDxeSmmReadyToLock != NULL) {
6009e6
@@ -810,6 +821,10 @@ S3BootScriptGetEntryAddAddress (
6009e6
 {
6009e6
   UINT8*                         NewEntryPtr;
6009e6
 
6009e6
+  if (!mAcpiS3Enable) {
6009e6
+    return NULL;
6009e6
+  }
6009e6
+
6009e6
   if (mS3BootScriptTablePtr->SmmLocked) {
6009e6
     //
6009e6
     // We need check InSmm, because after SmmReadyToLock, only SMM driver is allowed to write boot script.
6009e6
diff --git a/MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf b/MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
6009e6
index 517ea69..2b894c9 100644
6009e6
--- a/MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
6009e6
+++ b/MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
6009e6
@@ -1,7 +1,7 @@
6009e6
 ## @file
6009e6
 # DXE S3 boot script Library.
6009e6
 #
6009e6
-# Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.
6009e6
+# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
6009e6
 #
6009e6
 # SPDX-License-Identifier: BSD-2-Clause-Patent
6009e6
 #
6009e6
@@ -65,4 +65,4 @@
6009e6
   ## SOMETIMES_PRODUCES
6009e6
   gEfiMdeModulePkgTokenSpaceGuid.PcdS3BootScriptTablePrivateSmmDataPtr
6009e6
   gEfiMdeModulePkgTokenSpaceGuid.PcdS3BootScriptRuntimeTableReservePageNumber   ## CONSUMES
6009e6
-
6009e6
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable                                ## CONSUMES
6009e6
-- 
6009e6
1.8.3.1
6009e6