summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAjan Zhong <ajan.zhong@newfw.com>2025-03-12 10:34:31 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2025-03-13 17:40:31 +0000
commit2aff039da7a8443352f572cecb7ec8109455e7d8 (patch)
tree6a0cb35d2da365729c89b6abe44f6009af4b0de0
parent1e0051e293aedc1a196ae5678a1e953e5ed946f1 (diff)
downloadedk2-2aff039da7a8443352f572cecb7ec8109455e7d8.zip
edk2-2aff039da7a8443352f572cecb7ec8109455e7d8.tar.gz
edk2-2aff039da7a8443352f572cecb7ec8109455e7d8.tar.bz2
UefiPayloadPkg: Parse PCI RB Segment info when its available in FDT
When FDT based DTB is parsed, variables mPciRootBridgeInfo and mUplPciSegmentInfoHob are always dereferenced. If there is no PCI RB Bridge info or RB Segment info provided in FDT, it leads to NULL pointer dereferenced. To address this issue, parse PCI RB and Segment information only when they are available at FDT. If they are unavailable, skip it and allow the PciBusDxe and PciHostBridgeDxe to handle them. Signed-off-by: Ajan Zhong <ajan.zhong@newfw.com>
-rw-r--r--UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c74
1 files changed, 38 insertions, 36 deletions
diff --git a/UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c b/UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c
index 05780a2..41e15e4 100644
--- a/UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c
+++ b/UefiPayloadPkg/Library/FdtParserLib/FdtParserLib.c
@@ -1000,46 +1000,48 @@ ParseDtb (
}
}
- // Post processing: TODO: Need to look into it. Such cross dependency on DT nodes
- // may not be good idea. Instead have this prop part of RB
- mPciRootBridgeInfo->ResourceAssigned = (BOOLEAN)PciEnumDone;
-
- //
- // Assign PCI Segment number after all root bridge info ready
- //
- SegmentNumber = 0;
- RbSegNumAlreadyAssigned = AllocateZeroPool (sizeof (UINT8) * RootBridgeCount);
- NextPciBaseAddress = 0;
- NumberOfRbSegNumAlreadyAssigned = 0;
+ if ((NULL != mPciRootBridgeInfo) && (NULL != mUplPciSegmentInfoHob)) {
+ // Post processing: TODO: Need to look into it. Such cross dependency on DT nodes
+ // may not be good idea. Instead have this prop part of RB
+ mPciRootBridgeInfo->ResourceAssigned = (BOOLEAN)PciEnumDone;
+
+ //
+ // Assign PCI Segment number after all root bridge info ready
+ //
+ SegmentNumber = 0;
+ RbSegNumAlreadyAssigned = AllocateZeroPool (sizeof (UINT8) * RootBridgeCount);
+ NextPciBaseAddress = 0;
+ NumberOfRbSegNumAlreadyAssigned = 0;
+
+ //
+ // Always assign first root bridge segment number as 0
+ //
+ CurrentPciBaseAddress = mUplPciSegmentInfoHob->SegmentInfo[0].BaseAddress & ~0xFFFFFFF;
+ NextPciBaseAddress = CurrentPciBaseAddress;
+ mUplPciSegmentInfoHob->SegmentInfo[0].SegmentNumber = SegmentNumber;
+ mPciRootBridgeInfo->RootBridge[0].Segment = SegmentNumber;
+ RbSegNumAlreadyAssigned[0] = 1;
+ NumberOfRbSegNumAlreadyAssigned++;
+
+ while (NumberOfRbSegNumAlreadyAssigned < RootBridgeCount) {
+ for (index = 1; index < RootBridgeCount; index++) {
+ if (RbSegNumAlreadyAssigned[index] == 1) {
+ continue;
+ }
- //
- // Always assign first root bridge segment number as 0
- //
- CurrentPciBaseAddress = mUplPciSegmentInfoHob->SegmentInfo[0].BaseAddress & ~0xFFFFFFF;
- NextPciBaseAddress = CurrentPciBaseAddress;
- mUplPciSegmentInfoHob->SegmentInfo[0].SegmentNumber = SegmentNumber;
- mPciRootBridgeInfo->RootBridge[0].Segment = SegmentNumber;
- RbSegNumAlreadyAssigned[0] = 1;
- NumberOfRbSegNumAlreadyAssigned++;
-
- while (NumberOfRbSegNumAlreadyAssigned < RootBridgeCount) {
- for (index = 1; index < RootBridgeCount; index++) {
- if (RbSegNumAlreadyAssigned[index] == 1) {
- continue;
+ if (CurrentPciBaseAddress == (mUplPciSegmentInfoHob->SegmentInfo[index].BaseAddress & ~0xFFFFFFF)) {
+ mUplPciSegmentInfoHob->SegmentInfo[index].SegmentNumber = SegmentNumber;
+ mPciRootBridgeInfo->RootBridge[index].Segment = SegmentNumber;
+ RbSegNumAlreadyAssigned[index] = 1;
+ NumberOfRbSegNumAlreadyAssigned++;
+ } else if (CurrentPciBaseAddress == NextPciBaseAddress) {
+ NextPciBaseAddress = mUplPciSegmentInfoHob->SegmentInfo[index].BaseAddress & ~0xFFFFFFF;
+ }
}
- if (CurrentPciBaseAddress == (mUplPciSegmentInfoHob->SegmentInfo[index].BaseAddress & ~0xFFFFFFF)) {
- mUplPciSegmentInfoHob->SegmentInfo[index].SegmentNumber = SegmentNumber;
- mPciRootBridgeInfo->RootBridge[index].Segment = SegmentNumber;
- RbSegNumAlreadyAssigned[index] = 1;
- NumberOfRbSegNumAlreadyAssigned++;
- } else if (CurrentPciBaseAddress == NextPciBaseAddress) {
- NextPciBaseAddress = mUplPciSegmentInfoHob->SegmentInfo[index].BaseAddress & ~0xFFFFFFF;
- }
+ SegmentNumber++;
+ CurrentPciBaseAddress = NextPciBaseAddress;
}
-
- SegmentNumber++;
- CurrentPciBaseAddress = NextPciBaseAddress;
}
((EFI_HOB_HANDOFF_INFO_TABLE *)(mHobList))->BootMode = BootMode;