From 7f8961bdf9a8bd480c10b99bcd69a43a8109bd37 Mon Sep 17 00:00:00 2001 From: Alok Kulkarni Date: Thu, 15 Jan 2026 22:37:14 +0000 Subject: [PATCH] [CHERRY-PICK] MdeModulePkg: PciBusDxe: Degrade MEM64 to PMEM64 when bridge lacks MEM64 P2P bridge Memory Base/Limit registers (0x20-0x22) only support 32-bit addresses. Previously, MEM64 resources behind such bridges were always degraded to MEM32, forcing allocation below 4GB. This can lead to resource constraints when using massive storage (such as MPF drives) as MEM32 space is limited on most platforms. Based on PCIe Base Specification 6.3+, assigning 64-bit resources irrespective of the prefetchable/non-prefetchable BAR bit is allowed. In DegradeResource(), if an upstream bridge supports PMEM64, MEM64 resources are now degraded to PMEM64 first. This enables 64-bit BAR allocation for devices like NVMe controllers that declare non- prefetchable 64-bit BARs. We still fall back to MEM32 degradation if the bridge lacks PMEM64 support as well. Ref: PCI-SIG ECN "Removing Prefetchable Terminology" (2024-04-05) Ref: PCIe Base Specification 6.3+ Signed-off-by: Kun Qin (cherry picked from commit f6489621b8ae1164c5e4930902988ba7c86847ba) --- .../Bus/Pci/PciBusDxe/PciResourceSupport.c | 45 ++++++++++++++++--- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c index 8ffd05f327d..2859cbdf30c 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c @@ -1000,6 +1000,19 @@ ResourcePaddingPolicy ( PMEM64 -> PMEM32 -> MEM32 IO32 -> IO16. + Additionally, if the upstream bridge supports PMEM64 but not MEM64, + MEM64 resources are degraded to PMEM64 to enable 64-bit allocation + through the bridge's prefetchable window. So the below degradation + path is also now supported: + + MEM64 -> PMEM64 + + This is safe per PCI-SIG's ECN title "Removing Prefetchable Terminology" + (2024-04-05). + + The terms prefetchable and non-prefetchable have also been removed from + the PCIe base specification starting with version 6.3. + @param Bridge Pci device instance. @param Mem32Node Resource info node for 32-bit memory. @param PMem32Node Resource info node for 32-bit Prefetchable Memory. @@ -1090,14 +1103,34 @@ DegradeResource ( ); } else { // - // if the bridge does not support MEM64, degrade MEM64 to MEM32 + // If the upstream bridge does not support MEM64, check if we can + // degrade to PMEM64 first, instead of degrading to MEM32 directly. + // + // This is allowed per PCIe Base Spec 6.3+ which removes the terms + // prefetchable/non-prefetchable from the specification. + // The distinction originally only described P2P bridge read-ahead + // behavior, not resource allocation policy. + // + // We will still fall back and degrade to MEM32 if the upstream + // bridge lacks PMEM64 support. + // + // Refer to PCI-SIG ECN "Removing Prefetchable Terminology" + // (2024-04-05) for more details. // if (!BridgeSupportResourceDecode (Bridge, EFI_BRIDGE_MEM64_DECODE_SUPPORTED)) { - MergeResourceTree ( - Mem32Node, - Mem64Node, - TRUE - ); + if (BridgeSupportResourceDecode (Bridge, EFI_BRIDGE_PMEM64_DECODE_SUPPORTED)) { + MergeResourceTree ( + PMem64Node, + Mem64Node, + TRUE + ); + } else { + MergeResourceTree ( + Mem32Node, + Mem64Node, + TRUE + ); + } } //