Skip to content

Commit b83e2b3

Browse files
djrscallyrafaeljw
authored andcommitted
ACPI: scan: Add function to fetch dependent of ACPI device
In some ACPI tables we encounter, devices use the _DEP method to assert a dependence on other ACPI devices as opposed to the OpRegions that the specification intends. We need to be able to find those devices "from" the dependee, so add a callback and a wrapper to walk over the acpi_dep_list and return the dependent ACPI device. Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Daniel Scally <djrscally@gmail.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent a9e10e5 commit b83e2b3

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

drivers/acpi/scan.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,20 @@ static void acpi_bus_attach(struct acpi_device *device, bool first_pass)
21012101
device->handler->hotplug.notify_online(device);
21022102
}
21032103

2104+
static int acpi_dev_get_first_consumer_dev_cb(struct acpi_dep_data *dep, void *data)
2105+
{
2106+
struct acpi_device *adev;
2107+
2108+
adev = acpi_bus_get_acpi_device(dep->consumer);
2109+
if (!adev)
2110+
/* If we don't find an adev then we want to continue parsing */
2111+
return 0;
2112+
2113+
*(struct acpi_device **)data = adev;
2114+
2115+
return 1;
2116+
}
2117+
21042118
static int acpi_scan_clear_dep(struct acpi_dep_data *dep, void *data)
21052119
{
21062120
struct acpi_device *adev;
@@ -2164,6 +2178,27 @@ void acpi_dev_clear_dependencies(struct acpi_device *supplier)
21642178
}
21652179
EXPORT_SYMBOL_GPL(acpi_dev_clear_dependencies);
21662180

2181+
/**
2182+
* acpi_dev_get_first_consumer_dev - Return ACPI device dependent on @supplier
2183+
* @supplier: Pointer to the dependee device
2184+
*
2185+
* Returns the first &struct acpi_device which declares itself dependent on
2186+
* @supplier via the _DEP buffer, parsed from the acpi_dep_list.
2187+
*
2188+
* The caller is responsible for putting the reference to adev when it is no
2189+
* longer needed.
2190+
*/
2191+
struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier)
2192+
{
2193+
struct acpi_device *adev = NULL;
2194+
2195+
acpi_walk_dep_device_list(supplier->handle,
2196+
acpi_dev_get_first_consumer_dev_cb, &adev);
2197+
2198+
return adev;
2199+
}
2200+
EXPORT_SYMBOL_GPL(acpi_dev_get_first_consumer_dev);
2201+
21672202
/**
21682203
* acpi_bus_scan - Add ACPI device node objects in a given namespace scope.
21692204
* @handle: Root of the namespace scope to scan.

include/acpi/acpi_bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev)
692692
bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2);
693693

694694
void acpi_dev_clear_dependencies(struct acpi_device *supplier);
695+
struct acpi_device *acpi_dev_get_first_consumer_dev(struct acpi_device *supplier);
695696
struct acpi_device *
696697
acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv);
697698
struct acpi_device *

0 commit comments

Comments
 (0)