Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mn10300/PCI: Clip bridge windows to fit in upstream windows

Every PCI-PCI bridge window should fit inside an upstream bridge window
because orphaned address space is unreachable from the primary side of the
upstream bridge. If we inherit invalid bridge windows that overlap an
upstream window from firmware, clip them to fit and update the bridge
accordingly.

[bhelgaas: changelog]
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: David Howells <dhowells@redhat.com>
CC: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
CC: linux-am33-list@redhat.com

authored by

Yinghai Lu and committed by
Bjorn Helgaas
4e348ba2 576e4385

+25 -30
+1 -1
arch/mn10300/unit-asb2305/pci-asb2305.c
··· 106 106 if (!r->flags) 107 107 continue; 108 108 if (!r->start || 109 - pci_claim_resource(dev, idx) < 0) { 109 + pci_claim_bridge_resource(dev, idx) < 0) { 110 110 printk(KERN_ERR "PCI:" 111 111 " Cannot allocate resource" 112 112 " region %d of bridge %s\n",
+24 -29
arch/mn10300/unit-asb2305/pci.c
··· 281 281 return -ENODEV; 282 282 } 283 283 284 - static int is_valid_resource(struct pci_dev *dev, int idx) 285 - { 286 - unsigned int i, type_mask = IORESOURCE_IO | IORESOURCE_MEM; 287 - struct resource *devr = &dev->resource[idx], *busr; 288 - 289 - if (dev->bus) { 290 - pci_bus_for_each_resource(dev->bus, busr, i) { 291 - if (!busr || (busr->flags ^ devr->flags) & type_mask) 292 - continue; 293 - 294 - if (devr->start && 295 - devr->start >= busr->start && 296 - devr->end <= busr->end) 297 - return 1; 298 - } 299 - } 300 - 301 - return 0; 302 - } 303 - 304 284 static void pcibios_fixup_device_resources(struct pci_dev *dev) 305 285 { 306 - int limit, i; 286 + int idx; 307 287 308 - if (dev->bus->number != 0) 288 + if (!dev->bus) 309 289 return; 310 290 311 - limit = (dev->hdr_type == PCI_HEADER_TYPE_NORMAL) ? 312 - PCI_BRIDGE_RESOURCES : PCI_NUM_RESOURCES; 291 + for (idx = 0; idx < PCI_BRIDGE_RESOURCES; idx++) { 292 + struct resource *r = &dev->resource[idx]; 313 293 314 - for (i = 0; i < limit; i++) { 315 - if (!dev->resource[i].flags) 294 + if (!r->flags || r->parent || !r->start) 316 295 continue; 317 296 318 - if (is_valid_resource(dev, i)) 319 - pci_claim_resource(dev, i); 297 + pci_claim_resource(dev, idx); 298 + } 299 + } 300 + 301 + static void pcibios_fixup_bridge_resources(struct pci_dev *dev) 302 + { 303 + int idx; 304 + 305 + if (!dev->bus) 306 + return; 307 + 308 + for (idx = PCI_BRIDGE_RESOURCES; idx < PCI_NUM_RESOURCES; idx++) { 309 + struct resource *r = &dev->resource[idx]; 310 + 311 + if (!r->flags || r->parent || !r->start) 312 + continue; 313 + 314 + pci_claim_bridge_resource(dev, idx); 320 315 } 321 316 } 322 317 ··· 325 330 326 331 if (bus->self) { 327 332 pci_read_bridge_bases(bus); 328 - pcibios_fixup_device_resources(bus->self); 333 + pcibios_fixup_bridge_resources(bus->self); 329 334 } 330 335 331 336 list_for_each_entry(dev, &bus->devices, bus_list)