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