aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/controller
diff options
context:
space:
mode:
authorHonghui Zhang <honghui.zhang@mediatek.com>2018-10-15 04:08:52 -0400
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>2018-10-15 09:47:54 -0400
commit074d6f32689ce05a084b6fa3db38445745bf11cc (patch)
tree439006a762605fdbdddcc55689d196c765007e7a /drivers/pci/controller
parent17a0a1e5f6c4bd6df17834312ff577c1373d87b8 (diff)
PCI: mediatek: Fix mtk_pcie_find_port() endpoint/port matching logic
The Mediatek's host controller has two slots, each with its own control registers. The host driver needs to identify what slot is connected to what port in order to access the device's configuration space. Current code retrieving slot connected to a given endpoint device. Assuming each slot is connected to one endpoint device as below: host bridge bus 0 --> __________|_______ | | | | slot 0 slot 1 bus 1 -->| bus 2 --> | | | EP 0 EP 1 During PCI enumeration, system software will scan all the PCI devices on every bus starting from devfn 0. Using PCI_SLOT(devfn) for matching an endpoint to its slot is erroneous in that the devfn does not contain the hierarchical bus numbering in it. In order to match an endpoint with its slot (and related port), the PCI tree must be walked up to the root bus (where the root ports are situated) and then the PCI_SLOT(devfn) matching logic can be correctly applied for matching. This patch fixes the mtk_pcie_find_port() slot matching logic by adding appropriate PCI tree walking code to retrieve the slot/port a given endpoint is connected to. Signed-off-by: Honghui Zhang <honghui.zhang@mediatek.com> [lorenzo.pieralisi@arm.com: rewrote the commit log] Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Acked-by: Ryder Lee <ryder.lee@mediatek.com>
Diffstat (limited to 'drivers/pci/controller')
-rw-r--r--drivers/pci/controller/pcie-mediatek.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index 1477939ef38a..0d100f56cb88 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -337,6 +337,17 @@ static struct mtk_pcie_port *mtk_pcie_find_port(struct pci_bus *bus,
337{ 337{
338 struct mtk_pcie *pcie = bus->sysdata; 338 struct mtk_pcie *pcie = bus->sysdata;
339 struct mtk_pcie_port *port; 339 struct mtk_pcie_port *port;
340 struct pci_dev *dev = NULL;
341
342 /*
343 * Walk the bus hierarchy to get the devfn value
344 * of the port in the root bus.
345 */
346 while (bus && bus->number) {
347 dev = bus->self;
348 bus = dev->bus;
349 devfn = dev->devfn;
350 }
340 351
341 list_for_each_entry(port, &pcie->ports, list) 352 list_for_each_entry(port, &pcie->ports, list)
342 if (port->slot == PCI_SLOT(devfn)) 353 if (port->slot == PCI_SLOT(devfn))