3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 This PEIM to abstract memory auto-scan in a Windows NT environment.
24 // The package level header files this module uses
27 #include <WinNtPeim.h>
29 // The protocols, PPI and GUID defintions for this module
31 #include <Ppi/NtAutoscan.h>
32 #include <Ppi/ReadOnlyVariable2.h>
34 #include <Guid/MemoryTypeInformation.h>
37 // The Library classes this module consumes
39 #include <Library/DebugLib.h>
40 #include <Library/PeimEntryPoint.h>
41 #include <Library/HobLib.h>
42 #include <Library/PeiServicesLib.h>
44 EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation
[] = {
45 { EfiReservedMemoryType
, 0x0004 },
46 { EfiRuntimeServicesCode
, 0x0040 },
47 { EfiRuntimeServicesData
, 0x0040 },
48 { EfiBootServicesCode
, 0x0300 },
49 { EfiBootServicesData
, 0x1000 },
50 { EfiMaxMemoryType
, 0 }
54 Validate variable data for the MemoryTypeInformation.
56 @param MemoryData Variable data.
57 @param MemoryDataSize Variable data length.
59 @return TRUE The variable data is valid.
60 @return FALSE The variable data is invalid.
64 ValidateMemoryTypeInfoVariable (
65 IN EFI_MEMORY_TYPE_INFORMATION
*MemoryData
,
66 IN UINTN MemoryDataSize
72 // Check the input parameter.
73 if (MemoryData
== NULL
) {
78 Count
= MemoryDataSize
/ sizeof (*MemoryData
);
81 if (Count
* sizeof(*MemoryData
) != MemoryDataSize
) {
85 // Check last entry type filed.
86 if (MemoryData
[Count
- 1].Type
!= EfiMaxMemoryType
) {
90 // Check the type filed.
91 for (Index
= 0; Index
< Count
- 1; Index
++) {
92 if (MemoryData
[Index
].Type
>= EfiMaxMemoryType
) {
102 PeimInitializeWinNtAutoScan (
103 IN EFI_PEI_FILE_HANDLE FileHandle
,
104 IN CONST EFI_PEI_SERVICES
**PeiServices
109 Perform a call-back into the SEC simulator to get a memory value
112 FfsHeader - General purpose data available to every PEIM
113 PeiServices - General purpose services available to every PEIM.
121 EFI_PEI_PPI_DESCRIPTOR
*PpiDescriptor
;
122 PEI_NT_AUTOSCAN_PPI
*PeiNtService
;
124 EFI_PHYSICAL_ADDRESS MemoryBase
;
126 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes
;
127 EFI_PEI_READ_ONLY_VARIABLE2_PPI
*Variable
;
129 EFI_MEMORY_TYPE_INFORMATION MemoryData
[EfiMaxMemoryType
+ 1];
132 DEBUG ((EFI_D_ERROR
, "NT 32 Autoscan PEIM Loaded\n"));
135 // Get the PEI NT Autoscan PPI
137 Status
= PeiServicesLocatePpi (
138 &gPeiNtAutoScanPpiGuid
, // GUID
140 &PpiDescriptor
, // EFI_PEI_PPI_DESCRIPTOR
141 (VOID
**)&PeiNtService
// PPI
143 ASSERT_EFI_ERROR (Status
);
147 Status
= PeiNtService
->NtAutoScan (Index
, &MemoryBase
, &MemorySize
);
148 if (!EFI_ERROR (Status
)) {
151 EFI_RESOURCE_ATTRIBUTE_PRESENT
|
152 EFI_RESOURCE_ATTRIBUTE_INITIALIZED
|
153 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE
|
154 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE
|
155 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE
|
156 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
161 // Register the memory with the PEI Core
163 Status
= PeiServicesInstallPeiMemory (MemoryBase
, MemorySize
);
164 ASSERT_EFI_ERROR (Status
);
166 Attributes
|= EFI_RESOURCE_ATTRIBUTE_TESTED
;
169 BuildResourceDescriptorHob (
170 EFI_RESOURCE_SYSTEM_MEMORY
,
177 } while (!EFI_ERROR (Status
));
180 // Build the CPU hob with 52-bit addressing and 16-bits of IO space.
182 BuildCpuHob (52, 16);
185 // Build GUIDed Hob that contains the Memory Type Information array
187 Status
= PeiServicesLocatePpi (
188 &gEfiPeiReadOnlyVariable2PpiGuid
,
193 ASSERT_EFI_ERROR (Status
);
195 DataSize
= sizeof (MemoryData
);
196 Status
= Variable
->GetVariable (
198 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME
,
199 &gEfiMemoryTypeInformationGuid
,
204 if (EFI_ERROR (Status
) || !ValidateMemoryTypeInfoVariable(MemoryData
, DataSize
)) {
206 // Create Memory Type Information HOB
209 &gEfiMemoryTypeInformationGuid
,
210 mDefaultMemoryTypeInformation
,
211 sizeof(mDefaultMemoryTypeInformation
)
215 // Create Memory Type Information HOB
218 &gEfiMemoryTypeInformationGuid
,