]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtAutoScanPei/WinNtAutoScan.c
MdeModulePkg CapsuleApp: Do not parse bits in CapsuleFlags of ESRT
[mirror_edk2.git] / Nt32Pkg / WinNtAutoScanPei / WinNtAutoScan.c
index 0a262da5f2a409082df9e62a0a74859d5ebb21ce..8b68fefcaa341aa447e54dc448761b28921a148c 100644 (file)
@@ -1,7 +1,8 @@
 /**@file\r
 \r
-Copyright (c) 2006, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
+Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
+This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
 http://opensource.org/licenses/bsd-license.php                                            \r
@@ -27,20 +28,80 @@ Revision History
 //\r
 // The protocols, PPI and GUID defintions for this module\r
 //\r
-#include <Ppi/BaseMemoryTest.h>\r
 #include <Ppi/NtAutoscan.h>\r
+#include <Ppi/ReadOnlyVariable2.h>\r
+\r
+#include <Guid/MemoryTypeInformation.h>\r
+\r
 //\r
 // The Library classes this module consumes\r
 //\r
 #include <Library/DebugLib.h>\r
 #include <Library/PeimEntryPoint.h>\r
 #include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {\r
+  { EfiReservedMemoryType,  0x0004 },\r
+  { EfiRuntimeServicesCode, 0x0040 },\r
+  { EfiRuntimeServicesData, 0x0040 },\r
+  { EfiBootServicesCode,    0x0300 },\r
+  { EfiBootServicesData,    0x1000 },\r
+  { EfiMaxMemoryType,       0      }\r
+};\r
+\r
+/**\r
+   Validate variable data for the MemoryTypeInformation. \r
+\r
+   @param MemoryData       Variable data.\r
+   @param MemoryDataSize   Variable data length.\r
+   \r
+   @return TRUE            The variable data is valid.\r
+   @return FALSE           The variable data is invalid.\r
+\r
+**/\r
+BOOLEAN\r
+ValidateMemoryTypeInfoVariable (\r
+  IN EFI_MEMORY_TYPE_INFORMATION      *MemoryData,\r
+  IN UINTN                            MemoryDataSize\r
+  )\r
+{\r
+  UINTN                       Count;\r
+  UINTN                       Index;\r
+\r
+  // Check the input parameter.\r
+  if (MemoryData == NULL) {\r
+    return FALSE;\r
+  }\r
+\r
+  // Get Count\r
+  Count = MemoryDataSize / sizeof (*MemoryData);\r
+\r
+  // Check Size\r
+  if (Count * sizeof(*MemoryData) != MemoryDataSize) {\r
+    return FALSE;\r
+  }\r
+\r
+  // Check last entry type filed.\r
+  if (MemoryData[Count - 1].Type != EfiMaxMemoryType) {\r
+    return FALSE;\r
+  }\r
+\r
+  // Check the type filed.\r
+  for (Index = 0; Index < Count - 1; Index++) {\r
+    if (MemoryData[Index].Type >= EfiMaxMemoryType) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
 \r
 EFI_STATUS\r
 EFIAPI\r
 PeimInitializeWinNtAutoScan (\r
-  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
-  IN EFI_PEI_SERVICES          **PeiServices\r
+  IN       EFI_PEI_FILE_HANDLE       FileHandle,\r
+  IN CONST EFI_PEI_SERVICES          **PeiServices\r
   )\r
 /*++\r
 \r
@@ -61,10 +122,11 @@ Returns:
   PEI_NT_AUTOSCAN_PPI         *PeiNtService;\r
   UINT64                      MemorySize;\r
   EFI_PHYSICAL_ADDRESS        MemoryBase;\r
-  PEI_BASE_MEMORY_TEST_PPI    *MemoryTestPpi;\r
-  EFI_PHYSICAL_ADDRESS        ErrorAddress;\r
   UINTN                       Index;\r
   EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;\r
+  EFI_PEI_READ_ONLY_VARIABLE2_PPI       *Variable;\r
+  UINTN                                 DataSize;\r
+  EFI_MEMORY_TYPE_INFORMATION           MemoryData [EfiMaxMemoryType + 1];\r
 \r
 \r
   DEBUG ((EFI_D_ERROR, "NT 32 Autoscan PEIM Loaded\n"));\r
@@ -72,25 +134,12 @@ Returns:
   //\r
   // Get the PEI NT Autoscan PPI\r
   //\r
-  Status = (**PeiServices).LocatePpi (\r
-                            PeiServices,\r
-                            &gPeiNtAutoScanPpiGuid, // GUID\r
-                            0,                      // INSTANCE\r
-                            &PpiDescriptor,         // EFI_PEI_PPI_DESCRIPTOR\r
-                            &PeiNtService           // PPI\r
-                            );\r
-  ASSERT_EFI_ERROR (Status);\r
-\r
-  //\r
-  // Get the Memory Test PPI\r
-  //\r
-  Status = (**PeiServices).LocatePpi (\r
-                            PeiServices,\r
-                            &gPeiBaseMemoryTestPpiGuid,\r
-                            0,\r
-                            NULL,\r
-                            &MemoryTestPpi\r
-                            );\r
+  Status = PeiServicesLocatePpi (\r
+             &gPeiNtAutoScanPpiGuid, // GUID\r
+             0,                      // INSTANCE\r
+             &PpiDescriptor,         // EFI_PEI_PPI_DESCRIPTOR\r
+             (VOID**)&PeiNtService           // PPI\r
+             );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   Index = 0;\r
@@ -109,22 +158,9 @@ Returns:
 \r
       if (Index == 0) {\r
         //\r
-        // For the first area register it as PEI tested memory\r
-        //\r
-        Status = MemoryTestPpi->BaseMemoryTest (\r
-                                  PeiServices,\r
-                                  MemoryTestPpi,\r
-                                  MemoryBase,\r
-                                  MemorySize,\r
-                                  Quick,\r
-                                  &ErrorAddress\r
-                                  );\r
-        ASSERT_EFI_ERROR (Status);\r
-\r
-        //\r
-        // Register the "tested" memory with the PEI Core\r
+        // Register the memory with the PEI Core\r
         //\r
-        Status = (**PeiServices).InstallPeiMemory (PeiServices, MemoryBase, MemorySize);\r
+        Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize);\r
         ASSERT_EFI_ERROR (Status);\r
 \r
         Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;\r
@@ -141,9 +177,49 @@ Returns:
   } while (!EFI_ERROR (Status));\r
 \r
   //\r
-  // Build the CPU hob with 36-bit addressing and 16-bits of IO space.\r
+  // Build the CPU hob with 52-bit addressing and 16-bits of IO space.\r
+  //\r
+  BuildCpuHob (52, 16);\r
+\r
+  //\r
+  // Build GUIDed Hob that contains the Memory Type Information array\r
   //\r
-  BuildCpuHob (36, 16);\r
-  \r
+  Status = PeiServicesLocatePpi (\r
+             &gEfiPeiReadOnlyVariable2PpiGuid,\r
+             0,\r
+             NULL,\r
+             (VOID **)&Variable\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  DataSize = sizeof (MemoryData);\r
+  Status = Variable->GetVariable (\r
+                       Variable,\r
+                       EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
+                       &gEfiMemoryTypeInformationGuid,\r
+                       NULL,\r
+                       &DataSize,\r
+                       &MemoryData\r
+                       );\r
+  if (EFI_ERROR (Status) || !ValidateMemoryTypeInfoVariable(MemoryData, DataSize)) {\r
+    //\r
+    // Create Memory Type Information HOB\r
+    //\r
+    BuildGuidDataHob (\r
+      &gEfiMemoryTypeInformationGuid,\r
+      mDefaultMemoryTypeInformation,\r
+      sizeof(mDefaultMemoryTypeInformation)\r
+      );\r
+  } else {\r
+    //\r
+    // Create Memory Type Information HOB\r
+    //\r
+    BuildGuidDataHob (\r
+      &gEfiMemoryTypeInformationGuid,\r
+      MemoryData,\r
+      DataSize\r
+      );\r
+  }\r
+\r
   return Status;\r
 }\r