Commit 5558ae34 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by David S. Miller

[PATCH] adjust_resource()

I need this to cope with some devices on PA-RISC and Russell also needs
something like it for PCMCIA.
parent d619064c
...@@ -99,6 +99,8 @@ extern int allocate_resource(struct resource *root, struct resource *new, ...@@ -99,6 +99,8 @@ extern int allocate_resource(struct resource *root, struct resource *new,
void (*alignf)(void *, struct resource *, void (*alignf)(void *, struct resource *,
unsigned long, unsigned long), unsigned long, unsigned long),
void *alignf_data); void *alignf_data);
int adjust_resource(struct resource *res, unsigned long start,
unsigned long size);
/* Convenience shorthand with allocation */ /* Convenience shorthand with allocation */
#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name)) #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name))
......
...@@ -360,6 +360,49 @@ int insert_resource(struct resource *parent, struct resource *new) ...@@ -360,6 +360,49 @@ int insert_resource(struct resource *parent, struct resource *new)
EXPORT_SYMBOL(insert_resource); 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. * This is compatibility stuff for IO resources.
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment