TianoCore EDK2 master
Loading...
Searching...
No Matches
HobParseLib.c
Go to the documentation of this file.
1
6#include <PiPei.h>
7#include <Library/BaseLib.h>
10#include <Library/DebugLib.h>
11#include <Library/HobLib.h>
12#include <Library/PcdLib.h>
14#include <Library/IoLib.h>
15#include <Library/CpuLib.h>
22
23#define MEMORY_ATTRIBUTE_MASK (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
24 EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
25 EFI_RESOURCE_ATTRIBUTE_TESTED | \
26 EFI_RESOURCE_ATTRIBUTE_READ_PROTECTED | \
27 EFI_RESOURCE_ATTRIBUTE_WRITE_PROTECTED | \
28 EFI_RESOURCE_ATTRIBUTE_EXECUTION_PROTECTED | \
29 EFI_RESOURCE_ATTRIBUTE_READ_ONLY_PROTECTED | \
30 EFI_RESOURCE_ATTRIBUTE_16_BIT_IO | \
31 EFI_RESOURCE_ATTRIBUTE_32_BIT_IO | \
32 EFI_RESOURCE_ATTRIBUTE_64_BIT_IO | \
33 EFI_RESOURCE_ATTRIBUTE_PERSISTENT )
34
35#define TESTED_MEMORY_ATTRIBUTES (EFI_RESOURCE_ATTRIBUTE_PRESENT | \
36 EFI_RESOURCE_ATTRIBUTE_INITIALIZED | \
37 EFI_RESOURCE_ATTRIBUTE_TESTED )
38
39extern VOID *mHobList;
40
51VOID *
52EFIAPI
54 IN UINT16 HobType,
55 IN UINT16 HobLength
56 );
57
74EFIAPI
76 IN VOID *EfiMemoryBottom,
77 IN VOID *EfiMemoryTop,
78 IN VOID *EfiFreeMemoryBottom,
79 IN VOID *EfiFreeMemoryTop
80 );
81
91 IN UINT64 AcpiTableBase
92 );
93
100VOID
103 )
104{
106
107 if (Hob->Raw == NULL) {
108 return;
109 }
110
111 NewHob.Header = CreateHob (Hob->Header->HobType, Hob->Header->HobLength);
112
113 if (NewHob.Header != NULL) {
114 CopyMem (NewHob.Header + 1, Hob->Header + 1, Hob->Header->HobLength - sizeof (EFI_HOB_GENERIC_HEADER));
115 }
116}
117
129 IN VOID *HobList,
132 )
133{
135 EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
136
137 for (Hob.Raw = (UINT8 *)HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
138 //
139 // Skip all HOBs except Resource Descriptor HOBs
140 //
141 if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
142 continue;
143 }
144
145 //
146 // Skip Resource Descriptor HOBs that do not describe tested system memory
147 //
148 ResourceHob = Hob.ResourceDescriptor;
149 if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) {
150 continue;
151 }
152
153 if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) {
154 continue;
155 }
156
157 //
158 // Skip Resource Descriptor HOBs that do not contain the PHIT range EfiFreeMemoryBottom..EfiFreeMemoryTop
159 //
160 if (Base < ResourceHob->PhysicalStart) {
161 continue;
162 }
163
164 if (Top > (ResourceHob->PhysicalStart + ResourceHob->ResourceLength)) {
165 continue;
166 }
167
168 return ResourceHob;
169 }
170
171 return NULL;
172}
173
185 IN VOID *HobList,
186 IN UINTN MinimalNeededSize,
187 IN EFI_HOB_RESOURCE_DESCRIPTOR *ExceptResourceHob
188 )
189{
191 EFI_HOB_RESOURCE_DESCRIPTOR *ResourceHob;
192 EFI_HOB_RESOURCE_DESCRIPTOR *ReturnResourceHob;
193
194 ReturnResourceHob = NULL;
195
196 for (Hob.Raw = (UINT8 *)HobList; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
197 //
198 // Skip all HOBs except Resource Descriptor HOBs
199 //
200 if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
201 continue;
202 }
203
204 //
205 // Skip Resource Descriptor HOBs that do not describe tested system memory
206 //
207 ResourceHob = Hob.ResourceDescriptor;
208 if (ResourceHob->ResourceType != EFI_RESOURCE_SYSTEM_MEMORY) {
209 continue;
210 }
211
212 if ((ResourceHob->ResourceAttribute & MEMORY_ATTRIBUTE_MASK) != TESTED_MEMORY_ATTRIBUTES) {
213 continue;
214 }
215
216 //
217 // Skip if the Resource Descriptor HOB equals to ExceptResourceHob
218 //
219 if (ResourceHob == ExceptResourceHob) {
220 continue;
221 }
222
223 //
224 // Skip Resource Descriptor HOBs that are beyond 4G
225 //
226 if ((ResourceHob->PhysicalStart + ResourceHob->ResourceLength) > BASE_4GB) {
227 continue;
228 }
229
230 //
231 // Skip Resource Descriptor HOBs that are too small
232 //
233 if (ResourceHob->ResourceLength < MinimalNeededSize) {
234 continue;
235 }
236
237 //
238 // Return the topest Resource Descriptor
239 //
240 if (ReturnResourceHob == NULL) {
241 ReturnResourceHob = ResourceHob;
242 } else {
243 if (ReturnResourceHob->PhysicalStart < ResourceHob->PhysicalStart) {
244 ReturnResourceHob = ResourceHob;
245 }
246 }
247 }
248
249 return ReturnResourceHob;
250}
251
263BOOLEAN
266 )
267{
268 if (Hob.Header->HobType == EFI_HOB_TYPE_HANDOFF) {
269 return FALSE;
270 }
271
272 if (Hob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION) {
273 if (CompareGuid (&Hob.MemoryAllocationModule->MemoryAllocationHeader.Name, &gEfiHobMemoryAllocModuleGuid)) {
274 return FALSE;
275 }
276 }
277
278 // Arrive here mean the HOB is need
279 return TRUE;
280}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
Definition: MemLibGuid.c:73
ACPI_BOARD_INFO * BuildHobFromAcpi(IN UINT64 AcpiTableBase)
Definition: AcpiTable.c:139
VOID *EFIAPI CreateHob(IN UINT16 HobType, IN UINT16 HobLength)
Definition: Hob.c:101
VOID AddNewHob(IN EFI_PEI_HOB_POINTERS *Hob)
Definition: HobParseLib.c:101
EFI_HOB_HANDOFF_INFO_TABLE *EFIAPI HobConstructor(IN VOID *EfiMemoryBottom, IN VOID *EfiMemoryTop, IN VOID *EfiFreeMemoryBottom, IN VOID *EfiFreeMemoryTop)
Definition: Hob.c:54
EFI_HOB_RESOURCE_DESCRIPTOR * FindResourceDescriptorByRange(IN VOID *HobList, IN EFI_PHYSICAL_ADDRESS Base, IN EFI_PHYSICAL_ADDRESS Top)
Definition: HobParseLib.c:128
BOOLEAN IsHobNeed(EFI_PEI_HOB_POINTERS Hob)
Definition: HobParseLib.c:264
EFI_HOB_RESOURCE_DESCRIPTOR * FindAnotherHighestBelow4GResourceDescriptor(IN VOID *HobList, IN UINTN MinimalNeededSize, IN EFI_HOB_RESOURCE_DESCRIPTOR *ExceptResourceHob)
Definition: HobParseLib.c:184
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
EFI_HOB_MEMORY_ALLOCATION_HEADER MemoryAllocationHeader
Definition: PiHob.h:207
EFI_PHYSICAL_ADDRESS PhysicalStart
Definition: PiHob.h:328
EFI_RESOURCE_TYPE ResourceType
Definition: PiHob.h:320
EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute
Definition: PiHob.h:324