Skip to content

Commit 73698b0

Browse files
Yinghai Lugregkh
authored andcommitted
PCI: Add pci_bus_clip_resource() to clip to fit upstream window
commit 0f7e7ae upstream. 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: 5b28541 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9f2e98f commit 73698b0

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎drivers/pci/bus.c‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,49 @@ int pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
228228
}
229229
EXPORT_SYMBOL(pci_bus_alloc_resource);
230230

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+
*/
237+
bool 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+
231274
void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
232275

233276
/**

‎drivers/pci/pci.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus,
208208
void __pci_bus_assign_resources(const struct pci_bus *bus,
209209
struct list_head *realloc_head,
210210
struct list_head *fail_head);
211+
bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
211212

212213
/**
213214
* pci_ari_enabled - query ARI forwarding status

0 commit comments

Comments
 (0)