Skip to content

Commit 11bb18a

Browse files
authored
Add resource descriptor hob v2 for memory attributes usage (#1258)
## Description 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? ## How This Was Tested This change was tested on QEMU Q35 and SBSA systems and booted to Windows. ## Integration Instructions 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).
1 parent cd3334a commit 11bb18a

File tree

11 files changed

+355
-27
lines changed

11 files changed

+355
-27
lines changed

MdeModulePkg/Core/Dxe/Gcd/Gcd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,7 +2350,7 @@ CoreInitializeMemoryServices (
23502350
//
23512351
Count = 0;
23522352
for (Hob.Raw = *HobStart; !END_OF_HOB_LIST (Hob); Hob.Raw = GET_NEXT_HOB (Hob)) {
2353-
if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
2353+
if ((GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) && (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2)) {
23542354
continue;
23552355
}
23562356

@@ -2392,7 +2392,7 @@ CoreInitializeMemoryServices (
23922392
//
23932393
// Skip all HOBs except Resource Descriptor HOBs
23942394
//
2395-
if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
2395+
if ((GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) && (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2)) {
23962396
continue;
23972397
}
23982398

@@ -2500,7 +2500,7 @@ CoreInitializeMemoryServices (
25002500
//
25012501
// Skip all HOBs except Resource Descriptor HOBs
25022502
//
2503-
if (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
2503+
if ((GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) && (GET_HOB_TYPE (Hob) != EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2)) {
25042504
continue;
25052505
}
25062506

@@ -2698,7 +2698,7 @@ CoreInitializeGcdServices (
26982698
GcdMemoryType = EfiGcdMemoryTypeNonExistent;
26992699
GcdIoType = EfiGcdIoTypeNonExistent;
27002700

2701-
if (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) {
2701+
if ((GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR) || (GET_HOB_TYPE (Hob) == EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2)) {
27022702
ResourceHob = Hob.ResourceDescriptor;
27032703

27042704
switch (ResourceHob->ResourceType) {

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.
@@ -332,6 +333,25 @@ typedef struct {
332333
UINT64 ResourceLength;
333334
} EFI_HOB_RESOURCE_DESCRIPTOR;
334335

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

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

MdePkg/Library/PeiHobLib/HobLib.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
77
**/
88

99
#include <PiPei.h>
10+
#include <Uefi/UefiSpec.h>
1011

1112
#include <Guid/MemoryAllocationHob.h>
1213

@@ -342,6 +343,58 @@ BuildResourceDescriptorWithOwnerHob (
342343
CopyGuid (&Hob->Owner, OwnerGUID);
343344
}
344345

346+
// MU_CHANGE Start: Add BuildResourceDescriptorV2 function
347+
348+
/**
349+
Builds a HOB that describes a chunk of system memory with memory attributes.
350+
351+
This function builds a HOB that describes a chunk of system memory.
352+
It can only be invoked during PEI phase;
353+
for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.
354+
355+
If there is no additional space for HOB creation, then ASSERT().
356+
357+
@param ResourceType The type of resource described by this HOB.
358+
@param ResourceAttribute The resource attributes of the memory described by this HOB.
359+
@param PhysicalStart The 64 bit physical address of memory described by this HOB.
360+
@param NumberOfBytes The length of the memory described by this HOB in bytes.
361+
@param EfiMemoryAttributes The memory attribute for the memory described by this HOB.
362+
@param OwnerGUID GUID for the owner of this resource.
363+
364+
**/
365+
VOID
366+
EFIAPI
367+
BuildResourceDescriptorV2 (
368+
IN EFI_RESOURCE_TYPE ResourceType,
369+
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
370+
IN EFI_PHYSICAL_ADDRESS PhysicalStart,
371+
IN UINT64 NumberOfBytes,
372+
IN UINT64 EfiMemoryAttributes,
373+
IN EFI_GUID *OwnerGUID OPTIONAL
374+
)
375+
{
376+
EFI_HOB_RESOURCE_DESCRIPTOR_V2 *Hob;
377+
378+
Hob = InternalPeiCreateHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR2, (UINT16)sizeof (EFI_HOB_RESOURCE_DESCRIPTOR_V2));
379+
if (Hob == NULL) {
380+
return;
381+
}
382+
383+
Hob->V1.ResourceType = ResourceType;
384+
Hob->V1.ResourceAttribute = ResourceAttribute;
385+
Hob->V1.PhysicalStart = PhysicalStart;
386+
Hob->V1.ResourceLength = NumberOfBytes;
387+
Hob->Attributes = EfiMemoryAttributes;
388+
389+
if (OwnerGUID != NULL) {
390+
CopyGuid (&Hob->V1.Owner, OwnerGUID);
391+
} else {
392+
ZeroMem (&(Hob->V1.Owner), sizeof (EFI_GUID));
393+
}
394+
}
395+
396+
// MU_CHANGE End
397+
345398
/**
346399
Builds a HOB that describes a chunk of system memory.
347400

0 commit comments

Comments
 (0)