mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-23 18:07:03 +00:00
PCI: Add pci_bus_clip_resource() to clip to fit upstream window
Add pci_bus_clip_resource(). If a PCI-PCI bridge window overlaps an
upstream bridge window but is not completely contained by it, this clips
the downstream window so it fits inside the upstream one.
No functional change (this adds the function but no callers).
[bhelgaas: changelog, split into separate patch]
Link: https://bugzilla.kernel.org/show_bug.cgi?id=85491
Reported-by: Marek Kordik <kordikmarek@gmail.com>
Fixes: 5b28541552
("PCI: Restrict 64-bit prefetchable bridge windows to 64-bit resources")
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
CC: stable@vger.kernel.org # v3.16+
This commit is contained in:
parent
3f2f4dc456
commit
0f7e7aee2f
@ -228,6 +228,49 @@ int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(pci_bus_alloc_resource);
|
EXPORT_SYMBOL(pci_bus_alloc_resource);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The @idx resource of @dev should be a PCI-PCI bridge window. If this
|
||||||
|
* resource fits inside a window of an upstream bridge, do nothing. If it
|
||||||
|
* overlaps an upstream window but extends outside it, clip the resource so
|
||||||
|
* it fits completely inside.
|
||||||
|
*/
|
||||||
|
bool pci_bus_clip_resource(struct pci_dev *dev, int idx)
|
||||||
|
{
|
||||||
|
struct pci_bus *bus = dev->bus;
|
||||||
|
struct resource *res = &dev->resource[idx];
|
||||||
|
struct resource orig_res = *res;
|
||||||
|
struct resource *r;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pci_bus_for_each_resource(bus, r, i) {
|
||||||
|
resource_size_t start, end;
|
||||||
|
|
||||||
|
if (!r)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (resource_type(res) != resource_type(r))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
start = max(r->start, res->start);
|
||||||
|
end = min(r->end, res->end);
|
||||||
|
|
||||||
|
if (start > end)
|
||||||
|
continue; /* no overlap */
|
||||||
|
|
||||||
|
if (res->start == start && res->end == end)
|
||||||
|
return false; /* no change */
|
||||||
|
|
||||||
|
res->start = start;
|
||||||
|
res->end = end;
|
||||||
|
dev_printk(KERN_DEBUG, &dev->dev, "%pR clipped to %pR\n",
|
||||||
|
&orig_res, res);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
|
void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -208,6 +208,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus,
|
|||||||
void __pci_bus_assign_resources(const struct pci_bus *bus,
|
void __pci_bus_assign_resources(const struct pci_bus *bus,
|
||||||
struct list_head *realloc_head,
|
struct list_head *realloc_head,
|
||||||
struct list_head *fail_head);
|
struct list_head *fail_head);
|
||||||
|
bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pci_ari_enabled - query ARI forwarding status
|
* pci_ari_enabled - query ARI forwarding status
|
||||||
|
Loading…
Reference in New Issue
Block a user