Merge branch 'for-2.6.31' of git://git.linux-nfs.org/projects/trondmy/nfs-2.6
[pandora-kernel.git] / drivers / pci / hotplug / cpqphp_pci.c
index 2909e3f..6173b9a 100644 (file)
@@ -37,7 +37,6 @@
 #include "../pci.h"
 #include "cpqphp.h"
 #include "cpqphp_nvram.h"
-#include <asm/pci_x86.h>
 
 
 u8 cpqhp_nic_irq;
@@ -89,7 +88,7 @@ int cpqhp_configure_device (struct controller* ctrl, struct pci_func* func)
        int num;
 
        if (func->pci_dev == NULL)
-               func->pci_dev = pci_find_slot(func->bus, PCI_DEVFN(func->device, func->function));
+               func->pci_dev = pci_get_bus_and_slot(func->bus,PCI_DEVFN(func->device, func->function));
 
        /* No pci device, we need to create it then */
        if (func->pci_dev == NULL) {
@@ -99,7 +98,7 @@ int cpqhp_configure_device (struct controller* ctrl, struct pci_func* func)
                if (num)
                        pci_bus_add_devices(ctrl->pci_dev->bus);
 
-               func->pci_dev = pci_find_slot(func->bus, PCI_DEVFN(func->device, func->function));
+               func->pci_dev = pci_get_bus_and_slot(func->bus, PCI_DEVFN(func->device, func->function));
                if (func->pci_dev == NULL) {
                        dbg("ERROR: pci_dev still null\n");
                        return 0;
@@ -112,6 +111,8 @@ int cpqhp_configure_device (struct controller* ctrl, struct pci_func* func)
                pci_do_scan_bus(child);
        }
 
+       pci_dev_put(func->pci_dev);
+
        return 0;
 }
 
@@ -123,9 +124,11 @@ int cpqhp_unconfigure_device(struct pci_func* func)
        dbg("%s: bus/dev/func = %x/%x/%x\n", __func__, func->bus, func->device, func->function);
 
        for (j=0; j<8 ; j++) {
-               struct pci_dev* temp = pci_find_slot(func->bus, PCI_DEVFN(func->device, j));
-               if (temp)
+               struct pci_dev* temp = pci_get_bus_and_slot(func->bus, PCI_DEVFN(func->device, j));
+               if (temp) {
+                       pci_dev_put(temp);
                        pci_remove_bus_device(temp);
+               }
        }
        return 0;
 }
@@ -194,16 +197,6 @@ int cpqhp_set_irq (u8 bus_num, u8 dev_num, u8 int_pin, u8 irq_num)
 }
 
 
-/*
- * WTF??? This function isn't in the code, yet a function calls it, but the
- * compiler optimizes it away?  strange.  Here as a placeholder to keep the
- * compiler happy.
- */
-static int PCI_ScanBusNonBridge (u8 bus, u8 device)
-{
-       return 0;
-}
-
 static int PCI_ScanBusForNonBridge(struct controller *ctrl, u8 bus_num, u8 * dev_num)
 {
        u16 tdevice;
@@ -232,9 +225,9 @@ static int PCI_ScanBusForNonBridge(struct controller *ctrl, u8 bus_num, u8 * dev
                /* Yep we got one. bridge ? */
                if ((work >> 8) == PCI_TO_PCI_BRIDGE_CLASS) {
                        pci_bus_read_config_byte (ctrl->pci_bus, PCI_DEVFN(tdevice, 0), PCI_SECONDARY_BUS, &tbus);
+                       /* XXX: no recursion, wtf? */
                        dbg("Recurse on bus_num %d tdevice %d\n", tbus, tdevice);
-                       if (PCI_ScanBusNonBridge(tbus, tdevice) == 0)
-                               return 0;
+                       return 0;
                }
        }
 
@@ -244,39 +237,23 @@ static int PCI_ScanBusForNonBridge(struct controller *ctrl, u8 bus_num, u8 * dev
 
 static int PCI_GetBusDevHelper(struct controller *ctrl, u8 *bus_num, u8 *dev_num, u8 slot, u8 nobridge)
 {
-       struct irq_routing_table *PCIIRQRoutingInfoLength;
-       long len;
-       long loop;
+       int loop, len;
        u32 work;
-
        u8 tbus, tdevice, tslot;
 
-       PCIIRQRoutingInfoLength = pcibios_get_irq_routing_table();
-       if (!PCIIRQRoutingInfoLength)
-               return -1;
-
-       len = (PCIIRQRoutingInfoLength->size -
-              sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
-       /* Make sure I got at least one entry */
-       if (len == 0) {
-               kfree(PCIIRQRoutingInfoLength );
-               return -1;
-       }
-
+       len = cpqhp_routing_table_length();
        for (loop = 0; loop < len; ++loop) {
-               tbus = PCIIRQRoutingInfoLength->slots[loop].bus;
-               tdevice = PCIIRQRoutingInfoLength->slots[loop].devfn;
-               tslot = PCIIRQRoutingInfoLength->slots[loop].slot;
+               tbus = cpqhp_routing_table->slots[loop].bus;
+               tdevice = cpqhp_routing_table->slots[loop].devfn;
+               tslot = cpqhp_routing_table->slots[loop].slot;
 
                if (tslot == slot) {
                        *bus_num = tbus;
                        *dev_num = tdevice;
                        ctrl->pci_bus->number = tbus;
                        pci_bus_read_config_dword (ctrl->pci_bus, *dev_num, PCI_VENDOR_ID, &work);
-                       if (!nobridge || (work == 0xffffffff)) {
-                               kfree(PCIIRQRoutingInfoLength );
+                       if (!nobridge || (work == 0xffffffff))
                                return 0;
-                       }
 
                        dbg("bus_num %d devfn %d\n", *bus_num, *dev_num);
                        pci_bus_read_config_dword (ctrl->pci_bus, *dev_num, PCI_CLASS_REVISION, &work);
@@ -287,17 +264,12 @@ static int PCI_GetBusDevHelper(struct controller *ctrl, u8 *bus_num, u8 *dev_num
                                dbg("Scan bus for Non Bridge: bus %d\n", tbus);
                                if (PCI_ScanBusForNonBridge(ctrl, tbus, dev_num) == 0) {
                                        *bus_num = tbus;
-                                       kfree(PCIIRQRoutingInfoLength );
                                        return 0;
                                }
-                       } else {
-                               kfree(PCIIRQRoutingInfoLength );
+                       } else
                                return 0;
-                       }
-
                }
        }
-       kfree(PCIIRQRoutingInfoLength );
        return -1;
 }
 
@@ -438,7 +410,7 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug)
                        new_slot->switch_save = 0x10;
                        /* In case of unsupported board */
                        new_slot->status = DevError;
-                       new_slot->pci_dev = pci_find_slot(new_slot->bus, (new_slot->device << 3) | new_slot->function);
+                       new_slot->pci_dev = pci_get_bus_and_slot(new_slot->bus, (new_slot->device << 3) | new_slot->function);
 
                        for (cloop = 0; cloop < 0x20; cloop++) {
                                rc = pci_bus_read_config_dword(ctrl->pci_bus, PCI_DEVFN(device, function), cloop << 2, (u32 *) & (new_slot-> config_space [cloop]));
@@ -446,6 +418,8 @@ int cpqhp_save_config(struct controller *ctrl, int busnumber, int is_hot_plug)
                                        return rc;
                        }
 
+                       pci_dev_put(new_slot->pci_dev);
+
                        function++;
 
                        stop_it = 0;