This is useful for drivers to find a resource inserted by, for example, an early PCI quirk. v2: We need to recurse through the resource tree as the named region we are looking for may be a grandchild of the root node. Signed-off-by: Chris Wilson <chris@xxxxxxxxxxxxxxxxxx> Cc: Jesse Barnes <jbarnes@xxxxxxxxxxxxxxxx> --- include/linux/ioport.h | 2 ++ kernel/resource.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 89b7c24..acad72f 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -158,6 +158,8 @@ extern int allocate_resource(struct resource *root, struct resource *new, resource_size_t), void *alignf_data); struct resource *lookup_resource(struct resource *root, resource_size_t start); +struct resource *lookup_resource_by_name(struct resource *root, + const char *name); int adjust_resource(struct resource *res, resource_size_t start, resource_size_t size); resource_size_t resource_alignment(struct resource *res); diff --git a/kernel/resource.c b/kernel/resource.c index 3f285dc..c6dd827 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -624,6 +624,36 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start) return res; } +static struct resource *__lookup_resource_by_name(struct resource *res, + const char *name) +{ + while (res) { + struct resource *child; + + if (strcmp(res->name, name) == 0) + return res; + + child = __lookup_resource_by_name(res->child, name); + if (child) + return child; + + res = res->sibling; + } + + return NULL; +} + +struct resource *lookup_resource_by_name(struct resource *root, const char *name) +{ + struct resource *res; + + read_lock(&resource_lock); + res = __lookup_resource_by_name(root->child, name); + read_unlock(&resource_lock); + + return res; +} + /* * Insert a resource into the resource tree. If successful, return NULL, * otherwise return the conflicting resource (compare to __request_resource()) -- 1.8.3.2 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/intel-gfx