| 1 | commit 1c388919d89ca35741e9c4d3255adf87f76f0c06 |
| 2 | Author: Geert Uytterhoeven <geert@linux-m68k.org> |
| 3 | Date: Sat May 7 20:53:16 2011 +0200 |
| 4 | |
| 5 | resources: Add lookup_resource() |
| 6 | |
| 7 | Add a function to find an existing resource by a resource start address. |
| 8 | This allows to implement simple allocators (with a malloc/free-alike API) |
| 9 | on top of the resource system. |
| 10 | |
| 11 | Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org> |
| 12 | |
| 13 | diff --git a/include/linux/ioport.h b/include/linux/ioport.h |
| 14 | index e9bb22c..63eb429 100644 |
| 15 | --- a/include/linux/ioport.h |
| 16 | +++ b/include/linux/ioport.h |
| 17 | @@ -132,6 +132,7 @@ extern int allocate_resource(struct resource *root, struct resource *new, |
| 18 | resource_size_t, |
| 19 | resource_size_t), |
| 20 | void *alignf_data); |
| 21 | +struct resource *lookup_resource(struct resource *root, resource_size_t start); |
| 22 | int adjust_resource(struct resource *res, resource_size_t start, |
| 23 | resource_size_t size); |
| 24 | resource_size_t resource_alignment(struct resource *res); |
| 25 | diff --git a/kernel/resource.c b/kernel/resource.c |
| 26 | index 3ff4017..3b3cedc 100644 |
| 27 | --- a/kernel/resource.c |
| 28 | +++ b/kernel/resource.c |
| 29 | @@ -553,6 +553,27 @@ int allocate_resource(struct resource *root, struct resource *new, |
| 30 | |
| 31 | EXPORT_SYMBOL(allocate_resource); |
| 32 | |
| 33 | +/** |
| 34 | + * lookup_resource - find an existing resource by a resource start address |
| 35 | + * @root: root resource descriptor |
| 36 | + * @start: resource start address |
| 37 | + * |
| 38 | + * Returns a pointer to the resource if found, NULL otherwise |
| 39 | + */ |
| 40 | +struct resource *lookup_resource(struct resource *root, resource_size_t start) |
| 41 | +{ |
| 42 | + struct resource *res; |
| 43 | + |
| 44 | + read_lock(&resource_lock); |
| 45 | + for (res = root->child; res; res = res->sibling) { |
| 46 | + if (res->start == start) |
| 47 | + break; |
| 48 | + } |
| 49 | + read_unlock(&resource_lock); |
| 50 | + |
| 51 | + return res; |
| 52 | +} |
| 53 | + |
| 54 | /* |
| 55 | * Insert a resource into the resource tree. If successful, return NULL, |
| 56 | * otherwise return the conflicting resource (compare to __request_resource()) |
| 57 | |