diff options
Diffstat (limited to 'kernel/resource.c')
-rw-r--r-- | kernel/resource.c | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/kernel/resource.c b/kernel/resource.c index af96c1e4b54b..4e9d87fd7bc5 100644 --- a/kernel/resource.c +++ b/kernel/resource.c | |||
@@ -188,6 +188,36 @@ static int __release_resource(struct resource *old) | |||
188 | return -EINVAL; | 188 | return -EINVAL; |
189 | } | 189 | } |
190 | 190 | ||
191 | static void __release_child_resources(struct resource *r) | ||
192 | { | ||
193 | struct resource *tmp, *p; | ||
194 | resource_size_t size; | ||
195 | |||
196 | p = r->child; | ||
197 | r->child = NULL; | ||
198 | while (p) { | ||
199 | tmp = p; | ||
200 | p = p->sibling; | ||
201 | |||
202 | tmp->parent = NULL; | ||
203 | tmp->sibling = NULL; | ||
204 | __release_child_resources(tmp); | ||
205 | |||
206 | printk(KERN_DEBUG "release child resource %pR\n", tmp); | ||
207 | /* need to restore size, and keep flags */ | ||
208 | size = resource_size(tmp); | ||
209 | tmp->start = 0; | ||
210 | tmp->end = size - 1; | ||
211 | } | ||
212 | } | ||
213 | |||
214 | void release_child_resources(struct resource *r) | ||
215 | { | ||
216 | write_lock(&resource_lock); | ||
217 | __release_child_resources(r); | ||
218 | write_unlock(&resource_lock); | ||
219 | } | ||
220 | |||
191 | /** | 221 | /** |
192 | * request_resource - request and reserve an I/O or memory resource | 222 | * request_resource - request and reserve an I/O or memory resource |
193 | * @root: root resource descriptor | 223 | * @root: root resource descriptor |
@@ -297,14 +327,29 @@ int walk_system_ram_range(unsigned long start_pfn, unsigned long nr_pages, | |||
297 | 327 | ||
298 | #endif | 328 | #endif |
299 | 329 | ||
330 | static int __is_ram(unsigned long pfn, unsigned long nr_pages, void *arg) | ||
331 | { | ||
332 | return 1; | ||
333 | } | ||
334 | /* | ||
335 | * This generic page_is_ram() returns true if specified address is | ||
336 | * registered as "System RAM" in iomem_resource list. | ||
337 | */ | ||
338 | int __weak page_is_ram(unsigned long pfn) | ||
339 | { | ||
340 | return walk_system_ram_range(pfn, 1, NULL, __is_ram) == 1; | ||
341 | } | ||
342 | |||
300 | /* | 343 | /* |
301 | * Find empty slot in the resource tree given range and alignment. | 344 | * Find empty slot in the resource tree given range and alignment. |
302 | */ | 345 | */ |
303 | static int find_resource(struct resource *root, struct resource *new, | 346 | static int find_resource(struct resource *root, struct resource *new, |
304 | resource_size_t size, resource_size_t min, | 347 | resource_size_t size, resource_size_t min, |
305 | resource_size_t max, resource_size_t align, | 348 | resource_size_t max, resource_size_t align, |
306 | void (*alignf)(void *, struct resource *, | 349 | resource_size_t (*alignf)(void *, |
307 | resource_size_t, resource_size_t), | 350 | const struct resource *, |
351 | resource_size_t, | ||
352 | resource_size_t), | ||
308 | void *alignf_data) | 353 | void *alignf_data) |
309 | { | 354 | { |
310 | struct resource *this = root->child; | 355 | struct resource *this = root->child; |
@@ -330,7 +375,7 @@ static int find_resource(struct resource *root, struct resource *new, | |||
330 | tmp.end = max; | 375 | tmp.end = max; |
331 | tmp.start = ALIGN(tmp.start, align); | 376 | tmp.start = ALIGN(tmp.start, align); |
332 | if (alignf) | 377 | if (alignf) |
333 | alignf(alignf_data, &tmp, size, align); | 378 | tmp.start = alignf(alignf_data, &tmp, size, align); |
334 | if (tmp.start < tmp.end && tmp.end - tmp.start >= size - 1) { | 379 | if (tmp.start < tmp.end && tmp.end - tmp.start >= size - 1) { |
335 | new->start = tmp.start; | 380 | new->start = tmp.start; |
336 | new->end = tmp.start + size - 1; | 381 | new->end = tmp.start + size - 1; |
@@ -358,8 +403,10 @@ static int find_resource(struct resource *root, struct resource *new, | |||
358 | int allocate_resource(struct resource *root, struct resource *new, | 403 | int allocate_resource(struct resource *root, struct resource *new, |
359 | resource_size_t size, resource_size_t min, | 404 | resource_size_t size, resource_size_t min, |
360 | resource_size_t max, resource_size_t align, | 405 | resource_size_t max, resource_size_t align, |
361 | void (*alignf)(void *, struct resource *, | 406 | resource_size_t (*alignf)(void *, |
362 | resource_size_t, resource_size_t), | 407 | const struct resource *, |
408 | resource_size_t, | ||
409 | resource_size_t), | ||
363 | void *alignf_data) | 410 | void *alignf_data) |
364 | { | 411 | { |
365 | int err; | 412 | int err; |