Messages in this thread Patch in this message | | | Date | Thu, 18 Dec 2003 14:14:48 +0000 | From | Matthew Wilcox <> | Subject | [PATCH] adjust_resource() |
| |
Hi Linus.
I need something along these lines to cope with some devices on PA-RISC and Russell also needs something like it for PCMCIA. What do you think?
diff -urpNX dontdiff linus-2.6/include/linux/ioport.h parisc-2.6/include/linux/ioport.h --- linus-2.6/include/linux/ioport.h Thu Dec 18 06:10:09 2003 +++ parisc-2.6/include/linux/ioport.h Thu Dec 18 05:48:57 2003 @@ -99,6 +99,8 @@ extern int allocate_resource(struct reso 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 -urpNX dontdiff linus-2.6/kernel/resource.c parisc-2.6/kernel/resource.c --- linus-2.6/kernel/resource.c Thu Dec 18 06:10:10 2003 +++ parisc-2.6/kernel/resource.c Thu Dec 18 05:48:59 2003 @@ -359,6 +361,49 @@ int insert_resource(struct resource *par } 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. -- "Next the statesmen will invent cheap lies, putting the blame upon the nation that is attacked, and every man will be glad of those conscience-soothing falsities, and will diligently study them, and refuse to examine any refutations of them; and thus he will by and by convince himself that the war is just, and will thank God for the better sleep he enjoys after this process of grotesque self-deception." -- Mark Twain - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |