Wonkyu Kim has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/84229?usp=email )
Change subject: libpayload: add more condition to check valid PCI device id ......................................................................
libpayload: add more condition to check valid PCI device id
Checking more conditions to check valid PCI device id to avoid device stuck issue.
Below are invalid PCI device id cases VID: 0x0 or 0xffff DID: 0x0 or 0xffff
Signed-off-by: Wonkyu Kim wonkyu.kim@intel.com Change-Id: I772c4199c7a6c13a25590a36f1bfee17c1a44daf --- M payloads/libpayload/drivers/usb/usbinit.c 1 file changed, 29 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/29/84229/1
diff --git a/payloads/libpayload/drivers/usb/usbinit.c b/payloads/libpayload/drivers/usb/usbinit.c index a234b00..dfcdae9 100644 --- a/payloads/libpayload/drivers/usb/usbinit.c +++ b/payloads/libpayload/drivers/usb/usbinit.c @@ -116,15 +116,36 @@ return 0; }
+static bool is_valid_pci_dev(int bus, int dev, int fun) +{ + u32 id; + u16 vid, did; + pcidev_t pci_device = PCI_DEV(bus, dev, fun); + + id = pci_read_config32(pci_device, REG_VENDOR_ID); + vid = id & 0xffff; + did = (id >> 16) & 0xffff; + + if ((vid == 0x0000) || (vid == 0xffff) || + (did == 0xffff) || (did== 0x0000)) { + usb_debug("PCI dev %02x:%02x:%02x [0x%04x|0x%04x] is not valid\n", + bus, dev, fun, vid, did); + return false; + } + return true; +} + static void usb_scan_pci_bus(int bus) { int dev, func; + + usb_debug("usb_scan_pci_bus start\n"); for (dev = 0; dev < 32; dev++) { u8 header_type; pcidev_t pci_device = PCI_DEV(bus, dev, 0);
- /* Check if there's a device here at all. */ - if (pci_read_config32(pci_device, REG_VENDOR_ID) == 0xffffffff) + /* Check valid pci device*/ + if ( is_valid_pci_dev(bus, dev, 0) == false ) continue;
/* @@ -143,6 +164,11 @@
for (; func >= 0; func--) { pci_device = PCI_DEV(bus, dev, func); + + /* Check valid pci device*/ + if ( is_valid_pci_dev(bus, dev, func) == false ) + continue; + header_type = pci_read_config8(pci_device, REG_HEADER_TYPE); /* If this is a bridge, scan the other side. */ if ((header_type & ~HEADER_TYPE_MULTIFUNCTION) == @@ -157,6 +183,7 @@ usb_controller_initialize(bus, dev, func); } } + usb_debug("usb_scan_pci_bus end\n"); } #endif