/* find the upstream PCIe-to-PCI bridge of a PCI device if the device is PCIE, return NULL if the device isn't connected to a PCIe bridge (that is its parent is a legacy PCI bridge and the bridge is directly connected to bus 0), return its parent  */
struct pci_dev* pci_find_upstream_pcie_bridge(struct pci_dev *pdev)
/* find the upstream PCIe-to-PCI bridge of a PCI device if the device is PCIE, return NULL if the device isn't connected to a PCIe bridge (that is its parent is a legacy PCI bridge and the bridge is directly connected to bus 0), return its parent  */
struct pci_dev* pci_find_upstream_pcie_bridge(struct pci_dev *pdev)
{
	struct pci_dev *tmp = NULL;
	if (pci_is_pcie(pdev))
		return NULL;
	while (1) {
		if (pci_is_root_bus(pdev->bus))
			break;
		pdev = pdev->bus->self;
		if (!pci_is_pcie(pdev)) {
			tmp = pdev;
			continue;
		}
		if (pdev->pcie_type != PCI_EXP_TYPE_PCI_BRIDGE) {
			WARN_ON_ONCE(1);
			return NULL;
		}
		return pdev;
	}
	return tmp;
}