Commit ab444ec9 authored by Gavin Shan's avatar Gavin Shan Committed by Benjamin Herrenschmidt

powerpc/pci: Partial tree hotplug support

When EEH error happens to one specific PE, the device drivers
of its attached EEH devices (PCI devices) are checked to see
the further action: reset with complete hotplug, or reset without
hotplug. However, that's not enough for those PCI devices whose
drivers can't support EEH, or those PCI devices without driver.
So we need do so-called "partial hotplug" on basis of PCI devices.
In the situation, part of PCI devices of the specific PE are
unplugged and plugged again after PE reset.

The patch changes pcibios_add_pci_devices() so that it can support
full hotplug and so-called "partial" hotplug based on device-tree
or real hardware. It's notable that pci_of_scan.c has been changed
for a bit in order to support the "partial" hotplug based on dev-tree.

Most of the generic code already supports that, we just need to
plumb it properly on our side.
Signed-off-by: default avatarGavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
parent 9feed42e
...@@ -1462,6 +1462,8 @@ void pcibios_finish_adding_to_bus(struct pci_bus *bus) ...@@ -1462,6 +1462,8 @@ void pcibios_finish_adding_to_bus(struct pci_bus *bus)
/* Allocate bus and devices resources */ /* Allocate bus and devices resources */
pcibios_allocate_bus_resources(bus); pcibios_allocate_bus_resources(bus);
pcibios_claim_one_bus(bus); pcibios_claim_one_bus(bus);
if (!pci_has_flag(PCI_PROBE_ONLY))
pci_assign_unassigned_bus_resources(bus);
/* Fixup EEH */ /* Fixup EEH */
eeh_add_device_tree_late(bus); eeh_add_device_tree_late(bus);
......
...@@ -71,7 +71,7 @@ EXPORT_SYMBOL_GPL(pcibios_remove_pci_devices); ...@@ -71,7 +71,7 @@ EXPORT_SYMBOL_GPL(pcibios_remove_pci_devices);
*/ */
void pcibios_add_pci_devices(struct pci_bus * bus) void pcibios_add_pci_devices(struct pci_bus * bus)
{ {
int slotno, num, mode, pass, max; int slotno, mode, pass, max;
struct pci_dev *dev; struct pci_dev *dev;
struct device_node *dn = pci_bus_to_OF_node(bus); struct device_node *dn = pci_bus_to_OF_node(bus);
...@@ -85,11 +85,15 @@ void pcibios_add_pci_devices(struct pci_bus * bus) ...@@ -85,11 +85,15 @@ void pcibios_add_pci_devices(struct pci_bus * bus)
/* use ofdt-based probe */ /* use ofdt-based probe */
of_rescan_bus(dn, bus); of_rescan_bus(dn, bus);
} else if (mode == PCI_PROBE_NORMAL) { } else if (mode == PCI_PROBE_NORMAL) {
/* use legacy probe */ /*
* Use legacy probe. In the partial hotplug case, we
* probably have grandchildren devices unplugged. So
* we don't check the return value from pci_scan_slot() in
* order for fully rescan all the way down to pick them up.
* They can have been removed during partial hotplug.
*/
slotno = PCI_SLOT(PCI_DN(dn->child)->devfn); slotno = PCI_SLOT(PCI_DN(dn->child)->devfn);
num = pci_scan_slot(bus, PCI_DEVFN(slotno, 0)); pci_scan_slot(bus, PCI_DEVFN(slotno, 0));
if (!num)
return;
pcibios_setup_bus_devices(bus); pcibios_setup_bus_devices(bus);
max = bus->busn_res.start; max = bus->busn_res.start;
for (pass = 0; pass < 2; pass++) { for (pass = 0; pass < 2; pass++) {
......
...@@ -230,11 +230,14 @@ void of_scan_pci_bridge(struct pci_dev *dev) ...@@ -230,11 +230,14 @@ void of_scan_pci_bridge(struct pci_dev *dev)
return; return;
} }
bus = pci_add_new_bus(dev->bus, dev, busrange[0]); bus = pci_find_bus(pci_domain_nr(dev->bus), busrange[0]);
if (!bus) { if (!bus) {
printk(KERN_ERR "Failed to create pci bus for %s\n", bus = pci_add_new_bus(dev->bus, dev, busrange[0]);
node->full_name); if (!bus) {
return; printk(KERN_ERR "Failed to create pci bus for %s\n",
node->full_name);
return;
}
} }
bus->primary = dev->bus->number; bus->primary = dev->bus->number;
...@@ -292,6 +295,38 @@ void of_scan_pci_bridge(struct pci_dev *dev) ...@@ -292,6 +295,38 @@ void of_scan_pci_bridge(struct pci_dev *dev)
} }
EXPORT_SYMBOL(of_scan_pci_bridge); EXPORT_SYMBOL(of_scan_pci_bridge);
static struct pci_dev *of_scan_pci_dev(struct pci_bus *bus,
struct device_node *dn)
{
struct pci_dev *dev = NULL;
const u32 *reg;
int reglen, devfn;
pr_debug(" * %s\n", dn->full_name);
if (!of_device_is_available(dn))
return NULL;
reg = of_get_property(dn, "reg", &reglen);
if (reg == NULL || reglen < 20)
return NULL;
devfn = (reg[0] >> 8) & 0xff;
/* Check if the PCI device is already there */
dev = pci_get_slot(bus, devfn);
if (dev) {
pci_dev_put(dev);
return dev;
}
/* create a new pci_dev for this device */
dev = of_create_pci_dev(dn, bus, devfn);
if (!dev)
return NULL;
pr_debug(" dev header type: %x\n", dev->hdr_type);
return dev;
}
/** /**
* __of_scan_bus - given a PCI bus node, setup bus and scan for child devices * __of_scan_bus - given a PCI bus node, setup bus and scan for child devices
* @node: device tree node for the PCI bus * @node: device tree node for the PCI bus
...@@ -302,8 +337,6 @@ static void __of_scan_bus(struct device_node *node, struct pci_bus *bus, ...@@ -302,8 +337,6 @@ static void __of_scan_bus(struct device_node *node, struct pci_bus *bus,
int rescan_existing) int rescan_existing)
{ {
struct device_node *child; struct device_node *child;
const u32 *reg;
int reglen, devfn;
struct pci_dev *dev; struct pci_dev *dev;
pr_debug("of_scan_bus(%s) bus no %d...\n", pr_debug("of_scan_bus(%s) bus no %d...\n",
...@@ -311,16 +344,7 @@ static void __of_scan_bus(struct device_node *node, struct pci_bus *bus, ...@@ -311,16 +344,7 @@ static void __of_scan_bus(struct device_node *node, struct pci_bus *bus,
/* Scan direct children */ /* Scan direct children */
for_each_child_of_node(node, child) { for_each_child_of_node(node, child) {
pr_debug(" * %s\n", child->full_name); dev = of_scan_pci_dev(bus, child);
if (!of_device_is_available(child))
continue;
reg = of_get_property(child, "reg", &reglen);
if (reg == NULL || reglen < 20)
continue;
devfn = (reg[0] >> 8) & 0xff;
/* create a new pci_dev for this device */
dev = of_create_pci_dev(child, bus, devfn);
if (!dev) if (!dev)
continue; continue;
pr_debug(" dev header type: %x\n", dev->hdr_type); pr_debug(" dev header type: %x\n", dev->hdr_type);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment