Merge branch 'for-2.6.27' of git://linux-nfs.org/~bfields/linux
[linux-2.6] / drivers / pci / hotplug / acpi_pcihp.c
index 270a33c..93e37f0 100644 (file)
 #include <linux/types.h>
 #include <linux/pci.h>
 #include <linux/pci_hotplug.h>
+#include <linux/pci-acpi.h>
 #include <acpi/acpi.h>
 #include <acpi/acpi_bus.h>
 #include <acpi/actypes.h>
 
 #define MY_NAME        "acpi_pcihp"
 
-#define dbg(fmt, arg...) do { if (debug_acpi) printk(KERN_DEBUG "%s: %s: " fmt , MY_NAME , __FUNCTION__ , ## arg); } while (0)
+#define dbg(fmt, arg...) do { if (debug_acpi) printk(KERN_DEBUG "%s: %s: " fmt , MY_NAME , __func__ , ## arg); } while (0)
 #define err(format, arg...) printk(KERN_ERR "%s: " format , MY_NAME , ## arg)
 #define info(format, arg...) printk(KERN_INFO "%s: " format , MY_NAME , ## arg)
 #define warn(format, arg...) printk(KERN_WARNING "%s: " format , MY_NAME , ## arg)
@@ -71,7 +72,7 @@ decode_type0_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
        default:
                printk(KERN_WARNING
                       "%s: Type 0 Revision %d record not supported\n",
-                      __FUNCTION__, revision);
+                      __func__, revision);
                return AE_ERROR;
        }
        return AE_OK;
@@ -100,7 +101,7 @@ decode_type1_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
        default:
                printk(KERN_WARNING
                       "%s: Type 1 Revision %d record not supported\n",
-                      __FUNCTION__, revision);
+                      __func__, revision);
                return AE_ERROR;
        }
        return AE_OK;
@@ -142,7 +143,7 @@ decode_type2_hpx_record(union acpi_object *record, struct hotplug_params *hpx)
        default:
                printk(KERN_WARNING
                       "%s: Type 2 Revision %d record not supported\n",
-                      __FUNCTION__, revision);
+                      __func__, revision);
                return AE_ERROR;
        }
        return AE_OK;
@@ -203,7 +204,7 @@ acpi_run_hpx(acpi_handle handle, struct hotplug_params *hpx)
                        break;
                default:
                        printk(KERN_ERR "%s: Type %d record not supported\n",
-                              __FUNCTION__, type);
+                              __func__, type);
                        status = AE_ERROR;
                        goto exit;
                }
@@ -235,7 +236,7 @@ acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
                ret_buf.pointer = kmalloc (ret_buf.length, GFP_KERNEL);
                if (!ret_buf.pointer) {
                        printk(KERN_ERR "%s:%s alloc for _HPP fail\n",
-                               __FUNCTION__, (char *)string.pointer);
+                               __func__, (char *)string.pointer);
                        kfree(string.pointer);
                        return AE_NO_MEMORY;
                }
