MdeModulePkg/PciBusDxe: Fix boot hang with faulty PCI Option ROM

A faulty PCI device has the Option ROM image size set to 0. UEFI reads
two headers PCI_EXPANSION_ROM_HEADER and PCI_DATA_STRUCTURE to get the
Option ROM information. Because the image size is 0, the Option ROM
header address never changes. As a result, UEFI keeps reading the same
two headers definitely. This patch is intended to fix it.

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
This commit is contained in:
Nhi Pham 2023-08-21 10:27:30 +07:00 committed by mergify[bot]
parent 9896a9c618
commit 5f46eb2307
1 changed files with 2 additions and 2 deletions

View File

@ -506,13 +506,13 @@ LoadOpRomImage (
Indicator = RomPcir->Indicator; Indicator = RomPcir->Indicator;
RomImageSize = RomImageSize + RomPcir->ImageLength * 512; RomImageSize = RomImageSize + RomPcir->ImageLength * 512;
RomBarOffset = RomBarOffset + RomPcir->ImageLength * 512; RomBarOffset = RomBarOffset + RomPcir->ImageLength * 512;
} while (((Indicator & 0x80) == 0x00) && ((RomBarOffset - RomBar) < RomSize)); } while (((Indicator & 0x80) == 0x00) && ((RomBarOffset - RomBar) < RomSize) && (RomImageSize > 0));
// //
// Some Legacy Cards do not report the correct ImageLength so used the maximum // Some Legacy Cards do not report the correct ImageLength so used the maximum
// of the legacy length and the PCIR Image Length // of the legacy length and the PCIR Image Length
// //
if (CodeType == PCI_CODE_TYPE_PCAT_IMAGE) { if ((RomImageSize > 0) && (CodeType == PCI_CODE_TYPE_PCAT_IMAGE)) {
RomImageSize = MAX (RomImageSize, LegacyImageLength); RomImageSize = MAX (RomImageSize, LegacyImageLength);
} }