Subject: [PATCH] [acpi driver model] Add helper for finding _CRS resources - Create include/acpi/resource.h and define the struct walk_resource structure, which describes a resource to search for. - Create drivers/acpi/drivers/core/resource.c and implement a wrapper for acpi_walk_resources() that provides its own callback, filtering the resources to the ones specified by the caller, and calling a simpler callback (also provided by the caller). Signed-off-by: Patrick Mochel --- drivers/acpi/drivers/core/Makefile | 2 +- drivers/acpi/drivers/core/resource.c | 31 +++++++++++++++++++++++++++++ include/acpi/resource.h | 36 ++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletions(-) create mode 100644 drivers/acpi/drivers/core/resource.c create mode 100644 include/acpi/resource.h applies-to: d5b97ca0b911952389a32190af968f287c5c1705 6a7368860e36b77a0421374a783ff4b4b7d7aa0b diff --git a/drivers/acpi/drivers/core/Makefile b/drivers/acpi/drivers/core/Makefile index caed047..562903a 100644 --- a/drivers/acpi/drivers/core/Makefile +++ b/drivers/acpi/drivers/core/Makefile @@ -1,6 +1,6 @@ obj-y := bus.o device.o driver.o event.o -obj-y += lib.o +obj-y += lib.o resource.o obj-$(CONFIG_ACPI_DM_SYSFS) += sysfs.o obj-$(CONFIG_ACPI_DM_SYSFS) += proc.o diff --git a/drivers/acpi/drivers/core/resource.c b/drivers/acpi/drivers/core/resource.c new file mode 100644 index 0000000..ad37f8c --- /dev/null +++ b/drivers/acpi/drivers/core/resource.c @@ -0,0 +1,31 @@ + +#include +#include + +static acpi_status walk_callback(struct acpi_resource * r, void * context) +{ + struct walk_resource * w = context; + int i; + + for (i = 0; i < w->num_rstypes; i++) { + if (w->rstypes[i] == r->id) { + int ret; + + w->resource = r; + ret = w->func(w); + return ret == 0 ? AE_OK : AE_CTRL_TERMINATE; + } + } + return AE_OK; +} + + +int acpi_dev_find_crs(struct walk_resource * w) +{ + acpi_status status; + + status = acpi_walk_resources(w->handle, METHOD_NAME__CRS, walk_callback, w); + return ACPI_SUCCESS(status) ? 0 : -ENODEV; +} + +EXPORT_SYMBOL_GPL(acpi_dev_find_crs); diff --git a/include/acpi/resource.h b/include/acpi/resource.h new file mode 100644 index 0000000..06c8709 --- /dev/null +++ b/include/acpi/resource.h @@ -0,0 +1,36 @@ +#include + + +/* + * ACPI_RESOURCE_TYPEs (from + + #define ACPI_RSTYPE_IRQ 0 + #define ACPI_RSTYPE_DMA 1 + #define ACPI_RSTYPE_START_DPF 2 + #define ACPI_RSTYPE_END_DPF 3 + #define ACPI_RSTYPE_IO 4 + #define ACPI_RSTYPE_FIXED_IO 5 + #define ACPI_RSTYPE_VENDOR 6 + #define ACPI_RSTYPE_END_TAG 7 + #define ACPI_RSTYPE_MEM24 8 + #define ACPI_RSTYPE_MEM32 9 + #define ACPI_RSTYPE_FIXED_MEM32 10 + #define ACPI_RSTYPE_ADDRESS16 11 + #define ACPI_RSTYPE_ADDRESS32 12 + #define ACPI_RSTYPE_ADDRESS64 13 + #define ACPI_RSTYPE_EXT_IRQ 14 +*/ + +#define ACPI_NUM_RESOURCES 15 + +struct walk_resource { + acpi_handle handle; + u32 rstypes[ACPI_NUM_RESOURCES]; + u32 num_rstypes; + int (*func)(struct walk_resource *); + void * data; + + struct acpi_resource * resource; +}; + +extern int acpi_dev_find_crs(struct walk_resource * w); --- 0.99.9.GIT