]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/pci/hotplug/rpadlpar_core.c
[PATCH] fix more missing includes
[linux-2.6-omap-h63xx.git] / drivers / pci / hotplug / rpadlpar_core.c
index f2a73f70e58c416bee4b4a72ca050246433d8ec5..cc03609f45d02947095e214b5cde11cb8868deee 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"
 
 static DECLARE_MUTEX(rpadlpar_sem);
 
+#define DLPAR_MODULE_NAME "rpadlpar_io"
+
 #define NODE_TYPE_VIO  1
 #define NODE_TYPE_SLOT 2
 #define NODE_TYPE_PHB  3
@@ -93,14 +98,14 @@ static struct device_node *find_dlpar_node(char *drc_name, int *node_type)
        return NULL;
 }
 
-static struct slot *find_slot(char *drc_name)
+static struct slot *find_slot(struct device_node *dn)
 {
        struct list_head *tmp, *n;
        struct slot *slot;
 
         list_for_each_safe(tmp, n, &rpaphp_slot_head) {
                 slot = list_entry(tmp, struct slot, rpaphp_slot_list);
-                if (strcmp(slot->location, drc_name) == 0)
+                if (slot->dn == dn)
                         return slot;
         }
 
@@ -129,42 +134,6 @@ static void rpadlpar_claim_one_bus(struct pci_bus *b)
                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)
 {
@@ -181,29 +150,42 @@ 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__);
+       rpaphp_eeh_init_nodes(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 */
+       rpadlpar_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;
@@ -212,7 +194,9 @@ 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;
 
        /* Add pci bus */
        dev = dlpar_pci_add_bus(dn);
@@ -222,15 +206,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",
@@ -261,36 +236,34 @@ static int dlpar_remove_root_bus(struct pci_controller *phb)
        return 0;
 }
 
