]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c
OvmfPkg/AcpiPlatformDxe: Measure ACPI table from QEMU in TDVF
[mirror_edk2.git] / OvmfPkg / AcpiPlatformDxe / QemuFwCfgAcpi.c
index 462921466604dcad1657c0da73e806866235bf0a..68abc34f2280ca5aaebc23dfa6f4223a45651c4c 100644 (file)
@@ -10,6 +10,7 @@
 \r
 #include <IndustryStandard/Acpi.h>            // EFI_ACPI_DESCRIPTION_HEADER\r
 #include <IndustryStandard/QemuLoader.h>      // QEMU_LOADER_FNAME_SIZE\r
+#include <IndustryStandard/UefiTcgPlatform.h>\r
 #include <Library/BaseLib.h>                  // AsciiStrCmp()\r
 #include <Library/BaseMemoryLib.h>            // CopyMem()\r
 #include <Library/DebugLib.h>                 // DEBUG()\r
@@ -18,6 +19,7 @@
 #include <Library/QemuFwCfgLib.h>             // QemuFwCfgFindFile()\r
 #include <Library/QemuFwCfgS3Lib.h>           // QemuFwCfgS3Enabled()\r
 #include <Library/UefiBootServicesTableLib.h> // gBS\r
+#include <Library/TpmMeasurementLib.h>\r
 \r
 #include "AcpiPlatform.h"\r
 \r
@@ -415,6 +417,21 @@ ProcessCmdAllocate (
     (UINT64)Blob->Size,\r
     (UINT64)(UINTN)Blob->Base\r
     ));\r
+\r
+  //\r
+  // Measure the data which is downloaded from QEMU.\r
+  // It has to be done before it is consumed. Because the data will\r
+  // be updated in the following operations.\r
+  //\r
+  TpmMeasureAndLogData (\r
+    1,\r
+    EV_PLATFORM_CONFIG_FLAGS,\r
+    EV_POSTCODE_INFO_ACPI_DATA,\r
+    ACPI_DATA_LEN,\r
+    (VOID *)(UINTN)Blob->Base,\r
+    Blob->Size\r
+    );\r
+\r
   return EFI_SUCCESS;\r
 \r
 FreeBlob:\r
@@ -1126,6 +1143,21 @@ InstallQemuFwCfgTables (
   QemuFwCfgSelectItem (FwCfgItem);\r
   QemuFwCfgReadBytes (FwCfgSize, LoaderStart);\r
   RestorePciDecoding (OriginalPciAttributes, OriginalPciAttributesCount);\r
+\r
+  //\r
+  // Measure the "etc/table-loader" which is downloaded from QEMU.\r
+  // It has to be done before it is consumed. Because it would be\r
+  // updated in the following operations.\r
+  //\r
+  TpmMeasureAndLogData (\r
+    1,\r
+    EV_PLATFORM_CONFIG_FLAGS,\r
+    EV_POSTCODE_INFO_ACPI_DATA,\r
+    ACPI_DATA_LEN,\r
+    (VOID *)(UINTN)LoaderStart,\r
+    FwCfgSize\r
+    );\r
+\r
   LoaderEnd = LoaderStart + FwCfgSize / sizeof *LoaderEntry;\r
 \r
   AllocationsRestrictedTo32Bit = NULL;\r
@@ -1247,6 +1279,21 @@ InstallQemuFwCfgTables (
     }\r
   }\r
 \r
+  //\r
+  // Install a protocol to notify that the ACPI table provided by Qemu is\r
+  // ready.\r
+  //\r
+  QemuAcpiHandle = NULL;\r
+  Status         = gBS->InstallProtocolInterface (\r
+                          &QemuAcpiHandle,\r
+                          &gQemuAcpiTableNotifyProtocolGuid,\r
+                          EFI_NATIVE_INTERFACE,\r
+                          NULL\r
+                          );\r
+  if (EFI_ERROR (Status)) {\r
+    goto UninstallAcpiTables;\r
+  }\r
+\r
   //\r
   // Translating the condensed QEMU_LOADER_WRITE_POINTER commands to ACPI S3\r
   // Boot Script opcodes has to be the last operation in this function, because\r
@@ -1255,7 +1302,7 @@ InstallQemuFwCfgTables (
   if (S3Context != NULL) {\r
     Status = TransferS3ContextToBootScript (S3Context);\r
     if (EFI_ERROR (Status)) {\r
-      goto UninstallAcpiTables;\r
+      goto UninstallQemuAcpiTableNotifyProtocol;\r
     }\r
 \r
     //\r
@@ -1266,6 +1313,15 @@ InstallQemuFwCfgTables (
 \r
   DEBUG ((DEBUG_INFO, "%a: installed %d tables\n", __FUNCTION__, Installed));\r
 \r
+UninstallQemuAcpiTableNotifyProtocol:\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->UninstallProtocolInterface (\r
+           QemuAcpiHandle,\r
+           &gQemuAcpiTableNotifyProtocolGuid,\r
+           NULL\r
+           );\r
+  }\r
+\r
 UninstallAcpiTables:\r
   if (EFI_ERROR (Status)) {\r
     //\r
@@ -1275,18 +1331,6 @@ UninstallAcpiTables:
       --Installed;\r
       AcpiProtocol->UninstallAcpiTable (AcpiProtocol, InstalledKey[Installed]);\r
     }\r
-  } else {\r
-    //\r
-    // Install a protocol to notify that the ACPI table provided by Qemu is\r
-    // ready.\r
-    //\r
-    QemuAcpiHandle = NULL;\r
-    gBS->InstallProtocolInterface (\r
-           &QemuAcpiHandle,\r
-           &gQemuAcpiTableNotifyProtocolGuid,\r
-           EFI_NATIVE_INTERFACE,\r
-           NULL\r
-           );\r
   }\r
 \r
   for (SeenPointerEntry = OrderedCollectionMin (SeenPointers);\r