Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7846de4

Browse files
groeckozbenh
authored andcommitted
powerpc/pci: Improve device hotplug initialization
Commit 37f0219 (powerpc/pci: fix PCI-e devices rescan issue on powerpc platform) fixes a problem with interrupt and DMA initialization on hot plugged devices. With this commit, interrupt and DMA initialization for hot plugged devices is handled in the pci device enable function. This approach has a couple of drawbacks. First, it creates two code paths for device initialization, one for hot plugged devices and another for devices known during the initial PCI scan. Second, the initialization code for hot plugged devices is only called when the device is enabled, ie typically in the probe function. Also, the platform specific setup code is called each time pci_enable_device() is called, not only once during device discovery, meaning it is actually called multiple times, once for devices discovered during the initial scan and again each time a driver is re-loaded. The visible result is that interrupt pins are only assigned to hot plugged devices when the device driver is loaded. Effectively this changes the PCI probe API, since pci_dev->irq and the device's dma configuration will now only be valid after pci_enable() was called at least once. A more subtle change is that platform specific PCI device setup is moved from device discovery into the driver's probe function, more specifically into the pci_enable_device() call. To fix the inconsistencies, add new function pcibios_add_device. Call pcibios_setup_device from pcibios_setup_bus_devices if device setup is not complete, and from pcibios_add_device if bus setup is complete. With this change, device setup code is moved back into device initialization, and called exactly once for both static and hot plugged devices. [ This also fixes a regression introduced by the above patch which causes dev->irq to be overwritten under some cirumstances after MSIs have been enabled for the device which leads to crashes due to the MSI core "hijacking" dev->irq to store the base MSI number and not the LSI. --BenH ] Cc: Yuanquan Chen <[email protected]> Cc: Benjamin Herrenschmidt <[email protected]> Cc: Hiroo Matsumoto <[email protected]> Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Benjamin Herrenschmidt <[email protected]>
1 parent 1abd601 commit 7846de4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

arch/powerpc/kernel/pci-common.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ void pcibios_setup_bus_self(struct pci_bus *bus)
994994
ppc_md.pci_dma_bus_setup(bus);
995995
}
996996

997-
void pcibios_setup_device(struct pci_dev *dev)
997+
static void pcibios_setup_device(struct pci_dev *dev)
998998
{
999999
/* Fixup NUMA node as it may not be setup yet by the generic
10001000
* code and is needed by the DMA init
@@ -1015,6 +1015,17 @@ void pcibios_setup_device(struct pci_dev *dev)
10151015
ppc_md.pci_irq_fixup(dev);
10161016
}
10171017

1018+
int pcibios_add_device(struct pci_dev *dev)
1019+
{
1020+
/*
1021+
* We can only call pcibios_setup_device() after bus setup is complete,
1022+
* since some of the platform specific DMA setup code depends on it.
1023+
*/
1024+
if (dev->bus->is_added)
1025+
pcibios_setup_device(dev);
1026+
return 0;
1027+
}
1028+
10181029
void pcibios_setup_bus_devices(struct pci_bus *bus)
10191030
{
10201031
struct pci_dev *dev;
@@ -1469,10 +1480,6 @@ int pcibios_enable_device(struct pci_dev *dev, int mask)
14691480
if (ppc_md.pcibios_enable_device_hook(dev))
14701481
return -EINVAL;
14711482

1472-
/* avoid pcie irq fix up impact on cardbus */
1473-
if (dev->hdr_type != PCI_HEADER_TYPE_CARDBUS)
1474-
pcibios_setup_device(dev);
1475-
14761483
return pci_enable_resources(dev, mask);
14771484
}
14781485

0 commit comments

Comments
 (0)