]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/AcpiPlatformDxe: Differentiate TDX case for Cloud Hypervisor
authorSebastien Boeuf <sebastien.boeuf@intel.com>
Thu, 15 Dec 2022 15:10:04 +0000 (23:10 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 16 Dec 2022 02:37:56 +0000 (02:37 +0000)
Rely on CcProbe() to identify when running on TDX so that ACPI tables
can be retrieved differently for Cloud Hypervisor. Instead of relying on
the PVH structure to find the RSDP pointer, the tables are individually
passed through the HOB.

Signed-off-by: Jiaqi Gao <jiaqi.gao@intel.com>
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Reviewed-by: Min Xu <min.m.xu@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
ArmVirtPkg/ArmVirtQemu.dsc
OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c
OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h
OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf
OvmfPkg/AcpiPlatformDxe/CloudHvAcpi.c
OvmfPkg/OvmfPkg.dec

index f77443229e8e2af14a0d25d6036b3ce482fbbbd7..1dea715e9e4bd477740cfa1f9ddcf3fc0509a317 100644 (file)
@@ -68,6 +68,7 @@
   VirtNorFlashPlatformLib|ArmVirtPkg/Library/NorFlashQemuLib/NorFlashQemuLib.inf\r
 \r
   CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf\r
+  CcProbeLib|MdePkg/Library/CcProbeLibNull/CcProbeLibNull.inf\r
   BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf\r
   PlatformBootManagerLib|ArmVirtPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf\r
   PlatformBmPrintScLib|OvmfPkg/Library/PlatformBmPrintScLib/PlatformBmPrintScLib.inf\r
index fcfb9703bd60e0bf7dffebd93ef9c72844bbbc18..0cc3d958bed47d3edbece895b0eb338fadc8880d 100644 (file)
@@ -9,6 +9,8 @@
 \r
 #include <OvmfPlatforms.h> // CLOUDHV_DEVICE_ID\r
 \r
+#include <Library/CcProbeLib.h> // CcProbe(), CcGuestTypeIntelTdx\r
+\r
 #include "AcpiPlatform.h"\r
 \r
 /**\r
@@ -33,7 +35,11 @@ InstallAcpiTables (
 \r
   HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);\r
   if (HostBridgeDevId == CLOUDHV_DEVICE_ID) {\r
-    Status = InstallCloudHvTables (AcpiTable);\r
+    if (CcProbe () == CcGuestTypeIntelTdx) {\r
+      Status = InstallCloudHvTablesTdx (AcpiTable);\r
+    } else {\r
+      Status = InstallCloudHvTables (AcpiTable);\r
+    }\r
   } else {\r
     Status = InstallQemuFwCfgTables (AcpiTable);\r
   }\r
index 342339750ddb51e76ebf328f19c23115bacfd234..3ec50986586335264b041a7306158038d23b43bc 100644 (file)
@@ -19,6 +19,12 @@ typedef struct {
 \r
 typedef struct S3_CONTEXT S3_CONTEXT;\r
 \r
+EFI_STATUS\r
+EFIAPI\r
+InstallCloudHvTablesTdx (\r
+  IN   EFI_ACPI_TABLE_PROTOCOL  *AcpiProtocol\r
+  );\r
+\r
 EFI_STATUS\r
 EFIAPI\r
 InstallCloudHvTables (\r
index 09daf30bcd3d4f75843bce96cb12d12eca113223..1647a90add8bb9a7701f169bfbb5f30f33564108 100644 (file)
@@ -45,6 +45,8 @@
   QemuFwCfgS3Lib\r
   UefiBootServicesTableLib\r
   UefiDriverEntryPoint\r
+  HobLib\r
+  CcProbeLib\r
 \r
 [Protocols]\r
   gEfiAcpiTableProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
@@ -53,6 +55,7 @@
 \r
 [Guids]\r
   gRootBridgesConnectedEventGroupGuid\r
+  gUefiOvmfPkgTdxAcpiHobGuid\r
 \r
 [Pcd]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration\r
index ff59600d3ea14b57c4a89319dcbc1065ba5d9821..cbe8bb9b0c7530a2a214f90a2570e5b3ca19c361 100644 (file)
 \r
 **/\r
 \r
+#include <IndustryStandard/Acpi.h>                        // EFI_ACPI_DESCRIPTION_HEADER\r
 #include <IndustryStandard/CloudHv.h>                     // CLOUDHV_RSDP_ADDRESS\r
 #include <IndustryStandard/Xen/arch-x86/hvm/start_info.h> // hvm_start_info\r
 #include <Library/BaseLib.h>                              // CpuDeadLoop()\r
 #include <Library/DebugLib.h>                             // DEBUG()\r
 #include <Library/PcdLib.h>                               // PcdGet32()\r
+#include <Library/HobLib.h>                               // GetFirstGuidHob(), GetNextGuidHob()\r
+#include <Library/UefiBootServicesTableLib.h>             // gBS\r
+\r
+#include <Protocol/AcpiSystemDescriptionTable.h>\r
+#include <Protocol/AcpiTable.h>\r
+#include <Protocol/QemuAcpiTableNotify.h>                 // QEMU_ACPI_TABLE_NOTIFY_PROTOCOL\r
 \r
 #include "AcpiPlatform.h"\r
 \r
+EFI_HANDLE                       mChAcpiHandle = NULL;\r
+QEMU_ACPI_TABLE_NOTIFY_PROTOCOL  mChAcpiNotifyProtocol;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InstallCloudHvTablesTdx (\r
+  IN   EFI_ACPI_TABLE_PROTOCOL  *AcpiProtocol\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       TableHandle;\r
+\r
+  EFI_PEI_HOB_POINTERS         Hob;\r
+  EFI_ACPI_DESCRIPTION_HEADER  *CurrentTable;\r
+  EFI_ACPI_DESCRIPTION_HEADER  *DsdtTable;\r
+\r
+  DsdtTable   = NULL;\r
+  TableHandle = 0;\r
+\r
+  Hob.Guid = (EFI_HOB_GUID_TYPE *)GetFirstGuidHob (&gUefiOvmfPkgTdxAcpiHobGuid);\r
+\r
+  while (Hob.Guid != NULL) {\r
+    CurrentTable = (EFI_ACPI_DESCRIPTION_HEADER *)(&Hob.Guid->Name + 1);\r
+    if (!AsciiStrnCmp ((CHAR8 *)&CurrentTable->Signature, "DSDT", 4)) {\r
+      DsdtTable = CurrentTable;\r
+    } else {\r
+      //\r
+      // Install the tables\r
+      //\r
+      Status = AcpiProtocol->InstallAcpiTable (\r
+                               AcpiProtocol,\r
+                               CurrentTable,\r
+                               CurrentTable->Length,\r
+                               &TableHandle\r
+                               );\r
+      for (UINTN i = 0; i < CurrentTable->Length; i++) {\r
+        DEBUG ((DEBUG_INFO, " %x", *((UINT8 *)CurrentTable + i)));\r
+      }\r
+\r
+      DEBUG ((DEBUG_INFO, "\n"));\r
+    }\r
+\r
+    Hob.Raw  = GET_NEXT_HOB (Hob.Raw);\r
+    Hob.Guid = (EFI_HOB_GUID_TYPE *)GetNextGuidHob (&gUefiOvmfPkgTdxAcpiHobGuid, Hob.Raw);\r
+  }\r
+\r
+  //\r
+  // Install DSDT table. If we reached this point without finding the DSDT,\r
+  // then we're out of sync with the hypervisor, and cannot continue.\r
+  //\r
+  if (DsdtTable == NULL) {\r
+    DEBUG ((DEBUG_INFO, "%a: no DSDT found\n", __FUNCTION__));\r
+    ASSERT (FALSE);\r
+  }\r
+\r
+  Status = AcpiProtocol->InstallAcpiTable (\r
+                           AcpiProtocol,\r
+                           DsdtTable,\r
+                           DsdtTable->Length,\r
+                           &TableHandle\r
+                           );\r
+  if (EFI_ERROR (Status)) {\r
+    ASSERT_EFI_ERROR (Status);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Install a protocol to notify that the ACPI table provided by CH is\r
+  // ready.\r
+  //\r
+  gBS->InstallProtocolInterface (\r
+         &mChAcpiHandle,\r
+         &gQemuAcpiTableNotifyProtocolGuid,\r
+         EFI_NATIVE_INTERFACE,\r
+         &mChAcpiNotifyProtocol\r
+         );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
 // Get the ACPI tables from EBDA start\r
 EFI_STATUS\r
 EFIAPI\r
index 5f5556c67c6c9ca2c82479438c7170d741c30ab3..a350bb8f84b909f7c93128e804bab98b7737b471 100644 (file)
   gConfidentialComputingSevSnpBlobGuid  = {0x067b1f5f, 0xcf26, 0x44c5, {0x85, 0x54, 0x93, 0xd7, 0x77, 0x91, 0x2d, 0x42}}\r
   gUefiOvmfPkgPlatformInfoGuid          = {0xdec9b486, 0x1f16, 0x47c7, {0x8f, 0x68, 0xdf, 0x1a, 0x41, 0x88, 0x8b, 0xa5}}\r
   gVMMBootOrderGuid                     = {0x668f4529, 0x63d0, 0x4bb5, {0xb6, 0x5d, 0x6f, 0xbb, 0x9d, 0x36, 0xa4, 0x4a}}\r
+  gUefiOvmfPkgTdxAcpiHobGuid            = {0x6a0c5870, 0xd4ed, 0x44f4, {0xa1, 0x35, 0xdd, 0x23, 0x8b, 0x6f, 0x0c, 0x8d}}\r
 \r
 [Ppis]\r
   # PPI whose presence in the PPI database signals that the TPM base address\r