3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 This PEIM to abstract memory auto-scan in a Windows NT environment.
23 // The package level header files this module uses
26 #include <WinNtPeim.h>
28 // The protocols, PPI and GUID defintions for this module
30 #include <Ppi/NtAutoscan.h>
31 #include <Ppi/ReadOnlyVariable2.h>
33 #include <Guid/MemoryTypeInformation.h>
36 // The Library classes this module consumes
38 #include <Library/DebugLib.h>
39 #include <Library/PeimEntryPoint.h>
40 #include <Library/HobLib.h>
41 #include <Library/PeiServicesLib.h>
43 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation
[] = {
44 { EfiReservedMemoryType
, 0x0004 },
45 { EfiRuntimeServicesCode
, 0x0040 },
46 { EfiRuntimeServicesData
, 0x0040 },
47 { EfiBootServicesCode
, 0x0300 },
48 { EfiBootServicesData
, 0x1000 },
49 { EfiMaxMemoryType
, 0 }
54 PeimInitializeWinNtAutoScan (
55 IN EFI_PEI_FILE_HANDLE FileHandle
,
56 IN CONST EFI_PEI_SERVICES
**PeiServices
61 Perform a call-back into the SEC simulator to get a memory value
64 FfsHeader - General purpose data available to every PEIM
65 PeiServices - General purpose services available to every PEIM.
73 EFI_PEI_PPI_DESCRIPTOR
*PpiDescriptor
;
74 PEI_NT_AUTOSCAN_PPI
*PeiNtService
;
76 EFI_PHYSICAL_ADDRESS MemoryBase
;
78 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes
;
79 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*Variable
;
81 EFI_MEMORY_TYPE_INFORMATION MemoryData
[EfiMaxMemoryType
+ 1];
84 DEBUG ((EFI_D_ERROR
, "NT 32 Autoscan PEIM Loaded\n"));
87 // Get the PEI NT Autoscan PPI
89 Status
= PeiServicesLocatePpi (
90 &gPeiNtAutoScanPpiGuid
, // GUID
92 &PpiDescriptor
, // EFI_PEI_PPI_DESCRIPTOR
93 (VOID
**)&PeiNtService
// PPI
95 ASSERT_EFI_ERROR (Status
);
99 Status
= PeiNtService
->NtAutoScan (Index
, &MemoryBase
, &MemorySize
);
100 if (!EFI_ERROR (Status
)) {
103 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
104 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
105 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
106 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
107 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
108 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
113 // Register the memory with the PEI Core
115 Status
= PeiServicesInstallPeiMemory (MemoryBase
, MemorySize
);
116 ASSERT_EFI_ERROR (Status
);
118 Attributes
|= EFI_RESOURCE_ATTRIBUTE_TESTED
;
121 BuildResourceDescriptorHob (
122 EFI_RESOURCE_SYSTEM_MEMORY
,
129 } while (!EFI_ERROR (Status
));
132 // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
134 BuildCpuHob (36, 16);
137 // Build GUIDed Hob that contains the Memory Type Information array
139 Status
= PeiServicesLocatePpi (
140 &gEfiPeiReadOnlyVariable2PpiGuid
,
145 ASSERT_EFI_ERROR (Status
);
147 DataSize
= sizeof (MemoryData
);
148 Status
= Variable
->GetVariable (
150 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME
,
151 &gEfiMemoryTypeInformationGuid
,
156 if (EFI_ERROR (Status
)) {
158 // Create Memory Type Information HOB
161 &gEfiMemoryTypeInformationGuid
,
162 mDefaultMemoryTypeInformation
,
163 sizeof(mDefaultMemoryTypeInformation
)
167 // Create Memory Type Information HOB
170 &gEfiMemoryTypeInformationGuid
,