These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / drivers / pci / host / pci-host-generic.c
index ba46e58..5434c90 100644 (file)
@@ -27,7 +27,7 @@
 
 struct gen_pci_cfg_bus_ops {
        u32 bus_shift;
-       void __iomem *(*map_bus)(struct pci_bus *, unsigned int, int);
+       struct pci_ops ops;
 };
 
 struct gen_pci_cfg_windows {
@@ -35,10 +35,19 @@ struct gen_pci_cfg_windows {
        struct resource                         *bus_range;
        void __iomem                            **win;
 
-       const struct gen_pci_cfg_bus_ops        *ops;
+       struct gen_pci_cfg_bus_ops              *ops;
 };
 
+/*
+ * ARM pcibios functions expect the ARM struct pci_sys_data as the PCI
+ * sysdata.  Add pci_sys_data as the first element in struct gen_pci so
+ * that when we use a gen_pci pointer as sysdata, it is also a pointer to
+ * a struct pci_sys_data.
+ */
 struct gen_pci {
+#ifdef CONFIG_ARM
+       struct pci_sys_data                     sys;
+#endif
        struct pci_host_bridge                  host;
        struct gen_pci_cfg_windows              cfg;
        struct list_head                        resources;
@@ -48,8 +57,7 @@ static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
                                             unsigned int devfn,
                                             int where)
 {
-       struct pci_sys_data *sys = bus->sysdata;
-       struct gen_pci *pci = sys->private_data;
+       struct gen_pci *pci = bus->sysdata;
        resource_size_t idx = bus->number - pci->cfg.bus_range->start;
 
        return pci->cfg.win[idx] + ((devfn << 8) | where);
@@ -57,15 +65,18 @@ static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
 
 static struct gen_pci_cfg_bus_ops gen_pci_cfg_cam_bus_ops = {
        .bus_shift      = 16,
-       .map_bus        = gen_pci_map_cfg_bus_cam,
+       .ops            = {
+               .map_bus        = gen_pci_map_cfg_bus_cam,
+               .read           = pci_generic_config_read,
+               .write          = pci_generic_config_write,
+       }
 };
 
 static void __iomem *gen_pci_map_cfg_bus_ecam(struct pci_bus *bus,
                                              unsigned int devfn,
                                              int where)
 {
-       struct pci_sys_data *sys = bus->sysdata;
-       struct gen_pci *pci = sys->private_data;
+       struct gen_pci *pci = bus->sysdata;
        resource_size_t idx = bus->number - pci->cfg.bus_range->start;
 
        return pci->cfg.win[idx] + ((devfn << 12) | where);
@@ -73,12 +84,11 @@ static void __iomem *gen_pci_map_cfg_bus_ecam(struct pci_bus *bus,
 
 static struct gen_pci_cfg_bus_ops gen_pci_cfg_ecam_bus_ops = {
        .bus_shift      = 20,
-       .map_bus        = gen_pci_map_cfg_bus_ecam,
-};
-
-static struct pci_ops gen_pci_ops = {
-       .read   = pci_generic_config_read,
-       .write  = pci_generic_config_write,
+       .ops            = {
+               .map_bus        = gen_pci_map_cfg_bus_ecam,
+               .read           = pci_generic_config_read,
+               .write          = pci_generic_config_write,
+       }
 };
 
 static const struct of_device_id gen_pci_of_match[] = {
@@ -159,6 +169,7 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
        struct resource *bus_range;
        struct device *dev = pci->host.dev.parent;
        struct device_node *np = dev->of_node;
+       u32 sz = 1 << pci->cfg.ops->bus_shift;
 
        err = of_address_to_resource(np, 0, &pci->cfg.res);
        if (err) {
@@ -186,10 +197,9 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
        bus_range = pci->cfg.bus_range;
        for (busn = bus_range->start; busn <= bus_range->end; ++busn) {
                u32 idx = busn - bus_range->start;
-               u32 sz = 1 << pci->cfg.ops->bus_shift;
 
                pci->cfg.win[idx] = devm_ioremap(dev,
-                                                pci->cfg.res.start + busn * sz,
+                                                pci->cfg.res.start + idx * sz,
                                                 sz);
                if (!pci->cfg.win[idx])
                        return -ENOMEM;
@@ -198,29 +208,15 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
        return 0;
 }
 
-static int gen_pci_setup(int nr, struct pci_sys_data *sys)
-{
-       struct gen_pci *pci = sys->private_data;
-       list_splice_init(&pci->resources, &sys->resources);
-       return 1;
-}
-
 static int gen_pci_probe(struct platform_device *pdev)
 {
        int err;
        const char *type;
        const struct of_device_id *of_id;
-       const int *prop;
        struct device *dev = &pdev->dev;
        struct device_node *np = dev->of_node;
        struct gen_pci *pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
-       struct hw_pci hw = {
-               .nr_controllers = 1,
-               .private_data   = (void **)&pci,
-               .setup          = gen_pci_setup,
-               .map_irq        = of_irq_parse_and_map_pci,
-               .ops            = &gen_pci_ops,
-       };
+       struct pci_bus *bus, *child;
 
        if (!pci)
                return -ENOMEM;
@@ -231,17 +227,10 @@ static int gen_pci_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
-       prop = of_get_property(of_chosen, "linux,pci-probe-only", NULL);
-       if (prop) {
-               if (*prop)
-                       pci_add_flags(PCI_PROBE_ONLY);
-               else
-                       pci_clear_flags(PCI_PROBE_ONLY);
-       }
+       of_pci_check_probe_only();
 
        of_id = of_match_node(gen_pci_of_match, np);
-       pci->cfg.ops = of_id->data;
-       gen_pci_ops.map_bus = pci->cfg.ops->map_bus;
+       pci->cfg.ops = (struct gen_pci_cfg_bus_ops *)of_id->data;
        pci->host.dev.parent = dev;
        INIT_LIST_HEAD(&pci->host.windows);
        INIT_LIST_HEAD(&pci->resources);
@@ -258,7 +247,29 @@ static int gen_pci_probe(struct platform_device *pdev)
                return err;
        }
 
-       pci_common_init_dev(dev, &hw);
+       /* Do not reassign resources if probe only */
+       if (!pci_has_flag(PCI_PROBE_ONLY))
+               pci_add_flags(PCI_REASSIGN_ALL_RSRC | PCI_REASSIGN_ALL_BUS);
+
+
+       bus = pci_scan_root_bus(dev, pci->cfg.bus_range->start,
+                               &pci->cfg.ops->ops, pci, &pci->resources);
+       if (!bus) {
+               dev_err(dev, "Scanning rootbus failed");
+               return -ENODEV;
+       }
+
+       pci_fixup_irqs(pci_common_swizzle, of_irq_parse_and_map_pci);
+
+       if (!pci_has_flag(PCI_PROBE_ONLY)) {
+               pci_bus_size_bridges(bus);
+               pci_bus_assign_resources(bus);
+
+               list_for_each_entry(child, &bus->children, node)
+                       pcie_bus_configure_settings(child);
+       }
+
+       pci_bus_add_devices(bus);
        return 0;
 }