ACPI / platform: Pay attention to parent device's resources
[cascardo/linux.git] / drivers / acpi / acpi_platform.c
index 159f7f1..b200ae1 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/dma-mapping.h>
+#include <linux/pci.h>
 #include <linux/platform_device.h>
 
 #include "internal.h"
@@ -30,6 +31,22 @@ static const struct acpi_device_id forbidden_id_list[] = {
        {"", 0},
 };
 
+static void acpi_platform_fill_resource(struct acpi_device *adev,
+       const struct resource *src, struct resource *dest)
+{
+       struct device *parent;
+
+       *dest = *src;
+
+       /*
+        * If the device has parent we need to take its resources into
+        * account as well because this device might consume part of those.
+        */
+       parent = acpi_get_first_physical_node(adev->parent);
+       if (parent && dev_is_pci(parent))
+               dest->parent = pci_find_resource(to_pci_dev(parent), dest);
+}
+
 /**
  * acpi_create_platform_device - Create platform device for ACPI device node
  * @adev: ACPI device node to create a platform device for.
@@ -70,7 +87,8 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
                }
                count = 0;
                list_for_each_entry(rentry, &resource_list, node)
-                       resources[count++] = *rentry->res;
+                       acpi_platform_fill_resource(adev, rentry->res,
+                                                   &resources[count++]);
 
                acpi_dev_free_resource_list(&resource_list);
        }