Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b97ea289 authored by Yijing Wang's avatar Yijing Wang Committed by Bjorn Helgaas
Browse files

PCI: Assign resources before drivers claim devices (pci_scan_root_bus())



Previously, pci_scan_root_bus() created a root PCI bus, enumerated the
devices on it, and called pci_bus_add_devices(), which made the devices
available for drivers to claim them.

Most callers assigned resources to devices after pci_scan_root_bus()
returns, which may be after drivers have claimed the devices.  This is
incorrect; the PCI core should not change device resources while a driver
is managing the device.

Remove pci_bus_add_devices() from pci_scan_root_bus() and do it after any
resource assignment in the callers.

Note that ARM's pci_common_init_dev() already called pci_bus_add_devices()
after pci_scan_root_bus(), so we only need to remove the first call:

  pci_common_init_dev
    pcibios_init_hw
      pci_scan_root_bus
        pci_bus_add_devices        # first call
    pci_bus_assign_resources
    pci_bus_add_devices            # second call

[bhelgaas: changelog, drop "root_bus" var in alpha common_init_pci(),
return failure earlier in mn10300, add "return" in x86 pcibios_scan_root(),
return early if xtensa platform_pcibios_fixup() fails]
Signed-off-by: default avatarYijing Wang <wangyijing@huawei.com>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
CC: Richard Henderson <rth@twiddle.net>
CC: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
CC: Matt Turner <mattst88@gmail.com>
CC: David Howells <dhowells@redhat.com>
CC: Tony Luck <tony.luck@intel.com>
CC: Michal Simek <monstr@monstr.eu>
CC: Ralf Baechle <ralf@linux-mips.org>
CC: Koichi Yasutake <yasutake.koichi@jp.panasonic.com>
CC: Sebastian Ott <sebott@linux.vnet.ibm.com>
CC: "David S. Miller" <davem@davemloft.net>
CC: Chris Metcalf <cmetcalf@ezchip.com>
CC: Chris Zankel <chris@zankel.net>
CC: Max Filippov <jcmvbkbc@gmail.com>
CC: Thomas Gleixner <tglx@linutronix.de>
parent c90570d9
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -338,6 +338,8 @@ common_init_pci(void)

		bus = pci_scan_root_bus(NULL, next_busno, alpha_mv.pci_ops,
					hose, &resources);
		if (!bus)
			continue;
		hose->bus = bus;
		hose->need_domain_info = need_domain_info;
		next_busno = bus->busn_res.end + 1;
@@ -353,6 +355,11 @@ common_init_pci(void)

	pci_assign_unassigned_resources();
	pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq);
	for (hose = hose_head; hose; hose = hose->next) {
		bus = hose->bus;
		if (bus)
			pci_bus_add_devices(bus);
	}
}


+5 −1
Original line number Diff line number Diff line
@@ -316,6 +316,7 @@ void pcibios_fixup_bus(struct pci_bus *bus)

int __init pcibios_init(void)
{
	struct pci_bus *bus;
	struct pci_ops *dir = NULL;
	LIST_HEAD(resources);

@@ -383,12 +384,15 @@ int __init pcibios_init(void)
	printk("PCI: Probing PCI hardware\n");
	pci_add_resource(&resources, &pci_ioport_resource);
	pci_add_resource(&resources, &pci_iomem_resource);
	pci_scan_root_bus(NULL, 0, pci_root_ops, NULL, &resources);
	bus = pci_scan_root_bus(NULL, 0, pci_root_ops, NULL, &resources);

	pcibios_irq_init();
	pcibios_fixup_irqs();
	pcibios_resource_survey();
	if (!bus)
		return 0;

	pci_bus_add_devices(bus);
	return 0;
}

+2 −0
Original line number Diff line number Diff line
@@ -271,7 +271,9 @@ sn_pci_controller_fixup(int segment, int busnum, struct pci_bus *bus)
 	if (bus == NULL) {
		kfree(res);
		kfree(controller);
		return;
	}
	pci_bus_add_devices(bus);
}

/*
+4 −0
Original line number Diff line number Diff line
@@ -1382,6 +1382,10 @@ static int __init pcibios_init(void)

	/* Call common code to handle resource allocation */
	pcibios_resource_survey();
	list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
		if (hose->bus)
			pci_bus_add_devices(hose->bus);
	}

	return 0;
}
+1 −0
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ static void pcibios_scanbus(struct pci_controller *hose)
			pci_bus_size_bridges(bus);
			pci_bus_assign_resources(bus);
		}
		pci_bus_add_devices(bus);
	}
}

Loading