]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/SecCore/SecBist.c
UefiCpuPkg/CpuDxe: Enable protection for newly added page table
[mirror_edk2.git] / UefiCpuPkg / SecCore / SecBist.c
index cba445dca038ad27018ca36209268491a7c8e80d..a9d36acadb0d652a85732b5b92315b60bdcfb2f6 100644 (file)
 \r
 #include "SecMain.h"\r
 \r
+EFI_SEC_PLATFORM_INFORMATION_PPI mSecPlatformInformation = {\r
+  SecPlatformInformationBist\r
+};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiSecPlatformInformationPpiGuid,\r
+  &mSecPlatformInformation\r
+};\r
+\r
+EFI_SEC_PLATFORM_INFORMATION2_PPI mSecPlatformInformation2 = {\r
+  SecPlatformInformation2Bist\r
+};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR mPeiSecPlatformInformation2 = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiSecPlatformInformation2PpiGuid,\r
+  &mSecPlatformInformation2\r
+};\r
+\r
 /**\r
-  Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.\r
+  Worker function to parse CPU BIST information from Guided HOB.\r
 \r
-  @param  PeiServices                The pointer to the PEI Services Table.\r
-  @param  StructureSize              The pointer to the variable describing size of the input buffer.\r
-  @param  PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.\r
+  @param[in, out] StructureSize     Pointer to the variable describing size of the input buffer.\r
+  @param[in, out] StructureBuffer   Pointer to the buffer save CPU BIST information.\r
 \r
-  @retval EFI_SUCCESS                The data was successfully returned.\r
-  @retval EFI_BUFFER_TOO_SMALL       The buffer was too small. The current buffer size needed to\r
-                                     hold the record is returned in StructureSize.\r
+  @retval EFI_SUCCESS           The data was successfully returned.\r
+  @retval EFI_BUFFER_TOO_SMALL  The buffer was too small.\r
 \r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
-SecPlatformInformation2 (\r
-  IN CONST EFI_PEI_SERVICES                   **PeiServices,\r
-  IN OUT UINT64                               *StructureSize,\r
-     OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
+GetBistFromHob (\r
+  IN OUT UINT64           *StructureSize,\r
+  IN OUT VOID             *StructureBuffer\r
   )\r
 {\r
   EFI_HOB_GUID_TYPE       *GuidHob;\r
   VOID                    *DataInHob;\r
   UINTN                   DataSize;\r
 \r
-  GuidHob = GetFirstGuidHob (&gEfiSecPlatformInformation2PpiGuid);\r
+  GuidHob = GetFirstGuidHob (&gEfiCallerIdGuid);\r
   if (GuidHob == NULL) {\r
     *StructureSize = 0;\r
     return EFI_SUCCESS;\r
@@ -56,20 +72,65 @@ SecPlatformInformation2 (
   }\r
 \r
   *StructureSize = (UINT64) DataSize;\r
-  CopyMem (PlatformInformationRecord2, DataInHob, DataSize);\r
+  CopyMem (StructureBuffer, DataInHob, DataSize);\r
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  Implementation of the PlatformInformation service in EFI_SEC_PLATFORM_INFORMATION_PPI.\r
+\r
+  @param[in]      PeiServices                Pointer to the PEI Services Table.\r
+  @param[in, out] StructureSize              Pointer to the variable describing size of the input buffer.\r
+  @param[out]     PlatformInformationRecord  Pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD.\r
+\r
+  @retval EFI_SUCCESS                    The data was successfully returned.\r
+  @retval EFI_BUFFER_TOO_SMALL           The buffer was too small.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SecPlatformInformationBist (\r
+  IN CONST EFI_PEI_SERVICES                  **PeiServices,\r
+  IN OUT UINT64                              *StructureSize,\r
+     OUT EFI_SEC_PLATFORM_INFORMATION_RECORD *PlatformInformationRecord\r
+  )\r
+{\r
+  return GetBistFromHob (StructureSize, PlatformInformationRecord);\r
+}\r
+\r
+/**\r
+  Implementation of the PlatformInformation2 service in EFI_SEC_PLATFORM_INFORMATION2_PPI.\r
+\r
+  @param[in]      PeiServices                The pointer to the PEI Services Table.\r
+  @param[in, out] StructureSize              The pointer to the variable describing size of the input buffer.\r
+  @param[out]     PlatformInformationRecord2 The pointer to the EFI_SEC_PLATFORM_INFORMATION_RECORD2.\r
+\r
+  @retval EFI_SUCCESS                    The data was successfully returned.\r
+  @retval EFI_BUFFER_TOO_SMALL           The buffer was too small. The current buffer size needed to\r
+                                         hold the record is returned in StructureSize.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SecPlatformInformation2Bist (\r
+  IN CONST EFI_PEI_SERVICES                   **PeiServices,\r
+  IN OUT UINT64                               *StructureSize,\r
+     OUT EFI_SEC_PLATFORM_INFORMATION_RECORD2 *PlatformInformationRecord2\r
+  )\r
+{\r
+  return GetBistFromHob (StructureSize, PlatformInformationRecord2);\r
+}\r
+\r
 /**\r
   Worker function to get CPUs' BIST by calling SecPlatformInformationPpi\r
   or SecPlatformInformation2Ppi.\r
 \r
-  @param  PeiServices         Pointer to PEI Services Table\r
-  @param  Guid                PPI Guid\r
-  @param  PpiDescriptor       Return a pointer to instance of the\r
-                              EFI_PEI_PPI_DESCRIPTOR\r
-  @param  BistInformationData Pointer to BIST information data\r
-  @param  BistInformationSize Return the size in bytes of BIST information\r
+  @param[in]  PeiServices         Pointer to PEI Services Table\r
+  @param[in]  Guid                PPI Guid\r
+  @param[out] PpiDescriptor       Return a pointer to instance of the\r
+                                  EFI_PEI_PPI_DESCRIPTOR\r
+  @param[out] BistInformationData Pointer to BIST information data\r
+  @param[out] BistInformationSize Return the size in bytes of BIST information\r
 \r
   @retval EFI_SUCCESS         Retrieve of the BIST data successfully\r
   @retval EFI_NOT_FOUND       No sec platform information(2) ppi export\r
@@ -138,3 +199,72 @@ GetBistInfoFromPpi (
 \r
   return EFI_DEVICE_ERROR;\r
 }\r
+\r
+/**\r
+  Get CPUs' BIST by calling SecPlatformInformationPpi/SecPlatformInformation2Ppi.\r
+\r
+**/\r
+VOID\r
+RepublishSecPlatformInformationPpi (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS                            Status;\r
+  CONST EFI_PEI_SERVICES                **PeiServices;\r
+  UINT64                                BistInformationSize;\r
+  VOID                                  *BistInformationData;\r
+  EFI_PEI_PPI_DESCRIPTOR                *SecInformationDescriptor;\r
+\r
+  PeiServices = GetPeiServicesTablePointer ();\r
+  Status = GetBistInfoFromPpi (\r
+             PeiServices,\r
+             &gEfiSecPlatformInformation2PpiGuid,\r
+             &SecInformationDescriptor,\r
+             &BistInformationData,\r
+             &BistInformationSize\r
+             );\r
+  if (Status == EFI_SUCCESS) {\r
+    BuildGuidDataHob (\r
+      &gEfiCallerIdGuid,\r
+      BistInformationData,\r
+      (UINTN) BistInformationSize\r
+      );\r
+    //\r
+    // The old SecPlatformInformation2 data is on temporary memory.\r
+    // After memory discovered, we should never get it from temporary memory,\r
+    // or the data will be crashed. So, we reinstall SecPlatformInformation2 PPI here.\r
+    //\r
+    Status = PeiServicesReInstallPpi (\r
+               SecInformationDescriptor,\r
+               &mPeiSecPlatformInformation2\r
+               );\r
+  } if (Status == EFI_NOT_FOUND) {\r
+    Status = GetBistInfoFromPpi (\r
+               PeiServices,\r
+               &gEfiSecPlatformInformationPpiGuid,\r
+               &SecInformationDescriptor,\r
+               &BistInformationData,\r
+               &BistInformationSize\r
+               );\r
+    if (Status == EFI_SUCCESS) {\r
+      BuildGuidDataHob (\r
+        &gEfiCallerIdGuid,\r
+        BistInformationData,\r
+        (UINTN) BistInformationSize\r
+        );\r
+      //\r
+      // The old SecPlatformInformation data is on temporary memory.\r
+      // After memory discovered, we should never get it from temporary memory,\r
+      // or the data will be crashed. So, we reinstall SecPlatformInformation PPI here.\r
+      //\r
+      Status = PeiServicesReInstallPpi (\r
+                 SecInformationDescriptor,\r
+                 &mPeiSecPlatformInformation\r
+                 );\r
+    } else if (Status == EFI_NOT_FOUND) {\r
+      return;\r
+    }\r
+  }\r
+\r
+  ASSERT_EFI_ERROR(Status);\r
+}\r