-static int dlpar_remove_phb(struct slot *slot)
+static int dlpar_remove_phb(char *drc_name, struct device_node *dn)
 {
-       struct pci_controller *phb;
-       struct device_node *dn;
+       struct slot *slot;
+       struct pci_dn *pdn;
        int rc = 0;
 
-       dn = slot->dn;
-       if (!dn) {
-               printk(KERN_ERR "%s: unexpected NULL slot device node\n",
-                               __FUNCTION__);
-               return -EIO;
-       }
-
-       phb = dn->phb;
-       if (!phb) {
-               printk(KERN_ERR "%s: unexpected NULL phb pointer\n",
-                               __FUNCTION__);
-               return -EIO;
-       }
+       if (!rpaphp_find_pci_bus(dn))
+               return -EINVAL;
 
-       if (rpaphp_remove_slot(slot)) {
-               printk(KERN_ERR "%s: unable to remove hotplug slot %s\n",
-                       __FUNCTION__, slot->location);
-               return -EIO;
+       slot = find_slot(dn);
+       if (slot) {
+               /* Remove hotplug slot */
+               if (rpaphp_remove_slot(slot)) {
+                       printk(KERN_ERR
+                               "%s: unable to remove hotplug slot %s\n",
+                               __FUNCTION__, drc_name);
+                       return -EIO;
+               }
        }
 
-       rc = dlpar_remove_root_bus(phb);
+       pdn = dn->data;
+       BUG_ON(!pdn || !pdn->phb);
+       rc = dlpar_remove_root_bus(pdn->phb);
        if (rc < 0)
                return rc;
 
+       pdn->phb = NULL;
+
        return 0;
 }
 
@@ -298,9 +271,14 @@ static int dlpar_add_phb(char *drc_name, struct device_node *dn)
 {
        struct pci_controller *phb;
 
+       if (PCI_DN(dn) && PCI_DN(dn)->phb) {
+               /* PHB already exists */
+               return -EINVAL;
+       }
+
        phb = init_phb_dynamic(dn);
        if (!phb)
-               return -EINVAL;
+               return -EIO;
 
        if (rpaphp_add_slot(dn)) {
                printk(KERN_ERR "%s: unable to add hotplug slot %s\n",
@@ -310,6 +288,20 @@ static int dlpar_add_phb(char *drc_name, struct device_node *dn)
        return 0;
 }
 
+static int dlpar_add_vio_slot(char *drc_name, struct device_node *dn)
+{
+       if (vio_find_node(dn))
+               return -EINVAL;
+
+       if (!vio_register_device_node(dn)) {
+               printk(KERN_ERR
+                       "%s: failed to register vio node %s\n",
+                       __FUNCTION__, drc_name);
+               return -EIO;
+       }
+       return 0;
+}
+
 /**
  * dlpar_add_slot - DLPAR add an I/O Slot
  * @drc_name: drc-name of newly added slot
@@ -327,17 +319,11 @@ int dlpar_add_slot(char *drc_name)
 {
        struct device_node *dn = NULL;
        int node_type;
-       int rc;
+       int rc = -EIO;
 
        if (down_interruptible(&rpadlpar_sem))
                return -ERESTARTSYS;
 
-       /* Check for existing hotplug slot */
-       if (find_slot(drc_name)) {
-               rc = -EINVAL;
-               goto exit;
-       }
-
        /* Find newly added node */
        dn = find_dlpar_node(drc_name, &node_type);
        if (!dn) {
@@ -345,32 +331,19 @@ int dlpar_add_slot(char *drc_name)
                goto exit;
        }
 
-       rc = -EIO;
        switch (node_type) {
                case NODE_TYPE_VIO:
-                       if (!vio_register_device_node(dn)) {
-                               printk(KERN_ERR
-                                       "%s: failed to register vio node %s\n",
-                                       __FUNCTION__, drc_name);
-                               goto exit;
-                       }
+                       rc = dlpar_add_vio_slot(drc_name, dn);
                        break;
                case NODE_TYPE_SLOT:
                        rc = dlpar_add_pci_slot(drc_name, dn);
-                       if (rc)
-                               goto exit;
                        break;
                case NODE_TYPE_PHB:
                        rc = dlpar_add_phb(drc_name, dn);
-                       if (rc)
-                               goto exit;
                        break;
-               default:
-                       printk("%s: unexpected node type\n", __FUNCTION__);
-                       goto exit;
        }
 
-       rc = 0;
+       printk(KERN_INFO "%s: slot %s added\n", DLPAR_MODULE_NAME, drc_name);
 exit:
        up(&rpadlpar_sem);
        return rc;
@@ -384,18 +357,15 @@ exit:
  * of an I/O Slot.
  * Return Codes:
  * 0                   Success
- * -EIO                        Internal  Error
+ * -EINVAL             Vio dev doesn't exist
  */
-static int dlpar_remove_vio_slot(struct device_node *dn, char *drc_name)
+static int dlpar_remove_vio_slot(char *drc_name, struct device_node *dn)
 {
        struct vio_dev *vio_dev;
 
        vio_dev = vio_find_node(dn);
-       if (!vio_dev) {
-               printk(KERN_ERR "%s: %s does not correspond to a vio dev\n",
-                               __FUNCTION__, drc_name);
-               return -EIO;
-       }
+       if (!vio_dev)
+               return -EINVAL;
 
        vio_unregister_device(vio_dev);
        return 0;
@@ -412,15 +382,26 @@ static int dlpar_remove_vio_slot(struct device_node *dn, char *drc_name)
  * -ENODEV             Not a valid drc_name
  * -EIO                        Internal PCI Error
  */
-int dlpar_remove_pci_slot(struct slot *slot, char *drc_name)
+int dlpar_remove_pci_slot(char *drc_name, struct device_node *dn)
 {
-       struct pci_bus *bus = slot->bus;
+       struct pci_bus *bus;
+       struct slot *slot;
 
-       /* Remove hotplug slot */
-       if (rpaphp_remove_slot(slot)) {
-               printk(KERN_ERR "%s: unable to remove hotplug slot %s\n",
-                       __FUNCTION__, drc_name);
-               return -EIO;
+       bus = rpaphp_find_pci_bus(dn);
+       if (!bus)
+               return -EINVAL;
+
+       slot = find_slot(dn);
+       if (slot) {
+               /* Remove hotplug slot */
+               if (rpaphp_remove_slot(slot)) {
+                       printk(KERN_ERR
+                               "%s: unable to remove hotplug slot %s\n",
+                               __FUNCTION__, drc_name);
+                       return -EIO;
+               }
+       } else {
+               rpaphp_unconfig_pci_adapter(bus);
        }
 
        if (unmap_bus_range(bus)) {
@@ -450,7 +431,6 @@ int dlpar_remove_pci_slot(struct slot *slot, char *drc_name)
 int dlpar_remove_slot(char *drc_name)
 {
        struct device_node *dn;
-       struct slot *slot;
        int node_type;
        int rc = 0;
 
@@ -463,22 +443,18 @@ int dlpar_remove_slot(char *drc_name)
                goto exit;
        }
 
-       if (node_type == NODE_TYPE_VIO) {
-               rc = dlpar_remove_vio_slot(dn, drc_name);
-       } else {
-               slot = find_slot(drc_name);
-               if (!slot) {
-                       rc = -EINVAL;
-                       goto exit;
-               }
-
-               if (node_type == NODE_TYPE_PHB)
-                       rc = dlpar_remove_phb(slot);
-               else {
-                       /* NODE_TYPE_SLOT */
-                       rc = dlpar_remove_pci_slot(slot, drc_name);
-               }
+       switch (node_type) {
+               case NODE_TYPE_VIO:
+                       rc = dlpar_remove_vio_slot(drc_name, dn);
+                       break;
+               case NODE_TYPE_PHB:
+                       rc = dlpar_remove_phb(drc_name, dn);
+                       break;
+               case NODE_TYPE_SLOT:
+                       rc = dlpar_remove_pci_slot(drc_name, dn);
+                       break;
        }
+       printk(KERN_INFO "%s: slot %s removed\n", DLPAR_MODULE_NAME, drc_name);
 exit:
        up(&rpadlpar_sem);
        return rc;