ACPI: Introduce helper function acpi_dev_filter_resource_type()

Introduce helper function acpi_dev_filter_resource_type(), which may
be used by acpi_dev_get_resources() to filer out resource based on
resource type.

Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Jiang Liu 2015-02-02 10:43:01 +08:00 committed by Rafael J. Wysocki
parent 93286f4798
commit 62d1141ff3
2 changed files with 63 additions and 0 deletions

View File

@ -569,3 +569,58 @@ int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
return c.count;
}
EXPORT_SYMBOL_GPL(acpi_dev_get_resources);
/**
* acpi_dev_filter_resource_type - Filter ACPI resource according to resource
* types
* @ares: Input ACPI resource object.
* @types: Valid resource types of IORESOURCE_XXX
*
* This is a hepler function to support acpi_dev_get_resources(), which filters
* ACPI resource objects according to resource types.
*/
int acpi_dev_filter_resource_type(struct acpi_resource *ares,
unsigned long types)
{
unsigned long type = 0;
switch (ares->type) {
case ACPI_RESOURCE_TYPE_MEMORY24:
case ACPI_RESOURCE_TYPE_MEMORY32:
case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
type = IORESOURCE_MEM;
break;
case ACPI_RESOURCE_TYPE_IO:
case ACPI_RESOURCE_TYPE_FIXED_IO:
type = IORESOURCE_IO;
break;
case ACPI_RESOURCE_TYPE_IRQ:
case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
type = IORESOURCE_IRQ;
break;
case ACPI_RESOURCE_TYPE_DMA:
case ACPI_RESOURCE_TYPE_FIXED_DMA:
type = IORESOURCE_DMA;
break;
case ACPI_RESOURCE_TYPE_GENERIC_REGISTER:
type = IORESOURCE_REG;
break;
case ACPI_RESOURCE_TYPE_ADDRESS16:
case ACPI_RESOURCE_TYPE_ADDRESS32:
case ACPI_RESOURCE_TYPE_ADDRESS64:
case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
if (ares->data.address.resource_type == ACPI_MEMORY_RANGE)
type = IORESOURCE_MEM;
else if (ares->data.address.resource_type == ACPI_IO_RANGE)
type = IORESOURCE_IO;
else if (ares->data.address.resource_type ==
ACPI_BUS_NUMBER_RANGE)
type = IORESOURCE_BUS;
break;
default:
break;
}
return (type & types) ? 0 : 1;
}
EXPORT_SYMBOL_GPL(acpi_dev_filter_resource_type);

View File

@ -310,6 +310,14 @@ void acpi_dev_free_resource_list(struct list_head *list);
int acpi_dev_get_resources(struct acpi_device *adev, struct list_head *list,
int (*preproc)(struct acpi_resource *, void *),
void *preproc_data);
int acpi_dev_filter_resource_type(struct acpi_resource *ares,
unsigned long types);
static inline int acpi_dev_filter_resource_type_cb(struct acpi_resource *ares,
void *arg)
{
return acpi_dev_filter_resource_type(ares, (unsigned long)arg);
}
int acpi_check_resource_conflict(const struct resource *res);