Skip to content

Commit 4f0450a

Browse files
Lorenzo Pieralisirafaeljw
Lorenzo Pieralisi
authored andcommitted
ACPI: Make acpi_dev_get_resources() method agnostic
The function acpi_dev_get_resources() is completely generic and can be used to parse resource objects that are not necessarily coming from the _CRS method but also from other objects eg _DMA that have the same _CRS resource format. Create an acpi_dev_get_resources() helper, internal to the ACPI resources parsing compilation unit, __acpi_dev_get_resources(), that takes a const char* parameter to detect which ACPI method should be called to retrieve the resources list and make acpi_dev_get_resources() call it with a method name _CRS leaving the API behaviour unchanged. Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com> Tested-by: Nate Watterson <nwatters@codeaurora.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 0d624f5 commit 4f0450a

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed

drivers/acpi/resource.c

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,35 @@ static acpi_status acpi_dev_process_resource(struct acpi_resource *ares,
573573
return AE_OK;
574574
}
575575

576+
static int __acpi_dev_get_resources(struct acpi_device *adev,
577+
struct list_head *list,
578+
int (*preproc)(struct acpi_resource *, void *),
579+
void *preproc_data, char *method)
580+
{
581+
struct res_proc_context c;
582+
acpi_status status;
583+
584+
if (!adev || !adev->handle || !list_empty(list))
585+
return -EINVAL;
586+
587+
if (!acpi_has_method(adev->handle, method))
588+
return 0;
589+
590+
c.list = list;
591+
c.preproc = preproc;
592+
c.preproc_data = preproc_data;
593+
c.count = 0;
594+
c.error = 0;
595+
status = acpi_walk_resources(adev->handle, method,
596+
acpi_dev_process_resource, &c);
597+
if (ACPI_FAILURE(status)) {
598+
acpi_dev_free_resource_list(list);
599+
return c.error ? c.error : -EIO;
600+
}
601+
602+
return c.count;
603+
}
604+
576605
/**
577606
* acpi_dev_get_resources - Get current resources of a device.
578607
* @adev: ACPI device node to get the resources for.
@@ -601,28 +630,8 @@ int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
601630
int (*preproc)(struct acpi_resource *, void *),
602631
void *preproc_data)
603632
{
604-
struct res_proc_context c;
605-
acpi_status status;
606-
607-
if (!adev || !adev->handle || !list_empty(list))
608-
return -EINVAL;
609-
610-
if (!acpi_has_method(adev->handle, METHOD_NAME__CRS))
611-
return 0;
612-
613-
c.list = list;
614-
c.preproc = preproc;
615-
c.preproc_data = preproc_data;
616-
c.count = 0;
617-
c.error = 0;
618-
status = acpi_walk_resources(adev->handle, METHOD_NAME__CRS,
619-
acpi_dev_process_resource, &c);
620-
if (ACPI_FAILURE(status)) {
621-
acpi_dev_free_resource_list(list);
622-
return c.error ? c.error : -EIO;
623-
}
624-
625-
return c.count;
633+
return __acpi_dev_get_resources(adev, list, preproc, preproc_data,
634+
METHOD_NAME__CRS);
626635
}
627636
EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
628637

0 commit comments

Comments
 (0)