]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg: Update TdxDxe to set TDX PCDs
authorMin Xu <min.m.xu@intel.com>
Mon, 24 Jan 2022 13:03:58 +0000 (21:03 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Sat, 2 Apr 2022 10:09:47 +0000 (10:09 +0000)
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3429

TDX_PEI_LESS_BOOT indicates the boot without PEI phase. In this case
settings in EFI_HOB_PLATFORM_INFO should be set to its according PCDs.
TdxDxe driver is workable for both Legacy guest and Tdx guest. It is
because for Legacy guest (in PEI-less boot) there should be a place
to set the PCDs based on EFI_HOB_PLATFORM_INFO hob. TdxDxe driver is
the right place to do this work.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Brijesh Singh <brijesh.singh@amd.com>
Cc: Erdem Aktas <erdemaktas@google.com>
Cc: James Bottomley <jejb@linux.ibm.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Min Xu <min.m.xu@intel.com>
OvmfPkg/TdxDxe/TdxDxe.c
OvmfPkg/TdxDxe/TdxDxe.inf

index b1959a8b196de5d10a26bb2d73e3fed1ef7a786d..f0929998233c07a5e28da9a37328a414c1d002b2 100644 (file)
 #include <Library/HobLib.h>\r
 #include <Protocol/Cpu.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
+#include <ConfidentialComputingGuestAttr.h>\r
 #include <IndustryStandard/Tdx.h>\r
 #include <Library/PlatformInitLib.h>\r
 #include <Library/TdxLib.h>\r
 #include <TdxAcpiTable.h>\r
 #include <Library/MemEncryptTdxLib.h>\r
 \r
+VOID\r
+SetPcdSettings (\r
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob\r
+  )\r
+{\r
+  RETURN_STATUS  PcdStatus;\r
+\r
+  PcdStatus = PcdSet64S (PcdConfidentialComputingGuestAttr, PlatformInfoHob->PcdConfidentialComputingGuestAttr);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+  PcdStatus = PcdSetBoolS (PcdSetNxForStack, PlatformInfoHob->PcdSetNxForStack);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+\r
+  DEBUG ((\r
+    DEBUG_INFO,\r
+    "HostBridgeDevId=0x%x, CCAttr=0x%x, SetNxForStack=%x\n",\r
+    PlatformInfoHob->HostBridgeDevId,\r
+    PlatformInfoHob->PcdConfidentialComputingGuestAttr,\r
+    PlatformInfoHob->PcdSetNxForStack\r
+    ));\r
+\r
+  PcdStatus = PcdSet32S (PcdCpuBootLogicalProcessorNumber, PlatformInfoHob->PcdCpuBootLogicalProcessorNumber);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+  PcdStatus = PcdSet32S (PcdCpuMaxLogicalProcessorNumber, PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber);\r
+  ASSERT_RETURN_ERROR (PcdStatus);\r
+\r
+  DEBUG ((\r
+    DEBUG_INFO,\r
+    "MaxCpuCount=0x%x, BootCpuCount=0x%x\n",\r
+    PlatformInfoHob->PcdCpuMaxLogicalProcessorNumber,\r
+    PlatformInfoHob->PcdCpuBootLogicalProcessorNumber\r
+    ));\r
+\r
+  if (TdIsEnabled ()) {\r
+    PcdStatus = PcdSet64S (PcdTdxSharedBitMask, TdSharedPageMask ());\r
+    ASSERT_RETURN_ERROR (PcdStatus);\r
+    DEBUG ((DEBUG_INFO, "TdxSharedBitMask=0x%llx\n", PcdGet64 (PcdTdxSharedBitMask)));\r
+  } else {\r
+    PcdStatus = PcdSet64S (PcdPciMmio64Base, PlatformInfoHob->PcdPciMmio64Base);\r
+    ASSERT_RETURN_ERROR (PcdStatus);\r
+    PcdStatus = PcdSet64S (PcdPciMmio64Size, PlatformInfoHob->PcdPciMmio64Size);\r
+    ASSERT_RETURN_ERROR (PcdStatus);\r
+    PcdStatus = PcdSet64S (PcdPciMmio32Base, PlatformInfoHob->PcdPciMmio32Base);\r
+    ASSERT_RETURN_ERROR (PcdStatus);\r
+    PcdStatus = PcdSet64S (PcdPciMmio32Size, PlatformInfoHob->PcdPciMmio32Size);\r
+    ASSERT_RETURN_ERROR (PcdStatus);\r
+    PcdStatus = PcdSet64S (PcdPciIoBase, PlatformInfoHob->PcdPciIoBase);\r
+    ASSERT_RETURN_ERROR (PcdStatus);\r
+    PcdStatus = PcdSet64S (PcdPciIoSize, PlatformInfoHob->PcdPciIoSize);\r
+    ASSERT_RETURN_ERROR (PcdStatus);\r
+  }\r
+}\r
+\r
 /**\r
   Location of resource hob matching type and starting address\r
 \r
@@ -187,8 +240,19 @@ TdxDxeEntryPoint (
   PcdStatus = PcdSet16S (PcdOvmfHostBridgePciDevId, PlatformInfo->HostBridgeDevId);\r
   ASSERT_RETURN_ERROR (PcdStatus);\r
 \r
+ #ifdef TDX_PEI_LESS_BOOT\r
+  //\r
+  // For Pei-less boot, PlatformInfo contains more information and\r
+  // need to set PCDs based on these information.\r
+  //\r
+  SetPcdSettings (PlatformInfo);\r
+ #endif\r
+\r
   if (!TdIsEnabled ()) {\r
-    return EFI_UNSUPPORTED;\r
+    //\r
+    // If it is Non-Td guest, we're done.\r
+    //\r
+    return EFI_SUCCESS;\r
   }\r
 \r
   SetMmioSharedBit ();\r
index b5976ab3cebac7bea8173ecbf1fb218c93b540ab..2ec2ef2ed5f2902d43882fbf65b749d9489d693d 100644 (file)
@@ -60,5 +60,9 @@
   gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId\r
   gUefiCpuPkgTokenSpaceGuid.PcdCpuMaxLogicalProcessorNumber\r
+  gUefiCpuPkgTokenSpaceGuid.PcdCpuBootLogicalProcessorNumber\r
   gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress\r
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress\r
+  gEfiMdePkgTokenSpaceGuid.PcdConfidentialComputingGuestAttr\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdTdxSharedBitMask\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack\r