PCI: move host bridge-related code to host-bridge.c
authorYinghai Lu <yinghai@kernel.org>
Tue, 3 Apr 2012 01:31:53 +0000 (18:31 -0700)
committerBjorn Helgaas <bhelgaas@google.com>
Mon, 30 Apr 2012 19:36:14 +0000 (13:36 -0600)
Move host bridge-related code from probe.c to a new host-bridge.c.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/Makefile
drivers/pci/host-bridge.c [new file with mode: 0644]
drivers/pci/pci.h
drivers/pci/probe.c

index 083a49f..2c224ed 100644 (file)
@@ -2,7 +2,7 @@
 # Makefile for the PCI bus specific drivers.
 #
 
-obj-y          += access.o bus.o probe.o remove.o pci.o \
+obj-y          += access.o bus.o probe.o host-bridge.o remove.o pci.o \
                        pci-driver.o search.o pci-sysfs.o rom.o setup-res.o \
                        irq.o vpd.o
 obj-$(CONFIG_PROC_FS) += proc.o
diff --git a/drivers/pci/host-bridge.c b/drivers/pci/host-bridge.c
new file mode 100644 (file)
index 0000000..28b24a5
--- /dev/null
@@ -0,0 +1,93 @@
+/*
+ * host bridge related code
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/pci.h>
+#include <linux/module.h>
+
+#include "pci.h"
+
+static LIST_HEAD(pci_host_bridges);
+
+void add_to_pci_host_bridges(struct pci_host_bridge *bridge)
+{
+       list_add_tail(&bridge->list, &pci_host_bridges);
+}
+
+static struct pci_host_bridge *pci_host_bridge(struct pci_dev *dev)
+{
+       struct pci_bus *bus;
+       struct pci_host_bridge *bridge;
+
+       bus = dev->bus;
+       while (bus->parent)
+               bus = bus->parent;
+
+       list_for_each_entry(bridge, &pci_host_bridges, list) {
+               if (bridge->bus == bus)
+                       return bridge;
+       }
+
+       return NULL;
+}
+
+static bool resource_contains(struct resource *res1, struct resource *res2)
+{
+       return res1->start <= res2->start && res1->end >= res2->end;
+}
+
+void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
+                            struct resource *res)
+{
+       struct pci_host_bridge *bridge = pci_host_bridge(dev);
+       struct pci_host_bridge_window *window;
+       resource_size_t offset = 0;
+
+       list_for_each_entry(window, &bridge->windows, list) {
+               if (resource_type(res) != resource_type(window->res))
+                       continue;
+
+               if (resource_contains(window->res, res)) {
+                       offset = window->offset;
+                       break;
+               }
+       }
+
+       region->start = res->start - offset;
+       region->end = res->end - offset;
+}
+EXPORT_SYMBOL(pcibios_resource_to_bus);
+
+static bool region_contains(struct pci_bus_region *region1,
+                           struct pci_bus_region *region2)
+{
+       return region1->start <= region2->start && region1->end >= region2->end;
+}
+
+void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
+                            struct pci_bus_region *region)
+{
+       struct pci_host_bridge *bridge = pci_host_bridge(dev);
+       struct pci_host_bridge_window *window;
+       struct pci_bus_region bus_region;
+       resource_size_t offset = 0;
+
+       list_for_each_entry(window, &bridge->windows, list) {
+               if (resource_type(res) != resource_type(window->res))
+                       continue;
+
+               bus_region.start = window->res->start - window->offset;
+               bus_region.end = window->res->end - window->offset;
+
+               if (region_contains(&bus_region, region)) {
+                       offset = window->offset;
+                       break;
+               }
+       }
+
+       res->start = region->start + offset;
+       res->end = region->end + offset;
+}
+EXPORT_SYMBOL(pcibios_bus_to_resource);
index e494347..c695a92 100644 (file)
@@ -231,6 +231,8 @@ static inline int pci_ari_enabled(struct pci_bus *bus)
 void pci_reassigndev_resource_alignment(struct pci_dev *dev);
 extern void pci_disable_bridge_window(struct pci_dev *dev);
 
+void add_to_pci_host_bridges(struct pci_host_bridge *bridge);
+
 /* Single Root I/O Virtualization */
 struct pci_sriov {
        int pos;                /* capability position */
index 5e1ca3c..bcea52b 100644 (file)
 #define CARDBUS_LATENCY_TIMER  176     /* secondary latency timer */
 #define CARDBUS_RESERVE_BUSNR  3
 
-static LIST_HEAD(pci_host_bridges);
-
 /* Ugh.  Need to stop exporting this to modules. */
 LIST_HEAD(pci_root_buses);
 EXPORT_SYMBOL(pci_root_buses);
 
-
 static int find_anything(struct device *dev, void *data)
 {
        return 1;
@@ -44,82 +41,6 @@ int no_pci_devices(void)
 }
 EXPORT_SYMBOL(no_pci_devices);
 
-static struct pci_host_bridge *pci_host_bridge(struct pci_dev *dev)
-{
-       struct pci_bus *bus;
-       struct pci_host_bridge *bridge;
-
-       bus = dev->bus;
-       while (bus->parent)
-               bus = bus->parent;
-
-       list_for_each_entry(bridge, &pci_host_bridges, list) {
-               if (bridge->bus == bus)
-                       return bridge;
-       }
-
-       return NULL;
-}
-
-static bool resource_contains(struct resource *res1, struct resource *res2)
-{
-       return res1->start <= res2->start && res1->end >= res2->end;
-}
-
-void pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
-                            struct resource *res)
-{
-       struct pci_host_bridge *bridge = pci_host_bridge(dev);
-       struct pci_host_bridge_window *window;
-       resource_size_t offset = 0;
-
-       list_for_each_entry(window, &bridge->windows, list) {
-               if (resource_type(res) != resource_type(window->res))
-                       continue;
-
-               if (resource_contains(window->res, res)) {
-                       offset = window->offset;
-                       break;
-               }
-       }
-
-       region->start = res->start - offset;
-       region->end = res->end - offset;
-}
-EXPORT_SYMBOL(pcibios_resource_to_bus);
-
-static bool region_contains(struct pci_bus_region *region1,
-                           struct pci_bus_region *region2)
-{
-       return region1->start <= region2->start && region1->end >= region2->end;
-}
-
-void pcibios_bus_to_resource(struct pci_dev *dev, struct resource *res,
-                            struct pci_bus_region *region)
-{
-       struct pci_host_bridge *bridge = pci_host_bridge(dev);
-       struct pci_host_bridge_window *window;
-       struct pci_bus_region bus_region;
-       resource_size_t offset = 0;
-
-       list_for_each_entry(window, &bridge->windows, list) {
-               if (resource_type(res) != resource_type(window->res))
-                       continue;
-
-               bus_region.start = window->res->start - window->offset;
-               bus_region.end = window->res->end - window->offset;
-
-               if (region_contains(&bus_region, region)) {
-                       offset = window->offset;
-                       break;
-               }
-       }
-
-       res->start = region->start + offset;
-       res->end = region->end + offset;
-}
-EXPORT_SYMBOL(pcibios_bus_to_resource);
-
 /*
  * PCI Bus Class
  */
@@ -1732,7 +1653,7 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
        }
 
        down_write(&pci_bus_sem);
-       list_add_tail(&bridge->list, &pci_host_bridges);
+       add_to_pci_host_bridges(bridge);
        list_add_tail(&b->node, &pci_root_buses);
        up_write(&pci_bus_sem);