]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: S3 Suspend: save boot script after ACPI context
authorLaszlo Ersek <lersek@redhat.com>
Tue, 4 Mar 2014 08:03:56 +0000 (08:03 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 4 Mar 2014 08:03:56 +0000 (08:03 +0000)
The trigger to actually save the boot script is the installation of
EFI_DXE_SMM_READY_TO_LOCK_PROTOCOL, to be performed by any DXE driver.
Installation of the protocol also locks down SMM (as its name indicates)
and (in theory) prevents further LockBox access.

We cannot install this protocol before BdsLibBootViaBootOption() is called
(eg. in OVMF's PlatformBdsPolicyBehavior()), because
BdsLibBootViaBootOption() calls EFI_ACPI_S3_SAVE_PROTOCOL.S3Save(), which
needs LockBox access.

We also can't install the protocol after BdsLibBootViaBootOption()
returns, simply because control is never returned to us.

Therefore modify our EFI_ACPI_S3_SAVE_PROTOCOL implementation so that the
boot script is prepared and installed internally to S3Save().

(The boot script must contain at least one opcode, otherwise
S3BootScriptLib runs into an assertion failure. We add a harmless (no-op)
"information" opcode.)

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15305 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/AcpiS3SaveDxe/AcpiS3Save.c
OvmfPkg/AcpiS3SaveDxe/AcpiS3SaveDxe.inf

index 80f12eb77abbae78b50a06538f446f2e16810cc7..684ddb70114a3890ffcb49022fb0add79c923e0d 100644 (file)
@@ -28,6 +28,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/AcpiS3Context.h>\r
 #include <Guid/Acpi.h>\r
 #include <Protocol/AcpiS3Save.h>\r
+#include <Protocol/S3SaveState.h>\r
+#include <Protocol/DxeSmmReadyToLock.h>\r
 #include <IndustryStandard/Acpi.h>\r
 \r
 #include "AcpiS3Save.h"\r
@@ -406,6 +408,48 @@ LegacyGetS3MemorySize (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Save the S3 boot script.\r
+\r
+  Note that we trigger DxeSmmReadyToLock here -- otherwise the script wouldn't\r
+  be saved actually. Triggering this protocol installation event in turn locks\r
+  down SMM, so no further changes to LockBoxes or SMRAM are possible\r
+  afterwards.\r
+**/\r
+STATIC\r
+VOID\r
+EFIAPI\r
+SaveS3BootScript (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                 Status;\r
+  EFI_S3_SAVE_STATE_PROTOCOL *BootScript;\r
+  EFI_HANDLE                 Handle;\r
+  STATIC CONST UINT8         Info[] = { 0xDE, 0xAD, 0xBE, 0xEF };\r
+\r
+  Status = gBS->LocateProtocol (&gEfiS3SaveStateProtocolGuid, NULL,\r
+                  (VOID **) &BootScript);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Despite the opcode documentation in the PI spec, the protocol\r
+  // implementation embeds a deep copy of the info in the boot script, rather\r
+  // than storing just a pointer to runtime or NVS storage.\r
+  //\r
+  Status = BootScript->Write(BootScript, EFI_BOOT_SCRIPT_INFORMATION_OPCODE,\r
+                         (UINT32) sizeof Info,\r
+                         (EFI_PHYSICAL_ADDRESS)(UINTN) &Info);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (&Handle,\r
+                  &gEfiDxeSmmReadyToLockProtocolGuid, EFI_NATIVE_INTERFACE,\r
+                  NULL);\r
+  ASSERT_EFI_ERROR (Status);\r
+}\r
+\r
+\r
 /**\r
   Prepares all information that is needed in the S3 resume boot path.\r
   \r
@@ -511,6 +555,11 @@ S3Ready (
   Status = SetLockBoxAttributes (&gEfiAcpiS3ContextGuid, LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Save the boot script too. Note that this requires/includes emitting the\r
+  // DxeSmmReadyToLock event, which in turn locks down SMM.\r
+  //\r
+  SaveS3BootScript ();\r
   return EFI_SUCCESS;\r
 }\r
 \r
index 169e400c70689ef7b405dabe7e55ae5b5a094c8e..159cdb82feab54ed8964dfced0a7e00a9cfe7031 100644 (file)
@@ -62,6 +62,8 @@
   gEfiLegacyBiosProtocolGuid                    # PROTOCOL ALWAYS_CONSUMED\r
   gEfiLegacyRegion2ProtocolGuid                 # PROTOCOL SOMETIMES_CONSUMED\r
   gFrameworkEfiMpServiceProtocolGuid            # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiS3SaveStateProtocolGuid                   # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiDxeSmmReadyToLockProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
 \r
 [FeaturePcd]\r
   gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPlatformCsmSupport          ## CONSUMES\r
@@ -73,4 +75,4 @@
   gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable\r
 \r
 [Depex]\r
-  gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid\r
+  gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid AND gEfiS3SaveStateProtocolGuid\r