diff options
Diffstat (limited to 'drivers/acpi/resource.c')
-rw-r--r-- | drivers/acpi/resource.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/drivers/acpi/resource.c b/drivers/acpi/resource.c index 56241eb341f4..cb57962ef7c4 100644 --- a/drivers/acpi/resource.c +++ b/drivers/acpi/resource.c | |||
@@ -664,3 +664,60 @@ int acpi_dev_filter_resource_type(struct acpi_resource *ares, | |||
664 | return (type & types) ? 0 : 1; | 664 | return (type & types) ? 0 : 1; |
665 | } | 665 | } |
666 | EXPORT_SYMBOL_GPL(acpi_dev_filter_resource_type); | 666 | EXPORT_SYMBOL_GPL(acpi_dev_filter_resource_type); |
667 | |||
668 | static int acpi_dev_consumes_res(struct acpi_device *adev, struct resource *res) | ||
669 | { | ||
670 | struct list_head resource_list; | ||
671 | struct resource_entry *rentry; | ||
672 | int ret, found = 0; | ||
673 | |||
674 | INIT_LIST_HEAD(&resource_list); | ||
675 | ret = acpi_dev_get_resources(adev, &resource_list, NULL, NULL); | ||
676 | if (ret < 0) | ||
677 | return 0; | ||
678 | |||
679 | list_for_each_entry(rentry, &resource_list, node) { | ||
680 | if (resource_contains(rentry->res, res)) { | ||
681 | found = 1; | ||
682 | break; | ||
683 | } | ||
684 | |||
685 | } | ||
686 | |||
687 | acpi_dev_free_resource_list(&resource_list); | ||
688 | return found; | ||
689 | } | ||
690 | |||
691 | static acpi_status acpi_res_consumer_cb(acpi_handle handle, u32 depth, | ||
692 | void *context, void **ret) | ||
693 | { | ||
694 | struct resource *res = context; | ||
695 | struct acpi_device **consumer = (struct acpi_device **) ret; | ||
696 | struct acpi_device *adev; | ||
697 | |||
698 | if (acpi_bus_get_device(handle, &adev)) | ||
699 | return AE_OK; | ||
700 | |||
701 | if (acpi_dev_consumes_res(adev, res)) { | ||
702 | *consumer = adev; | ||
703 | return AE_CTRL_TERMINATE; | ||
704 | } | ||
705 | |||
706 | return AE_OK; | ||
707 | } | ||
708 | |||
709 | /** | ||
710 | * acpi_resource_consumer - Find the ACPI device that consumes @res. | ||
711 | * @res: Resource to search for. | ||
712 | * | ||
713 | * Search the current resource settings (_CRS) of every ACPI device node | ||
714 | * for @res. If we find an ACPI device whose _CRS includes @res, return | ||
715 | * it. Otherwise, return NULL. | ||
716 | */ | ||
717 | struct acpi_device *acpi_resource_consumer(struct resource *res) | ||
718 | { | ||
719 | struct acpi_device *consumer = NULL; | ||
720 | |||
721 | acpi_get_devices(NULL, acpi_res_consumer_cb, res, (void **) &consumer); | ||
722 | return consumer; | ||
723 | } | ||