Skip to content

Commit d70d141

Browse files
committed
ACPI: utils: Introduce helper for _DEP list lookup
The ACPI LPSS driver and the Surface platform driver code use almost the same code pattern for checking if one ACPI device is present in the list returned by _DEP for another ACPI device. To reduce the resulting code duplication, introduce a helper for that called acpi_device_dep() and invoke it from both places. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
1 parent 4c660ff commit d70d141

File tree

4 files changed

+38
-54
lines changed

4 files changed

+38
-54
lines changed

drivers/acpi/acpi_lpss.c

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -562,31 +562,6 @@ static struct device *acpi_lpss_find_device(const char *hid, const char *uid)
562562
return bus_find_device(&pci_bus_type, NULL, &data, match_hid_uid);
563563
}
564564

565-
static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
566-
{
567-
struct acpi_handle_list dep_devices;
568-
bool ret = false;
569-
int i;
570-
571-
if (!acpi_has_method(adev->handle, "_DEP"))
572-
return false;
573-
574-
if (!acpi_evaluate_reference(adev->handle, "_DEP", NULL, &dep_devices)) {
575-
dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
576-
return false;
577-
}
578-
579-
for (i = 0; i < dep_devices.count; i++) {
580-
if (dep_devices.handles[i] == handle) {
581-
ret = true;
582-
break;
583-
}
584-
}
585-
586-
acpi_handle_list_free(&dep_devices);
587-
return ret;
588-
}
589-
590565
static void acpi_lpss_link_consumer(struct device *dev1,
591566
const struct lpss_device_links *link)
592567
{
@@ -597,7 +572,7 @@ static void acpi_lpss_link_consumer(struct device *dev1,
597572
return;
598573

599574
if ((link->dep_missing_ids && dmi_check_system(link->dep_missing_ids))
600-
|| acpi_lpss_dep(ACPI_COMPANION(dev2), ACPI_HANDLE(dev1)))
575+
|| acpi_device_dep(ACPI_HANDLE(dev2), ACPI_HANDLE(dev1)))
601576
device_link_add(dev2, dev1, link->flags);
602577

603578
put_device(dev2);
@@ -613,7 +588,7 @@ static void acpi_lpss_link_supplier(struct device *dev1,
613588
return;
614589

615590
if ((link->dep_missing_ids && dmi_check_system(link->dep_missing_ids))
616-
|| acpi_lpss_dep(ACPI_COMPANION(dev1), ACPI_HANDLE(dev2)))
591+
|| acpi_device_dep(ACPI_HANDLE(dev1), ACPI_HANDLE(dev2)))
617592
device_link_add(dev1, dev2, link->flags);
618593

619594
put_device(dev2);

drivers/acpi/utils.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,40 @@ void acpi_handle_list_free(struct acpi_handle_list *list)
450450
}
451451
EXPORT_SYMBOL_GPL(acpi_handle_list_free);
452452

453+
/**
454+
* acpi_device_dep - Check ACPI device dependency
455+
* @target: ACPI handle of the target ACPI device.
456+
* @match: ACPI handle to look up in the target's _DEP list.
457+
*
458+
* Return true if @match is present in the list returned by _DEP for
459+
* @target or false otherwise.
460+
*/
461+
bool acpi_device_dep(acpi_handle target, acpi_handle match)
462+
{
463+
struct acpi_handle_list dep_devices;
464+
bool ret = false;
465+
int i;
466+
467+
if (!acpi_has_method(target, "_DEP"))
468+
return false;
469+
470+
if (!acpi_evaluate_reference(target, "_DEP", NULL, &dep_devices)) {
471+
acpi_handle_debug(target, "Failed to evaluate _DEP.\n");
472+
return false;
473+
}
474+
475+
for (i = 0; i < dep_devices.count; i++) {
476+
if (dep_devices.handles[i] == match) {
477+
ret = true;
478+
break;
479+
}
480+
}
481+
482+
acpi_handle_list_free(&dep_devices);
483+
return ret;
484+
}
485+
EXPORT_SYMBOL_GPL(acpi_device_dep);
486+
453487
acpi_status
454488
acpi_get_physical_device_location(acpi_handle handle, struct acpi_pld_info **pld)
455489
{

drivers/platform/surface/surface_acpi_notify.c

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -736,32 +736,6 @@ do { \
736736
#define san_consumer_warn(dev, handle, fmt, ...) \
737737
san_consumer_printk(warn, dev, handle, fmt, ##__VA_ARGS__)
738738

739-
static bool is_san_consumer(struct platform_device *pdev, acpi_handle handle)
740-
{
741-
struct acpi_handle_list dep_devices;
742-
acpi_handle supplier = ACPI_HANDLE(&pdev->dev);
743-
bool ret = false;
744-
int i;
745-
746-
if (!acpi_has_method(handle, "_DEP"))
747-
return false;
748-
749-
if (!acpi_evaluate_reference(handle, "_DEP", NULL, &dep_devices)) {
750-
san_consumer_dbg(&pdev->dev, handle, "failed to evaluate _DEP\n");
751-
return false;
752-
}
753-
754-
for (i = 0; i < dep_devices.count; i++) {
755-
if (dep_devices.handles[i] == supplier) {
756-
ret = true;
757-
break;
758-
}
759-
}
760-
761-
acpi_handle_list_free(&dep_devices);
762-
return ret;
763-
}
764-
765739
static acpi_status san_consumer_setup(acpi_handle handle, u32 lvl,
766740
void *context, void **rv)
767741
{
@@ -770,7 +744,7 @@ static acpi_status san_consumer_setup(acpi_handle handle, u32 lvl,
770744
struct acpi_device *adev;
771745
struct device_link *link;
772746

773-
if (!is_san_consumer(pdev, handle))
747+
if (!acpi_device_dep(handle, ACPI_HANDLE(&pdev->dev)))
774748
return AE_OK;
775749

776750
/* Ignore ACPI devices that are not present. */

include/acpi/acpi_bus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ bool acpi_handle_list_equal(struct acpi_handle_list *list1,
3333
void acpi_handle_list_replace(struct acpi_handle_list *dst,
3434
struct acpi_handle_list *src);
3535
void acpi_handle_list_free(struct acpi_handle_list *list);
36+
bool acpi_device_dep(acpi_handle target, acpi_handle match);
3637
acpi_status
3738
acpi_evaluate_ost(acpi_handle handle, u32 source_event, u32 status_code,
3839
struct acpi_buffer *status_buf);

0 commit comments

Comments
 (0)