]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/pci/hotplug/rpadlpar_core.c
Merge with /home/shaggy/git/linus-clean/
[linux-2.6-omap-h63xx.git] / drivers / pci / hotplug / rpadlpar_core.c
index 4ada15111af0849fafd69769d31d189942ab43c1..7d93dbaf628deda9dc32811b5c0ed95c023ea500 100644 (file)
  */
 #include <linux/init.h>
 #include <linux/pci.h>
+#include <linux/string.h>
+
 #include <asm/pci-bridge.h>
 #include <asm/semaphore.h>
 #include <asm/rtas.h>
 #include <asm/vio.h>
+
 #include "../pci.h"
 #include "rpaphp.h"
 #include "rpadlpar.h"
@@ -109,64 +112,6 @@ static struct slot *find_slot(struct device_node *dn)
         return NULL;
 }
 
-static void rpadlpar_claim_one_bus(struct pci_bus *b)
-{
-       struct list_head *ld;
-       struct pci_bus *child_bus;
-
-       for (ld = b->devices.next; ld != &b->devices; ld = ld->next) {
-               struct pci_dev *dev = pci_dev_b(ld);
-               int i;
-
-               for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-                       struct resource *r = &dev->resource[i];
-
-                       if (r->parent || !r->start || !r->flags)
-                               continue;
-                       rpaphp_claim_resource(dev, i);
-               }
-       }
-
-       list_for_each_entry(child_bus, &b->children, node)
-               rpadlpar_claim_one_bus(child_bus);
-}
-
-static int pci_add_secondary_bus(struct device_node *dn,
-               struct pci_dev *bridge_dev)
-{
-       struct pci_controller *hose = dn->phb;
-       struct pci_bus *child;
-       u8 sec_busno;
-
-       /* Get busno of downstream bus */
-       pci_read_config_byte(bridge_dev, PCI_SECONDARY_BUS, &sec_busno);
-
-       /* Allocate and add to children of bridge_dev->bus */
-       child = pci_add_new_bus(bridge_dev->bus, bridge_dev, sec_busno);
-       if (!child) {
-               printk(KERN_ERR "%s: could not add secondary bus\n", __FUNCTION__);
-               return -ENOMEM;
-       }
-
-       sprintf(child->name, "PCI Bus #%02x", child->number);
-
-       /* Fixup subordinate bridge bases and resources */
-       pcibios_fixup_bus(child);
-
-       /* Claim new bus resources */
-       rpadlpar_claim_one_bus(bridge_dev->bus);
-
-       if (hose->last_busno < child->number)
-               hose->last_busno = child->number;
-
-       dn->bussubno = child->number;
-
-       /* ioremap() for child bus, which may or may not succeed */
-       remap_bus_range(child);
-
-       return 0;
-}
-
 static struct pci_dev *dlpar_find_new_dev(struct pci_bus *parent,
                                        struct device_node *dev_dn)
 {
@@ -183,29 +128,43 @@ static struct pci_dev *dlpar_find_new_dev(struct pci_bus *parent,
 
 static struct pci_dev *dlpar_pci_add_bus(struct device_node *dn)
 {
-       struct pci_controller *hose = dn->phb;
+       struct pci_dn *pdn = dn->data;
+       struct pci_controller *phb = pdn->phb;
        struct pci_dev *dev = NULL;
 
-       /* Scan phb bus for EADS device, adding new one to bus->devices */
-       if (!pci_scan_single_device(hose->bus, dn->devfn)) {
-               printk(KERN_ERR "%s: found no device on bus\n", __FUNCTION__);
+       eeh_add_device_tree_early(dn);
+
+       /* Add EADS device to PHB bus, adding new entry to bus->devices */
+       dev = of_create_pci_dev(dn, phb->bus, pdn->devfn);
+       if (!dev) {
+               printk(KERN_ERR "%s: failed to create pci dev for %s\n",
+                               __FUNCTION__, dn->full_name);
                return NULL;
        }
 
+       if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
+           dev->hdr_type == PCI_HEADER_TYPE_CARDBUS)
+               of_scan_pci_bridge(dn, dev);
+
+       rpaphp_init_new_devs(dev->subordinate);
+
+       /* Claim new bus resources */
+       pcibios_claim_one_bus(dev->bus);
+
+       /* ioremap() for child bus, which may or may not succeed */
+       (void) remap_bus_range(dev->bus);
+
        /* Add new devices to global lists.  Register in proc, sysfs. */
-       pci_bus_add_devices(hose->bus);
+       pci_bus_add_devices(phb->bus);
 
        /* Confirm new bridge dev was created */
-       dev = dlpar_find_new_dev(hose->bus, dn);
+       dev = dlpar_find_new_dev(phb->bus, dn);
        if (dev) {
                if (dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
                        printk(KERN_ERR "%s: unexpected header type %d\n",
                                __FUNCTION__, dev->hdr_type);
                        return NULL;
                }
-
-               if (pci_add_secondary_bus(dn, dev))
-                       return NULL;
        }
 
        return dev;
@@ -214,7 +173,6 @@ static struct pci_dev *dlpar_pci_add_bus(struct device_node *dn)
 static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn)
 {
        struct pci_dev *dev;
-       int rc;
 
        if (rpaphp_find_pci_bus(dn))
                return -EINVAL;
@@ -227,15 +185,6 @@ static int dlpar_add_pci_slot(char *drc_name, struct device_node *dn)
                return -EIO;
        }
 
-       if (dn->child) {
-               rc = rpaphp_config_pci_adapter(dev->subordinate);
-               if (rc < 0) {
-                       printk(KERN_ERR "%s: unable to enable slot %s\n",
-                               __FUNCTION__, drc_name);
-                       return -EIO;
-               }
-       }
-
        /* Add hotplug slot */
        if (rpaphp_add_slot(dn)) {
                printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
@@ -269,6 +218,7 @@ static int dlpar_remove_root_bus(struct pci_controller *phb)
 static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
 {
        struct slot *slot;
+       struct pci_dn *pdn;
        int rc = 0;
 
        if (!rpaphp_find_pci_bus(dn))
@@ -285,12 +235,13 @@ static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
                }
        }
 
-       BUG_ON(!dn->phb);
-       rc = dlpar_remove_root_bus(dn->phb);
+       pdn = dn->data;
+       BUG_ON(!pdn || !pdn->phb);
+       rc = dlpar_remove_root_bus(pdn->phb);
        if (rc < 0)
                return rc;
 
-       dn->phb = NULL;
+       pdn->phb = NULL;
 
        return 0;
 }
@@ -299,7 +250,7 @@ static int dlpar_add_phb(char *drc_name, struct device_node *dn)
 {
        struct pci_controller *phb;
 
-       if (dn->phb) {
+       if (PCI_DN(dn) && PCI_DN(dn)->phb) {
                /* PHB already exists */
                return -EINVAL;
        }
@@ -428,6 +379,8 @@ int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
                                __FUNCTION__, drc_name);
                        return -EIO;
                }
+       } else {
+               rpaphp_unconfig_pci_adapter(bus);
        }
 
        if (unmap_bus_range(bus)) {