diff options
author | Geert Uytterhoeven <geert@linux-m68k.org> | 2011-05-07 14:53:16 -0400 |
---|---|---|
committer | Geert Uytterhoeven <geert@linux-m68k.org> | 2011-07-30 15:21:39 -0400 |
commit | 1c388919d89ca35741e9c4d3255adf87f76f0c06 (patch) | |
tree | 3858d97ce2f91cdf6ec3badafbf66ef058e178a7 | |
parent | 88efd0bbc0fe403a9948e6f94cc48b9f15ee4861 (diff) |
resources: Add lookup_resource()
Add a function to find an existing resource by a resource start address.
This allows to implement simple allocators (with a malloc/free-alike API)
on top of the resource system.
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
-rw-r--r-- | include/linux/ioport.h | 1 | ||||
-rw-r--r-- | kernel/resource.c | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/include/linux/ioport.h b/include/linux/ioport.h index e9bb22cba764..63eb429ecbe6 100644 --- a/include/linux/ioport.h +++ b/include/linux/ioport.h | |||
@@ -132,6 +132,7 @@ extern int allocate_resource(struct resource *root, struct resource *new, | |||
132 | resource_size_t, | 132 | resource_size_t, |
133 | resource_size_t), | 133 | resource_size_t), |
134 | void *alignf_data); | 134 | void *alignf_data); |
135 | struct resource *lookup_resource(struct resource *root, resource_size_t start); | ||
135 | int adjust_resource(struct resource *res, resource_size_t start, | 136 | int adjust_resource(struct resource *res, resource_size_t start, |
136 | resource_size_t size); | 137 | resource_size_t size); |
137 | resource_size_t resource_alignment(struct resource *res); | 138 | resource_size_t resource_alignment(struct resource *res); |
diff --git a/kernel/resource.c b/kernel/resource.c index 3ff40178dce7..3b3cedc52592 100644 --- a/kernel/resource.c +++ b/kernel/resource.c | |||
@@ -553,6 +553,27 @@ int allocate_resource(struct resource *root, struct resource *new, | |||
553 | 553 | ||
554 | EXPORT_SYMBOL(allocate_resource); | 554 | EXPORT_SYMBOL(allocate_resource); |
555 | 555 | ||
556 | /** | ||
557 | * lookup_resource - find an existing resource by a resource start address | ||
558 | * @root: root resource descriptor | ||
559 | * @start: resource start address | ||
560 | * | ||
561 | * Returns a pointer to the resource if found, NULL otherwise | ||
562 | */ | ||
563 | struct resource *lookup_resource(struct resource *root, resource_size_t start) | ||
564 | { | ||
565 | struct resource *res; | ||
566 | |||
567 | read_lock(&resource_lock); | ||
568 | for (res = root->child; res; res = res->sibling) { | ||
569 | if (res->start == start) | ||
570 | break; | ||
571 | } | ||
572 | read_unlock(&resource_lock); | ||
573 | |||
574 | return res; | ||
575 | } | ||
576 | |||
556 | /* | 577 | /* |
557 | * Insert a resource into the resource tree. If successful, return NULL, | 578 | * Insert a resource into the resource tree. If successful, return NULL, |
558 | * otherwise return the conflicting resource (compare to __request_resource()) | 579 | * otherwise return the conflicting resource (compare to __request_resource()) |