From 736c436e5355e1370f13392a6cecf2cf260608a8 Mon Sep 17 00:00:00 2001 From: Ruiyu Ni Date: Tue, 11 Dec 2018 17:49:17 +0800 Subject: MdeModulePkg/PciBus: Fix system hang when no PCI Option ROM exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1394 When there is no PCI option ROM exists, today's logic still creates virtual BAR for option ROM using Length = 0, Alignment = (-1). It causes the final MEM32 alignment requirement is as big as 0xFFFFFFFF_FFFFFFFF. The patch fixes this issue by only creating virtual BAR for option ROM when there is PCI option ROM. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ruiyu Ni Cc: Chiu Chasel Cc: Hao A Wu Cc: Jian J Wang Tested-by: Ard Biesheuvel Reviewed-by: Chasel Chiu Reviewed-by: Jian J Wang Reviewed-by: Hao Wu Reviewed-by: Philippe Mathieu-Daudé --- MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c index 7255bcf..ee5c771 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c @@ -515,10 +515,12 @@ PciHostBridgeResourceAllocator ( // All devices' Option ROM share the same MEM32 resource. // MaxOptionRomSize = GetMaxOptionRomSize (RootBridgeDev); - RootBridgeDev->PciBar[0].BarType = PciBarTypeOpRom; - RootBridgeDev->PciBar[0].Length = MaxOptionRomSize; - RootBridgeDev->PciBar[0].Alignment = MaxOptionRomSize - 1; - GetResourceFromDevice (RootBridgeDev, IoBridge, Mem32Bridge, PMem32Bridge, Mem64Bridge, PMem64Bridge); + if (MaxOptionRomSize != 0) { + RootBridgeDev->PciBar[0].BarType = PciBarTypeOpRom; + RootBridgeDev->PciBar[0].Length = MaxOptionRomSize; + RootBridgeDev->PciBar[0].Alignment = MaxOptionRomSize - 1; + GetResourceFromDevice (RootBridgeDev, IoBridge, Mem32Bridge, PMem32Bridge, Mem64Bridge, PMem64Bridge); + } // // Create resourcemap by going through all the devices subject to this root bridge -- cgit v1.1