MemInfoCallbackMmio() classifies each Reserved memory-map entry by a heuristic: below mTopOfLowerUsableDram it is treated as reserved DRAM, above it as device MMIO. A bootloader that already knows a range is device MMIO has no way to say so and has to rely on the heuristic being right for its platform.
Add MEM_MAP_FLAG_MMIO, a bit in the existing and so far unused MEMORY_MAP_ENTRY.Flag byte, and honour it in MemInfoCallbackMmio() ahead of the heuristic. The flag is deliberately not a new MEMORY_MAP_ENTRY.Type value. That namespace mirrors the ACPI Address Range Types and is still growing, so taking the next free number for a private convention would collide with a future assignment. In the other direction, an older payload receiving such a Type would fall through to the heuristic and silently publish device MMIO as cacheable reserved DRAM. A Flag bit is additive in both directions: an older payload ignores it and keeps today's behaviour, and a bootloader that does not set it behaves exactly as before. Cc: Benjamin Doron <[email protected]> Cc: Gua Guo <[email protected]> Cc: Guo Dong <[email protected]> Cc: James Lu <[email protected]> Cc: Sean Rhodes <[email protected]> Cc: Shuo Liu <[email protected]> Assisted-by: claude-opus-5 Signed-off-by: Alexander Graf <[email protected]> --- UefiPayloadPkg/Include/Guid/MemoryMapInfoGuid.h | 11 +++++++++++ .../UefiPayloadEntry/UefiPayloadEntry.c | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/UefiPayloadPkg/Include/Guid/MemoryMapInfoGuid.h b/UefiPayloadPkg/Include/Guid/MemoryMapInfoGuid.h index 64ab60d665..03a77ba3d7 100644 --- a/UefiPayloadPkg/Include/Guid/MemoryMapInfoGuid.h +++ b/UefiPayloadPkg/Include/Guid/MemoryMapInfoGuid.h @@ -15,6 +15,17 @@ /// extern EFI_GUID gLoaderMemoryMapInfoGuid; +/// +/// MEMORY_MAP_ENTRY.Flag bits. +/// +/// A bootloader that already knows a range is device MMIO can say so +/// explicitly rather than leaving UefiPayloadEntry to classify the range by +/// the below/above mTopOfLowerUsableDram heuristic. The bit is additive: a +/// payload that predates it simply falls back to the heuristic, and a +/// bootloader that does not set it behaves exactly as before. +/// +#define MEM_MAP_FLAG_MMIO BIT0 + #pragma pack(1) typedef struct { UINT64 Base; diff --git a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c index be0af7be17..00b016003b 100644 --- a/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c +++ b/UefiPayloadPkg/UefiPayloadEntry/UefiPayloadEntry.c @@ -76,11 +76,12 @@ MemInfoCallbackMmio ( if (MemoryMapEntry->Base == AcpiBoardInfo->PcieBaseAddress) { // - // MMCONF is always MMIO. Optionally surface it as Reserved instead - // so that Linux's is_mmconf_reserved() check accepts it and - // MMCONFIG can be used for extended PCIe config space. A plain - // MMIO resource is only surfaced by CoreGetMemoryMap() when it - // also carries EFI_MEMORY_RUNTIME, which this range does not. + // MMCONF is always MMIO. Optionally surface it as Reserved instead; + // see PcdPublishMcfgAsReservedMemory in UefiPayloadPkg.dec for why an + // OS may need that. This check runs before the MEM_MAP_FLAG_MMIO + // branch below because a bootloader that discovers MMIO from the + // outer firmware's GCD map will emit the ECAM window with that flag + // set. // if (FeaturePcdGet (PcdPublishMcfgAsReservedMemory)) { // @@ -109,6 +110,12 @@ MemInfoCallbackMmio ( } else { Type = EFI_RESOURCE_MEMORY_MAPPED_IO; } + } else if ((MemoryMapEntry->Flag & MEM_MAP_FLAG_MMIO) != 0) { + // + // The bootloader explicitly marked this range as device MMIO, so + // take it at its word instead of guessing from the address. + // + Type = EFI_RESOURCE_MEMORY_MAPPED_IO; } else if (MemoryMapEntry->Base < mTopOfLowerUsableDram) { // // It's in DRAM and thus must be reserved -- 2.47.3 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#122092): https://edk2.groups.io/g/devel/message/122092 Mute This Topic: https://groups.io/mt/120797256/21656 Group Owner: [email protected] Unsubscribe: https://edk2.groups.io/g/devel/unsub [[email protected]] -=-=-=-=-=-=-=-=-=-=-=-
