REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1169
Current code checks HeaderType of Function 0 even Function 0 is not
implemented. HeaderType value will be 0xFF if Function 0 is not
implemented, then MaxFunction will be set to PCI_MAX_FUNC + 1.
The code can be optimized to only check HeaderType if Function 0 is
implemented.
Test done:
With this patch, the result is same with the result after the patch at
https://lists.01.org/pipermail/edk2-devel/2018-September/029623.html.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Rangasai V Chaganty <rangasai.v.chaganty@intel.com>
Cc: Tomson Chang <tomson.chang@intel.com>
Cc: Jenny Huang <jenny.huang@intel.com>
Cc: Amy Chan <amy.chan@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
UINT8 HeaderType;\r
UINT8 BaseClass;\r
UINT8 SubClass;\r
UINT8 HeaderType;\r
UINT8 BaseClass;\r
UINT8 SubClass;\r
UINT16 VendorID;\r
UINT16 DeviceID;\r
EFI_STATUS Status;\r
\r
// Scan the PCI bus for devices\r
UINT16 VendorID;\r
UINT16 DeviceID;\r
EFI_STATUS Status;\r
\r
// Scan the PCI bus for devices\r
- for (Device = 0; Device < PCI_MAX_DEVICE + 1; Device++) {\r
- HeaderType = PciSegmentRead8 (PCI_SEGMENT_LIB_ADDRESS(Segment, Bus, Device, 0, PCI_HEADER_TYPE_OFFSET));\r
- MaxFunction = PCI_MAX_FUNC + 1;\r
- if ((HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00) {\r
- MaxFunction = 1;\r
- }\r
- for (Function = 0; Function < MaxFunction; Function++) {\r
+ for (Device = 0; Device <= PCI_MAX_DEVICE; Device++) {\r
+ for (Function = 0; Function <= PCI_MAX_FUNC; Function++) {\r
VendorID = PciSegmentRead16 (PCI_SEGMENT_LIB_ADDRESS(Segment, Bus, Device, Function, PCI_VENDOR_ID_OFFSET));\r
DeviceID = PciSegmentRead16 (PCI_SEGMENT_LIB_ADDRESS(Segment, Bus, Device, Function, PCI_DEVICE_ID_OFFSET));\r
if (VendorID == 0xFFFF && DeviceID == 0xFFFF) {\r
VendorID = PciSegmentRead16 (PCI_SEGMENT_LIB_ADDRESS(Segment, Bus, Device, Function, PCI_VENDOR_ID_OFFSET));\r
DeviceID = PciSegmentRead16 (PCI_SEGMENT_LIB_ADDRESS(Segment, Bus, Device, Function, PCI_DEVICE_ID_OFFSET));\r
if (VendorID == 0xFFFF && DeviceID == 0xFFFF) {\r
+\r
+ if (Function == 0) {\r
+ HeaderType = PciSegmentRead8 (PCI_SEGMENT_LIB_ADDRESS(Segment, Bus, Device, 0, PCI_HEADER_TYPE_OFFSET));\r
+ if ((HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00) {\r
+ //\r
+ // It is not a multi-function device, do not scan other functions.\r
+ //\r
+ break;\r
+ }\r
+ }\r