2005-11-04 00:52:16 +00:00
|
|
|
/*
|
|
|
|
* PCI Dynamic LPAR, PCI Hot Plug and PCI EEH recovery code
|
|
|
|
* for RPA-compliant PPC64 platform.
|
|
|
|
* Copyright (C) 2003 Linda Xie <lxie@us.ibm.com>
|
|
|
|
* Copyright (C) 2005 International Business Machines
|
|
|
|
*
|
|
|
|
* Updates, 2005, John Rose <johnrose@austin.ibm.com>
|
|
|
|
* Updates, 2005, Linas Vepstas <linas@austin.ibm.com>
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
|
|
|
|
* NON INFRINGEMENT. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
2011-07-29 06:19:31 +00:00
|
|
|
#include <linux/export.h>
|
2005-11-04 00:52:16 +00:00
|
|
|
#include <asm/pci-bridge.h>
|
2006-03-14 23:46:45 +00:00
|
|
|
#include <asm/ppc-pci.h>
|
2006-03-28 12:15:54 +00:00
|
|
|
#include <asm/firmware.h>
|
2007-03-22 22:14:07 +00:00
|
|
|
#include <asm/eeh.h>
|
2005-11-04 00:52:16 +00:00
|
|
|
|
|
|
|
static struct pci_bus *
|
|
|
|
find_bus_among_children(struct pci_bus *bus,
|
|
|
|
struct device_node *dn)
|
|
|
|
{
|
|
|
|
struct pci_bus *child = NULL;
|
2014-02-13 13:14:01 +00:00
|
|
|
struct pci_bus *tmp;
|
2005-11-04 00:52:16 +00:00
|
|
|
struct device_node *busdn;
|
|
|
|
|
|
|
|
busdn = pci_bus_to_OF_node(bus);
|
|
|
|
if (busdn == dn)
|
|
|
|
return bus;
|
|
|
|
|
2014-02-13 13:14:01 +00:00
|
|
|
list_for_each_entry(tmp, &bus->children, node) {
|
|
|
|
child = find_bus_among_children(tmp, dn);
|
2005-11-04 00:52:16 +00:00
|
|
|
if (child)
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pci_bus *
|
|
|
|
pcibios_find_pci_bus(struct device_node *dn)
|
|
|
|
{
|
|
|
|
struct pci_dn *pdn = dn->data;
|
|
|
|
|
|
|
|
if (!pdn || !pdn->phb || !pdn->phb->bus)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return find_bus_among_children(pdn->phb->bus, dn);
|
|
|
|
}
|
2006-02-02 00:19:06 +00:00
|
|
|
EXPORT_SYMBOL_GPL(pcibios_find_pci_bus);
|
2005-11-04 00:52:16 +00:00
|
|
|
|
2012-12-21 22:04:10 +00:00
|
|
|
struct pci_controller *init_phb_dynamic(struct device_node *dn)
|
2006-03-14 23:46:45 +00:00
|
|
|
{
|
|
|
|
struct pci_controller *phb;
|
|
|
|
|
2008-10-27 19:48:52 +00:00
|
|
|
pr_debug("PCI: Initializing new hotplug PHB %s\n", dn->full_name);
|
|
|
|
|
2006-03-14 23:46:45 +00:00
|
|
|
phb = pcibios_alloc_controller(dn);
|
|
|
|
if (!phb)
|
|
|
|
return NULL;
|
2006-11-11 06:25:08 +00:00
|
|
|
rtas_setup_phb(phb);
|
2006-03-14 23:46:45 +00:00
|
|
|
pci_process_bridge_OF_ranges(phb, dn, 0);
|
|
|
|
|
|
|
|
pci_devs_phb_init_dynamic(phb);
|
|
|
|
|
powerpc/eeh: Introduce EEH device
Original EEH implementation depends on struct pci_dn heavily. However,
EEH shouldn't depend on that actually because EEH needn't share much
information with other PCI components. That's to say, EEH should have
worked independently.
The patch introduces struct eeh_dev so that EEH core components needn't
be working based on struct pci_dn in future. Also, struct pci_dn, struct
eeh_dev instances are created in dynamic fasion and the binding with EEH
device, OF node, PCI device is implemented as well.
The EEH devices are created after PHBs are detected and initialized, but
PCI emunation hasn't started yet. Apart from that, PHB might be created
dynamically through DLPAR component and the EEH devices should be creatd
as well. Another case might be OF node is created dynamically by DR
(Dynamic Reconfiguration), which has been defined by PAPR. For those OF
nodes created by DR, EEH devices should be also created accordingly. The
binding between EEH device and OF node is done while the EEH device is
initially created.
The binding between EEH device and PCI device should be done after PCI
emunation is done. Besides, PCI hotplug also needs the binding so that
the EEH devices could be traced from the newly coming PCI buses or PCI
devices.
Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
2012-02-27 20:04:04 +00:00
|
|
|
/* Create EEH devices for the PHB */
|
|
|
|
eeh_dev_phb_init_dynamic(phb);
|
|
|
|
|
2006-03-14 23:46:45 +00:00
|
|
|
if (dn->child)
|
|
|
|
eeh_add_device_tree_early(dn);
|
|
|
|
|
2011-02-04 18:24:11 +00:00
|
|
|
pcibios_scan_phb(phb);
|
2008-10-27 19:48:52 +00:00
|
|
|
pcibios_finish_adding_to_bus(phb->bus);
|
2006-03-14 23:46:45 +00:00
|
|
|
|
|
|
|
return phb;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(init_phb_dynamic);
|
2008-10-27 19:48:52 +00:00
|
|
|
|
|
|
|
/* RPA-specific bits for removing PHBs */
|
|
|
|
int remove_phb_dynamic(struct pci_controller *phb)
|
|
|
|
{
|
|
|
|
struct pci_bus *b = phb->bus;
|
|
|
|
struct resource *res;
|
|
|
|
int rc, i;
|
|
|
|
|
2010-02-06 07:47:20 +00:00
|
|
|
pr_debug("PCI: Removing PHB %04x:%02x...\n",
|
2008-10-27 19:48:52 +00:00
|
|
|
pci_domain_nr(b), b->number);
|
|
|
|
|
|
|
|
/* We cannot to remove a root bus that has children */
|
|
|
|
if (!(list_empty(&b->children) && list_empty(&b->devices)))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
/* We -know- there aren't any child devices anymore at this stage
|
|
|
|
* and thus, we can safely unmap the IO space as it's not in use
|
|
|
|
*/
|
|
|
|
res = &phb->io_resource;
|
|
|
|
if (res->flags & IORESOURCE_IO) {
|
|
|
|
rc = pcibios_unmap_io_space(b);
|
|
|
|
if (rc) {
|
|
|
|
printk(KERN_ERR "%s: failed to unmap IO on bus %s\n",
|
|
|
|
__func__, b->name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-29 17:48:13 +00:00
|
|
|
/* Remove the PCI bus and unregister the bridge device from sysfs */
|
2008-10-27 19:48:52 +00:00
|
|
|
phb->bus = NULL;
|
|
|
|
pci_remove_bus(b);
|
2014-07-29 17:48:13 +00:00
|
|
|
device_unregister(b->bridge);
|
2008-10-27 19:48:52 +00:00
|
|
|
|
|
|
|
/* Now release the IO resource */
|
|
|
|
if (res->flags & IORESOURCE_IO)
|
|
|
|
release_resource(res);
|
|
|
|
|
|
|
|
/* Release memory resources */
|
|
|
|
for (i = 0; i < 3; ++i) {
|
|
|
|
res = &phb->mem_resources[i];
|
|
|
|
if (!(res->flags & IORESOURCE_MEM))
|
|
|
|
continue;
|
|
|
|
release_resource(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free pci_controller data structure */
|
|
|
|
pcibios_free_controller(phb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(remove_phb_dynamic);
|