Commit 6ae72bfa authored by Yicong Yang's avatar Yicong Yang Committed by Bjorn Helgaas

PCI: Unify pcie_find_root_port() and pci_find_pcie_root_port()

Previously we used pcie_find_root_port() to find a Root Port from a PCIe
device and pci_find_pcie_root_port() to find a Root Port from a
Conventional PCI device.

Unify the two functions and use pcie_find_root_port() to find a Root Port
from either a Conventional PCI device or a PCIe device.  Then there is no
need to distinguish the type of the device.

Link: https://lore.kernel.org/r/1589019568-5216-1-git-send-email-yangyicong@hisilicon.comSigned-off-by: default avatarYicong Yang <yangyicong@hisilicon.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
Acked-by: Kalle Valo <kvalo@codeaurora.org> # wireless
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> # thunderbolt
parent 914a1951
...@@ -948,7 +948,7 @@ static bool acpi_pci_bridge_d3(struct pci_dev *dev) ...@@ -948,7 +948,7 @@ static bool acpi_pci_bridge_d3(struct pci_dev *dev)
* Look for a special _DSD property for the root port and if it * Look for a special _DSD property for the root port and if it
* is set we know the hierarchy behind it supports D3 just fine. * is set we know the hierarchy behind it supports D3 just fine.
*/ */
root = pci_find_pcie_root_port(dev); root = pcie_find_root_port(dev);
if (!root) if (!root)
return false; return false;
......
...@@ -751,30 +751,6 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res) ...@@ -751,30 +751,6 @@ struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res)
} }
EXPORT_SYMBOL(pci_find_resource); EXPORT_SYMBOL(pci_find_resource);
/**
* pci_find_pcie_root_port - return PCIe Root Port
* @dev: PCI device to query
*
* Traverse up the parent chain and return the PCIe Root Port PCI Device
* for a given PCI Device.
*/
struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
{
struct pci_dev *bridge, *highest_pcie_bridge = dev;
bridge = pci_upstream_bridge(dev);
while (bridge && pci_is_pcie(bridge)) {
highest_pcie_bridge = bridge;
bridge = pci_upstream_bridge(bridge);
}
if (pci_pcie_type(highest_pcie_bridge) != PCI_EXP_TYPE_ROOT_PORT)
return NULL;
return highest_pcie_bridge;
}
EXPORT_SYMBOL(pci_find_pcie_root_port);
/** /**
* pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos * pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos
* @dev: the PCI device to operate on * @dev: the PCI device to operate on
......
...@@ -2056,7 +2056,7 @@ static void pci_configure_relaxed_ordering(struct pci_dev *dev) ...@@ -2056,7 +2056,7 @@ static void pci_configure_relaxed_ordering(struct pci_dev *dev)
* For now, we only deal with Relaxed Ordering issues with Root * For now, we only deal with Relaxed Ordering issues with Root
* Ports. Peer-to-Peer DMA is another can of worms. * Ports. Peer-to-Peer DMA is another can of worms.
*/ */
root = pci_find_pcie_root_port(dev); root = pcie_find_root_port(dev);
if (!root) if (!root)
return; return;
......
...@@ -4319,7 +4319,7 @@ DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_AMD, 0x1a02, PCI_CLASS_NOT_DEFINED, ...@@ -4319,7 +4319,7 @@ DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_AMD, 0x1a02, PCI_CLASS_NOT_DEFINED,
*/ */
static void quirk_disable_root_port_attributes(struct pci_dev *pdev) static void quirk_disable_root_port_attributes(struct pci_dev *pdev)
{ {
struct pci_dev *root_port = pci_find_pcie_root_port(pdev); struct pci_dev *root_port = pcie_find_root_port(pdev);
if (!root_port) { if (!root_port) {
pci_warn(pdev, "PCIe Completion erratum may cause device errors\n"); pci_warn(pdev, "PCIe Completion erratum may cause device errors\n");
......
...@@ -263,7 +263,7 @@ static void nvm_authenticate_start_dma_port(struct tb_switch *sw) ...@@ -263,7 +263,7 @@ static void nvm_authenticate_start_dma_port(struct tb_switch *sw)
* itself. To be on the safe side keep the root port in D0 during * itself. To be on the safe side keep the root port in D0 during
* the whole upgrade process. * the whole upgrade process.
*/ */
root_port = pci_find_pcie_root_port(sw->tb->nhi->pdev); root_port = pcie_find_root_port(sw->tb->nhi->pdev);
if (root_port) if (root_port)
pm_runtime_get_noresume(&root_port->dev); pm_runtime_get_noresume(&root_port->dev);
} }
...@@ -272,7 +272,7 @@ static void nvm_authenticate_complete_dma_port(struct tb_switch *sw) ...@@ -272,7 +272,7 @@ static void nvm_authenticate_complete_dma_port(struct tb_switch *sw)
{ {
struct pci_dev *root_port; struct pci_dev *root_port;
root_port = pci_find_pcie_root_port(sw->tb->nhi->pdev); root_port = pcie_find_root_port(sw->tb->nhi->pdev);
if (root_port) if (root_port)
pm_runtime_put(&root_port->dev); pm_runtime_put(&root_port->dev);
} }
......
...@@ -1025,7 +1025,6 @@ void pci_bus_add_device(struct pci_dev *dev); ...@@ -1025,7 +1025,6 @@ void pci_bus_add_device(struct pci_dev *dev);
void pci_read_bridge_bases(struct pci_bus *child); void pci_read_bridge_bases(struct pci_bus *child);
struct resource *pci_find_parent_resource(const struct pci_dev *dev, struct resource *pci_find_parent_resource(const struct pci_dev *dev,
struct resource *res); struct resource *res);
struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev);
u8 pci_swizzle_interrupt_pin(const struct pci_dev *dev, u8 pin); u8 pci_swizzle_interrupt_pin(const struct pci_dev *dev, u8 pin);
int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge); int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge);
u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp); u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp);
...@@ -2143,17 +2142,23 @@ static inline int pci_pcie_type(const struct pci_dev *dev) ...@@ -2143,17 +2142,23 @@ static inline int pci_pcie_type(const struct pci_dev *dev)
return (pcie_caps_reg(dev) & PCI_EXP_FLAGS_TYPE) >> 4; return (pcie_caps_reg(dev) & PCI_EXP_FLAGS_TYPE) >> 4;
} }
/**
* pcie_find_root_port - Get the PCIe root port device
* @dev: PCI device
*
* Traverse up the parent chain and return the PCIe Root Port PCI Device
* for a given PCI/PCIe Device.
*/
static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev) static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
{ {
while (1) { struct pci_dev *bridge = pci_upstream_bridge(dev);
if (!pci_is_pcie(dev))
break; while (bridge) {
if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT) if (pci_pcie_type(bridge) == PCI_EXP_TYPE_ROOT_PORT)
return dev; return bridge;
if (!dev->bus->self) bridge = pci_upstream_bridge(bridge);
break;
dev = dev->bus->self;
} }
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment