diff options
Diffstat (limited to 'kernel/resource.c')
-rw-r--r-- | kernel/resource.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/kernel/resource.c b/kernel/resource.c index 78b087221c15..fb11a58b9594 100644 --- a/kernel/resource.c +++ b/kernel/resource.c | |||
@@ -223,13 +223,13 @@ int release_resource(struct resource *old) | |||
223 | 223 | ||
224 | EXPORT_SYMBOL(release_resource); | 224 | EXPORT_SYMBOL(release_resource); |
225 | 225 | ||
226 | #if defined(CONFIG_MEMORY_HOTPLUG) && !defined(CONFIG_ARCH_HAS_WALK_MEMORY) | 226 | #if !defined(CONFIG_ARCH_HAS_WALK_MEMORY) |
227 | /* | 227 | /* |
228 | * Finds the lowest memory reosurce exists within [res->start.res->end) | 228 | * Finds the lowest memory reosurce exists within [res->start.res->end) |
229 | * the caller must specify res->start, res->end, res->flags. | 229 | * the caller must specify res->start, res->end, res->flags and "name". |
230 | * If found, returns 0, res is overwritten, if not found, returns -1. | 230 | * If found, returns 0, res is overwritten, if not found, returns -1. |
231 | */ | 231 | */ |
232 | static int find_next_system_ram(struct resource *res) | 232 | static int find_next_system_ram(struct resource *res, char *name) |
233 | { | 233 | { |
234 | resource_size_t start, end; | 234 | resource_size_t start, end; |
235 | struct resource *p; | 235 | struct resource *p; |
@@ -245,6 +245,8 @@ static int find_next_system_ram(struct resource *res) | |||
245 | /* system ram is just marked as IORESOURCE_MEM */ | 245 | /* system ram is just marked as IORESOURCE_MEM */ |
246 | if (p->flags != res->flags) | 246 | if (p->flags != res->flags) |
247 | continue; | 247 | continue; |
248 | if (name && strcmp(p->name, name)) | ||
249 | continue; | ||
248 | if (p->start > end) { | 250 | if (p->start > end) { |
249 | p = NULL; | 251 | p = NULL; |
250 | break; | 252 | break; |
@@ -262,19 +264,26 @@ static int find_next_system_ram(struct resource *res) | |||
262 | res->end = p->end; | 264 | res->end = p->end; |
263 | return 0; | 265 | return 0; |
264 | } | 266 | } |
265 | int | 267 | |
266 | walk_memory_resource(unsigned long start_pfn, unsigned long nr_pages, void *arg, | 268 | /* |
267 | int (*func)(unsigned long, unsigned long, void *)) | 269 | * This function calls callback against all memory range of "System RAM" |
270 | * which are marked as IORESOURCE_MEM and IORESOUCE_BUSY. | ||
271 | * Now, this function is only for "System RAM". | ||
272 | */ | ||
273 | int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages, | ||
274 | void *arg, int (*func)(unsigned long, unsigned long, void *)) | ||
268 | { | 275 | { |
269 | struct resource res; | 276 | struct resource res; |
270 | unsigned long pfn, len; | 277 | unsigned long pfn, len; |
271 | u64 orig_end; | 278 | u64 orig_end; |
272 | int ret = -1; | 279 | int ret = -1; |
280 | |||
273 | res.start = (u64) start_pfn << PAGE_SHIFT; | 281 | res.start = (u64) start_pfn << PAGE_SHIFT; |
274 | res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1; | 282 | res.end = ((u64)(start_pfn + nr_pages) << PAGE_SHIFT) - 1; |
275 | res.flags = IORESOURCE_MEM | IORESOURCE_BUSY; | 283 | res.flags = IORESOURCE_MEM | IORESOURCE_BUSY; |
276 | orig_end = res.end; | 284 | orig_end = res.end; |
277 | while ((res.start < res.end) && (find_next_system_ram(&res) >= 0)) { | 285 | while ((res.start < res.end) && |
286 | (find_next_system_ram(&res, "System RAM") >= 0)) { | ||
278 | pfn = (unsigned long)(res.start >> PAGE_SHIFT); | 287 | pfn = (unsigned long)(res.start >> PAGE_SHIFT); |
279 | len = (unsigned long)((res.end + 1 - res.start) >> PAGE_SHIFT); | 288 | len = (unsigned long)((res.end + 1 - res.start) >> PAGE_SHIFT); |
280 | ret = (*func)(pfn, len, arg); | 289 | ret = (*func)(pfn, len, arg); |