Skip to content

Commit 0d97d4a

Browse files
kuqin12os-d
authored andcommitted
[CHERRY-PICK] Add resource descriptor hob v2 for memory attributes usage (#1258)
This change adds the implementation of supporting "resource descriptor hob type 2", which will extends the existing definition of resource descriptor hob with an attribute field. This field can be used to provide the actual attributes needs to be set for the memory region, instead of relying on the state of the system. - [x] Impacts functionality? - [ ] Impacts security? - [ ] Breaking change? - [ ] Includes tests? - [ ] Includes documentation? - [ ] Backport to release branch? This change was tested on QEMU Q35 and SBSA systems and booted to Windows. For platforms needing to propagate specific memory attributes (especially the cache attributes) to the DXE phase, `BuildResourceDescriptorWithCacheHob` should be used to produce resource descriptors (v2). (cherry picked from commit 221fa7a)
1 parent 7e97ce0 commit 0d97d4a

13 files changed

Lines changed: 360 additions & 33 deletions

File tree

MdeModulePkg/Core/Dxe/Gcd/Gcd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,7 +2326,7 @@ CoreInitializeMemoryServices (
23262326
//
23272327
// Skip all HOBs except Resource Descriptor HOBs
23282328
//
2329-
if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
2329+
if ((GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) && (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2)) {
23302330
continue;
23312331
}
23322332

@@ -2444,7 +2444,7 @@ CoreInitializeMemoryServices (
24442444
//
24452445
// Skip all HOBs except Resource Descriptor HOBs
24462446
//
2447-
if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
2447+
if ((GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) && (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2)) {
24482448
continue;
24492449
}
24502450

@@ -2647,7 +2647,7 @@ CoreInitializeGcdServices (
26472647
GcdMemoryType = EfiGcdMemoryTypeNonExistent;
26482648
GcdIoType = EfiGcdIoTypeNonExistent;
26492649

2650-
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
2650+
if ((GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) || (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2)) {
26512651
ResourceHob = Hob.ResourceDescriptor;
26522652

26532653
switch (ResourceHob->ResourceType) {

MdeModulePkg/Core/Dxe/Mem/MemoryBin.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ GetMemoryTypeInformationResourceHob (
233233
MemoryTypeInformationResourceHob = NULL;
234234
Count = 0;
235235
for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
236-
if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
236+
// MU_CHANGE START: Add support for EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2
237+
if ((GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) && (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2)) {
238+
// MU_CHANGE END: Add support for EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2
237239
continue;
238240
}
239241

MdeModulePkg/Core/Pei/Memory/MemoryBin.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,9 @@ GetMemoryTypeInformationResourceHob (
233233
MemoryTypeInformationResourceHob = NULL;
234234
Count = 0;
235235
for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
236-
if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
237-
continue;
238-
}
239-
240-
ResourceHob = Hob.ResourceDescriptor;
241-
if (!CompareGuid (&ResourceHob->Owner, &gEfiMemoryTypeInformationGuid)) {
236+
// MU_CHANGE START: Add support for EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2
237+
if ((GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) && (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2)) {
238+
// MU_CHANGE END: Add support for EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2
242239
continue;
243240
}
244241

MdeModulePkg/Library/BaseHobLibNull/BaseHobLibNull.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,38 @@ BuildResourceDescriptorWithOwnerHob (
231231
ASSERT (FALSE);
232232
}
233233

234+
// MU_CHANGE Start: Add BuildResourceDescriptorV2 function
235+
236+
/**
237+
Builds a HOB that describes a chunk of system memory with memory attributes.
238+
239+
This function builds a HOB that describes a chunk of system memory.
240+
If there is no additional space for HOB creation, then ASSERT().
241+
242+
@param ResourceType The type of resource described by this HOB.
243+
@param ResourceAttribute The resource attributes of the memory described by this HOB.
244+
@param PhysicalStart The 64 bit physical address of memory described by this HOB.
245+
@param NumberOfBytes The length of the memory described by this HOB in bytes.
246+
@param EfiMemoryAttributes The memory attribute for the memory described by this HOB.
247+
@param OwnerGUID GUID for the owner of this resource.
248+
249+
**/
250+
VOID
251+
EFIAPI
252+
BuildResourceDescriptorV2 (
253+
IN EFI_RESOURCE_TYPE ResourceType,
254+
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
255+
IN EFI_PHYSICAL_ADDRESS PhysicalStart,
256+
IN UINT64 NumberOfBytes,
257+
IN UINT64 EfiMemoryAttributes,
258+
IN EFI_GUID *OwnerGUID OPTIONAL
259+
)
260+
{
261+
ASSERT (FALSE);
262+
}
263+
264+
// MU_CHANGE End
265+
234266
/**
235267
Builds a HOB that describes a chunk of system memory.
236268

MdeModulePkg/Library/HobPrintLib/HobPrintLib.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,35 @@ PrintResourceDiscriptorHob (
214214
return EFI_SUCCESS;
215215
}
216216

217+
/**
218+
Print the information in Resource Discriptor Hob.
219+
@param[in] HobStart A pointer to HOB of type EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2.
220+
@param[in] HobLength The Length in bytes of HOB of type EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2.
221+
@retval EFI_SUCCESS If it completed successfully.
222+
**/
223+
EFI_STATUS
224+
PrintResourceDiscriptor2Hob (
225+
IN VOID *HobStart,
226+
IN UINT16 HobLength
227+
)
228+
{
229+
EFI_PEI_HOB_POINTERS Hob;
230+
231+
Hob.Raw = (UINT8 *)HobStart;
232+
ASSERT (HobLength >= sizeof (*Hob.ResourceDescriptorV2));
233+
234+
DEBUG ((DEBUG_INFO, " ResourceType = %a\n", mResource_Type_List[Hob.ResourceDescriptorV2->V1.ResourceType]));
235+
if (!IsZeroGuid (&Hob.ResourceDescriptorV2->V1.Owner)) {
236+
DEBUG ((DEBUG_INFO, " Owner = %g\n", &Hob.ResourceDescriptorV2->V1.Owner));
237+
}
238+
239+
DEBUG ((DEBUG_INFO, " ResourceAttribute = 0x%x\n", Hob.ResourceDescriptorV2->V1.ResourceAttribute));
240+
DEBUG ((DEBUG_INFO, " PhysicalStart = 0x%lx\n", Hob.ResourceDescriptorV2->V1.PhysicalStart));
241+
DEBUG ((DEBUG_INFO, " ResourceLength = 0x%lx\n", Hob.ResourceDescriptorV2->V1.ResourceLength));
242+
DEBUG ((DEBUG_INFO, " Attributes = 0x%x\n", Hob.ResourceDescriptorV2->Attributes));
243+
return EFI_SUCCESS;
244+
}
245+
217246
/**
218247
Print the Guid Hob using related print handle function.
219248
@param[in] HobStart A pointer to the HOB of type EFI_HOB_TYPE_GUID_EXTENSION.
@@ -386,16 +415,17 @@ PrintFv3Hob (
386415
// Mapping table from Hob type to Hob print function.
387416
//
388417
HOB_PRINT_HANDLER_TABLE mHobHandles[] = {
389-
{ EFI_HOB_TYPE_HANDOFF, "EFI_HOB_TYPE_HANDOFF", PrintHandOffHob },
390-
{ EFI_HOB_TYPE_MEMORY_ALLOCATION, "EFI_HOB_TYPE_MEMORY_ALLOCATION", PrintMemoryAllocationHob },
391-
{ EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, "EFI_HOB_TYPE_RESOURCE_DESCRIPTOR", PrintResourceDiscriptorHob },
392-
{ EFI_HOB_TYPE_GUID_EXTENSION, "EFI_HOB_TYPE_GUID_EXTENSION", PrintGuidHob },
393-
{ EFI_HOB_TYPE_FV, "EFI_HOB_TYPE_FV", PrintFvHob },
394-
{ EFI_HOB_TYPE_CPU, "EFI_HOB_TYPE_CPU", PrintCpuHob },
395-
{ EFI_HOB_TYPE_MEMORY_POOL, "EFI_HOB_TYPE_MEMORY_POOL", PrintMemoryPoolHob },
396-
{ EFI_HOB_TYPE_FV2, "EFI_HOB_TYPE_FV2", PrintFv2Hob },
397-
{ EFI_HOB_TYPE_UEFI_CAPSULE, "EFI_HOB_TYPE_UEFI_CAPSULE", PrintCapsuleHob },
398-
{ EFI_HOB_TYPE_FV3, "EFI_HOB_TYPE_FV3", PrintFv3Hob }
418+
{ EFI_HOB_TYPE_HANDOFF, "EFI_HOB_TYPE_HANDOFF", PrintHandOffHob },
419+
{ EFI_HOB_TYPE_MEMORY_ALLOCATION, "EFI_HOB_TYPE_MEMORY_ALLOCATION", PrintMemoryAllocationHob },
420+
{ EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, "EFI_HOB_TYPE_RESOURCE_DESCRIPTOR", PrintResourceDiscriptorHob },
421+
{ EFI_HOB_TYPE_GUID_EXTENSION, "EFI_HOB_TYPE_GUID_EXTENSION", PrintGuidHob },
422+
{ EFI_HOB_TYPE_FV, "EFI_HOB_TYPE_FV", PrintFvHob },
423+
{ EFI_HOB_TYPE_CPU, "EFI_HOB_TYPE_CPU", PrintCpuHob },
424+
{ EFI_HOB_TYPE_MEMORY_POOL, "EFI_HOB_TYPE_MEMORY_POOL", PrintMemoryPoolHob },
425+
{ EFI_HOB_TYPE_FV2, "EFI_HOB_TYPE_FV2", PrintFv2Hob },
426+
{ EFI_HOB_TYPE_UEFI_CAPSULE, "EFI_HOB_TYPE_UEFI_CAPSULE", PrintCapsuleHob },
427+
{ EFI_HOB_TYPE_FV3, "EFI_HOB_TYPE_FV3", PrintFv3Hob },
428+
{ EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2, "EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2", PrintResourceDiscriptor2Hob }
399429
};
400430

401431
/**

MdePkg/Include/Library/HobLib.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,38 @@ BuildResourceDescriptorWithOwnerHob (
204204
IN EFI_GUID *OwnerGUID
205205
);
206206

207+
// MU_CHANGE Start: Add BuildResourceDescriptorV2 function
208+
209+
/**
210+
Builds a HOB that describes a chunk of system memory with memory attributes.
211+
212+
This function builds a HOB that describes a chunk of system memory.
213+
It can only be invoked during PEI phase;
214+
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
215+
216+
If there is no additional space for HOB creation, then ASSERT().
217+
218+
@param ResourceType The type of resource described by this HOB.
219+
@param ResourceAttribute The resource attributes of the memory described by this HOB.
220+
@param PhysicalStart The 64 bit physical address of memory described by this HOB.
221+
@param NumberOfBytes The length of the memory described by this HOB in bytes.
222+
@param EfiMemoryAttributes The memory attribute for the memory described by this HOB.
223+
@param OwnerGUID GUID for the owner of this resource.
224+
225+
**/
226+
VOID
227+
EFIAPI
228+
BuildResourceDescriptorV2 (
229+
IN EFI_RESOURCE_TYPE ResourceType,
230+
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
231+
IN EFI_PHYSICAL_ADDRESS PhysicalStart,
232+
IN UINT64 NumberOfBytes,
233+
IN UINT64 EfiMemoryAttributes,
234+
IN EFI_GUID *OwnerGUID OPTIONAL
235+
);
236+
237+
// MU_CHANGE End
238+
207239
/**
208240
Builds a HOB that describes a chunk of system memory.
209241

MdePkg/Include/Pi/PiHob.h

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
1515
//
1616
// HobType of EFI_HOB_GENERIC_HEADER.
1717
//
18-
#define EFI_HOB_TYPE_HANDOFF 0x0001
19-
#define EFI_HOB_TYPE_MEMORY_ALLOCATION 0x0002
20-
#define EFI_HOB_TYPE_RESOURCE_DESCRIPTOR 0x0003
21-
#define EFI_HOB_TYPE_GUID_EXTENSION 0x0004
22-
#define EFI_HOB_TYPE_FV 0x0005
23-
#define EFI_HOB_TYPE_CPU 0x0006
24-
#define EFI_HOB_TYPE_MEMORY_POOL 0x0007
25-
#define EFI_HOB_TYPE_FV2 0x0009
26-
#define EFI_HOB_TYPE_LOAD_PEIM_UNUSED 0x000A
27-
#define EFI_HOB_TYPE_UEFI_CAPSULE 0x000B
28-
#define EFI_HOB_TYPE_FV3 0x000C
29-
#define EFI_HOB_TYPE_UNUSED 0xFFFE
30-
#define EFI_HOB_TYPE_END_OF_HOB_LIST 0xFFFF
18+
#define EFI_HOB_TYPE_HANDOFF 0x0001
19+
#define EFI_HOB_TYPE_MEMORY_ALLOCATION 0x0002
20+
#define EFI_HOB_TYPE_RESOURCE_DESCRIPTOR 0x0003
21+
#define EFI_HOB_TYPE_GUID_EXTENSION 0x0004
22+
#define EFI_HOB_TYPE_FV 0x0005
23+
#define EFI_HOB_TYPE_CPU 0x0006
24+
#define EFI_HOB_TYPE_MEMORY_POOL 0x0007
25+
#define EFI_HOB_TYPE_FV2 0x0009
26+
#define EFI_HOB_TYPE_LOAD_PEIM_UNUSED 0x000A
27+
#define EFI_HOB_TYPE_UEFI_CAPSULE 0x000B
28+
#define EFI_HOB_TYPE_FV3 0x000C
29+
#define EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2 0x000D
30+
#define EFI_HOB_TYPE_UNUSED 0xFFFE
31+
#define EFI_HOB_TYPE_END_OF_HOB_LIST 0xFFFF
3132

3233
///
3334
/// Describes the format and size of the data inside the HOB.
@@ -333,6 +334,25 @@ typedef struct {
333334
UINT64 ResourceLength;
334335
} EFI_HOB_RESOURCE_DESCRIPTOR;
335336

337+
/// PI Spec Status: Pending.
338+
/// This change is checked in as a code first approach. The PI spec will be updated
339+
/// to reflect this change in the future.
340+
///
341+
/// Describes the resource properties and memory attributes
342+
/// of all fixed, nonrelocatable resource ranges found on the
343+
/// processor host bus during the HOB producer phase.
344+
///
345+
typedef struct {
346+
///
347+
/// The HOB generic header. Header.HobType = EFI_HOB_TYPE_RESOURCE_DESCRIPTOR.
348+
///
349+
EFI_HOB_RESOURCE_DESCRIPTOR V1;
350+
///
351+
/// The memory attributes (paging and caching) of the resource region.
352+
///
353+
UINT64 Attributes;
354+
} EFI_HOB_RESOURCE_DESCRIPTOR_V2;
355+
336356
///
337357
/// Allows writers of executable content in the HOB producer phase to
338358
/// maintain and manage HOBs with specific GUID.
@@ -506,6 +526,7 @@ typedef union {
506526
EFI_HOB_CPU *Cpu;
507527
EFI_HOB_MEMORY_POOL *Pool;
508528
EFI_HOB_UEFI_CAPSULE *Capsule;
529+
EFI_HOB_RESOURCE_DESCRIPTOR_V2 *ResourceDescriptorV2;
509530
UINT8 *Raw;
510531
} EFI_PEI_HOB_POINTERS;
511532

MdePkg/Library/DxeCoreHobLib/HobLib.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,38 @@ BuildResourceDescriptorWithOwnerHob (
269269
ASSERT (FALSE);
270270
}
271271

272+
// MU_CHANGE Start: Add BuildResourceDescriptorV2 function
273+
274+
/**
275+
Builds a HOB that describes a chunk of system memory with memory attributes.
276+
277+
This function builds a HOB that describes a chunk of system memory.
278+
If there is no additional space for HOB creation, then ASSERT().
279+
280+
@param ResourceType The type of resource described by this HOB.
281+
@param ResourceAttribute The resource attributes of the memory described by this HOB.
282+
@param PhysicalStart The 64 bit physical address of memory described by this HOB.
283+
@param NumberOfBytes The length of the memory described by this HOB in bytes.
284+
@param EfiMemoryAttributes The memory attribute for the memory described by this HOB.
285+
@param OwnerGUID GUID for the owner of this resource.
286+
287+
**/
288+
VOID
289+
EFIAPI
290+
BuildResourceDescriptorV2 (
291+
IN EFI_RESOURCE_TYPE ResourceType,
292+
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
293+
IN EFI_PHYSICAL_ADDRESS PhysicalStart,
294+
IN UINT64 NumberOfBytes,
295+
IN UINT64 EfiMemoryAttributes,
296+
IN EFI_GUID *OwnerGUID OPTIONAL
297+
)
298+
{
299+
ASSERT (FALSE);
300+
}
301+
302+
// MU_CHANGE End
303+
272304
/**
273305
Builds a HOB that describes a chunk of system memory.
274306

MdePkg/Library/DxeHobLib/HobLib.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,38 @@ BuildResourceDescriptorWithOwnerHob (
304304
ASSERT (FALSE);
305305
}
306306

307+
// MU_CHANGE Start: Add BuildResourceDescriptorV2 function
308+
309+
/**
310+
Builds a HOB that describes a chunk of system memory with memory attributes.
311+
312+
This function builds a HOB that describes a chunk of system memory.
313+
If there is no additional space for HOB creation, then ASSERT().
314+
315+
@param ResourceType The type of resource described by this HOB.
316+
@param ResourceAttribute The resource attributes of the memory described by this HOB.
317+
@param PhysicalStart The 64 bit physical address of memory described by this HOB.
318+
@param NumberOfBytes The length of the memory described by this HOB in bytes.
319+
@param EfiMemoryAttributes The memory attribute for the memory described by this HOB.
320+
@param OwnerGUID GUID for the owner of this resource.
321+
322+
**/
323+
VOID
324+
EFIAPI
325+
BuildResourceDescriptorV2 (
326+
IN EFI_RESOURCE_TYPE ResourceType,
327+
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
328+
IN EFI_PHYSICAL_ADDRESS PhysicalStart,
329+
IN UINT64 NumberOfBytes,
330+
IN UINT64 EfiMemoryAttributes,
331+
IN EFI_GUID *OwnerGUID OPTIONAL
332+
)
333+
{
334+
ASSERT (FALSE);
335+
}
336+
337+
// MU_CHANGE End
338+
307339
/**
308340
Builds a HOB that describes a chunk of system memory.
309341

0 commit comments

Comments
 (0)