3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 This PEIM to abstract memory auto-scan in a Windows NT environment.
18 // The package level header files this module uses
21 #include <WinNtPeim.h>
23 // The protocols, PPI and GUID defintions for this module
25 #include <Ppi/NtAutoscan.h>
26 #include <Ppi/ReadOnlyVariable2.h>
28 #include <Guid/MemoryTypeInformation.h>
31 // The Library classes this module consumes
33 #include <Library/DebugLib.h>
34 #include <Library/PeimEntryPoint.h>
35 #include <Library/HobLib.h>
36 #include <Library/PeiServicesLib.h>
38 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation
[] = {
39 { EfiReservedMemoryType
, 0x0004 },
40 { EfiRuntimeServicesCode
, 0x0040 },
41 { EfiRuntimeServicesData
, 0x0040 },
42 { EfiBootServicesCode
, 0x0300 },
43 { EfiBootServicesData
, 0x1000 },
44 { EfiMaxMemoryType
, 0 }
48 Validate variable data for the MemoryTypeInformation.
50 @param MemoryData Variable data.
51 @param MemoryDataSize Variable data length.
53 @return TRUE The variable data is valid.
54 @return FALSE The variable data is invalid.
58 ValidateMemoryTypeInfoVariable (
59 IN EFI_MEMORY_TYPE_INFORMATION
*MemoryData
,
60 IN UINTN MemoryDataSize
66 // Check the input parameter.
67 if (MemoryData
== NULL
) {
72 Count
= MemoryDataSize
/ sizeof (*MemoryData
);
75 if (Count
* sizeof(*MemoryData
) != MemoryDataSize
) {
79 // Check last entry type filed.
80 if (MemoryData
[Count
- 1].Type
!= EfiMaxMemoryType
) {
84 // Check the type filed.
85 for (Index
= 0; Index
< Count
- 1; Index
++) {
86 if (MemoryData
[Index
].Type
>= EfiMaxMemoryType
) {
96 PeimInitializeWinNtAutoScan (
97 IN EFI_PEI_FILE_HANDLE FileHandle
,
98 IN CONST EFI_PEI_SERVICES
**PeiServices
103 Perform a call-back into the SEC simulator to get a memory value
106 FfsHeader - General purpose data available to every PEIM
107 PeiServices - General purpose services available to every PEIM.
115 EFI_PEI_PPI_DESCRIPTOR
*PpiDescriptor
;
116 PEI_NT_AUTOSCAN_PPI
*PeiNtService
;
118 EFI_PHYSICAL_ADDRESS MemoryBase
;
120 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes
;
121 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*Variable
;
123 EFI_MEMORY_TYPE_INFORMATION MemoryData
[EfiMaxMemoryType
+ 1];
126 DEBUG ((EFI_D_ERROR
, "NT 32 Autoscan PEIM Loaded\n"));
129 // Get the PEI NT Autoscan PPI
131 Status
= PeiServicesLocatePpi (
132 &gPeiNtAutoScanPpiGuid
, // GUID
134 &PpiDescriptor
, // EFI_PEI_PPI_DESCRIPTOR
135 (VOID
**)&PeiNtService
// PPI
137 ASSERT_EFI_ERROR (Status
);
141 Status
= PeiNtService
->NtAutoScan (Index
, &MemoryBase
, &MemorySize
);
142 if (!EFI_ERROR (Status
)) {
145 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
146 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
147 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
148 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
149 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
150 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
155 // Register the memory with the PEI Core
157 Status
= PeiServicesInstallPeiMemory (MemoryBase
, MemorySize
);
158 ASSERT_EFI_ERROR (Status
);
160 Attributes
|= EFI_RESOURCE_ATTRIBUTE_TESTED
;
163 BuildResourceDescriptorHob (
164 EFI_RESOURCE_SYSTEM_MEMORY
,
171 } while (!EFI_ERROR (Status
));
174 // Build the CPU hob with 52-bit addressing and 16-bits of IO space.
176 BuildCpuHob (52, 16);
179 // Build GUIDed Hob that contains the Memory Type Information array
181 Status
= PeiServicesLocatePpi (
182 &gEfiPeiReadOnlyVariable2PpiGuid
,
187 ASSERT_EFI_ERROR (Status
);
189 DataSize
= sizeof (MemoryData
);
190 Status
= Variable
->GetVariable (
192 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME
,
193 &gEfiMemoryTypeInformationGuid
,
198 if (EFI_ERROR (Status
) || !ValidateMemoryTypeInfoVariable(MemoryData
, DataSize
)) {
200 // Create Memory Type Information HOB
203 &gEfiMemoryTypeInformationGuid
,
204 mDefaultMemoryTypeInformation
,
205 sizeof(mDefaultMemoryTypeInformation
)
209 // Create Memory Type Information HOB
212 &gEfiMemoryTypeInformationGuid
,