From: Matthew Wilcox Date: Fri, 6 Feb 2004 07:07:04 +0000 (-0800) Subject: [PATCH] adjust_resource() X-Git-Tag: v2.6.3-rc1~3^2~2 X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=5558ae34e874f7f50920f70d1cd97cbb07e91a93;p=history.git [PATCH] adjust_resource() I need this to cope with some devices on PA-RISC and Russell also needs something like it for PCMCIA. --- diff --git a/include/linux/ioport.h b/include/linux/ioport.h index 5ad913d3cd96..363aef7268c6 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h @@ -99,6 +99,8 @@ extern int allocate_resource(struct resource *root, struct resource *new, void (*alignf)(void *, struct resource *, unsigned long, unsigned long), void *alignf_data); +int adjust_resource(struct resource *res, unsigned long start, + unsigned long size); /* Convenience shorthand with allocation */ #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name)) diff --git a/kernel/resource.c b/kernel/resource.c index e2048de77ae3..558e5ed0abcc 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -360,6 +360,49 @@ int insert_resource(struct resource *parent, struct resource *new) EXPORT_SYMBOL(insert_resource); +/* + * Given an existing resource, change its start and size to match the + * arguments. Returns -EBUSY if it can't fit. Existing children of + * the resource are assumed to be immutable. + */ +int adjust_resource(struct resource *res, unsigned long start, unsigned long size) +{ + struct resource *tmp, *parent = res->parent; + unsigned long end = start + size - 1; + int result = -EBUSY; + + write_lock(&resource_lock); + + if ((start < parent->start) || (end > parent->end)) + goto out; + + for (tmp = res->child; tmp; tmp = tmp->sibling) { + if ((tmp->start < start) || (tmp->end > end)) + goto out; + } + + if (res->sibling && (res->sibling->start <= end)) + goto out; + + tmp = parent->child; + if (tmp != res) { + while (tmp->sibling != res) + tmp = tmp->sibling; + if (start <= tmp->end) + goto out; + } + + res->start = start; + res->end = end; + result = 0; + + out: + write_unlock(&resource_lock); + return result; +} + +EXPORT_SYMBOL(adjust_resource); + /* * This is compatibility stuff for IO resources. *