diff options
author | KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> | 2007-10-16 04:26:10 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-16 12:43:01 -0400 |
commit | 75884fb1c6388f3713ddcca662f3647b3129aaeb (patch) | |
tree | 7debdd89fd94d099de3d3763b47af00ef6359d9d /kernel/resource.c | |
parent | 48f13bf3e742fca8aab87f6c39451d03bf5952d4 (diff) |
memory unplug: memory hotplug cleanup
A clean up patch for "scanning memory resource [start, end)" operation.
Now, find_next_system_ram() function is used in memory hotplug, but this
interface is not easy to use and codes are complicated.
This patch adds walk_memory_resouce(start,len,arg,func) function.
The function 'func' is called per valid memory resouce range in [start,pfn).
[pbadari@us.ibm.com: Error handling in walk_memory_resource()]
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: Badari Pulavarty <pbadari@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/resource.c')
-rw-r--r-- | kernel/resource.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/kernel/resource.c b/kernel/resource.c index 9bd14fd3e6de..a358142ff48f 100644 --- a/kernel/resource.c +++ b/kernel/resource.c | |||
@@ -234,7 +234,7 @@ EXPORT_SYMBOL(release_resource); | |||
234 | * the caller must specify res->start, res->end, res->flags. | 234 | * the caller must specify res->start, res->end, res->flags. |
235 | * If found, returns 0, res is overwritten, if not found, returns -1. | 235 | * If found, returns 0, res is overwritten, if not found, returns -1. |
236 | */ | 236 | */ |
237 | int find_next_system_ram(struct resource *res) | 237 | static int find_next_system_ram(struct resource *res) |
238 | { | 238 | { |
239 | resource_size_t start, end; | 239 | resource_size_t start, end; |
240 | struct resource *p; | 240 | struct resource *p; |
@@ -267,6 +267,30 @@ int find_next_system_ram(struct resource *res) | |||
267 | res->end = p->end; | 267 | res->end = p->end; |
268 | return 0; | 268 | return 0; |
269 | } | 269 | } |
270 | int | ||
271 | walk_memory_resource(unsigned long start_pfn, unsigned long nr_pages, void *arg, | ||
272 | int (*func)(unsigned long, unsigned long, void *)) | ||
273 | { | ||
274 | struct resource res; | ||
275 | unsigned long pfn, len; | ||
276 | u64 orig_end; | ||
277 | int ret = -1; | ||
278 | res.start = (u64) start_pfn << PAGE_SHIFT; | ||
279 | res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1; | ||
280 | res.flags = IORESOURCE_MEM; | ||
281 | orig_end = res.end; | ||
282 | while ((res.start < res.end) && (find_next_system_ram(&res) >= 0)) { | ||
283 | pfn = (unsigned long)(res.start >> PAGE_SHIFT); | ||
284 | len = (unsigned long)((res.end + 1 - res.start) >> PAGE_SHIFT); | ||
285 | ret = (*func)(pfn, len, arg); | ||
286 | if (ret) | ||
287 | break; | ||
288 | res.start = res.end + 1; | ||
289 | res.end = orig_end; | ||
290 | } | ||
291 | return ret; | ||
292 | } | ||
293 | |||
270 | #endif | 294 | #endif |
271 | 295 | ||
272 | /* | 296 | /* |