@@ -245,7 +246,7 @@ acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
                        break;
        default:
                if (ACPI_FAILURE(status)) {
-                       pr_debug("%s:%s _HPP fail=0x%x\n", __FUNCTION__,
+                       pr_debug("%s:%s _HPP fail=0x%x\n", __func__,
                                (char *)string.pointer, status);
                        kfree(string.pointer);
                        return status;
@@ -254,7 +255,7 @@ acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
 
        ext_obj = (union acpi_object *) ret_buf.pointer;
        if (ext_obj->type != ACPI_TYPE_PACKAGE) {
-               printk(KERN_ERR "%s:%s _HPP obj not a package\n", __FUNCTION__,
+               printk(KERN_ERR "%s:%s _HPP obj not a package\n", __func__,
                                (char *)string.pointer);
                status = AE_ERROR;
                goto free_and_return;
@@ -270,7 +271,7 @@ acpi_run_hpp(acpi_handle handle, struct hotplug_params *hpp)
                        break;
                default:
                        printk(KERN_ERR "%s:%s _HPP obj type incorrect\n",
-                               __FUNCTION__, (char *)string.pointer);
+                               __func__, (char *)string.pointer);
                        status = AE_ERROR;
                        goto free_and_return;
                }
@@ -299,7 +300,7 @@ free_and_return:
  *
  * @handle - the handle of the hotplug controller.
  */
-acpi_status acpi_run_oshp(acpi_handle handle)
+static acpi_status acpi_run_oshp(acpi_handle handle)
 {
        acpi_status             status;
        struct acpi_buffer      string = { ACPI_ALLOCATE_BUFFER, NULL };
@@ -311,20 +312,17 @@ acpi_status acpi_run_oshp(acpi_handle handle)
        if (ACPI_FAILURE(status))
                if (status != AE_NOT_FOUND)
                        printk(KERN_ERR "%s:%s OSHP fails=0x%x\n",
-                              __FUNCTION__, (char *)string.pointer, status);
+                              __func__, (char *)string.pointer, status);
                else
                        dbg("%s:%s OSHP not found\n",
-                           __FUNCTION__, (char *)string.pointer);
+                           __func__, (char *)string.pointer);
        else
-               pr_debug("%s:%s OSHP passes\n", __FUNCTION__,
+               pr_debug("%s:%s OSHP passes\n", __func__,
                        (char *)string.pointer);
 
        kfree(string.pointer);
        return status;
 }
-EXPORT_SYMBOL_GPL(acpi_run_oshp);
-
-
 
 /* acpi_get_hp_params_from_firmware
  *
@@ -374,6 +372,85 @@ acpi_status acpi_get_hp_params_from_firmware(struct pci_bus *bus,
 }
 EXPORT_SYMBOL_GPL(acpi_get_hp_params_from_firmware);
 
+/**
+ * acpi_get_hp_hw_control_from_firmware
+ * @dev: the pci_dev of the bridge that has a hotplug controller
+ * @flags: requested control bits for _OSC
+ *
+ * Attempt to take hotplug control from firmware.
+ */
+int acpi_get_hp_hw_control_from_firmware(struct pci_dev *dev, u32 flags)
+{
+       acpi_status status;
+       acpi_handle chandle, handle = DEVICE_ACPI_HANDLE(&(dev->dev));
+       struct pci_dev *pdev = dev;
+       struct pci_bus *parent;
+       struct acpi_buffer string = { ACPI_ALLOCATE_BUFFER, NULL };
+
+       flags &= (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL |
+                 OSC_SHPC_NATIVE_HP_CONTROL |
+                 OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
+       if (!flags) {
+               err("Invalid flags %u specified!\n", flags);
+               return -EINVAL;
+       }
+
+       /*
+        * Per PCI firmware specification, we should run the ACPI _OSC
+        * method to get control of hotplug hardware before using it. If
+        * an _OSC is missing, we look for an OSHP to do the same thing.
+        * To handle different BIOS behavior, we look for _OSC and OSHP
+        * within the scope of the hotplug controller and its parents,
+        * upto the host bridge under which this controller exists.
+        */
+       while (!handle) {
+               /*
+                * This hotplug controller was not listed in the ACPI name
+                * space at all. Try to get acpi handle of parent pci bus.
+                */
+               if (!pdev || !pdev->bus->parent)
+                       break;
+               parent = pdev->bus->parent;
+               dbg("Could not find %s in acpi namespace, trying parent\n",
+                   pci_name(pdev));
+               if (!parent->self)
+                       /* Parent must be a host bridge */
+                       handle = acpi_get_pci_rootbridge_handle(
+                                       pci_domain_nr(parent),
+                                       parent->number);
+               else
+                       handle = DEVICE_ACPI_HANDLE(&(parent->self->dev));
+               pdev = parent->self;
+       }
+
+       while (handle) {
+               acpi_get_name(handle, ACPI_FULL_PATHNAME, &string);
+               dbg("Trying to get hotplug control for %s \n",
+                   (char *)string.pointer);
+               status = pci_osc_control_set(handle, flags);
+               if (status == AE_NOT_FOUND)
+                       status = acpi_run_oshp(handle);
+               if (ACPI_SUCCESS(status)) {
+                       dbg("Gained control for hotplug HW for pci %s (%s)\n",
+                           pci_name(dev), (char *)string.pointer);
+                       kfree(string.pointer);
+                       return 0;
+               }
+               if (acpi_root_bridge(handle))
+                       break;
+               chandle = handle;
+               status = acpi_get_parent(chandle, &handle);
+               if (ACPI_FAILURE(status))
+                       break;
+       }
+
+       dbg("Cannot get control of hotplug hardware for pci %s\n",
+           pci_name(dev));
+
+       kfree(string.pointer);
+       return -ENODEV;
+}
+EXPORT_SYMBOL(acpi_get_hp_hw_control_from_firmware);
 
 /* acpi_root_bridge - check to see if this acpi object is a root bridge
  *