PCI: designware: Use pci_is_root_bus() to check if bus is root bus
authorRob Herring <robh@kernel.org>
Wed, 22 Jul 2020 02:25:00 +0000 (20:25 -0600)
committerLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Thu, 23 Jul 2020 10:20:50 +0000 (11:20 +0100)
Use pci_is_root_bus() rather than tracking the root bus number to
determine if the bus is the root bus or not. This removes storing
duplicated data as well as the need for the host bridge driver to have
to care about the bus numbers in most cases.

Link: https://lore.kernel.org/r/20200722022514.1283916-6-robh@kernel.org
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Cc: Richard Zhu <hongxing.zhu@nxp.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Pengutronix Kernel Team <kernel@pengutronix.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: NXP Linux Team <linux-imx@nxp.com>
Cc: Murali Karicheri <m-karicheri2@ti.com>
Cc: Jingoo Han <jingoohan1@gmail.com>
Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
drivers/pci/controller/dwc/pci-imx6.c
drivers/pci/controller/dwc/pci-keystone.c
drivers/pci/controller/dwc/pcie-designware-host.c
drivers/pci/controller/dwc/pcie-designware.h

index 8f08ae53f53e4b13f62a671eec74f949d4086a5f..9f1e4d9c008b3d7b1aab513093db2e71da2c4a0d 100644 (file)
@@ -1269,7 +1269,7 @@ static void imx6_pcie_quirk(struct pci_dev *dev)
        if (bus->dev.parent->parent->driver != &imx6_pcie_driver.driver)
                return;
 
-       if (bus->number == pp->root_bus_nr) {
+       if (pci_is_root_bus(bus)) {
                struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
                struct imx6_pcie *imx6_pcie = to_imx6_pcie(pci);
 
index 790679fdfa488cf727c7c8c14dc334fac16062a4..fcc3586c345b97c2f8ec606983217657a791b2bc 100644 (file)
@@ -440,7 +440,7 @@ static int ks_pcie_rd_other_conf(struct pcie_port *pp, struct pci_bus *bus,
 
        reg = CFG_BUS(bus->number) | CFG_DEVICE(PCI_SLOT(devfn)) |
                CFG_FUNC(PCI_FUNC(devfn));
-       if (bus->parent->number != pp->root_bus_nr)
+       if (!pci_is_root_bus(bus->parent))
                reg |= CFG_TYPE1;
        ks_pcie_app_writel(ks_pcie, CFG_SETUP, reg);
 
@@ -457,7 +457,7 @@ static int ks_pcie_wr_other_conf(struct pcie_port *pp, struct pci_bus *bus,
 
        reg = CFG_BUS(bus->number) | CFG_DEVICE(PCI_SLOT(devfn)) |
                CFG_FUNC(PCI_FUNC(devfn));
-       if (bus->parent->number != pp->root_bus_nr)
+       if (!pci_is_root_bus(bus->parent))
                reg |= CFG_TYPE1;
        ks_pcie_app_writel(ks_pcie, CFG_SETUP, reg);
 
index 4a16306cec257481f8497a99694a0fe9900ff13b..9e8a9cfc6d3a727f1425b7e98c53be63f5c9e835 100644 (file)
@@ -473,10 +473,8 @@ int dw_pcie_host_init(struct pcie_port *pp)
                goto err_free_msi;
        }
 
-       pp->root_bus_nr = pp->busn->start;
-
        bridge->sysdata = pp;
-       bridge->busnr = pp->root_bus_nr;
+       bridge->busnr = pp->busn->start;
        bridge->ops = &dw_pcie_ops;
        bridge->map_irq = of_irq_parse_and_map_pci;
        bridge->swizzle_irq = pci_common_swizzle;
@@ -528,7 +526,7 @@ static int dw_pcie_access_other_conf(struct pcie_port *pp, struct pci_bus *bus,
        busdev = PCIE_ATU_BUS(bus->number) | PCIE_ATU_DEV(PCI_SLOT(devfn)) |
                 PCIE_ATU_FUNC(PCI_FUNC(devfn));
 
-       if (bus->parent->number == pp->root_bus_nr) {
+       if (pci_is_root_bus(bus->parent)) {
                type = PCIE_ATU_TYPE_CFG0;
                cpu_addr = pp->cfg0_base;
                cfg_size = pp->cfg0_size;
@@ -584,13 +582,11 @@ static int dw_pcie_valid_device(struct pcie_port *pp, struct pci_bus *bus,
        struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 
        /* If there is no link, then there is no device */
-       if (bus->number != pp->root_bus_nr) {
+       if (!pci_is_root_bus(bus)) {
                if (!dw_pcie_link_up(pci))
                        return 0;
-       }
-
-       /* Access only one slot on each root port */
-       if (bus->number == pp->root_bus_nr && dev > 0)
+       } else if (dev > 0)
+               /* Access only one slot on each root port */
                return 0;
 
        return 1;
@@ -606,7 +602,7 @@ static int dw_pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
                return PCIBIOS_DEVICE_NOT_FOUND;
        }
 
-       if (bus->number == pp->root_bus_nr)
+       if (pci_is_root_bus(bus))
                return dw_pcie_rd_own_conf(pp, where, size, val);
 
        return dw_pcie_rd_other_conf(pp, bus, devfn, where, size, val);
@@ -620,7 +616,7 @@ static int dw_pcie_wr_conf(struct pci_bus *bus, u32 devfn,
        if (!dw_pcie_valid_device(pp, bus, PCI_SLOT(devfn)))
                return PCIBIOS_DEVICE_NOT_FOUND;
 
-       if (bus->number == pp->root_bus_nr)
+       if (pci_is_root_bus(bus))
                return dw_pcie_wr_own_conf(pp, where, size, val);
 
        return dw_pcie_wr_other_conf(pp, bus, devfn, where, size, val);
index 656e00f8fbeb49223af1747fb8caa3f1245276c4..fd2146298b586bd457ec28b10f2178e534faf26d 100644 (file)
@@ -173,7 +173,6 @@ struct dw_pcie_host_ops {
 };
 
 struct pcie_port {
-       u8                      root_bus_nr;
        u64                     cfg0_base;
        void __iomem            *va_cfg0_base;
        u32                     cfg0_size;