+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation \r
+All rights reserved. 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
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+ WinNtAutoscan.c\r
+\r
+Abstract:\r
+ This PEIM to abstract memory auto-scan in a Windows NT environment.\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+#include <WinNtPeim.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Ppi/BaseMemoryTest.h>\r
+#include <Ppi/NtAutoscan.h>\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
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeWinNtAutoScan (\r
+ IN EFI_FFS_FILE_HEADER *FfsHeader,\r
+ IN EFI_PEI_SERVICES **PeiServices\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ Perform a call-back into the SEC simulator to get a memory value\r
+\r
+Arguments:\r
+ FfsHeader - General purpose data available to every PEIM\r
+ PeiServices - General purpose services available to every PEIM.\r
+ \r
+Returns:\r
+ None\r
+\r
+--*/\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;\r
+ 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
+\r
+\r
+ DEBUG ((EFI_D_ERROR, "NT 32 Autoscan PEIM Loaded\n"));\r
+\r
+ //\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
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ Index = 0;\r
+ do {\r
+ Status = PeiNtService->NtAutoScan (Index, &MemoryBase, &MemorySize);\r
+ if (!EFI_ERROR (Status)) {\r
+ Attributes =\r
+ (\r
+ EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
+ EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
+ EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
+ EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
+ EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
+ EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
+ );\r
+\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
+ //\r
+ Status = (**PeiServices).InstallPeiMemory (PeiServices, MemoryBase, MemorySize);\r
+ ASSERT_EFI_ERROR (Status);\r
+\r
+ Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;\r
+ }\r
+ \r
+ BuildResourceDescriptorHob (\r
+ EFI_RESOURCE_SYSTEM_MEMORY,\r
+ Attributes,\r
+ MemoryBase,\r
+ MemorySize\r
+ );\r
+ }\r
+ Index++;\r
+ } while (!EFI_ERROR (Status));\r
+\r
+ //\r
+ // Build the CPU hob with 36-bit addressing and 16-bits of IO space.\r
+ //\r
+ BuildCpuHob (36, 16);\r
+ \r
+ return Status;\r
+}\r