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