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 }
53 Validate variable data for the MemoryTypeInformation.
55 @param MemoryData Variable data.
56 @param MemoryDataSize Variable data length.
58 @return TRUE The variable data is valid.
59 @return FALSE The variable data is invalid.
63 ValidateMemoryTypeInfoVariable (
64 IN EFI_MEMORY_TYPE_INFORMATION
*MemoryData
,
65 IN UINTN MemoryDataSize
71 // Check the input parameter.
72 if (MemoryData
== NULL
) {
77 Count
= MemoryDataSize
/ sizeof (*MemoryData
);
80 if (Count
* sizeof(*MemoryData
) != MemoryDataSize
) {
84 // Check last entry type filed.
85 if (MemoryData
[Count
- 1].Type
!= EfiMaxMemoryType
) {
89 // Check the type filed.
90 for (Index
= 0; Index
< Count
- 1; Index
++) {
91 if (MemoryData
[Index
].Type
>= EfiMaxMemoryType
) {
101 PeimInitializeWinNtAutoScan (
102 IN EFI_PEI_FILE_HANDLE FileHandle
,
103 IN CONST EFI_PEI_SERVICES
**PeiServices
108 Perform a call-back into the SEC simulator to get a memory value
111 FfsHeader - General purpose data available to every PEIM
112 PeiServices - General purpose services available to every PEIM.
120 EFI_PEI_PPI_DESCRIPTOR
*PpiDescriptor
;
121 PEI_NT_AUTOSCAN_PPI
*PeiNtService
;
123 EFI_PHYSICAL_ADDRESS MemoryBase
;
125 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes
;
126 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*Variable
;
128 EFI_MEMORY_TYPE_INFORMATION MemoryData
[EfiMaxMemoryType
+ 1];
131 DEBUG ((EFI_D_ERROR
, "NT 32 Autoscan PEIM Loaded\n"));
134 // Get the PEI NT Autoscan PPI
136 Status
= PeiServicesLocatePpi (
137 &gPeiNtAutoScanPpiGuid
, // GUID
139 &PpiDescriptor
, // EFI_PEI_PPI_DESCRIPTOR
140 (VOID
**)&PeiNtService
// PPI
142 ASSERT_EFI_ERROR (Status
);
146 Status
= PeiNtService
->NtAutoScan (Index
, &MemoryBase
, &MemorySize
);
147 if (!EFI_ERROR (Status
)) {
150 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
151 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
152 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
153 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
154 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
155 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
160 // Register the memory with the PEI Core
162 Status
= PeiServicesInstallPeiMemory (MemoryBase
, MemorySize
);
163 ASSERT_EFI_ERROR (Status
);
165 Attributes
|= EFI_RESOURCE_ATTRIBUTE_TESTED
;
168 BuildResourceDescriptorHob (
169 EFI_RESOURCE_SYSTEM_MEMORY
,
176 } while (!EFI_ERROR (Status
));
179 // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
181 BuildCpuHob (36, 16);
184 // Build GUIDed Hob that contains the Memory Type Information array
186 Status
= PeiServicesLocatePpi (
187 &gEfiPeiReadOnlyVariable2PpiGuid
,
192 ASSERT_EFI_ERROR (Status
);
194 DataSize
= sizeof (MemoryData
);
195 Status
= Variable
->GetVariable (
197 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME
,
198 &gEfiMemoryTypeInformationGuid
,
203 if (EFI_ERROR (Status
) || !ValidateMemoryTypeInfoVariable(MemoryData
, DataSize
)) {
205 // Create Memory Type Information HOB
208 &gEfiMemoryTypeInformationGuid
,
209 mDefaultMemoryTypeInformation
,
210 sizeof(mDefaultMemoryTypeInformation
)
214 // Create Memory Type Information HOB
217 &gEfiMemoryTypeInformationGuid
,