]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/MpInitLib/MpLib.c
UefiCpuPkg/MpInitLib: use PcdConfidentialComputingAttr to check SEV status
[mirror_edk2.git] / UefiCpuPkg / Library / MpInitLib / MpLib.c
index 34555c069331c4e2e4a2897db43a0b358ac05909..64fddb497e1e7f59c93a95e56690cfe7719c408d 100644 (file)
@@ -295,7 +295,7 @@ GetApLoopMode (
       ApLoopMode = ApInHltLoop;\r
     }\r
 \r
-    if (PcdGetBool (PcdSevEsIsEnabled)) {\r
+    if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) {\r
       //\r
       // For SEV-ES, force AP in Hlt-loop mode in order to use the GHCB\r
       // protocol for starting APs\r
@@ -1055,7 +1055,7 @@ AllocateResetVector (
     // The AP reset stack is only used by SEV-ES guests. Do not allocate it\r
     // if SEV-ES is not enabled.\r
     //\r
-    if (PcdGetBool (PcdSevEsIsEnabled)) {\r
+    if (ConfidentialComputingGuestHas (CCAttrAmdSevEs)) {\r
       //\r
       // Stack location is based on ProcessorNumber, so use the total number\r
       // of processors for calculating the total stack area.\r
@@ -1847,7 +1847,7 @@ MpInitLibInitialize (
   CpuMpData->CpuData          = (CPU_AP_DATA *)(CpuMpData + 1);\r
   CpuMpData->CpuInfoInHob     = (UINT64)(UINTN)(CpuMpData->CpuData + MaxLogicalProcessorNumber);\r
   InitializeSpinLock (&CpuMpData->MpLock);\r
-  CpuMpData->SevEsIsEnabled = PcdGetBool (PcdSevEsIsEnabled);\r
+  CpuMpData->SevEsIsEnabled = ConfidentialComputingGuestHas (CCAttrAmdSevEs);\r
   CpuMpData->SevEsAPBuffer  = (UINTN)-1;\r
   CpuMpData->GhcbBase       = PcdGet64 (PcdGhcbBase);\r
 \r
@@ -2755,3 +2755,70 @@ MpInitLibStartupAllCPUs (
            NULL\r
            );\r
 }\r
+\r
+/**\r
+  The function check if the specified Attr is set.\r
+\r
+  @param[in]  CurrentAttr   The current attribute.\r
+  @param[in]  Attr          The attribute to check.\r
+\r
+  @retval  TRUE      The specified Attr is set.\r
+  @retval  FALSE     The specified Attr is not set.\r
+\r
+**/\r
+STATIC\r
+BOOLEAN\r
+AmdMemEncryptionAttrCheck (\r
+  IN  UINT64                             CurrentAttr,\r
+  IN  CONFIDENTIAL_COMPUTING_GUEST_ATTR  Attr\r
+  )\r
+{\r
+  switch (Attr) {\r
+    case CCAttrAmdSev:\r
+      //\r
+      // SEV is automatically enabled if SEV-ES or SEV-SNP is active.\r
+      //\r
+      return CurrentAttr >= CCAttrAmdSev;\r
+    case CCAttrAmdSevEs:\r
+      //\r
+      // SEV-ES is automatically enabled if SEV-SNP is active.\r
+      //\r
+      return CurrentAttr >= CCAttrAmdSevEs;\r
+    case CCAttrAmdSevSnp:\r
+      return CurrentAttr == CCAttrAmdSevSnp;\r
+    default:\r
+      return FALSE;\r
+  }\r
+}\r
+\r
+/**\r
+  Check if the specified confidential computing attribute is active.\r
+\r
+  @param[in]  Attr          The attribute to check.\r
+\r
+  @retval TRUE   The specified Attr is active.\r
+  @retval FALSE  The specified Attr is not active.\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+ConfidentialComputingGuestHas (\r
+  IN  CONFIDENTIAL_COMPUTING_GUEST_ATTR  Attr\r
+  )\r
+{\r
+  UINT64  CurrentAttr;\r
+\r
+  //\r
+  // Get the current CC attribute.\r
+  //\r
+  CurrentAttr = PcdGet64 (PcdConfidentialComputingGuestAttr);\r
+\r
+  //\r
+  // If attr is for the AMD group then call AMD specific checks.\r
+  //\r
+  if (((RShiftU64 (CurrentAttr, 8)) & 0xff) == 1) {\r
+    return AmdMemEncryptionAttrCheck (CurrentAttr, Attr);\r
+  }\r
+\r
+  return (CurrentAttr == Attr);\r
+}\r