aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2015-01-15 17:21:49 -0500
committerBjorn Helgaas <bhelgaas@google.com>2015-01-16 11:04:42 -0500
commit0f7e7aee2f37119a32e6e8b63250922442528961 (patch)
tree4bb354ba434d5870c08b16440183792ff717b3d6 /drivers/pci
parent3f2f4dc456e9f80849b99d79600a7257690ca4b1 (diff)
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: 5b28541552ef ("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+
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/bus.c43
-rw-r--r--drivers/pci/pci.h1
2 files changed, 44 insertions, 0 deletions
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 73aef51a28f0..8fb16188cd82 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -228,6 +228,49 @@ int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
228} 228}
229EXPORT_SYMBOL(pci_bus_alloc_resource); 229EXPORT_SYMBOL(pci_bus_alloc_resource);
230 230
231/*
232 * The @idx resource of @dev should be a PCI-PCI bridge window. If this
233 * resource fits inside a window of an upstream bridge, do nothing. If it
234 * overlaps an upstream window but extends outside it, clip the resource so
235 * it fits completely inside.
236 */
237bool pci_bus_clip_resource(struct pci_dev *dev, int idx)
238{
239 struct pci_bus *bus = dev->bus;
240 struct resource *res = &dev->resource[idx];
241 struct resource orig_res = *res;
242 struct resource *r;
243 int i;
244
245 pci_bus_for_each_resource(bus, r, i) {
246 resource_size_t start, end;
247
248 if (!r)
249 continue;
250
251 if (resource_type(res) != resource_type(r))
252 continue;
253
254 start = max(r->start, res->start);
255 end = min(r->end, res->end);
256
257 if (start > end)
258 continue; /* no overlap */
259
260 if (res->start == start && res->end == end)
261 return false; /* no change */
262
263 res->start = start;
264 res->end = end;
265 dev_printk(KERN_DEBUG, &dev->dev, "%pR clipped to %pR\n",
266 &orig_res, res);
267
268 return true;
269 }
270
271 return false;
272}
273
231void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } 274void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
232 275
233/** 276/**
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 8aff29a804ff..d54632a1db43 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -208,6 +208,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus,
208void __pci_bus_assign_resources(const struct pci_bus *bus, 208void __pci_bus_assign_resources(const struct pci_bus *bus,
209 struct list_head *realloc_head, 209 struct list_head *realloc_head,
210 struct list_head *fail_head); 210 struct list_head *fail_head);
211bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
211 212
212/** 213/**
213 * pci_ari_enabled - query ARI forwarding status 214 * pci_ari_enabled - query ARI forwarding status