]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - Nt32Pkg/WinNtAutoScanPei/WinNtAutoScan.c
ArmPkg/Library: Add ArmReadSctlr for AArch64
[mirror_edk2.git] / Nt32Pkg / WinNtAutoScanPei / WinNtAutoScan.c
... / ...
CommitLineData
1/**@file\r
2\r
3Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
4(C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
5This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php \r
9 \r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13Module Name:\r
14 WinNtAutoscan.c\r
15\r
16Abstract:\r
17 This PEIM to abstract memory auto-scan in a Windows NT environment.\r
18\r
19Revision History\r
20\r
21**/\r
22\r
23//\r
24// The package level header files this module uses\r
25//\r
26#include <PiPei.h>\r
27#include <WinNtPeim.h>\r
28//\r
29// The protocols, PPI and GUID defintions for this module\r
30//\r
31#include <Ppi/NtAutoscan.h>\r
32#include <Ppi/ReadOnlyVariable2.h>\r
33\r
34#include <Guid/MemoryTypeInformation.h>\r
35\r
36//\r
37// The Library classes this module consumes\r
38//\r
39#include <Library/DebugLib.h>\r
40#include <Library/PeimEntryPoint.h>\r
41#include <Library/HobLib.h>\r
42#include <Library/PeiServicesLib.h>\r
43\r
44EFI_MEMORY_TYPE_INFORMATION mDefaultMemoryTypeInformation[] = {\r
45 { EfiReservedMemoryType, 0x0004 },\r
46 { EfiRuntimeServicesCode, 0x0040 },\r
47 { EfiRuntimeServicesData, 0x0040 },\r
48 { EfiBootServicesCode, 0x0300 },\r
49 { EfiBootServicesData, 0x1000 },\r
50 { EfiMaxMemoryType, 0 }\r
51};\r
52\r
53/**\r
54 Validate variable data for the MemoryTypeInformation. \r
55\r
56 @param MemoryData Variable data.\r
57 @param MemoryDataSize Variable data length.\r
58 \r
59 @return TRUE The variable data is valid.\r
60 @return FALSE The variable data is invalid.\r
61\r
62**/\r
63BOOLEAN\r
64ValidateMemoryTypeInfoVariable (\r
65 IN EFI_MEMORY_TYPE_INFORMATION *MemoryData,\r
66 IN UINTN MemoryDataSize\r
67 )\r
68{\r
69 UINTN Count;\r
70 UINTN Index;\r
71\r
72 // Check the input parameter.\r
73 if (MemoryData == NULL) {\r
74 return FALSE;\r
75 }\r
76\r
77 // Get Count\r
78 Count = MemoryDataSize / sizeof (*MemoryData);\r
79\r
80 // Check Size\r
81 if (Count * sizeof(*MemoryData) != MemoryDataSize) {\r
82 return FALSE;\r
83 }\r
84\r
85 // Check last entry type filed.\r
86 if (MemoryData[Count - 1].Type != EfiMaxMemoryType) {\r
87 return FALSE;\r
88 }\r
89\r
90 // Check the type filed.\r
91 for (Index = 0; Index < Count - 1; Index++) {\r
92 if (MemoryData[Index].Type >= EfiMaxMemoryType) {\r
93 return FALSE;\r
94 }\r
95 }\r
96\r
97 return TRUE;\r
98}\r
99\r
100EFI_STATUS\r
101EFIAPI\r
102PeimInitializeWinNtAutoScan (\r
103 IN EFI_PEI_FILE_HANDLE FileHandle,\r
104 IN CONST EFI_PEI_SERVICES **PeiServices\r
105 )\r
106/*++\r
107\r
108Routine Description:\r
109 Perform a call-back into the SEC simulator to get a memory value\r
110\r
111Arguments:\r
112 FfsHeader - General purpose data available to every PEIM\r
113 PeiServices - General purpose services available to every PEIM.\r
114 \r
115Returns:\r
116 None\r
117\r
118--*/\r
119{\r
120 EFI_STATUS Status;\r
121 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;\r
122 PEI_NT_AUTOSCAN_PPI *PeiNtService;\r
123 UINT64 MemorySize;\r
124 EFI_PHYSICAL_ADDRESS MemoryBase;\r
125 UINTN Index;\r
126 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;\r
127 EFI_PEI_READ_ONLY_VARIABLE2_PPI *Variable;\r
128 UINTN DataSize;\r
129 EFI_MEMORY_TYPE_INFORMATION MemoryData [EfiMaxMemoryType + 1];\r
130\r
131\r
132 DEBUG ((EFI_D_ERROR, "NT 32 Autoscan PEIM Loaded\n"));\r
133\r
134 //\r
135 // Get the PEI NT Autoscan PPI\r
136 //\r
137 Status = PeiServicesLocatePpi (\r
138 &gPeiNtAutoScanPpiGuid, // GUID\r
139 0, // INSTANCE\r
140 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
141 (VOID**)&PeiNtService // PPI\r
142 );\r
143 ASSERT_EFI_ERROR (Status);\r
144\r
145 Index = 0;\r
146 do {\r
147 Status = PeiNtService->NtAutoScan (Index, &MemoryBase, &MemorySize);\r
148 if (!EFI_ERROR (Status)) {\r
149 Attributes =\r
150 (\r
151 EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
152 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
153 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
154 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
155 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
156 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
157 );\r
158\r
159 if (Index == 0) {\r
160 //\r
161 // Register the memory with the PEI Core\r
162 //\r
163 Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize);\r
164 ASSERT_EFI_ERROR (Status);\r
165\r
166 Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;\r
167 }\r
168 \r
169 BuildResourceDescriptorHob (\r
170 EFI_RESOURCE_SYSTEM_MEMORY,\r
171 Attributes,\r
172 MemoryBase,\r
173 MemorySize\r
174 );\r
175 }\r
176 Index++;\r
177 } while (!EFI_ERROR (Status));\r
178\r
179 //\r
180 // Build the CPU hob with 52-bit addressing and 16-bits of IO space.\r
181 //\r
182 BuildCpuHob (52, 16);\r
183\r
184 //\r
185 // Build GUIDed Hob that contains the Memory Type Information array\r
186 //\r
187 Status = PeiServicesLocatePpi (\r
188 &gEfiPeiReadOnlyVariable2PpiGuid,\r
189 0,\r
190 NULL,\r
191 (VOID **)&Variable\r
192 );\r
193 ASSERT_EFI_ERROR (Status);\r
194\r
195 DataSize = sizeof (MemoryData);\r
196 Status = Variable->GetVariable (\r
197 Variable,\r
198 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
199 &gEfiMemoryTypeInformationGuid,\r
200 NULL,\r
201 &DataSize,\r
202 &MemoryData\r
203 );\r
204 if (EFI_ERROR (Status) || !ValidateMemoryTypeInfoVariable(MemoryData, DataSize)) {\r
205 //\r
206 // Create Memory Type Information HOB\r
207 //\r
208 BuildGuidDataHob (\r
209 &gEfiMemoryTypeInformationGuid,\r
210 mDefaultMemoryTypeInformation,\r
211 sizeof(mDefaultMemoryTypeInformation)\r
212 );\r
213 } else {\r
214 //\r
215 // Create Memory Type Information HOB\r
216 //\r
217 BuildGuidDataHob (\r
218 &gEfiMemoryTypeInformationGuid,\r
219 MemoryData,\r
220 DataSize\r
221 );\r
222 }\r
223\r
224 return Status;\r
225}\r