2012-04-03 09:31:53 +08:00
|
|
|
/*
|
|
|
|
* host bridge related code
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
#include "pci.h"
|
|
|
|
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
static struct pci_bus *find_pci_root_bus(struct pci_bus *bus)
|
2012-04-03 09:31:53 +08:00
|
|
|
{
|
|
|
|
while (bus->parent)
|
|
|
|
bus = bus->parent;
|
|
|
|
|
2012-04-03 09:31:53 +08:00
|
|
|
return bus;
|
|
|
|
}
|
|
|
|
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
static struct pci_host_bridge *find_pci_host_bridge(struct pci_bus *bus)
|
2012-04-03 09:31:53 +08:00
|
|
|
{
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
struct pci_bus *root_bus = find_pci_root_bus(bus);
|
2012-04-03 09:31:53 +08:00
|
|
|
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
return to_pci_host_bridge(root_bus->bridge);
|
2012-04-03 09:31:53 +08:00
|
|
|
}
|
|
|
|
|
2015-03-04 01:52:11 +08:00
|
|
|
struct device *pci_get_host_bridge_device(struct pci_dev *dev)
|
|
|
|
{
|
|
|
|
struct pci_bus *root_bus = find_pci_root_bus(dev->bus);
|
|
|
|
struct device *bridge = root_bus->bridge;
|
|
|
|
|
|
|
|
kobject_get(&bridge->kobj);
|
|
|
|
return bridge;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pci_put_host_bridge_device(struct device *dev)
|
|
|
|
{
|
|
|
|
kobject_put(&dev->kobj);
|
|
|
|
}
|
|
|
|
|
2012-04-03 09:31:53 +08:00
|
|
|
void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
|
|
|
|
void (*release_fn)(struct pci_host_bridge *),
|
|
|
|
void *release_data)
|
|
|
|
{
|
|
|
|
bridge->release_fn = release_fn;
|
|
|
|
bridge->release_data = release_data;
|
|
|
|
}
|
|
|
|
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
|
2012-04-03 09:31:53 +08:00
|
|
|
struct resource *res)
|
|
|
|
{
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
struct pci_host_bridge *bridge = find_pci_host_bridge(bus);
|
2015-02-05 13:44:44 +08:00
|
|
|
struct resource_entry *window;
|
2012-04-03 09:31:53 +08:00
|
|
|
resource_size_t offset = 0;
|
|
|
|
|
2015-02-05 13:44:44 +08:00
|
|
|
resource_list_for_each_entry(window, &bridge->windows) {
|
2012-04-03 09:31:53 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
|
2012-04-03 09:31:53 +08:00
|
|
|
struct pci_bus_region *region)
|
|
|
|
{
|
PCI: Convert pcibios_resource_to_bus() to take a pci_bus, not a pci_dev
These interfaces:
pcibios_resource_to_bus(struct pci_dev *dev, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_dev *dev, *resource, *bus_region)
took a pci_dev, but they really depend only on the pci_bus. And we want to
use them in resource allocation paths where we have the bus but not a
device, so this patch converts them to take the pci_bus instead of the
pci_dev:
pcibios_resource_to_bus(struct pci_bus *bus, *bus_region, *resource)
pcibios_bus_to_resource(struct pci_bus *bus, *resource, *bus_region)
In fact, with standard PCI-PCI bridges, they only depend on the host
bridge, because that's the only place address translation occurs, but
we aren't going that far yet.
[bhelgaas: changelog]
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
2013-12-10 14:54:40 +08:00
|
|
|
struct pci_host_bridge *bridge = find_pci_host_bridge(bus);
|
2015-02-05 13:44:44 +08:00
|
|
|
struct resource_entry *window;
|
2012-04-03 09:31:53 +08:00
|
|
|
resource_size_t offset = 0;
|
|
|
|
|
2015-02-05 13:44:44 +08:00
|
|
|
resource_list_for_each_entry(window, &bridge->windows) {
|
2012-04-03 09:31:53 +08:00
|
|
|
struct pci_bus_region bus_region;
|
|
|
|
|
2012-04-03 09:31:53 +08:00
|
|
|
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);
|