diff options
author | Aleksey Makarov <aleksey.makarov@linaro.org> | 2016-02-16 07:52:38 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-02-16 13:56:28 -0500 |
commit | 3b95bd160547f56a68aeb972c33ae9511e7a8380 (patch) | |
tree | 2aee4b0afd45b60ccde072b85be3e2298f034f35 | |
parent | 18558cae0272f8fd9647e69d3fec1565a7949865 (diff) |
ACPI: introduce a function to find the first physical device
Factor out the code that finds the first physical device
of a given ACPI device. It is used in several places.
Signed-off-by: Aleksey Makarov <aleksey.makarov@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r-- | drivers/acpi/acpi_platform.c | 19 | ||||
-rw-r--r-- | drivers/acpi/bus.c | 26 | ||||
-rw-r--r-- | drivers/acpi/internal.h | 1 |
3 files changed, 23 insertions, 23 deletions
diff --git a/drivers/acpi/acpi_platform.c b/drivers/acpi/acpi_platform.c index 296b7a14893a..c3af1088bf6b 100644 --- a/drivers/acpi/acpi_platform.c +++ b/drivers/acpi/acpi_platform.c | |||
@@ -43,7 +43,6 @@ static const struct acpi_device_id forbidden_id_list[] = { | |||
43 | struct platform_device *acpi_create_platform_device(struct acpi_device *adev) | 43 | struct platform_device *acpi_create_platform_device(struct acpi_device *adev) |
44 | { | 44 | { |
45 | struct platform_device *pdev = NULL; | 45 | struct platform_device *pdev = NULL; |
46 | struct acpi_device *acpi_parent; | ||
47 | struct platform_device_info pdevinfo; | 46 | struct platform_device_info pdevinfo; |
48 | struct resource_entry *rentry; | 47 | struct resource_entry *rentry; |
49 | struct list_head resource_list; | 48 | struct list_head resource_list; |
@@ -82,22 +81,8 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) | |||
82 | * attached to it, that physical device should be the parent of the | 81 | * attached to it, that physical device should be the parent of the |
83 | * platform device we are about to create. | 82 | * platform device we are about to create. |
84 | */ | 83 | */ |
85 | pdevinfo.parent = NULL; | 84 | pdevinfo.parent = adev->parent ? |
86 | acpi_parent = adev->parent; | 85 | acpi_get_first_physical_node(adev->parent) : NULL; |
87 | if (acpi_parent) { | ||
88 | struct acpi_device_physical_node *entry; | ||
89 | struct list_head *list; | ||
90 | |||
91 | mutex_lock(&acpi_parent->physical_node_lock); | ||
92 | list = &acpi_parent->physical_node_list; | ||
93 | if (!list_empty(list)) { | ||
94 | entry = list_first_entry(list, | ||
95 | struct acpi_device_physical_node, | ||
96 | node); | ||
97 | pdevinfo.parent = entry->dev; | ||
98 | } | ||
99 | mutex_unlock(&acpi_parent->physical_node_lock); | ||
100 | } | ||
101 | pdevinfo.name = dev_name(&adev->dev); | 86 | pdevinfo.name = dev_name(&adev->dev); |
102 | pdevinfo.id = -1; | 87 | pdevinfo.id = -1; |
103 | pdevinfo.res = resources; | 88 | pdevinfo.res = resources; |
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 891c42d1cd65..0e8567846f1a 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c | |||
@@ -479,24 +479,38 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device) | |||
479 | Device Matching | 479 | Device Matching |
480 | -------------------------------------------------------------------------- */ | 480 | -------------------------------------------------------------------------- */ |
481 | 481 | ||
482 | static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev, | 482 | /** |
483 | const struct device *dev) | 483 | * acpi_get_first_physical_node - Get first physical node of an ACPI device |
484 | * @adev: ACPI device in question | ||
485 | * | ||
486 | * Return: First physical node of ACPI device @adev | ||
487 | */ | ||
488 | struct device *acpi_get_first_physical_node(struct acpi_device *adev) | ||
484 | { | 489 | { |
485 | struct mutex *physical_node_lock = &adev->physical_node_lock; | 490 | struct mutex *physical_node_lock = &adev->physical_node_lock; |
491 | struct device *phys_dev; | ||
486 | 492 | ||
487 | mutex_lock(physical_node_lock); | 493 | mutex_lock(physical_node_lock); |
488 | if (list_empty(&adev->physical_node_list)) { | 494 | if (list_empty(&adev->physical_node_list)) { |
489 | adev = NULL; | 495 | phys_dev = NULL; |
490 | } else { | 496 | } else { |
491 | const struct acpi_device_physical_node *node; | 497 | const struct acpi_device_physical_node *node; |
492 | 498 | ||
493 | node = list_first_entry(&adev->physical_node_list, | 499 | node = list_first_entry(&adev->physical_node_list, |
494 | struct acpi_device_physical_node, node); | 500 | struct acpi_device_physical_node, node); |
495 | if (node->dev != dev) | 501 | |
496 | adev = NULL; | 502 | phys_dev = node->dev; |
497 | } | 503 | } |
498 | mutex_unlock(physical_node_lock); | 504 | mutex_unlock(physical_node_lock); |
499 | return adev; | 505 | return phys_dev; |
506 | } | ||
507 | |||
508 | static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev, | ||
509 | const struct device *dev) | ||
510 | { | ||
511 | const struct device *phys_dev = acpi_get_first_physical_node(adev); | ||
512 | |||
513 | return phys_dev && phys_dev == dev ? adev : NULL; | ||
500 | } | 514 | } |
501 | 515 | ||
502 | /** | 516 | /** |
diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 1e6833a5cd44..8668891cb1fa 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h | |||
@@ -106,6 +106,7 @@ bool acpi_device_is_present(struct acpi_device *adev); | |||
106 | bool acpi_device_is_battery(struct acpi_device *adev); | 106 | bool acpi_device_is_battery(struct acpi_device *adev); |
107 | bool acpi_device_is_first_physical_node(struct acpi_device *adev, | 107 | bool acpi_device_is_first_physical_node(struct acpi_device *adev, |
108 | const struct device *dev); | 108 | const struct device *dev); |
109 | struct device *acpi_get_first_physical_node(struct acpi_device *adev); | ||
109 | 110 | ||
110 | /* -------------------------------------------------------------------------- | 111 | /* -------------------------------------------------------------------------- |
111 | Device Matching and Notification | 112 | Device Matching and Notification |