Commit 3b95bd16 authored by Aleksey Makarov's avatar Aleksey Makarov Committed by Rafael J. Wysocki

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: default avatarAleksey Makarov <aleksey.makarov@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 18558cae
...@@ -43,7 +43,6 @@ static const struct acpi_device_id forbidden_id_list[] = { ...@@ -43,7 +43,6 @@ static const struct acpi_device_id forbidden_id_list[] = {
struct platform_device *acpi_create_platform_device(struct acpi_device *adev) struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
{ {
struct platform_device *pdev = NULL; struct platform_device *pdev = NULL;
struct acpi_device *acpi_parent;
struct platform_device_info pdevinfo; struct platform_device_info pdevinfo;
struct resource_entry *rentry; struct resource_entry *rentry;
struct list_head resource_list; struct list_head resource_list;
...@@ -82,22 +81,8 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev) ...@@ -82,22 +81,8 @@ struct platform_device *acpi_create_platform_device(struct acpi_device *adev)
* attached to it, that physical device should be the parent of the * attached to it, that physical device should be the parent of the
* platform device we are about to create. * platform device we are about to create.
*/ */
pdevinfo.parent = NULL; pdevinfo.parent = adev->parent ?
acpi_parent = adev->parent; acpi_get_first_physical_node(adev->parent) : NULL;
if (acpi_parent) {
struct acpi_device_physical_node *entry;
struct list_head *list;
mutex_lock(&acpi_parent->physical_node_lock);
list = &acpi_parent->physical_node_list;
if (!list_empty(list)) {
entry = list_first_entry(list,
struct acpi_device_physical_node,
node);
pdevinfo.parent = entry->dev;
}
mutex_unlock(&acpi_parent->physical_node_lock);
}
pdevinfo.name = dev_name(&adev->dev); pdevinfo.name = dev_name(&adev->dev);
pdevinfo.id = -1; pdevinfo.id = -1;
pdevinfo.res = resources; pdevinfo.res = resources;
......
...@@ -479,24 +479,38 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device) ...@@ -479,24 +479,38 @@ static void acpi_device_remove_notify_handler(struct acpi_device *device)
Device Matching Device Matching
-------------------------------------------------------------------------- */ -------------------------------------------------------------------------- */
static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev, /**
const struct device *dev) * acpi_get_first_physical_node - Get first physical node of an ACPI device
* @adev: ACPI device in question
*
* Return: First physical node of ACPI device @adev
*/
struct device *acpi_get_first_physical_node(struct acpi_device *adev)
{ {
struct mutex *physical_node_lock = &adev->physical_node_lock; struct mutex *physical_node_lock = &adev->physical_node_lock;
struct device *phys_dev;
mutex_lock(physical_node_lock); mutex_lock(physical_node_lock);
if (list_empty(&adev->physical_node_list)) { if (list_empty(&adev->physical_node_list)) {
adev = NULL; phys_dev = NULL;
} else { } else {
const struct acpi_device_physical_node *node; const struct acpi_device_physical_node *node;
node = list_first_entry(&adev->physical_node_list, node = list_first_entry(&adev->physical_node_list,
struct acpi_device_physical_node, node); struct acpi_device_physical_node, node);
if (node->dev != dev)
adev = NULL; phys_dev = node->dev;
} }
mutex_unlock(physical_node_lock); mutex_unlock(physical_node_lock);
return adev; return phys_dev;
}
static struct acpi_device *acpi_primary_dev_companion(struct acpi_device *adev,
const struct device *dev)
{
const struct device *phys_dev = acpi_get_first_physical_node(adev);
return phys_dev && phys_dev == dev ? adev : NULL;
} }
/** /**
......
...@@ -106,6 +106,7 @@ bool acpi_device_is_present(struct acpi_device *adev); ...@@ -106,6 +106,7 @@ bool acpi_device_is_present(struct acpi_device *adev);
bool acpi_device_is_battery(struct acpi_device *adev); bool acpi_device_is_battery(struct acpi_device *adev);
bool acpi_device_is_first_physical_node(struct acpi_device *adev, bool acpi_device_is_first_physical_node(struct acpi_device *adev,
const struct device *dev); const struct device *dev);
struct device *acpi_get_first_physical_node(struct acpi_device *adev);
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
Device Matching and Notification Device Matching and Notification
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment